linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 1/2] btrfs-progs: Follow kernel changes to add new member of btrfs_ioctl_dev_info_args.
@ 2014-05-06  6:33 Qu Wenruo
  2014-05-06  6:33 ` [RFC PATCH 2/2] btrfs-progs: Add userspace support for kernel missing dev detection Qu Wenruo
  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
  0 siblings, 2 replies; 4+ messages in thread
From: Qu Wenruo @ 2014-05-06  6:33 UTC (permalink / raw)
  To: linux-btrfs

Follow the kernel header changes to add new member of
btrfs_ioctl_dev_info_args.

This change will use special bit to keep backward compatibility, so even
on old kernels this will not screw anything up.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 ioctl.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/ioctl.h b/ioctl.h
index 9627e8d..672a3a3 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -156,12 +156,15 @@ struct btrfs_ioctl_dev_replace_args {
 	__u64 spare[64];
 };
 
+#define BTRFS_IOCTL_DEV_INFO_MISSING			(1ULL<<0)
+#define BTRFS_IOCTL_DEV_INFO_FLAG_SET			(1ULL<<63)
 struct btrfs_ioctl_dev_info_args {
 	__u64 devid;				/* in/out */
 	__u8 uuid[BTRFS_UUID_SIZE];		/* in/out */
 	__u64 bytes_used;			/* out */
 	__u64 total_bytes;			/* out */
-	__u64 unused[379];			/* pad to 4k */
+	__u64 flags;				/* out */
+	__u64 unused[378];			/* pad to 4k */
 	__u8 path[BTRFS_DEVICE_PATH_NAME_MAX];	/* out */
 };
 
-- 
1.9.2


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

* [RFC PATCH 2/2] btrfs-progs: Add userspace support for kernel missing dev detection.
  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
  2014-05-21  3:38   ` 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
  1 sibling, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2014-05-06  6:33 UTC (permalink / raw)
  To: linux-btrfs

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


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

* Re: [RFC PATCH 1/2] btrfs-progs: Follow kernel changes to add new member of btrfs_ioctl_dev_info_args.
  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 ` [RFC PATCH 2/2] btrfs-progs: Add userspace support for kernel missing dev detection Qu Wenruo
@ 2014-05-21  3:38 ` Anand Jain
  1 sibling, 0 replies; 4+ messages in thread
From: Anand Jain @ 2014-05-21  3:38 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs


Hi Qu,

in-line below..

On 06/05/14 14:33, Qu Wenruo wrote:
> Follow the kernel header changes to add new member of
> btrfs_ioctl_dev_info_args.
>
> This change will use special bit to keep backward compatibility, so even
> on old kernels this will not screw anything up.
>
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
> ---
>   ioctl.h | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/ioctl.h b/ioctl.h
> index 9627e8d..672a3a3 100644
> --- a/ioctl.h
> +++ b/ioctl.h
> @@ -156,12 +156,15 @@ struct btrfs_ioctl_dev_replace_args {
>   	__u64 spare[64];
>   };
>
> +#define BTRFS_IOCTL_DEV_INFO_MISSING			(1ULL<<0)
> +#define BTRFS_IOCTL_DEV_INFO_FLAG_SET			(1ULL<<63)
>   struct btrfs_ioctl_dev_info_args {
>   	__u64 devid;				/* in/out */
>   	__u8 uuid[BTRFS_UUID_SIZE];		/* in/out */
>   	__u64 bytes_used;			/* out */
>   	__u64 total_bytes;			/* out */
> -	__u64 unused[379];			/* pad to 4k */
> +	__u64 flags;				/* out */
> +	__u64 unused[378];			/* pad to 4k */


  In the long term perspective we would need to revamp the way to
  obtain btrfs_fs_device and btrfs_devices from the kernel.

  one way was proposed ioctl BTRFS_IOC_GET_DEVS [1], which
  used btrfs-control interface (not the mount point) to
  obtain everything of the above two kernel structs.

  the other method discussed was using the sysfs interface.

  So these plans would duplicate any efforts trying to enhance
  current BTRFS_IOC_DEV_INFO ioctl.

[1]
  http://www.spinics.net/lists/linux-btrfs/msg34161.html


>   	__u8 path[BTRFS_DEVICE_PATH_NAME_MAX];	/* out */
>   };
>
>

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

* Re: [RFC PATCH 2/2] btrfs-progs: Add userspace support for kernel missing dev detection.
  2014-05-06  6:33 ` [RFC PATCH 2/2] btrfs-progs: Add userspace support for kernel missing dev detection Qu Wenruo
@ 2014-05-21  3:38   ` Anand Jain
  0 siblings, 0 replies; 4+ messages in thread
From: Anand Jain @ 2014-05-21  3:38 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs; +Cc: David Sterba


Hi Qu,

  First of all. With this patch, we don't need the old btrfs-progs
  workaround fix [1] anymore.  David should back-out if you are ok.

[1]
  commit 206efb60cbe3049e0d44c6da3c1909aeee18f813
  Author: Qu Wenruo <quwenruo@cn.fujitsu.com>
  Date:   Fri Feb 7 15:07:19 2014 +0800

     btrfs-progs: Add missing devices check for mounted btrfs.


more below.


On 05/06/2014 02:33 PM, Qu Wenruo wrote:
> 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;

  This part didn't work until I made this change
----
-       int new_flag = 0;
+       u64 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");
> +		}
> +	}

  we need one good solution - which is to update kernel when we have
  missing disk and we don't need the btrfs-progs workaround fix.
  which means we also don't need the new_flag check as well.

>   	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;
>

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

end of thread, other threads:[~2014-05-21  3:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [RFC PATCH 2/2] btrfs-progs: Add userspace support for kernel missing dev detection Qu Wenruo
2014-05-21  3:38   ` 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

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