aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ceph
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2011-07-26 14:28:11 -0400
committerSage Weil <sage@newdream.net>2011-07-26 14:28:11 -0400
commit468640e32c7f6bfdaaa011095cc388786755d159 (patch)
treebeb059d860c2ca39cda9ca3aa45603025655e1a6 /fs/ceph
parent9bae113a085b790de384bf86f09e15b42a65a985 (diff)
ceph: fix ceph_lookup_open intent usage
We weren't properly calling lookup_instantiate_filp when setting up the lookup intent, which could lead to file leakage on errors. So: - use separate helper for the hidden snapdir translation, immediately following the mds request - use ceph_finish_lookup for the final dentry/return value dance in the exit path - lookup_instantiate_filp on success Reported-by: Al Viro <viro@ZenIV.linux.org.uk> Reviewed-by: Yehuda Sadeh <yehuda@hq.newdream.net> Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph')
-rw-r--r--fs/ceph/dir.c31
-rw-r--r--fs/ceph/file.c23
-rw-r--r--fs/ceph/super.h2
3 files changed, 37 insertions, 19 deletions
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 53b441fe78f1..f39a409db0ea 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -482,18 +482,10 @@ static loff_t ceph_dir_llseek(struct file *file, loff_t offset, int origin)
482} 482}
483 483
484/* 484/*
485 * Process result of a lookup/open request. 485 * Handle lookups for the hidden .snap directory.
486 *
487 * Mainly, make sure we return the final req->r_dentry (if it already
488 * existed) in place of the original VFS-provided dentry when they
489 * differ.
490 *
491 * Gracefully handle the case where the MDS replies with -ENOENT and
492 * no trace (which it may do, at its discretion, e.g., if it doesn't
493 * care to issue a lease on the negative dentry).
494 */ 486 */
495struct dentry *ceph_finish_lookup(struct ceph_mds_request *req, 487int ceph_handle_snapdir(struct ceph_mds_request *req,
496 struct dentry *dentry, int err) 488 struct dentry *dentry, int err)
497{ 489{
498 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb); 490 struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
499 struct inode *parent = dentry->d_parent->d_inode; 491 struct inode *parent = dentry->d_parent->d_inode;
@@ -510,7 +502,23 @@ struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
510 d_add(dentry, inode); 502 d_add(dentry, inode);
511 err = 0; 503 err = 0;
512 } 504 }
505 return err;
506}
513 507
508/*
509 * Figure out final result of a lookup/open request.
510 *
511 * Mainly, make sure we return the final req->r_dentry (if it already
512 * existed) in place of the original VFS-provided dentry when they
513 * differ.
514 *
515 * Gracefully handle the case where the MDS replies with -ENOENT and
516 * no trace (which it may do, at its discretion, e.g., if it doesn't
517 * care to issue a lease on the negative dentry).
518 */
519struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
520 struct dentry *dentry, int err)
521{
514 if (err == -ENOENT) { 522 if (err == -ENOENT) {
515 /* no trace? */ 523 /* no trace? */
516 err = 0; 524 err = 0;
@@ -605,6 +613,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
605 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE); 613 req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE);
606 req->r_locked_dir = dir; 614 req->r_locked_dir = dir;
607 err = ceph_mdsc_do_request(mdsc, NULL, req); 615 err = ceph_mdsc_do_request(mdsc, NULL, req);
616 err = ceph_handle_snapdir(req, dentry, err);
608 dentry = ceph_finish_lookup(req, dentry, err); 617 dentry = ceph_finish_lookup(req, dentry, err);
609 ceph_mdsc_put_request(req); /* will dput(dentry) */ 618 ceph_mdsc_put_request(req); /* will dput(dentry) */
610 dout("lookup result=%p\n", dentry); 619 dout("lookup result=%p\n", dentry);
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index e0115eb4e9ba..f34d47d66e7c 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -223,8 +223,9 @@ struct dentry *ceph_lookup_open(struct inode *dir, struct dentry *dentry,
223{ 223{
224 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb); 224 struct ceph_fs_client *fsc = ceph_sb_to_client(dir->i_sb);
225 struct ceph_mds_client *mdsc = fsc->mdsc; 225 struct ceph_mds_client *mdsc = fsc->mdsc;
226 struct file *file = nd->intent.open.file; 226 struct file *file;
227 struct ceph_mds_request *req; 227 struct ceph_mds_request *req;
228 struct dentry *ret;
228 int err; 229 int err;
229 int flags = nd->intent.open.flags - 1; /* silly vfs! */ 230 int flags = nd->intent.open.flags - 1; /* silly vfs! */
230 231
@@ -245,15 +246,21 @@ struct dentry *ceph_lookup_open(struct inode *dir, struct dentry *dentry,
245 err = ceph_mdsc_do_request(mdsc, 246 err = ceph_mdsc_do_request(mdsc,
246 (flags & (O_CREAT|O_TRUNC)) ? dir : NULL, 247 (flags & (O_CREAT|O_TRUNC)) ? dir : NULL,
247 req); 248 req);
248 dentry = ceph_finish_lookup(req, dentry, err); 249 err = ceph_handle_snapdir(req, dentry, err);
249 if (!err && (flags & O_CREAT) && !req->r_reply_info.head->is_dentry) 250 if (err)
251 goto out;
252 if ((flags & O_CREAT) && !req->r_reply_info.head->is_dentry)
250 err = ceph_handle_notrace_create(dir, dentry); 253 err = ceph_handle_notrace_create(dir, dentry);
251 if (!err) 254 if (err)
252 err = ceph_init_file(req->r_dentry->d_inode, file, 255 goto out;
253 req->r_fmode); 256 file = lookup_instantiate_filp(nd, req->r_dentry, ceph_open);
257 if (IS_ERR(file))
258 err = PTR_ERR(file);
259out:
260 ret = ceph_finish_lookup(req, dentry, err);
254 ceph_mdsc_put_request(req); 261 ceph_mdsc_put_request(req);
255 dout("ceph_lookup_open result=%p\n", dentry); 262 dout("ceph_lookup_open result=%p\n", ret);
256 return dentry; 263 return ret;
257} 264}
258 265
259int ceph_release(struct inode *inode, struct file *file) 266int ceph_release(struct inode *inode, struct file *file)
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index a8a273320241..c24891a5bec2 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -791,6 +791,8 @@ extern const struct dentry_operations ceph_dentry_ops, ceph_snap_dentry_ops,
791 ceph_snapdir_dentry_ops; 791 ceph_snapdir_dentry_ops;
792 792
793extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry); 793extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry);
794extern int ceph_handle_snapdir(struct ceph_mds_request *req,
795 struct dentry *dentry, int err);
794extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req, 796extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
795 struct dentry *dentry, int err); 797 struct dentry *dentry, int err);
796 798