All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d"
@ 2014-09-13  1:21 Anand Jain
  2014-09-13  1:21 ` [PATCH 2/5] btrfs-progs: don't fall back to recursive /dev scan Anand Jain
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Anand Jain @ 2014-09-13  1:21 UTC (permalink / raw)
  To: linux-btrfs

From: Eric Sandeen <sandeen@redhat.com>

We can scan for btrfs devices in a few ways.  By default
libblkid is used for "device scan" and "filesystem show";
with the -m option only mounted filesystems are scanned,
and with -d we physically read every system device.

But there's no reason for the complexity of a descent through
/dev; /proc/partitions has every device known to the kernel, so
just use that when -d is specified.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-device.c     | 2 +-
 cmds-filesystem.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/cmds-device.c b/cmds-device.c
index d7af090..ad0bd35 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -223,7 +223,7 @@ static int cmd_scan_dev(int argc, char **argv)
 			break;
 		switch (c) {
 		case 'd':
-			where = BTRFS_SCAN_DEV;
+			where = BTRFS_SCAN_PROC;
 			all = 1;
 			break;
 		default:
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index d8b6938..818e05f 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -563,7 +563,7 @@ static int cmd_show(int argc, char **argv)
 			break;
 		switch (c) {
 		case 'd':
-			where = BTRFS_SCAN_DEV;
+			where = BTRFS_SCAN_PROC;
 			break;
 		case 'm':
 			where = BTRFS_SCAN_MOUNTED;
@@ -587,7 +587,7 @@ static int cmd_show(int argc, char **argv)
 		 * right away
 		 */
 		if (type == BTRFS_ARG_BLKDEV) {
-			if (where == BTRFS_SCAN_DEV) {
+			if (where == BTRFS_SCAN_PROC) {
 				/* we need to do this because
 				 * legacy BTRFS_SCAN_DEV
 				 * provides /dev/dm-x paths
@@ -618,7 +618,7 @@ static int cmd_show(int argc, char **argv)
 		}
 	}
 
-	if (where == BTRFS_SCAN_DEV)
+	if (where == BTRFS_SCAN_PROC)
 		goto devs_only;
 
 	/* show mounted btrfs */
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/5] btrfs-progs: don't fall back to recursive /dev scan
  2014-09-13  1:21 [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d" Anand Jain
@ 2014-09-13  1:21 ` Anand Jain
  2014-09-13  1:21 ` [PATCH 3/5] btrfs-progs: remove BTRFS_SCAN_DEV and btrfs_scan_one_dir Anand Jain
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Anand Jain @ 2014-09-13  1:21 UTC (permalink / raw)
  To: linux-btrfs

From: Eric Sandeen <sandeen@redhat.com>

If we didn't find what we are looking for in /proc/partitions,
we're not going to find it by scanning every node under /dev, either.

But that's just what btrfs_scan_for_fsid() does.

Remove that fallback; at that point btrfs_scan_for_fsid() just calls
scan_for_btrfs(), so remove the wrapper & call it directly.

Side note: so, these paths always use /proc/partitions, not libblkid.
Userspace-intiated scans default to libblkid.  I presume this is
part of the design, and intentional?  Anyway, not changing it now!

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
---
 disk-io.c |  2 +-
 utils.c   | 12 +-----------
 2 files changed, 2 insertions(+), 12 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index f71f5ca..2a1f6d4 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1007,7 +1007,7 @@ int btrfs_scan_fs_devices(int fd, const char *path,
 	}
 
 	if (total_devs != 1) {
-		ret = btrfs_scan_for_fsid(run_ioctl);
+		ret = scan_for_btrfs(BTRFS_SCAN_PROC, run_ioctl);
 		if (ret)
 			return ret;
 	}
diff --git a/utils.c b/utils.c
index 0064587..cf7635c 100644
--- a/utils.c
+++ b/utils.c
@@ -1148,7 +1148,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(!BTRFS_UPDATE_KERNEL)))
+		if ((ret = scan_for_btrfs(BTRFS_SCAN_PROC, !BTRFS_UPDATE_KERNEL)))
 			return ret;
 	}
 
@@ -1336,16 +1336,6 @@ fail:
 	return ret;
 }
 
-int btrfs_scan_for_fsid(int run_ioctls)
-{
-	int ret;
-
-	ret = scan_for_btrfs(BTRFS_SCAN_PROC, run_ioctls);
-	if (ret)
-		ret = scan_for_btrfs(BTRFS_SCAN_DEV, run_ioctls);
-	return ret;
-}
-
 int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
 				 int super_offset)
 {
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/5] btrfs-progs: remove BTRFS_SCAN_DEV and btrfs_scan_one_dir
  2014-09-13  1:21 [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d" Anand Jain
  2014-09-13  1:21 ` [PATCH 2/5] btrfs-progs: don't fall back to recursive /dev scan Anand Jain
