-2001-09020 NeilBrown <neilb@cse.unsw.edu.au>
+2001-09-20 NeilBrown <neilb@cse.unsw.edu.au>
+
+ Arrange that "exportfs -au" never does DNS lookup:
+
+ * support/export/client.c (client_lookup) : add "canonical"
+ flag which says that the hostname is known to be canonical, so
+ don't do a lookup
+
+ * support/export/export.c (export_create) : add "canonical"
+ flag to be passed down to client_lookup
+ * support/export/export.c (export_lookup) : Likewise
+
+ * support/export/xtab.c (xtab_read) : pass appropriate
+ "canonical" flag to export_lookup and export_create:
+ set if reading list of filesystems currently exports
+ (is_export != 1).
+
+ * support/export/export.c (export_read) : pass 0 as
+ "canonical" flag to export_lookup and export_create
+ * support/export/rmtab.s (rmtab_read) : Likewise
+
+ * support/include/exportfs.h : redeclare various routines
+ to have "canonical" flag
+
+ * utils/exportfs/exportfs.c (main) : redo logic for
+ "-au" to read in what is currently exported, but never even
+ look at what "should" be exported.
+
+ * utils/exportfs/exportfs.c (unexportall) : remove this
+ routine. Functionality is completely included in
+ exports_update
+
+ * utils/exportfs/exportfs.c (exportfs) : set "canonical"
+ flag to zero in calls to export_lookup and export_create.
+
+
+2001-09-20 NeilBrown <neilb@cse.unsw.edu.au>
Anne Milicia <milicia@missioncriticallinux.com>
* support/export/client.c (client_lookup) call gethostbyadd
nfs_client *clientlist[MCL_MAXTYPES] = { NULL, };
+/* if canonical is set, then we *know* this is already a canonical name
+ * so hostname lookup is avoided.
+ * This is used when reading /proc/fs/nfs/exports
+ */
nfs_client *
-client_lookup(char *hname)
+client_lookup(char *hname, int canonical)
{
nfs_client *clp = NULL;
int htype;
htype = client_gettype(hname);
- if (htype == MCL_FQDN) {
+ if (htype == MCL_FQDN && !canonical) {
struct hostent *hp2;
hp = gethostbyname(hname);
if (hp == NULL || hp->h_addrtype != AF_INET) {
setexportent(fname, "r");
while ((eep = getexportent()) != NULL) {
- exp = export_lookup(eep->e_hostname, eep->e_path);
+ exp = export_lookup(eep->e_hostname, eep->e_path, 0);
if (!exp)
- export_create(eep);
+ export_create(eep,0);
else {
if (exp->m_export.e_flags != eep->e_flags) {
xlog(L_ERROR, "incompatible duplicated export entries:");
* Create an in-core export struct from an export entry.
*/
nfs_export *
-export_create(struct exportent *xep)
+export_create(struct exportent *xep, int canonical)
{
nfs_client *clp;
nfs_export *exp;
- if (!(clp = client_lookup(xep->e_hostname))) {
+ if (!(clp = client_lookup(xep->e_hostname, canonical))) {
/* bad export entry; complaint already logged */
return NULL;
}
}
nfs_export *
-export_lookup(char *hname, char *path)
+export_lookup(char *hname, char *path, int canonical)
{
nfs_client *clp;
nfs_export *exp;
- if (!(clp = client_lookup(hname)))
+ if (!(clp = client_lookup(hname, canonical)))
return NULL;
for (exp = exportlist[clp->m_type]; exp; exp = exp->m_next)
if (exp->m_client == clp && !strcmp(exp->m_export.e_path, path))
/* see if the entry already exists, otherwise this was an instantiated
* wild card, and we must add it
*/
- exp = export_lookup(rep->r_client, xp->e_path);
+ exp = export_lookup(rep->r_client, xp->e_path, 0);
if (!exp) {
strncpy (xp->e_hostname, rep->r_client,
sizeof (xp->e_hostname) - 1);
xp->e_hostname[sizeof (xp->e_hostname) -1] = '\0';
- exp = export_create(xp);
+ exp = export_create(xp, 0);
}
free (hp);
return 0;
setexportent(xtab, "r");
while ((xp = getexportent()) != NULL) {
- if (!(exp = export_lookup(xp->e_hostname, xp->e_path)) &&
- !(exp = export_create(xp))) {
+ if (!(exp = export_lookup(xp->e_hostname, xp->e_path, is_export != 1)) &&
+ !(exp = export_create(xp, is_export!=1))) {
continue;
}
switch (is_export) {
extern nfs_client * clientlist[MCL_MAXTYPES];
extern nfs_export * exportlist[MCL_MAXTYPES];
-nfs_client * client_lookup(char *hname);
+nfs_client * client_lookup(char *hname, int canonical);
nfs_client * client_find(struct hostent *);
void client_add(nfs_client *);
nfs_client * client_dup(nfs_client *, struct hostent *);
int export_read(char *fname);
void export_add(nfs_export *);
void export_reset(nfs_export *);
-nfs_export * export_lookup(char *hname, char *path);
+nfs_export * export_lookup(char *hname, char *path, int caconical);
nfs_export * export_find(struct hostent *, char *path);
struct exportent * export_allowed(struct hostent *, char *path);
-nfs_export * export_create(struct exportent *);
+nfs_export * export_create(struct exportent *, int canonical);
nfs_export * export_dup(nfs_export *, struct hostent *);
void export_freeall(void);
int export_export(nfs_export *);
#include "xlog.h"
static void export_all(int verbose);
-static void unexport_all(int verbose);
static void exportfs(char *arg, char *options, int verbose);
static void unexportfs(char *arg, int verbose);
static void exports_update(int verbose);
for (i = optind; i < argc ; i++)
exportfs(argv[i], options, f_verbose);
}
- /* note: xtab_*_read does not update entries if they already exist,
- * so this will not lose new options
+ /* If we are unexporting everything, then
+ * don't care about what should be exported, as that
+ * may require DNS lookups..
*/
- if (!f_reexport)
- xtab_export_read();
- if (!f_export) {
- if (f_all)
- unexport_all(f_verbose);
- else
+ if (! ( !f_export && f_all)) {
+ /* note: xtab_*_read does not update entries if they already exist,
+ * so this will not lose new options
+ */
+ if (!f_reexport)
+ xtab_export_read();
+ if (!f_export)
for (i = optind ; i < argc ; i++)
unexportfs(argv[i], f_verbose);
+ rmtab_read();
}
- rmtab_read();
xtab_mount_read();
exports_update(f_verbose);
xtab_export_write();
}
}
}
-/*
- * unexport_all finds all entries that are mayexport, and
- * marks them not xtabent and not mayexport
- */
-static void
-unexport_all(int verbose)
-{
- nfs_export *exp;
- int i;
-
- for (i = 0; i < MCL_MAXTYPES; i++) {
- for (exp = exportlist[i]; exp; exp = exp->m_next)
- if (exp->m_mayexport) {
- if (verbose) {
- if (exp->m_exported) {
- printf("unexporting %s:%s from kernel\n",
- exp->m_client->m_hostname,
- exp->m_export.e_path);
- }
- else {
- printf("unexporting %s:%s\n",
- exp->m_client->m_hostname,
- exp->m_export.e_path);
- }
- }
- if (exp->m_exported && !export_unexport(exp))
- error(exp, errno);
- exp->m_xtabent = 0;
- exp->m_mayexport = 0;
- }
- }
-}
static void
hp = hp2;
exp = export_find(hp, path);
} else {
- exp = export_lookup(hname, path);
+ exp = export_lookup(hname, path, 0);
}
if (!exp) {
if (!(eep = mkexportent(hname, path, options)) ||
- !(exp = export_create(eep))) {
+ !(exp = export_create(eep, 0))) {
if (hp) free (hp);
return;
}