Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Sep 2012 12:19:37 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r240774 - head/lib/libstand
Message-ID:  <201209211219.q8LCJb3o031958@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Fri Sep 21 12:19:36 2012
New Revision: 240774
URL: http://svn.freebsd.org/changeset/base/240774

Log:
  Don't use global nfs_root_node variable as per-file storage. There are
  fields that should be file-specific.

Modified:
  head/lib/libstand/nfs.c

Modified: head/lib/libstand/nfs.c
==============================================================================
--- head/lib/libstand/nfs.c	Fri Sep 21 10:31:19 2012	(r240773)
+++ head/lib/libstand/nfs.c	Fri Sep 21 12:19:36 2012	(r240774)
@@ -486,6 +486,9 @@ nfs_open(const char *upath, struct open_
 	desc->destip = rootip;
 	if ((error = nfs_getrootfh(desc, rootpath, nfs_root_node.fh)))
 		return (error);
+	nfs_root_node.fa.fa_type  = htonl(NFDIR);
+	nfs_root_node.fa.fa_mode  = htonl(0755);
+	nfs_root_node.fa.fa_nlink = htonl(2);
 	nfs_root_node.iodesc = desc;
 
 	fh = &nfs_root_node.fh[0];
@@ -498,14 +501,15 @@ nfs_open(const char *upath, struct open_
 	setenv("boot.nfsroot.path", rootpath, 1);
 	setenv("boot.nfsroot.nfshandle", buf, 1);
 
-#ifndef NFS_NOSYMLINK
-	/* Fake up attributes for the root dir. */
-	fa = &nfs_root_node.fa;
-	fa->fa_type  = htonl(NFDIR);
-	fa->fa_mode  = htonl(0755);
-	fa->fa_nlink = htonl(2);
+	/* Allocate file system specific data structure */
+	currfd = malloc(sizeof(*newfd));
+	if (currfd == NULL) {
+		error = ENOMEM;
+		goto out;
+	}
 
-	currfd = &nfs_root_node;
+#ifndef NFS_NOSYMLINK
+	bcopy(&nfs_root_node, currfd, sizeof(*currfd));
 	newfd = 0;
 
 	cp = path = strdup(upath);
@@ -533,7 +537,6 @@ nfs_open(const char *upath, struct open_
 		/* allocate file system specific data structure */
 		newfd = malloc(sizeof(*newfd));
 		newfd->iodesc = currfd->iodesc;
-		newfd->off = 0;
 
 		/*
 		 * Get next component of path name.
@@ -585,11 +588,8 @@ nfs_open(const char *upath, struct open_
 			 * If relative pathname, restart at parent directory.
 			 */
 			cp = namebuf;
-			if (*cp == '/') {
-				if (currfd != &nfs_root_node)
-					free(currfd);
-				currfd = &nfs_root_node;
-			}
+			if (*cp == '/')
+				bcopy(&nfs_root_node, currfd, sizeof(*currfd));
 
 			free(newfd);
 			newfd = 0;
@@ -597,8 +597,7 @@ nfs_open(const char *upath, struct open_
 			continue;
 		}
 
-		if (currfd != &nfs_root_node)
-			free(currfd);
+		free(currfd);
 		currfd = newfd;
 		newfd = 0;
 	}
@@ -611,14 +610,12 @@ out:
 	if (path)
 		free(path);
 #else
-        /* allocate file system specific data structure */
-        currfd = malloc(sizeof(*currfd));
         currfd->iodesc = desc;
-        currfd->off = 0;
 
         error = nfs_lookupfh(&nfs_root_node, upath, currfd);
 #endif
 	if (!error) {
+		currfd->off = 0;
 		f->f_fsdata = (void *)currfd;
 		return (0);
 	}
@@ -628,10 +625,7 @@ out:
 		printf("nfs_open: %s lookupfh failed: %s\n",
 		    path, strerror(error));
 #endif
-#ifndef NFS_NOSYMLINK
-	if (currfd != &nfs_root_node)
-#endif
-		free(currfd);
+	free(currfd);
 
 	return (error);
 }
@@ -646,7 +640,7 @@ nfs_close(struct open_file *f)
 		printf("nfs_close: fp=0x%lx\n", (u_long)fp);
 #endif
 
-	if (fp != &nfs_root_node && fp)
+	if (fp)
 		free(fp);
 	f->f_fsdata = (void *)0;
 
@@ -1133,6 +1127,9 @@ nfs_open(const char *upath, struct open_
 	if ((error = nfs_getrootfh(desc, rootpath, &nfs_root_node.fhsize,
 	    nfs_root_node.fh)))
 		return (error);
+	nfs_root_node.fa.fa_type  = htonl(NFDIR);
+	nfs_root_node.fa.fa_mode  = htonl(0755);
+	nfs_root_node.fa.fa_nlink = htonl(2);
 	nfs_root_node.iodesc = desc;
 
 	fh = &nfs_root_node.fh[0];
@@ -1147,14 +1144,14 @@ nfs_open(const char *upath, struct open_
 	sprintf(buf, "%d", nfs_root_node.fhsize);
 	setenv("boot.nfsroot.nfshandlelen", buf, 1);
 
+	/* Allocate file system specific data structure */
+	currfd = malloc(sizeof(*newfd));
+	if (currfd == NULL) {
+		error = ENOMEM;
+		goto out;
+	}
 #ifndef NFS_NOSYMLINK
-	/* Fake up attributes for the root dir. */
-	fa = &nfs_root_node.fa;
-	fa->fa_type  = htonl(NFDIR);
-	fa->fa_mode  = htonl(0755);
-	fa->fa_nlink = htonl(2);
-
-	currfd = &nfs_root_node;
+	bcopy(&nfs_root_node, currfd, sizeof(*currfd));
 	newfd = 0;
 
 	cp = path = strdup(upath);
@@ -1186,7 +1183,6 @@ nfs_open(const char *upath, struct open_
 			goto out;
 		}
 		newfd->iodesc = currfd->iodesc;
-		newfd->off = 0;
 
 		/*
 		 * Get next component of path name.
@@ -1238,11 +1234,8 @@ nfs_open(const char *upath, struct open_
 			 * If relative pathname, restart at parent directory.
 			 */
 			cp = namebuf;
-			if (*cp == '/') {
-				if (currfd != &nfs_root_node)
-					free(currfd);
-				currfd = &nfs_root_node;
-			}
+			if (*cp == '/')
+				bcopy(&nfs_root_node, currfd, sizeof(*currfd));
 
 			free(newfd);
 			newfd = 0;
@@ -1250,8 +1243,7 @@ nfs_open(const char *upath, struct open_
 			continue;
 		}
 
-		if (currfd != &nfs_root_node)
-			free(currfd);
+		free(currfd);
 		currfd = newfd;
 		newfd = 0;
 	}
@@ -1262,17 +1254,12 @@ out:
 	free(newfd);
 	free(path);
 #else
-	/* allocate file system specific data structure */
-	currfd = malloc(sizeof(*currfd));
-	if (currfd != NULL) {
-		currfd->iodesc = desc;
-		currfd->off = 0;
+	currfd->iodesc = desc;
 
-		error = nfs_lookupfh(&nfs_root_node, upath, currfd);
-	} else
-		error = ENOMEM;
+	error = nfs_lookupfh(&nfs_root_node, upath, currfd);
 #endif
 	if (!error) {
+		currfd->off = 0;
 		f->f_fsdata = (void *)currfd;
 		return (0);
 	}
@@ -1282,10 +1269,7 @@ out:
 		printf("nfs_open: %s lookupfh failed: %s\n",
 		    path, strerror(error));
 #endif
-#ifndef NFS_NOSYMLINK
-	if (currfd != &nfs_root_node)
-#endif
-		free(currfd);
+	free(currfd);
 
 	return (error);
 }
@@ -1300,7 +1284,7 @@ nfs_close(struct open_file *f)
 		printf("nfs_close: fp=0x%lx\n", (u_long)fp);
 #endif
 
-	if (fp != &nfs_root_node && fp)
+	if (fp)
 		free(fp);
 	f->f_fsdata = (void *)0;
 



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