The idea was to introduce /dev/mapper to find for btrfs disk, However I found first we need to congregate the disk scan procedure at a function so it would help to consistently tune it across the btrfs-progs. As of now both fi show and dev scan use the disks scan they do it on their own. So here it would congregate btrfs-disk scans at the function scan_devs_for_btrfs, adds /dev/mapper to be used to scan for btrfs, and updates its calling functions and few bug fixes. Anand Jain (4): btrfs-progs: replace filesystem show --all-devices with -d option btrfs-progs: label option in btrfs filesystem show is not coded btrfs-progs: use /dev/mapper to find the btrfs disks btrfs-progs: btrfs_scan_for_fsid doesn''t need all the arguments btrfs-find-root.c | 2 +- cmds-device.c | 50 ++++++++++++++++++++++++++++---------------------- cmds-filesystem.c | 38 ++++++++++++++++++++++++-------------- disk-io.c | 2 +- man/btrfs.8.in | 13 +++++++------ utils.c | 45 +++++++++++++++++++++++++++++++++++++-------- utils.h | 4 ++-- 7 files changed, 100 insertions(+), 54 deletions(-) -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-May-17 10:54 UTC
[PATCH 1/4] btrfs-progs: replace filesystem show --all-devices with -d option
The btrfs fi show --all-devices is odd man out as compared to the rest of the command line options with in btrfs-progs. So match it with the btrfs-progs symantics Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-filesystem.c | 18 ++++++++++++++---- man/btrfs.8.in | 6 +++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index f41a72a..6ba27ad 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -232,7 +232,7 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices) } static const char * const cmd_show_usage[] = { - "btrfs filesystem show [--all-devices] [<uuid>|<label>]", + "btrfs filesystem show [-d] [<uuid>|<label>]", "Show the structure of a filesystem", "If no argument is given, structure of all present filesystems is shown.", NULL @@ -248,9 +248,19 @@ static int cmd_show(int argc, char **argv) int checklist = 1; int searchstart = 1; - if( argc > 1 && !strcmp(argv[1],"--all-devices")){ - checklist = 0; - searchstart += 1; + optind = 1; + while(1) { + int c = getopt(argc, argv, "d"); + if (c < 0) + break; + switch(c) { + case ''d'': + checklist = 0; + searchstart += 1; + break; + default: + usage(cmd_show_usage); + } } if (check_argc_max(argc, searchstart + 1)) diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 9b1f294..3d05862 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -31,7 +31,7 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP .PP -\fBbtrfs\fP \fBfilesystem show\fP\fI [--all-devices|<uuid>|<label>]\fP +\fBbtrfs\fP \fBfilesystem show\fP\fI [-d] [<uuid>|<label>]\fP .PP \fBbtrfs\fP \fBfilesystem balance\fP\fI <path> \fP .PP @@ -282,10 +282,10 @@ NOTE: Currently there are the following limitations: - the filesystem should not have more than one device. .TP -\fBfilesystem show\fR [--all-devices|<uuid>|<label>]\fR +\fBfilesystem show\fR [-d] [<uuid>|<label>]\fR Show the btrfs filesystem with some additional info. If no \fIUUID\fP or \fIlabel\fP is passed, \fBbtrfs\fR show info of all the btrfs filesystem. -If \fB--all-devices\fP is passed, all the devices under /dev are scanned; +If \fB-d\fP is passed, all the devices under /dev are scanned; otherwise the devices list is extracted from the /proc/partitions file. .TP -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-May-17 10:54 UTC
[PATCH 2/4] btrfs-progs: label option in btrfs filesystem show is not coded
So update the usage and man page Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-filesystem.c | 2 +- man/btrfs.8.in | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 6ba27ad..470de31 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -232,7 +232,7 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices) } static const char * const cmd_show_usage[] = { - "btrfs filesystem show [-d] [<uuid>|<label>]", + "btrfs filesystem show [-d] [<uuid>]", "Show the structure of a filesystem", "If no argument is given, structure of all present filesystems is shown.", NULL diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 3d05862..8105019 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -31,7 +31,7 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP .PP -\fBbtrfs\fP \fBfilesystem show\fP\fI [-d] [<uuid>|<label>]\fP +\fBbtrfs\fP \fBfilesystem show\fP\fI [-d] [<uuid>]\fP .PP \fBbtrfs\fP \fBfilesystem balance\fP\fI <path> \fP .PP @@ -282,9 +282,9 @@ NOTE: Currently there are the following limitations: - the filesystem should not have more than one device. .TP -\fBfilesystem show\fR [-d] [<uuid>|<label>]\fR -Show the btrfs filesystem with some additional info. If no \fIUUID\fP or -\fIlabel\fP is passed, \fBbtrfs\fR show info of all the btrfs filesystem. +\fBfilesystem show\fR [-d] [<uuid>]\fR +Show the btrfs filesystem with some additional info. If no \fIUUID\fP +is passed, \fBbtrfs\fR show info of all the btrfs filesystem. If \fB-d\fP is passed, all the devices under /dev are scanned; otherwise the devices list is extracted from the /proc/partitions file. .TP -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-May-17 10:54 UTC
[PATCH 3/4] btrfs-progs: use /dev/mapper to find the btrfs disks
Currently, btrsf fi show uses /proc/partitions (by default) (with priority given to dm-<x> over sd<y> paths) and with -d option would scan /dev only (with /dev/mapper skipped since its a link). However using /dev/mapper paths are in common practice with mount, fstab, and lvm, so its better to be consistent with them. This patch uses the /dev/mapper on top of scanning /proc/partitions and updates paths with /dev/mapper paths where available (which takes care if some of the disks is under blacklist). Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-device.c | 50 ++++++++++++++++++++++++++++---------------------- cmds-filesystem.c | 24 ++++++++++++------------ man/btrfs.8.in | 5 +++-- utils.c | 33 ++++++++++++++++++++++++++++++--- utils.h | 1 + 5 files changed, 74 insertions(+), 39 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index 41e79d3..e3b80d6 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -178,50 +178,56 @@ static int cmd_rm_dev(int argc, char **argv) } static const char * const cmd_scan_dev_usage[] = { - "btrfs device scan [<device>...]", + "btrfs device scan [-d|<device>...]", "Scan devices for a btrfs filesystem", + "\t -d use /dev to scan (skips /dev/mapper)\n" + "\t<device> use only this disk/dev/file to scan for btrfs", NULL }; static int cmd_scan_dev(int argc, char **argv) { - int i, fd, e; - int checklist = 1; - int devstart = 1; + int i, fd, e; + int checklist = 0; + int searchstart = 1; + int ret; - if( argc > 1 && !strcmp(argv[1],"--all-devices")){ - if (check_argc_max(argc, 2)) + optind = 1; + while(1) { + int c = getopt(argc, argv, "d"); + if (c < 0) + break; + switch(c) { + case ''d'': + checklist = 2; + searchstart += 1; + break; + default: usage(cmd_scan_dev_usage); - - checklist = 0; - devstart += 1; + } } - if(argc<=devstart){ - - int ret; + if (argc == searchstart) { - printf("Scanning for Btrfs filesystems\n"); - if(checklist) - ret = btrfs_scan_block_devices(1); - else - ret = btrfs_scan_one_dir("/dev", 1); - if (ret){ - fprintf(stderr, "ERROR: error %d while scanning\n", ret); + ret = scan_devs_for_btrfs(checklist, 1); + if (ret) { + fprintf(stderr, "ERROR: while scanning - %s\n", + strerror(-ret)); return 18; } return 0; } + if (checklist != 0) + usage(cmd_scan_dev_usage); + fd = open("/dev/btrfs-control", O_RDWR); if (fd < 0) { perror("failed to open /dev/btrfs-control"); return 10; } - - for( i = devstart ; i < argc ; i++ ){ + for (i = searchstart; i < argc; i++) { struct btrfs_ioctl_vol_args args; - int ret; printf("Scanning for Btrfs filesystems in ''%s''\n", argv[i]); diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 470de31..43a222b 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -232,9 +232,12 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices) } static const char * const cmd_show_usage[] = { - "btrfs filesystem show [-d] [<uuid>]", + "btrfs filesystem show [-d|<fsid>]", "Show the structure of a filesystem", - "If no argument is given, structure of all present filesystems is shown.", + "\tIf no argument is given, structure of all present filesystems is shown\n" + "\tIf no option is given, scans /proc/partitions and /dev/mapper\n" + "\t -d scans /dev only (does not pick /dev/mapper though)\n" + "\t<fsid> shows structure of the filesystem", NULL }; @@ -244,8 +247,8 @@ static int cmd_show(int argc, char **argv) struct btrfs_fs_devices *fs_devices; struct list_head *cur_uuid; char *search = 0; - int ret; - int checklist = 1; + int ret = 0; + int checklist = 0; int searchstart = 1; optind = 1; @@ -255,7 +258,7 @@ static int cmd_show(int argc, char **argv) break; switch(c) { case ''d'': - checklist = 0; + checklist = 2; searchstart += 1; break; default: @@ -266,16 +269,13 @@ static int cmd_show(int argc, char **argv) if (check_argc_max(argc, searchstart + 1)) usage(cmd_show_usage); - if(checklist) - ret = btrfs_scan_block_devices(0); - else - ret = btrfs_scan_one_dir("/dev", 0); - + ret = scan_devs_for_btrfs(checklist, 0); if (ret){ - fprintf(stderr, "ERROR: error %d while scanning\n", ret); + fprintf(stderr, "ERROR: while scanning - %s\n", + strerror(-ret)); return 18; } - + if(searchstart < argc) search = argv[searchstart]; diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 8105019..9a68246 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -282,11 +282,12 @@ NOTE: Currently there are the following limitations: - the filesystem should not have more than one device. .TP -\fBfilesystem show\fR [-d] [<uuid>]\fR +\fBfilesystem show\fR [-d|m] [<uuid>]\fR Show the btrfs filesystem with some additional info. If no \fIUUID\fP is passed, \fBbtrfs\fR show info of all the btrfs filesystem. If \fB-d\fP is passed, all the devices under /dev are scanned; -otherwise the devices list is extracted from the /proc/partitions file. +otherwise the devices list is extracted from the /proc/partitions +and /dev/mapper. .TP \fBfilesystem balance\fR \fI<path>\fR diff --git a/utils.c b/utils.c index 7b4cd74..663670b 100644 --- a/utils.c +++ b/utils.c @@ -1018,6 +1018,7 @@ int btrfs_scan_one_dir(char *dirname, int run_ioctl) struct list_head pending_list; struct btrfs_fs_devices *tmp_devices; u64 num_devices; + int skip_link = 1; INIT_LIST_HEAD(&pending_list); @@ -1026,6 +1027,9 @@ int btrfs_scan_one_dir(char *dirname, int run_ioctl) return -ENOMEM; strcpy(pending->name, dirname); + if (!strncmp(dirname, "/dev/mapper", strlen("/dev/mapper"))) + skip_link = 0; + again: dirname_len = strlen(pending->name); fullpath = malloc(PATH_MAX); @@ -1057,7 +1061,7 @@ again: fprintf(stderr, "failed to stat %s\n", fullpath); continue; } - if (S_ISLNK(st.st_mode)) + if (skip_link && S_ISLNK(st.st_mode)) continue; if (S_ISDIR(st.st_mode)) { struct pending_dir *next = malloc(sizeof(*next)); @@ -1068,9 +1072,9 @@ again: strcpy(next->name, fullpath); list_add_tail(&next->list, &pending_list); } - if (!S_ISBLK(st.st_mode)) { + if (skip_link && !S_ISBLK(st.st_mode)) continue; - } + fd = open(fullpath, O_RDONLY); if (fd < 0) { /* ignore the following errors: @@ -1807,3 +1811,26 @@ int test_dev_for_mkfs(char *file, int force_overwrite, char *estr) close(fd); return 0; } + +int scan_devs_for_btrfs(int where, int update_kernel) +{ + int ret = 0; + + switch (where) { + case 0: + ret = btrfs_scan_block_devices(update_kernel); + + /* /dev/mapper unified path is most + * prefered if enabled for disks, + * so use it which would replace the + * disks found in above + */ + if (!ret) + btrfs_scan_one_dir("/dev/mapper", update_kernel); + break; + case 2: + ret = btrfs_scan_one_dir("/dev", update_kernel); + break; + } + return ret; +} diff --git a/utils.h b/utils.h index 3c17e14..375c15a 100644 --- a/utils.h +++ b/utils.h @@ -65,5 +65,6 @@ u64 btrfs_device_size(int fd, struct stat *st); /* Helper to always get proper size of the destination string */ #define strncpy_null(dest, src) __strncpy__null(dest, src, sizeof(dest)) int test_dev_for_mkfs(char *file, int force_overwrite, char *estr); +int scan_devs_for_btrfs(int where, int update_kernel); #endif -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-May-17 10:54 UTC
[PATCH 4/4] btrfs-progs: btrfs_scan_for_fsid doesn''t need all the arguments
btrfs_scan_for_fsid uses only one argument run_ioctl out of 3 so remove the rest two of them and also update to use the new function scan_devs_for_btrfs Signed-off-by: Anand Jain <anand.jain@oracle.com> --- btrfs-find-root.c | 2 +- disk-io.c | 2 +- utils.c | 12 +++++++----- utils.h | 3 +-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/btrfs-find-root.c b/btrfs-find-root.c index 810d835..e736cb5 100644 --- a/btrfs-find-root.c +++ b/btrfs-find-root.c @@ -110,7 +110,7 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device) } if (total_devs != 1) { - ret = btrfs_scan_for_fsid(fs_devices, total_devs, 1); + ret = btrfs_scan_for_fsid(1); if (ret) goto out; } diff --git a/disk-io.c b/disk-io.c index 21b410d..574cca9 100644 --- a/disk-io.c +++ b/disk-io.c @@ -835,7 +835,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, } if (total_devs != 1) { - ret = btrfs_scan_for_fsid(fs_devices, total_devs, 1); + ret = btrfs_scan_for_fsid(1); if (ret) goto out; } diff --git a/utils.c b/utils.c index 663670b..18148c7 100644 --- a/utils.c +++ b/utils.c @@ -928,7 +928,7 @@ int check_mounted_where(int fd, const char *file, char *where, int size, /* scan other devices */ if (is_btrfs && total_devs > 1) { - if((ret = btrfs_scan_for_fsid(fs_devices_mnt, total_devs, 1))) + if((ret = btrfs_scan_for_fsid(1))) return ret; } @@ -1114,14 +1114,16 @@ fail: return ret; } -int btrfs_scan_for_fsid(struct btrfs_fs_devices *fs_devices, u64 total_devs, - int run_ioctls) +int btrfs_scan_for_fsid(int run_ioctls) { int ret; - ret = btrfs_scan_block_devices(run_ioctls); + /* try the default (0) fist which will scan /dev/mapper and + * /proc/partitions and then /dev (2) + */ + ret = scan_devs_for_btrfs(0, run_ioctls); if (ret) - ret = btrfs_scan_one_dir("/dev", run_ioctls); + ret = scan_devs_for_btrfs(2, run_ioctls); return ret; } diff --git a/utils.h b/utils.h index 375c15a..b57044a 100644 --- a/utils.h +++ b/utils.h @@ -35,8 +35,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, struct btrfs_root *root, int fd, char *path, u64 block_count, u32 io_width, u32 io_align, u32 sectorsize); -int btrfs_scan_for_fsid(struct btrfs_fs_devices *fs_devices, u64 total_devs, - int run_ioctls); +int btrfs_scan_for_fsid(int run_ioctls); void btrfs_register_one_device(char *fname); int btrfs_scan_one_dir(char *dirname, int run_ioctl); int check_mounted(const char *devicename); -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Gabriel de Perthuis
2013-May-17 11:21 UTC
Re: [PATCH 0/4] a structure for the disks scan for btrfs
On Fri, 17 May 2013 18:54:38 +0800, Anand Jain wrote:> The idea was to introduce /dev/mapper to find for btrfs disk, > However I found first we need to congregate the disk scan > procedure at a function so it would help to consistently tune > it across the btrfs-progs. As of now both fi show and > dev scan use the disks scan they do it on their own. > > So here it would congregate btrfs-disk scans at the function > scan_devs_for_btrfs, adds /dev/mapper to be used to scan > for btrfs, and updates its calling functions and few bug fixes.Just scan /dev/block/*. That contains all block devices. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Gabriel de Perthuis
2013-May-17 11:25 UTC
Re: [PATCH 0/4] a structure for the disks scan for btrfs
> Just scan /dev/block/*. That contains all block devices.Oh, this is about finding nicer names. Never mind. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 17/05/2013 19:21, Gabriel de Perthuis wrote:> On Fri, 17 May 2013 18:54:38 +0800, Anand Jain wrote: >> The idea was to introduce /dev/mapper to find for btrfs disk, >> However I found first we need to congregate the disk scan >> procedure at a function so it would help to consistently tune >> it across the btrfs-progs. As of now both fi show and >> dev scan use the disks scan they do it on their own. >> >> So here it would congregate btrfs-disk scans at the function >> scan_devs_for_btrfs, adds /dev/mapper to be used to scan >> for btrfs, and updates its calling functions and few bug fixes. > > Just scan /dev/block/*. That contains all block devices.That does not help. /dev/mapper has unified dev path, /dev/block/ don''t. when multipath is enabled for a disk, we don''t have to bother to probe its non multipath block path. using /dev/mapper helps in this context. Thanks Anand -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-May-30 03:40 UTC
[PATCH 0/6 v2] btrfs-progs: a structure for the disks scan for btrfs
The idea was to introduce /dev/mapper to find for btrfs disk, However I found first we need to congregate the disk scan procedure at a function so it would help to consistently tune it across the btrfs-progs. As of now both fi show and dev scan use the disks scan they do it on their own. So here it would congregate btrfs-disk scans at the function scan_devs_for_btrfs, adds /dev/mapper to be used to scan for btrfs, and updates its calling functions and few bug fixes. v1->v2: Rebased on top of David'' integration branch origin/integration-20130524 patch 1 to 5 (below) are made independent of the idea to have the /dev/mapper as one of the path to recognize the btrfs disks. Which means they can be installed with out having anything new. It just adds the framework/improves to integrated a /dev/mapper path, which is only done in the patch 6. So patch 1 to 5 are safe. Also in v1 I suggested that we have -d option instead of long option --all-devices which I have dropped that idea here in v2. Patch 6: adds a new option --mapper to the filesystem show and device scan which inturn will use /dev/mapper to scan for the btrfs. Example output of using the --mapper option is as below.. btrfs filesystem show --mapper Label: none uuid: 0a621111-ad84-4d80-842a-dd9c1c60bf51 Total devices 2 FS bytes used 1.17MB devid 1 size 44.99GB used 2.04GB path /dev/mapper/mpathe devid 2 size 48.23GB used 2.03GB path /dev/mapper/mpathd Label: none uuid: bad9105f-bdc6-4626-9ba7-80bd97aebe19 Total devices 1 FS bytes used 28.00KB devid 1 size 15.00GB used 2.04GB path /dev/mapper/mpathbp1 Btrfs v0.20-rc1-350-g7731651 btrfs device scan --mapper ----- [1118885.473298] device fsid bad9105f-bdc6-4626-9ba7-80bd97aebe19 devid 1 transid 4 /dev/mapper/mpathbp1 [1118885.474077] device fsid 0a621111-ad84-4d80-842a-dd9c1c60bf51 devid 2 transid 103 /dev/mapper/mpathd [1118885.474133] device fsid 0a621111-ad84-4d80-842a-dd9c1c60bf51 devid 1 transid 103 /dev/mapper/mpathe ----- Anand Jain (6): btrfs-progs: btrfs_scan_for_fsid doesn''t need all the arguments btrfs-progs: label option in btrfs filesystem show is not coded btrfs-progs: update device scan usage btrfs-progs: congregate dev scan btrfs-progs: btrfs_scan_one_dir not to skip links when /dev/mapper is provided btrfs-progs: scan /dev/mapper in filesystem show and device scan btrfs-find-root.c | 2 +- cmds-device.c | 19 ++++++++++--------- cmds-filesystem.c | 16 ++++++++-------- disk-io.c | 2 +- man/btrfs.8.in | 16 +++++++++------- utils.c | 34 +++++++++++++++++++++++++++++----- utils.h | 9 ++++++--- 7 files changed, 64 insertions(+), 34 deletions(-) -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-May-30 03:40 UTC
[PATCH 1/6 v2] btrfs-progs: btrfs_scan_for_fsid doesn''t need all the arguments
btrfs_scan_for_fsid uses only one argument run_ioctl out of 3 so remove the rest two of them Signed-off-by: Anand Jain <anand.jain@oracle.com> --- btrfs-find-root.c | 2 +- disk-io.c | 2 +- utils.c | 5 ++--- utils.h | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/btrfs-find-root.c b/btrfs-find-root.c index 810d835..e736cb5 100644 --- a/btrfs-find-root.c +++ b/btrfs-find-root.c @@ -110,7 +110,7 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device) } if (total_devs != 1) { - ret = btrfs_scan_for_fsid(fs_devices, total_devs, 1); + ret = btrfs_scan_for_fsid(1); if (ret) goto out; } diff --git a/disk-io.c b/disk-io.c index 9ffe6e4..acd5480 100644 --- a/disk-io.c +++ b/disk-io.c @@ -838,7 +838,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path, } if (total_devs != 1) { - ret = btrfs_scan_for_fsid(fs_devices, total_devs, 1); + ret = btrfs_scan_for_fsid(1); if (ret) goto out; } diff --git a/utils.c b/utils.c index 7b4cd74..25f3cb4 100644 --- a/utils.c +++ b/utils.c @@ -928,7 +928,7 @@ int check_mounted_where(int fd, const char *file, char *where, int size, /* scan other devices */ if (is_btrfs && total_devs > 1) { - if((ret = btrfs_scan_for_fsid(fs_devices_mnt, total_devs, 1))) + if((ret = btrfs_scan_for_fsid(1))) return ret; } @@ -1110,8 +1110,7 @@ fail: return ret; } -int btrfs_scan_for_fsid(struct btrfs_fs_devices *fs_devices, u64 total_devs, - int run_ioctls) +int btrfs_scan_for_fsid(int run_ioctls) { int ret; diff --git a/utils.h b/utils.h index 3c17e14..dba37e8 100644 --- a/utils.h +++ b/utils.h @@ -35,8 +35,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, struct btrfs_root *root, int fd, char *path, u64 block_count, u32 io_width, u32 io_align, u32 sectorsize); -int btrfs_scan_for_fsid(struct btrfs_fs_devices *fs_devices, u64 total_devs, - int run_ioctls); +int btrfs_scan_for_fsid(int run_ioctls); void btrfs_register_one_device(char *fname); int btrfs_scan_one_dir(char *dirname, int run_ioctl); int check_mounted(const char *devicename); -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-May-30 03:40 UTC
[PATCH 2/6 v2] btrfs-progs: label option in btrfs filesystem show is not coded
appears to be a cut and paste error Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-filesystem.c | 2 +- man/btrfs.8.in | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index f41a72a..c6a7100 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -232,7 +232,7 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices) } static const char * const cmd_show_usage[] = { - "btrfs filesystem show [--all-devices] [<uuid>|<label>]", + "btrfs filesystem show [--all-devices|<uuid>]", "Show the structure of a filesystem", "If no argument is given, structure of all present filesystems is shown.", NULL diff --git a/man/btrfs.8.in b/man/btrfs.8.in index 9b1f294..ae984f8 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -31,7 +31,7 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP .PP -\fBbtrfs\fP \fBfilesystem show\fP\fI [--all-devices|<uuid>|<label>]\fP +\fBbtrfs\fP \fBfilesystem show\fP\fI [--all-devices|<uuid>]\fP .PP \fBbtrfs\fP \fBfilesystem balance\fP\fI <path> \fP .PP @@ -282,9 +282,9 @@ NOTE: Currently there are the following limitations: - the filesystem should not have more than one device. .TP -\fBfilesystem show\fR [--all-devices|<uuid>|<label>]\fR -Show the btrfs filesystem with some additional info. If no \fIUUID\fP or -\fIlabel\fP is passed, \fBbtrfs\fR show info of all the btrfs filesystem. +\fBfilesystem show\fR [--all-devices|<uuid>]\fR +Show the btrfs filesystem with some additional info. If no \fIUUID\fP +is passed, \fBbtrfs\fR show info of all the btrfs filesystem. If \fB--all-devices\fP is passed, all the devices under /dev are scanned; otherwise the devices list is extracted from the /proc/partitions file. .TP -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
the btrfs device scan usage does not publish --all-devices option so add it Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds-device.c b/cmds-device.c index 41e79d3..d25159b 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -178,7 +178,7 @@ static int cmd_rm_dev(int argc, char **argv) } static const char * const cmd_scan_dev_usage[] = { - "btrfs device scan [<device>...]", + "btrfs device scan [<--all-devices>|<device> [<device>...]]", "Scan devices for a btrfs filesystem", NULL }; -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
the dev scan to find btrfs is performed at two locations all most the same way one at filesystem show and another at device scan. They both follow the same steps. This patch does not alter anything except that it brings these two same logic into the function scan_for_btrfs so that we can play tweaking it. the patch which recommends to use /dev/mapper will also need it thanks Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-device.c | 11 +++-------- cmds-filesystem.c | 9 +++------ utils.c | 18 ++++++++++++++++++ utils.h | 5 ++++- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index d25159b..b6ecb3b 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -186,26 +186,21 @@ static const char * const cmd_scan_dev_usage[] = { static int cmd_scan_dev(int argc, char **argv) { int i, fd, e; - int checklist = 1; + int where = BTRFS_SCAN_PROC; int devstart = 1; if( argc > 1 && !strcmp(argv[1],"--all-devices")){ if (check_argc_max(argc, 2)) usage(cmd_scan_dev_usage); - checklist = 0; + where = BTRFS_SCAN_DEV; devstart += 1; } if(argc<=devstart){ - int ret; - printf("Scanning for Btrfs filesystems\n"); - if(checklist) - ret = btrfs_scan_block_devices(1); - else - ret = btrfs_scan_one_dir("/dev", 1); + ret = scan_for_btrfs(where, 1); if (ret){ fprintf(stderr, "ERROR: error %d while scanning\n", ret); return 18; diff --git a/cmds-filesystem.c b/cmds-filesystem.c index c6a7100..0d76d58 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -245,21 +245,18 @@ static int cmd_show(int argc, char **argv) struct list_head *cur_uuid; char *search = 0; int ret; - int checklist = 1; + int where = BTRFS_SCAN_PROC; int searchstart = 1; if( argc > 1 && !strcmp(argv[1],"--all-devices")){ - checklist = 0; + where = BTRFS_SCAN_DEV; searchstart += 1; } if (check_argc_max(argc, searchstart + 1)) usage(cmd_show_usage); - if(checklist) - ret = btrfs_scan_block_devices(0); - else - ret = btrfs_scan_one_dir("/dev", 0); + ret = scan_for_btrfs(where, 0); if (ret){ fprintf(stderr, "ERROR: error %d while scanning\n", ret); diff --git a/utils.c b/utils.c index 25f3cb4..f15136b 100644 --- a/utils.c +++ b/utils.c @@ -1806,3 +1806,21 @@ int test_dev_for_mkfs(char *file, int force_overwrite, char *estr) close(fd); return 0; } + +/* + * scans devs for the btrfs +*/ +int scan_for_btrfs(int where, int update_kernel) +{ + int ret = 0; + + switch (where) { + case BTRFS_SCAN_PROC: + ret = btrfs_scan_block_devices(update_kernel); + break; + case BTRFS_SCAN_DEV: + ret = btrfs_scan_one_dir("/dev", update_kernel); + break; + } + return ret; +} diff --git a/utils.h b/utils.h index dba37e8..78f3a65 100644 --- a/utils.h +++ b/utils.h @@ -24,6 +24,9 @@ #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024) +#define BTRFS_SCAN_PROC 1 +#define BTRFS_SCAN_DEV 2 + int make_btrfs(int fd, const char *device, const char *label, u64 blocks[6], u64 num_bytes, u32 nodesize, u32 leafsize, u32 sectorsize, u32 stripesize); @@ -64,5 +67,5 @@ u64 btrfs_device_size(int fd, struct stat *st); /* Helper to always get proper size of the destination string */ #define strncpy_null(dest, src) __strncpy__null(dest, src, sizeof(dest)) int test_dev_for_mkfs(char *file, int force_overwrite, char *estr); - +int scan_for_btrfs(int where, int update_kernel); #endif -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-May-30 03:40 UTC
[PATCH 5/6 v2] btrfs-progs: btrfs_scan_one_dir not to skip links when /dev/mapper is provided
we would need btrfs_scan_one_dir to san devs under /dev/mapper, but /dev/mapper has links to the actual devs and current implementation of btrfs_scan_one_dir skips links so it does not pick any links under /dev/mapper. skipping links is fine when scanning whole of /dev. But when we just want to scan /dev/mapper we want to avoid skipping links otherwise we would be left with nothing. This patch just adds the check if we are scanning devs ONLY under /dev/mapper if when so it will not skip links Thanks Signed-off-by: Anand Jain <anand.jain@oracle.com> --- utils.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils.c b/utils.c index f15136b..6ac7c73 100644 --- a/utils.c +++ b/utils.c @@ -1018,6 +1018,7 @@ int btrfs_scan_one_dir(char *dirname, int run_ioctl) struct list_head pending_list; struct btrfs_fs_devices *tmp_devices; u64 num_devices; + int skip_link = 1; INIT_LIST_HEAD(&pending_list); @@ -1026,6 +1027,9 @@ int btrfs_scan_one_dir(char *dirname, int run_ioctl) return -ENOMEM; strcpy(pending->name, dirname); + if (!strncmp(dirname, "/dev/mapper", strlen("/dev/mapper"))) + skip_link = 0; + again: dirname_len = strlen(pending->name); fullpath = malloc(PATH_MAX); @@ -1057,7 +1061,7 @@ again: fprintf(stderr, "failed to stat %s\n", fullpath); continue; } - if (S_ISLNK(st.st_mode)) + if (skip_link && S_ISLNK(st.st_mode)) continue; if (S_ISDIR(st.st_mode)) { struct pending_dir *next = malloc(sizeof(*next)); @@ -1068,7 +1072,7 @@ again: strcpy(next->name, fullpath); list_add_tail(&next->list, &pending_list); } - if (!S_ISBLK(st.st_mode)) { + if (skip_link && !S_ISBLK(st.st_mode)) { continue; } fd = open(fullpath, O_RDONLY); -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Anand Jain
2013-May-30 03:40 UTC
[PATCH 6/6 v2] btrfs-progs: scan /dev/mapper in filesystem show and device scan
Currently, btrsf fi show and btrfs dev scan uses /proc/partitions (by default) (which gives priority to dm-<x> over sd<y> paths) and with --all-devices it will scan /dev only (when it skips links under /dev/mapper). However using /dev/mapper paths are in common practice with mount, fstab, and lvm, so its better to be consistent with them. This patch adds --mapper option to device scan and filesystem show cli, when used will look for btrfs dev under /dev/mapper and will use the links provided under /dev/mapper. eg: btrfs fi show --mapper Label: none uuid: 0a621111-ad84-4d80-842a-dd9c1c60bf51 Total devices 2 FS bytes used 1.17MB devid 1 size 44.99GB used 2.04GB path /dev/mapper/mpathe devid 2 size 48.23GB used 2.03GB path /dev/mapper/mpathd Label: none uuid: bad9105f-bdc6-4626-9ba7-80bd97aebe19 Total devices 1 FS bytes used 28.00KB devid 1 size 15.00GB used 2.04GB path /dev/mapper/mpathbp1 In the long run I want the usage of /dev/mapper path along with /proc/partitions be the default option to scan for the btrfs devs. /proc/partitions must be scanned as well because to include the mapper blacklisted devs. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-device.c | 8 +++++++- cmds-filesystem.c | 7 +++++-- man/btrfs.8.in | 12 +++++++----- utils.c | 3 +++ utils.h | 5 +++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index b6ecb3b..ef6bc60 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -178,7 +178,7 @@ static int cmd_rm_dev(int argc, char **argv) } static const char * const cmd_scan_dev_usage[] = { - "btrfs device scan [<--all-devices>|<device> [<device>...]]", + "btrfs device scan [<--all-devices>|<--mapper>|<device> [<device>...]]", "Scan devices for a btrfs filesystem", NULL }; @@ -195,6 +195,12 @@ static int cmd_scan_dev(int argc, char **argv) where = BTRFS_SCAN_DEV; devstart += 1; + } else if( argc > 1 && !strcmp(argv[1],"--mapper")){ + if (check_argc_max(argc, 2)) + usage(cmd_scan_dev_usage); + + where = BTRFS_SCAN_MAPPER; + devstart += 1; } if(argc<=devstart){ diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 0d76d58..9b7bcf1 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -232,7 +232,7 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices) } static const char * const cmd_show_usage[] = { - "btrfs filesystem show [--all-devices|<uuid>]", + "btrfs filesystem show [--all-devices|--mapper|<uuid>]", "Show the structure of a filesystem", "If no argument is given, structure of all present filesystems is shown.", NULL @@ -248,9 +248,12 @@ static int cmd_show(int argc, char **argv) int where = BTRFS_SCAN_PROC; int searchstart = 1; - if( argc > 1 && !strcmp(argv[1],"--all-devices")){ + if (argc > 1 && !strcmp(argv[1],"--all-devices")) { where = BTRFS_SCAN_DEV; searchstart += 1; + } else if (argc > 1 && !strcmp(argv[1],"--mapper")) { + where = BTRFS_SCAN_MAPPER; + searchstart += 1; } if (check_argc_max(argc, searchstart + 1)) diff --git a/man/btrfs.8.in b/man/btrfs.8.in index ae984f8..8988b16 100644 --- a/man/btrfs.8.in +++ b/man/btrfs.8.in @@ -31,11 +31,11 @@ btrfs \- control a btrfs filesystem .PP \fBbtrfs\fP \fBfilesystem label\fP\fI <dev> [newlabel]\fP .PP -\fBbtrfs\fP \fBfilesystem show\fP\fI [--all-devices|<uuid>]\fP +\fBbtrfs\fP \fBfilesystem show\fP\fI [--all-devices|--mapper|<uuid>]\fP .PP \fBbtrfs\fP \fBfilesystem balance\fP\fI <path> \fP .PP -\fBbtrfs\fP \fBdevice scan\fP\fI [--all-devices|<device> [<device>...]]\fP +\fBbtrfs\fP \fBdevice scan\fP\fI [--all-devices|--mapper|<device> [<device>...]]\fP .PP \fBbtrfs\fP \fBdevice stats\fP [-z] {\fI<path>\fP|\fI<device>\fP} .PP @@ -282,10 +282,11 @@ NOTE: Currently there are the following limitations: - the filesystem should not have more than one device. .TP -\fBfilesystem show\fR [--all-devices|<uuid>]\fR +\fBfilesystem show\fR [--all-devices|--mapper|<uuid>]\fR Show the btrfs filesystem with some additional info. If no \fIUUID\fP is passed, \fBbtrfs\fR show info of all the btrfs filesystem. If \fB--all-devices\fP is passed, all the devices under /dev are scanned; +If \fB--mapper\fP is passed, all the devices under /dev/mapper are scanned; otherwise the devices list is extracted from the /proc/partitions file. .TP @@ -314,11 +315,12 @@ Add device(s) to the filesystem identified by \fI<path>\fR. Remove device(s) from a filesystem identified by \fI<path>\fR. .TP -\fBdevice scan\fR \fI[--all-devices|<device> [<device>...]\fR +\fBdevice scan\fR \fI[--all-devices|--mapper|<device> [<device>...]\fR If one or more devices are passed, these are scanned for a btrfs filesystem. If no devices are passed, \fBbtrfs\fR scans all the block devices listed in the /proc/partitions file. -Finally, if \fB--all-devices\fP is passed, all the devices under /dev are +If \fB--all-devices\fP is passed, all the devices under /dev are +Finally, if \fB--mapper\fP is passed, all the devices under /dev/mapper are scanned. .TP diff --git a/utils.c b/utils.c index 6ac7c73..afec980 100644 --- a/utils.c +++ b/utils.c @@ -1825,6 +1825,9 @@ int scan_for_btrfs(int where, int update_kernel) case BTRFS_SCAN_DEV: ret = btrfs_scan_one_dir("/dev", update_kernel); break; + case BTRFS_SCAN_MAPPER: + ret = btrfs_scan_one_dir("/dev/mapper", update_kernel); + break; } return ret; } diff --git a/utils.h b/utils.h index 78f3a65..733d13b 100644 --- a/utils.h +++ b/utils.h @@ -24,8 +24,9 @@ #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024) -#define BTRFS_SCAN_PROC 1 -#define BTRFS_SCAN_DEV 2 +#define BTRFS_SCAN_PROC 1 +#define BTRFS_SCAN_DEV 2 +#define BTRFS_SCAN_MAPPER 3 int make_btrfs(int fd, const char *device, const char *label, u64 blocks[6], u64 num_bytes, u32 nodesize, -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
the dev scan to find btrfs is performed at two locations all most the same way one at filesystem show and another at device scan. They both follow the same steps. This patch does not alter anything except that it brings these two same logic into the function scan_for_btrfs so that we can play tweaking it. the patch which recommends to use /dev/mapper will also need it v3: bring in btrfs_scan_for_fsid to use scan_for_btrfs thanks Signed-off-by: Anand Jain <anand.jain@oracle.com> --- cmds-device.c | 11 +++-------- cmds-filesystem.c | 9 +++------ utils.c | 22 ++++++++++++++++++++-- utils.h | 5 ++++- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/cmds-device.c b/cmds-device.c index d25159b..b6ecb3b 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -186,26 +186,21 @@ static const char * const cmd_scan_dev_usage[] = { static int cmd_scan_dev(int argc, char **argv) { int i, fd, e; - int checklist = 1; + int where = BTRFS_SCAN_PROC; int devstart = 1; if( argc > 1 && !strcmp(argv[1],"--all-devices")){ if (check_argc_max(argc, 2)) usage(cmd_scan_dev_usage); - checklist = 0; + where = BTRFS_SCAN_DEV; devstart += 1; } if(argc<=devstart){ - int ret; - printf("Scanning for Btrfs filesystems\n"); - if(checklist) - ret = btrfs_scan_block_devices(1); - else - ret = btrfs_scan_one_dir("/dev", 1); + ret = scan_for_btrfs(where, 1); if (ret){ fprintf(stderr, "ERROR: error %d while scanning\n", ret); return 18; diff --git a/cmds-filesystem.c b/cmds-filesystem.c index c6a7100..0d76d58 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -245,21 +245,18 @@ static int cmd_show(int argc, char **argv) struct list_head *cur_uuid; char *search = 0; int ret; - int checklist = 1; + int where = BTRFS_SCAN_PROC; int searchstart = 1; if( argc > 1 && !strcmp(argv[1],"--all-devices")){ - checklist = 0; + where = BTRFS_SCAN_DEV; searchstart += 1; } if (check_argc_max(argc, searchstart + 1)) usage(cmd_show_usage); - if(checklist) - ret = btrfs_scan_block_devices(0); - else - ret = btrfs_scan_one_dir("/dev", 0); + ret = scan_for_btrfs(where, 0); if (ret){ fprintf(stderr, "ERROR: error %d while scanning\n", ret); diff --git a/utils.c b/utils.c index 25f3cb4..6b2344d 100644 --- a/utils.c +++ b/utils.c @@ -1114,9 +1114,9 @@ int btrfs_scan_for_fsid(int run_ioctls) { int ret; - ret = btrfs_scan_block_devices(run_ioctls); + ret = scan_for_btrfs(BTRFS_SCAN_PROC, run_ioctls); if (ret) - ret = btrfs_scan_one_dir("/dev", run_ioctls); + ret = scan_for_btrfs(BTRFS_SCAN_DEV, run_ioctls); return ret; } @@ -1806,3 +1806,21 @@ int test_dev_for_mkfs(char *file, int force_overwrite, char *estr) close(fd); return 0; } + +/* + * scans devs for the btrfs +*/ +int scan_for_btrfs(int where, int update_kernel) +{ + int ret = 0; + + switch (where) { + case BTRFS_SCAN_PROC: + ret = btrfs_scan_block_devices(update_kernel); + break; + case BTRFS_SCAN_DEV: + ret = btrfs_scan_one_dir("/dev", update_kernel); + break; + } + return ret; +} diff --git a/utils.h b/utils.h index dba37e8..78f3a65 100644 --- a/utils.h +++ b/utils.h @@ -24,6 +24,9 @@ #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024) +#define BTRFS_SCAN_PROC 1 +#define BTRFS_SCAN_DEV 2 + int make_btrfs(int fd, const char *device, const char *label, u64 blocks[6], u64 num_bytes, u32 nodesize, u32 leafsize, u32 sectorsize, u32 stripesize); @@ -64,5 +67,5 @@ u64 btrfs_device_size(int fd, struct stat *st); /* Helper to always get proper size of the destination string */ #define strncpy_null(dest, src) __strncpy__null(dest, src, sizeof(dest)) int test_dev_for_mkfs(char *file, int force_overwrite, char *estr); - +int scan_for_btrfs(int where, int update_kernel); #endif -- 1.8.1.227.g44fe835 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html