summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorAnand Jain <anand.jain@oracle.com>2014-10-31 12:11:20 +0800
committerDavid Sterba <dsterba@suse.cz>2014-11-03 19:17:11 +0100
commit2f55fd70191ed3e204cbe589af34a8c678dceab6 (patch)
treea27eef08f96fef122580b944b5976c3ae7de23d3 /utils.c
parent53cb7fbe8da8253ea3ac1ecc6a71c7ffd1d63f76 (diff)
btrfs-progs: optimize btrfs_scan_lblkid() for multiple calls
btrfs_scan_lblikd() is called by most the device related command functions. And btrfs_scan_lblkid() is most expensive function and it becomes more expensive as number of devices in the system increase. Further some threads call this function more than once for absolutely no extra benefit and the real waste of resources. Below list of threads and number of times btrfs_scan_lblkid() is called in that thread. 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 This patch will: move out calling register_one_device with in btrfs_scan_lblkid() and so function setting the BTRFS_UPDATE_KERNEL to yes will call btrfs_register_all_devices() separately. introduce a global variable scan_done, which is set when scan is done succssfully per thread. So that following calls to this function will just return success. Further if any function needs to force scan after scan_done is set, then it can be done when there is such a requirement, but as of now there isn't any such requirement. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/utils.c b/utils.c
index 5a12517f..f51bc564 100644
--- a/utils.c
+++ b/utils.c
@@ -52,6 +52,8 @@
#define BLKDISCARD _IO(0x12,119)
#endif
+static int btrfs_scan_done = 0;
+
static char argv0_buf[ARGV0_BUF_SIZE] = "btrfs";
void fixup_argv0(char **argv, const char *token)
@@ -1186,7 +1188,7 @@ int check_mounted_where(int fd, const char *file, char *where, int size,
/* scan other devices */
if (is_btrfs && total_devs > 1) {
- ret = btrfs_scan_lblkid(!BTRFS_UPDATE_KERNEL);
+ ret = btrfs_scan_lblkid();
if (ret)
return ret;
}
@@ -2179,7 +2181,7 @@ int test_dev_for_mkfs(char *file, int force_overwrite, char *estr)
return 0;
}
-int btrfs_scan_lblkid(int update_kernel)
+int btrfs_scan_lblkid()
{
int fd = -1;
int ret;
@@ -2190,6 +2192,9 @@ int btrfs_scan_lblkid(int update_kernel)
blkid_cache cache = NULL;
char path[PATH_MAX];
+ if (btrfs_scan_done)
+ return 0;
+
if (blkid_get_cache(&cache, 0) < 0) {
printf("ERROR: lblkid cache get failed\n");
return 1;
@@ -2218,11 +2223,12 @@ int btrfs_scan_lblkid(int update_kernel)
}
close(fd);
- if (update_kernel)
- btrfs_register_one_device(path);
}
blkid_dev_iterate_end(iter);
blkid_put_cache(cache);
+
+ btrfs_scan_done = 1;
+
return 0;
}