Skip to content

Commit 765927b

Browse files
author
Al Viro
committed
switch dentry_open() to struct path, make it grab references itself
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent bf349a4 commit 765927b

File tree

15 files changed

+106
-151
lines changed

15 files changed

+106
-151
lines changed

arch/powerpc/platforms/cell/spufs/inode.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ spufs_mkdir(struct inode *dir, struct dentry *dentry, unsigned int flags,
317317
return ret;
318318
}
319319

320-
static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
320+
static int spufs_context_open(struct path *path)
321321
{
322322
int ret;
323323
struct file *filp;
@@ -326,11 +326,7 @@ static int spufs_context_open(struct dentry *dentry, struct vfsmount *mnt)
326326
if (ret < 0)
327327
return ret;
328328

329-
/*
330-
* get references for dget and mntget, will be released
331-
* in error path of *_open().
332-
*/
333-
filp = dentry_open(dget(dentry), mntget(mnt), O_RDONLY, current_cred());
329+
filp = dentry_open(path, O_RDONLY, current_cred());
334330
if (IS_ERR(filp)) {
335331
put_unused_fd(ret);
336332
return PTR_ERR(filp);
@@ -452,6 +448,7 @@ spufs_create_context(struct inode *inode, struct dentry *dentry,
452448
int affinity;
453449
struct spu_gang *gang;
454450
struct spu_context *neighbor;
451+
struct path path = {.mnt = mnt, .dentry = dentry};
455452

456453
ret = -EPERM;
457454
if ((flags & SPU_CREATE_NOSCHED) &&
@@ -494,7 +491,7 @@ spufs_create_context(struct inode *inode, struct dentry *dentry,
494491
put_spu_context(neighbor);
495492
}
496493

497-
ret = spufs_context_open(dentry, mnt);
494+
ret = spufs_context_open(&path);
498495
if (ret < 0) {
499496
WARN_ON(spufs_rmdir(inode, dentry));
500497
if (affinity)
@@ -551,7 +548,7 @@ spufs_mkgang(struct inode *dir, struct dentry *dentry, umode_t mode)
551548
return ret;
552549
}
553550

554-
static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt)
551+
static int spufs_gang_open(struct path *path)
555552
{
556553
int ret;
557554
struct file *filp;
@@ -564,7 +561,7 @@ static int spufs_gang_open(struct dentry *dentry, struct vfsmount *mnt)
564561
* get references for dget and mntget, will be released
565562
* in error path of *_open().
566563
*/
567-
filp = dentry_open(dget(dentry), mntget(mnt), O_RDONLY, current_cred());
564+
filp = dentry_open(path, O_RDONLY, current_cred());
568565
if (IS_ERR(filp)) {
569566
put_unused_fd(ret);
570567
return PTR_ERR(filp);
@@ -579,13 +576,14 @@ static int spufs_create_gang(struct inode *inode,
579576
struct dentry *dentry,
580577
struct vfsmount *mnt, umode_t mode)
581578
{
579+
struct path path = {.mnt = mnt, .dentry = dentry};
582580
int ret;
583581

584582
ret = spufs_mkgang(inode, dentry, mode & S_IRWXUGO);
585583
if (ret)
586584
goto out;
587585

588-
ret = spufs_gang_open(dentry, mnt);
586+
ret = spufs_gang_open(&path);
589587
if (ret < 0) {
590588
int err = simple_rmdir(inode, dentry);
591589
WARN_ON(err);

fs/autofs4/dev-ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ static int autofs_dev_ioctl_open_mountpoint(const char *name, dev_t devid)
257257
* corresponding to the autofs fs we want to open.
258258
*/
259259

260-
filp = dentry_open(path.dentry, path.mnt, O_RDONLY,
261-
current_cred());
260+
filp = dentry_open(&path, O_RDONLY, current_cred());
261+
path_put(&path);
262262
if (IS_ERR(filp)) {
263263
err = PTR_ERR(filp);
264264
goto out;

fs/cachefiles/rdwr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
891891
struct cachefiles_cache *cache;
892892
mm_segment_t old_fs;
893893
struct file *file;
894+
struct path path;
894895
loff_t pos, eof;
895896
size_t len;
896897
void *data;
@@ -916,10 +917,9 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
916917

917918
/* write the page to the backing filesystem and let it store it in its
918919
* own time */
919-
dget(object->backer);
920-
mntget(cache->mnt);
921-
file = dentry_open(object->backer, cache->mnt, O_RDWR,
922-
cache->cache_cred);
920+
path.mnt = cache->mnt;
921+
path.dentry = object->backer;
922+
file = dentry_open(&path, O_RDWR, cache->cache_cred);
923923
if (IS_ERR(file)) {
924924
ret = PTR_ERR(file);
925925
} else {

fs/ecryptfs/kthread.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929

3030
struct ecryptfs_open_req {
3131
struct file **lower_file;
32-
struct dentry *lower_dentry;
33-
struct vfsmount *lower_mnt;
32+
struct path path;
3433
struct completion done;
3534
struct list_head kthread_ctl_list;
3635
};
@@ -74,10 +73,7 @@ static int ecryptfs_threadfn(void *ignored)
7473
struct ecryptfs_open_req,
7574
kthread_ctl_list);
7675
list_del(&req->kthread_ctl_list);
77-
dget(req->lower_dentry);
78-
mntget(req->lower_mnt);
79-
(*req->lower_file) = dentry_open(
80-
req->lower_dentry, req->lower_mnt,
76+
*req->lower_file = dentry_open(&req->path,
8177
(O_RDWR | O_LARGEFILE), current_cred());
8278
complete(&req->done);
8379
}
@@ -140,23 +136,22 @@ int ecryptfs_privileged_open(struct file **lower_file,
140136
int flags = O_LARGEFILE;
141137
int rc = 0;
142138

139+
init_completion(&req.done);
140+
req.lower_file = lower_file;
141+
req.path.dentry = lower_dentry;
142+
req.path.mnt = lower_mnt;
143+
143144
/* Corresponding dput() and mntput() are done when the
144145
* lower file is fput() when all eCryptfs files for the inode are
145146
* released. */
146-
dget(lower_dentry);
147-
mntget(lower_mnt);
148147
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);
150149
if (!IS_ERR(*lower_file))
151150
goto out;
152151
if ((flags & O_ACCMODE) == O_RDONLY) {
153152
rc = PTR_ERR((*lower_file));
154153
goto out;
155154
}
156-
init_completion(&req.done);
157-
req.lower_file = lower_file;
158-
req.lower_dentry = lower_dentry;
159-
req.lower_mnt = lower_mnt;
160155
mutex_lock(&ecryptfs_kthread_ctl.mux);
161156
if (ecryptfs_kthread_ctl.flags & ECRYPTFS_KTHREAD_ZOMBIE) {
162157
rc = -EIO;

fs/exportfs/expfs.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
#define dprintk(fmt, args...) do{}while(0)
2020

2121

22-
static int get_name(struct vfsmount *mnt, struct dentry *dentry, char *name,
23-
struct dentry *child);
22+
static int get_name(const struct path *path, char *name, struct dentry *child);
2423

2524

2625
static int exportfs_get_name(struct vfsmount *mnt, struct dentry *dir,
2726
char *name, struct dentry *child)
2827
{
2928
const struct export_operations *nop = dir->d_sb->s_export_op;
29+
struct path path = {.mnt = mnt, .dentry = dir};
3030

3131
if (nop->get_name)
3232
return nop->get_name(dir, name, child);
3333
else
34-
return get_name(mnt, dir, name, child);
34+
return get_name(&path, name, child);
3535
}
3636

3737
/*
@@ -249,11 +249,10 @@ static int filldir_one(void * __buf, const char * name, int len,
249249
* calls readdir on the parent until it finds an entry with
250250
* the same inode number as the child, and returns that.
251251
*/
252-
static int get_name(struct vfsmount *mnt, struct dentry *dentry,
253-
char *name, struct dentry *child)
252+
static int get_name(const struct path *path, char *name, struct dentry *child)
254253
{
255254
const struct cred *cred = current_cred();
256-
struct inode *dir = dentry->d_inode;
255+
struct inode *dir = path->dentry->d_inode;
257256
int error;
258257
struct file *file;
259258
struct getdents_callback buffer;
@@ -267,7 +266,7 @@ static int get_name(struct vfsmount *mnt, struct dentry *dentry,
267266
/*
268267
* Open the directory ...
269268
*/
270-
file = dentry_open(dget(dentry), mntget(mnt), O_RDONLY, cred);
269+
file = dentry_open(path, O_RDONLY, cred);
271270
error = PTR_ERR(file);
272271
if (IS_ERR(file))
273272
goto out;

fs/hppfs/hppfs.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,7 @@ static int hppfs_open(struct inode *inode, struct file *file)
420420
{
421421
const struct cred *cred = file->f_cred;
422422
struct hppfs_private *data;
423-
struct vfsmount *proc_mnt;
424-
struct dentry *proc_dentry;
423+
struct path path;
425424
char *host_file;
426425
int err, fd, type, filter;
427426

@@ -434,12 +433,11 @@ static int hppfs_open(struct inode *inode, struct file *file)
434433
if (host_file == NULL)
435434
goto out_free2;
436435

437-
proc_dentry = HPPFS_I(inode)->proc_dentry;
438-
proc_mnt = inode->i_sb->s_fs_info;
436+
path.mnt = inode->i_sb->s_fs_info;
437+
path.dentry = HPPFS_I(inode)->proc_dentry;
439438

440439
/* XXX This isn't closed anywhere */
441-
data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt),
442-
file_mode(file->f_mode), cred);
440+
data->proc_file = dentry_open(&path, file_mode(file->f_mode), cred);
443441
err = PTR_ERR(data->proc_file);
444442
if (IS_ERR(data->proc_file))
445443
goto out_free1;
@@ -484,19 +482,17 @@ static int hppfs_dir_open(struct inode *inode, struct file *file)
484482
{
485483
const struct cred *cred = file->f_cred;
486484
struct hppfs_private *data;
487-
struct vfsmount *proc_mnt;
488-
struct dentry *proc_dentry;
485+
struct path path;
489486
int err;
490487

491488
err = -ENOMEM;
492489
data = hppfs_data();
493490
if (data == NULL)
494491
goto out;
495492

496-
proc_dentry = HPPFS_I(inode)->proc_dentry;
497-
proc_mnt = inode->i_sb->s_fs_info;
498-
data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt),
499-
file_mode(file->f_mode), cred);
493+
path.mnt = inode->i_sb->s_fs_info;
494+
path.dentry = HPPFS_I(inode)->proc_dentry;
495+
data->proc_file = dentry_open(&path, file_mode(file->f_mode), cred);
500496
err = PTR_ERR(data->proc_file);
501497
if (IS_ERR(data->proc_file))
502498
goto out_free;

fs/nfsd/vfs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ __be32
745745
nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
746746
int may_flags, struct file **filp)
747747
{
748-
struct dentry *dentry;
748+
struct path path;
749749
struct inode *inode;
750750
int flags = O_RDONLY|O_LARGEFILE;
751751
__be32 err;
@@ -762,8 +762,9 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
762762
if (err)
763763
goto out;
764764

765-
dentry = fhp->fh_dentry;
766-
inode = dentry->d_inode;
765+
path.mnt = fhp->fh_export->ex_path.mnt;
766+
path.dentry = fhp->fh_dentry;
767+
inode = path.dentry->d_inode;
767768

768769
/* Disallow write access to files with the append-only bit set
769770
* or any access when mandatory locking enabled
@@ -792,8 +793,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,
792793
else
793794
flags = O_WRONLY|O_LARGEFILE;
794795
}
795-
*filp = dentry_open(dget(dentry), mntget(fhp->fh_export->ex_path.mnt),
796-
flags, current_cred());
796+
*filp = dentry_open(&path, flags, current_cred());
797797
if (IS_ERR(*filp))
798798
host_err = PTR_ERR(*filp);
799799
else {

fs/notify/fanotify/fanotify_user.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ static struct fsnotify_event *get_one_event(struct fsnotify_group *group,
6161
static int create_fd(struct fsnotify_group *group, struct fsnotify_event *event)
6262
{
6363
int client_fd;
64-
struct dentry *dentry;
65-
struct vfsmount *mnt;
6664
struct file *new_file;
6765

6866
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)
8179
* we need a new file handle for the userspace program so it can read even if it was
8280
* originally opened O_WRONLY.
8381
*/
84-
dentry = dget(event->path.dentry);
85-
mnt = mntget(event->path.mnt);
8682
/* it's possible this event was an overflow event. in that case dentry and mnt
8783
* are NULL; That's fine, just don't call dentry open */
88-
if (dentry && mnt)
89-
new_file = dentry_open(dentry, mnt,
84+
if (event->path.dentry && event->path.mnt)
85+
new_file = dentry_open(&event->path,
9086
group->fanotify_data.f_flags | FMODE_NONOTIFY,
9187
current_cred());
9288
else

fs/open.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -766,11 +766,7 @@ int finish_no_open(struct file *file, struct dentry *dentry)
766766
}
767767
EXPORT_SYMBOL(finish_no_open);
768768

769-
/*
770-
* dentry_open() will have done dput(dentry) and mntput(mnt) if it returns an
771-
* error.
772-
*/
773-
struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags,
769+
struct file *dentry_open(const struct path *path, int flags,
774770
const struct cred *cred)
775771
{
776772
int error;
@@ -779,19 +775,16 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags,
779775
validate_creds(cred);
780776

781777
/* We must always pass in a valid mount pointer. */
782-
BUG_ON(!mnt);
778+
BUG_ON(!path->mnt);
783779

784780
error = -ENFILE;
785781
f = get_empty_filp();
786-
if (f == NULL) {
787-
dput(dentry);
788-
mntput(mnt);
782+
if (f == NULL)
789783
return ERR_PTR(error);
790-
}
791784

792785
f->f_flags = flags;
793-
f->f_path.mnt = mnt;
794-
f->f_path.dentry = dentry;
786+
f->f_path = *path;
787+
path_get(&f->f_path);
795788
error = do_dentry_open(f, NULL, cred);
796789
if (!error) {
797790
error = open_check_o_direct(f);

fs/xfs/xfs_ioctl.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ xfs_open_by_handle(
208208
struct inode *inode;
209209
struct dentry *dentry;
210210
fmode_t fmode;
211+
struct path path;
211212

212213
if (!capable(CAP_SYS_ADMIN))
213214
return -XFS_ERROR(EPERM);
@@ -252,8 +253,10 @@ xfs_open_by_handle(
252253
goto out_dput;
253254
}
254255

255-
filp = dentry_open(dentry, mntget(parfilp->f_path.mnt),
256-
hreq->oflags, cred);
256+
path.mnt = parfilp->f_path.mnt;
257+
path.dentry = dentry;
258+
filp = dentry_open(&path, hreq->oflags, cred);
259+
dput(dentry);
257260
if (IS_ERR(filp)) {
258261
put_unused_fd(fd);
259262
return PTR_ERR(filp);

0 commit comments

Comments
 (0)