Skip to content

Commit 829745b

Browse files
committed
Merge tag 'pull-finish_no_open' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull finish_no_open updates from Al Viro: "finish_no_open calling conventions change to simplify callers" * tag 'pull-finish_no_open' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: slightly simplify nfs_atomic_open() simplify gfs2_atomic_open() simplify fuse_atomic_open() simplify nfs_atomic_open_v23() simplify vboxsf_dir_atomic_open() simplify cifs_atomic_open() 9p: simplify v9fs_vfs_atomic_open_dotl() 9p: simplify v9fs_vfs_atomic_open() allow finish_no_open(file, ERR_PTR(-E...))
2 parents 867e451 + 2944ebe commit 829745b

8 files changed

Lines changed: 54 additions & 103 deletions

File tree

fs/9p/vfs_inode.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -768,22 +768,18 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
768768
struct v9fs_inode __maybe_unused *v9inode;
769769
struct v9fs_session_info *v9ses;
770770
struct p9_fid *fid;
771-
struct dentry *res = NULL;
772771
struct inode *inode;
773772
int p9_omode;
774773

775774
if (d_in_lookup(dentry)) {
776-
res = v9fs_vfs_lookup(dir, dentry, 0);
777-
if (IS_ERR(res))
778-
return PTR_ERR(res);
779-
780-
if (res)
781-
dentry = res;
775+
struct dentry *res = v9fs_vfs_lookup(dir, dentry, 0);
776+
if (res || d_really_is_positive(dentry))
777+
return finish_no_open(file, res);
782778
}
783779

784780
/* Only creates */
785-
if (!(flags & O_CREAT) || d_really_is_positive(dentry))
786-
return finish_no_open(file, res);
781+
if (!(flags & O_CREAT))
782+
return finish_no_open(file, NULL);
787783

788784
v9ses = v9fs_inode2v9ses(dir);
789785
perm = unixmode2p9mode(v9ses, mode);
@@ -795,17 +791,17 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
795791
"write-only file with writeback enabled, creating w/ O_RDWR\n");
796792
}
797793
fid = v9fs_create(v9ses, dir, dentry, NULL, perm, p9_omode);
798-
if (IS_ERR(fid)) {
799-
err = PTR_ERR(fid);
800-
goto error;
801-
}
794+
if (IS_ERR(fid))
795+
return PTR_ERR(fid);
802796

803797
v9fs_invalidate_inode_attr(dir);
804798
inode = d_inode(dentry);
805799
v9inode = V9FS_I(inode);
806800
err = finish_open(file, dentry, generic_file_open);
807-
if (err)
808-
goto error;
801+
if (unlikely(err)) {
802+
p9_fid_put(fid);
803+
return err;
804+
}
809805

810806
file->private_data = fid;
811807
#ifdef CONFIG_9P_FSCACHE
@@ -818,13 +814,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
818814
v9fs_open_fid_add(inode, &fid);
819815

820816
file->f_mode |= FMODE_CREATED;
821-
out:
822-
dput(res);
823-
return err;
824-
825-
error:
826-
p9_fid_put(fid);
827-
goto out;
817+
return 0;
828818
}
829819

830820
/**

fs/9p/vfs_inode_dotl.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,16 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
238238
struct p9_fid *dfid = NULL, *ofid = NULL;
239239
struct v9fs_session_info *v9ses;
240240
struct posix_acl *pacl = NULL, *dacl = NULL;
241-
struct dentry *res = NULL;
242241

243242
if (d_in_lookup(dentry)) {
244-
res = v9fs_vfs_lookup(dir, dentry, 0);
245-
if (IS_ERR(res))
246-
return PTR_ERR(res);
247-
248-
if (res)
249-
dentry = res;
243+
struct dentry *res = v9fs_vfs_lookup(dir, dentry, 0);
244+
if (res || d_really_is_positive(dentry))
245+
return finish_no_open(file, res);
250246
}
251247

252248
/* Only creates */
253-
if (!(flags & O_CREAT) || d_really_is_positive(dentry))
254-
return finish_no_open(file, res);
249+
if (!(flags & O_CREAT))
250+
return finish_no_open(file, NULL);
255251

256252
v9ses = v9fs_inode2v9ses(dir);
257253

@@ -337,7 +333,6 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,
337333
p9_fid_put(ofid);
338334
p9_fid_put(fid);
339335
v9fs_put_acl(dacl, pacl);
340-
dput(res);
341336
return err;
342337
}
343338

