Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Apr 2023 13:20:54 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: afa8f8971b86 - main - vn_start_write(): consistently set *mpp to NULL on error or after failed sleep
Message-ID:  <202304111320.33BDKsuv010229@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=afa8f8971b869b8b5d1468e431d18c615a35a63e

commit afa8f8971b869b8b5d1468e431d18c615a35a63e
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-04-05 21:00:04 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-04-11 12:59:46 +0000

    vn_start_write(): consistently set *mpp to NULL on error or after failed sleep
    
    This ensures that *mpp != NULL iff vn_finished_write() should be
    called, regardless of the returned error, except for V_NOWAIT.
    The only exception that must be maintained is the case where
    vn_start_write(V_NOWAIT) is called with the intent of later dropping
    other locks and then doing vn_start_write(V_XSLEEP), which needs the mp
    value calculated from the non-waitable call above it.
    
    Also note that V_XSLEEP is not supported by vn_start_secondary_write().
    
    Reviewed by:    markj, mjg (previous version), rmacklem (previous version)
    Tested by:      pho
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D39441
---
 sys/kern/vfs_vnops.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 122e53c0d9fb..52242cce0692 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -1935,7 +1935,10 @@ vn_start_write(struct vnode *vp, struct mount **mpp, int flags)
 	if (vp == NULL)
 		vfs_ref(mp);
 
-	return (vn_start_write_refed(mp, flags, false));
+	error = vn_start_write_refed(mp, flags, false);
+	if (error != 0 && (flags & V_NOWAIT) == 0)
+		*mpp = NULL;
+	return (error);
 }
 
 /*
@@ -1951,7 +1954,7 @@ vn_start_secondary_write(struct vnode *vp, struct mount **mpp, int flags)
 	struct mount *mp;
 	int error, mflags;
 
-	KASSERT((flags & ~V_VALID_FLAGS) == 0,
+	KASSERT((flags & (~V_VALID_FLAGS | V_XSLEEP)) == 0,
 	    ("%s: invalid flags passed %d\n", __func__, flags));
 
  retry:
@@ -1989,6 +1992,7 @@ vn_start_secondary_write(struct vnode *vp, struct mount **mpp, int flags)
 	if ((flags & V_NOWAIT) != 0) {
 		MNT_REL(mp);
 		MNT_IUNLOCK(mp);
+		*mpp = NULL;
 		return (EWOULDBLOCK);
 	}
 	/*
@@ -2004,6 +2008,7 @@ vn_start_secondary_write(struct vnode *vp, struct mount **mpp, int flags)
 	vfs_rel(mp);
 	if (error == 0)
 		goto retry;
+	*mpp = NULL;
 	return (error);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202304111320.33BDKsuv010229>