From owner-svn-src-all@freebsd.org Sun Jul 1 17:49:03 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B6DC1FD0FBA; Sun, 1 Jul 2018 17:49:03 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 56784772D5; Sun, 1 Jul 2018 17:49:03 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 12DA721EEB; Sun, 1 Jul 2018 17:49:03 +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 w61Hn23g016235; Sun, 1 Jul 2018 17:49:02 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w61Hn2ZR016234; Sun, 1 Jul 2018 17:49:02 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201807011749.w61Hn2ZR016234@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Sun, 1 Jul 2018 17:49:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335845 - head/usr.sbin/pnfsdsfile X-SVN-Group: head X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: head/usr.sbin/pnfsdsfile X-SVN-Commit-Revision: 335845 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Jul 2018 17:49:04 -0000 Author: rmacklem Date: Sun Jul 1 17:49:02 2018 New Revision: 335845 URL: https://svnweb.freebsd.org/changeset/base/335845 Log: Add a new "-m" option to pnfsdsfile(8) to prepare a file for mirroring. When pnfsdscopymr(8) is used to create a mirror of a file on a mirrored pNFS service, it expects to find an entry in the extended attribute for IP address 0.0.0.0. This patch adds a "-m" option which can be used to create these entrie(s). It also tightens up the checks for use of incompatible command line options. Modified: head/usr.sbin/pnfsdsfile/pnfsdsfile.c Modified: head/usr.sbin/pnfsdsfile/pnfsdsfile.c ============================================================================== --- head/usr.sbin/pnfsdsfile/pnfsdsfile.c Sun Jul 1 17:28:46 2018 (r335844) +++ head/usr.sbin/pnfsdsfile/pnfsdsfile.c Sun Jul 1 17:49:02 2018 (r335845) @@ -50,6 +50,7 @@ static void usage(void); static struct option longopts[] = { { "changeds", required_argument, NULL, 'c' }, + { "mirror", required_argument, NULL, 'm' }, { "quiet", no_argument, NULL, 'q' }, { "zerods", required_argument, NULL, 'r' }, { "ds", required_argument, NULL, 's' }, @@ -71,27 +72,27 @@ main(int argc, char *argv[]) struct sockaddr_in6 *sin6, adsin6; char hostn[2 * NI_MAXHOST + 2], *cp; struct pnfsdsfile dsfile[NFSDEV_MAXMIRRORS]; - int ch, dosetxattr, i, mirrorcnt, quiet, zerods, zerofh; + int ch, dosetxattr, i, mirrorcnt, mirrorit, quiet, zerods, zerofh; in_port_t tport; ssize_t xattrsize, xattrsize2; zerods = 0; zerofh = 0; + mirrorit = 0; quiet = 0; dosetxattr = 0; res = NULL; newres = NULL; cp = NULL; - while ((ch = getopt_long(argc, argv, "c:qr:s:z", longopts, NULL)) != -1) - { + while ((ch = getopt_long(argc, argv, "c:m:qr:s:z", longopts, NULL)) != + -1) { switch (ch) { case 'c': /* Replace the first DS server with the second one. */ - if (zerofh != 0 || zerods != 0) - errx(1, "-c, -r and -z are mutually " - "exclusive"); - if (res != NULL) - errx(1, "-c and -s are mutually exclusive"); + if (zerofh != 0 || zerods != 0 || mirrorit != 0 || + newres != NULL || res != NULL) + errx(1, "-c, -m, -r, -s and -z are mutually " + "exclusive and only can be used once"); strlcpy(hostn, optarg, 2 * NI_MAXHOST + 2); cp = strchr(hostn, ','); if (cp == NULL) @@ -103,31 +104,44 @@ main(int argc, char *argv[]) if (getaddrinfo(cp, NULL, NULL, &newres) != 0) errx(1, "Can't get IP# for %s", cp); break; + case 'm': + /* Add 0.0.0.0 entries up to mirror level. */ + if (zerofh != 0 || zerods != 0 || mirrorit != 0 || + newres != NULL || res != NULL) + errx(1, "-c, -m, -r, -s and -z are mutually " + "exclusive and only can be used once"); + mirrorit = atoi(optarg); + if (mirrorit < 2 || mirrorit > NFSDEV_MAXMIRRORS) + errx(1, "-m %d out of range", mirrorit); + break; case 'q': quiet = 1; break; case 'r': /* Reset the DS server in a mirror with 0.0.0.0. */ - if (zerofh != 0 || res != NULL || newres != NULL) - errx(1, "-r and -s, -z or -c are mutually " - "exclusive"); + if (zerofh != 0 || zerods != 0 || mirrorit != 0 || + newres != NULL || res != NULL) + errx(1, "-c, -m, -r, -s and -z are mutually " + "exclusive and only can be used once"); zerods = 1; /* Translate the server name to an IP address. */ if (getaddrinfo(optarg, NULL, NULL, &res) != 0) errx(1, "Can't get IP# for %s", optarg); break; case 's': - if (res != NULL) - errx(1, "-s, -c and -r are mutually " - "exclusive"); /* Translate the server name to an IP address. */ + if (zerods != 0 || mirrorit != 0 || newres != NULL || + res != NULL) + errx(1, "-c, -m and -r are mutually exclusive " + "from use with -s and -z"); if (getaddrinfo(optarg, NULL, NULL, &res) != 0) errx(1, "Can't get IP# for %s", optarg); break; case 'z': - if (newres != NULL || zerods != 0) - errx(1, "-c, -r and -z are mutually " - "exclusive"); + if (zerofh != 0 || zerods != 0 || mirrorit != 0 || + newres != NULL) + errx(1, "-c, -m and -r are mutually exclusive " + "from use with -s and -z"); zerofh = 1; break; default: @@ -309,8 +323,26 @@ main(int argc, char *argv[]) dsfile[i].dsf_filename); } } + /* Add entrie(s) with IP address set to 0.0.0.0, as required. */ + for (i = mirrorcnt; i < mirrorit; i++) { + dsfile[i] = dsfile[0]; + dsfile[i].dsf_sin.sin_family = AF_INET; + dsfile[i].dsf_sin.sin_len = sizeof(struct sockaddr_in); + dsfile[i].dsf_sin.sin_addr.s_addr = 0; + dsfile[i].dsf_sin.sin_port = 0; + if (quiet == 0) { + /* Print out the 0.0.0.0 entry. */ + printf("\t0.0.0.0\tds%d/%s", dsfile[i].dsf_dir, + dsfile[i].dsf_filename); + } + } + if (mirrorit > mirrorcnt) { + xattrsize = mirrorit * sizeof(struct pnfsdsfile); + dosetxattr = 1; + } 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");