From patchwork Thu Feb 15 19:05:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10223411 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 DD518602CB for ; Thu, 15 Feb 2018 19:06:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD35B29485 for ; Thu, 15 Feb 2018 19:06:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1B7C2948F; Thu, 15 Feb 2018 19:06:19 +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 4319A29485 for ; Thu, 15 Feb 2018 19:06:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1167132AbeBOTGN (ORCPT ); Thu, 15 Feb 2018 14:06:13 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:42397 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1167182AbeBOTFy (ORCPT ); Thu, 15 Feb 2018 14:05:54 -0500 Received: by mail-pg0-f65.google.com with SMTP id y8so494537pgr.9 for ; Thu, 15 Feb 2018 11:05:54 -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=rCI4jXsJxHAD0/H8uKsKW5pKosJXtX2L+eYtX0TlfCY=; b=mROPh/SBNy6aMZXgyEfDKaqs73SEHKVs60OEbBvA9qq3CuRyCcXv7DVT80fTPN5n2e dURskxunWEcOrGOVHQOb4gay+mzhYk90EiuKOGdNyM+kx+vbRD8Sc5Fr/bWF/AtevwIv l99l9fIhxr1TsmUVYGHn3c+UyPUWBXXbuQmKwE+IPO6Bklphx4/QaCmfufUMjRE6dyoo ItcdcTiKYkKHmbjouZsdkd0w30L61F+a6nIpLdggFIndwfRCDL84mIqnL+XkfRdMPidK nFLoneWAfQPKvyEKiBktd4v4hn/BTEipsAsj17Q262qrQg7AoUS2LcTlPNTJQ2vx94cz 5qmw== 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=rCI4jXsJxHAD0/H8uKsKW5pKosJXtX2L+eYtX0TlfCY=; b=YAA40c+Yt4KcV3jIhc1OX6LTCLe8dkuGCr8POyYrMOYtllWpdYZRGYhz1ROliPBINz JuVzdS5hCuhOKI5IvdKZmZI4rOS4XmI1wH6FpiZ1eUMzG4oGlF6fYOGG3/rOxFwnh0gu 4JgopQZoiGYlVsF0WHLW+i4ucbJZ4PSFpprPjB1E4rFiKFdyBnVF5TalbfFIuuYVZquO ewpT59pPic2kd9+dNEOvVP1rcsBrhuJbKY7YSdUkgrKbqM2LMFYPdKpTMe2WEj1FSRzA lH4ERP3M0J+KxVxyI8ReMJBapvN2/Wy2SKwYbcAtvtrcJ06yfRZpwE5CtneKLlV7X8UL F8aA== X-Gm-Message-State: APf1xPB5e6LMKP0fTJ99OXuop5hBitBsn7Vp+D4Z9idTHO4F8YZzW11U V228PeZ6nJpY3Jcn1CjvnDjdlLuk9iI= X-Google-Smtp-Source: AH8x227UWVwBRWnRqL6w+QPjmnKQBzT1wt0I6lmNvkKdA7foRoL7uz//sqg2qSrF+bCBGEk76pc3YA== X-Received: by 10.101.97.3 with SMTP id z3mr3029215pgu.44.1518721553298; Thu, 15 Feb 2018 11:05:53 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:4a19]) by smtp.gmail.com with ESMTPSA id p1sm40467428pgr.44.2018.02.15.11.05.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 11:05:52 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH v2 24/27] btrfs-progs: replace test_issubvolume() with btrfs_util_is_subvolume() Date: Thu, 15 Feb 2018 11:05:09 -0800 Message-Id: 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 This gets the remaining occurrences that weren't covered by previous conversions. Signed-off-by: Omar Sandoval --- cmds-qgroup.c | 11 ++++------- cmds-subvolume.c | 10 +++------- utils.c | 34 +++++----------------------------- utils.h | 1 - 4 files changed, 12 insertions(+), 44 deletions(-) diff --git a/cmds-qgroup.c b/cmds-qgroup.c index f9a52fa8..f733565e 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -425,6 +425,7 @@ static int cmd_qgroup_limit(int argc, char **argv) int compressed = 0; int exclusive = 0; DIR *dirstream = NULL; + enum btrfs_util_error err; while (1) { int c = getopt(argc, argv, "ce"); @@ -465,13 +466,9 @@ static int cmd_qgroup_limit(int argc, char **argv) if (argc - optind == 2) { args.qgroupid = 0; path = argv[optind + 1]; - ret = test_issubvolume(path); - if (ret < 0) { - error("cannot access '%s': %s", path, strerror(-ret)); - return 1; - } - if (!ret) { - error("'%s' is not a subvolume", path); + err = btrfs_util_is_subvolume(path); + if (err) { + error_btrfs_util(err); return 1; } /* diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 9bab9312..43875c96 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -756,13 +756,9 @@ static int cmd_subvol_find_new(int argc, char **argv) subvol = argv[optind]; last_gen = arg_strtou64(argv[optind + 1]); - ret = test_issubvolume(subvol); - if (ret < 0) { - error("cannot access subvolume %s: %s", subvol, strerror(-ret)); - return 1; - } - if (!ret) { - error("not a subvolume: %s", subvol); + err = btrfs_util_is_subvolume(subvol); + if (err) { + error_btrfs_util(err); return 1; } diff --git a/utils.c b/utils.c index 6e6f295f..9be91437 100644 --- a/utils.c +++ b/utils.c @@ -40,6 +40,8 @@ #include #include +#include + #include "kerncompat.h" #include "radix-tree.h" #include "ctree.h" @@ -1453,6 +1455,7 @@ u64 parse_qgroupid(const char *p) char *s = strchr(p, '/'); const char *ptr_src_end = p + strlen(p); char *ptr_parse_end = NULL; + enum btrfs_util_error err; u64 level; u64 id; int fd; @@ -1480,8 +1483,8 @@ u64 parse_qgroupid(const char *p) path: /* Path format like subv at 'my_subvol' is the fallback case */ - ret = test_issubvolume(p); - if (ret < 0 || !ret) + err = btrfs_util_is_subvolume(p); + if (err) goto err; fd = open(p, O_RDONLY); if (fd < 0) @@ -2451,33 +2454,6 @@ int test_issubvolname(const char *name) strcmp(name, ".") && strcmp(name, ".."); } -/* - * Test if path is a subvolume - * Returns: - * 0 - path exists but it is not a subvolume - * 1 - path exists and it is a subvolume - * < 0 - error - */ -int test_issubvolume(const char *path) -{ - struct stat st; - struct statfs stfs; - int res; - - res = stat(path, &st); - if (res < 0) - return -errno; - - if (st.st_ino != BTRFS_FIRST_FREE_OBJECTID || !S_ISDIR(st.st_mode)) - return 0; - - res = statfs(path, &stfs); - if (res < 0) - return -errno; - - return (int)stfs.f_type == BTRFS_SUPER_MAGIC; -} - const char *subvol_strip_mountpoint(const char *mnt, const char *full_path) { int len = strlen(mnt); diff --git a/utils.h b/utils.h index eb460e9b..403de481 100644 --- a/utils.h +++ b/utils.h @@ -149,7 +149,6 @@ u64 disk_size(const char *path); u64 get_partition_size(const char *dev); int test_issubvolname(const char *name); -int test_issubvolume(const char *path); int test_isdir(const char *path); const char *subvol_strip_mountpoint(const char *mnt, const char *full_path);