Commit c7b7143c authored by Miklos Szeredi's avatar Miklos Szeredi

fuse: clean up args in fuse_finish_open() and fuse_release_fill()

Move setting ff->fh, ff->nodeid and file->private_data outside
fuse_finish_open().  Add ->open_flags member to struct fuse_file.

This simplifies the argument passing to fuse_finish_open() and
fuse_release_fill(), and paves the way for creating an open helper
that doesn't need an inode pointer.
Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
parent 2106cb18
...@@ -365,9 +365,9 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, ...@@ -365,9 +365,9 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
* Synchronous release for the case when something goes wrong in CREATE_OPEN * Synchronous release for the case when something goes wrong in CREATE_OPEN
*/ */
static void fuse_sync_release(struct fuse_conn *fc, struct fuse_file *ff, static void fuse_sync_release(struct fuse_conn *fc, struct fuse_file *ff,
u64 nodeid, int flags) int flags)
{ {
fuse_release_fill(ff, nodeid, flags, FUSE_RELEASE); fuse_release_fill(ff, flags, FUSE_RELEASE);
ff->reserved_req->force = 1; ff->reserved_req->force = 1;
fuse_request_send(fc, ff->reserved_req); fuse_request_send(fc, ff->reserved_req);
fuse_put_request(fc, ff->reserved_req); fuse_put_request(fc, ff->reserved_req);
...@@ -445,12 +445,14 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode, ...@@ -445,12 +445,14 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
goto out_free_ff; goto out_free_ff;
fuse_put_request(fc, req); fuse_put_request(fc, req);
ff->fh = outopen.fh;
ff->nodeid = outentry.nodeid;
ff->open_flags = outopen.open_flags;
inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation, inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
&outentry.attr, entry_attr_timeout(&outentry), 0); &outentry.attr, entry_attr_timeout(&outentry), 0);
if (!inode) { if (!inode) {
flags &= ~(O_CREAT | O_EXCL | O_TRUNC); flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
ff->fh = outopen.fh; fuse_sync_release(fc, ff, flags);
fuse_sync_release(fc, ff, outentry.nodeid, flags);
fuse_send_forget(fc, forget_req, outentry.nodeid, 1); fuse_send_forget(fc, forget_req, outentry.nodeid, 1);
return -ENOMEM; return -ENOMEM;
} }
...@@ -460,11 +462,11 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode, ...@@ -460,11 +462,11 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
fuse_invalidate_attr(dir); fuse_invalidate_attr(dir);
file = lookup_instantiate_filp(nd, entry, generic_file_open); file = lookup_instantiate_filp(nd, entry, generic_file_open);
if (IS_ERR(file)) { if (IS_ERR(file)) {
ff->fh = outopen.fh; fuse_sync_release(fc, ff, flags);
fuse_sync_release(fc, ff, outentry.nodeid, flags);
return PTR_ERR(file); return PTR_ERR(file);
} }
fuse_finish_open(inode, file, ff, &outopen); file->private_data = fuse_file_get(ff);
fuse_finish_open(inode, file);
return 0; return 0;
out_free_ff: out_free_ff:
......
...@@ -79,7 +79,7 @@ void fuse_file_free(struct fuse_file *ff) ...@@ -79,7 +79,7 @@ void fuse_file_free(struct fuse_file *ff)
kfree(ff); kfree(ff);
} }
static struct fuse_file *fuse_file_get(struct fuse_file *ff) struct fuse_file *fuse_file_get(struct fuse_file *ff)
{ {
atomic_inc(&ff->count); atomic_inc(&ff->count);
return ff; return ff;
...@@ -102,18 +102,16 @@ static void fuse_file_put(struct fuse_file *ff) ...@@ -102,18 +102,16 @@ static void fuse_file_put(struct fuse_file *ff)
} }
} }
void fuse_finish_open(struct inode *inode, struct file *file, void fuse_finish_open(struct inode *inode, struct file *file)
struct fuse_file *ff, struct fuse_open_out *outarg)
{ {
if (outarg->open_flags & FOPEN_DIRECT_IO) struct fuse_file *ff = file->private_data;
if (ff->open_flags & FOPEN_DIRECT_IO)
file->f_op = &fuse_direct_io_file_operations; file->f_op = &fuse_direct_io_file_operations;
if (!(outarg->open_flags & FOPEN_KEEP_CACHE)) if (!(ff->open_flags & FOPEN_KEEP_CACHE))
invalidate_inode_pages2(inode->i_mapping); invalidate_inode_pages2(inode->i_mapping);
if (outarg->open_flags & FOPEN_NONSEEKABLE) if (ff->open_flags & FOPEN_NONSEEKABLE)
nonseekable_open(inode, file); nonseekable_open(inode, file);
ff->fh = outarg->fh;
ff->nodeid = get_node_id(inode);
file->private_data = fuse_file_get(ff);
} }
int fuse_open_common(struct inode *inode, struct file *file, int isdir) int fuse_open_common(struct inode *inode, struct file *file, int isdir)
...@@ -141,13 +139,17 @@ int fuse_open_common(struct inode *inode, struct file *file, int isdir) ...@@ -141,13 +139,17 @@ int fuse_open_common(struct inode *inode, struct file *file, int isdir)
else { else {
if (isdir) if (isdir)
outarg.open_flags &= ~FOPEN_DIRECT_IO; outarg.open_flags &= ~FOPEN_DIRECT_IO;
fuse_finish_open(inode, file, ff, &outarg); ff->fh = outarg.fh;
ff->nodeid = get_node_id(inode);
ff->open_flags = outarg.open_flags;
file->private_data = fuse_file_get(ff);
fuse_finish_open(inode, file);
} }
return err; return err;
} }
void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode) void fuse_release_fill(struct fuse_file *ff, int flags, int opcode)
{ {
struct fuse_req *req = ff->reserved_req; struct fuse_req *req = ff->reserved_req;
struct fuse_release_in *inarg = &req->misc.release.in; struct fuse_release_in *inarg = &req->misc.release.in;
...@@ -155,7 +157,7 @@ void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode) ...@@ -155,7 +157,7 @@ void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode)
inarg->fh = ff->fh; inarg->fh = ff->fh;
inarg->flags = flags; inarg->flags = flags;
req->in.h.opcode = opcode; req->in.h.opcode = opcode;
req->in.h.nodeid = nodeid; req->in.h.nodeid = ff->nodeid;
req->in.numargs = 1; req->in.numargs = 1;
req->in.args[0].size = sizeof(struct fuse_release_in); req->in.args[0].size = sizeof(struct fuse_release_in);
req->in.args[0].value = inarg; req->in.args[0].value = inarg;
...@@ -174,7 +176,7 @@ int fuse_release_common(struct inode *inode, struct file *file, int isdir) ...@@ -174,7 +176,7 @@ int fuse_release_common(struct inode *inode, struct file *file, int isdir)
fc = get_fuse_conn(inode); fc = get_fuse_conn(inode);
req = ff->reserved_req; req = ff->reserved_req;
fuse_release_fill(ff, get_node_id(inode), file->f_flags, fuse_release_fill(ff, file->f_flags,
isdir ? FUSE_RELEASEDIR : FUSE_RELEASE); isdir ? FUSE_RELEASEDIR : FUSE_RELEASE);
/* Hold vfsmount and dentry until release is finished */ /* Hold vfsmount and dentry until release is finished */
......
...@@ -119,6 +119,9 @@ struct fuse_file { ...@@ -119,6 +119,9 @@ struct fuse_file {
/** Refcount */ /** Refcount */
atomic_t count; atomic_t count;
/** FOPEN_* flags returned by open */
u32 open_flags;
/** Entry on inode's write_files list */ /** Entry on inode's write_files list */
struct list_head write_entry; struct list_head write_entry;
...@@ -528,12 +531,12 @@ void fuse_read_fill(struct fuse_req *req, struct file *file, ...@@ -528,12 +531,12 @@ void fuse_read_fill(struct fuse_req *req, struct file *file,
int fuse_open_common(struct inode *inode, struct file *file, int isdir); int fuse_open_common(struct inode *inode, struct file *file, int isdir);
struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
struct fuse_file *fuse_file_get(struct fuse_file *ff);
void fuse_file_free(struct fuse_file *ff); void fuse_file_free(struct fuse_file *ff);
void fuse_finish_open(struct inode *inode, struct file *file, void fuse_finish_open(struct inode *inode, struct file *file);
struct fuse_file *ff, struct fuse_open_out *outarg);
/** Fill in ff->reserved_req with a RELEASE request */ /** Fill in ff->reserved_req with a RELEASE request */
void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode); void fuse_release_fill(struct fuse_file *ff, int flags, int opcode);
/** /**
* Send RELEASE or RELEASEDIR request * Send RELEASE or RELEASEDIR request
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment