Print this page
195 Need replacement for nfs/lockd+klm


  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 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  28 /*      All Rights Reserved */
  29 




  30 #include <sys/flock_impl.h>
  31 #include <sys/vfs.h>
  32 #include <sys/t_lock.h>           /* for <sys/callb.h> */
  33 #include <sys/callb.h>
  34 #include <sys/clconf.h>
  35 #include <sys/cladm.h>
  36 #include <sys/nbmlock.h>
  37 #include <sys/cred.h>
  38 #include <sys/policy.h>
  39 
  40 /*
  41  * The following four variables are for statistics purposes and they are
  42  * not protected by locks. They may not be accurate but will at least be
  43  * close to the actual value.
  44  */
  45 
  46 int     flk_lock_allocs;
  47 int     flk_lock_frees;
  48 int     edge_allocs;
  49 int     edge_frees;


2262 
2263         SET_LOCK_TO_FIRST_ACTIVE_VP(gp, lock, vp);
2264 
2265         if (lock) {
2266                 while (lock->l_vnode == vp) {
2267                         if (IS_REMOTE(lock)) {
2268                                 result = 1;
2269                                 goto done;
2270                         }
2271                         lock = lock->l_next;
2272                 }
2273         }
2274 
2275         SET_LOCK_TO_FIRST_SLEEP_VP(gp, lock, vp);
2276 
2277         if (lock) {
2278                 while (lock->l_vnode == vp) {
2279                         if (IS_REMOTE(lock)) {
2280                                 result = 1;
2281                                 goto done;



















































2282                         }
2283                         lock = lock->l_next;
2284                 }
2285         }
2286 
2287 done:
2288         mutex_exit(&gp->gp_mutex);
2289         return (result);
2290 }
2291 
2292 /*
2293  * Determine if there are any locks owned by the given sysid.
2294  * Returns zero if not, non-zero if there are.  Note that this return code
2295  * could be derived from flk_get_{sleeping,active}_locks, but this routine
2296  * avoids all the memory allocations of those routines.
2297  *
2298  * This routine has the same synchronization issues as
2299  * flk_has_remote_locks.
2300  */
2301 




  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 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  28 /*      All Rights Reserved */
  29 
  30 /*
  31  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  32  */
  33 
  34 #include <sys/flock_impl.h>
  35 #include <sys/vfs.h>
  36 #include <sys/t_lock.h>           /* for <sys/callb.h> */
  37 #include <sys/callb.h>
  38 #include <sys/clconf.h>
  39 #include <sys/cladm.h>
  40 #include <sys/nbmlock.h>
  41 #include <sys/cred.h>
  42 #include <sys/policy.h>
  43 
  44 /*
  45  * The following four variables are for statistics purposes and they are
  46  * not protected by locks. They may not be accurate but will at least be
  47  * close to the actual value.
  48  */
  49 
  50 int     flk_lock_allocs;
  51 int     flk_lock_frees;
  52 int     edge_allocs;
  53 int     edge_frees;


2266 
2267         SET_LOCK_TO_FIRST_ACTIVE_VP(gp, lock, vp);
2268 
2269         if (lock) {
2270                 while (lock->l_vnode == vp) {
2271                         if (IS_REMOTE(lock)) {
2272                                 result = 1;
2273                                 goto done;
2274                         }
2275                         lock = lock->l_next;
2276                 }
2277         }
2278 
2279         SET_LOCK_TO_FIRST_SLEEP_VP(gp, lock, vp);
2280 
2281         if (lock) {
2282                 while (lock->l_vnode == vp) {
2283                         if (IS_REMOTE(lock)) {
2284                                 result = 1;
2285                                 goto done;
2286                         }
2287                         lock = lock->l_next;
2288                 }
2289         }
2290 
2291 done:
2292         mutex_exit(&gp->gp_mutex);
2293         return (result);
2294 }
2295 
2296 /*
2297  * Determine whether there are any locks for the given vnode with a remote
2298  * sysid matching given sysid.
2299  * Used by the new (open source) NFS Lock Manager (NLM)
2300  */
2301 int
2302 flk_has_remote_locks_for_sysid(vnode_t *vp, int sysid)
2303 {
2304         lock_descriptor_t *lock;
2305         int result = 0;
2306         graph_t *gp;
2307 
2308         if (sysid == 0)
2309                 return (0);
2310 
2311         gp = flk_get_lock_graph(vp, FLK_USE_GRAPH);
2312         if (gp == NULL) {
2313                 return (0);
2314         }
2315 
2316         mutex_enter(&gp->gp_mutex);
2317 
2318         SET_LOCK_TO_FIRST_ACTIVE_VP(gp, lock, vp);
2319 
2320         if (lock) {
2321                 while (lock->l_vnode == vp) {
2322                         if (lock->l_flock.l_sysid == sysid) {
2323                                 result = 1;
2324                                 goto done;
2325                         }
2326                         lock = lock->l_next;
2327                 }
2328         }
2329 
2330         SET_LOCK_TO_FIRST_SLEEP_VP(gp, lock, vp);
2331 
2332         if (lock) {
2333                 while (lock->l_vnode == vp) {
2334                         if (lock->l_flock.l_sysid == sysid) {
2335                                 result = 1;
2336                                 goto done;
2337                         }
2338                         lock = lock->l_next;
2339                 }
2340         }
2341 
2342 done:
2343         mutex_exit(&gp->gp_mutex);
2344         return (result);
2345 }
2346 
2347 /*
2348  * Determine if there are any locks owned by the given sysid.
2349  * Returns zero if not, non-zero if there are.  Note that this return code
2350  * could be derived from flk_get_{sleeping,active}_locks, but this routine
2351  * avoids all the memory allocations of those routines.
2352  *
2353  * This routine has the same synchronization issues as
2354  * flk_has_remote_locks.
2355  */
2356