linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] btrfs-progs: remove BTRFS_SCAN_PROC scan method
@ 2014-09-18  3:31 Gui Hecheng
  2014-09-18  3:31 ` [PATCH 2/3] btrfs-progs: remove scan_for_btrfs() Gui Hecheng
  2014-09-18  3:31 ` [PATCH 3/3] btrfs-progs: fix device missing of btrfs fi show with seeding devices Gui Hecheng
  0 siblings, 2 replies; 6+ messages in thread
From: Gui Hecheng @ 2014-09-18  3:31 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Anand.Jain, Anand Jain

From: Anand Jain <Anand.Jain@oracle.com>

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 a7183e3..a728f21 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -200,13 +200,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;
@@ -224,7 +224,6 @@ static int cmd_scan_dev(int argc, char **argv)
 			break;
 		switch (c) {
 		case 'd':
-			where = BTRFS_SCAN_PROC;
 			all = 1;
 			break;
 		default:
@@ -237,7 +236,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 69c1ca5..dc5185e 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -505,7 +505,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];
@@ -526,7 +526,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;
@@ -550,7 +550,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
@@ -586,7 +586,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 */
@@ -601,7 +601,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 c7901f4..9fe8769 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1005,7 +1005,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 fb78dd6..0ae0475 100644
--- a/utils.c
+++ b/utils.c
@@ -1150,7 +1150,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;
 	}
 
@@ -2181,9 +2181,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 01b3259..13f2e60 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
 
-- 
1.8.1.4


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

* [PATCH 2/3] btrfs-progs: remove scan_for_btrfs()
  2014-09-18  3:31 [PATCH 1/3] btrfs-progs: remove BTRFS_SCAN_PROC scan method Gui Hecheng
@ 2014-09-18  3:31 ` Gui Hecheng
  2014-09-18  3:31 ` [PATCH 3/3] btrfs-progs: fix device missing of btrfs fi show with seeding devices Gui Hecheng
  1 sibling, 0 replies; 6+ messages in thread
From: Gui Hecheng @ 2014-09-18  3:31 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Anand.Jain, Anand Jain

From: Anand Jain <Anand.Jain@oracle.com>

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 0ae0475..0cd97c7 100644
--- a/utils.c
+++ b/utils.c
@@ -2173,21 +2173,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 13f2e60..12466a6 100644
--- a/utils.h
+++ b/utils.h
@@ -105,7 +105,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);
-- 
1.8.1.4


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

