Print this page
11083 support NFS server in zone
Portions contributed by: Dan Kruchinin <dan.kruchinin@nexenta.com>
Portions contributed by: Stepan Zastupov <stepan.zastupov@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Portions contributed by: Mike Zeller <mike@mikezeller.net>
Portions contributed by: Dan McDonald <danmcd@joyent.com>
Portions contributed by: Gordon Ross <gordon.w.ross@gmail.com>
Portions contributed by: Vitaliy Gusev <gusev.vitaliy@gmail.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Jason King <jbk@joyent.com>
Reviewed by: C Fraire <cfraire@me.com>
Change-Id: I22f289d357503f9b48a0bc2482cc4328a6d43d16
        
@@ -16,15 +16,20 @@
  * fields enclosed by brackets "[]" replaced with your own identifying
  * information: Portions Copyright [yyyy] [name of copyright owner]
  *
  * CDDL HEADER END
  */
+
 /*
  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
+/*
+ * Copyright 2018 Nexenta Systems, Inc.
+ */
+
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/pathname.h>
 #include <sys/errno.h>
 #include <sys/cmn_err.h>
@@ -43,38 +48,71 @@
 #ifdef nextdp
 #undef nextdp
 #endif
 #define nextdp(dp)      ((struct dirent64 *)((char *)(dp) + (dp)->d_reclen))
 
-kmutex_t        nfscmd_lock;
-door_handle_t   nfscmd_dh;
+typedef struct nfscmd_globals {
+        kmutex_t        nfscmd_lock;
+        door_handle_t   nfscmd_dh;
+} nfscmd_globals_t;
 
+static zone_key_t nfscmd_zone_key;
+
 static struct charset_cache *nfscmd_charmap(exportinfo_t *exi,
     struct sockaddr *sp);
+static void *nfscmd_zone_init(zoneid_t);
+static void nfscmd_zone_fini(zoneid_t, void *);
 
-
 void
 nfscmd_args(uint_t did)
 {
-        mutex_enter(&nfscmd_lock);
-        if (nfscmd_dh)
-                door_ki_rele(nfscmd_dh);
-        nfscmd_dh = door_ki_lookup(did);
-        mutex_exit(&nfscmd_lock);
+        nfscmd_globals_t *ncg = zone_getspecific(nfscmd_zone_key, curzone);
+
+        mutex_enter(&ncg->nfscmd_lock);
+        if (ncg->nfscmd_dh != NULL)
+                door_ki_rele(ncg->nfscmd_dh);
+        ncg->nfscmd_dh = door_ki_lookup(did);
+        mutex_exit(&ncg->nfscmd_lock);
 }
 
 void
 nfscmd_init(void)
 {
-        mutex_init(&nfscmd_lock, NULL, MUTEX_DEFAULT, NULL);
+        zone_key_create(&nfscmd_zone_key, nfscmd_zone_init,
+            NULL, nfscmd_zone_fini);
 }
 
 void
 nfscmd_fini(void)
 {
+        (void) zone_key_delete(nfscmd_zone_key);
 }
 
+/*ARGSUSED*/
+static void *
+nfscmd_zone_init(zoneid_t zoneid)
+{
+        nfscmd_globals_t *ncg;
+
+        ncg = kmem_zalloc(sizeof (*ncg), KM_SLEEP);
+        mutex_init(&ncg->nfscmd_lock, NULL, MUTEX_DEFAULT, NULL);
+
+        return (ncg);
+}
+
+/*ARGSUSED*/
+static void
+nfscmd_zone_fini(zoneid_t zoneid, void *data)
+{
+        nfscmd_globals_t *ncg = data;
+
+        mutex_destroy(&ncg->nfscmd_lock);
+        if (ncg->nfscmd_dh)
+                door_ki_rele(ncg->nfscmd_dh);
+        kmem_free(ncg, sizeof (*ncg));
+}
+
 /*
  * nfscmd_send(arg, result)
  *
  * Send a command to the daemon listening on the door. The result is
  * returned in the result pointer if the function return value is
@@ -86,17 +124,18 @@
         door_handle_t   dh;
         door_arg_t      da;
         door_info_t     di;
         int             ntries = 0;
         int             last = 0;
+        nfscmd_globals_t *ncg = zone_getspecific(nfscmd_zone_key, curzone);
 
 retry:
-        mutex_enter(&nfscmd_lock);
-        dh = nfscmd_dh;
+        mutex_enter(&ncg->nfscmd_lock);
+        dh = ncg->nfscmd_dh;
         if (dh != NULL)
                 door_ki_hold(dh);
-        mutex_exit(&nfscmd_lock);
+        mutex_exit(&ncg->nfscmd_lock);
 
         if (dh == NULL) {
                 /*
                  * The rendezvous point has not been established yet !
                  * This could mean that either mountd(1m) has not yet
@@ -139,14 +178,14 @@
                                  * the (existing) door on us; we
                                  * want to wait to give smf(5) a
                                  * chance to restart mountd(1m)
                                  * and establish a new door handle.
                                  */
-                                mutex_enter(&nfscmd_lock);
-                                if (dh == nfscmd_dh)
-                                        nfscmd_dh = NULL;
-                                mutex_exit(&nfscmd_lock);
+                                mutex_enter(&ncg->nfscmd_lock);
+                                if (dh == ncg->nfscmd_dh)
+                                        ncg->nfscmd_dh = NULL;
+                                mutex_exit(&ncg->nfscmd_lock);
                                 door_ki_rele(dh);
                                 delay(hz);
                                 goto retry;
                         }
                         /*