svn commit: r304927 - head/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Sat Aug 27 22:43:42 UTC 2016


Author: mjg
Date: Sat Aug 27 22:43:41 2016
New Revision: 304927
URL: https://svnweb.freebsd.org/changeset/base/304927

Log:
  vfs: provide a common exit point in namei for error cases
  
  This shortens the function, adds the SDT_PROBE use for error cases and
  consistenly unrefs rootdir last.
  
  Reviewed by:	kib
  MFC after:	2 weeks

Modified:
  head/sys/kern/vfs_lookup.c

Modified: head/sys/kern/vfs_lookup.c
==============================================================================
--- head/sys/kern/vfs_lookup.c	Sat Aug 27 22:23:10 2016	(r304926)
+++ head/sys/kern/vfs_lookup.c	Sat Aug 27 22:43:41 2016	(r304927)
@@ -295,21 +295,15 @@ namei(struct nameidata *ndp)
 	if (error != 0) {
 		if (dp != NULL)
 			vrele(dp);
-		vrele(ndp->ni_rootdir);
-		namei_cleanup_cnp(cnp);
-		return (error);
+		goto out;
 	}
 	SDT_PROBE3(vfs, namei, lookup, entry, dp, cnp->cn_pnbuf,
 	    cnp->cn_flags);
 	for (;;) {
 		ndp->ni_startdir = dp;
 		error = lookup(ndp);
-		if (error != 0) {
-			vrele(ndp->ni_rootdir);
-			namei_cleanup_cnp(cnp);
-			SDT_PROBE2(vfs, namei, lookup, return, error, NULL);
-			return (error);
-		}
+		if (error != 0)
+			goto out;
 		/*
 		 * If not a symbolic link, we're done.
 		 */
@@ -383,18 +377,16 @@ namei(struct nameidata *ndp)
 		if (*(cnp->cn_nameptr) == '/') {
 			vrele(dp);
 			error = namei_handle_root(ndp, &dp);
-			if (error != 0) {
-				vrele(ndp->ni_rootdir);
-				namei_cleanup_cnp(cnp);
-				return (error);
-			}
+			if (error != 0)
+				goto out;
 		}
 	}
-	vrele(ndp->ni_rootdir);
-	namei_cleanup_cnp(cnp);
 	vput(ndp->ni_vp);
 	ndp->ni_vp = NULL;
 	vrele(ndp->ni_dvp);
+out:
+	vrele(ndp->ni_rootdir);
+	namei_cleanup_cnp(cnp);
 	SDT_PROBE2(vfs, namei, lookup, return, error, NULL);
 	return (error);
 }


More information about the svn-src-head mailing list