fs/fuse/dir.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -739,22 +739,18 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
739739
int err;
740740
struct mnt_idmap *idmap = file_mnt_idmap(file);
741741
struct fuse_conn *fc = get_fuse_conn(dir);
742-
struct dentry *res = NULL;
743742

744743
if (fuse_is_bad(dir))
745744
return -EIO;
746745

747746
if (d_in_lookup(entry)) {
748-
res = fuse_lookup(dir, entry, 0);
749-
if (IS_ERR(res))
750-
return PTR_ERR(res);
751-
752-
if (res)
753-
entry = res;
747+
struct dentry *res = fuse_lookup(dir, entry, 0);
748+
if (res || d_really_is_positive(entry))
749+
return finish_no_open(file, res);
754750
}
755751

756-
if (!(flags & O_CREAT) || d_really_is_positive(entry))
757-
goto no_open;
752+
if (!(flags & O_CREAT))
753+
return finish_no_open(file, NULL);
758754

759755
/* Only creates */
760756
file->f_mode |= FMODE_CREATED;
@@ -768,16 +764,13 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
768764
goto mknod;
769765
} else if (err == -EEXIST)
770766
fuse_invalidate_entry(entry);
771-
out_dput:
772-
dput(res);
773767
return err;
774768

775769
mknod:
776770
err = fuse_mknod(idmap, dir, entry, mode, 0);
777771
if (err)
778-
goto out_dput;
779-
no_open:
780-
return finish_no_open(file, res);
772+
return err;
773+
return finish_no_open(file, NULL);
781774
}
782775

783776
/*

fs/gfs2/inode.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,27 +1368,19 @@ static int gfs2_atomic_open(struct inode *dir, struct dentry *dentry,
13681368
struct file *file, unsigned flags,
13691369
umode_t mode)
13701370
{
1371-
struct dentry *d;
13721371
bool excl = !!(flags & O_EXCL);
13731372

1374-
if (!d_in_lookup(dentry))
1375-
goto skip_lookup;
1376-
1377-
d = __gfs2_lookup(dir, dentry, file);
1378-
if (IS_ERR(d))
1379-
return PTR_ERR(d);
1380-
if (d != NULL)
1381-
dentry = d;
1382-
if (d_really_is_positive(dentry)) {
1383-
if (!(file->f_mode & FMODE_OPENED))
1373+
if (d_in_lookup(dentry)) {
1374+
struct dentry *d = __gfs2_lookup(dir, dentry, file);
1375+
if (file->f_mode & FMODE_OPENED) {
1376+
if (IS_ERR(d))
1377+
return PTR_ERR(d);
1378+
dput(d);
1379+
return excl && (flags & O_CREAT) ? -EEXIST : 0;
1380+
}
1381+
if (d || d_really_is_positive(dentry))
13841382
return finish_no_open(file, d);
1385-
dput(d);
1386-
return excl && (flags & O_CREAT) ? -EEXIST : 0;
13871383
}
1388-
1389-
BUG_ON(d != NULL);
1390-
1391-
skip_lookup:
13921384
if (!(flags & O_CREAT))
13931385
return -ENOENT;
13941386

fs/nfs/dir.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,8 +2198,6 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
21982198
else
21992199
dput(dentry);
22002200
}
2201-
if (IS_ERR(res))
2202-
return PTR_ERR(res);
22032201
return finish_no_open(file, res);
22042202
}
22052203
EXPORT_SYMBOL_GPL(nfs_atomic_open);
@@ -2260,7 +2258,7 @@ int nfs_atomic_open_v23(struct inode *dir, struct dentry *dentry,
22602258
struct file *file, unsigned int open_flags,
22612259
umode_t mode)
22622260
{
2263-
2261+
struct dentry *res = NULL;
22642262
/* Same as look+open from lookup_open(), but with different O_TRUNC
22652263
* handling.
22662264
*/
@@ -2275,21 +2273,15 @@ int nfs_atomic_open_v23(struct inode *dir, struct dentry *dentry,
22752273
if (error)
22762274
return error;
22772275
return finish_open(file, dentry, NULL);
2278-
} else if (d_in_lookup(dentry)) {
2276+
}
2277+
if (d_in_lookup(dentry)) {
22792278
/* The only flags nfs_lookup considers are
22802279
* LOOKUP_EXCL and LOOKUP_RENAME_TARGET, and
22812280
* we want those to be zero so the lookup isn't skipped.
22822281
*/
2283-
struct dentry *res = nfs_lookup(dir, dentry, 0);
2284-
2285-
d_lookup_done(dentry);
2286-
if (unlikely(res)) {
2287-
if (IS_ERR(res))
2288-
return PTR_ERR(res);
2289-
return finish_no_open(file, res);
2290-
}
2282+
res = nfs_lookup(dir, dentry, 0);
22912283
}
2292-
return finish_no_open(file, NULL);
2284+
return finish_no_open(file, res);
22932285

