From: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Subject: [PATCH 2/2] btrfs-progs: fix wrong num_devices for btrfs fi show with seed devices
Date: Fri, 7 Nov 2014 10:07:43 +0800 [thread overview]
Message-ID: <1415326063-8838-3-git-send-email-guihc.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1415326063-8838-1-git-send-email-guihc.fnst@cn.fujitsu.com>
The @fi_args->num_devices in @get_fs_info() does not include seed devices.
We could just correct it by searching the chunk tree and count how
many dev_items there are in total which includes seed devices.
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
*Note*
This is just a temporary workaround to fix this problem in order to
make users happy, because a new ioctl or sysfs interface to handle this
problem needs more discussions and efforts. After the work implemented
and accepted, we could drop this.
---
utils.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/utils.c b/utils.c
index 9bcc1a0..a6dcb8a 100644
--- a/utils.c
+++ b/utils.c
@@ -1781,6 +1781,73 @@ int get_device_info(int fd, u64 devid,
return ret ? -errno : 0;
}
+u64 find_max_id(struct btrfs_ioctl_search_args *search_args, int nr_items)
+{
+ struct btrfs_dev_item *dev_item;
+ char *buf = search_args->buf;
+
+ buf += (nr_items - 1) * (sizeof(struct btrfs_ioctl_search_header)
+ + sizeof(struct btrfs_dev_item));
+ buf += sizeof(struct btrfs_ioctl_search_header);
+
+ dev_item = (struct btrfs_dev_item *)buf;
+
+ return btrfs_stack_device_id(dev_item);
+}
+
+int correct_fs_info(int fd, struct btrfs_ioctl_fs_info_args *fi_args)
+{
+ int ret;
+ int max_items;
+ u64 start_devid = 1;
+ struct btrfs_ioctl_search_args search_args;
+ struct btrfs_ioctl_search_key *search_key = &search_args.key;
+
+ fi_args->num_devices = 0;
+
+ max_items = BTRFS_SEARCH_ARGS_BUFSIZE
+ / (sizeof(struct btrfs_ioctl_search_header)
+ + sizeof(struct btrfs_dev_item));
+
+ search_key->tree_id = BTRFS_CHUNK_TREE_OBJECTID;
+ search_key->min_objectid = BTRFS_DEV_ITEMS_OBJECTID;
+ search_key->max_objectid = BTRFS_DEV_ITEMS_OBJECTID;
+ search_key->min_type = BTRFS_DEV_ITEM_KEY;
+ search_key->max_type = BTRFS_DEV_ITEM_KEY;
+ search_key->min_transid = 0;
+ search_key->max_transid = (u64)-1;
+ search_key->nr_items = max_items;
+ search_key->max_offset = (u64)-1;
+
+again:
+ search_key->min_offset = start_devid;
+
+ ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &search_args);
+ if (ret < 0)
+ return -errno;
+
+ fi_args->num_devices += (u64)search_key->nr_items;
+
+ if (search_key->nr_items == max_items) {
+ start_devid = find_max_id(&search_args,
+ search_key->nr_items) + 1;
+ goto again;
+ }
+
+ /* get the lastest max_id to stay consistent with the num_devices */
+ if (search_key->nr_items == 0)
+ /*
+ * last tree_search returns an empty buf, use the devid of
+ * the last dev_item of the previous tree_search
+ */
+ fi_args->max_id = start_devid - 1;
+ else
+ fi_args->max_id = find_max_id(&search_args,
+ search_key->nr_items);
+
+ return 0;
+}
+
/*
* For a given path, fill in the ioctl fs_ and info_ args.
* If the path is a btrfs mountpoint, fill info for all devices.
@@ -1860,6 +1927,13 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
ret = -errno;
goto out;
}
+
+ /*
+ * The fs_args->num_devices does not include seed devices
+ */
+ ret = correct_fs_info(fd, fi_args);
+ if (ret)
+ goto out;
}
if (!fi_args->num_devices)
--
1.8.1.4
next prev parent reply other threads:[~2014-11-07 2:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-07 2:07 [PATCH] btrfs-progs: skip fs with no seed when build seed/sprout mapping for fi show Gui Hecheng
2014-11-07 2:07 ` [PATCH 1/2] btrfs-progs: remove BUG_ON on num of devices for btrfs " Gui Hecheng
2014-11-07 2:07 ` Gui Hecheng [this message]
2014-11-07 18:16 ` [PATCH 2/2] btrfs-progs: fix wrong num_devices for btrfs fi show with seed devices David Sterba
2014-11-08 1:03 ` anand jain
2014-11-08 19:47 ` Mike Fleetwood
2014-11-10 7:53 ` Gui Hecheng
2014-11-07 17:41 ` [PATCH] btrfs-progs: skip fs with no seed when build seed/sprout mapping for fi show David Sterba
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=1415326063-8838-3-git-send-email-guihc.fnst@cn.fujitsu.com \
--to=guihc.fnst@cn.fujitsu.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).