The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=246f5b4136c39a26898e97b85d243d9b89f5d13f
commit 246f5b4136c39a26898e97b85d243d9b89f5d13f Author: Konstantin Belousov <k...@freebsd.org> AuthorDate: 2025-07-30 15:00:06 +0000 Commit: Konstantin Belousov <k...@freebsd.org> CommitDate: 2025-08-05 00:30:28 +0000 swapongeom: destroy consumer/close vnode in case swaponsomething failed (cherry picked from commit 2e3fa9395fc67e7369fda8d8b5c6613142d2a57d) --- sys/vm/swap_pager.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index ee810ad1c9d5..f5815d615e16 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -2995,6 +2995,7 @@ swapongeom_locked(struct cdev *dev, struct vnode *vp) cp->index = 1; /* Number of active I/Os, plus one for being active. */ cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE; g_attach(cp, pp); + /* * XXX: Every time you think you can improve the margin for * footshooting, somebody depends on the ability to do so: @@ -3002,15 +3003,19 @@ swapongeom_locked(struct cdev *dev, struct vnode *vp) * set an exclusive count :-( */ error = g_access(cp, 1, 1, 0); + + if (error == 0) { + nblks = pp->mediasize / DEV_BSIZE; + error = swaponsomething(vp, cp, nblks, swapgeom_strategy, + swapgeom_close, dev2udev(dev), + (pp->flags & G_PF_ACCEPT_UNMAPPED) != 0 ? SW_UNMAPPED : 0); + if (error != 0) + g_access(cp, -1, -1, 0); + } if (error != 0) { g_detach(cp); g_destroy_consumer(cp); - return (error); } - nblks = pp->mediasize / DEV_BSIZE; - error = swaponsomething(vp, cp, nblks, swapgeom_strategy, - swapgeom_close, dev2udev(dev), - (pp->flags & G_PF_ACCEPT_UNMAPPED) != 0 ? SW_UNMAPPED : 0); return (error); } @@ -3102,6 +3107,8 @@ swaponvp(struct thread *td, struct vnode *vp, u_long nblks) error = swaponsomething(vp, vp, nblks, swapdev_strategy, swapdev_close, NODEV, 0); + if (error != 0) + VOP_CLOSE(vp, FREAD | FWRITE, td->td_ucred, td); return (error); }