diff options
author | Sage Weil <sage@newdream.net> | 2011-07-26 14:28:11 -0400 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2011-07-26 14:28:11 -0400 |
commit | 468640e32c7f6bfdaaa011095cc388786755d159 (patch) | |
tree | beb059d860c2ca39cda9ca3aa45603025655e1a6 /fs/ceph/dir.c | |
parent | 9bae113a085b790de384bf86f09e15b42a65a985 (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/dir.c')
-rw-r--r-- | fs/ceph/dir.c | 31 |
1 files changed, 20 insertions, 11 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 | */ |
495 | struct dentry *ceph_finish_lookup(struct ceph_mds_request *req, | 487 | int 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 | */ | ||
519 | struct 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); |