All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libxfs: detect zoned disks and prevent their raw use
@ 2018-06-15 20:50 Luis R. Rodriguez
  2018-06-15 20:56 ` Bart Van Assche
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Luis R. Rodriguez @ 2018-06-15 20:50 UTC (permalink / raw)
  To: sandeen
  Cc: linux-xfs, snitzer, hare, axboe, mwilck, Luis R. Rodriguez,
	Damien Le Moal, Bart Van Assche

Using raw zoned disks by filesystems requires special handling, only
f2fs currently supports this. All other filesystems do not support
dealing with zoned disks directly.

As such using raw zoned disks is not supported by XFS, to use them you
need to use dm-zoned-tools, format them with dzadm, set the scheduler to
deadline, and then setup a dmsetup with zoned type, and somehow set
this up on every boot to live a semi-happy life for now.

Even if you use dmsetup on every boot, the zoned disk is still exposed,
and a user may still think they have to run mkfs.xfs on it instead
of the /dev/mapper/ disk, and then mount it by mistake.

In either case you may seem to believe your disk works and only eventually
end up with alignmet issues and perhaps lose you data. For instance:

[10869.959501] device-mapper: zoned reclaim: (sda): Align zone 865 wp 28349 to 30842 (wp+2493) blocks failed -5
[10870.014488] sd 0:0:0:0: [sda] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[10870.016137] sd 0:0:0:0: [sda] tag#0 Sense Key : Illegal Request [current]
[10870.017696] sd 0:0:0:0: [sda] tag#0 Add. Sense: Unaligned write command

We have to prevent these mistakes by avoiding mkfs.xfs use on zoned disks.

Note that this not enough yet, if users are on old AHCI controllers,
the disks may not be detected as zoned. More work through udev may be
required to detect this situation old old parent PCI IDs for zoned
disks, and then prevent their use somehow.

If you are stuck on using XFS there a udev rule out there [0], this is
far from perfect, and not fully what we want done upstream on Linux
distributions long term but it should at least help developers for now
enjoy their shiny big fat zoned disks with XFS.

This check should help avoid having folks shoot themselves in the foot
for now with zoned disks. If you make the mistake to use mkfs.xfs
on a zoned disk, you will now get:

 # mkfs.xfs /dev/sda
/dev/sda: zoned disk detected, refer to dm-zoned-tools for how to use with XFS

[0] https://lkml.kernel.org/r/20180614001147.1545-1-mcgrof@kernel.org

Cc: Damien Le Moal <damien.lemoal@wdc.com>
Cc: Bart Van Assche <Bart.VanAssche@wdc.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 libxfs/init.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/libxfs/init.c b/libxfs/init.c
index a65c86c3..cca33ec7 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -98,6 +98,32 @@ libxfs_device_to_fd(dev_t device)
 	/* NOTREACHED */
 }
 
+static int
+is_zoned_disk(char *path)
+{
+	char str[PATH_MAX];
+	char *devname = basename(path);
+	FILE *file;
+	int len;
+
+
+	len = snprintf(str, sizeof(str), "/sys/block/%s/queue/zoned", devname);
+
+	/* Indicates truncation */
+	if (len >= PATH_MAX) {
+		errno = ENAMETOOLONG;
+		return -1;
+	}
+
+	file = fopen(str, "r");
+	if (!file)
+		return 0;
+
+	fclose(file);
+
+	return 1;
+}
+
 /* libxfs_device_open:
  *     open a device and return its device number
  */
@@ -108,6 +134,7 @@ libxfs_device_open(char *path, int creat, int xflags, int setblksize)
 	int		fd, d, flags;
 	int		readonly, dio, excl;
 	struct stat	statb;
+	int ret;
 
 	readonly = (xflags & LIBXFS_ISREADONLY);
 	excl = (xflags & LIBXFS_EXCLUSIVELY) && !creat;
@@ -119,6 +146,20 @@ retry:
 		(dio ? O_DIRECT : 0) | \
 		(excl ? O_EXCL : 0);
 
+	ret = is_zoned_disk(path);
+	if (ret < 0) {
+		fprintf(stderr, _("%s: error opening %s\n"),
+			path, strerror(errno));
+		exit(1);
+	}
+
+	if (ret == 1) {
+		fprintf(stderr,
+_("%s: zoned disk detected, refer to dm-zoned-tools for how to use with XFS\n"),
+			path);
+		exit(1);
+	}
+
 	if ((fd = open(path, flags, 0666)) < 0) {
 		if (errno == EINVAL && --dio == 0)
 			goto retry;
-- 
2.17.1


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

* Re: [PATCH] libxfs: detect zoned disks and prevent their raw use
  2018-06-15 20:50 [PATCH] libxfs: detect zoned disks and prevent their raw use Luis R. Rodriguez
@ 2018-06-15 20:56 ` Bart Van Assche
  2018-06-15 20:59 ` Darrick J. Wong
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Bart Van Assche @ 2018-06-15 20:56 UTC (permalink / raw)
  To: sandeen, mcgrof; +Cc: linux-xfs, hare, mwilck, Damien Le Moal, snitzer, axboe

On Fri, 2018-06-15 at 13:50 -0700, Luis R. Rodriguez wrote:
> +static int
> +is_zoned_disk(char *path)
> +{
> +	char str[PATH_MAX];
> +	char *devname = basename(path);
> +	FILE *file;
> +	int len;
> +
> +
> +	len = snprintf(str, sizeof(str), "/sys/block/%s/queue/zoned", devname);

Have you considered to use asprintf() instead of using snprintf() and a fixed
size buffer?

> +
> +	/* Indicates truncation */
> +	if (len >= PATH_MAX) {
> +		errno = ENAMETOOLONG;
> +		return -1;
> +	}
> +
> +	file = fopen(str, "r");
> +	if (!file)
> +		return 0;
> +
> +	fclose(file);
> +
> +	return 1;
> +}

I think that you have to read the sysfs file and only return 1 for host-managed
drives. Creating a filesystem on top of a host-aware drive should not be forbidden.
Please also rename "is_zoned_disk()" into "is_host_managed()" or so.

Thanks,

Bart.





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

* Re: [PATCH] libxfs: detect zoned disks and prevent their raw use
  2018-06-15 20:50 [PATCH] libxfs: detect zoned disks and prevent their raw use Luis R. Rodriguez
  2018-06-15 20:56 ` Bart Van Assche
