git: 4b2caeec43ea - stable/13 - swapon: extend the region where the swap vnode is locked
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 02 Dec 2021 02:31:52 UTC
The branch stable/13 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=4b2caeec43eabdb6331352ca9249abd5175f4838
commit 4b2caeec43eabdb6331352ca9249abd5175f4838
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-11-24 03:06:02 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-12-02 02:21:14 +0000
swapon: extend the region where the swap vnode is locked
(cherry picked from commit 6ddf41faa6f54738db9b3f313086974b6403d680)
---
sys/vm/swap_pager.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
index 38c225db51ee..8363dce52683 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -2360,8 +2360,8 @@ sys_swapon(struct thread *td, struct swapon_args *uap)
goto done;
}
- NDINIT(&nd, LOOKUP, ISOPEN | FOLLOW | AUDITVNODE1, UIO_USERSPACE,
- uap->name, td);
+ NDINIT(&nd, LOOKUP, ISOPEN | FOLLOW | LOCKLEAF | AUDITVNODE1,
+ UIO_USERSPACE, uap->name, td);
error = namei(&nd);
if (error)
goto done;
@@ -2381,8 +2381,10 @@ sys_swapon(struct thread *td, struct swapon_args *uap)
error = swaponvp(td, vp, attr.va_size / DEV_BSIZE);
}
- if (error)
- vrele(vp);
+ if (error != 0)
+ vput(vp);
+ else
+ VOP_UNLOCK(vp);
done:
sx_xunlock(&swdev_syscall_lock);
return (error);
@@ -3005,7 +3007,7 @@ swapongeom(struct vnode *vp)
{
int error;
- vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+ ASSERT_VOP_ELOCKED(vp, "swapongeom");
if (vp->v_type != VCHR || VN_IS_DOOMED(vp)) {
error = ENOENT;
} else {
@@ -3013,7 +3015,6 @@ swapongeom(struct vnode *vp)
error = swapongeom_locked(vp->v_rdev, vp);
g_topology_unlock();
}
- VOP_UNLOCK(vp);
return (error);
}
@@ -3064,6 +3065,7 @@ swaponvp(struct thread *td, struct vnode *vp, u_long nblks)
struct swdevt *sp;
int error;
+ ASSERT_VOP_ELOCKED(vp, "swaponvp");
if (nblks == 0)
return (ENXIO);
mtx_lock(&sw_dev_mtx);
@@ -3075,14 +3077,12 @@ swaponvp(struct thread *td, struct vnode *vp, u_long nblks)
}
mtx_unlock(&sw_dev_mtx);
- (void) vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
#ifdef MAC
error = mac_system_check_swapon(td->td_ucred, vp);
if (error == 0)
#endif
error = VOP_OPEN(vp, FREAD | FWRITE, td->td_ucred, td, NULL);
- (void) VOP_UNLOCK(vp);
- if (error)
+ if (error != 0)
return (error);
swaponsomething(vp, vp, nblks, swapdev_strategy, swapdev_close,