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

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/nfs/nfs_cmd.c
          +++ new/usr/src/uts/common/fs/nfs/nfs_cmd.c
↓ open down ↓ 10 lines elided ↑ open up ↑
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
       21 +
  21   22  /*
  22   23   * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23   24   * Use is subject to license terms.
  24   25   */
  25   26  
       27 +/*
       28 + * Copyright 2018 Nexenta Systems, Inc.
       29 + */
       30 +
  26   31  #include <sys/param.h>
  27   32  #include <sys/types.h>
  28   33  #include <sys/pathname.h>
  29   34  #include <sys/errno.h>
  30   35  #include <sys/cmn_err.h>
  31   36  #include <sys/debug.h>
  32   37  #include <sys/systm.h>
  33   38  #include <sys/unistd.h>
  34   39  #include <sys/door.h>
  35   40  #include <sys/socket.h>
↓ open down ↓ 2 lines elided ↑ open up ↑
  38   43  #include <sys/kmem.h>
  39   44  #include <sys/sunddi.h>
  40   45  
  41   46  #define NFSCMD_DR_TRYCNT        8
  42   47  
  43   48  #ifdef nextdp
  44   49  #undef nextdp
  45   50  #endif
  46   51  #define nextdp(dp)      ((struct dirent64 *)((char *)(dp) + (dp)->d_reclen))
  47   52  
  48      -kmutex_t        nfscmd_lock;
  49      -door_handle_t   nfscmd_dh;
       53 +typedef struct nfscmd_globals {
       54 +        kmutex_t        nfscmd_lock;
       55 +        door_handle_t   nfscmd_dh;
       56 +} nfscmd_globals_t;
  50   57  
       58 +static zone_key_t nfscmd_zone_key;
       59 +
  51   60  static struct charset_cache *nfscmd_charmap(exportinfo_t *exi,
  52   61      struct sockaddr *sp);
       62 +static void *nfscmd_zone_init(zoneid_t);
       63 +static void nfscmd_zone_fini(zoneid_t, void *);
  53   64  
  54      -
  55   65  void
  56   66  nfscmd_args(uint_t did)
  57   67  {
  58      -        mutex_enter(&nfscmd_lock);
  59      -        if (nfscmd_dh)
  60      -                door_ki_rele(nfscmd_dh);
  61      -        nfscmd_dh = door_ki_lookup(did);
  62      -        mutex_exit(&nfscmd_lock);
       68 +        nfscmd_globals_t *ncg = zone_getspecific(nfscmd_zone_key, curzone);
       69 +
       70 +        mutex_enter(&ncg->nfscmd_lock);
       71 +        if (ncg->nfscmd_dh != NULL)
       72 +                door_ki_rele(ncg->nfscmd_dh);
       73 +        ncg->nfscmd_dh = door_ki_lookup(did);
       74 +        mutex_exit(&ncg->nfscmd_lock);
  63   75  }
  64   76  
  65   77  void
  66   78  nfscmd_init(void)
  67   79  {
  68      -        mutex_init(&nfscmd_lock, NULL, MUTEX_DEFAULT, NULL);
       80 +        zone_key_create(&nfscmd_zone_key, nfscmd_zone_init,
       81 +            NULL, nfscmd_zone_fini);
  69   82  }
  70   83  
  71   84  void
  72   85  nfscmd_fini(void)
  73   86  {
       87 +        (void) zone_key_delete(nfscmd_zone_key);
  74   88  }
  75   89  
       90 +/*ARGSUSED*/
       91 +static void *
       92 +nfscmd_zone_init(zoneid_t zoneid)
       93 +{
       94 +        nfscmd_globals_t *ncg;
       95 +
       96 +        ncg = kmem_zalloc(sizeof (*ncg), KM_SLEEP);
       97 +        mutex_init(&ncg->nfscmd_lock, NULL, MUTEX_DEFAULT, NULL);
       98 +
       99 +        return (ncg);
      100 +}
      101 +
      102 +/*ARGSUSED*/
      103 +static void
      104 +nfscmd_zone_fini(zoneid_t zoneid, void *data)
      105 +{
      106 +        nfscmd_globals_t *ncg = data;
      107 +
      108 +        mutex_destroy(&ncg->nfscmd_lock);
      109 +        if (ncg->nfscmd_dh)
      110 +                door_ki_rele(ncg->nfscmd_dh);
      111 +        kmem_free(ncg, sizeof (*ncg));
      112 +}
      113 +
  76  114  /*
  77  115   * nfscmd_send(arg, result)
  78  116   *
  79  117   * Send a command to the daemon listening on the door. The result is
  80  118   * returned in the result pointer if the function return value is
  81  119   * NFSCMD_ERR_SUCCESS. Otherwise it is the error value.
  82  120   */
  83  121  int
  84  122  nfscmd_send(nfscmd_arg_t *arg, nfscmd_res_t *res)
  85  123  {
  86  124          door_handle_t   dh;
  87  125          door_arg_t      da;
  88  126          door_info_t     di;
  89  127          int             ntries = 0;
  90  128          int             last = 0;
      129 +        nfscmd_globals_t *ncg = zone_getspecific(nfscmd_zone_key, curzone);
  91  130  
  92  131  retry:
  93      -        mutex_enter(&nfscmd_lock);
  94      -        dh = nfscmd_dh;
      132 +        mutex_enter(&ncg->nfscmd_lock);
      133 +        dh = ncg->nfscmd_dh;
  95  134          if (dh != NULL)
  96  135                  door_ki_hold(dh);
  97      -        mutex_exit(&nfscmd_lock);
      136 +        mutex_exit(&ncg->nfscmd_lock);
  98  137  
  99  138          if (dh == NULL) {
 100  139                  /*
 101  140                   * The rendezvous point has not been established yet !
 102  141                   * This could mean that either mountd(1m) has not yet
 103  142                   * been started or that _this_ routine nuked the door
 104  143                   * handle after receiving an EINTR for a REVOKED door.
 105  144                   *
 106  145                   * Returning NFSAUTH_DROP will cause the NFS client
 107  146                   * to retransmit the request, so let's try to be more
↓ open down ↓ 26 lines elided ↑ open up ↑
 134  173          case EINTR:
 135  174                  if (!door_ki_info(dh, &di)) {
 136  175                          if (di.di_attributes & DOOR_REVOKED) {
 137  176                                  /*
 138  177                                   * The server barfed and revoked
 139  178                                   * the (existing) door on us; we
 140  179                                   * want to wait to give smf(5) a
 141  180                                   * chance to restart mountd(1m)
 142  181                                   * and establish a new door handle.
 143  182                                   */
 144      -                                mutex_enter(&nfscmd_lock);
 145      -                                if (dh == nfscmd_dh)
 146      -                                        nfscmd_dh = NULL;
 147      -                                mutex_exit(&nfscmd_lock);
      183 +                                mutex_enter(&ncg->nfscmd_lock);
      184 +                                if (dh == ncg->nfscmd_dh)
      185 +                                        ncg->nfscmd_dh = NULL;
      186 +                                mutex_exit(&ncg->nfscmd_lock);
 148  187                                  door_ki_rele(dh);
 149  188                                  delay(hz);
 150  189                                  goto retry;
 151  190                          }
 152  191                          /*
 153  192                           * If the door was _not_ revoked on us,
 154  193                           * then more than likely we took an INTR,
 155  194                           * so we need to fail the operation.
 156  195                           */
 157  196                          door_ki_rele(dh);
↓ open down ↓ 377 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX