git: 57ff348804f9 - main - svc_rpcsec_gss.c: Separate out the non-vnet initialization

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Wed, 01 Mar 2023 23:30:31 UTC
The branch main has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=57ff348804f98d956f2e203b665de5a8989dbf8c

commit 57ff348804f98d956f2e203b665de5a8989dbf8c
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2023-03-01 23:29:25 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2023-03-01 23:29:25 +0000

    svc_rpcsec_gss.c: Separate out the non-vnet initialization
    
    Without this patch, a single initialization function was
    used to initialize both the vnet'd and non-vnet'd data.
    This patch separates out the non-vnet'd initializations
    into a separate function invoked by SYSINIT().
    This avoids use of IS_DEFAULT_VNET() in the initialization
    functions and also configures the non-vnet'd initialization
    function to be called first, although ordering is not
    currently needed.
    
    Reviewed by:    glebius
    MFC after:      3 months
    Differential Revision:  https://reviews.freebsd.org/D38749
---
 sys/rpc/rpcsec_gss/svc_rpcsec_gss.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c b/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
index 03e185bd912b..132d7fb8c0f4 100644
--- a/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
+++ b/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
@@ -205,6 +205,25 @@ KGSS_VNET_DEFINE_STATIC(uint32_t, svc_rpc_gss_next_clientid) = 1;
 
 static void
 svc_rpc_gss_init(void *unused __unused)
+{
+
+	svc_auth_reg(RPCSEC_GSS, svc_rpc_gss, rpc_gss_svc_getcred);
+	sx_init(&svc_rpc_gss_lock, "gsslock");
+}
+SYSINIT(svc_rpc_gss_init, SI_SUB_VFS, SI_ORDER_ANY,
+    svc_rpc_gss_init, NULL);
+
+static void
+svc_rpc_gss_cleanup(void *unused __unused)
+{
+
+	sx_destroy(&svc_rpc_gss_lock);
+}
+SYSUNINIT(svc_rpc_gss_cleanup, SI_SUB_VFS, SI_ORDER_ANY,
+    svc_rpc_gss_cleanup, NULL);
+
+static void
+svc_rpc_gss_vnetinit(void *unused __unused)
 {
 	int i;
 
@@ -214,26 +233,20 @@ svc_rpc_gss_init(void *unused __unused)
 	for (i = 0; i < svc_rpc_gss_client_hash_size; i++)
 		TAILQ_INIT(&KGSS_VNET(svc_rpc_gss_client_hash)[i]);
 	TAILQ_INIT(&KGSS_VNET(svc_rpc_gss_clients));
-	if (IS_DEFAULT_VNET(curvnet)) {
-		svc_auth_reg(RPCSEC_GSS, svc_rpc_gss, rpc_gss_svc_getcred);
-		sx_init(&svc_rpc_gss_lock, "gsslock");
-	}
 }
-VNET_SYSINIT(svc_rpc_gss_init, SI_SUB_VNET_DONE, SI_ORDER_ANY,
-    svc_rpc_gss_init, NULL);
+VNET_SYSINIT(svc_rpc_gss_vnetinit, SI_SUB_VNET_DONE, SI_ORDER_ANY,
+    svc_rpc_gss_vnetinit, NULL);
 
 static void
-svc_rpc_gss_cleanup(void *unused __unused)
+svc_rpc_gss_vnet_cleanup(void *unused __unused)
 {
 
 	mem_free(KGSS_VNET(svc_rpc_gss_client_hash),
 	    sizeof(struct svc_rpc_gss_client_list) *
 	    svc_rpc_gss_client_hash_size);
-	if (IS_DEFAULT_VNET(curvnet))
-		sx_destroy(&svc_rpc_gss_lock);
 }
-VNET_SYSUNINIT(svc_rpc_gss_cleanup, SI_SUB_VNET_DONE, SI_ORDER_ANY,
-    svc_rpc_gss_cleanup, NULL);
+VNET_SYSUNINIT(svc_rpc_gss_vnet_cleanup, SI_SUB_VNET_DONE, SI_ORDER_ANY,
+    svc_rpc_gss_vnet_cleanup, NULL);
 
 bool_t
 rpc_gss_set_callback(rpc_gss_callback_t *cb)