diff mbox series

[5/5] btrfs-progs: use direct-IO for zoned device

Message ID 20210927041554.325884-6-naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: use direct-IO for zoned device | expand

Commit Message

Naohiro Aota Sept. 27, 2021, 4:15 a.m. UTC
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(-)

Comments

David Sterba Sept. 27, 2021, 6:48 p.m. UTC | #1
On Mon, Sep 27, 2021 at 01:15:54PM +0900, Naohiro Aota wrote:
> 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).

I think this should be ok, we don't want to mix direct io and buffered
writes and both main device opening wrappers do that. As long as it's
abstracted like that we don't need any special detection or flags in the
callers. I was thinking about adding one to open_ctree_flags but that
does not seem necessary.
diff mbox series

Patch

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;