From owner-svn-src-projects@freebsd.org Mon Sep 4 21:14:14 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 07215E1EC14 for ; Mon, 4 Sep 2017 21:14:14 +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 D59D52C62; Mon, 4 Sep 2017 21:14:13 +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 v84LECSt075794; Mon, 4 Sep 2017 21:14:12 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v84LECai075793; Mon, 4 Sep 2017 21:14:12 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201709042114.v84LECai075793@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Mon, 4 Sep 2017 21:14:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r323162 - projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile X-SVN-Group: projects X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile X-SVN-Commit-Revision: 323162 X-SVN-Commit-Repository: base 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: Mon, 04 Sep 2017 21:14:14 -0000 Author: rmacklem Date: Mon Sep 4 21:14:12 2017 New Revision: 323162 URL: https://svnweb.freebsd.org/changeset/base/323162 Log: Fix pnfsdsfile to handle mirrors. 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 Mon Sep 4 20:57:38 2017 (r323161) +++ projects/pnfs-planb-server-stable11/usr.bin/pnfsdsfile/pnfsdsfile.c Mon Sep 4 21:14:12 2017 (r323162) @@ -40,6 +40,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +#include +#include #include 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