* [PATCH 3/3] btrfs-progs: fix device missing of btrfs fi show with seeding devices
  2014-09-18  3:31 [PATCH 1/3] btrfs-progs: remove BTRFS_SCAN_PROC scan method Gui Hecheng
  2014-09-18  3:31 ` [PATCH 2/3] btrfs-progs: remove scan_for_btrfs() Gui Hecheng
@ 2014-09-18  3:31 ` Gui Hecheng
  2014-09-18  5:59   ` Anand Jain
  1 sibling, 1 reply; 6+ messages in thread
From: Gui Hecheng @ 2014-09-18  3:31 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Anand.Jain, Gui Hecheng

*Note*: this handles the problem under umounted state,
	the problem under mounted state is already fixed by Anand.

Steps to reproduce:
	# mkfs.btrfs -f /dev/sda1
	# btrfstune -S 1 /dev/sda1
	# mount /dev/sda1 /mnt
	# btrfs dev add /dev/sda2 /mnt
	# umount /mnt			<== (umounted)
	# btrfs fi show /dev/sda2
result:
	Label: none  uuid: XXXXXXXXXXXXXXXXXX
	Total devices 2 FS bytes used 368.00KiB
	devid    2 size 9.31GiB used 1.25GiB path /dev/sda2
	*** Some devices missing
	Btrfs v3.16-67-g69f54ea-dirty

It is because the @btrfs_scan_lblkid procedure is not capable of detecting
seeding devices since the seeding devices have different FSIDs from
derived devices. So when it tries to show all devices under the derived
fs, only the derived devices are shown.
Actually the @open_ctree deal with the seeding devices properly, so
we can make use of it to find seeding devices.
We call @open_ctree on every block device with a btrfs on it,
and all devices under the opening filesystem including the seed devices
will be ready to be shown.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 cmds-filesystem.c | 104 ++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 69 insertions(+), 35 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index dc5185e..f978175 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -28,6 +28,7 @@
 #include <mntent.h>
 #include <linux/limits.h>
 #include <getopt.h>
+#include <blkid/blkid.h>
 
 #include "kerncompat.h"
 #include "ctree.h"
@@ -268,10 +269,26 @@ static int cmp_device_id(void *priv, struct list_head *a,
 		da->devid > db->devid ? 1 : 0;
 }
 
+static void print_devices(struct btrfs_fs_devices *fs_devices, u64 *devs_found)
+{
+	struct btrfs_device *device;
+	struct list_head *cur;
+
+	list_sort(NULL, &fs_devices->devices, cmp_device_id);
+	list_for_each(cur, &fs_devices->devices) {
+		device = list_entry(cur, struct btrfs_device, dev_list);
+
+		printf("\tdevid %4llu size %s used %s path %s\n",
+			(unsigned long long)device->devid,
+			pretty_size(device->total_bytes),
+			pretty_size(device->bytes_used), device->name);
+			(*devs_found)++;
+		}
+}
+
 static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
 {
 	char uuidbuf[BTRFS_UUID_UNPARSED_SIZE];
-	struct list_head *cur;
 	struct btrfs_device *device;
 	u64 devs_found = 0;
 	u64 total;
@@ -293,17 +310,10 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
 	       (unsigned long long)total,
 	       pretty_size(device->super_bytes_used));
 
-	list_sort(NULL, &fs_devices->devices, cmp_device_id);
-	list_for_each(cur, &fs_devices->devices) {
-		device = list_entry(cur, struct btrfs_device, dev_list);
-
-		printf("\tdevid %4llu size %s used %s path %s\n",
-		       (unsigned long long)device->devid,
-		       pretty_size(device->total_bytes),
-		       pretty_size(device->bytes_used), device->name);
+	if (fs_devices->seed)
+		print_devices(fs_devices->seed, &devs_found);
+	print_devices(fs_devices, &devs_found);
 
-		devs_found++;
-	}
 	if (devs_found < total) {
 		printf("\t*** Some devices missing\n");
 	}
@@ -489,6 +499,53 @@ out:
 	return ret;
 }
 
+static int scan_all_fs_lblkid(char *search_target)
+{
+	blkid_dev_iterate iter = NULL;
+	blkid_dev dev = NULL;
+	blkid_cache cache = NULL;
+	char path[PATH_MAX];
+	struct btrfs_fs_info *fs_info;
+	int found = 0;
+
+	if (blkid_get_cache(&cache, 0) < 0) {
+		printf("ERROR: lblkid cache get failed\n");
+		return -1;
+	}
+	blkid_probe_all(cache);
+	iter = blkid_dev_iterate_begin(cache);
+	blkid_dev_set_search(iter, "TYPE", "btrfs");
+	while (blkid_dev_next(iter, &dev) == 0) {
+		dev = blkid_verify(cache, dev);
+		if (!dev)
+			continue;
+		strncpy(path, blkid_dev_devname(dev), PATH_MAX);
+		fs_info = open_ctree_fs_info(path, 0, 0, OPEN_CTREE_PARTIAL);
+		if (!fs_info)
+			continue;
+
+		if (search_target
+			&& !uuid_search(fs_info->fs_devices, search_target)) {
+			close_ctree(fs_info->fs_root);
+			continue;
+		}
+
+		if (search_target)
+			found = 1;
+		print_one_uuid(fs_info->fs_devices);
+
+		close_ctree(fs_info->fs_root);
+	}
+	blkid_dev_iterate_end(iter);
+	blkid_put_cache(cache);
+
+	if (search_target && !found)
+		return 1;
+
+	return 0;
+}
+
+
 static const char * const cmd_show_usage[] = {
 	"btrfs filesystem show [options] [<path>|<uuid>|<device>|label]",
 	"Show the structure of a filesystem",
@@ -500,9 +557,6 @@ static const char * const cmd_show_usage[] = {
 
 static int cmd_show(int argc, char **argv)
 {
-	struct list_head *all_uuids;
-	struct btrfs_fs_devices *fs_devices;
-	struct list_head *cur_uuid;
 	char *search = NULL;
 	int ret;
 	int where = -1; // default, search both kernel and udev
@@ -511,7 +565,6 @@ static int cmd_show(int argc, char **argv)
 	char path[PATH_MAX];
 	__u8 fsid[BTRFS_FSID_SIZE];
 	char uuid_buf[BTRFS_UUID_UNPARSED_SIZE];
-	int found = 0;
 
 	while (1) {
 		int long_index;
@@ -601,31 +654,12 @@ static int cmd_show(int argc, char **argv)
 		goto out;
 
 devs_only:
-	ret = btrfs_scan_lblkid(!BTRFS_UPDATE_KERNEL);
-
+	ret = scan_all_fs_lblkid(search);
 	if (ret) {
 		fprintf(stderr, "ERROR: %d while scanning\n", ret);
 		return 1;
 	}
 	
-	all_uuids = btrfs_scanned_uuids();
-	list_for_each(cur_uuid, all_uuids) {
-		fs_devices = list_entry(cur_uuid, struct btrfs_fs_devices,
-					list);
-		if (search && uuid_search(fs_devices, search) == 0)
-			continue;
-
-		print_one_uuid(fs_devices);
-		found = 1;
-	}
-	if (search && !found)
-		ret = 1;
-
-	while (!list_empty(all_uuids)) {
-		fs_devices = list_entry(all_uuids->next,
-					struct btrfs_fs_devices, list);
-		btrfs_close_devices(fs_devices);
-	}
 out:
 	printf("%s\n", BTRFS_BUILD_VERSION);
 	free_seen_fsid();
-- 
1.8.1.4


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

* Re: [PATCH 3/3] btrfs-progs: fix device missing of btrfs fi show with seeding devices
  2014-09-18  3:31 ` [PATCH 3/3] btrfs-progs: fix device missing of btrfs fi show with seeding devices Gui Hecheng
