Commit aa60cfc3 authored by Jeff Layton's avatar Jeff Layton Committed by Ilya Dryomov

ceph: don't use d_add in ceph_handle_snapdir

It's possible ceph_get_snapdir could end up finding a (disconnected)
inode that already exists in the cache. Change the prototype for
ceph_handle_snapdir to return a dentry pointer and have it use
d_splice_alias so we don't end up with an aliased dentry in the cache.
Reported-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent d3c51ae1
...@@ -667,7 +667,7 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int whence) ...@@ -667,7 +667,7 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int whence)
/* /*
* Handle lookups for the hidden .snap directory. * Handle lookups for the hidden .snap directory.
*/ */
int ceph_handle_snapdir(struct ceph_mds_request *req, struct dentry *ceph_handle_snapdir(struct ceph_mds_request *req,
struct dentry *dentry, int err) struct dentry *dentry, int err)
{ {
struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb); struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
...@@ -676,16 +676,17 @@ int ceph_handle_snapdir(struct ceph_mds_request *req, ...@@ -676,16 +676,17 @@ int ceph_handle_snapdir(struct ceph_mds_request *req,
/* .snap dir? */ /* .snap dir? */
if (err == -ENOENT && if (err == -ENOENT &&
ceph_snap(parent) == CEPH_NOSNAP && ceph_snap(parent) == CEPH_NOSNAP &&
strcmp(dentry->d_name.name, strcmp(dentry->d_name.name, fsc->mount_options->snapdir_name) == 0) {
fsc->mount_options->snapdir_name) == 0) { struct dentry *res;
struct inode *inode = ceph_get_snapdir(parent); struct inode *inode = ceph_get_snapdir(parent);
dout("ENOENT on snapdir %p '%pd', linking to snapdir %p\n",
dentry, dentry, inode); res = d_splice_alias(inode, dentry);
BUG_ON(!d_unhashed(dentry)); dout("ENOENT on snapdir %p '%pd', linking to snapdir %p. Spliced dentry %p\n",
d_add(dentry, inode); dentry, dentry, inode, res);
err = 0; if (res)
dentry = res;
} }
return err; return dentry;
} }
/* /*
...@@ -741,6 +742,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, ...@@ -741,6 +742,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(dir->i_sb); struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(dir->i_sb);
struct ceph_mds_request *req; struct ceph_mds_request *req;
struct dentry *res;
int op; int op;
int mask; int mask;
int err; int err;
...@@ -791,7 +793,13 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry, ...@@ -791,7 +793,13 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
req->r_parent = dir; req->r_parent = dir;
set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
err = ceph_mdsc_do_request(mdsc, NULL, req); err = ceph_mdsc_do_request(mdsc, NULL, req);
err = ceph_handle_snapdir(req, dentry, err); res = ceph_handle_snapdir(req, dentry, err);
if (IS_ERR(res)) {
err = PTR_ERR(res);
} else {
dentry = res;
err = 0;
}
dentry = ceph_finish_lookup(req, dentry, err); dentry = ceph_finish_lookup(req, dentry, err);
ceph_mdsc_put_request(req); /* will dput(dentry) */ ceph_mdsc_put_request(req); /* will dput(dentry) */
dout("lookup result=%p\n", dentry); dout("lookup result=%p\n", dentry);
......
...@@ -739,9 +739,12 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, ...@@ -739,9 +739,12 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
err = ceph_mdsc_do_request(mdsc, err = ceph_mdsc_do_request(mdsc,
(flags & (O_CREAT|O_TRUNC)) ? dir : NULL, (flags & (O_CREAT|O_TRUNC)) ? dir : NULL,
req); req);
err = ceph_handle_snapdir(req, dentry, err); dentry = ceph_handle_snapdir(req, dentry, err);
if (err) if (IS_ERR(dentry)) {
err = PTR_ERR(dentry);
goto out_req; goto out_req;
}
err = 0;
if ((flags & O_CREAT) && !req->r_reply_info.head->is_dentry) if ((flags & O_CREAT) && !req->r_reply_info.head->is_dentry)
err = ceph_handle_notrace_create(dir, dentry); err = ceph_handle_notrace_create(dir, dentry);
......
...@@ -1193,7 +1193,7 @@ extern const struct dentry_operations ceph_dentry_ops; ...@@ -1193,7 +1193,7 @@ extern const struct dentry_operations ceph_dentry_ops;
extern loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order); extern loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order);
extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry); extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry);
extern int ceph_handle_snapdir(struct ceph_mds_request *req, extern struct dentry *ceph_handle_snapdir(struct ceph_mds_request *req,
struct dentry *dentry, int err); struct dentry *dentry, int err);
extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req, extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
struct dentry *dentry, int err); struct dentry *dentry, int err);
......
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