svn commit: r320029 - projects/pnfs-planb-server/usr.bin/pnfsdsfile
Rick Macklem
rmacklem at FreeBSD.org
Fri Jun 16 21:40:46 UTC 2017
Author: rmacklem
Date: Fri Jun 16 21:40:44 2017
New Revision: 320029
URL: https://svnweb.freebsd.org/changeset/base/320029
Log:
Add options to pnfsdsfile so that it can be used by a sysadmin to zero out
a DS file handle in the extended attributes. This needs to be done when the
file handle becomes stale and this would normally happen when the file is
recovered from backup. It also adds an option to quiet the normal default
output of where the DS file resides.
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 Fri Jun 16 21:37:05 2017 (r320028)
+++ projects/pnfs-planb-server/usr.bin/pnfsdsfile/pnfsdsfile.c Fri Jun 16 21:40:44 2017 (r320029)
@@ -29,9 +29,12 @@
__FBSDID("$FreeBSD$");
#include <err.h>
+#include <getopt.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include <sys/param.h>
#include <sys/extattr.h>
#include <sys/mount.h>
@@ -41,6 +44,13 @@ __FBSDID("$FreeBSD$");
static void usage(void);
+static struct option longopts[] = {
+ { "quiet", no_argument, NULL, 'q' },
+ { "ds", required_argument, NULL, 's' },
+ { "zerofh", no_argument, NULL, 'z' },
+ { NULL, 0, NULL, 0 }
+};
+
/*
* This program displays the location information of a data storage file
* for a given file on a MetaData Server (MDS) in a pNFS service. This program
@@ -50,20 +60,85 @@ static void usage(void);
int
main(int argc, char *argv[])
{
+ struct addrinfo *res, *ad;
+ struct sockaddr_in *sin, *adsin;
+ struct sockaddr_in6 *sin6, *adsin6;
char hostn[NI_MAXHOST + 1];
struct pnfsdsfile dsfile;
+ int ch, quiet, zerofh;
- if (argc != 2)
+ zerofh = 0;
+ quiet = 0;
+ res = NULL;
+ while ((ch = getopt_long(argc, argv, "qs:z", longopts, NULL)) != -1) {
+ switch (ch) {
+ case 'q':
+ quiet = 1;
+ break;
+ case 's':
+ /* Translate the server name to an IP address. */
+ if (getaddrinfo(optarg, NULL, NULL, &res) != 0)
+ errx(1, "Can't get IP# for %s\n", optarg);
+ break;
+ case 'z':
+ zerofh = 1;
+ break;
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ if (argc != 1)
usage();
+ argv += optind;
/*
* The host address and directory where the data storage file is
* located is in the extended attribute "pnfsd.dsfile".
*/
- if (extattr_get_file(argv[1], EXTATTR_NAMESPACE_SYSTEM, "pnfsd.dsfile",
+ if (extattr_get_file(*argv, EXTATTR_NAMESPACE_SYSTEM, "pnfsd.dsfile",
&dsfile, sizeof(dsfile)) != sizeof(dsfile))
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;
+ }
+ 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");
+ }
+ }
+
+ 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)
@@ -76,7 +151,8 @@ static void
usage(void)
{
- fprintf(stderr, "pnfsdsfile [filepath]\n");
+ fprintf(stderr, "pnfsdsfile [-q/--quiet] [-z/--zerofh] "
+ "[-s/--ds <dshostname>] <filename>\n");
exit(1);
}
More information about the svn-src-projects
mailing list