@ 2014-09-18  5:59   ` Anand Jain
  2014-09-18  6:49     ` Gui Hecheng
  2014-10-06 10:16     ` [PATCH v2 3/3] btrfs-progs: fix device missing of btrfs fi show with seed devices Gui Hecheng
  0 siblings, 2 replies; 6+ messages in thread
From: Anand Jain @ 2014-09-18  5:59 UTC (permalink / raw)
  To: Gui Hecheng; +Cc: linux-btrfs



  Hi Gui,

  Thanks for the attempt to fix this. more below..

On 09/18/2014 11:31 AM, Gui Hecheng wrote:
> *Note*: this handles the problem under umounted state,
> 	the problem under mounted state is already fixed by Anand.
>
> Steps to reproduce:
> 	# mkfs.btrfs -f /dev/sda1
> 	# btrfstune -S 1 /dev/sda1
> 	# mount /dev/sda1 /mnt
> 	# btrfs dev add /dev/sda2 /mnt
> 	# umount /mnt			<== (umounted)
> 	# btrfs fi show /dev/sda2
> result:
> 	Label: none  uuid: XXXXXXXXXXXXXXXXXX
> 	Total devices 2 FS bytes used 368.00KiB
> 	devid    2 size 9.31GiB used 1.25GiB path /dev/sda2
> 	*** Some devices missing
> 	Btrfs v3.16-67-g69f54ea-dirty
>
> It is because the @btrfs_scan_lblkid procedure is not capable of detecting
> seeding devices since the seeding devices have different FSIDs from
> derived devices. So when it tries to show all devices under the derived
> fs, only the derived devices are shown.

  Hmm.. thats not true.  btrfs_scan_lblkid() finds all btrfs devices
  including the seed/sprout devices. However btrfs_scan_lblkid won't
  establish mapping between the seed and sprout devices.

> Actually the @open_ctree deal with the seeding devices properly, so
> we can make use of it to find seeding devices.
> We call @open_ctree on every block device with a btrfs on it,
> and all devices under the opening filesystem including the seed devices
> will be ready to be shown.

  looking at the below code, I doubt if this will work with
  nested seed-sprout relations. ? what did I miss ?

  Its better to keep seed sprout mapping part separate from the device
  scan using lblkid.


Thanks, Anand


> Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> ---
>   cmds-filesystem.c | 104 ++++++++++++++++++++++++++++++++++++------------------
>   1 file changed, 69 insertions(+), 35 deletions(-)
>
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index dc5185e..f978175 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -28,6 +28,7 @@
>   #include <mntent.h>
>   #include <linux/limits.h>
>   #include <getopt.h>
> +#include <blkid/blkid.h>
>
>   #include "kerncompat.h"
>   #include "ctree.h"
> @@ -268,10 +269,26 @@ static int cmp_device_id(void *priv, struct list_head *a,
>   		da->devid > db->devid ? 1 : 0;
>   }
>
> +static void print_devices(struct btrfs_fs_devices *fs_devices, u64 *devs_found)
> +{
> +	struct btrfs_device *device;
> +	struct list_head *cur;
> +
> +	list_sort(NULL, &fs_devices->devices, cmp_device_id);
> +	list_for_each(cur, &fs_devices->devices) {
> +		device = list_entry(cur, struct btrfs_device, dev_list);
> +
> +		printf("\tdevid %4llu size %s used %s path %s\n",
> +			(unsigned long long)device->devid,
> +			pretty_size(device->total_bytes),
> +			pretty_size(device->bytes_used), device->name);
> +			(*devs_found)++;
> +		}
> +}
> +
>   static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
>   {
>   	char uuidbuf[BTRFS_UUID_UNPARSED_SIZE];
> -	struct list_head *cur;
>   	struct btrfs_device *device;
>   	u64 devs_found = 0;
>   	u64 total;
> @@ -293,17 +310,10 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
>   	       (unsigned long long)total,
>   	       pretty_size(device->super_bytes_used));
>
> -	list_sort(NULL, &fs_devices->devices, cmp_device_id);
> -	list_for_each(cur, &fs_devices->devices) {
> -		device = list_entry(cur, struct btrfs_device, dev_list);
> -
> -		printf("\tdevid %4llu size %s used %s path %s\n",
> -		       (unsigned long long)device->devid,
> -		       pretty_size(device->total_bytes),
> -		       pretty_size(device->bytes_used), device->name);
> +	if (fs_devices->seed)
> +		print_devices(fs_devices->seed, &devs_found);
> +	print_devices(fs_devices, &devs_found);
>
> -		devs_found++;
> -	}
>   	if (devs_found < total) {
>   		printf("\t*** Some devices missing\n");
>   	}
> @@ -489,6 +499,53 @@ out:
>   	return ret;
>   }
>
> +static int scan_all_fs_lblkid(char *search_target)
> +{
> +	blkid_dev_iterate iter = NULL;
> +	blkid_dev dev = NULL;
> +	blkid_cache cache = NULL;
> +	char path[PATH_MAX];
> +	struct btrfs_fs_info *fs_info;
> +	int found = 0;
> +
> +	if (blkid_get_cache(&cache, 0) < 0) {
> +		printf("ERROR: lblkid cache get failed\n");
> +		return -1;
> +	}
> +	blkid_probe_all(cache);
> +	iter = blkid_dev_iterate_begin(cache);
> +	blkid_dev_set_search(iter, "TYPE", "btrfs");
> +	while (blkid_dev_next(iter, &dev) == 0) {
> +		dev = blkid_verify(cache, dev);
> +		if (!dev)
> +			continue;
> +		strncpy(path, blkid_dev_devname(dev), PATH_MAX);
> +		fs_info = open_ctree_fs_info(path, 0, 0, OPEN_CTREE_PARTIAL);
> +		if (!fs_info)
> +			continue;
> +
> +		if (search_target
> +			&& !uuid_search(fs_info->fs_devices, search_target)) {
> +			close_ctree(fs_info->fs_root);
> +			continue;
> +		}
> +
> +		if (search_target)
> +			found = 1;
> +		print_one_uuid(fs_info->fs_devices);
> +
> +		close_ctree(fs_info->fs_root);
> +	}
> +	blkid_dev_iterate_end(iter);
> +	blkid_put_cache(cache);
> +
> +	if (search_target && !found)
> +		return 1;
> +
> +	return 0;
> +}
> +
> +
>   static const char * const cmd_show_usage[] = {
>   	"btrfs filesystem show [options] [<path>|<uuid>|<device>|label]",
>   	"Show the structure of a filesystem",
> @@ -500,9 +557,6 @@ static const char * const cmd_show_usage[] = {
>
>   static int cmd_show(int argc, char **argv)
>   {
> -	struct list_head *all_uuids;
> -	struct btrfs_fs_devices *fs_devices;
> -	struct list_head *cur_uuid;
>   	char *search = NULL;
>   	int ret;
>   	int where = -1; // default, search both kernel and udev
> @@ -511,7 +565,6 @@ static int cmd_show(int argc, char **argv)
>   	char path[PATH_MAX];
>   	__u8 fsid[BTRFS_FSID_SIZE];
>   	char uuid_buf[BTRFS_UUID_UNPARSED_SIZE];
> -	int found = 0;
>
>   	while (1) {
>   		int long_index;
> @@ -601,31 +654,12 @@ static int cmd_show(int argc, char **argv)
>   		goto out;
>
>   devs_only:
> -	ret = btrfs_scan_lblkid(!BTRFS_UPDATE_KERNEL);
> -
> +	ret = scan_all_fs_lblkid(search);
>   	if (ret) {
>   		fprintf(stderr, "ERROR: %d while scanning\n", ret);
>   		return 1;
>   	}
>   	
> -	all_uuids = btrfs_scanned_uuids();
> -	list_for_each(cur_uuid, all_uuids) {
> -		fs_devices = list_entry(cur_uuid, struct btrfs_fs_devices,
> -					list);
> -		if (search && uuid_search(fs_devices, search) == 0)
> -			continue;
> -
> -		print_one_uuid(fs_devices);
> -		found = 1;
> -	}
> -	if (search && !found)
> -		ret = 1;
> -
> -	while (!list_empty(all_uuids)) {
> -		fs_devices = list_entry(all_uuids->next,
> -					struct btrfs_fs_devices, list);
> -		btrfs_close_devices(fs_devices);
> -	}
>   out:
>   	printf("%s\n", BTRFS_BUILD_VERSION);
>   	free_seen_fsid();
>

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

* Re: [PATCH 3/3] btrfs-progs: fix device missing of btrfs fi show with seeding devices
  2014-09-18  5:59   ` Anand Jain
