Date: Tue, 29 May 2018 12:19:29 +0000 (UTC) From: Rick Macklem <rmacklem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r334321 - projects/pnfs-planb-server/usr.sbin/nfsd Message-ID: <201805291219.w4TCJT29095940@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rmacklem Date: Tue May 29 12:19:29 2018 New Revision: 334321 URL: https://svnweb.freebsd.org/changeset/base/334321 Log: Fix up nfsd.c for distributed mirror handling. A new "-m" option is added to enable mirroring. The man page still needs to be updated. Modified: projects/pnfs-planb-server/usr.sbin/nfsd/nfsd.c Modified: projects/pnfs-planb-server/usr.sbin/nfsd/nfsd.c ============================================================================== --- projects/pnfs-planb-server/usr.sbin/nfsd/nfsd.c Tue May 29 11:59:02 2018 (r334320) +++ projects/pnfs-planb-server/usr.sbin/nfsd/nfsd.c Tue May 29 12:19:29 2018 (r334321) @@ -59,7 +59,6 @@ static const char rcsid[] = #include <rpc/rpc.h> #include <rpc/pmap_clnt.h> #include <rpcsvc/nfs_prot.h> -#include <rpcsvc/mount.h> #include <netdb.h> #include <arpa/inet.h> @@ -111,6 +110,7 @@ static struct option longopts[] = { { "minthreads", required_argument, &minthreads_set, 1 }, { "maxthreads", required_argument, &maxthreads_set, 1 }, { "pnfs", required_argument, NULL, 'p' }, + { "mirror", required_argument, NULL, 'm' }, { NULL, 0, NULL, 0} }; @@ -157,6 +157,8 @@ static void parse_dsserver(const char *, struct nfsd_n * -t - support tcp nfs clients * -u - support udp nfs clients * -e - forces it to run a server that supports nfsv4 + * -p - enable a pNFS service + * -m - set the mirroring level for a pNFS service * followed by "n" which is the number of nfsds' to fork off */ int @@ -185,16 +187,17 @@ main(int argc, char **argv) pid_t pid; struct nfsd_nfsd_args nfsdargs; + nfsdargs.mirrorcnt = 1; nfsdcnt = DEFNFSDCNT; unregister = reregister = tcpflag = maxsock = 0; bindanyflag = udpflag = connect_type_cnt = bindhostc = 0; - getopt_shortopts = "ah:n:rdtuep:"; + getopt_shortopts = "ah:n:rdtuep:m:"; getopt_usage = "usage:\n" " nfsd [-ardtue] [-h bindip]\n" " [-n numservers] [--minthreads #] [--maxthreads #]\n" " [-p/--pnfs dsserver0:/dsserver0-mounted-on-dir,...," - "dsserverN:/dsserverN-mounted-on-dir\n"; + "dsserverN:/dsserverN-mounted-on-dir] [-m mirrorlevel]\n"; while ((ch = getopt_long(argc, argv, getopt_shortopts, longopts, &longindex)) != -1) switch (ch) { @@ -232,6 +235,14 @@ main(int argc, char **argv) /* Parse out the DS server host names and mount pts. */ parse_dsserver(optarg, &nfsdargs); break; + case 'm': + /* Set the mirror level for a pNFS service. */ + i = atoi(optarg); + if (i < 2 || i > NFSDEV_MAXMIRRORS) + errx(1, "Mirror level out of range 2<-->%d", + NFSDEV_MAXMIRRORS); + nfsdargs.mirrorcnt = i; + break; case 0: lopt = longopts[longindex].name; if (!strcmp(lopt, "minthreads")) { @@ -1175,10 +1186,8 @@ static void parse_dsserver(const char *optarg, struct nfsd_nfsd_args *nfsdargp) { char *ad, *cp, *cp2, *dsaddr, *dshost, *dspath, *dsvol, nfsprt[9]; - char *mirror, mirrorstr[NFSDEV_MIRRORSTR + 1], *cp3; int adsiz, dsaddrcnt, dshostcnt, dspathcnt, ecode, hostsiz, pathsiz; - int mirrorcnt, mirrorstrsiz, mirrorindex; - size_t dsaddrsiz, dshostsiz, dspathsiz, nfsprtsiz, mirrorsiz; + size_t dsaddrsiz, dshostsiz, dspathsiz, nfsprtsiz; struct addrinfo hints, *ai_tcp; struct sockaddr_in *sin; @@ -1202,38 +1211,20 @@ parse_dsserver(const char *optarg, struct nfsd_nfsd_ar dsaddr = malloc(dsaddrsiz); if (dsaddr == NULL) errx(1, "Out of memory"); - mirrorsiz = 1024; - mirrorcnt = 0; - mirror = malloc(mirrorsiz); - if (mirror == NULL) - errx(1, "Out of memory"); /* Put the NFS port# in "." form. */ snprintf(nfsprt, 9, ".%d.%d", 2049 >> 8, 2049 & 0xff); nfsprtsiz = strlen(nfsprt); ai_tcp = NULL; - mirrorindex = 0; /* Loop around for each DS server name. */ do { - /* - * If the next DS is separated from the current one with a '#', - * it is a mirror. If the next DS is separated from the current - * one with a ',', it is not a mirror of the previous DS. - */ cp2 = strchr(cp, ','); - cp3 = strchr(cp, '#'); - if (cp3 != NULL && (cp2 == NULL || cp3 < cp2)) - cp2 = cp3; /* A mirror of the previous DS. */ - else - cp3 = NULL; /* Not a mirror of the previous DS. */ if (cp2 != NULL) { /* Not the last DS in the list. */ *cp2++ = '\0'; if (*cp2 == '\0') usage(); - if (cp3 == NULL) - mirrorindex++; /* Increment if not a mirror. */ } dsvol = strchr(cp, ':'); @@ -1294,20 +1285,6 @@ printf("pnfs path=%s\n", dsvol); strcpy(&dshost[dshostcnt], ai_tcp->ai_canonname); dshostcnt += hostsiz + 1; - /* Append this mirrorindex to mirror. */ - if (snprintf(mirrorstr, NFSDEV_MIRRORSTR + 1, "%d", - mirrorindex) > NFSDEV_MIRRORSTR) - errx(1, "Too many mirrors"); - mirrorstrsiz = strlen(mirrorstr); - if (mirrorcnt + mirrorstrsiz + 1 > mirrorsiz) { - mirrorsiz *= 2; - mirror = realloc(mirror, mirrorsiz); - if (mirror == NULL) - errx(1, "Out of memory"); - } - strcpy(&mirror[mirrorcnt], mirrorstr); - mirrorcnt += mirrorstrsiz + 1; - cp = cp2; } while (cp != NULL); @@ -1323,8 +1300,6 @@ printf("pnfs path=%s\n", dsvol); nfsdargp->dnshostlen = dshostcnt; nfsdargp->dspath = dspath; nfsdargp->dspathlen = dspathcnt; - nfsdargp->mirror = mirror; - nfsdargp->mirrorlen = mirrorcnt; freeaddrinfo(ai_tcp); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201805291219.w4TCJT29095940>