svn commit: r323163 - projects/pnfs-planb-server/usr.bin/pnfsdsfile
Rick Macklem
rmacklem at FreeBSD.org
Mon Sep 4 21:17:51 UTC 2017
Author: rmacklem
Date: Mon Sep 4 21:17:50 2017
New Revision: 323163
URL: https://svnweb.freebsd.org/changeset/base/323163
Log:
Fix pnfsdsfile to handle mirrors.
Modified:
projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.c
Modified: projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.c
==============================================================================
--- projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.c Mon Sep 4 21:14:12 2017 (r323162)
+++ projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.c Mon Sep 4 21:17:50 2017 (r323163)
@@ -40,6 +40,9 @@ __FBSDID("$FreeBSD$");
#include <sys/mount.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <fs/nfs/nfskpiport.h>
+#include <fs/nfs/nfsproto.h>
+#include <fs/nfs/nfs.h>
#include <fs/nfs/nfsrvstate.h>
static void usage(void);
@@ -65,12 +68,14 @@ main(int argc, char *argv[])
struct sockaddr_in *sin, *adsin;
struct sockaddr_in6 *sin6, *adsin6;
char hostn[2 * NI_MAXHOST + 2], *cp;
- struct pnfsdsfile dsfile;
- int ch, quiet, zerofh;
+ struct pnfsdsfile dsfile[NFSDEV_MAXMIRRORS];
+ int ch, dosetxattr, i, mirrorcnt, quiet, zerofh;
in_port_t tport;
+ ssize_t xattrsize;
zerofh = 0;
quiet = 0;
+ dosetxattr = 0;
res = NULL;
newres = NULL;
while ((ch = getopt_long(argc, argv, "c:qs:z", longopts, NULL)) != -1) {
@@ -116,110 +121,121 @@ main(int argc, char *argv[])
* The host address and directory where the data storage file is
* located is in the extended attribute "pnfsd.dsfile".
*/
- if (extattr_get_file(*argv, EXTATTR_NAMESPACE_SYSTEM, "pnfsd.dsfile",
- &dsfile, sizeof(dsfile)) != sizeof(dsfile))
+ xattrsize = extattr_get_file(*argv, EXTATTR_NAMESPACE_SYSTEM,
+ "pnfsd.dsfile", dsfile, sizeof(dsfile));
+ mirrorcnt = xattrsize / sizeof(struct pnfsdsfile);
+ if (mirrorcnt < 1 || xattrsize != mirrorcnt * sizeof(struct pnfsdsfile))
err(1, "Can't get extattr pnfsd.dsfile\n");
- /* Do the zerofh option. You must be root to use this option. */
- if (zerofh != 0) {
- if (geteuid() != 0)
- errx(1, "Must be root/su to zerofh\n");
-
- /*
- * Do it for the server specified by -s/--ds or all servers,
- * if -s/--ds was not sepcified.
- */
- sin = &dsfile.dsf_sin;
- sin6 = &dsfile.dsf_sin6;
- ad = res;
- while (ad != NULL) {
- adsin = (struct sockaddr_in *)ad->ai_addr;
- adsin6 = (struct sockaddr_in6 *)ad->ai_addr;
- if (adsin->sin_family == sin->sin_family) {
- if (sin->sin_family == AF_INET &&
- sin->sin_addr.s_addr ==
- adsin->sin_addr.s_addr)
- break;
- else if (sin->sin_family == AF_INET6 &&
- IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr,
- &adsin6->sin6_addr))
- break;
+ for (i = 0; i < mirrorcnt; i++) {
+ if (i > 0)
+ printf(" ");
+ /* Do the zerofh option. You must be root. */
+ if (zerofh != 0) {
+ if (geteuid() != 0)
+ errx(1, "Must be root/su to zerofh\n");
+
+ /*
+ * Do it for the server specified by -s/--ds or all
+ * servers, if -s/--ds was not specified.
+ */
+ sin = &dsfile[i].dsf_sin;
+ sin6 = &dsfile[i].dsf_sin6;
+ ad = res;
+ while (ad != NULL) {
+ adsin = (struct sockaddr_in *)ad->ai_addr;
+ adsin6 = (struct sockaddr_in6 *)ad->ai_addr;
+ if (adsin->sin_family == sin->sin_family) {
+ if (sin->sin_family == AF_INET &&
+ sin->sin_addr.s_addr ==
+ adsin->sin_addr.s_addr)
+ break;
+ else if (sin->sin_family == AF_INET6 &&
+ IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr,
+ &adsin6->sin6_addr))
+ break;
+ }
+ ad = ad->ai_next;
}
- ad = ad->ai_next;
- }
- if (res == NULL || ad != NULL) {
- memset(&dsfile.dsf_fh, 0, sizeof(dsfile.dsf_fh));
- if (extattr_set_file(*argv, EXTATTR_NAMESPACE_SYSTEM,
- "pnfsd.dsfile", &dsfile, sizeof(dsfile)) !=
- sizeof(dsfile))
- err(1, "Can't set pnfsd.dsfile\n");
- }
- }
-
- /* Do the -c option to replace the DS host address. */
- if (newres != NULL) {
- if (geteuid() != 0)
- errx(1, "Must be root/su to replace the host addr\n");
-
- /*
- * Check that the old host address matches.
- */
- sin = &dsfile.dsf_sin;
- sin6 = &dsfile.dsf_sin6;
- ad = res;
- while (ad != NULL) {
- adsin = (struct sockaddr_in *)ad->ai_addr;
- adsin6 = (struct sockaddr_in6 *)ad->ai_addr;
- if (adsin->sin_family == sin->sin_family) {
- if (sin->sin_family == AF_INET &&
- sin->sin_addr.s_addr ==
- adsin->sin_addr.s_addr)
- break;
- else if (sin->sin_family == AF_INET6 &&
- IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr,
- &adsin6->sin6_addr))
- break;
+ if (res == NULL || ad != NULL) {
+ memset(&dsfile[i].dsf_fh, 0, sizeof(fhandle_t));
+ dosetxattr = 1;
}
- ad = ad->ai_next;
}
- if (ad != NULL) {
- if (sin->sin_family == AF_INET)
- tport = sin->sin_port;
- else
- tport = sin6->sin6_port;
+
+ /* Do the -c option to replace the DS host address. */
+ if (newres != NULL) {
+ if (geteuid() != 0)
+ errx(1, "Must be root/su to replace the host"
+ " addr\n");
+
/*
- * We have a match, so replace it with the first
- * AF_INET or AF_INET6 address in the newres list.
+ * Check that the old host address matches.
*/
- while (newres->ai_addr->sa_family != AF_INET &&
- newres->ai_addr->sa_family != AF_INET6) {
- newres = newres->ai_next;
- if (newres == NULL)
- errx(1, "Hostname %s has no IP#\n", cp);
+ sin = &dsfile[i].dsf_sin;
+ sin6 = &dsfile[i].dsf_sin6;
+ ad = res;
+ while (ad != NULL) {
+ adsin = (struct sockaddr_in *)ad->ai_addr;
+ adsin6 = (struct sockaddr_in6 *)ad->ai_addr;
+ if (adsin->sin_family == sin->sin_family) {
+ if (sin->sin_family == AF_INET &&
+ sin->sin_addr.s_addr ==
+ adsin->sin_addr.s_addr)
+ break;
+ else if (sin->sin_family == AF_INET6 &&
+ IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr,
+ &adsin6->sin6_addr))
+ break;
+ }
+ ad = ad->ai_next;
}
- if (newres->ai_addr->sa_family == AF_INET) {
- memcpy(sin, newres->ai_addr, sizeof(*sin));
- sin->sin_port = tport;
- } else if (newres->ai_addr->sa_family == AF_INET6) {
- memcpy(sin6, newres->ai_addr, sizeof(*sin6));
- sin6->sin6_port = tport;
+ if (ad != NULL) {
+ if (sin->sin_family == AF_INET)
+ tport = sin->sin_port;
+ else
+ tport = sin6->sin6_port;
+ /*
+ * We have a match, so replace it with the first
+ * AF_INET or AF_INET6 address in the newres
+ * list.
+ */
+ while (newres->ai_addr->sa_family != AF_INET &&
+ newres->ai_addr->sa_family != AF_INET6) {
+ newres = newres->ai_next;
+ if (newres == NULL)
+ errx(1, "Hostname %s has no"
+ " IP#\n", cp);
+ }
+ if (newres->ai_addr->sa_family == AF_INET) {
+ memcpy(sin, newres->ai_addr,
+ sizeof(*sin));
+ sin->sin_port = tport;
+ } else if (newres->ai_addr->sa_family ==
+ AF_INET6) {
+ memcpy(sin6, newres->ai_addr,
+ sizeof(*sin6));
+ sin6->sin6_port = tport;
+ }
+ dosetxattr = 1;
}
- if (extattr_set_file(*argv, EXTATTR_NAMESPACE_SYSTEM,
- "pnfsd.dsfile", &dsfile, sizeof(dsfile)) !=
- sizeof(dsfile))
- err(1, "Can't set pnfsd.dsfile\n");
}
+
+ if (quiet == 0) {
+ /* Translate the IP address to a hostname. */
+ if (getnameinfo((struct sockaddr *)&dsfile[i].dsf_sin,
+ dsfile[i].dsf_sin.sin_len, hostn, sizeof(hostn),
+ NULL, 0, 0) < 0)
+ err(1, "Can't get hostname\n");
+ printf("%s\tds%d/%s", hostn, dsfile[i].dsf_dir,
+ dsfile[i].dsf_filename);
+ }
}
-
- if (quiet != 0)
- exit(0);
-
- /* Translate the IP address to a hostname. */
- if (getnameinfo((struct sockaddr *)&dsfile.dsf_sin,
- dsfile.dsf_sin.sin_len, hostn, sizeof(hostn), NULL, 0, 0) < 0)
- err(1, "Can't get hostname\n");
-
- printf("%s\tds%d/%s\n", hostn, dsfile.dsf_dir, dsfile.dsf_filename);
+ if (quiet == 0)
+ printf("\n");
+ if (dosetxattr != 0 && extattr_set_file(*argv, EXTATTR_NAMESPACE_SYSTEM,
+ "pnfsd.dsfile", dsfile, xattrsize) != xattrsize)
+ err(1, "Can't set pnfsd.dsfile\n");
}
static void
More information about the svn-src-projects
mailing list