22942286
}
22952287
EXPORT_SYMBOL_GPL(nfs_atomic_open_v23);

fs/open.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,18 +1059,20 @@ EXPORT_SYMBOL(finish_open);
10591059
* finish_no_open - finish ->atomic_open() without opening the file
10601060
*
10611061
* @file: file pointer
1062-
* @dentry: dentry or NULL (as returned from ->lookup())
1062+
* @dentry: dentry, ERR_PTR(-E...) or NULL (as returned from ->lookup())
10631063
*
1064-
* This can be used to set the result of a successful lookup in ->atomic_open().
1064+
* This can be used to set the result of a lookup in ->atomic_open().
10651065
*
10661066
* NB: unlike finish_open() this function does consume the dentry reference and
10671067
* the caller need not dput() it.
10681068
*
1069-
* Returns "0" which must be the return value of ->atomic_open() after having
1070-
* called this function.
1069+
* Returns 0 or -E..., which must be the return value of ->atomic_open() after
1070+
* having called this function.
10711071
*/
10721072
int finish_no_open(struct file *file, struct dentry *dentry)
10731073
{
1074+
if (IS_ERR(dentry))
1075+
return PTR_ERR(dentry);
10741076
file->f_path.dentry = dentry;
10751077
return 0;
10761078
}

fs/smb/client/dir.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,20 +484,14 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
484484
* in network traffic in the other paths.
485485
*/
486486
if (!(oflags & O_CREAT)) {
487-
struct dentry *res;
488-
489487
/*
490488
* Check for hashed negative dentry. We have already revalidated
491489
* the dentry and it is fine. No need to perform another lookup.
492490
*/
493491
if (!d_in_lookup(direntry))
494492
return -ENOENT;
495493

496-
res = cifs_lookup(inode, direntry, 0);
497-
if (IS_ERR(res))
498-
return PTR_ERR(res);
499-
500-
return finish_no_open(file, res);
494+
return finish_no_open(file, cifs_lookup(inode, direntry, 0));
501495
}
502496

503497
xid = get_xid();

fs/vboxsf/dir.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -315,46 +315,39 @@ static int vboxsf_dir_atomic_open(struct inode *parent, struct dentry *dentry,
315315
{
316316
struct vboxsf_sbi *sbi = VBOXSF_SBI(parent->i_sb);
317317
struct vboxsf_handle *sf_handle;
318-
struct dentry *res = NULL;
319318
u64 handle;
320319
int err;
321320

322321
if (d_in_lookup(dentry)) {
323-
res = vboxsf_dir_lookup(parent, dentry, 0);
324-
if (IS_ERR(res))
325-
return PTR_ERR(res);
326-
327-
if (res)
328-
dentry = res;
322+
struct dentry *res = vboxsf_dir_lookup(parent, dentry, 0);
323+
if (res || d_really_is_positive(dentry))
324+
return finish_no_open(file, res);
329325
}
330326

331327
/* Only creates */
332-
if (!(flags & O_CREAT) || d_really_is_positive(dentry))
333-
return finish_no_open(file, res);
328+
if (!(flags & O_CREAT))
329+
return finish_no_open(file, NULL);
334330

335331
err = vboxsf_dir_create(parent, dentry, mode, false, flags & O_EXCL, &handle);
336332
if (err)
337-
goto out;
333+
return err;
338334

339335
sf_handle = vboxsf_create_sf_handle(d_inode(dentry), handle, SHFL_CF_ACCESS_READWRITE);
340336
if (IS_ERR(sf_handle)) {
341337
vboxsf_close(sbi->root, handle);
342-
err = PTR_ERR(sf_handle);
343-
goto out;
338+
return PTR_ERR(sf_handle);
344339
}
345340

346341
err = finish_open(file, dentry, generic_file_open);
347342
if (err) {
348343
/* This also closes the handle passed to vboxsf_create_sf_handle() */
349344
vboxsf_release_sf_handle(d_inode(dentry), sf_handle);
350-
goto out;
345+
return err;
351346
}
352347

353348
file->private_data = sf_handle;
354349
file->f_mode |= FMODE_CREATED;
355-
out:
356-
dput(res);
357-
return err;
350+
return 0;
358351
}
359352

360353
static int vboxsf_dir_unlink(struct inode *parent, struct dentry *dentry)

0 commit comments

Comments
 (0)