aboutsummaryrefslogtreecommitdiff
path: root/fs/bcachefs/super-io.c
diff options
context:
space:
mode:
authorGravatar Kent Overstreet <kent.overstreet@linux.dev> 2023-07-10 20:30:04 -0400
committerGravatar Kent Overstreet <kent.overstreet@linux.dev> 2023-10-22 17:10:07 -0400
commitf39d1aca4de011949b1b1c636de3146f3b7c1384 (patch)
tree46691098043c7c43b70c8341d1c36c3e5f9f74b7 /fs/bcachefs/super-io.c
parentbcachefs: Fallocate now checks page cache (diff)
downloadlinux-f39d1aca4de011949b1b1c636de3146f3b7c1384.tar.gz
linux-f39d1aca4de011949b1b1c636de3146f3b7c1384.tar.bz2
linux-f39d1aca4de011949b1b1c636de3146f3b7c1384.zip
bcachefs: Add buffered IO fallback for userspace
In userspace, we want to be able to switch to buffered IO when we're dealing with an image on a filesystem/device that doesn't support the blocksize the filesystem was formatted with. This plumbs through !opts.direct_io -> FMODE_BUFFERED, which will be supported by the shim version of blkdev_get_by_path() in -tools, and it adds a fallback to disable direct IO and retry for userspace. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/super-io.c')
-rw-r--r--fs/bcachefs/super-io.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c
index 6ee1e7bb5eba..deef31a617c4 100644
--- a/fs/bcachefs/super-io.c
+++ b/fs/bcachefs/super-io.c
@@ -662,7 +662,9 @@ int bch2_read_super(const char *path, struct bch_opts *opts,
struct printbuf err = PRINTBUF;
__le64 *i;
int ret;
-
+#ifndef __KERNEL__
+retry:
+#endif
memset(sb, 0, sizeof(*sb));
sb->mode = BLK_OPEN_READ;
sb->have_bio = true;
@@ -670,6 +672,11 @@ int bch2_read_super(const char *path, struct bch_opts *opts,
if (!sb->holder)
return -ENOMEM;
+#ifndef __KERNEL__
+ if (opt_get(*opts, direct_io) == false)
+ sb->mode |= FMODE_BUFFERED;
+#endif
+
if (!opt_get(*opts, noexcl))
sb->mode |= BLK_OPEN_EXCL;
@@ -754,7 +761,13 @@ int bch2_read_super(const char *path, struct bch_opts *opts,
got_super:
if (le16_to_cpu(sb->sb->block_size) << 9 <
- bdev_logical_block_size(sb->bdev)) {
+ bdev_logical_block_size(sb->bdev) &&
+ opt_get(*opts, direct_io)) {
+#ifndef __KERNEL__
+ opt_set(*opts, direct_io, false);
+ bch2_free_super(sb);
+ goto retry;
+#endif
prt_printf(&err, "block size (%u) smaller than device block size (%u)",
le16_to_cpu(sb->sb->block_size) << 9,
bdev_logical_block_size(sb->bdev));