@ 2014-09-18  6:49     ` Gui Hecheng
  2014-10-06 10:16     ` [PATCH v2 3/3] btrfs-progs: fix device missing of btrfs fi show with seed devices Gui Hecheng
  1 sibling, 0 replies; 6+ messages in thread
From: Gui Hecheng @ 2014-09-18  6:49 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Thu, 2014-09-18 at 13:59 +0800, Anand Jain wrote:
> 
>   Hi Gui,
> 
>   Thanks for the attempt to fix this. more below..
> 
> On 09/18/2014 11:31 AM, Gui Hecheng wrote:
> > *Note*: this handles the problem under umounted state,
> > 	the problem under mounted state is already fixed by Anand.
> >
> > Steps to reproduce:
> > 	# mkfs.btrfs -f /dev/sda1
> > 	# btrfstune -S 1 /dev/sda1
> > 	# mount /dev/sda1 /mnt
> > 	# btrfs dev add /dev/sda2 /mnt
> > 	# umount /mnt			<== (umounted)
> > 	# btrfs fi show /dev/sda2
> > result:
> > 	Label: none  uuid: XXXXXXXXXXXXXXXXXX
> > 	Total devices 2 FS bytes used 368.00KiB
> > 	devid    2 size 9.31GiB used 1.25GiB path /dev/sda2
> > 	*** Some devices missing
> > 	Btrfs v3.16-67-g69f54ea-dirty
> >
> > It is because the @btrfs_scan_lblkid procedure is not capable of detecting
> > seeding devices since the seeding devices have different FSIDs from
> > derived devices. So when it tries to show all devices under the derived
> > fs, only the derived devices are shown.
> 
>   Hmm.. thats not true.  btrfs_scan_lblkid() finds all btrfs devices
>   including the seed/sprout devices. However btrfs_scan_lblkid won't
>   establish mapping between the seed and sprout devices.

Yes, I think the seed/sprout mapping relation do have to be clarified.

> > Actually the @open_ctree deal with the seeding devices properly, so
> > we can make use of it to find seeding devices.
> > We call @open_ctree on every block device with a btrfs on it,
> > and all devices under the opening filesystem including the seed devices
> > will be ready to be shown.
> 
>   looking at the below code, I doubt if this will work with
>   nested seed-sprout relations. ? what did I miss ?

Oh, this seems to be my missing point. I will test it in the next
version.

>   Its better to keep seed sprout mapping part separate from the device
>   scan using lblkid.

That sounds to be a good idea. So I will keep the original
@btrfs_scan_lblkid() and try to build the seed/sprout mapping after it.

Thanks very much for your comments, please allow me to give a "re-shot".

-Gui