@ 2018-06-15 20:59 ` Darrick J. Wong
  2018-06-15 21:48 ` Eric Sandeen
  2018-06-16  0:13 ` Dave Chinner
  3 siblings, 0 replies; 6+ messages in thread
From: Darrick J. Wong @ 2018-06-15 20:59 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: sandeen, linux-xfs, snitzer, hare, axboe, mwilck, Damien Le Moal,
	Bart Van Assche

On Fri, Jun 15, 2018 at 01:50:11PM -0700, Luis R. Rodriguez wrote:
> Using raw zoned disks by filesystems requires special handling, only
> f2fs currently supports this. All other filesystems do not support
> dealing with zoned disks directly.
> 
> As such using raw zoned disks is not supported by XFS, to use them you
> need to use dm-zoned-tools, format them with dzadm, set the scheduler to
> deadline, and then setup a dmsetup with zoned type, and somehow set
> this up on every boot to live a semi-happy life for now.
> 
> Even if you use dmsetup on every boot, the zoned disk is still exposed,
> and a user may still think they have to run mkfs.xfs on it instead
> of the /dev/mapper/ disk, and then mount it by mistake.
> 
> In either case you may seem to believe your disk works and only eventually
> end up with alignmet issues and perhaps lose you data. For instance:
> 
> [10869.959501] device-mapper: zoned reclaim: (sda): Align zone 865 wp 28349 to 30842 (wp+2493) blocks failed -5
> [10870.014488] sd 0:0:0:0: [sda] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
> [10870.016137] sd 0:0:0:0: [sda] tag#0 Sense Key : Illegal Request [current]
> [10870.017696] sd 0:0:0:0: [sda] tag#0 Add. Sense: Unaligned write command
> 
> We have to prevent these mistakes by avoiding mkfs.xfs use on zoned disks.
> 
> Note that this not enough yet, if users are on old AHCI controllers,
> the disks may not be detected as zoned. More work through udev may be
> required to detect this situation old old parent PCI IDs for zoned
> disks, and then prevent their use somehow.
> 
> If you are stuck on using XFS there a udev rule out there [0], this is
> far from perfect, and not fully what we want done upstream on Linux
> distributions long term but it should at least help developers for now
> enjoy their shiny big fat zoned disks with XFS.
> 
> This check should help avoid having folks shoot themselves in the foot
> for now with zoned disks. If you make the mistake to use mkfs.xfs
> on a zoned disk, you will now get:
> 
>  # mkfs.xfs /dev/sda
> /dev/sda: zoned disk detected, refer to dm-zoned-tools for how to use with XFS
> 
> [0] https://lkml.kernel.org/r/20180614001147.1545-1-mcgrof@kernel.org
> 
> Cc: Damien Le Moal <damien.lemoal@wdc.com>
> Cc: Bart Van Assche <Bart.VanAssche@wdc.com>
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> ---
>  libxfs/init.c | 41 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 41 insertions(+)
> 
> diff --git a/libxfs/init.c b/libxfs/init.c
> index a65c86c3..cca33ec7 100644
> --- a/libxfs/init.c
> +++ b/libxfs/init.c
> @@ -98,6 +98,32 @@ libxfs_device_to_fd(dev_t device)
>  	/* NOTREACHED */
>  }
>  
> +static int
> +is_zoned_disk(char *path)
> +{
> +	char str[PATH_MAX];
> +	char *devname = basename(path);
> +	FILE *file;
> +	int len;
> +
> +
> +	len = snprintf(str, sizeof(str), "/sys/block/%s/queue/zoned", devname);
> +
> +	/* Indicates truncation */
> +	if (len >= PATH_MAX) {
> +		errno = ENAMETOOLONG;
> +		return -1;
> +	}
> +
> +	file = fopen(str, "r");
> +	if (!file)
> +		return 0;
> +

Shouldn't we read the *file contents and return 0 if the contents
are 'none'?

$ lsscsi
[0:0:0:0]    disk    ATA      Samsung SSD 850  1B6Q  /dev/sda
$ cat /sys/block/sda/queue/zoned
none

--D

> +	fclose(file);
> +
> +	return 1;
> +}
> +
>  /* libxfs_device_open:
>   *     open a device and return its device number
>   */
> @@ -108,6 +134,7 @@ libxfs_device_open(char *path, int creat, int xflags, int setblksize)
>  	int		fd, d, flags;
>  	int		readonly, dio, excl;
>  	struct stat	statb;
> +	int ret;
>  
>  	readonly = (xflags & LIBXFS_ISREADONLY);
>  	excl = (xflags & LIBXFS_EXCLUSIVELY) && !creat;
> @@ -119,6 +146,20 @@ retry:
>  		(dio ? O_DIRECT : 0) | \
>  		(excl ? O_EXCL : 0);
>  
> +	ret = is_zoned_disk(path);
> +	if (ret < 0) {
> +		fprintf(stderr, _("%s: error opening %s\n"),
> +			path, strerror(errno));
> +		exit(1);
> +	}
> +
> +	if (ret == 1) {
> +		fprintf(stderr,
> +_("%s: zoned disk detected, refer to dm-zoned-tools for how to use with XFS\n"),
> +			path);
> +		exit(1);
> +	}
> +
>  	if ((fd = open(path, flags, 0666)) < 0) {
>  		if (errno == EINVAL && --dio == 0)
>  			goto retry;
> -- 
> 2.17.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] libxfs: detect zoned disks and prevent their raw use
  2018-06-15 20:50 [PATCH] libxfs: detect zoned disks and prevent their raw use Luis R. Rodriguez
  2018-06-15 20:56 ` Bart Van Assche
  2018-06-15 20:59 ` Darrick J. Wong
@ 2018-06-15 21:48 ` Eric Sandeen
  2018-06-15 21:52   ` Luis R. Rodriguez
  2018-06-16  0:13 ` Dave Chinner
  3 siblings, 1 reply; 6+ messages in thread
