xref: /titanic_51/usr/src/uts/common/klm/klmops.c (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy is of the CDDL is also available via the Internet
9  * at http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
14  */
15 
16 /*
17  * NFS Lock Manager, client-side
18  * Note: depends on (links with) klmmod
19  *
20  * This file contains all the external entry points of klmops.
21  * Basically, this is the "glue" to the BSD nlm code.
22  */
23 
24 #include <sys/types.h>
25 #include <sys/errno.h>
26 #include <sys/modctl.h>
27 #include <sys/flock.h>
28 
29 #include <nfs/lm.h>
30 #include <rpcsvc/nlm_prot.h>
31 #include "nlm_impl.h"
32 
33 
34 static struct modlmisc modlmisc = {
35 	&mod_miscops, "lock mgr calls"
36 };
37 
38 static struct modlinkage modlinkage = {
39 	MODREV_1, &modlmisc, NULL
40 };
41 
42 
43 
44 /*
45  * ****************************************************************
46  * module init, fini, info
47  */
48 int
49 _init()
50 {
51 	return (mod_install(&modlinkage));
52 }
53 
54 int
55 _fini()
56 {
57 	/* Don't unload. */
58 	return (EBUSY);
59 }
60 
61 int
62 _info(struct modinfo *modinfop)
63 {
64 	return (mod_info(&modlinkage, modinfop));
65 }
66 
67 
68 
69 /*
70  * ****************************************************************
71  * Stubs listed in modstubs.s
72  * These are called from fs/nfs
73  */
74 
75 /*
76  * NFSv2 lock/unlock.  Called by nfs_frlock()
77  * Uses NLM version 1 (NLM_VERS)
78  */
79 int
80 lm_frlock(struct vnode *vp, int cmd, struct flock64 *flk, int flags,
81     u_offset_t off, struct cred *cr, struct netobj *fh,
82     struct flk_callback *flcb)
83 {
84 	return (nlm_frlock(vp, cmd, flk, flags, off,
85 	    cr, fh, flcb, NLM_VERS));
86 }
87 
88 /*
89  * NFSv3 lock/unlock.  Called by nfs3_frlock()
90  * Uses NLM version 4 (NLM4_VERS)
91  */
92 int
93 lm4_frlock(struct vnode *vp, int cmd, struct flock64 *flk, int flags,
94 	u_offset_t off, struct cred *cr, struct netobj *fh,
95 	struct flk_callback *flcb)
96 {
97 	int err;
98 	err = nlm_frlock(vp, cmd, flk, flags, off,
99 	    cr, fh, flcb, NLM4_VERS);
100 	return (err);
101 }
102 
103 /*
104  * NFSv2 shrlk/unshrlk.  See nfs_shrlock
105  * Uses NLM version 3 (NLM_VERSX)
106  */
107 int
108 lm_shrlock(struct vnode *vp, int cmd,
109     struct shrlock *shr, int flags, struct netobj *fh)
110 {
111 	return (nlm_shrlock(vp, cmd, shr, flags, fh, NLM_VERSX));
112 }
113 
114 /*
115  * NFSv3 shrlk/unshrlk.  See nfs3_shrlock
116  * Uses NLM version 4 (NLM4_VERS)
117  */
118 int
119 lm4_shrlock(struct vnode *vp, int cmd,
120     struct shrlock *shr, int flags, struct netobj *fh)
121 {
122 	return (nlm_shrlock(vp, cmd, shr, flags, fh, NLM4_VERS));
123 }
124 
125 /*
126  * Helper for lm_frlock, lm4_frlock, nfs_lockrelease
127  * After getting a lock from a remote lock manager,
128  * register the lock locally.
129  */
130 void
131 lm_register_lock_locally(struct vnode *vp, struct lm_sysid *ls,
132     struct flock64 *flk, int flags, u_offset_t offset)
133 {
134 	nlm_register_lock_locally(vp, (struct nlm_host *)ls,
135 	    flk, flags, offset);
136 }
137 
138 /*
139  * Old RPC service dispatch functions, no longer used.
140  * Here only to satisfy modstubs.s references.
141  */
142 void
143 lm_nlm_dispatch(struct svc_req *req, SVCXPRT *xprt)
144 {
145 	_NOTE(ARGUNUSED(req, xprt))
146 }
147 
148 void
149 lm_nlm4_dispatch(struct svc_req *req, SVCXPRT *xprt)
150 {
151 	_NOTE(ARGUNUSED(req, xprt))
152 }
153 
154 /*
155  * Old internal functions used for reclaiming locks
156  * our NFS client holds after some server restarts.
157  * The new NLM code does this differently, so these
158  * are here only to satisfy modstubs.s references.
159  */
160 void
161 lm_nlm_reclaim(struct vnode *vp, struct flock64 *flkp)
162 {
163 	_NOTE(ARGUNUSED(vp, flkp))
164 }
165 
166 void
167 lm_nlm4_reclaim(struct vnode *vp, struct flock64 *flkp)
168 {
169 	_NOTE(ARGUNUSED(vp, flkp))
170 }
171