From owner-svn-src-head@freebsd.org Wed Oct 4 08:43:58 2017 Return-Path: Delivered-To: svn-src-head@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 F1027E32D64; Wed, 4 Oct 2017 08:43:57 +0000 (UTC) (envelope-from manu@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 C07AB77CEC; Wed, 4 Oct 2017 08:43:57 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v948hu2X028835; Wed, 4 Oct 2017 08:43:56 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v948huhc028834; Wed, 4 Oct 2017 08:43:56 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201710040843.v948huhc028834@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Wed, 4 Oct 2017 08:43:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324257 - head/usr.sbin/mountd X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: head/usr.sbin/mountd X-SVN-Commit-Revision: 324257 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Oct 2017 08:43:58 -0000 Author: manu Date: Wed Oct 4 08:43:56 2017 New Revision: 324257 URL: https://svnweb.freebsd.org/changeset/base/324257 Log: mountd: Convert exportlist to SLIST Use SLIST from sys/queue.h instead of homebrew linked list for the exportlist. Reviewed by: bapt, rmacklem MFC after: 1 week Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D12502 Modified: head/usr.sbin/mountd/mountd.c Modified: head/usr.sbin/mountd/mountd.c ============================================================================== --- head/usr.sbin/mountd/mountd.c Wed Oct 4 07:43:23 2017 (r324256) +++ head/usr.sbin/mountd/mountd.c Wed Oct 4 08:43:56 2017 (r324257) @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -108,7 +109,6 @@ struct dirlist { #define DP_HOSTSET 0x2 struct exportlist { - struct exportlist *ex_next; struct dirlist *ex_dirl; struct dirlist *ex_defdir; int ex_flag; @@ -119,6 +119,8 @@ struct exportlist { int ex_secflavors[MAXSECFLAVORS]; int ex_defnumsecflavors; int ex_defsecflavors[MAXSECFLAVORS]; + + SLIST_ENTRY(exportlist) entries; }; /* ex_flag bits */ #define EX_LINKED 0x1 @@ -222,7 +224,7 @@ static int xdr_fhs(XDR *, caddr_t); static int xdr_mlist(XDR *, caddr_t); static void terminate(int); -static struct exportlist *exphead; +static SLIST_HEAD(, exportlist) exphead = SLIST_HEAD_INITIALIZER(exphead); static struct mountlist *mlhead; static struct grouplist *grphead; static char *exnames_default[2] = { _PATH_EXPORTS, NULL }; @@ -445,7 +447,6 @@ main(int argc, char **argv) argc -= optind; argv += optind; grphead = (struct grouplist *)NULL; - exphead = (struct exportlist *)NULL; mlhead = (struct mountlist *)NULL; if (argc > 0) exnames = argv; @@ -1284,8 +1285,8 @@ xdr_explist_common(XDR *xdrsp, caddr_t cp __unused, in sigemptyset(&sighup_mask); sigaddset(&sighup_mask, SIGHUP); sigprocmask(SIG_BLOCK, &sighup_mask, NULL); - ep = exphead; - while (ep) { + + SLIST_FOREACH(ep, &exphead, entries) { putdef = 0; if (put_exlist(ep->ex_dirl, xdrsp, ep->ex_defdir, &putdef, brief)) @@ -1294,7 +1295,6 @@ xdr_explist_common(XDR *xdrsp, caddr_t cp __unused, in put_exlist(ep->ex_defdir, xdrsp, (struct dirlist *)NULL, &putdef, brief)) goto errout; - ep = ep->ex_next; } sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL); if (!xdr_bool(xdrsp, &false)) @@ -1397,9 +1397,8 @@ static FILE *exp_file; static void get_exportlist_one(void) { - struct exportlist *ep, *ep2; + struct exportlist *ep; struct grouplist *grp, *tgrp; - struct exportlist **epp; struct dirlist *dirhead; struct statfs fsb; struct xucred anon; @@ -1676,19 +1675,8 @@ get_exportlist_one(void) } dirhead = (struct dirlist *)NULL; if ((ep->ex_flag & EX_LINKED) == 0) { - ep2 = exphead; - epp = &exphead; + SLIST_INSERT_HEAD(&exphead, ep, entries); - /* - * Insert in the list in alphabetical order. - */ - while (ep2 && strcmp(ep2->ex_fsdir, ep->ex_fsdir) < 0) { - epp = &ep2->ex_next; - ep2 = ep2->ex_next; - } - if (ep2) - ep->ex_next = ep2; - *epp = ep; ep->ex_flag |= EX_LINKED; } nextline: @@ -1730,13 +1718,10 @@ get_exportlist(void) /* * First, get rid of the old list */ - ep = exphead; - while (ep) { - ep2 = ep; - ep = ep->ex_next; - free_exp(ep2); + SLIST_FOREACH_SAFE(ep, &exphead, entries, ep2) { + SLIST_REMOVE(&exphead, ep, exportlist, entries); + free_exp(ep); } - exphead = (struct exportlist *)NULL; grp = grphead; while (grp) { @@ -1918,13 +1903,12 @@ ex_search(fsid_t *fsid) { struct exportlist *ep; - ep = exphead; - while (ep) { + SLIST_FOREACH(ep, &exphead, entries) { if (ep->ex_fs.val[0] == fsid->val[0] && ep->ex_fs.val[1] == fsid->val[1]) return (ep); - ep = ep->ex_next; } + return (ep); }