]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
rpc.mountd: make exportent->e_hostname a dynamically-allocated string
authorJeff Layton <jlayton@redhat.com>
Thu, 27 Sep 2007 10:53:53 +0000 (06:53 -0400)
committerNeil Brown <neilb@suse.de>
Fri, 28 Sep 2007 01:39:56 +0000 (11:39 +1000)
This makes the e_hostname field of the exportent into a pointer to a
dynamically allocated string. This is necessary since this is field is
often filled out from the m_hostname. This too adds a few
micro-optimizations as we can avoid copying the string in some places
and simply pass a pointer to the original string instead.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Acked-by: Steve Dickson <steved@redhat.com>
Signed-off-by: Neil Brown <neilb@suse.de>
support/export/export.c
support/export/rmtab.c
support/export/xtab.c
support/include/nfslib.h
support/nfs/exports.c

index 74e1d1b1bc46c68ace868e87775eed3580e46372..93c58b62c61f750a7c41247ed982097a4fa63971 100644 (file)
@@ -85,6 +85,8 @@ export_init(nfs_export *exp, nfs_client *clp, struct exportent *nep)
        struct exportent        *e = &exp->m_export;
 
        dupexportent(e, nep);
+       if (nep->e_hostname)
+               e->e_hostname = xstrdup(nep->e_hostname);
 
        exp->m_exported = 0;
        exp->m_xtabent = 0;
@@ -109,6 +111,8 @@ export_dup(nfs_export *exp, struct hostent *hp)
        new = (nfs_export *) xmalloc(sizeof(*new));
        memcpy(new, exp, sizeof(*new));
        dupexportent(&new->m_export, &exp->m_export);
+       if (exp->m_export.e_hostname)
+               new->m_export.e_hostname = xstrdup(exp->m_export.e_hostname);
        clp = client_dup(exp->m_client, hp);
        clp->m_count++;
        new->m_client = clp;
@@ -244,6 +248,7 @@ export_freeall(void)
                                free(exp->m_export.e_mountpoint);
                        if (exp->m_export.e_fslocdata)
                                xfree(exp->m_export.e_fslocdata);
+                       xfree(exp->m_export.e_hostname);
                        xfree(exp);
                }
                exportlist[i] = NULL;
index 15aab155ff18791c15d6ab68ba32f82d7909a5f6..2a882aaac0803177646b92acaa2061588e180ac9 100644 (file)
@@ -43,9 +43,7 @@ rmtab_read(void)
                        if (!exp2) {
                                struct exportent ee;
                                dupexportent(&ee, &exp->m_export);
-                               strncpy (ee.e_hostname, rep->r_client,
-                                        sizeof (ee.e_hostname) - 1);
-                               ee.e_hostname[sizeof (ee.e_hostname) -1] = '\0';
+                               ee.e_hostname = rep->r_client;
                                exp2 = export_create(&ee, 0);
                                exp2->m_changed = exp->m_changed;
                        }
index 292087b8c656bc07bd2cd5adea7f76815a7732f8..990113e14bf471da86269867a8b4b4ef4fb7528b 100644 (file)
@@ -108,10 +108,7 @@ xtab_write(char *xtab, char *xtabtmp, int is_export)
 
                        /* write out the export entry using the FQDN */
                        xe = exp->m_export;
-                       strncpy(xe.e_hostname,
-                               exp->m_client->m_hostname,
-                               sizeof (xe.e_hostname) - 1);
-                       xe.e_hostname[sizeof (xe.e_hostname) - 1] = '\0';
+                       xe.e_hostname = exp->m_client->m_hostname;
                        putexportent(&xe);
                }
        }
@@ -146,9 +143,7 @@ xtab_append(nfs_export *exp)
                return;
        setexportent(_PATH_XTAB, "a");
        xe = exp->m_export;
-       strncpy(xe.e_hostname, exp->m_client->m_hostname,
-              sizeof (xe.e_hostname) - 1);
-       xe.e_hostname[sizeof (xe.e_hostname) - 1] = '\0';
+       xe.e_hostname = exp->m_client->m_hostname;
        putexportent(&xe);
        endexportent();
        xfunlock(lockid);
index 5af9c30c33b18d70864cde8c25a70cda1cb6cbf2..ffa2440a9e30e47ced11fef8878e9aaaee1b5b8d 100644 (file)
@@ -65,7 +65,7 @@ struct sec_entry {
  * allow overrides when using exportfs.
  */
 struct exportent {
-       char            e_hostname[NFSCLNT_IDMAX+1];
+       char *          e_hostname;
        char            e_path[NFS_MAXPATHLEN+1];
        /* The mount path may be different from the exported path due
           to submount. It may change for every mount. The idea is we
index c82bb0ef29433048bf4b5b3e1eccecc0be9d79b5..6b567081123edee90f976fd508847df6381ff4c6 100644 (file)
@@ -176,13 +176,8 @@ getexportent(int fromkernel, int fromexports)
                if (!has_default_opts)
                        xlog(L_WARNING, "No options for %s %s: suggest %s(sync) to avoid warning", ee.e_path, exp, exp);
        }
-       if (strlen(hostname) >= sizeof(ee.e_hostname)) {
-               syntaxerr("client name too long");
-               export_errno = EINVAL;
-               return NULL;
-       }
-       strncpy(ee.e_hostname, hostname, sizeof (ee.e_hostname) - 1);
-       ee.e_hostname[sizeof (ee.e_hostname) - 1] = '\0';
+       xfree(ee.e_hostname);
+       ee.e_hostname = xstrdup(hostname);
 
        if (parseopts(opt, &ee, fromexports && !has_default_subtree_opts, NULL) < 0)
                return NULL;
@@ -335,6 +330,7 @@ dupexportent(struct exportent *dst, struct exportent *src)
                dst->e_mountpoint = strdup(src->e_mountpoint);
        if (src->e_fslocdata)
                dst->e_fslocdata = strdup(src->e_fslocdata);
+       dst->e_hostname = NULL;
 }
 
 struct exportent *
@@ -355,12 +351,9 @@ mkexportent(char *hname, char *path, char *options)
        ee.e_nsqgids = 0;
        ee.e_uuid = NULL;
 
-       if (strlen(hname) >= sizeof(ee.e_hostname)) {
-               xlog(L_WARNING, "client name %s too long", hname);
-               return NULL;
-       }
-       strncpy(ee.e_hostname, hname, sizeof (ee.e_hostname) - 1);
-       ee.e_hostname[sizeof (ee.e_hostname) - 1] = '\0';
+       xfree(ee.e_hostname);
+       ee.e_hostname = xstrdup(hname);
+
        if (strlen(path) >= sizeof(ee.e_path)) {
                xlog(L_WARNING, "path name %s too long", path);
                return NULL;