From owner-svn-src-projects@freebsd.org Fri Jun 16 21:40:46 2017 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 12FBBD89F88 for ; Fri, 16 Jun 2017 21:40:46 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E36437117D; Fri, 16 Jun 2017 21:40:45 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v5GLejD7076579; Fri, 16 Jun 2017 21:40:45 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v5GLejRU076578; Fri, 16 Jun 2017 21:40:45 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201706162140.v5GLejRU076578@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Fri, 16 Jun 2017 21:40:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r320029 - projects/pnfs-planb-server/usr.bin/pnfsdsfile X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Jun 2017 21:40:46 -0000 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 +#include #include #include #include +#include +#include #include #include #include @@ -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 ] \n"); exit(1); }