From: Omar Sandoval <osandov@osandov.com>
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 [thread overview]
Message-ID: <e663b885b0ff54aa31f5c79841c6d4621a62d41f.1518720598.git.osandov@fb.com> (raw)
In-Reply-To: <cover.1518720598.git.osandov@fb.com>
In-Reply-To: <cover.1518720598.git.osandov@fb.com>
From: Omar Sandoval <osandov@fb.com>
This gets the remaining occurrences that weren't covered by previous
conversions.
Signed-off-by: Omar Sandoval <osandov@fb.com>
---
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 <linux/magic.h>
#include <getopt.h>
+#include <btrfsutil.h>
+
#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);
--
2.16.1
next prev parent reply other threads:[~2018-02-15 19:05 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-15 19:04 [PATCH v2 00/27] btrfs-progs: introduce libbtrfsutil, "btrfs-progs as a library" Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 01/27] btrfs-progs: get rid of undocumented qgroup inheritance options Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 02/27] Add libbtrfsutil Omar Sandoval
2018-02-20 17:32 ` Liu Bo
2018-02-20 18:34 ` David Sterba
2018-02-15 19:04 ` [PATCH v2 03/27] libbtrfsutil: add Python bindings Omar Sandoval
2018-02-21 13:47 ` David Sterba
2018-02-21 18:08 ` Omar Sandoval
2018-02-22 1:44 ` Misono, Tomohiro
2018-02-15 19:04 ` [PATCH v2 04/27] libbtrfsutil: add btrfs_util_is_subvolume() and btrfs_util_subvolume_id() Omar Sandoval
2018-02-21 11:43 ` David Sterba
2018-02-21 13:02 ` David Sterba
2018-02-21 18:13 ` Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 05/27] libbtrfsutil: add qgroup inheritance helpers Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 06/27] libbtrfsutil: add btrfs_util_create_subvolume() Omar Sandoval
2018-02-23 8:24 ` Misono, Tomohiro
2018-02-23 22:58 ` Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 07/27] libbtrfsutil: add btrfs_util_subvolume_path() Omar Sandoval
2018-02-23 6:27 ` Misono, Tomohiro
2018-02-23 22:44 ` Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 08/27] libbtrfsutil: add btrfs_util_subvolume_info() Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 09/27] libbtrfsutil: add btrfs_util_[gs]et_read_only() Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 10/27] libbtrfsutil: add btrfs_util_[gs]et_default_subvolume() Omar Sandoval
2018-02-22 1:55 ` Misono, Tomohiro
2018-02-23 22:40 ` Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 11/27] libbtrfsutil: add subvolume iterator helpers Omar Sandoval
2018-02-23 7:40 ` Misono, Tomohiro
2018-02-23 22:49 ` Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 12/27] libbtrfsutil: add btrfs_util_create_snapshot() Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 13/27] libbtrfsutil: add btrfs_util_delete_subvolume() Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 14/27] libbtrfsutil: add btrfs_util_deleted_subvolumes() Omar Sandoval
2018-02-23 2:12 ` Misono, Tomohiro
2018-02-23 23:33 ` Omar Sandoval
2018-02-28 4:11 ` Misono, Tomohiro
2018-02-15 19:05 ` [PATCH v2 15/27] libbtrfsutil: add filesystem sync helpers Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 16/27] btrfs-progs: use libbtrfsutil for read-only property Omar Sandoval
2018-02-22 4:23 ` Misono, Tomohiro
2018-02-23 22:41 ` Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 17/27] btrfs-progs: use libbtrfsutil for sync ioctls Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 18/27] btrfs-progs: use libbtrfsutil for set-default Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 19/27] btrfs-progs: use libbtrfsutil for get-default Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 20/27] btrfs-progs: use libbtrfsutil for subvol create and snapshot Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 21/27] btrfs-progs: use libbtrfsutil for subvol delete Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 22/27] btrfs-progs: use libbtrfsutil for subvol show Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 23/27] btrfs-progs: use libbtrfsutil for subvol sync Omar Sandoval
2018-02-22 2:03 ` Misono, Tomohiro
2018-02-23 22:41 ` Omar Sandoval
2018-02-23 23:22 ` David Sterba
2018-02-22 2:09 ` Misono, Tomohiro
2018-02-15 19:05 ` Omar Sandoval [this message]
2018-02-15 19:05 ` [PATCH v2 25/27] btrfs-progs: add recursive snapshot/delete using libbtrfsutil Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 26/27] btrfs-progs: use libbtrfsutil for subvolume list Omar Sandoval
2018-02-23 2:26 ` Misono, Tomohiro
2018-02-23 23:05 ` Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 27/27] btrfs-progs: deprecate libbtrfs helpers Omar Sandoval
2018-02-21 15:04 ` David Sterba
2018-02-21 18:19 ` Omar Sandoval
2018-02-20 18:50 ` [PATCH v2 00/27] btrfs-progs: introduce libbtrfsutil, "btrfs-progs as a library" David Sterba
2018-02-21 15:13 ` David Sterba
2018-02-21 18:50 ` Omar Sandoval
2018-02-23 20:28 ` David Sterba
2018-02-26 23:36 ` Omar Sandoval
2018-02-27 15:04 ` David Sterba
2018-02-27 20:48 ` Omar Sandoval
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e663b885b0ff54aa31f5c79841c6d4621a62d41f.1518720598.git.osandov@fb.com \
--to=osandov@osandov.com \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).