Page MenuHomeFreeBSD

D57553.diff
No OneTemporary

D57553.diff

diff --git a/sys/kern/vfs_export.c.precreate b/sys/kern/vfs_export.c
--- a/sys/kern/vfs_export.c.precreate
+++ b/sys/kern/vfs_export.c
@@ -58,6 +58,7 @@
#include <netinet/in.h>
#include <net/radix.h>
+#include <sys/netexport.h>
#include <rpc/types.h>
#include <rpc/auth.h>
@@ -69,30 +70,11 @@
struct radix_node_head **prnh, int off);
#endif
static int vfs_free_netcred(struct radix_node *rn, void *w);
+static struct netexport *vfs_netexport_alloc(void);
static void vfs_free_addrlist_af(struct radix_node_head **prnh);
static int vfs_hang_addrlist(struct mount *mp, struct netexport *nep,
struct export_args *argp);
static struct netcred *vfs_export_lookup(struct mount *, struct sockaddr *);
-
-/*
- * Network address lookup element
- */
-struct netcred {
- struct radix_node netc_rnodes[2];
- uint64_t netc_exflags;
- struct ucred *netc_anon;
- int netc_numsecflavors;
- int netc_secflavors[MAXSECFLAVORS];
-};
-
-/*
- * Network export information
- */
-struct netexport {
- struct netcred ne_defexported; /* Default export */
- struct radix_node_head *ne4;
- struct radix_node_head *ne6;
-};
/*
* Build hash lists of net addresses and hang them off the mount point.
@@ -347,7 +329,7 @@
}
vfs_free_addrlist(nep);
mp->mnt_export = NULL;
- free(nep, M_MOUNT);
+ vfs_netexport_free(nep);
nep = NULL;
MNT_ILOCK(mp);
cr = mp->mnt_exjail;
@@ -376,16 +358,14 @@
} else
MNT_IUNLOCK(mp);
if (nep == NULL) {
- nep = malloc(sizeof(struct netexport), M_MOUNT,
- M_WAITOK | M_ZERO);
- mp->mnt_export = nep;
+ nep = mp->mnt_export = vfs_netexport_alloc();
new_nep = true;
}
if (argp->ex_flags & MNT_EXPUBLIC) {
if ((error = vfs_setpublicfs(mp, nep, argp)) != 0) {
if (new_nep) {
mp->mnt_export = NULL;
- free(nep, M_MOUNT);
+ vfs_netexport_free(nep);
}
goto out;
}
@@ -405,7 +385,7 @@
if ((error = vfs_hang_addrlist(mp, nep, argp))) {
if (new_nep) {
mp->mnt_export = NULL;
- free(nep, M_MOUNT);
+ vfs_netexport_free(nep);
}
goto out;
}
@@ -504,7 +484,7 @@
mp->mnt_flag &= ~(MNT_EXPORTED | MNT_DEFEXPORTED);
MNT_IUNLOCK(mp);
vfs_free_addrlist(mp->mnt_export);
- free(mp->mnt_export, M_MOUNT);
+ vfs_netexport_free(mp->mnt_export);
mp->mnt_export = NULL;
} else
MNT_IUNLOCK(mp);
@@ -695,3 +675,24 @@
lockmgr(&mp->mnt_explock, LK_RELEASE, NULL);
return (0);
}
+
+static struct netexport *
+vfs_netexport_alloc(void)
+{
+ struct netexport *nep;
+
+ nep = malloc(sizeof(struct netexport), M_MOUNT, M_WAITOK | M_ZERO);
+ refcount_init(&nep->ne_ref, 1);
+ mtx_init(&nep->ne_mtx, "mntexplock", NULL, MTX_DEF);
+ return (nep);
+}
+
+void
+vfs_netexport_free(struct netexport *nep)
+{
+
+ if (!refcount_release(&nep->ne_ref))
+ return;
+ mtx_destroy(&nep->ne_mtx);
+ free(nep, M_MOUNT);
+}
diff --git a/sys/kern/vfs_mount.c.precreate b/sys/kern/vfs_mount.c
--- a/sys/kern/vfs_mount.c.precreate
+++ b/sys/kern/vfs_mount.c
@@ -765,7 +765,7 @@
}
if (mp->mnt_export != NULL) {
vfs_free_addrlist(mp->mnt_export);
- free(mp->mnt_export, M_MOUNT);
+ vfs_netexport_free(mp->mnt_export);
}
vfsconf_lock();
mp->mnt_vfc->vfc_refcount--;
diff --git a/sys/sys/mount.h.precreate b/sys/sys/mount.h
--- a/sys/sys/mount.h.precreate
+++ b/sys/sys/mount.h
@@ -1039,6 +1039,7 @@
int vfs_export /* process mount export info */
(struct mount *, struct export_args *, bool);
void vfs_free_addrlist(struct netexport *);
+void vfs_netexport_free(struct netexport *);
void vfs_allocate_syncvnode(struct mount *);
void vfs_deallocate_syncvnode(struct mount *);
int vfs_donmount(struct thread *td, uint64_t fsflags,
diff --git a/sys/sys/netexport.h.precreate b/sys/sys/netexport.h
--- a/sys/sys/netexport.h.precreate
+++ b/sys/sys/netexport.h
@@ -0,0 +1,81 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _SYS_NETEXPORT_H_
+#define _SYS_NETEXPORT_H_
+
+#ifdef _KERNEL
+/*
+ * Network address lookup element
+ */
+struct netcred {
+ struct radix_node netc_rnodes[2];
+ uint64_t netc_exflags;
+ struct ucred *netc_anon;
+ int netc_numsecflavors;
+ int netc_secflavors[MAXSECFLAVORS];
+};
+
+/*
+ * Network export information
+ * ne_pnfsnumfile - Protected by the ne_mtx mutex.
+ * ne_pnfsnextfile - Protected by the vnode lock for the numfiles directory.
+ * ne_pnfsnumcnt - Handled as an atomic.
+ * (Although this value doesn't need to be exact, so using
+ * an atomic is not really necessary.)
+ */
+struct netexport {
+ struct netcred ne_defexported; /* Default export */
+ struct radix_node_head *ne4;
+ struct radix_node_head *ne6;
+ struct mtx ne_mtx; /* For ne_pnfsnumfile. */
+ struct vnode *ne_pnfsnumfile;
+ uint64_t ne_pnfsnextfile;
+ u_int ne_ref; /* Refcount for structure */
+ u_int ne_pnfsnumcnt; /* For stats, not protected. */
+};
+
+#define MNTEXP_LOCK(n) mtx_lock(&(n)->ne_mtx)
+#define MNTEXP_UNLOCK(n) mtx_unlock(&(n)->ne_mtx)
+#define MNTEXP_MTX(n) (&(n)->ne_mtx)
+
+#define PNFSD_START ((struct vnode *)-1)
+#define PNFSD_STOP ((struct vnode *)-2)
+#define PNFSD_STOPPED ((struct vnode *)-3)
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_NETEXPORT_H_ */

File Metadata

Mime Type
text/plain
Expires
Sun, Jun 14, 9:02 PM (3 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33959771
Default Alt Text
D57553.diff (6 KB)

Event Timeline