linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@kernel.org>
To: sandeen@sandeen.net
Cc: linux-xfs@vger.kernel.org, snitzer@redhat.com, hare@suse.de,
	axboe@kernel.dk, mwilck@suse.com,
	"Luis R. Rodriguez" <mcgrof@kernel.org>,
	Damien Le Moal <damien.lemoal@wdc.com>,
	Bart Van Assche <Bart.VanAssche@wdc.com>
Subject: [PATCH v2] libxfs: detect host managed zoned disks and prevent their raw use
Date: Fri, 15 Jun 2018 14:31:13 -0700	[thread overview]
Message-ID: <20180615213113.18597-1-mcgrof@kernel.org> (raw)

Using raw host managed zoned disks by filesystems requires special handling,
onlyf2fs currently supports this. No other filesystems supports dealing with
host managed zoned disks directly.

As such using host managed 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 host managed 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 host managed
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
host managed 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 host managed zoned disks. If you make the mistake to use mkfs.xfs
on a host managed zoned disk, you will now get:

 # mkfs.xfs /dev/sda
/dev/sda: host managed 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 | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/libxfs/init.c b/libxfs/init.c
index a65c86c3..68e0864c 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -98,6 +98,47 @@ libxfs_device_to_fd(dev_t device)
 	/* NOTREACHED */
 }
 
+static int
+is_zoned_host_managed(char *path)
+{
+	char str[PATH_MAX];
+	char *devname = basename(path);
+	FILE *file;
+	int len;
+	int ret;
+
+	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;
+
+	memset(str, 0, sizeof(str));
+	ret = fscanf(file, "%s", str);
+	if (ret != 1) {
+		fclose(file);
+		errno = EINVAL;
+		return -1;
+        }
+
+	fclose(file);
+
+	/*
+	 * host-aware zone disks should be supported natively, but not
+	 * host-managed zone disks. They require dm-zoned-tools magic.
+	 */
+	if (strcmp(str, "host-managed") != 0)
+		return 0;
+
+	return 1;
+}
+
 /* libxfs_device_open:
  *     open a device and return its device number
  */
@@ -108,6 +149,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 +161,20 @@ retry:
 		(dio ? O_DIRECT : 0) | \
 		(excl ? O_EXCL : 0);
 
+	ret = is_zoned_host_managed(path);
+	if (ret < 0) {
+		fprintf(stderr, _("%s: error opening %s\n"),
+			path, strerror(errno));
+		exit(1);
+	}
+
+	if (ret == 1) {
+		fprintf(stderr,
+_("%s: host managed 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


                 reply	other threads:[~2018-06-15 21:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180615213113.18597-1-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=Bart.VanAssche@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=damien.lemoal@wdc.com \
    --cc=hare@suse.de \
    --cc=linux-xfs@vger.kernel.org \
    --cc=mwilck@suse.com \
    --cc=sandeen@sandeen.net \
    --cc=snitzer@redhat.com \
    /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).