From: Eric Sandeen @ 2018-06-15 21:48 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: linux-xfs, snitzer, hare, axboe, mwilck, Damien Le Moal, Bart Van Assche



On 6/15/18 3:50 PM, Luis R. Rodriguez wrote:
> +	if (ret == 1) {
> +		fprintf(stderr,
> +_("%s: zoned disk detected, refer to dm-zoned-tools for how to use with XFS\n"),
> +			path);
> +		exit(1);

Sorry for not sending this before V2, but is "dm-zoned-tools" established enough
in the ecosystem at this point to embed it in help text of utilities like this?

(It's not in debian or in fedora, so that message might lead to some head-scratching,
I think)

-Eric

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

* Re: [PATCH] libxfs: detect zoned disks and prevent their raw use
  2018-06-15 21:48 ` Eric Sandeen
@ 2018-06-15 21:52   ` Luis R. Rodriguez
  0 siblings, 0 replies; 6+ messages in thread
From: Luis R. Rodriguez @ 2018-06-15 21:52 UTC (permalink / raw)
  To: Eric Sandeen
  Cc: Luis R. Rodriguez, linux-xfs, snitzer, hare, axboe, mwilck,
	Damien Le Moal, Bart Van Assche

On Fri, Jun 15, 2018 at 04:48:29PM -0500, Eric Sandeen wrote:
> 
> 
> On 6/15/18 3:50 PM, Luis R. Rodriguez wrote:
> > +	if (ret == 1) {
> > +		fprintf(stderr,
> > +_("%s: zoned disk detected, refer to dm-zoned-tools for how to use with XFS\n"),
> > +			path);
> > +		exit(1);
> 
> Sorry for not sending this before V2, but is "dm-zoned-tools" established enough
> in the ecosystem at this point to embed it in help text of utilities like this?
> 
> (It's not in debian or in fedora, so that message might lead to some head-scratching,
> I think)

It *should*, I'll help up clean that project up a bit now with some meta crap which
Debian police may want, but yeah not sure. You're call. Whatever you wish to
print I'm fine with.

AFAICT dmzadm *should* be packaged at least. Long term perhaps lvm2 may re-implement
it, but I can't see why folks should wait for such lofty vaporware.

  Luis

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

* Re: [PATCH] libxfs: detect zoned disks and prevent their raw use
  2018-06-15 20:50 [PATCH] libxfs: detect zoned disks and prevent their raw use Luis R. Rodriguez
                   ` (2 preceding siblings ...)
  2018-06-15 21:48 ` Eric Sandeen
@ 2018-06-16  0:13 ` Dave Chinner
  3 siblings, 0 replies; 6+ messages in thread
From: Dave Chinner @ 2018-06-16  0:13 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: sandeen, linux-xfs, snitzer, hare, axboe, mwilck, Damien Le Moal,
	Bart Van Assche

On Fri, Jun 15, 2018 at 01:50:11PM -0700, Luis R. Rodriguez wrote:
> Using raw zoned disks by filesystems requires special handling, only
> f2fs currently supports this. All other filesystems do not support
> dealing with zoned disks directly.
> 
> As such using raw zoned disks is not supported by XFS, to use them you
> need to use dm-zoned-tools, format them with dzadm, set the scheduler to
> deadline, and then setup a dmsetup with zoned type, and somehow set
> this up on every boot to live a semi-happy life for now.
> 
> Even if you use dmsetup on every boot, the zoned disk is still exposed,
> and a user may still think they have to run mkfs.xfs on it instead
> of the /dev/mapper/ disk, and then mount it by mistake.
> 
> In either case you may seem to believe your disk works and only eventually
> end up with alignmet issues and perhaps lose you data. For instance:
> 
> [10869.959501] device-mapper: zoned reclaim: (sda): Align zone 865 wp 28349 to 30842 (wp+2493) blocks failed -5
> [10870.014488] sd 0:0:0:0: [sda] tag#0 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
> [10870.016137] sd 0:0:0:0: [sda] tag#0 Sense Key : Illegal Request [current]
> [10870.017696] sd 0:0:0:0: [sda] tag#0 Add. Sense: Unaligned write command
> 
> We have to prevent these mistakes by avoiding mkfs.xfs use on zoned disks.
> 
> Note that this not enough yet, if users are on old AHCI controllers,
> the disks may not be detected as zoned. More work through udev may be
> required to detect this situation old old parent PCI IDs for zoned
> disks, and then prevent their use somehow.
> 
> If you are stuck on using XFS there a udev rule out there [0], this is
> far from perfect, and not fully what we want done upstream on Linux
> distributions long term but it should at least help developers for now
> enjoy their shiny big fat zoned disks with XFS.
> 
> This check should help avoid having folks shoot themselves in the foot
> for now with zoned disks. If you make the mistake to use mkfs.xfs
> on a zoned disk, you will now get:
> 
>  # mkfs.xfs /dev/sda
> /dev/sda: zoned disk detected, refer to dm-zoned-tools for how to use with XFS

Shouldn't this code be put in libblkid() so it's available to all
filesystem tools, not just XFS?

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

end of thread, other threads:[~2018-06-16  0:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-15 20:50 [PATCH] libxfs: detect zoned disks and prevent their raw use Luis R. Rodriguez
2018-06-15 20:56 ` Bart Van Assche
2018-06-15 20:59 ` Darrick J. Wong
2018-06-15 21:48 ` Eric Sandeen
2018-06-15 21:52   ` Luis R. Rodriguez
2018-06-16  0:13 ` Dave Chinner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.