Skip to content

Commit 55752a3

Browse files
author
Miklos Szeredi
committed
fuse: multiplex cached/direct_io file operations
This is cleanup, as well as allowing switching between I/O modes while the file is open in the future. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent d4136d6 commit 55752a3

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

fs/fuse/file.c

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include <linux/falloc.h>
2020
#include <linux/uio.h>
2121

22-
static const struct file_operations fuse_direct_io_file_operations;
23-
2422
static int fuse_send_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
2523
int opcode, struct fuse_open_out *outargp)
2624
{
@@ -174,8 +172,6 @@ void fuse_finish_open(struct inode *inode, struct file *file)
174172
struct fuse_file *ff = file->private_data;
175173
struct fuse_conn *fc = get_fuse_conn(inode);
176174

177-
if (ff->open_flags & FOPEN_DIRECT_IO)
178-
file->f_op = &fuse_direct_io_file_operations;
179175
if (!(ff->open_flags & FOPEN_KEEP_CACHE))
180176
invalidate_inode_pages2(inode->i_mapping);
181177
if (ff->open_flags & FOPEN_NONSEEKABLE)
@@ -929,7 +925,7 @@ static int fuse_readpages(struct file *file, struct address_space *mapping,
929925
return err;
930926
}
931927

932-
static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
928+
static ssize_t fuse_cache_read_iter(struct kiocb *iocb, struct iov_iter *to)
933929
{
934930
struct inode *inode = iocb->ki_filp->f_mapping->host;
935931
struct fuse_conn *fc = get_fuse_conn(inode);
@@ -1183,7 +1179,7 @@ static ssize_t fuse_perform_write(struct kiocb *iocb,
11831179
return res > 0 ? res : err;
11841180
}
11851181

1186-
static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
1182+
static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
11871183
{
11881184
struct file *file = iocb->ki_filp;
11891185
struct address_space *mapping = file->f_mapping;
@@ -1486,6 +1482,26 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)
14861482
return res;
14871483
}
14881484

1485+
static ssize_t fuse_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
1486+
{
1487+
struct fuse_file *ff = iocb->ki_filp->private_data;
1488+
1489+
if (!(ff->open_flags & FOPEN_DIRECT_IO))
1490+
return fuse_cache_read_iter(iocb, to);
1491+
else
1492+
return fuse_direct_read_iter(iocb, to);
1493+
}
1494+
1495+
static ssize_t fuse_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
1496+
{
1497+
struct fuse_file *ff = iocb->ki_filp->private_data;
1498+
1499+
if (!(ff->open_flags & FOPEN_DIRECT_IO))
1500+
return fuse_cache_write_iter(iocb, from);
1501+
else
1502+
return fuse_direct_write_iter(iocb, from);
1503+
}
1504+
14891505
static void fuse_writepage_free(struct fuse_conn *fc, struct fuse_req *req)
14901506
{
14911507
int i;
@@ -2129,6 +2145,18 @@ static const struct vm_operations_struct fuse_file_vm_ops = {
21292145

21302146
static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
21312147
{
2148+
struct fuse_file *ff = file->private_data;
2149+
2150+
if (ff->open_flags & FOPEN_DIRECT_IO) {
2151+
/* Can't provide the coherency needed for MAP_SHARED */
2152+
if (vma->vm_flags & VM_MAYSHARE)
2153+
return -ENODEV;
2154+
2155+
invalidate_inode_pages2(file->f_mapping);
2156+
2157+
return generic_file_mmap(file, vma);
2158+
}
2159+
21322160
if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_MAYWRITE))
21332161
fuse_link_write_file(file);
21342162

@@ -2137,17 +2165,6 @@ static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
21372165
return 0;
21382166
}
21392167

2140-
static int fuse_direct_mmap(struct file *file, struct vm_area_struct *vma)
2141-
{
2142-
/* Can't provide the coherency needed for MAP_SHARED */
2143-
if (vma->vm_flags & VM_MAYSHARE)
2144-
return -ENODEV;
2145-
2146-
invalidate_inode_pages2(file->f_mapping);
2147-
2148-
return generic_file_mmap(file, vma);
2149-
}
2150-
21512168
static int convert_fuse_file_lock(struct fuse_conn *fc,
21522169
const struct fuse_file_lock *ffl,
21532170
struct file_lock *fl)
@@ -3164,26 +3181,6 @@ static const struct file_operations fuse_file_operations = {
31643181
.copy_file_range = fuse_copy_file_range,
31653182
};
31663183

3167-
static const struct file_operations fuse_direct_io_file_operations = {
3168-
.llseek = fuse_file_llseek,
3169-
.read_iter = fuse_direct_read_iter,
3170-
.write_iter = fuse_direct_write_iter,
3171-
.mmap = fuse_direct_mmap,
3172-
.open = fuse_open,
3173-
.flush = fuse_flush,
3174-
.release = fuse_release,
3175-
.fsync = fuse_fsync,
3176-
.lock = fuse_file_lock,
3177-
.flock = fuse_file_flock,
3178-
.splice_read = generic_file_splice_read,
3179-
.splice_write = iter_file_splice_write,
3180-
.unlocked_ioctl = fuse_file_ioctl,
3181-
.compat_ioctl = fuse_file_compat_ioctl,
3182-
.poll = fuse_file_poll,
3183-
.fallocate = fuse_file_fallocate,
3184-
.copy_file_range = fuse_copy_file_range,
3185-
};
3186-
31873184
static const struct address_space_operations fuse_file_aops = {
31883185
.readpage = fuse_readpage,
31893186
.writepage = fuse_writepage,

0 commit comments

Comments
 (0)