linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 4/6 v2] btrfs-progs: congregate dev scan
Date: Thu, 30 May 2013 11:40:24 +0800	[thread overview]
Message-ID: <1369885226-3640-5-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1369885226-3640-1-git-send-email-anand.jain@oracle.com>

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


  parent reply	other threads:[~2013-05-30  3:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-17 10:54 [PATCH 0/4] a structure for the disks scan for btrfs Anand Jain
2013-05-17 10:54 ` [PATCH 1/4] btrfs-progs: replace filesystem show --all-devices with -d option Anand Jain
2013-05-17 10:54 ` [PATCH 2/4] btrfs-progs: label option in btrfs filesystem show is not coded Anand Jain
2013-05-17 10:54 ` [PATCH 3/4] btrfs-progs: use /dev/mapper to find the btrfs disks Anand Jain
2013-05-17 10:54 ` [PATCH 4/4] btrfs-progs: btrfs_scan_for_fsid doesn't need all the arguments Anand Jain
2013-05-17 11:21 ` [PATCH 0/4] a structure for the disks scan for btrfs Gabriel de Perthuis
2013-05-17 11:25   ` Gabriel de Perthuis
2013-05-18  4:35   ` anand jain
2013-05-30  3:40 ` [PATCH 0/6 v2] btrfs-progs: " Anand Jain
2013-05-30  3:40   ` [PATCH 1/6 v2] btrfs-progs: btrfs_scan_for_fsid doesn't need all the arguments Anand Jain
2013-05-30  3:40   ` [PATCH 2/6 v2] btrfs-progs: label option in btrfs filesystem show is not coded Anand Jain
2013-05-30  3:40   ` [PATCH 3/6 v2] btrfs-progs: update device scan usage Anand Jain
2013-05-30  3:40   ` Anand Jain [this message]
2013-05-31  8:17     ` [PATCH 4/6 v3] btrfs-progs: congregate dev scan Anand Jain
2013-05-30  3:40   ` [PATCH 5/6 v2] btrfs-progs: btrfs_scan_one_dir not to skip links when /dev/mapper is provided Anand Jain
2013-05-30  3:40   ` [PATCH 6/6 v2] btrfs-progs: scan /dev/mapper in filesystem show and device scan Anand Jain

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=1369885226-3640-5-git-send-email-anand.jain@oracle.com \
    --to=anand.jain@oracle.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).