btrfs-progs: congregate dev scan
authorAnand Jain <anand.jain@oracle.com>
Mon, 15 Jul 2013 05:30:50 +0000 (13:30 +0800)
committerDavid Sterba <dsterba@suse.cz>
Fri, 9 Aug 2013 12:32:36 +0000 (14:32 +0200)
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

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
cmds-device.c
cmds-filesystem.c
utils.c
utils.h

index 4bbf401..c1dc363 100644 (file)
@@ -188,26 +188,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;
index 945ef2e..982b954 100644 (file)
@@ -233,21 +233,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 011a42a..29252df 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -1135,9 +1135,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;
 }
 
@@ -1835,3 +1835,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 fb9670d..79390cf 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -25,6 +25,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);
@@ -74,5 +77,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