Author: mav
Date: Thu Jul  4 15:19:45 2013
New Revision: 252700
URL: http://svnweb.freebsd.org/changeset/base/252700

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

Modified:
  stable/9/lib/libstand/nfs.c
Directory Properties:
  stable/9/lib/libstand/   (props changed)

Modified: stable/9/lib/libstand/nfs.c
==============================================================================
--- stable/9/lib/libstand/nfs.c Thu Jul  4 14:26:42 2013        (r252699)
+++ stable/9/lib/libstand/nfs.c Thu Jul  4 15:19:45 2013        (r252700)
@@ -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;
 
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "[email protected]"

Reply via email to