Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,11 @@ static int fuse_do_readpage(struct file *file, struct page *page)

fuse_read_args_fill(&ia, file, pos, desc.length, FUSE_READ);
res = fuse_simple_request(fm, &ia.ap.args);
if (res < 0)
if (res < 0) {
if (res == -EAGAIN)
res = AOP_TRUNCATED_PAGE;
return res;
}
Comment thread
cding-ddn marked this conversation as resolved.
Resolved
/*
* Short read means EOF. If file size is larger, truncate it
*/
Expand Down Expand Up @@ -2506,6 +2509,57 @@ static void fuse_vma_close(struct vm_area_struct *vma)
mapping_set_error(vma->vm_file->f_mapping, err);
}

/**
* Request a DLM lock from the FUSE server.
*
* This routine is similar to fuse_get_dlm_write_lock(), but it
* does not cache the DLM lock in the kernel.
*/
static int fuse_get_page_mkwrite_lock(struct file *file, loff_t offset, size_t length)
{
struct fuse_file *ff = file->private_data;
struct inode *inode = file_inode(file);
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_mount *fm = ff->fm;

FUSE_ARGS(args);
struct fuse_dlm_lock_in inarg;
struct fuse_dlm_lock_out outarg;
int err;

if (WARN_ON_ONCE((offset & ~PAGE_MASK) || (length & ~PAGE_MASK)))
return -EIO;

memset(&inarg, 0, sizeof(inarg));
inarg.fh = ff->fh;

inarg.offset = offset;
inarg.size = length;
inarg.type = FUSE_DLM_PAGE_MKWRITE;

args.opcode = FUSE_DLM_WB_LOCK;
args.nodeid = get_node_id(inode);
args.in_numargs = 1;
args.in_args[0].size = sizeof(inarg);
args.in_args[0].value = &inarg;
args.out_numargs = 1;
args.out_args[0].size = sizeof(outarg);
args.out_args[0].value = &outarg;
err = fuse_simple_request(fm, &args);
if (err == -ENOSYS) {
fc->dlm = 0;
err = 0;
}

if (!err && outarg.locksize < length) {
/* fuse server is seriously broken */
pr_warn("fuse: dlm lock request for %lu bytes returned %u bytes\n",
Comment thread
bsbernd marked this conversation as resolved.
Resolved
length, outarg.locksize);
fuse_abort_conn(fc);
err = -EINVAL;
}
return err;
}
/*
* Wait for writeback against this page to complete before allowing it
* to be marked dirty again, and hence written back again, possibly
Expand All @@ -2524,7 +2578,18 @@ static void fuse_vma_close(struct vm_area_struct *vma)
static vm_fault_t fuse_page_mkwrite(struct vm_fault *vmf)
{
struct page *page = vmf->page;
struct inode *inode = file_inode(vmf->vma->vm_file);
struct file *file = vmf->vma->vm_file;
struct inode *inode = file_inode(file);
struct fuse_mount *fm = get_fuse_mount(inode);

if (fm->fc->dlm) {
loff_t pos = vmf->pgoff << PAGE_SHIFT;
size_t length = PAGE_SIZE;
int err = fuse_get_page_mkwrite_lock(file, pos, length);
if (err < 0) {
return vmf_error(err);
}
}

file_update_time(vmf->vma->vm_file);
lock_page(page);
Expand Down
2 changes: 1 addition & 1 deletion fs/fuse/fuse_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
EM( FUSE_SYNCFS, "FUSE_SYNCFS") \
EM( FUSE_TMPFILE, "FUSE_TMPFILE") \
EM( FUSE_STATX, "FUSE_STATX") \
EM( FUSE_DLM_WB_LOCK, "FUSE_DLM_WB_LOCK") \
EM( FUSE_DLM_WB_LOCK, "FUSE_DLM_WB_LOCK") \
EMe(CUSE_INIT, "CUSE_INIT")

/*
Expand Down
7 changes: 5 additions & 2 deletions include/uapi/linux/fuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,9 @@ enum fuse_opcode {
FUSE_SYNCFS = 50,
FUSE_TMPFILE = 51,
FUSE_STATX = 52,
FUSE_DLM_WB_LOCK = 53,

/* Operations which have not been merged into upstream */
FUSE_DLM_WB_LOCK = 100,

Comment thread
bsbernd marked this conversation as resolved.
Resolved
/* CUSE specific operations */
CUSE_INIT = 4096,
Expand Down Expand Up @@ -1183,7 +1185,8 @@ struct fuse_supp_groups {
enum fuse_dlm_lock_type {
FUSE_DLM_LOCK_NONE = 0,
FUSE_DLM_LOCK_READ = 1,
FUSE_DLM_LOCK_WRITE = 2
FUSE_DLM_LOCK_WRITE = 2,
FUSE_DLM_PAGE_MKWRITE = 3,
};

/**
Expand Down