aboutsummaryrefslogtreecommitdiff
path: root/fs/fuse/dir.c
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2005-11-07 00:59:51 -0800
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-07 07:53:42 -0800
commitfd72faac95d7e47610e981d7ed7b3c1529e55c88 (patch)
tree65cde1eb6958f410c4b4c72e322fd59db463150f /fs/fuse/dir.c
parent31d40d74b402a6fa18a006fb3745f64609f35b77 (diff)
[PATCH] FUSE: atomic create+open
This patch adds an atomic create+open operation. This does not yet work if the file type changes between lookup and create+open, but solves the permission checking problems for the separte create and open methods. Signed-off-by: Miklos Szeredi <miklos@szeredi.hu> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'fs/fuse/dir.c')
-rw-r--r--fs/fuse/dir.c106
1 files changed, 105 insertions, 1 deletions
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 4bc1afcc476..83be119ef06 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -13,6 +13,7 @@
#include <linux/gfp.h>
#include <linux/sched.h>
#include <linux/namei.h>
+#include <linux/mount.h>
static inline unsigned long time_to_jiffies(unsigned long sec,
unsigned long nsec)
@@ -134,6 +135,101 @@ static void fuse_invalidate_entry(struct dentry *entry)
entry->d_time = jiffies - 1;
}
+static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
+ struct nameidata *nd)
+{
+ int err;
+ struct inode *inode;
+ struct fuse_conn *fc = get_fuse_conn(dir);
+ struct fuse_req *req;
+ struct fuse_open_in inarg;
+ struct fuse_open_out outopen;
+ struct fuse_entry_out outentry;
+ struct fuse_inode *fi;
+ struct fuse_file *ff;
+ struct file *file;
+ int flags = nd->intent.open.flags - 1;
+
+ err = -ENOSYS;
+ if (fc->no_create)
+ goto out;
+
+ err = -ENAMETOOLONG;
+ if (entry->d_name.len > FUSE_NAME_MAX)
+ goto out;
+
+ err = -EINTR;
+ req = fuse_get_request(fc);
+ if (!req)
+ goto out;
+
+ ff = fuse_file_alloc();
+ if (!ff)
+ goto out_put_request;
+
+ flags &= ~O_NOCTTY;
+ memset(&inarg, 0, sizeof(inarg));
+ inarg.flags = flags;
+ inarg.mode = mode;
+ req->in.h.opcode = FUSE_CREATE;
+ req->in.h.nodeid = get_node_id(dir);
+ req->inode = dir;
+ req->in.numargs = 2;
+ req->in.args[0].size = sizeof(inarg);
+ req->in.args[0].value = &inarg;
+ req->in.args[1].size = entry->d_name.len + 1;
+ req->in.args[1].value = entry->d_name.name;
+ req->out.numargs = 2;
+ req->out.args[0].size = sizeof(outentry);
+ req->out.args[0].value = &outentry;
+ req->out.args[1].size = sizeof(outopen);
+ req->out.args[1].value = &outopen;
+ request_send(fc, req);
+ err = req->out.h.error;
+ if (err) {
+ if (err == -ENOSYS)
+ fc->no_create = 1;
+ goto out_free_ff;
+ }
+
+ err = -EIO;
+ if (!S_ISREG(outentry.attr.mode))
+ goto out_free_ff;
+
+ inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
+ &outentry.attr);
+ err = -ENOMEM;
+ if (!inode) {
+ flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
+ ff->fh = outopen.fh;
+ fuse_send_release(fc, ff, outentry.nodeid, NULL, flags, 0);
+ goto out_put_request;
+ }
+ fuse_put_request(fc, req);
+ entry->d_time = time_to_jiffies(outentry.entry_valid,
+ outentry.entry_valid_nsec);
+ fi = get_fuse_inode(inode);
+ fi->i_time = time_to_jiffies(outentry.attr_valid,
+ outentry.attr_valid_nsec);
+
+ d_instantiate(entry, inode);
+ file = lookup_instantiate_filp(nd, entry, generic_file_open);
+ if (IS_ERR(file)) {
+ ff->fh = outopen.fh;
+ fuse_send_release(fc, ff, outentry.nodeid, inode, flags, 0);
+ return PTR_ERR(file);
+ }
+ fuse_finish_open(inode, file, ff, &outopen);
+ return 0;
+
+ out_free_ff:
+ fuse_file_free(ff);
+ out_put_request:
+ fuse_put_request(fc, req);
+ out:
+ return err;
+}
+
static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
struct inode *dir, struct dentry *entry,
int mode)
@@ -208,6 +304,12 @@ static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode,
static int fuse_create(struct inode *dir, struct dentry *entry, int mode,
struct nameidata *nd)
{
+ if (nd && (nd->flags & LOOKUP_CREATE)) {
+ int err = fuse_create_open(dir, entry, mode, nd);
+ if (err != -ENOSYS)
+ return err;
+ /* Fall back on mknod */
+ }
return fuse_mknod(dir, entry, mode, 0);
}
@@ -767,7 +869,9 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
struct nameidata *nd)
{
struct inode *inode;
- int err = fuse_lookup_iget(dir, entry, &inode);
+ int err;
+
+ err = fuse_lookup_iget(dir, entry, &inode);
if (err)
return ERR_PTR(err);
if (inode && S_ISDIR(inode->i_mode)) {