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 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _NFS_LM_H 27 #define _NFS_LM_H 28 29 /* 30 * Interface definitions for the NFSv2/v3 lock manager. 31 */ 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 #include <sys/cred.h> 38 #include <sys/fcntl.h> 39 #include <sys/types.h> 40 #include <sys/vnode.h> 41 #include <rpc/rpc.h> 42 #include <nfs/export.h> 43 44 #ifdef _KERNEL 45 46 /* 47 * Common interfaces. 48 */ 49 50 /* 51 * The numeric sysid is used to identify a host and transport. 52 * 53 * The local locking code uses (pid, sysid) to uniquely identify a process. 54 * This means that the client-side code must doctor up the sysid before 55 * registering a lock, so that the local locking code doesn't confuse a 56 * remote process with a local process just because they have the same pid. 57 * We currently do this by ORing LM_SYSID_CLIENT into the sysid before 58 * registering a lock. 59 * 60 * If you change LM_SYSID and LM_SYSID_MAX, be sure to pick values so that 61 * LM_SYSID_MAX > LM_SYSID using signed arithmetic, and don't use zero. 62 * You may also need a different way to tag lock manager locks that are 63 * registered locally. 64 */ 65 #define LM_SYSID ((sysid_t)0x0001) 66 #define LM_SYSID_MAX ((sysid_t)0x3FFF) 67 #define LM_SYSID_CLIENT ((sysid_t)0x4000) 68 #define LM_NOSYSID ((sysid_t)-1) 69 70 /* 71 * Struct used to represent a host. 72 */ 73 struct lm_sysid; 74 75 /* 76 * Given a knetconfig and network address, returns a reference to the 77 * associated lm_sysid. The 3rd argument is the hostname to assign to the 78 * lm_sysid. The 4th argument is an output parameter. It is set non-zero 79 * if the returned lm_sysid has a different protocol 80 * (knetconfig::knc_proto) than what was requested. 81 */ 82 extern struct lm_sysid *lm_get_sysid(struct knetconfig *, struct netbuf *, 83 char *, bool_t *); 84 extern void lm_rel_sysid(struct lm_sysid *); 85 86 /* 87 * Return the integer sysid for the given lm_sysid. 88 */ 89 extern sysid_t lm_sysidt(struct lm_sysid *); 90 91 extern void lm_free_config(struct knetconfig *); 92 93 extern void lm_cprsuspend(void); 94 extern void lm_cprresume(void); 95 96 /* 97 * Client-side interfaces. 98 */ 99 100 extern int lm_frlock(struct vnode *vp, int cmd, 101 struct flock64 *flk, int flag, 102 u_offset_t offset, struct cred *cr, 103 netobj *fh, struct flk_callback *); 104 extern int lm_has_sleep(const struct vnode *); 105 extern void lm_register_lock_locally(vnode_t *, 106 struct lm_sysid *, struct flock64 *, int, 107 u_offset_t); 108 extern int lm_safelock(vnode_t *, const struct flock64 *, 109 cred_t *); 110 extern int lm_safemap(const vnode_t *); 111 extern int lm_shrlock(struct vnode *vp, int cmd, 112 struct shrlock *shr, int flag, netobj *fh); 113 extern int lm4_frlock(struct vnode *vp, int cmd, 114 struct flock64 *flk, int flag, 115 u_offset_t offset, struct cred *cr, 116 netobj *fh, struct flk_callback *); 117 extern int lm4_shrlock(struct vnode *vp, int cmd, 118 struct shrlock *shr, int flag, netobj *fh); 119 120 /* 121 * Server-side interfaces. 122 */ 123 124 extern void lm_unexport(struct exportinfo *); 125 126 /* 127 * Clustering: functions to encode the nlmid of the node where this NLM 128 * server is running in the l_sysid of the flock struct or the s_sysid 129 * field of the shrlock struct (respectively). 130 */ 131 extern void lm_set_nlmid_flk(int *); 132 extern void lm_set_nlmid_shr(int32_t *); 133 /* Hook for deleting all mandatory NFSv4 file locks held by a remote client */ 134 extern void (*lm_remove_file_locks)(int); 135 136 /* 137 * The following global variable is the node id of the node where this 138 * NLM server is running. 139 */ 140 extern int lm_global_nlmid; 141 142 /* 143 * End of clustering hooks. 144 */ 145 146 /* 147 * Return non-zero if the given local vnode is in use. 148 */ 149 extern int lm_vp_active(const struct vnode *); 150 151 extern sysid_t lm_alloc_sysidt(void); 152 extern void lm_free_sysidt(sysid_t); 153 154 #else /* _KERNEL */ 155 156 #ifdef __STDC__ 157 extern int lm_shutdown(void); 158 #else 159 extern int lm_shutdown(); 160 #endif /* __STDC__ */ 161 162 #endif /* _KERNEL */ 163 164 #ifdef __cplusplus 165 } 166 #endif 167 168 #endif /* _NFS_LM_H */ 169