From patchwork Fri Jan 26 18:41:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10186777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 11A6D601D5 for ; Fri, 26 Jan 2018 18:42:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 043EF29EC8 for ; Fri, 26 Jan 2018 18:42:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED45029ED0; Fri, 26 Jan 2018 18:42:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F4FA29EC8 for ; Fri, 26 Jan 2018 18:42:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752350AbeAZSmj (ORCPT ); Fri, 26 Jan 2018 13:42:39 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:44722 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751925AbeAZSlj (ORCPT ); Fri, 26 Jan 2018 13:41:39 -0500 Received: by mail-pf0-f193.google.com with SMTP id m26so813007pfj.11 for ; Fri, 26 Jan 2018 10:41:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=6YILKgQcLD2K92Y+2n3zmh+Yvdl+4sX0CL5+MLuWMnA=; b=HtD7BFRzT7D2eYmnsprrt3+npPUtMU8bWQoNrLt3nd3w2sgo+4j+lZY1j8ZECJmN6H BM39ZQtRxdGGGYiChx8/y5TAxKoKdEd+JH3d9K0Xg8/scA6Ehq2dZwlwqWWpZJ0t00Tr 3wQ7CTypVM5GYpiSsZPMRDBEZ2swVQSGZA7/kuCFaKouNkqj1r56ZadqhkLorkXxXq5R qYfLGw8SE/Bj3ru0MscbFXouzEc9MaX0Kn9zECP+PEV7+GLTJElGk+Ww2HVLpJxhWBX+ R+xCsB2c46RNo0f9QRHHSkRN+ISSSA/WQBXkH7MMVZRFssRVc4sdXD9eyO8fpVuvbSt2 437A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=6YILKgQcLD2K92Y+2n3zmh+Yvdl+4sX0CL5+MLuWMnA=; b=uMNWm3NSWOlyECqFaSER84TGDRGxMowegFiH0XDyvv4jjkcI7aZO4+eVIhyKMZV6j/ Xb0nt6TiprROIjWr5N3SJ7Eg4McH9PmZvGF3R4en+xKfd7GnP5SsBUG+/msChMeHHpm7 Xm4d3OLFcLW0SZcK0gsaz3BcBVC7RK4ULbDR6DsEI8oSScdCVB9/cKQT1ABwy47QkD59 uHKokak8A9IirET4/RdJI+dFIdBtL6ch/o/4hV5FQQ55DxBxjKsOS5WHpoEYbFkYVbiB qH8O010adEo60+ILbVhIatjcSumNSVel5lMI0pXs+zm7gkk4/kW1qxO2l/Y7UIiRm9bo Jorg== X-Gm-Message-State: AKwxytfV/d6ulklbBUf7OHFI723yPKapxxpd5LlhOsVSVpMApr0IwgOG k/115By8yyscJznCqtDD6ZAEDqEIFpA= X-Google-Smtp-Source: AH8x225R3gQMQDRPagmfFdvSWXICiEk4GsoGx9sLn4kLfIxUewIGX2n2uaIoC1pHIN6UqQ4rm2O1gg== X-Received: by 2002:a17:902:7797:: with SMTP id o23-v6mr5729694pll.287.1516992098744; Fri, 26 Jan 2018 10:41:38 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:7f96]) by smtp.gmail.com with ESMTPSA id y29sm19627400pff.24.2018.01.26.10.41.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2018 10:41:38 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 17/26] btrfs-progs: use libbtrfsutil for set-default Date: Fri, 26 Jan 2018 10:41:05 -0800 Message-Id: <11eb6c489a7f2e0b7512003cd4035d00af1a9ad0.1516991902.git.osandov@fb.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval Signed-off-by: Omar Sandoval --- cmds-subvolume.c | 47 ++++++++++------------------------------------- messages.h | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 89a4ebb0..aaf88af8 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -28,6 +28,8 @@ #include #include +#include + #include "kerncompat.h" #include "ioctl.h" #include "qgroup.h" @@ -853,11 +855,9 @@ static const char * const cmd_subvol_set_default_usage[] = { static int cmd_subvol_set_default(int argc, char **argv) { - int ret=0, fd, e; - u64 objectid; - char *path; - char *subvolid; - DIR *dirstream = NULL; + u64 objectid; + char *path; + enum btrfs_util_error err; clean_args_no_options(argc, argv, cmd_subvol_set_default_usage); @@ -867,44 +867,17 @@ static int cmd_subvol_set_default(int argc, char **argv) if (argc - optind == 1) { /* path to the subvolume is specified */ + objectid = 0; path = argv[optind]; - - ret = test_issubvolume(path); - if (ret < 0) { - error("stat error: %s", strerror(-ret)); - return 1; - } else if (!ret) { - error("'%s' is not a subvolume", path); - return 1; - } - - fd = btrfs_open_dir(path, &dirstream, 1); - if (fd < 0) - return 1; - - ret = lookup_path_rootid(fd, &objectid); - if (ret) { - error("unable to get subvol id: %s", strerror(-ret)); - close_file_or_dir(fd, dirstream); - return 1; - } } else { /* subvol id and path to the filesystem are specified */ - subvolid = argv[optind]; + objectid = arg_strtou64(argv[optind]); path = argv[optind + 1]; - objectid = arg_strtou64(subvolid); - - fd = btrfs_open_dir(path, &dirstream, 1); - if (fd < 0) - return 1; } - ret = ioctl(fd, BTRFS_IOC_DEFAULT_SUBVOL, &objectid); - e = errno; - close_file_or_dir(fd, dirstream); - if (ret < 0) { - error("unable to set a new default subvolume: %s", - strerror(e)); + err = btrfs_util_set_default_subvolume(path, objectid); + if (err) { + error_btrfs_util(err); return 1; } return 0; diff --git a/messages.h b/messages.h index 4999c7b9..cfabb86f 100644 --- a/messages.h +++ b/messages.h @@ -54,6 +54,20 @@ DO_ABORT_ON_ERROR; \ } while (0) +#define error_btrfs_util(err) \ + do { \ + const char *errno_str = strerror(errno); \ + const char *lib_str = btrfs_util_strerror(err) \ + PRINT_TRACE_ON_ERROR; \ + PRINT_VERBOSE_ERROR; \ + if (lib_str && strcmp(errno_str, lib_str) != 0) \ + __btrfs_error("%s: %s", lib_str, errno_str); \ + else \ + __btrfs_error("%s", errno_str); \ + DO_ABORT_ON_ERROR; \ + } while (0) + + #define warning(fmt, ...) \ do { \ PRINT_TRACE_ON_ERROR; \