Date: Fri, 16 Jun 2017 21:36:21 +0000 (UTC) From: Rick Macklem <rmacklem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r320027 - projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile Message-ID: <201706162136.v5GLaLGY076311@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rmacklem Date: Fri Jun 16 21:36:21 2017 New Revision: 320027 URL: https://svnweb.freebsd.org/changeset/base/320027 Log: Add some command line options to pnfsdsfile so that it can be used by a sysadmin to zero out the file handle field of the pnfsd.dsfile extended attribute. It also adds an option to suppress the default output of where the DS file can be found. Modified: projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/pnfsdsfile.c Modified: projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/pnfsdsfile.c ============================================================================== --- projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/pnfsdsfile.c Fri Jun 16 21:26:41 2017 (r320026) +++ projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/pnfsdsfile.c Fri Jun 16 21:36:21 2017 (r320027) @@ -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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706162136.v5GLaLGY076311>