All of lore.kernel.org
 help / color / mirror / Atom feed
From: Naohiro Aota <naohiro.aota@wdc.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>, Naohiro Aota <naohiro.aota@wdc.com>
Subject: [PATCH 5/5] btrfs-progs: use direct-IO for zoned device
Date: Mon, 27 Sep 2021 13:15:54 +0900	[thread overview]
Message-ID: <20210927041554.325884-6-naohiro.aota@wdc.com> (raw)
In-Reply-To: <20210927041554.325884-1-naohiro.aota@wdc.com>

We need to use direct-IO for zoned devices to preserve the write ordering.
Instead of detecting if the device is zoned or not, we simply use direct-IO
for any kind of device (even if emulated zoned mode on a regular device).

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 kernel-shared/disk-io.c | 3 +++
 kernel-shared/volumes.c | 4 ++++
 mkfs/main.c             | 7 ++++++-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c
index dd48599a5f1f..aabeba7821ed 100644
--- a/kernel-shared/disk-io.c
+++ b/kernel-shared/disk-io.c
@@ -1382,6 +1382,9 @@ struct btrfs_fs_info *open_ctree_fs_info(struct open_ctree_flags *ocf)
 	if (!(ocf->flags & OPEN_CTREE_WRITES))
 		oflags = O_RDONLY;
 
+	if ((oflags & O_RDWR) && zoned_model(ocf->filename) == ZONED_HOST_MANAGED)
+		oflags |= O_DIRECT;
+
 	fp = open(ocf->filename, oflags);
 	if (fp < 0) {
 		error("cannot open '%s': %m", ocf->filename);
diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c
index b2a6b04f8e3d..ff4bd0723dbb 100644
--- a/kernel-shared/volumes.c
+++ b/kernel-shared/volumes.c
@@ -455,6 +455,10 @@ int btrfs_open_devices(struct btrfs_fs_info *fs_info,
 			continue;
 		}
 
+		if ((flags & O_RDWR) &&
+		    zoned_model(device->name) == ZONED_HOST_MANAGED)
+			flags |= O_DIRECT;
+
 		fd = open(device->name, flags);
 		if (fd < 0) {
 			ret = -errno;
diff --git a/mkfs/main.c b/mkfs/main.c
index b925c572b2b3..01187763a90c 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -894,6 +894,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
 	int ssd = 0;
 	int zoned = 0;
 	int force_overwrite = 0;
+	int oflags;
 	char *source_dir = NULL;
 	bool source_dir_set = false;
 	bool shrink_rootdir = false;
@@ -1310,12 +1311,16 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
 
 	dev_cnt--;
 
+	oflags = O_RDWR;
+	if (zoned && zoned_model(file) == ZONED_HOST_MANAGED)
+		oflags |= O_DIRECT;
+
 	/*
 	 * Open without O_EXCL so that the problem should not occur by the
 	 * following operation in kernel:
 	 * (btrfs_register_one_device() fails if O_EXCL is on)
 	 */
-	fd = open(file, O_RDWR);
+	fd = open(file, oflags);
 	if (fd < 0) {
 		error("unable to open %s: %m", file);
 		goto error;
-- 
2.33.0


  parent reply	other threads:[~2021-09-27  4:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27  4:15 [PATCH 0/5] btrfs-progs: use direct-IO for zoned device Naohiro Aota
2021-09-27  4:15 ` [PATCH 1/5] btrfs-progs: mkfs: do not set zone size on non-zoned mode Naohiro Aota
2021-09-27  9:19   ` Johannes Thumshirn
2021-09-27  4:15 ` [PATCH 2/5] btrfs-progs: introduce btrfs_pwrite wrapper for pwrite Naohiro Aota
2021-09-27  9:39   ` Johannes Thumshirn
2021-09-27  4:15 ` [PATCH 3/5] btrfs-progs: introduce btrfs_pread wrapper for pread Naohiro Aota
2021-09-27 10:23   ` Johannes Thumshirn
2021-09-27 18:41     ` David Sterba
2021-09-27  4:15 ` [PATCH 4/5] btrfs-progs: temporally set zoned flag for initial tree reading Naohiro Aota
2021-09-27 12:38   ` Johannes Thumshirn
2021-09-27  4:15 ` Naohiro Aota [this message]
2021-09-27 18:48   ` [PATCH 5/5] btrfs-progs: use direct-IO for zoned device David Sterba
2021-09-27 19:26 ` [PATCH 0/5] " David Sterba
2021-09-29  2:21   ` Naohiro Aota
2021-09-29 10:16     ` David Sterba
2021-09-27 21:51 ` David Sterba
2021-09-29  2:24   ` Naohiro Aota
2021-09-29 10:22     ` David Sterba
2021-10-05  6:11       ` Naohiro Aota

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=20210927041554.325884-6-naohiro.aota@wdc.com \
    --to=naohiro.aota@wdc.com \
    --cc=dsterba@suse.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 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.