@ 2014-09-13  1:21 ` Anand Jain
  2014-09-13  1:21 ` [PATCH 4/5] btrfs-progs: remove BTRFS_SCAN_PROC scan method Anand Jain
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Anand Jain @ 2014-09-13  1:21 UTC (permalink / raw)
  To: linux-btrfs

From: Eric Sandeen <sandeen@redhat.com>

After the previous 2 patches, nothing uses
whole-dev-tree scanning, so remove the code which
implemented that functionality.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
---
 utils.c | 114 ----------------------------------------------------------------
 utils.h |   6 ++--
 2 files changed, 2 insertions(+), 118 deletions(-)

diff --git a/utils.c b/utils.c
index cf7635c..901127f 100644
--- a/utils.c
+++ b/utils.c
@@ -1225,117 +1225,6 @@ void btrfs_register_one_device(char *fname)
 	close(fd);
 }
 
-int btrfs_scan_one_dir(char *dirname, int run_ioctl)
-{
-	DIR *dirp = NULL;
-	struct dirent *dirent;
-	struct pending_dir *pending;
-	struct stat st;
-	int ret;
-	int fd;
-	int dirname_len;
-	char *fullpath;
-	struct list_head pending_list;
-	struct btrfs_fs_devices *tmp_devices;
-	u64 num_devices;
-
-	INIT_LIST_HEAD(&pending_list);
-
-	pending = malloc(sizeof(*pending));
-	if (!pending)
-		return -ENOMEM;
-	strcpy(pending->name, dirname);
-
-again:
-	dirname_len = strlen(pending->name);
-	fullpath = malloc(PATH_MAX);
-	dirname = pending->name;
-
-	if (!fullpath) {
-		ret = -ENOMEM;
-		goto fail;
-	}
-	dirp = opendir(dirname);
-	if (!dirp) {
-		fprintf(stderr, "Unable to open %s for scanning\n", dirname);
-		ret = -errno;
-		goto fail;
-	}
-	while(1) {
-		dirent = readdir(dirp);
-		if (!dirent)
-			break;
-		if (dirent->d_name[0] == '.')
-			continue;
-		if (dirname_len + strlen(dirent->d_name) + 2 > PATH_MAX) {
-			ret = -EFAULT;
-			goto fail;
-		}
-		snprintf(fullpath, PATH_MAX, "%s/%s", dirname, dirent->d_name);
-		ret = lstat(fullpath, &st);
-		if (ret < 0) {
-			fprintf(stderr, "failed to stat %s\n", fullpath);
-			continue;
-		}
-		if (S_ISLNK(st.st_mode))
-			continue;
-		if (S_ISDIR(st.st_mode)) {
-			struct pending_dir *next = malloc(sizeof(*next));
-			if (!next) {
-				ret = -ENOMEM;
-				goto fail;
-			}
-			strcpy(next->name, fullpath);
-			list_add_tail(&next->list, &pending_list);
-		}
-		if (!S_ISBLK(st.st_mode)) {
-			continue;
-		}
-		fd = open(fullpath, O_RDONLY);
-		if (fd < 0) {
-			/* ignore the following errors:
-				ENXIO (device don't exists) 
-				ENOMEDIUM (No medium found -> 
-					like a cd tray empty)
-			*/
-			if(errno != ENXIO && errno != ENOMEDIUM) 
-				fprintf(stderr, "failed to read %s: %s\n", 
-					fullpath, strerror(errno));
-			continue;
-		}
-		ret = btrfs_scan_one_device(fd, fullpath, &tmp_devices,
-					    &num_devices,
-					    BTRFS_SUPER_INFO_OFFSET, 0);
-		if (ret == 0 && run_ioctl > 0) {
-			btrfs_register_one_device(fullpath);
-		}
-		close(fd);
-	}
-	if (!list_empty(&pending_list)) {
-		free(pending);
-		pending = list_entry(pending_list.next, struct pending_dir,
-				     list);
-		free(fullpath);
-		list_del(&pending->list);
-		closedir(dirp);
-		dirp = NULL;
-		goto again;
-	}
-	ret = 0;
-fail:
-	free(pending);
-	free(fullpath);
-	while (!list_empty(&pending_list)) {
-		pending = list_entry(pending_list.next, struct pending_dir,
-				     list);
-		list_del(&pending->list);
-		free(pending);
-	}
-	if (dirp)
-		closedir(dirp);
-	return ret;
-}
-
 int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
 				 int super_offset)
 {
@@ -2247,9 +2136,6 @@ int scan_for_btrfs(int where, int update_kernel)
 	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;
 	case BTRFS_SCAN_LBLKID:
 		ret = btrfs_scan_lblkid(update_kernel);
 		break;
diff --git a/utils.h b/utils.h
index 26c767b..52a9dfc 100644
--- a/utils.h
+++ b/utils.h
@@ -27,9 +27,8 @@
 #define BTRFS_MKFS_SMALL_VOLUME_SIZE (1024 * 1024 * 1024)
 
 #define BTRFS_SCAN_PROC		(1ULL << 0)
-#define BTRFS_SCAN_DEV		(1ULL << 1)
-#define BTRFS_SCAN_MOUNTED	(1ULL << 2)
-#define BTRFS_SCAN_LBLKID	(1ULL << 3)
+#define BTRFS_SCAN_MOUNTED	(1ULL << 1)
+#define BTRFS_SCAN_LBLKID	(1ULL << 2)
 
 #define BTRFS_UPDATE_KERNEL	1
 
@@ -62,7 +61,6 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
 		      u32 sectorsize);
 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);
 char *canonicalize_dm_name(const char *ptname);
 char *canonicalize_path(const char *path);
 int check_mounted(const char *devicename);
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/5] btrfs-progs: remove BTRFS_SCAN_PROC scan method
  2014-09-13  1:21 [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d" Anand Jain
  2014-09-13  1:21 ` [PATCH 2/5] btrfs-progs: don't fall back to recursive /dev scan Anand Jain
  2014-09-13  1:21 ` [PATCH 3/5] btrfs-progs: remove BTRFS_SCAN_DEV and btrfs_scan_one_dir Anand Jain
@ 2014-09-13  1:21 ` Anand Jain
  2014-10-07  0:08   ` [PATCH] btrfs-progs: btrfs_scan_block_devices is unused function delete it Anand Jain
  2014-09-13  1:21 ` [PATCH 5/5] btrfs-progs: remove scan_for_btrfs() Anand Jain
  2014-09-23 17:00 ` [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d" David Sterba
  4 siblings, 1 reply; 11+ messages in thread
From: Anand Jain @ 2014-09-13  1:21 UTC (permalink / raw)
  To: linux-btrfs

The libblkid scan method which was introduced later, will also
scan devices under /proc/partitions. So we don't have to do
the explicit scan of the same.

Remove the scan method BTRFS_SCAN_PROC.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 cmds-device.c     |  5 ++---
 cmds-filesystem.c | 10 +++++-----
 disk-io.c         |  2 +-
 utils.c           |  5 +----
 utils.h           |  5 ++---
 5 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/cmds-device.c b/cmds-device.c
index ad0bd35..86787a4 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -199,13 +199,13 @@ static int cmd_rm_dev(int argc, char **argv)
 static const char * const cmd_scan_dev_usage[] = {
 	"btrfs device scan [(-d|--all-devices)|<device> [<device>...]]",
 	"Scan devices for a btrfs filesystem",
+	" -d|--all-devices (deprecated)",
 	NULL
 };
 
 static int cmd_scan_dev(int argc, char **argv)
 {
 	int i, fd, e;
-	int where = BTRFS_SCAN_LBLKID;
 	int devstart = 1;
 	int all = 0;
 	int ret = 0;
@@ -223,7 +223,6 @@ static int cmd_scan_dev(int argc, char **argv)
 			break;
 		switch (c) {
 		case 'd':
-			where = BTRFS_SCAN_PROC;
 			all = 1;
 			break;
 		default:
@@ -236,7 +235,7 @@ static int cmd_scan_dev(int argc, char **argv)
 
 	if (all || argc == 1) {
 		printf("Scanning for Btrfs filesystems\n");
-		ret = scan_for_btrfs(where, BTRFS_UPDATE_KERNEL);
+		ret = btrfs_scan_lblkid(BTRFS_UPDATE_KERNEL);
 		if (ret)
 			fprintf(stderr, "ERROR: error %d while scanning\n", ret);
 		goto out;
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 818e05f..ebaccca 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -542,7 +542,7 @@ static int cmd_show(int argc, char **argv)
 	struct list_head *cur_uuid;
 	char *search = NULL;
 	int ret;
-	int where = BTRFS_SCAN_LBLKID;
+	int where = -1; // default, search both kernel and udev
 	int type = 0;
 	char mp[BTRFS_PATH_NAME_MAX + 1];
 	char path[PATH_MAX];
@@ -563,7 +563,7 @@ static int cmd_show(int argc, char **argv)
 			break;
 		switch (c) {
 		case 'd':
-			where = BTRFS_SCAN_PROC;
+			where = BTRFS_SCAN_LBLKID;
 			break;
 		case 'm':
 			where = BTRFS_SCAN_MOUNTED;
@@ -587,7 +587,7 @@ static int cmd_show(int argc, char **argv)
 		 * right away
 		 */
 		if (type == BTRFS_ARG_BLKDEV) {
-			if (where == BTRFS_SCAN_PROC) {
+			if (where == BTRFS_SCAN_LBLKID) {
 				/* we need to do this because
 				 * legacy BTRFS_SCAN_DEV
 				 * provides /dev/dm-x paths
@@ -618,7 +618,7 @@ static int cmd_show(int argc, char **argv)
 		}
 	}
 
-	if (where == BTRFS_SCAN_PROC)
+	if (where == BTRFS_SCAN_LBLKID)
 		goto devs_only;
 
 	/* show mounted btrfs */
@@ -633,7 +633,7 @@ static int cmd_show(int argc, char **argv)
 		goto out;
 
 devs_only:
-	ret = scan_for_btrfs(where, !BTRFS_UPDATE_KERNEL);
+	ret = btrfs_scan_lblkid(!BTRFS_UPDATE_KERNEL);
 
 	if (ret) {
 		fprintf(stderr, "ERROR: %d while scanning\n", ret);
diff --git a/disk-io.c b/disk-io.c
index 2a1f6d4..bb011d0 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1007,7 +1007,7 @@ int btrfs_scan_fs_devices(int fd, const char *path,
 	}
 
 	if (total_devs != 1) {
-		ret = scan_for_btrfs(BTRFS_SCAN_PROC, run_ioctl);
+		ret = btrfs_scan_lblkid(run_ioctl);
 		if (ret)
 			return ret;
 	}
diff --git a/utils.c b/utils.c
index 901127f..7c1e48b 100644
--- a/utils.c
+++ b/utils.c
@@ -1148,7 +1148,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 = scan_for_btrfs(BTRFS_SCAN_PROC, !BTRFS_UPDATE_KERNEL)))
+		if ((ret = btrfs_scan_lblkid(!BTRFS_UPDATE_KERNEL)))
 			return ret;
 	}
 
@@ -2133,9 +2133,6 @@ 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_LBLKID:
 		ret = btrfs_scan_lblkid(update_kernel);
 		break;
diff --git a/utils.h b/utils.h
index 52a9dfc..ea0d5d4 100644
--- a/utils.h
+++ b/utils.h
@@ -26,9 +26,8 @@
 #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
 #define BTRFS_MKFS_SMALL_VOLUME_SIZE (1024 * 1024 * 1024)
 
-#define BTRFS_SCAN_PROC		(1ULL << 0)
-#define BTRFS_SCAN_MOUNTED	(1ULL << 1)
-#define BTRFS_SCAN_LBLKID	(1ULL << 2)
+#define BTRFS_SCAN_MOUNTED	(1ULL << 0)
+#define BTRFS_SCAN_LBLKID	(1ULL << 1)
 
 #define BTRFS_UPDATE_KERNEL	1
 
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/5] btrfs-progs: remove scan_for_btrfs()
  2014-09-13  1:21 [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d" Anand Jain
                   ` (2 preceding siblings ...)
  2014-09-13  1:21 ` [PATCH 4/5] btrfs-progs: remove BTRFS_SCAN_PROC scan method Anand Jain
@ 2014-09-13  1:21 ` Anand Jain
  2014-09-23 17:00 ` [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d" David Sterba
  4 siblings, 0 replies; 11+ messages in thread
From: Anand Jain @ 2014-09-13  1:21 UTC (permalink / raw)
  To: linux-btrfs

With the changes as in the previous patch, now scan_for_btrfs()
is an unused function. So delete it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 utils.c | 15 ---------------
 utils.h |  1 -
 2 files changed, 16 deletions(-)

diff --git a/utils.c b/utils.c
index 7c1e48b..38d867d 100644
--- a/utils.c
+++ b/utils.c
@@ -2125,21 +2125,6 @@ int btrfs_scan_lblkid(int update_kernel)
 	return 0;
 }
 
-/*
- * scans devs for the btrfs
-*/
-int scan_for_btrfs(int where, int update_kernel)
-{
-	int ret = 0;
-
-	switch (where) {
-	case BTRFS_SCAN_LBLKID:
-		ret = btrfs_scan_lblkid(update_kernel);
-		break;
-	}
-	return ret;
-}
-
 int is_vol_small(char *file)
 {
 	int fd = -1;
diff --git a/utils.h b/utils.h
index ea0d5d4..b639bb6 100644
--- a/utils.h
+++ b/utils.h
@@ -100,7 +100,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_for_btrfs(int where, int update_kernel);
 int get_label_mounted(const char *mount_path, char *labelp);
 int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
 	u64 dev_cnt, int mixed, char *estr);
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d"
  2014-09-13  1:21 [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d" Anand Jain
                   ` (3 preceding siblings ...)
  2014-09-13  1:21 ` [PATCH 5/5] btrfs-progs: remove scan_for_btrfs() Anand Jain
@ 2014-09-23 17:00 ` David Sterba
  2014-10-06  9:31   ` Anand Jain
  4 siblings, 1 reply; 11+ messages in thread
From: David Sterba @ 2014-09-23 17:00 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs, guihc.fnst, sandeen

Hi,

all 5 patches will be in the next integration. I haven't tested them
yet, seems it's a bit more important to make a more stable devel base
for more updates you might want to send.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d"
  2014-09-23 17:00 ` [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d" David Sterba
@ 2014-10-06  9:31   ` Anand Jain
  2014-10-23 13:12     ` Anand Jain
  0 siblings, 1 reply; 11+ messages in thread
From: Anand Jain @ 2014-10-06  9:31 UTC (permalink / raw)
  To: dsterba, linux-btrfs, guihc.fnst, sandeen



  I am running some tests with larger disks pool (48 disks).
  With that the performance of the various scan methods are as below..

----
scanning BTRFS_SCAN_LBLKID
real    0m0.330s
user    0m0.005s
sys     0m0.026s

scanning BTRFS_SCAN_DEV
real    0m0.010s
user    0m0.002s
sys     0m0.005s

scanning BTRFS_SCAN_PROC
real    0m0.010s
user    0m0.002s
sys     0m0.005s
-----

  This is the time taken to scan 48disks one time by various methods
  we have/had - but our progs do this scan 30times for btrfs fi show.
  yep 30times as show below.. I am working to fix it.

-------
                                 Function: time(us)    count  avg(us)
::
                          get_device_info:     1034       27       38
                     pretty_size_snprintf:     1218      124        9
                    btrfs_scan_one_device:     1790      186        9
                     btrfs_read_dev_super:     1956      116       16
                                 cmd_show:    15418      335       46
                        btrfs_scan_lblkid:   148477       30     4949
-------

  IMO we should still stick to LBLKID scan.
  Just a thought - any idea if its better to provide a compile time
  fallback scan switch, just in case if something fails with lblkid. ?


Thanks, Anand


On 09/24/14 01:00, David Sterba wrote:
> Hi,
>
> all 5 patches will be in the next integration. I haven't tested them
> yet, seems it's a bit more important to make a more stable devel base
> for more updates you might want to send.
> --
> 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
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] btrfs-progs: btrfs_scan_block_devices is unused function delete it
  2014-09-13  1:21 ` [PATCH 4/5] btrfs-progs: remove BTRFS_SCAN_PROC scan method Anand Jain
@ 2014-10-07  0:08   ` Anand Jain
  2014-10-22 11:10     ` Anand Jain
  2015-05-05 16:54     ` David Sterba
  0 siblings, 2 replies; 11+ messages in thread
From: Anand Jain @ 2014-10-07  0:08 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba

After Patch:
 remove BTRFS_SCAN_PROC scan method
There isn't any consumer for btrfs_scan_block_devices() so delete it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 utils.c | 83 -----------------------------------------------------------------
 utils.h |  1 -
 2 files changed, 84 deletions(-)

diff --git a/utils.c b/utils.c
index 48d2d9a..b23f332 100644
--- a/utils.c
+++ b/utils.c
@@ -1542,89 +1542,6 @@ int set_label(const char *btrfs_dev, const char *label)
 	return ret;
 }
 
-int btrfs_scan_block_devices(int run_ioctl)
-{
-
-	struct stat st;
-	int ret;
-	int fd;
-	struct btrfs_fs_devices *tmp_devices;
-	u64 num_devices;
-	FILE *proc_partitions;
-	int i;
-	char buf[1024];
-	char fullpath[110];
-	int scans = 0;
-	int special;
-
-scan_again:
-	proc_partitions = fopen("/proc/partitions","r");
-	if (!proc_partitions) {
-		fprintf(stderr, "Unable to open '/proc/partitions' for scanning\n");
-		return -ENOENT;
-	}
-	/* skip the header */
-	for (i = 0; i < 2; i++)
-		if (!fgets(buf, 1023, proc_partitions)) {
-			fprintf(stderr,
-				"Unable to read '/proc/partitions' for scanning\n");
-			fclose(proc_partitions);
-			return -ENOENT;
-		}
-
-	strcpy(fullpath,"/dev/");
-	while(fgets(buf, 1023, proc_partitions)) {
-		i = sscanf(buf," %*d %*d %*d %99s", fullpath+5);
-
-		/*
-		 * multipath and MD devices may register as a btrfs filesystem
-		 * both through the original block device and through
-		 * the special (/dev/mapper or /dev/mdX) entry.
-		 * This scans the special entries last
-		 */
-		special = strncmp(fullpath, "/dev/dm-", strlen("/dev/dm-")) == 0;
-		if (!special)
-			special = strncmp(fullpath, "/dev/md", strlen("/dev/md")) == 0;
-
-		if (scans == 0 && special)
-			continue;
-		if (scans > 0 && !special)
-			continue;
-
-		ret = lstat(fullpath, &st);
-		if (ret < 0) {
-			fprintf(stderr, "failed to stat %s\n", fullpath);
-			continue;
-		}
-		if (!S_ISBLK(st.st_mode)) {
-			continue;
-		}
-
-		fd = open(fullpath, O_RDONLY);
-		if (fd < 0) {
-			if (errno != ENOMEDIUM)
-				fprintf(stderr, "failed to open %s: %s\n",
-					fullpath, strerror(errno));
-			continue;
-		}
-		ret = btrfs_scan_one_device(fd, fullpath, &tmp_devices,
-					    &num_devices,
-					    BTRFS_SUPER_INFO_OFFSET, 0);
-		if (ret == 0 && run_ioctl > 0) {
-			btrfs_register_one_device(fullpath);
-		}
-		close(fd);
-	}
-
-	fclose(proc_partitions);
-
-	if (scans == 0) {
-		scans++;
-		goto scan_again;
-	}
-	return 0;
-}
-
 /*
  * A not-so-good version fls64. No fascinating optimization since
  * no one except parse_size use it
diff --git a/utils.h b/utils.h
index 1536469..e332fd1 100644
--- a/utils.h
+++ b/utils.h
@@ -100,7 +100,6 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_bytes, unsigned unit_mo
 	})
 
 int get_mountpt(char *dev, char *mntpt, size_t size);
-int btrfs_scan_block_devices(int run_ioctl);
 u64 parse_size(char *s);
 u64 arg_strtou64(const char *str);
 int open_file_or_dir(const char *fname, DIR **dirstream);
-- 
2.0.0.153.g79dcccc


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] btrfs-progs: btrfs_scan_block_devices is unused function delete it
  2014-10-07  0:08   ` [PATCH] btrfs-progs: btrfs_scan_block_devices is unused function delete it Anand Jain
@ 2014-10-22 11:10     ` Anand Jain
  2015-05-05 16:54     ` David Sterba
  1 sibling, 0 replies; 11+ messages in thread
From: Anand Jain @ 2014-10-22 11:10 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs



   This is just a clean up patch which looks like you have missed
   it in 3.17. sorry if it confused you.


On 10/07/14 08:08, Anand Jain wrote:
> After Patch:
>   remove BTRFS_SCAN_PROC scan method
> There isn't any consumer for btrfs_scan_block_devices() so delete it.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
>   utils.c | 83 -----------------------------------------------------------------
>   utils.h |  1 -
>   2 files changed, 84 deletions(-)
>
> diff --git a/utils.c b/utils.c
> index 48d2d9a..b23f332 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -1542,89 +1542,6 @@ int set_label(const char *btrfs_dev, const char *label)
>   	return ret;
>   }
>
> -int btrfs_scan_block_devices(int run_ioctl)
> -{
> -
> -	struct stat st;
> -	int ret;
> -	int fd;
> -	struct btrfs_fs_devices *tmp_devices;
> -	u64 num_devices;
> -	FILE *proc_partitions;
> -	int i;
> -	char buf[1024];
> -	char fullpath[110];
> -	int scans = 0;
> -	int special;
> -
> -scan_again:
> -	proc_partitions = fopen("/proc/partitions","r");
> -	if (!proc_partitions) {
> -		fprintf(stderr, "Unable to open '/proc/partitions' for scanning\n");
> -		return -ENOENT;
> -	}
> -	/* skip the header */
> -	for (i = 0; i < 2; i++)
> -		if (!fgets(buf, 1023, proc_partitions)) {
> -			fprintf(stderr,
> -				"Unable to read '/proc/partitions' for scanning\n");
> -			fclose(proc_partitions);
> -			return -ENOENT;
> -		}
> -
> -	strcpy(fullpath,"/dev/");
> -	while(fgets(buf, 1023, proc_partitions)) {
> -		i = sscanf(buf," %*d %*d %*d %99s", fullpath+5);
> -
> -		/*
> -		 * multipath and MD devices may register as a btrfs filesystem
> -		 * both through the original block device and through
> -		 * the special (/dev/mapper or /dev/mdX) entry.
> -		 * This scans the special entries last
> -		 */
> -		special = strncmp(fullpath, "/dev/dm-", strlen("/dev/dm-")) == 0;
> -		if (!special)
> -			special = strncmp(fullpath, "/dev/md", strlen("/dev/md")) == 0;
> -
> -		if (scans == 0 && special)
> -			continue;
> -		if (scans > 0 && !special)
> -			continue;
> -
> -		ret = lstat(fullpath, &st);
> -		if (ret < 0) {
> -			fprintf(stderr, "failed to stat %s\n", fullpath);
> -			continue;
> -		}
> -		if (!S_ISBLK(st.st_mode)) {
> -			continue;
> -		}
> -
> -		fd = open(fullpath, O_RDONLY);
> -		if (fd < 0) {
> -			if (errno != ENOMEDIUM)
> -				fprintf(stderr, "failed to open %s: %s\n",
> -					fullpath, strerror(errno));
> -			continue;
> -		}
> -		ret = btrfs_scan_one_device(fd, fullpath, &tmp_devices,
> -					    &num_devices,
> -					    BTRFS_SUPER_INFO_OFFSET, 0);
> -		if (ret == 0 && run_ioctl > 0) {
> -			btrfs_register_one_device(fullpath);
> -		}
> -		close(fd);
> -	}
> -
> -	fclose(proc_partitions);
> -
> -	if (scans == 0) {
> -		scans++;
> -		goto scan_again;
> -	}
> -	return 0;
> -}
> -
>   /*
>    * A not-so-good version fls64. No fascinating optimization since
>    * no one except parse_size use it
> diff --git a/utils.h b/utils.h
> index 1536469..e332fd1 100644
> --- a/utils.h
> +++ b/utils.h
> @@ -100,7 +100,6 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_bytes, unsigned unit_mo
>   	})
>
>   int get_mountpt(char *dev, char *mntpt, size_t size);
> -int btrfs_scan_block_devices(int run_ioctl);
>   u64 parse_size(char *s);
>   u64 arg_strtou64(const char *str);
>   int open_file_or_dir(const char *fname, DIR **dirstream);
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d"
  2014-10-06  9:31   ` Anand Jain
@ 2014-10-23 13:12     ` Anand Jain
  0 siblings, 0 replies; 11+ messages in thread
From: Anand Jain @ 2014-10-23 13:12 UTC (permalink / raw)
  To: linux-btrfs; +Cc: dsterba, guihc.fnst, sandeen




  my stap func profiling script was wrong, I got the number of
  times scan_lblkid func called per thread wrong, now its
  been corrected as below. yet calling the system-wide device
  scan more than once per thread does not make any sense. There
  are quite a number of threads like that as below. The worst is
  mkfs.btrfs which calls n number of times, where n is number of
  disk being mkfs-ed.


   btrfs-find-root            1
   btrfs rescue super-recover 2
   btrfs-debug-tree           1
   btrfs-image -r             2
   btrfs check                2
   btrfs restore              2
   calc-size                  NC
   btrfs-corrupt-block        NC
   btrfs-image                NC
   btrfs-map-logical          1
   btrfs-select-super         NC
   btrfstune                  2
   btrfs-zero-log             NC
   tester                     NC
   quick-test.c               NC
   btrfs-convert              0
   mkfs                       #number of devices to be mkfs
   btrfs label set unmounted  2
   btrfs get label unmounted  2






On 10/06/14 17:31, Anand Jain wrote:
>
>
>   I am running some tests with larger disks pool (48 disks).
>   With that the performance of the various scan methods are as below..
>
> ----
> scanning BTRFS_SCAN_LBLKID
> real    0m0.330s
> user    0m0.005s
> sys     0m0.026s
>
> scanning BTRFS_SCAN_DEV
> real    0m0.010s
> user    0m0.002s
> sys     0m0.005s
>
> scanning BTRFS_SCAN_PROC
> real    0m0.010s
> user    0m0.002s
> sys     0m0.005s
> -----
>
>   This is the time taken to scan 48disks one time by various methods
>   we have/had - but our progs do this scan 30times for btrfs fi show.
>   yep 30times as show below.. I am working to fix it.
>
> -------
>                                  Function: time(us)    count  avg(us)
> ::
>                           get_device_info:     1034       27       38
>                      pretty_size_snprintf:     1218      124        9
>                     btrfs_scan_one_device:     1790      186        9
>                      btrfs_read_dev_super:     1956      116       16
>                                  cmd_show:    15418      335       46
>                         btrfs_scan_lblkid:   148477       30     4949
> -------
>
>   IMO we should still stick to LBLKID scan.
>   Just a thought - any idea if its better to provide a compile time
>   fallback scan switch, just in case if something fails with lblkid. ?
>
>
> Thanks, Anand
>
>
> On 09/24/14 01:00, David Sterba wrote:
>> Hi,
>>
>> all 5 patches will be in the next integration. I haven't tested them
>> yet, seems it's a bit more important to make a more stable devel base
>> for more updates you might want to send.
>> --
>> 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
>>
> --
> 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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] btrfs-progs: btrfs_scan_block_devices is unused function delete it
  2014-10-07  0:08   ` [PATCH] btrfs-progs: btrfs_scan_block_devices is unused function delete it Anand Jain
  2014-10-22 11:10     ` Anand Jain
@ 2015-05-05 16:54     ` David Sterba
  1 sibling, 0 replies; 11+ messages in thread
From: David Sterba @ 2015-05-05 16:54 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Tue, Oct 07, 2014 at 08:08:31AM +0800, Anand Jain wrote:
> After Patch:
>  remove BTRFS_SCAN_PROC scan method
> There isn't any consumer for btrfs_scan_block_devices() so delete it.
> 
> Signed-off-by: Anand Jain <anand.jain@oracle.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-05-05 16:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-13  1:21 [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d" Anand Jain
2014-09-13  1:21 ` [PATCH 2/5] btrfs-progs: don't fall back to recursive /dev scan Anand Jain
2014-09-13  1:21 ` [PATCH 3/5] btrfs-progs: remove BTRFS_SCAN_DEV and btrfs_scan_one_dir Anand Jain
2014-09-13  1:21 ` [PATCH 4/5] btrfs-progs: remove BTRFS_SCAN_PROC scan method Anand Jain
2014-10-07  0:08   ` [PATCH] btrfs-progs: btrfs_scan_block_devices is unused function delete it Anand Jain
2014-10-22 11:10     ` Anand Jain
2015-05-05 16:54     ` David Sterba
2014-09-13  1:21 ` [PATCH 5/5] btrfs-progs: remove scan_for_btrfs() Anand Jain
2014-09-23 17:00 ` [PATCH 1/5] btrfs-progs: scan /proc/partitions not all of /dev with "-d" David Sterba
2014-10-06  9:31   ` Anand Jain
2014-10-23 13:12     ` Anand Jain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.