as of now with out this patch user would see
fsinfo per btrfs mount path but which mean multiple
entry if more than one subvol is mounted of the same
fsid. so this patch will handle that nicely.
v2: accepts Zach suggested
Signed-off-by: Anand Jain
---
cmds-filesystem.c | 90 +
utils.c | 88 ++-
utils.h |3 +-
3 files changed, 130 insertions(+), 51 deletions(-)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index d2cad81..f8e8475 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -317,6 +317,29 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args
*fs_info,
return 0;
}
+static void handle_print(char *mnt, char *label)
+{
+ int fd;
+ struct btrfs_ioctl_fs_info_args fs_info_arg;
+ struct btrfs_ioctl_dev_info_args *dev_info_arg = NULL;
+ struct btrfs_ioctl_space_args *space_info_arg;
+
+ if (get_fs_info(mnt, &fs_info_arg, &dev_info_arg)) {
+ fprintf(stdout, "ERROR: get_fs_info failed\n");
+ return;
+ }
+
+ fd = open(mnt, O_RDONLY);
+ if (fd > 0 && !get_df(fd, &space_info_arg)) {
+ print_one_fs(&fs_info_arg, dev_info_arg,
+ space_info_arg, label, mnt);
+ kfree(space_info_arg);
+ }
+ if (fd > 0)
+ close(fd);
+ kfree(dev_info_arg);
+}
+
/* This function checks if the given input parameter is
* an uuid or a path
* return -1: some error in the given input
@@ -350,47 +373,39 @@ static int check_arg_type(char *input)
static int btrfs_scan_kernel(void *search)
{
- int ret = 0, fd;
- FILE *f;
- struct mntent *mnt;
- struct btrfs_ioctl_fs_info_args fs_info_arg;
- struct btrfs_ioctl_dev_info_args *dev_info_arg = NULL;
- struct btrfs_ioctl_space_args *space_info_arg;
+ int ret = 0;
char label[BTRFS_LABEL_SIZE];
-
- f = setmntent("/proc/self/mounts", "r");
- if (f == NULL)
- return 1;
-
- memset(label, 0, sizeof(label));
- while ((mnt = getmntent(f)) != NULL) {
- if (strcmp(mnt->mnt_type, "btrfs"))
+ char mnt[BTRFS_PATH_NAME_MAX + 1];
+ struct btrfs_ioctl_fslist *fslist;
+ struct btrfs_ioctl_fslist *fslist_saved;
+ u64 cnt_fs;
+ int cnt_mnt;
+ __u8 *fsid;
+ __u64 flags;
+
+ ret = get_fslist(&fslist, &cnt_fs);
+ if (ret)
+ return ret;
+ fslist_saved = fslist;
+ while (cnt_fs--) {
+ fsid = fslist->fsid;
+ flags = fslist->flags;
+ fslist++;
+ if (!(flags & BTRFS_FS_MOUNTED))
continue;
- ret = get_fs_info(mnt->mnt_dir, &fs_info_arg,
- &dev_info_arg);
+ memset(mnt, 0, BTRFS_PATH_NAME_MAX + 1);
+ memset(label, 0, sizeof(label));
+ ret = fsid_to_mntpt(fsid, mnt, &cnt_mnt);
if (ret)
return ret;
-
- if (get_label_mounted(mnt->mnt_dir, label)) {
- kfree(dev_info_arg);
+ if (get_label_mounted(mnt, label))
return 1;
- }
- if (search && !match_search_item_kernel(fs_info_arg.fsid,
- mnt->mnt_dir, label, search)) {
- kfree(dev_info_arg);
+
+ if (search && !match_search_item_kernel(fsid,
+ mnt, label, search))
continue;
- }
- fd = open(mnt->mnt_dir, O_RDONLY);
- if (fd > 0 && !get_df(fd, &space_info_arg)) {
- print_one_fs(&fs_info_arg, dev_info_arg,
- space_info_arg, label, mnt->mnt_dir);
- kfree(space_info_arg);
- memset(label, 0, sizeof(label));
- }
- if (fd > 0)
- close(fd);
- kfree(dev_info_arg);
+ handle_print(mnt, label);
if (search)
return 0;
}
@@ -469,6 +484,13 @@ static int cmd_show(int argc, char **argv)
goto devs_only;
}
}
+ if (type == BTRFS_ARG_MNTPOINT) {
+ char label[BTRFS_LABEL_SIZE];
+ if (get_label_mounted(search, label))
+ return 1;
+ handle_print(search, label);
+ return 0;
+ }
}
if (where == BTRFS_SCAN_DEV)
diff --git a/utils.c b/utils.c
index 1798a7c..d466ffa 100644
--- a/utils.c
+++ b/utils.c
@@ -47,6 +47,7 @@
#include "utils.h"
#include "volumes.h"
#include "io