return inode;
}
+static int fuse_send_lookup(struct fuse_conn *fc, struct fuse_req *req,
+ struct inode *dir, struct dentry *entry,
+ struct fuse_entry_out *outarg, int *version)
+{
+ req->in.h.opcode = FUSE_LOOKUP;
+ req->in.h.ino = dir->i_ino;
+ req->in.numargs = 1;
+ req->in.args[0].size = entry->d_name.len + 1;
+ req->in.args[0].value = entry->d_name.name;
+ req->out.numargs = 1;
+ req->out.args[0].size = sizeof(struct fuse_entry_out);
+ req->out.args[0].value = outarg;
+ request_send(fc, req);
+ *version = req->out.h.unique;
+ return req->out.h.error;
+}
+
static int fuse_do_lookup(struct inode *dir, struct dentry *entry,
struct fuse_entry_out *outarg, int *version)
{
req = fuse_get_request(fc);
if (!req)
return -ERESTARTSYS;
- req->in.h.opcode = FUSE_LOOKUP;
- req->in.h.ino = dir->i_ino;
- req->in.numargs = 1;
- req->in.args[0].size = entry->d_name.len + 1;
- req->in.args[0].value = entry->d_name.name;
- req->out.numargs = 1;
- req->out.args[0].size = sizeof(struct fuse_entry_out);
- req->out.args[0].value = outarg;
- request_send(fc, req);
- *version = req->out.h.unique;
- err = req->out.h.error;
+
+ err = fuse_send_lookup(fc, req, dir, entry, outarg, version);
fuse_put_request(fc, req);
return err;
}
static int fuse_lookup_iget(struct inode *dir, struct dentry *entry,
struct inode **inodep)
{
+ struct fuse_conn *fc = INO_FC(dir);
int err;
struct fuse_entry_out outarg;
int version;
struct inode *inode = NULL;
+ struct fuse_req *req;
+
+ if (entry->d_name.len > FUSE_NAME_MAX)
+ return -ENAMETOOLONG;
+ req = fuse_get_request(fc);
+ if (!req)
+ return -ERESTARTSYS;
- err = fuse_do_lookup(dir, entry, &outarg, &version);
+ err = fuse_send_lookup(fc, req, dir, entry, &outarg, &version);
if (!err) {
inode = fuse_iget(dir->i_sb, outarg.ino, outarg.generation,
&outarg.attr, version);
- if (!inode)
+ if (!inode) {
+ fuse_send_forget(fc, req, outarg.ino, version);
return -ENOMEM;
- } else if (err != -ENOENT)
+ }
+ }
+ fuse_put_request(fc, req);
+ if (err && err != -ENOENT)
return err;
entry->d_time = time_to_jiffies(outarg.entry_valid,
return 0;
}
-static int lookup_new_entry(struct inode *dir, struct dentry *entry,
- struct fuse_entry_out *outarg, int version,
- int mode)
+static int lookup_new_entry(struct fuse_conn *fc, struct fuse_req *req,
+ struct inode *dir, struct dentry *entry,
+ struct fuse_entry_out *outarg, int version,
+ int mode)
{
struct inode *inode;
inode = fuse_iget(dir->i_sb, outarg->ino, outarg->generation,
&outarg->attr, version);
- if (!inode)
+ if (!inode) {
+ fuse_send_forget(fc, req, outarg->ino, version);
return -ENOMEM;
+ }
+ fuse_put_request(fc, req);
/* Don't allow userspace to do really stupid things... */
if ((inode->i_mode ^ mode) & S_IFMT) {
request_send(fc, req);
err = req->out.h.error;
if (!err)
- err = lookup_new_entry(dir, entry, &outarg, req->out.h.unique,
- mode);
- fuse_put_request(fc, req);
+ err = lookup_new_entry(fc, req, dir, entry, &outarg,
+ req->out.h.unique, mode);
+ else
+ fuse_put_request(fc, req);
return err;
}
request_send(fc, req);
err = req->out.h.error;
if (!err)
- err = lookup_new_entry(dir, entry, &outarg, req->out.h.unique,
- S_IFDIR);
- fuse_put_request(fc, req);
+ err = lookup_new_entry(fc, req, dir, entry, &outarg,
+ req->out.h.unique, S_IFDIR);
+ else
+ fuse_put_request(fc, req);
return err;
}
request_send(fc, req);
err = req->out.h.error;
if (!err)
- err = lookup_new_entry(dir, entry, &outarg, req->out.h.unique,
- S_IFLNK);
- fuse_put_request(fc, req);
+ err = lookup_new_entry(fc, req, dir, entry, &outarg,
+ req->out.h.unique, S_IFLNK);
+ else
+ fuse_put_request(fc, req);
return err;
}
if (!err) {
/* Invalidate old entry, so attributes are refreshed */
d_invalidate(entry);
- err = lookup_new_entry(newdir, newent, &outarg,
+ err = lookup_new_entry(fc, req, newdir, newent, &outarg,
req->out.h.unique, inode->i_mode);
- }
- fuse_put_request(fc, req);
+ } else
+ fuse_put_request(fc, req);
return err;
}
/* No op */
}
+void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, ino_t ino,
+ int version)
+{
+ struct fuse_forget_in *inarg = &req->misc.forget_in;
+ inarg->version = version;
+ req->in.h.opcode = FUSE_FORGET;
+ req->in.h.ino = ino;
+ req->in.numargs = 1;
+ req->in.args[0].size = sizeof(struct fuse_forget_in);
+ req->in.args[0].value = inarg;
+ request_send_noreply(fc, req);
+}
+
static void fuse_clear_inode(struct inode *inode)
{
struct fuse_conn *fc = INO_FC(inode);
struct fuse_req *req;
- struct fuse_forget_in *inarg = NULL;
if (fc == NULL)
return;
req = fuse_get_request_nonint(fc);
- inarg = &req->misc.forget_in;
- inarg->version = inode->i_version;
- req->in.h.opcode = FUSE_FORGET;
- req->in.h.ino = inode->i_ino;
- req->in.numargs = 1;
- req->in.args[0].size = sizeof(struct fuse_forget_in);
- req->in.args[0].value = inarg;
- request_send_noreply(fc, req);
+ fuse_send_forget(fc, req, inode->i_ino, inode->i_version);
}
static void fuse_put_super(struct super_block *sb)
static void do_lookup(struct fuse *f, struct fuse_in_header *in, char *name)
{
int res;
+ int res2;
char *path;
struct fuse_entry_out arg;
res = lookup_path(f, in->ino, in->unique, name, path, &arg);
free(path);
}
- send_reply(f, in, res, &arg, sizeof(arg));
+ res2 = send_reply(f, in, res, &arg, sizeof(arg));
+ if (res == 0 && res2 == -ENOENT)
+ destroy_node(f, arg.ino, in->unique);
}
static void do_forget(struct fuse *f, struct fuse_in_header *in,
struct fuse_mknod_in *inarg)
{
int res;
+ int res2;
char *path;
char *name = PARAM(inarg);
struct fuse_entry_out outarg;
}
free(path);
}
- send_reply(f, in, res, &outarg, sizeof(outarg));
+ res2 = send_reply(f, in, res, &outarg, sizeof(outarg));
+ if (res == 0 && res2 == -ENOENT)
+ destroy_node(f, outarg.ino, in->unique);
}
static void do_mkdir(struct fuse *f, struct fuse_in_header *in,
struct fuse_mkdir_in *inarg)
{
int res;
+ int res2;
char *path;
char *name = PARAM(inarg);
struct fuse_entry_out outarg;
}
free(path);
}
- send_reply(f, in, res, &outarg, sizeof(outarg));
+ res2 = send_reply(f, in, res, &outarg, sizeof(outarg));
+ if (res == 0 && res2 == -ENOENT)
+ destroy_node(f, outarg.ino, in->unique);
}
static void do_unlink(struct fuse *f, struct fuse_in_header *in, char *name)
char *link)
{
int res;
+ int res2;
char *path;
struct fuse_entry_out outarg;
}
free(path);
}
- send_reply(f, in, res, &outarg, sizeof(outarg));
+ res2 = send_reply(f, in, res, &outarg, sizeof(outarg));
+ if (res == 0 && res2 == -ENOENT)
+ destroy_node(f, outarg.ino, in->unique);
+
}
static void do_rename(struct fuse *f, struct fuse_in_header *in,
struct fuse_link_in *arg)
{
int res;
+ int res2;
char *oldpath;
char *newpath;
char *name = PARAM(arg);
}
free(oldpath);
}
- send_reply(f, in, res, &outarg, sizeof(outarg));
+ res2 = send_reply(f, in, res, &outarg, sizeof(outarg));
+ if (res == 0 && res2 == -ENOENT)
+ destroy_node(f, outarg.ino, in->unique);
}
static void do_open(struct fuse *f, struct fuse_in_header *in,