1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1986, 2010, Oracle and/or its affiliates. All rights reserved.
  23  *
  24  *      Copyright (c) 1983,1984,1985,1986,1987,1988,1989  AT&T.
  25  *      All rights reserved.
  26  */
  27 
  28 #include <sys/param.h>
  29 #include <sys/types.h>
  30 #include <sys/systm.h>
  31 #include <sys/thread.h>
  32 #include <sys/t_lock.h>
  33 #include <sys/time.h>
  34 #include <sys/vnode.h>
  35 #include <sys/vfs.h>
  36 #include <sys/errno.h>
  37 #include <sys/buf.h>
  38 #include <sys/stat.h>
  39 #include <sys/cred.h>
  40 #include <sys/kmem.h>
  41 #include <sys/debug.h>
  42 #include <sys/dnlc.h>
  43 #include <sys/vmsystm.h>
  44 #include <sys/flock.h>
  45 #include <sys/share.h>
  46 #include <sys/cmn_err.h>
  47 #include <sys/tiuser.h>
  48 #include <sys/sysmacros.h>
  49 #include <sys/callb.h>
  50 #include <sys/acl.h>
  51 #include <sys/kstat.h>
  52 #include <sys/signal.h>
  53 #include <sys/list.h>
  54 #include <sys/zone.h>
  55 
  56 #include <rpc/types.h>
  57 #include <rpc/xdr.h>
  58 #include <rpc/auth.h>
  59 #include <rpc/clnt.h>
  60 
  61 #include <nfs/nfs.h>
  62 #include <nfs/nfs_clnt.h>
  63 
  64 #include <nfs/rnode.h>
  65 #include <nfs/nfs_acl.h>
  66 #include <nfs/lm.h>
  67 
  68 #include <vm/hat.h>
  69 #include <vm/as.h>
  70 #include <vm/page.h>
  71 #include <vm/pvn.h>
  72 #include <vm/seg.h>
  73 #include <vm/seg_map.h>
  74 #include <vm/seg_vn.h>
  75 
  76 static void     nfs3_attr_cache(vnode_t *, vattr_t *, vattr_t *, hrtime_t,
  77                         cred_t *);
  78 static int      nfs_getattr_cache(vnode_t *, struct vattr *);
  79 static int      nfs_remove_locking_id(vnode_t *, int, char *, char *, int *);
  80 
  81 struct mi_globals {
  82         kmutex_t        mig_lock;  /* lock protecting mig_list */
 
2810         ASSERT(nfs_clntup == B_FALSE);
2811 #endif
2812 
2813         error = nfs_subrinit();
2814         if (error)
2815                 return (error);
2816 
2817         error = nfs_vfsinit();
2818         if (error) {
2819                 /*
2820                  * Cleanup nfs_subrinit() work
2821                  */
2822                 nfs_subrfini();
2823                 return (error);
2824         }
2825         zone_key_create(&mi_list_key, nfs_mi_init, nfs_mi_shutdown,
2826             nfs_mi_destroy);
2827 
2828         nfs4_clnt_init();
2829 
2830 #ifdef DEBUG
2831         nfs_clntup = B_TRUE;
2832 #endif
2833 
2834         return (0);
2835 }
2836 
2837 /*
2838  * This routine is only called if the NFS Client has been initialized but
2839  * the module failed to be installed. This routine will cleanup the previously
2840  * allocated/initialized work.
2841  */
2842 void
2843 nfs_clntfini(void)
2844 {
2845         (void) zone_key_delete(mi_list_key);
2846         nfs_subrfini();
2847         nfs_vfsfini();
2848         nfs4_clnt_fini();
2849 }
2850 
2851 /*
2852  * nfs_lockrelease:
2853  *
2854  * Release any locks on the given vnode that are held by the current
2855  * process.
2856  */
2857 void
2858 nfs_lockrelease(vnode_t *vp, int flag, offset_t offset, cred_t *cr)
2859 {
2860         flock64_t ld;
2861         struct shrlock shr;
2862         char *buf;
2863         int remote_lock_possible;
2864         int ret;
2865 
2866         ASSERT((uintptr_t)vp > KERNELBASE);
2867 
2868         /*
 
 | 
   1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 1986, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  *      Copyright (c) 1983,1984,1985,1986,1987,1988,1989  AT&T.
  28  *      All rights reserved.
  29  */
  30 
  31 /*
  32  * Copyright 2018 Nexenta Systems, Inc.
  33  */
  34 
  35 #include <sys/param.h>
  36 #include <sys/types.h>
  37 #include <sys/systm.h>
  38 #include <sys/thread.h>
  39 #include <sys/t_lock.h>
  40 #include <sys/time.h>
  41 #include <sys/vnode.h>
  42 #include <sys/vfs.h>
  43 #include <sys/errno.h>
  44 #include <sys/buf.h>
  45 #include <sys/stat.h>
  46 #include <sys/cred.h>
  47 #include <sys/kmem.h>
  48 #include <sys/debug.h>
  49 #include <sys/dnlc.h>
  50 #include <sys/vmsystm.h>
  51 #include <sys/flock.h>
  52 #include <sys/share.h>
  53 #include <sys/cmn_err.h>
  54 #include <sys/tiuser.h>
  55 #include <sys/sysmacros.h>
  56 #include <sys/callb.h>
  57 #include <sys/acl.h>
  58 #include <sys/kstat.h>
  59 #include <sys/signal.h>
  60 #include <sys/list.h>
  61 #include <sys/zone.h>
  62 
  63 #include <rpc/types.h>
  64 #include <rpc/xdr.h>
  65 #include <rpc/auth.h>
  66 #include <rpc/clnt.h>
  67 
  68 #include <nfs/nfs.h>
  69 #include <nfs/nfs_clnt.h>
  70 #include <nfs/nfs_cmd.h>
  71 
  72 #include <nfs/rnode.h>
  73 #include <nfs/nfs_acl.h>
  74 #include <nfs/lm.h>
  75 
  76 #include <vm/hat.h>
  77 #include <vm/as.h>
  78 #include <vm/page.h>
  79 #include <vm/pvn.h>
  80 #include <vm/seg.h>
  81 #include <vm/seg_map.h>
  82 #include <vm/seg_vn.h>
  83 
  84 static void     nfs3_attr_cache(vnode_t *, vattr_t *, vattr_t *, hrtime_t,
  85                         cred_t *);
  86 static int      nfs_getattr_cache(vnode_t *, struct vattr *);
  87 static int      nfs_remove_locking_id(vnode_t *, int, char *, char *, int *);
  88 
  89 struct mi_globals {
  90         kmutex_t        mig_lock;  /* lock protecting mig_list */
 
2818         ASSERT(nfs_clntup == B_FALSE);
2819 #endif
2820 
2821         error = nfs_subrinit();
2822         if (error)
2823                 return (error);
2824 
2825         error = nfs_vfsinit();
2826         if (error) {
2827                 /*
2828                  * Cleanup nfs_subrinit() work
2829                  */
2830                 nfs_subrfini();
2831                 return (error);
2832         }
2833         zone_key_create(&mi_list_key, nfs_mi_init, nfs_mi_shutdown,
2834             nfs_mi_destroy);
2835 
2836         nfs4_clnt_init();
2837 
2838         nfscmd_init();
2839 
2840 #ifdef DEBUG
2841         nfs_clntup = B_TRUE;
2842 #endif
2843 
2844         return (0);
2845 }
2846 
2847 /*
2848  * This routine is only called if the NFS Client has been initialized but
2849  * the module failed to be installed. This routine will cleanup the previously
2850  * allocated/initialized work.
2851  */
2852 void
2853 nfs_clntfini(void)
2854 {
2855         (void) zone_key_delete(mi_list_key);
2856         nfs_subrfini();
2857         nfs_vfsfini();
2858         nfs4_clnt_fini();
2859         nfscmd_fini();
2860 }
2861 
2862 /*
2863  * nfs_lockrelease:
2864  *
2865  * Release any locks on the given vnode that are held by the current
2866  * process.
2867  */
2868 void
2869 nfs_lockrelease(vnode_t *vp, int flag, offset_t offset, cred_t *cr)
2870 {
2871         flock64_t ld;
2872         struct shrlock shr;
2873         char *buf;
2874         int remote_lock_possible;
2875         int ret;
2876 
2877         ASSERT((uintptr_t)vp > KERNELBASE);
2878 
2879         /*
 
 |