From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [RFC PATCH 2/2] btrfs-progs: Add userspace support for kernel missing dev detection.
Date: Tue, 6 May 2014 14:33:25 +0800 [thread overview]
Message-ID: <1399358005-9780-2-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1399358005-9780-1-git-send-email-quwenruo@cn.fujitsu.com>
Add userspace support for kernel missing dev detection from dev_info
ioctl.
Now 'btrfs fi show' will auto detect the output format of dev_info ioctl
and use kernel missing dev detection if supported.
Also userspace missing dev detection is used as a fallback method and
when used, a info message will be printed showing 'btrfs dev del missing'
will not work.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-filesystem.c | 29 ++++++++++++++++++++++-------
utils.c | 2 ++
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 306f715..0ff1ca6 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -369,6 +369,7 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
char uuidbuf[BTRFS_UUID_UNPARSED_SIZE];
struct btrfs_ioctl_dev_info_args *tmp_dev_info;
int ret;
+ int new_flag = 0;
ret = add_seen_fsid(fs_info->fsid);
if (ret == -EEXIST)
@@ -389,13 +390,22 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
for (i = 0; i < fs_info->num_devices; i++) {
tmp_dev_info = (struct btrfs_ioctl_dev_info_args *)&dev_info[i];
- /* Add check for missing devices even mounted */
- fd = open((char *)tmp_dev_info->path, O_RDONLY);
- if (fd < 0) {
- missing = 1;
- continue;
+ new_flag = tmp_dev_info->flags & BTRFS_IOCTL_DEV_INFO_FLAG_SET;
+ if (!new_flag) {
+ /* Add check for missing devices even mounted */
+ fd = open((char *)tmp_dev_info->path, O_RDONLY);
+ if (fd < 0) {
+ missing = 1;
+ continue;
+ }
+ close(fd);
+ } else {
+ if (tmp_dev_info->flags &
+ BTRFS_IOCTL_DEV_INFO_MISSING) {
+ missing = 1;
+ continue;
+ }
}
- close(fd);
printf("\tdevid %4llu size %s used %s path %s\n",
tmp_dev_info->devid,
pretty_size(tmp_dev_info->total_bytes),
@@ -403,8 +413,13 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
tmp_dev_info->path);
}
- if (missing)
+ if (missing) {
printf("\t*** Some devices missing\n");
+ if (!new_flag) {
+ printf("\tOlder kernel detected\n");
+ printf("\t'btrfs dev delete missing' may not work\n");
+ }
+ }
printf("\n");
return 0;
}
diff --git a/utils.c b/utils.c
index 3e9c527..230471f 100644
--- a/utils.c
+++ b/utils.c
@@ -1670,6 +1670,8 @@ int get_device_info(int fd, u64 devid,
di_args->devid = devid;
memset(&di_args->uuid, '\0', sizeof(di_args->uuid));
+ /* Clear flags to ensure old kernel returns untouched flags */
+ memset(&di_args->flags, 0, sizeof(di_args->flags));
ret = ioctl(fd, BTRFS_IOC_DEV_INFO, di_args);
return ret ? -errno : 0;
--
1.9.2
next prev parent reply other threads:[~2014-05-06 6:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-06 6:33 [RFC PATCH 1/2] btrfs-progs: Follow kernel changes to add new member of btrfs_ioctl_dev_info_args Qu Wenruo
2014-05-06 6:33 ` Qu Wenruo [this message]
2014-05-21 3:38 ` [RFC PATCH 2/2] btrfs-progs: Add userspace support for kernel missing dev detection Anand Jain
2014-05-21 3:38 ` [RFC PATCH 1/2] btrfs-progs: Follow kernel changes to add new member of btrfs_ioctl_dev_info_args 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=1399358005-9780-2-git-send-email-quwenruo@cn.fujitsu.com \
--to=quwenruo@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).