diff options
author | Konstantin Belousov <kib@FreeBSD.org> | 2021-04-19 10:25:30 +0000 |
---|---|---|
committer | Konstantin Belousov <kib@FreeBSD.org> | 2021-05-01 00:38:30 +0000 |
commit | 9102ba040a6faf1badf950d6af104440b667f89f (patch) | |
tree | 40fb29c7c0142d23322e1b30409b78c6821d1839 | |
parent | f7020e7b5ee2bbe6d309b1ccea1ad74184ba4478 (diff) | |
download | src-9102ba040a6faf1badf950d6af104440b667f89f.tar.gz src-9102ba040a6faf1badf950d6af104440b667f89f.zip |
vn_open_vnode(): handle error when fp == NULL
PR: 255119
(cherry picked from commit 54f98c4dbf9b1203a4e3e1b13fd0738441226991)
-rw-r--r-- | sys/kern/vfs_vnops.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index 1e0b76089b0f..ff44aba46f95 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -405,16 +405,34 @@ vn_open_vnode(struct vnode *vp, int fmode, struct ucred *cred, /* * Error from advlock or VOP_ADD_WRITECOUNT() still requires * calling VOP_CLOSE() to pair with earlier VOP_OPEN(). - * Arrange for that by having fdrop() to use vn_closefile(). */ if (error != 0) { - fp->f_flag |= FOPENFAILED; - fp->f_vnode = vp; - if (fp->f_ops == &badfileops) { - fp->f_type = DTYPE_VNODE; - fp->f_ops = &vnops; + if (fp != NULL) { + /* + * Arrange the call by having fdrop() to use + * vn_closefile(). This is to satisfy + * filesystems like devfs or tmpfs, which + * override fo_close(). + */ + fp->f_flag |= FOPENFAILED; + fp->f_vnode = vp; + if (fp->f_ops == &badfileops) { + fp->f_type = DTYPE_VNODE; + fp->f_ops = &vnops; + } + vref(vp); + } else { + /* + * If there is no fp, due to kernel-mode open, + * we can call VOP_CLOSE() now. + */ + if (vp->v_type != VFIFO && (fmode & FWRITE) != 0 && + !MNT_EXTENDED_SHARED(vp->v_mount) && + VOP_ISLOCKED(vp) != LK_EXCLUSIVE) + vn_lock(vp, LK_UPGRADE | LK_RETRY); + (void)VOP_CLOSE(vp, fmode & (FREAD | FWRITE | FEXEC), + cred, td); } - vref(vp); } ASSERT_VOP_LOCKED(vp, "vn_open_vnode"); |