aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2012-06-26 13:58:53 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2012-07-22 16:01:29 -0400
commit765927b2d508712d320c8934db963bbe14c3fcec (patch)
tree97acdb14fae285764def396c4ed01d4d5c93e76a /fs
parentbf349a447059656ebe63fb4fd1ccb27ac1da22ad (diff)
switch dentry_open() to struct path, make it grab references itself
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r--fs/autofs4/dev-ioctl.c4
-rw-r--r--fs/cachefiles/rdwr.c8
-rw-r--r--fs/ecryptfs/kthread.c21
-rw-r--r--fs/exportfs/expfs.c13
-rw-r--r--fs/hppfs/hppfs.c20
-rw-r--r--fs/nfsd/vfs.c10
-rw-r--r--fs/notify/fanotify/fanotify_user.c8
-rw-r--r--fs/open.c17
-rw-r--r--fs/xfs/xfs_ioctl.c7
9 files changed, 45 insertions, 63 deletions
diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index aa9103f8f01..abf645c1703 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -257,8 +257,8 @@ static int autofs_dev_ioctl_open_mountpoint(const char *name, dev_t devid)
257 * corresponding to the autofs fs we want to open. 257 * corresponding to the autofs fs we want to open.
258 */ 258 */
259 259
260 filp = dentry_open(path.dentry, path.mnt, O_RDONLY, 260 filp = dentry_open(&path, O_RDONLY, current_cred());
261 current_cred()); 261 path_put(&path);
262 if (IS_ERR(filp)) { 262 if (IS_ERR(filp)) {
263 err = PTR_ERR(filp); 263 err = PTR_ERR(filp);
264 goto out; 264 goto out;
diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
index 0e3c0924cc3..c0353dfac51 100644
--- a/fs/cachefiles/rdwr.c
+++ b/fs/cachefiles/rdwr.c
@@ -891,6 +891,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
891 struct cachefiles_cache *cache; 891 struct cachefiles_cache *cache;
892 mm_segment_t old_fs; 892 mm_segment_t old_fs;
893 struct file *file; 893 struct file *file;
894 struct path path;
894 loff_t pos, eof; 895 loff_t pos, eof;
895 size_t len; 896 size_t len;
896 void *data; 897 void *data;
@@ -916,10 +917,9 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
916 917
917 /* write the page to the backing filesystem and let it store it in its 918 /* write the page to the backing filesystem and let it store it in its
918 * own time */ 919 * own time */
919 dget(object->backer); 920 path.mnt = cache->mnt;
920 mntget(cache->mnt); 921 path.dentry = object->backer;
921 file = dentry_open(object->backer, cache->mnt, O_RDWR, 922 file = dentry_open(&path, O_RDWR, cache->cache_cred);
922 cache->cache_cred);
923 if (IS_ERR(file)) { 923 if (IS_ERR(file)) {
924 ret = PTR_ERR(file); 924 ret = PTR_ERR(file);
925 } else { 925 } else {
diff --git a/fs/ecryptfs/kthread.c b/fs/ecryptfs/kthread.c
index c7d199dc7d2..809e67d05ca 100644
--- a/fs/ecryptfs/kthread.c
+++ b/fs/ecryptfs/kthread.c
@@ -29,8 +29,7 @@
29 29
30struct ecryptfs_open_req { 30struct ecryptfs_open_req {
31 struct file **lower_file; 31 struct file **lower_file;
32 struct dentry *lower_dentry; 32 struct path path;
33 struct vfsmount *lower_mnt;
34 struct completion done; 33 struct completion done;
35 struct list_head kthread_ctl_list; 34 struct list_head kthread_ctl_list;
36}; 35};
@@ -74,10 +73,7 @@ static int ecryptfs_threadfn(void *ignored)
74 struct ecryptfs_open_req, 73 struct ecryptfs_open_req,
75 kthread_ctl_list); 74 kthread_ctl_list);
76 list_del(&req->kthread_ctl_list); 75 list_del(&req->kthread_ctl_list);
77 dget(req->lower_dentry); 76 *req->lower_file = dentry_open(&req->path,
78 mntget(req->lower_mnt);
79 (*req->lower_file) = dentry_open(
80 req->lower_dentry, req->lower_mnt,
81 (O_RDWR | O_LARGEFILE), current_cred()); 77 (O_RDWR | O_LARGEFILE), current_cred());
82 complete(&req->done); 78 complete(&req->done);
83 } 79 }
@@ -140,23 +136,22 @@ int ecryptfs_privileged_open(struct file **lower_file,
140 int flags = O_LARGEFILE; 136 int flags = O_LARGEFILE;
141 int rc = 0; 137 int rc = 0;
142 138
139 init_completion(&req.done);
140 req.lower_file = lower_file;
141 req.path.dentry = lower_dentry;
142 req.path.mnt = lower_mnt;
143
143 /* Corresponding dput() and mntput() are done when the 144 /* Corresponding dput() and mntput() are done when the
144 * lower file is fput() when all eCryptfs files for the inode are 145 * lower file is fput() when all eCryptfs files for the inode are
145 * released. */ 146 * released. */
146 dget(lower_dentry);
147 mntget(lower_mnt);
148 flags |= IS_RDONLY(lower_dentry->d_inode) ? O_RDONLY : O_RDWR; 147 flags |= IS_RDONLY(lower_dentry->d_inode) ? O_RDONLY : O_RDWR;
149 (*lower_file) = dentry_open(lower_dentry, lower_mnt, flags, cred); 148 (*lower_file) = dentry_open(&req.path, flags, cred);
150 if (!IS_ERR(*lower_file)) 149 if (!IS_ERR(*lower_file))
151 goto out; 150 goto out;
152 if ((flags & O_ACCMODE) == O_RDONLY) { 151 if ((flags & O_ACCMODE) == O_RDONLY) {
153 rc = PTR_ERR((*lower_file)); 152 rc = PTR_ERR((*lower_file));
154 goto out; 153 goto out;
155 } 154 }
156 init_completion(&req.done);
157 req.lower_file = lower_file;
158 req.lower_dentry = lower_dentry;
159 req.lower_mnt = lower_mnt;
160 mutex_lock(&ecryptfs_kthread_ctl.mux); 155 mutex_lock(&ecryptfs_kthread_ctl.mux);
161 if (ecryptfs_kthread_ctl.flags & ECRYPTFS_KTHREAD_ZOMBIE) { 156 if (ecryptfs_kthread_ctl.flags & ECRYPTFS_KTHREAD_ZOMBIE) {
162 rc = -EIO; 157 rc = -EIO;
diff --git a/fs/exportfs/expfs.c b/fs/exportfs/expfs.c
index b42063cf1b2..29ab099e3e0 100644
--- a/fs/exportfs/expfs.c
+++ b/fs/exportfs/expfs.c
@@ -19,19 +19,19 @@
19#define dprintk(fmt, args...) do{}while(0) 19#define dprintk(fmt, args...) do{}while(0)
20 20
21 21
22static int get_name(struct vfsmount *mnt, struct dentry *dentry, char *name, 22static int get_name(const struct path *path, char *name, struct dentry *child);
23 struct dentry *child);
24 23
25 24
26static int exportfs_get_name(struct vfsmount *mnt, struct dentry *dir, 25static int exportfs_get_name(struct vfsmount *mnt, struct dentry *dir,
27 char *name, struct dentry *child) 26 char *name, struct dentry *child)
28{ 27{
29 const struct export_operations *nop = dir->d_sb->s_export_op; 28 const struct export_operations *nop = dir->d_sb->s_export_op;
29 struct path path = {.mnt = mnt, .dentry = dir};
30 30
31 if (nop->get_name) 31 if (nop->get_name)
32 return nop->get_name(dir, name, child); 32 return nop->get_name(dir, name, child);
33 else 33 else
34 return get_name(mnt, dir, name, child); 34 return get_name(&path, name, child);
35} 35}
36 36
37/* 37/*
@@ -249,11 +249,10 @@ static int filldir_one(void * __buf, const char * name, int len,
249 * calls readdir on the parent until it finds an entry with 249 * calls readdir on the parent until it finds an entry with
250 * the same inode number as the child, and returns that. 250 * the same inode number as the child, and returns that.
251 */ 251 */
252static int get_name(struct vfsmount *mnt, struct dentry *dentry, 252static int get_name(const struct path *path, char *name, struct dentry *child)
253 char *name, struct dentry *child)
254{ 253{
255 const struct cred *cred = current_cred(); 254 const struct cred *cred = current_cred();
256 struct inode *dir = dentry->d_inode; 255 struct inode *dir = path->dentry->d_inode;
257 int error; 256 int error;
258 struct file *file; 257 struct file *file;
259 struct getdents_callback buffer; 258 struct getdents_callback buffer;
@@ -267,7 +266,7 @@ static int get_name(struct vfsmount *mnt, struct dentry *dentry,
267 /* 266 /*
268 * Open the directory ... 267 * Open the directory ...
269 */ 268 */
270 file = dentry_open(dget(dentry), mntget(mnt), O_RDONLY, cred); 269 file = dentry_open(path, O_RDONLY, cred);
271 error = PTR_ERR(file); 270 error = PTR_ERR(file);
272 if (IS_ERR(file)) 271 if (IS_ERR(file))
273 goto out; 272 goto out;
diff --git a/fs/hppfs/hppfs.c b/fs/hppfs/hppfs.c
index e5c06531dcc..c1dffe47fde 100644
--- a/fs/hppfs/hppfs.c
+++ b/fs/hppfs/hppfs.c
@@ -420,8 +420,7 @@ static int hppfs_open(struct inode *inode, struct file *file)
420{ 420{
421 const struct cred *cred = file->f_cred; 421 const struct cred *cred = file->f_cred;
422 struct hppfs_private *data; 422 struct hppfs_private *data;
423 struct vfsmount *proc_mnt; 423 struct path path;
424 struct dentry *proc_dentry;
425 char *host_file; 424 char *host_file;
426 int err, fd, type, filter; 425 int err, fd, type, filter;
427 426
@@ -434,12 +433,11 @@ static int hppfs_open(struct inode *inode, struct file *file)
434 if (host_file == NULL) 433 if (host_file == NULL)
435 goto out_free2; 434 goto out_free2;
436 435
437 proc_dentry = HPPFS_I(inode)->proc_dentry; 436 path.mnt = inode->i_sb->s_fs_info;
438 proc_mnt = inode->i_sb->s_fs_info; 437 path.dentry = HPPFS_I(inode)->proc_dentry;
439 438
440 /* XXX This isn't closed anywhere */ 439 /* XXX This isn't closed anywhere */
441 data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), 440 data->proc_file = dentry_open(&path, file_mode(file->f_mode), cred);
442 file_mode(file->f_mode), cred);
443 err = PTR_ERR(data->proc_file); 441 err = PTR_ERR(data->proc_file);
444 if (IS_ERR(data->proc_file)) 442 if (IS_ERR(data->proc_file))
445 goto out_free1; 443 goto out_free1;
@@ -484,8 +482,7 @@ static int hppfs_dir_open(struct inode *inode, struct file *file)
484{ 482{
485 const struct cred *cred = file->f_cred; 483 const struct cred *cred = file->f_cred;
486 struct hppfs_private *data; 484 struct hppfs_private *data;
487 struct vfsmount *proc_mnt; 485 struct path path;
488 struct dentry *proc_dentry;
489 int err; 486 int err;
490 487
491 err = -ENOMEM; 488 err = -ENOMEM;
@@ -493,10 +490,9 @@ static int hppfs_dir_open(struct inode *inode, struct file *file)
493 if (data == NULL) 490 if (data == NULL)
494 goto out; 491 goto out;
495 492
496 proc_dentry = HPPFS_I(inode)->proc_dentry; 493 path.mnt = inode->i_sb->s_fs_info;
497 proc_mnt = inode->i_sb->s_fs_info; 494 path.dentry = HPPFS_I(inode)->proc_dentry;
498 data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), 495 data->proc_file = dentry_open(&path, file_mode(file->f_mode), cred);
499 file_mode(file->f_mode), cred);
500 err = PTR_ERR(data->proc_file); 496 err = PTR_ERR(data->proc_file);
501 if (IS_ERR(data->proc_file)) 497 if (IS_ERR(data->proc_file))
502 goto out_free; 498 goto out_free;
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 05d9eee6be3..4700a0a929d 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -745,7 +745,7 @@ __be32
745nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, 745nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
746 int may_flags, struct file **filp) 746 int may_flags, struct file **filp)
747{ 747{
748 struct dentry *dentry; 748 struct path path;
749 struct inode *inode; 749 struct inode *inode;
750 int flags = O_RDONLY|O_LARGEFILE; 750 int flags = O_RDONLY|O_LARGEFILE;
751 __be32 err; 751 __be32 err;
@@ -762,8 +762,9 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
762 if (err) 762 if (err)
763 goto out; 763 goto out;
764 764
765 dentry = fhp->fh_dentry; 765 path.mnt = fhp->fh_export->ex_path.mnt;
766 inode = dentry->d_inode; 766 path.dentry = fhp->fh_dentry;
767 inode = path.dentry->d_inode;
767 768
768 /* Disallow write access to files with the append-only bit set 769 /* Disallow write access to files with the append-only bit set
769 * or any access when mandatory locking enabled 770 * or any access when mandatory locking enabled
@@ -792,8 +793,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
792 else 793 else
793 flags = O_WRONLY|O_LARGEFILE; 794 flags = O_WRONLY|O_LARGEFILE;
794 } 795 }
795 *filp = dentry_open(dget(dentry), mntget(fhp->fh_export->ex_path.mnt), 796 *filp = dentry_open(&path, flags, current_cred());
796 flags, current_cred());
797 if (IS_ERR(*filp)) 797 if (IS_ERR(*filp))
798 host_err = PTR_ERR(*filp); 798 host_err = PTR_ERR(*filp);
799 else { 799 else {
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 3568c8a8b13..d4380366973 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -61,8 +61,6 @@ static struct fsnotify_event *get_one_event(struct fsnotify_group *group,
61static int create_fd(struct fsnotify_group *group, struct fsnotify_event *event) 61static int create_fd(struct fsnotify_group *group, struct fsnotify_event *event)
62{ 62{
63 int client_fd; 63 int client_fd;
64 struct dentry *dentry;
65 struct vfsmount *mnt;
66 struct file *new_file; 64 struct file *new_file;
67 65
68 pr_debug("%s: group=%p event=%p\n", __func__, group, event); 66 pr_debug("%s: group=%p event=%p\n", __func__, group, event);
@@ -81,12 +79,10 @@ static int create_fd(struct fsnotify_group *group, struct fsnotify_event *event)
81 * we need a new file handle for the userspace program so it can read even if it was 79 * we need a new file handle for the userspace program so it can read even if it was
82 * originally opened O_WRONLY. 80 * originally opened O_WRONLY.
83 */ 81 */
84 dentry = dget(event->path.dentry);
85 mnt = mntget(event->path.mnt);
86 /* it's possible this event was an overflow event. in that case dentry and mnt 82 /* it's possible this event was an overflow event. in that case dentry and mnt
87 * are NULL; That's fine, just don't call dentry open */ 83 * are NULL; That's fine, just don't call dentry open */
88 if (dentry && mnt) 84 if (event->path.dentry && event->path.mnt)
89 new_file = dentry_open(dentry, mnt, 85 new_file = dentry_open(&event->path,
90 group->fanotify_data.f_flags | FMODE_NONOTIFY, 86 group->fanotify_data.f_flags | FMODE_NONOTIFY,
91 current_cred()); 87 current_cred());
92 else 88 else
diff --git a/fs/open.c b/fs/open.c
index 75bea868ef8..1e914b397e1 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -766,11 +766,7 @@ int finish_no_open(struct file *file, struct dentry *dentry)
766} 766}
767EXPORT_SYMBOL(finish_no_open); 767EXPORT_SYMBOL(finish_no_open);
768 768
769/* 769struct file *dentry_open(const struct path *path, int flags,
770 * dentry_open() will have done dput(dentry) and mntput(mnt) if it returns an
771 * error.
772 */
773struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags,
774 const struct cred *cred) 770 const struct cred *cred)
775{ 771{
776 int error; 772 int error;
@@ -779,19 +775,16 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags,
779 validate_creds(cred); 775 validate_creds(cred);
780 776
781 /* We must always pass in a valid mount pointer. */ 777 /* We must always pass in a valid mount pointer. */
782 BUG_ON(!mnt); 778 BUG_ON(!path->mnt);
783 779
784 error = -ENFILE; 780 error = -ENFILE;
785 f = get_empty_filp(); 781 f = get_empty_filp();
786 if (f == NULL) { 782 if (f == NULL)
787 dput(dentry);
788 mntput(mnt);
789 return ERR_PTR(error); 783 return ERR_PTR(error);
790 }
791 784
792 f->f_flags = flags; 785 f->f_flags = flags;
793 f->f_path.mnt = mnt; 786 f->f_path = *path;
794 f->f_path.dentry = dentry; 787 path_get(&f->f_path);
795 error = do_dentry_open(f, NULL, cred); 788 error = do_dentry_open(f, NULL, cred);
796 if (!error) { 789 if (!error) {
797 error = open_check_o_direct(f); 790 error = open_check_o_direct(f);
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 3a05a41b5d7..1f1535d25a9 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -208,6 +208,7 @@ xfs_open_by_handle(
208 struct inode *inode; 208 struct inode *inode;
209 struct dentry *dentry; 209 struct dentry *dentry;
210 fmode_t fmode; 210 fmode_t fmode;
211 struct path path;
211 212
212 if (!capable(CAP_SYS_ADMIN)) 213 if (!capable(CAP_SYS_ADMIN))
213 return -XFS_ERROR(EPERM); 214 return -XFS_ERROR(EPERM);
@@ -252,8 +253,10 @@ xfs_open_by_handle(
252 goto out_dput; 253 goto out_dput;
253 } 254 }
254 255
255 filp = dentry_open(dentry, mntget(parfilp->f_path.mnt), 256 path.mnt = parfilp->f_path.mnt;
256 hreq->oflags, cred); 257 path.dentry = dentry;
258 filp = dentry_open(&path, hreq->oflags, cred);
259 dput(dentry);
257 if (IS_ERR(filp)) { 260 if (IS_ERR(filp)) {
258 put_unused_fd(fd); 261 put_unused_fd(fd);
259 return PTR_ERR(filp); 262 return PTR_ERR(filp);