> 
> Thanks, Anand
> 
> 
> > Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> > ---
> >   cmds-filesystem.c | 104 ++++++++++++++++++++++++++++++++++++------------------
> >   1 file changed, 69 insertions(+), 35 deletions(-)
> >
> > diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> > index dc5185e..f978175 100644
> > --- a/cmds-filesystem.c
> > +++ b/cmds-filesystem.c
> > @@ -28,6 +28,7 @@
> >   #include <mntent.h>
> >   #include <linux/limits.h>
> >   #include <getopt.h>
> > +#include <blkid/blkid.h>
> >
> >   #include "kerncompat.h"
> >   #include "ctree.h"
> > @@ -268,10 +269,26 @@ static int cmp_device_id(void *priv, struct list_head *a,
> >   		da->devid > db->devid ? 1 : 0;
> >   }
> >
> > +static void print_devices(struct btrfs_fs_devices *fs_devices, u64 *devs_found)
> > +{
> > +	struct btrfs_device *device;
> > +	struct list_head *cur;
> > +
> > +	list_sort(NULL, &fs_devices->devices, cmp_device_id);
> > +	list_for_each(cur, &fs_devices->devices) {
> > +		device = list_entry(cur, struct btrfs_device, dev_list);
> > +
> > +		printf("\tdevid %4llu size %s used %s path %s\n",
> > +			(unsigned long long)device->devid,
> > +			pretty_size(device->total_bytes),
> > +			pretty_size(device->bytes_used), device->name);
> > +			(*devs_found)++;
> > +		}
> > +}
> > +
> >   static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
> >   {
> >   	char uuidbuf[BTRFS_UUID_UNPARSED_SIZE];
> > -	struct list_head *cur;
> >   	struct btrfs_device *device;
> >   	u64 devs_found = 0;
> >   	u64 total;
> > @@ -293,17 +310,10 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
> >   	       (unsigned long long)total,
> >   	       pretty_size(device->super_bytes_used));
> >
> > -	list_sort(NULL, &fs_devices->devices, cmp_device_id);
> > -	list_for_each(cur, &fs_devices->devices) {
> > -		device = list_entry(cur, struct btrfs_device, dev_list);
> > -
> > -		printf("\tdevid %4llu size %s used %s path %s\n",
> > -		       (unsigned long long)device->devid,
> > -		       pretty_size(device->total_bytes),
> > -		       pretty_size(device->bytes_used), device->name);
> > +	if (fs_devices->seed)
> > +		print_devices(fs_devices->seed, &devs_found);
> > +	print_devices(fs_devices, &devs_found);
> >
> > -		devs_found++;
> > -	}
> >   	if (devs_found < total) {
> >   		printf("\t*** Some devices missing\n");
> >   	}
> > @@ -489,6 +499,53 @@ out:
> >   	return ret;
> >   }
> >
> > +static int scan_all_fs_lblkid(char *search_target)
> > +{
> > +	blkid_dev_iterate iter = NULL;
> > +	blkid_dev dev = NULL;
> > +	blkid_cache cache = NULL;
> > +	char path[PATH_MAX];
> > +	struct btrfs_fs_info *fs_info;
> > +	int found = 0;
> > +
> > +	if (blkid_get_cache(&cache, 0) < 0) {
> > +		printf("ERROR: lblkid cache get failed\n");
> > +		return -1;
> > +	}
> > +	blkid_probe_all(cache);
> > +	iter = blkid_dev_iterate_begin(cache);
> > +	blkid_dev_set_search(iter, "TYPE", "btrfs");
> > +	while (blkid_dev_next(iter, &dev) == 0) {
> > +		dev = blkid_verify(cache, dev);
> > +		if (!dev)
> > +			continue;
> > +		strncpy(path, blkid_dev_devname(dev), PATH_MAX);
> > +		fs_info = open_ctree_fs_info(path, 0, 0, OPEN_CTREE_PARTIAL);
> > +		if (!fs_info)
> > +			continue;
> > +
> > +		if (search_target
> > +			&& !uuid_search(fs_info->fs_devices, search_target)) {
> > +			close_ctree(fs_info->fs_root);
> > +			continue;
> > +		}
> > +
> > +		if (search_target)
> > +			found = 1;
> > +		print_one_uuid(fs_info->fs_devices);
> > +
> > +		close_ctree(fs_info->fs_root);
> > +	}
> > +	blkid_dev_iterate_end(iter);
> > +	blkid_put_cache(cache);
> > +
> > +	if (search_target && !found)
> > +		return 1;
> > +
> > +	return 0;
> > +}
> > +
> > +
> >   static const char * const cmd_show_usage[] = {
> >   	"btrfs filesystem show [options] [<path>|<uuid>|<device>|label]",
> >   	"Show the structure of a filesystem",
> > @@ -500,9 +557,6 @@ static const char * const cmd_show_usage[] = {
> >
> >   static int cmd_show(int argc, char **argv)
> >   {
> > -	struct list_head *all_uuids;
> > -	struct btrfs_fs_devices *fs_devices;
> > -	struct list_head *cur_uuid;
> >   	char *search = NULL;
> >   	int ret;
> >   	int where = -1; // default, search both kernel and udev
> > @@ -511,7 +565,6 @@ static int cmd_show(int argc, char **argv)
> >   	char path[PATH_MAX];
> >   	__u8 fsid[BTRFS_FSID_SIZE];
> >   	char uuid_buf[BTRFS_UUID_UNPARSED_SIZE];
> > -	int found = 0;
> >
> >   	while (1) {
> >   		int long_index;
> > @@ -601,31 +654,12 @@ static int cmd_show(int argc, char **argv)
> >   		goto out;
> >
> >   devs_only:
> > -	ret = btrfs_scan_lblkid(!BTRFS_UPDATE_KERNEL);
> > -
> > +	ret = scan_all_fs_lblkid(search);
> >   	if (ret) {
> >   		fprintf(stderr, "ERROR: %d while scanning\n", ret);
> >   		return 1;
> >   	}
> >   	
> > -	all_uuids = btrfs_scanned_uuids();
> > -	list_for_each(cur_uuid, all_uuids) {
> > -		fs_devices = list_entry(cur_uuid, struct btrfs_fs_devices,
> > -					list);
> > -		if (search && uuid_search(fs_devices, search) == 0)
> > -			continue;
> > -
> > -		print_one_uuid(fs_devices);
> > -		found = 1;
> > -	}
> > -	if (search && !found)
> > -		ret = 1;
> > -
> > -	while (!list_empty(all_uuids)) {
> > -		fs_devices = list_entry(all_uuids->next,
> > -					struct btrfs_fs_devices, list);
> > -		btrfs_close_devices(fs_devices);
> > -	}
> >   out:
> >   	printf("%s\n", BTRFS_BUILD_VERSION);
> >   	free_seen_fsid();
> >



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

* [PATCH v2 3/3] btrfs-progs: fix device missing of btrfs fi show with seed devices
  2014-09-18  5:59   ` Anand Jain
  2014-09-18  6:49     ` Gui Hecheng
@ 2014-10-06 10:16     ` Gui Hecheng
  1 sibling, 0 replies; 6+ messages in thread
From: Gui Hecheng @ 2014-10-06 10:16 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Anand.Jain, Gui Hecheng

*Note*
this handles the problem under umounted state, the similar problem
under mounted state is already fixed by Anand.

Steps to reproduce:
        # mkfs.btrfs -f /dev/sda1
        # btrfstune -S 1 /dev/sda1
        # mount /dev/sda1 /mnt
        # btrfs dev add /dev/sda2 /mnt
        # umount /mnt                   <== (umounted)
        # btrfs fi show /dev/sda2
result:
        Label: none  uuid: XXXXXXXXXXXXXXXXXX
        Total devices 2 FS bytes used 368.00KiB
        devid    2 size 9.31GiB used 1.25GiB path /dev/sda2
        *** Some devices missing
        Btrfs v3.16-67-g69f54ea-dirty

It is because @btrfs_scan_lblkid() won't establish mappinig
between the seed and sprout devices. So seeding devices are missing.
We could use @open_ctree_* to detect all seed/sprout mappings
for each fs scanned after @btrfs_scan_lblkid().

sth worthes mention:
o If there are multi-level of seeds, all devices in them will be shown
  in the ascending order of @devid
o If device replace is execed on a sprout fs with a device in a seed fs,
  the replaced device still exist in the seed fs together with
  the replacing device in the sprout fs, so we only keep the latest device
  with the newest generation

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
changelog
	v1->v2: o add multi-level of seeds handle
		o add dev replace handle
---
 cmds-filesystem.c | 294 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 volumes.c         |   1 +
 volumes.h         |   2 +
 3 files changed, 271 insertions(+), 26 deletions(-)

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index dc5185e..6cb67f7 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -268,10 +268,71 @@ static int cmp_device_id(void *priv, struct list_head *a,
 		da->devid > db->devid ? 1 : 0;
 }
 
+static void splice_device_list(struct list_head *seed_devices,
+			       struct list_head *all_devices)
+{
+	struct btrfs_device *in_all, *next_all;
+	struct btrfs_device *in_seed, *next_seed;
+
+	list_for_each_entry_safe(in_all, next_all, all_devices, dev_list) {
+		list_for_each_entry_safe(in_seed, next_seed, seed_devices,
+								dev_list) {
+			if (in_all->devid == in_seed->devid) {
+				/*
+				 * When do dev replace in a sprout fs
+				 * to a dev in its seed fs, the replacing
+				 * dev will reside in the sprout fs and
+				 * the replaced dev will still exist
+				 * in the seed fs.
+				 * So pick the latest one when showing
+				 * the sprout fs.
+				 */
+				if (in_all->generation
+						< in_seed->generation) {
+					list_del(&in_all->dev_list);
+					free(in_all);
+				} else if (in_all->generation
+						> in_seed->generation) {
+					list_del(&in_seed->dev_list);
+					free(in_seed);
+				}
+				break;
+			}
+		}
+	}
+
+	list_splice(seed_devices, all_devices);
+}
+
+static void print_devices(struct btrfs_fs_devices *fs_devices,
+			  u64 *devs_found)
+{
+	struct btrfs_device *device;
+	struct btrfs_fs_devices *cur_fs;
+	struct list_head *all_devices;
+
+	all_devices = &fs_devices->devices;
+	cur_fs = fs_devices->seed;
+	/* add all devices of seed fs to the fs to be printed */
+	while (cur_fs) {
+		splice_device_list(&cur_fs->devices, all_devices);
+		cur_fs = cur_fs->seed;
+	}
+
+	list_sort(NULL, all_devices, cmp_device_id);
+	list_for_each_entry(device, all_devices, dev_list) {
+		printf("\tdevid %4llu size %s used %s path %s\n",
+		       (unsigned long long)device->devid,
+		       pretty_size(device->total_bytes),
+		       pretty_size(device->bytes_used), device->name);
+
+		(*devs_found)++;
+	}
+}
+
 static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
 {
 	char uuidbuf[BTRFS_UUID_UNPARSED_SIZE];
-	struct list_head *cur;
 	struct btrfs_device *device;
 	u64 devs_found = 0;
 	u64 total;
@@ -287,23 +348,13 @@ static void print_one_uuid(struct btrfs_fs_devices *fs_devices)
 	else
 		printf("Label: none ");
 
-
 	total = device->total_devs;
 	printf(" uuid: %s\n\tTotal devices %llu FS bytes used %s\n", uuidbuf,
 	       (unsigned long long)total,
 	       pretty_size(device->super_bytes_used));
 
-	list_sort(NULL, &fs_devices->devices, cmp_device_id);
-	list_for_each(cur, &fs_devices->devices) {
-		device = list_entry(cur, struct btrfs_device, dev_list);
+	print_devices(fs_devices, &devs_found);
 
-		printf("\tdevid %4llu size %s used %s path %s\n",
-		       (unsigned long long)device->devid,
-		       pretty_size(device->total_bytes),
-		       pretty_size(device->bytes_used), device->name);
-
-		devs_found++;
-	}
 	if (devs_found < total) {
 		printf("\t*** Some devices missing\n");
 	}
@@ -489,6 +540,194 @@ out:
 	return ret;
 }
 
+static void free_fs_devices(struct btrfs_fs_devices *fs_devices)
+{
+	struct btrfs_fs_devices *cur_seed, *next_seed;
+	struct btrfs_device *device;
+
+	while (!list_empty(&fs_devices->devices)) {
+		device = list_entry(fs_devices->devices.next,
+					struct btrfs_device, dev_list);
+		list_del(&device->dev_list);
+
+		free(device->name);
+		free(device->label);
+		free(device);
+	}
+
+	/* free seed fs chain */
+	cur_seed = fs_devices->seed;
+	fs_devices->seed = NULL;
+	while (cur_seed) {
+		next_seed = cur_seed->seed;
+		free(cur_seed);
+
+		cur_seed = next_seed;
+	}
+
+	list_del(&fs_devices->list);
+	free(fs_devices);
+}
+
+static int copy_device(struct btrfs_device *dst,
+		       struct btrfs_device *src)
+{
+	dst->devid = src->devid;
+	memcpy(dst->uuid, src->uuid, BTRFS_UUID_SIZE);
+	if (src->name == NULL)
+		dst->name = NULL;
+	else {
+		dst->name = strdup(src->name);
+		if (!dst->name)
+			return -ENOMEM;
+	}
+	if (src->label == NULL)
+		dst->label = NULL;
+	else {
+		dst->label = strdup(src->label);
+		if (!dst->label) {
+			free(dst->name);
+			return -ENOMEM;
+		}
+	}
+	dst->total_devs = src->total_devs;
+	dst->super_bytes_used = src->super_bytes_used;
+	dst->total_bytes = src->total_bytes;
+	dst->bytes_used = src->bytes_used;
+	dst->generation = src->generation;
+
+	return 0;
+}
+
+static int copy_fs_devices(struct btrfs_fs_devices *dst,
+			   struct btrfs_fs_devices *src)
+{
+	struct btrfs_device *cur_dev, *dev_copy;
+	int ret = 0;
+
+	memcpy(dst->fsid, src->fsid, BTRFS_FSID_SIZE);
+	INIT_LIST_HEAD(&dst->devices);
+	dst->seed = NULL;
+
+	list_for_each_entry(cur_dev, &src->devices, dev_list) {
+		dev_copy = malloc(sizeof(*dev_copy));
+		if (!dev_copy) {
+			ret = -ENOMEM;
+			break;
+		}
+
+		ret = copy_device(dev_copy, cur_dev);
+		if (ret) {
+			free(dev_copy);
+			break;
+		}
+
+		list_add(&dev_copy->dev_list, &dst->devices);
+		dev_copy->fs_devices = dst;
+	}
+
+	return ret;
+}
+
+static int find_and_copy_seed(struct btrfs_fs_devices *seed,
+			      struct btrfs_fs_devices *copy,
+			      struct list_head *fs_uuids) {
+	struct btrfs_fs_devices *cur_fs;
+
+	list_for_each_entry(cur_fs, fs_uuids, list)
+		if (!memcmp(seed->fsid, cur_fs->fsid, BTRFS_FSID_SIZE))
+			return copy_fs_devices(copy, cur_fs);
+
+	return 1;
+}
+
+static int map_seed_devices(struct list_head *all_uuids,
+			    char *search, int *found)
+{
+	struct btrfs_fs_devices *cur_fs, *cur_seed;
+	struct btrfs_fs_devices *fs_copy, *seed_copy;
+	struct btrfs_fs_devices *opened_fs;
+	struct btrfs_device *device;
+	struct btrfs_fs_info *fs_info;
+	struct list_head *fs_uuids;
+	int ret = 0;
+
+	fs_uuids = btrfs_scanned_uuids();
+
+	/*
+	 * The fs_uuids list is global, and open_ctree_* will
+	 * modify it, make a private copy here
+	 */
+	list_for_each_entry(cur_fs, fs_uuids, list) {
+		/* don't bother handle all fs, if search target specified */
+		if (search) {
+			if (uuid_search(cur_fs, search) == 0)
+				continue;
+			*found = 1;
+		}
+
+		fs_copy = malloc(sizeof(*fs_copy));
+		if (!fs_copy) {
+			ret = -ENOMEM;
+			goto out;
+		}
+
+		ret = copy_fs_devices(fs_copy, cur_fs);
+		if (ret) {
+			free(fs_copy);
+			goto out;
+		}
+
+		list_add(&fs_copy->list, all_uuids);
+	}
+
+	list_for_each_entry(cur_fs, all_uuids, list) {
+		device = list_first_entry(&cur_fs->devices,
+						struct btrfs_device, dev_list);
+		if (!device)
+			continue;
+		/*
+		 * open_ctree_* detects seed/sprout mapping
+		 */
+		fs_info = open_ctree_fs_info(device->name, 0, 0,
+						OPEN_CTREE_PARTIAL);
+		if (!fs_info)
+			continue;
+
+		/*
+		 * copy the seed chain under the opened fs
+		 */
+		opened_fs = fs_info->fs_devices;
+		cur_seed = cur_fs;
+		while (opened_fs->seed) {
+			seed_copy = malloc(sizeof(*seed_copy));
+			if (!seed_copy) {
+				ret = -ENOMEM;
+				goto fail_out;
+			}
+			ret = find_and_copy_seed(opened_fs->seed, seed_copy,
+						 fs_uuids);
+			if (ret) {
+				free(seed_copy);
+				goto fail_out;
+			}
+
+			cur_seed->seed = seed_copy;
+
+			opened_fs = opened_fs->seed;
+			cur_seed = cur_seed->seed;
+		}
+
+		close_ctree(fs_info->chunk_root);
+	}
+
+out:
+	return ret;
+fail_out:
+	close_ctree(fs_info->chunk_root);
+	goto out;
+}
+
 static const char * const cmd_show_usage[] = {
 	"btrfs filesystem show [options] [<path>|<uuid>|<device>|label]",
 	"Show the structure of a filesystem",
@@ -500,9 +739,8 @@ static const char * const cmd_show_usage[] = {
 
 static int cmd_show(int argc, char **argv)
 {
-	struct list_head *all_uuids;
+	LIST_HEAD(all_uuids);
 	struct btrfs_fs_devices *fs_devices;
-	struct list_head *cur_uuid;
 	char *search = NULL;
 	int ret;
 	int where = -1; // default, search both kernel and udev
@@ -607,24 +845,28 @@ devs_only:
 		fprintf(stderr, "ERROR: %d while scanning\n", ret);
 		return 1;
 	}
-	
-	all_uuids = btrfs_scanned_uuids();
-	list_for_each(cur_uuid, all_uuids) {
-		fs_devices = list_entry(cur_uuid, struct btrfs_fs_devices,
-					list);
-		if (search && uuid_search(fs_devices, search) == 0)
-			continue;
 
-		print_one_uuid(fs_devices);
-		found = 1;
+	/*
+	 * scan_for_btrfs() don't build seed/sprout mapping,
+	 * do mapping build for each scanned fs here
+	 */
+	ret = map_seed_devices(&all_uuids, search, &found);
+	if (ret) {
+		fprintf(stderr,
+			"ERROR: %d while mapping seed devices\n", ret);
+		return 1;
 	}
+
+	list_for_each_entry(fs_devices, &all_uuids, list)
+		print_one_uuid(fs_devices);
+
 	if (search && !found)
 		ret = 1;
 
-	while (!list_empty(all_uuids)) {
-		fs_devices = list_entry(all_uuids->next,
+	while (!list_empty(&all_uuids)) {
+		fs_devices = list_entry(all_uuids.next,
 					struct btrfs_fs_devices, list);
-		btrfs_close_devices(fs_devices);
+		free_fs_devices(fs_devices);
 	}
 out:
 	printf("%s\n", BTRFS_BUILD_VERSION);
diff --git a/volumes.c b/volumes.c
index 266a474..eaf3f9f 100644
--- a/volumes.c
+++ b/volumes.c
@@ -116,6 +116,7 @@ static int device_list_add(const char *path,
 		}
 		device->fd = -1;
 		device->devid = devid;
+		device->generation = found_transid;
 		memcpy(device->uuid, disk_super->dev_item.uuid,
 		       BTRFS_UUID_SIZE);
 		device->name = kstrdup(path, GFP_NOFS);
diff --git a/volumes.h b/volumes.h
index 447dd4b..221ef34 100644
--- a/volumes.h
+++ b/volumes.h
@@ -39,6 +39,8 @@ struct btrfs_device {
 	u64 total_devs;
 	u64 super_bytes_used;
 
+	u64 generation;
+
 	/* the internal btrfs device id */
 	u64 devid;
 
-- 
1.8.1.4


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

end of thread, other threads:[~2014-10-06 10:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-18  3:31 [PATCH 1/3] btrfs-progs: remove BTRFS_SCAN_PROC scan method Gui Hecheng
2014-09-18  3:31 ` [PATCH 2/3] btrfs-progs: remove scan_for_btrfs() Gui Hecheng
2014-09-18  3:31 ` [PATCH 3/3] btrfs-progs: fix device missing of btrfs fi show with seeding devices Gui Hecheng
2014-09-18  5:59   ` Anand Jain
2014-09-18  6:49     ` Gui Hecheng
2014-10-06 10:16     ` [PATCH v2 3/3] btrfs-progs: fix device missing of btrfs fi show with seed devices Gui Hecheng

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).