btrfs-progs: congregate dev scan

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>
master
Anand Jain 2013-07-15 13:30:50 +08:00 committed by David Sterba
parent 8f7c5897e9
commit 5333445574
4 changed files with 30 additions and 17 deletions

View 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;

View 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);

22
utils.c
View File

@ -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;
}

View File

@ -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