From c8bec83e307f28751c433ba1d3f648429fb5a34c Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 10 Jul 2023 20:31:34 -0400 Subject: Update bcachefs sources to e14d7c7195 bcachefs: Compression levels Signed-off-by: Kent Overstreet --- linux/blkdev.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'linux/blkdev.c') diff --git a/linux/blkdev.c b/linux/blkdev.c index 45b03fba..ea901a46 100644 --- a/linux/blkdev.c +++ b/linux/blkdev.c @@ -183,16 +183,19 @@ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, else if (mode & FMODE_WRITE) flags = O_WRONLY; + if (!(mode & FMODE_BUFFERED)) + flags |= O_DIRECT; + #if 0 /* using O_EXCL doesn't work with opening twice for an O_SYNC fd: */ if (mode & FMODE_EXCL) flags |= O_EXCL; #endif - buffered_fd = open(path, flags); + buffered_fd = open(path, flags & ~O_DIRECT); if (buffered_fd < 0) return ERR_PTR(-errno); - fd = open(path, flags|O_DIRECT); + fd = open(path, flags); if (fd < 0) fd = dup(buffered_fd); if (fd < 0) { @@ -200,9 +203,9 @@ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, return ERR_PTR(-errno); } - sync_fd = open(path, flags|O_DIRECT|O_SYNC); + sync_fd = open(path, flags|O_SYNC); if (sync_fd < 0) - sync_fd = open(path, flags|O_SYNC); + sync_fd = open(path, (flags & ~O_DIRECT)|O_SYNC); if (sync_fd < 0) { close(fd); close(buffered_fd); -- cgit v1.2.3