]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/mountd/cache.c
Open channel files O_WRONLY, and improve mountlist support.
[nfs-utils.git] / utils / mountd / cache.c
index c5bc53fa3023166a4d3f51d8ce99a3806c1ba72f..2e35b17417173914899234d4cfe28f6ff9aa42a4 100644 (file)
@@ -78,6 +78,9 @@ void auth_unix_ip(FILE *f)
                qword_print(f, *client?client:"DEFAULT");
        qword_eol(f);
 
+       if (client && strcmp(ipaddr, client))
+               mountlist_add(ipaddr, *client?client:"DEFAULT");
+
        if (client) free(client);
        
 }
@@ -100,6 +103,7 @@ void nfsd_fh(FILE *f)
        struct exportent *found = NULL;
        nfs_export *exp;
        int i;
+       int dev_missing = 0;
 
        if (readline(fileno(f), &lbuf, &lbuflen) != 1)
                return;
@@ -145,6 +149,11 @@ void nfsd_fh(FILE *f)
                                continue;
                        if (fsidtype == 0) {
                                struct stat stb;
+                               if (exp->m_export.e_mountpoint &&
+                                   !is_mountpoint(exp->m_export.e_mountpoint[0]?
+                                                  exp->m_export.e_mountpoint:
+                                                  exp->m_export.e_path))
+                                       dev_missing ++;
                                if (stat(exp->m_export.e_path, &stb) != 0)
                                        continue;
                                if (stb.st_ino != inode)
@@ -158,12 +167,33 @@ void nfsd_fh(FILE *f)
                                found = &exp->m_export;
                        else if (strcmp(found->e_path, exp->m_export.e_path)!= 0)
                        {
-                               xlog(L_WARNING, "%s and %s have name filehandle for %s, using first",
+                               xlog(L_WARNING, "%s and %s have same filehandle for %s, using first",
                                     found->e_path, exp->m_export.e_path, dom);
                        }
                }
        }
-       cache_export_ent(dom, found);
+       if (found && 
+           found->e_mountpoint &&
+           !is_mountpoint(found->e_mountpoint[0]?
+                          found->e_mountpoint:
+                          found->e_path)) {
+               /* Cannot export this yet 
+                * should log a warning, but need to rate limit
+                  xlog(L_WARNING, "%s not exported as %d not a mountpoint",
+                  found->e_path, found->e_mountpoint);
+                */
+               /* FIXME we need to make sure we re-visit this later */
+               goto out;
+       }
+       if (!found && dev_missing) {
+               /* The missing dev could be what we want, so just be
+                * quite rather than returning stale yet
+                */
+               goto out;
+       }
+
+       if (found)
+               cache_export_ent(dom, found);
 
        qword_print(f, dom);
        qword_printint(f, fsidtype);
@@ -231,6 +261,7 @@ void nfsd_export(FILE *f)
                qword_printint(f, found->m_export.e_anonuid);
                qword_printint(f, found->m_export.e_anongid);
                qword_printint(f, found->m_export.e_fsid);
+               mountlist_add(dom, path);
        }
        qword_eol(f);
  out:
@@ -293,7 +324,7 @@ int cache_process_req(fd_set *readfds)
 void cache_export_ent(char *domain, struct exportent *exp)
 {
 
-       FILE *f = fopen("/proc/net/rpc/nfsd.export/channel", "r+");
+       FILE *f = fopen("/proc/net/rpc/nfsd.export/channel", "w");
        if (!f)
                return;
 
@@ -307,13 +338,15 @@ void cache_export_ent(char *domain, struct exportent *exp)
        qword_eol(f);
 
        fclose(f);
+
+       mountlist_add(domain, exp->e_path);
 }
 
 void cache_export(nfs_export *exp)
 {
        FILE *f;
 
-       f = fopen("/proc/net/rpc/auth.unix.ip/channel", "r+");
+       f = fopen("/proc/net/rpc/auth.unix.ip/channel", "w");
        if (!f)
                return;
 
@@ -325,6 +358,9 @@ void cache_export(nfs_export *exp)
        
        fclose(f);
 
+       if (strcmp(inet_ntoa(exp->m_client->m_addrlist[0]), exp->m_client->m_hostname))
+               mountlist_add(inet_ntoa(exp->m_client->m_addrlist[0]), exp->m_client->m_hostname);
+
        cache_export_ent(exp->m_client->m_hostname, &exp->m_export);
 }