Bug Summary

File:xlators/nfs/server/src/nlm4.c
Location:line 2199, column 17
Description:Value stored to 'ret' is never read

Annotated Source Code

1/*
2 Copyright (c) 2012 Gluster, Inc. <http://www.gluster.com>
3 This file is part of GlusterFS.
4
5 GlusterFS is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3 of the License,
8 or (at your option) any later version.
9
10 GlusterFS is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see
17 <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef _CONFIG_H
21#define _CONFIG_H
22#include "config.h"
23#endif
24
25#include "defaults.h"
26#include "rpcsvc.h"
27#include "dict.h"
28#include "xlator.h"
29#include "nfs.h"
30#include "mem-pool.h"
31#include "logging.h"
32#include "nfs-fops.h"
33#include "inode.h"
34#include "mount3.h"
35#include "nfs3.h"
36#include "nfs-mem-types.h"
37#include "nfs3-helpers.h"
38#include "nfs3-fh.h"
39#include "nlm4.h"
40#include "nlm4-xdr.h"
41#include "msg-nfs3.h"
42#include "nfs-generics.h"
43#include "rpc-clnt.h"
44#include "nsm-xdr.h"
45#include "nlmcbk-xdr.h"
46#include "run.h"
47#include <unistd.h>
48#include <rpc/pmap_clnt.h>
49#include <rpc/rpc.h>
50#include <rpc/xdr.h>
51#include <statedump.h>
52
53/* TODO:
54 * 1) 2 opens racing .. creating an fd leak.
55 * 2) use mempool for nlmclnt - destroy if no fd exists, create during 1st call
56 */
57
58typedef ssize_t (*nlm4_serializer) (struct iovec outmsg, void *args);
59
60extern void nfs3_call_state_wipe (nfs3_call_state_t *cs);
61
62struct list_head nlm_client_list;
63gf_lock_t nlm_client_list_lk;
64
65/* race on this is harmless */
66int nlm_grace_period = 50;
67
68#define nlm4_validate_nfs3_state(request, state, status, label, retval)do { state = (((rpcsvc_program_t *)((request)->prog))->
private); if (!state) { do { do { if (0) printf ("NFSv3 state "
"missing from RPC request"); } while (0); _gf_log ("nfs""-NLM"
, "nlm4.c", __FUNCTION__, 68, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); (req)->rpc_err = SYSTEM_ERR; status = nlm4_failed
; goto label; } } while (0);
\
69 do { \
70 state = rpcsvc_request_program_private (request)(((rpcsvc_program_t *)((request)->prog))->private); \
71 if (!state) { \
72 gf_log (GF_NLM, GF_LOG_ERROR, "NFSv3 state " \do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
73, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request")
; } while (0)
73 "missing from RPC request")do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
73, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request")
; } while (0)
; \
74 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR; \
75 status = nlm4_failed; \
76 goto label; \
77 } \
78 } while (0); \
79
80nfs3_call_state_t *
81nfs3_call_state_init (struct nfs3_state *s, rpcsvc_request_t *req, xlator_t *v);
82
83#define nlm4_handle_call_state_init(nfs3state, calls, rq, opstat, errlabel)do { calls = nlm4_call_state_init ((nfs3state), (rq)); if (!calls
) { do { do { if (0) printf ("Failed to " "init call state");
} while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 83
, GF_LOG_ERROR, "Failed to " "init call state"); } while (0);
opstat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto errlabel
; } } while (0)
\
84 do { \
85 calls = nlm4_call_state_init ((nfs3state), (rq)); \
86 if (!calls) { \
87 gf_log (GF_NLM, GF_LOG_ERROR, "Failed to " \do { do { if (0) printf ("Failed to " "init call state"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 88, GF_LOG_ERROR
, "Failed to " "init call state"); } while (0)
88 "init call state")do { do { if (0) printf ("Failed to " "init call state"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 88, GF_LOG_ERROR
, "Failed to " "init call state"); } while (0)
; \
89 opstat = nlm4_failed; \
90 rpcsvc_request_seterr (req, SYSTEM_ERR)(req)->rpc_err = SYSTEM_ERR; \
91 goto errlabel; \
92 } \
93 } while (0) \
94
95#define nlm4_validate_gluster_fh(handle, status, errlabel)do { if (!nfs3_fh_validate (handle)) { status = nlm4_stale_fh
; goto errlabel; } } while (0)
\
96 do { \
97 if (!nfs3_fh_validate (handle)) { \
98 status = nlm4_stale_fh; \
99 goto errlabel; \
100 } \
101 } while (0) \
102
103xlator_t *
104nfs3_fh_to_xlator (struct nfs3_state *nfs3, struct nfs3_fh *fh);
105
106#define nlm4_map_fh_to_volume(nfs3state, handle, req, volume, status, label)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); volume = nfs3_fh_to_xlator ((nfs3state), &handle
); if (!volume) { uuid_unparse (handle.exportid, exportid); uuid_unparse
(handle.gfid, gfid); trans = ((req)->trans); do { do { if
(0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 106, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 106, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); status = nlm4_stale_fh; goto
label; } else { do { do { if (0) printf ("FH to Volume: %s" ,
volume->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 106, GF_LOG_TRACE, "FH to Volume: %s" ,volume
->name); } while (0); (req)->private = (void *)(volume)
; } } while (0);
\
107 do { \
108 char exportid[256], gfid[256]; \
109 rpc_transport_t *trans = NULL((void*)0); \
110 volume = nfs3_fh_to_xlator ((nfs3state), &handle); \
111 if (!volume) { \
112 uuid_unparse (handle.exportid, exportid); \
113 uuid_unparse (handle.gfid, gfid); \
114 trans = rpcsvc_request_transport (req)((req)->trans); \
115 gf_log (GF_NLM, GF_LOG_ERROR, "Failed to map " \do { do { if (0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 118, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
116 "FH to vol: client=%s, exportid=%s, gfid=%s",\do { do { if (0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 118, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
117 trans->peerinfo.identifier, exportid, \do { do { if (0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 118, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
118 gfid)do { do { if (0) printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 118, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; \
119 gf_log (GF_NLM, GF_LOG_ERROR, \do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 122, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0)
120 "Stale nfs client %s must be trying to "\do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 122, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0)
121 "connect to a deleted volume, please " \do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 122, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0)
122 "unmount it.", trans->peerinfo.identifier)do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 122, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0)
;\
123 status = nlm4_stale_fh; \
124 goto label; \
125 } else { \
126 gf_log (GF_NLM, GF_LOG_TRACE, "FH to Volume: %s"\do { do { if (0) printf ("FH to Volume: %s" ,volume->name)
; } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 127
, GF_LOG_TRACE, "FH to Volume: %s" ,volume->name); } while
(0)
127 ,volume->name)do { do { if (0) printf ("FH to Volume: %s" ,volume->name)
; } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 127
, GF_LOG_TRACE, "FH to Volume: %s" ,volume->name); } while
(0)
; \
128 rpcsvc_request_set_private (req, volume)(req)->private = (void *)(volume); \
129 } \
130 } while (0); \
131
132#define nlm4_volume_started_check(nfs3state, vlm, rtval, erlbl)do { if ((!nfs_subvolume_started ((nfs3state->nfsx)->private
, vlm))){ do { do { if (0) printf ("Volume is disabled: %s", vlm
->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 132, GF_LOG_ERROR, "Volume is disabled: %s", vlm->name);
} while (0); rtval = (-2); goto erlbl; } } while (0)
\
133 do { \
134 if ((!nfs_subvolume_started (nfs_state (nfs3state->nfsx)(nfs3state->nfsx)->private, vlm))){\
135 gf_log (GF_NLM, GF_LOG_ERROR, "Volume is disabled: %s",\do { do { if (0) printf ("Volume is disabled: %s", vlm->name
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
136, GF_LOG_ERROR, "Volume is disabled: %s", vlm->name); }
while (0)
136 vlm->name)do { do { if (0) printf ("Volume is disabled: %s", vlm->name
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
136, GF_LOG_ERROR, "Volume is disabled: %s", vlm->name); }
while (0)
; \
137 rtval = RPCSVC_ACTOR_IGNORE(-2); \
138 goto erlbl; \
139 } \
140 } while (0) \
141
142#define nlm4_check_fh_resolve_status(cst, nfstat, erlabl)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cst)->resolve_ret
< 0) { trans = ((cst->req)->trans); xlatorp = nfs3_fh_to_xlator
(cst->nfs3state, &cst->resolvefh); uuid_unparse (cst
->resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans
->peerinfo.identifier, xlatorp ? xlatorp->name : "ERR",
gfid); do { do { if (0) printf ("Unable to resolve FH" ": %s"
, buf); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 142, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); nfstat = nlm4_errno_to_nlm4stat (cst->resolve_errno)
; goto erlabl; } } while (0)
\
143 do { \
144 xlator_t *xlatorp = NULL((void*)0); \
145 char buf[256], gfid[256]; \
146 rpc_transport_t *trans = NULL((void*)0); \
147 if ((cst)->resolve_ret < 0) { \
148 trans = rpcsvc_request_transport (cst->req)((cst->req)->trans); \
149 xlatorp = nfs3_fh_to_xlator (cst->nfs3state, \
150 &cst->resolvefh); \
151 uuid_unparse (cst->resolvefh.gfid, gfid); \
152 sprintf (buf, "(%s) %s : %s", trans->peerinfo.identifier,\
153 xlatorp ? xlatorp->name : "ERR", gfid); \
154 gf_log (GF_NLM, GF_LOG_ERROR, "Unable to resolve FH"\do { do { if (0) printf ("Unable to resolve FH" ": %s", buf);
} while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 155
, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while (
0)
155 ": %s", buf)do { do { if (0) printf ("Unable to resolve FH" ": %s", buf);
} while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 155
, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while (
0)
; \
156 nfstat = nlm4_errno_to_nlm4stat (cst->resolve_errno);\
157 goto erlabl; \
158 } \
159 } while (0) \
160
161
162void
163nlm4_prep_nlm4_testargs (nlm4_testargs *args, struct nfs3_fh *fh,
164 nlm4_lkowner_t *oh, char *cookiebytes)
165{
166 memset (args, 0, sizeof (*args));
167 args->alock.fh.n_bytes = (void *)fh;
168 args->alock.oh.n_bytes = (void *)oh;
169 args->cookie.n_bytes = (void *)cookiebytes;
170}
171
172void
173nlm4_prep_nlm4_lockargs (nlm4_lockargs *args, struct nfs3_fh *fh,
174 nlm4_lkowner_t *oh, char *cookiebytes)
175{
176 memset (args, 0, sizeof (*args));
177 args->alock.fh.n_bytes = (void *)fh;
178 args->alock.oh.n_bytes = (void *)oh;
179 args->cookie.n_bytes = (void *)cookiebytes;
180}
181
182void
183nlm4_prep_nlm4_cancargs (nlm4_cancargs *args, struct nfs3_fh *fh,
184 nlm4_lkowner_t *oh, char *cookiebytes)
185{
186 memset (args, 0, sizeof (*args));
187 args->alock.fh.n_bytes = (void *)fh;
188 args->alock.oh.n_bytes = (void *)oh;
189 args->cookie.n_bytes = (void *)cookiebytes;
190}
191
192void
193nlm4_prep_nlm4_unlockargs (nlm4_unlockargs *args, struct nfs3_fh *fh,
194 nlm4_lkowner_t *oh, char *cookiebytes)
195{
196 memset (args, 0, sizeof (*args));
197 args->alock.fh.n_bytes = (void *)fh;
198 args->alock.oh.n_bytes = (void *)oh;
199 args->cookie.n_bytes = (void *)cookiebytes;
200}
201
202void
203nlm4_prep_shareargs (nlm4_shareargs *args, struct nfs3_fh *fh,
204 nlm4_lkowner_t *oh, char *cookiebytes)
205{
206 memset (args, 0, sizeof (*args));
207 args->share.fh.n_bytes = (void *)fh;
208 args->share.oh.n_bytes = (void *)oh;
209 args->cookie.n_bytes = (void *)cookiebytes;
210}
211
212void
213nlm4_prep_freeallargs (nlm4_freeallargs *args, nlm4_lkowner_t *oh)
214{
215 memset (args, 0, sizeof (*args));
216 args->name = (void *)oh;
217}
218
219void
220nlm_copy_lkowner (gf_lkowner_t *dst, netobj *src)
221{
222 dst->len = src->n_len;
223 memcpy (dst->data, src->n_bytes, dst->len);
224}
225
226int
227nlm_is_oh_same_lkowner (gf_lkowner_t *a, netobj *b)
228{
229 if (!a || !b) {
230 gf_log (GF_NLM, GF_LOG_ERROR, "invalid args")do { do { if (0) printf ("invalid args"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 230, GF_LOG_ERROR, "invalid args"
); } while (0)
;
231 return -1;
232 }
233
234 return (a->len == b->n_len &&
235 !memcmp (a->data, b->n_bytes, a->len));
236}
237
238nfsstat3
239nlm4_errno_to_nlm4stat (int errnum)
240{
241 nlm4_stats stat = nlm4_denied;
242
243 switch (errnum) {
244 case 0:
245 stat = nlm4_granted;
246 break;
247 case EROFS30:
248 stat = nlm4_rofs;
249 break;
250 case ESTALE116:
251 stat = nlm4_stale_fh;
252 break;
253 case ENOLCK37:
254 stat = nlm4_failed;
255 break;
256 default:
257 stat = nlm4_denied;
258 break;
259 }
260
261 return stat;
262}
263
264nfs3_call_state_t *
265nlm4_call_state_init (struct nfs3_state *s, rpcsvc_request_t *req)
266{
267 nfs3_call_state_t *cs = NULL((void*)0);
268
269 if ((!s) || (!req))
270 return NULL((void*)0);
271
272 cs = (nfs3_call_state_t *) mem_get (s->localpool);
273 if (!cs)
274 return NULL((void*)0);
275
276 memset (cs, 0, sizeof (*cs));
277 INIT_LIST_HEAD (&cs->entries.list)do { (&cs->entries.list)->next = (&cs->entries
.list)->prev = &cs->entries.list; } while (0)
;
278 INIT_LIST_HEAD (&cs->openwait_q)do { (&cs->openwait_q)->next = (&cs->openwait_q
)->prev = &cs->openwait_q; } while (0)
;
279 cs->operrno = EINVAL22;
280 cs->req = req;
281 cs->nfsx = s->nfsx;
282 cs->nfs3state = s;
283 cs->monitor = 1;
284
285 return cs;
286}
287
288int
289nlm_monitor (char *caller_name)
290{
291 nlm_client_t *nlmclnt = NULL((void*)0);
292 int monitor = -1;
293
294 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
295 list_for_each_entry (nlmclnt, &nlm_client_list, nlm_clients)for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
{
296 if (!strcmp(caller_name, nlmclnt->caller_name)) {
297 monitor = nlmclnt->nsm_monitor;
298 nlmclnt->nsm_monitor = 1;
299 break;
300 }
301 }
302 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
303
304 if (monitor == -1)
305 gf_log (GF_NLM, GF_LOG_ERROR, "%s was not found in "do { do { if (0) printf ("%s was not found in " "the nlmclnt list"
, caller_name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 306, GF_LOG_ERROR, "%s was not found in " "the nlmclnt list"
, caller_name); } while (0)
306 "the nlmclnt list", caller_name)do { do { if (0) printf ("%s was not found in " "the nlmclnt list"
, caller_name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 306, GF_LOG_ERROR, "%s was not found in " "the nlmclnt list"
, caller_name); } while (0)
;
307
308 return monitor;
309}
310
311rpc_clnt_t *
312nlm_get_rpc_clnt (char *caller_name)
313{
314 nlm_client_t *nlmclnt = NULL((void*)0);
315 int nlmclnt_found = 0;
316 rpc_clnt_t *rpc_clnt = NULL((void*)0);
317
318 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
319 list_for_each_entry (nlmclnt, &nlm_client_list, nlm_clients)for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
{
320 if (!strcmp(caller_name, nlmclnt->caller_name)) {
321 nlmclnt_found = 1;
322 break;
323 }
324 }
325 if (!nlmclnt_found)
326 goto ret;
327 if (nlmclnt->rpc_clnt)
328 rpc_clnt = rpc_clnt_ref (nlmclnt->rpc_clnt);
329ret:
330 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
331 return rpc_clnt;
332}
333
334int
335nlm_set_rpc_clnt (rpc_clnt_t *rpc_clnt, char *caller_name)
336{
337 nlm_client_t *nlmclnt = NULL((void*)0);
338 int nlmclnt_found = 0;
339 int ret = -1;
340
341 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
342 list_for_each_entry (nlmclnt, &nlm_client_list, nlm_clients)for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
{
343 if (!strcmp(caller_name, nlmclnt->caller_name)) {
344 nlmclnt_found = 1;
345 break;
346 }
347 }
348
349 if (!nlmclnt_found) {
350 nlmclnt = GF_CALLOC (1, sizeof(*nlmclnt),__gf_calloc (1, sizeof(*nlmclnt), gf_nfs_mt_nlm4_nlmclnt)
351 gf_nfs_mt_nlm4_nlmclnt)__gf_calloc (1, sizeof(*nlmclnt), gf_nfs_mt_nlm4_nlmclnt);
352 if (nlmclnt == NULL((void*)0))
353 goto ret;
354
355 INIT_LIST_HEAD(&nlmclnt->fdes)do { (&nlmclnt->fdes)->next = (&nlmclnt->fdes
)->prev = &nlmclnt->fdes; } while (0)
;
356 INIT_LIST_HEAD(&nlmclnt->nlm_clients)do { (&nlmclnt->nlm_clients)->next = (&nlmclnt->
nlm_clients)->prev = &nlmclnt->nlm_clients; } while
(0)
;
357 INIT_LIST_HEAD(&nlmclnt->shares)do { (&nlmclnt->shares)->next = (&nlmclnt->shares
)->prev = &nlmclnt->shares; } while (0)
;
358
359 list_add (&nlmclnt->nlm_clients, &nlm_client_list);
360 nlmclnt->caller_name = gf_strdup (caller_name);
361 }
362
363 if (nlmclnt->rpc_clnt == NULL((void*)0)) {
364 nlmclnt->rpc_clnt = rpc_clnt_ref (rpc_clnt);
365 }
366 ret = 0;
367ret:
368 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
369 return ret;
370}
371
372int
373nlm_unset_rpc_clnt (rpc_clnt_t *rpc)
374{
375 nlm_client_t *nlmclnt = NULL((void*)0);
376 rpc_clnt_t *rpc_clnt = NULL((void*)0);
377
378 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
379 list_for_each_entry (nlmclnt, &nlm_client_list, nlm_clients)for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
{
380 if (rpc == nlmclnt->rpc_clnt) {
381 rpc_clnt = nlmclnt->rpc_clnt;
382 nlmclnt->rpc_clnt = NULL((void*)0);
383 break;
384 }
385 }
386 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
387 if (rpc_clnt == NULL((void*)0)) {
388 return -1;
389 }
390 if (rpc_clnt) {
391 /* cleanup the saved-frames before last unref */
392 rpc_clnt_connection_cleanup (&rpc_clnt->conn);
393
394 rpc_clnt_unref (rpc_clnt);
395 }
396 return 0;
397}
398
399int
400nlm_add_nlmclnt (char *caller_name)
401{
402 nlm_client_t *nlmclnt = NULL((void*)0);
403 int nlmclnt_found = 0;
404 int ret = -1;
405
406 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
407 list_for_each_entry (nlmclnt, &nlm_client_list, nlm_clients)for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
{
408 if (!strcmp(caller_name, nlmclnt->caller_name)) {
409 nlmclnt_found = 1;
410 break;
411 }
412 }
413 if (!nlmclnt_found) {
414 nlmclnt = GF_CALLOC (1, sizeof(*nlmclnt),__gf_calloc (1, sizeof(*nlmclnt), gf_nfs_mt_nlm4_nlmclnt)
415 gf_nfs_mt_nlm4_nlmclnt)__gf_calloc (1, sizeof(*nlmclnt), gf_nfs_mt_nlm4_nlmclnt);
416 if (nlmclnt == NULL((void*)0)) {
417 gf_log (GF_NLM, GF_LOG_DEBUG, "malloc error")do { do { if (0) printf ("malloc error"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 417, GF_LOG_DEBUG, "malloc error"
); } while (0)
;
418 goto ret;
419 }
420
421 INIT_LIST_HEAD(&nlmclnt->fdes)do { (&nlmclnt->fdes)->next = (&nlmclnt->fdes
)->prev = &nlmclnt->fdes; } while (0)
;
422 INIT_LIST_HEAD(&nlmclnt->nlm_clients)do { (&nlmclnt->nlm_clients)->next = (&nlmclnt->
nlm_clients)->prev = &nlmclnt->nlm_clients; } while
(0)
;
423 INIT_LIST_HEAD(&nlmclnt->shares)do { (&nlmclnt->shares)->next = (&nlmclnt->shares
)->prev = &nlmclnt->shares; } while (0)
;
424
425 list_add (&nlmclnt->nlm_clients, &nlm_client_list);
426 nlmclnt->caller_name = gf_strdup (caller_name);
427 }
428 ret = 0;
429ret:
430 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
431 return ret;
432}
433
434int
435nlm4svc_submit_reply (rpcsvc_request_t *req, void *arg, nlm4_serializer sfunc)
436{
437 struct iovec outmsg = {0, };
438 struct iobuf *iob = NULL((void*)0);
439 struct nfs3_state *nfs3 = NULL((void*)0);
440 int ret = -1;
441 struct iobref *iobref = NULL((void*)0);
442
443 if (!req)
444 return -1;
445
446 nfs3 = (struct nfs3_state *)rpcsvc_request_program_private (req)(((rpcsvc_program_t *)((req)->prog))->private);
447 if (!nfs3) {
448 gf_log (GF_NLM, GF_LOG_ERROR, "mount state not found")do { do { if (0) printf ("mount state not found"); } while (0
); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 448, GF_LOG_ERROR
, "mount state not found"); } while (0)
;
449 goto ret;
450 }
451
452 /* First, get the io buffer into which the reply in arg will
453 * be serialized.
454 */
455 iob = iobuf_get (nfs3->iobpool);
456 if (!iob) {
457 gf_log (GF_NLM, GF_LOG_ERROR, "Failed to get iobuf")do { do { if (0) printf ("Failed to get iobuf"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 457, GF_LOG_ERROR
, "Failed to get iobuf"); } while (0)
;
458 goto ret;
459 }
460
461 iobuf_to_iovec (iob, &outmsg);
462 /* Use the given serializer to translate the give C structure in arg
463 * to XDR format which will be written into the buffer in outmsg.
464 */
465 outmsg.iov_len = sfunc (outmsg, arg);
466
467 iobref = iobref_new ();
468 if (iobref == NULL((void*)0)) {
469 gf_log (GF_NLM, GF_LOG_ERROR, "Failed to get iobref")do { do { if (0) printf ("Failed to get iobref"); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 469, GF_LOG_ERROR
, "Failed to get iobref"); } while (0)
;
470 goto ret;
471 }
472
473 iobref_add (iobref, iob);
474
475 /* Then, submit the message for transmission. */
476 ret = rpcsvc_submit_message (req, &outmsg, 1, NULL((void*)0), 0, iobref);
477 if (ret == -1) {
478 gf_log (GF_NLM, GF_LOG_ERROR, "Reply submission failed")do { do { if (0) printf ("Reply submission failed"); } while (
0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 478, GF_LOG_ERROR
, "Reply submission failed"); } while (0)
;
479 goto ret;
480 }
481
482 ret = 0;
483ret:
484 if (iob)
485 iobuf_unref (iob);
486 if (iobref)
487 iobref_unref (iobref);
488
489 return ret;
490}
491
492typedef int (*nlm4_resume_fn_t) (void *cs);
493
494int32_t
495nlm4_file_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
496 int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata)
497{
498 nfs3_call_state_t *cs = frame->local;
499
500 if (op_ret == 0)
501 fd_bind (cs->fd);
502 cs->resolve_ret = op_ret;
503 cs->resume_fn (cs);
504 frame->local = NULL((void*)0);
505 STACK_DESTROY (frame->root);
506 return 0;
507}
508
509void *
510nsm_monitor(void *arg)
511{
512 CLIENT *clnt = NULL((void*)0);
513 enum clnt_stat ret;
514 struct mon nsm_mon;
515 struct sm_stat_res res;
516 struct timeval tout = { 5, 0 };
517 char *host = NULL((void*)0);
518
519 host = arg;
520 nsm_mon.mon_id.mon_name = gf_strdup(host);
521 nsm_mon.mon_id.my_id.my_name = gf_strdup("localhost");
522 nsm_mon.mon_id.my_id.my_prog = NLMCBK_PROGRAM100021;
523 nsm_mon.mon_id.my_id.my_vers = NLMCBK_V11;
524 nsm_mon.mon_id.my_id.my_proc = NLMCBK_SM_NOTIFY16;
525 /* nothing to put in the private data */
526#define SM_PROG100024 100024
527#define SM_VERS1 1
528#define SM_MON2 2
529
530 /* create a connection to nsm on the localhost */
531 clnt = clnt_create("localhost", SM_PROG100024, SM_VERS1, "tcp");
532 if(!clnt)
533 {
534 gf_log (GF_NLM, GF_LOG_ERROR, "%s",do { do { if (0) printf ("%s", clnt_spcreateerror ("Clnt_create()"
)); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 535, GF_LOG_ERROR, "%s", clnt_spcreateerror ("Clnt_create()"
)); } while (0)
535 clnt_spcreateerror ("Clnt_create()"))do { do { if (0) printf ("%s", clnt_spcreateerror ("Clnt_create()"
)); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 535, GF_LOG_ERROR, "%s", clnt_spcreateerror ("Clnt_create()"
)); } while (0)
;
536 goto out;
537 }
538
539 ret = clnt_call(clnt, SM_MON,((*(clnt)->cl_ops->cl_call)(clnt, 2, (xdrproc_t) xdr_mon
, (caddr_t) & nsm_mon, (xdrproc_t) xdr_sm_stat_res, (caddr_t
) & res, tout))
540 (xdrproc_t) xdr_mon, (caddr_t) & nsm_mon,((*(clnt)->cl_ops->cl_call)(clnt, 2, (xdrproc_t) xdr_mon
, (caddr_t) & nsm_mon, (xdrproc_t) xdr_sm_stat_res, (caddr_t
) & res, tout))
541 (xdrproc_t) xdr_sm_stat_res, (caddr_t) & res, tout)((*(clnt)->cl_ops->cl_call)(clnt, 2, (xdrproc_t) xdr_mon
, (caddr_t) & nsm_mon, (xdrproc_t) xdr_sm_stat_res, (caddr_t
) & res, tout))
;
542 if(ret != RPC_SUCCESS)
543 {
544 gf_log (GF_NLM, GF_LOG_ERROR, "clnt_call(): %s",do { do { if (0) printf ("clnt_call(): %s", clnt_sperrno(ret)
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
545, GF_LOG_ERROR, "clnt_call(): %s", clnt_sperrno(ret)); } while
(0)
545 clnt_sperrno(ret))do { do { if (0) printf ("clnt_call(): %s", clnt_sperrno(ret)
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
545, GF_LOG_ERROR, "clnt_call(): %s", clnt_sperrno(ret)); } while
(0)
;
546 goto out;
547 }
548 if(res.res_stat != STAT_SUCC)
549 {
550 gf_log (GF_NLM, GF_LOG_ERROR, "clnt_call(): %s",do { do { if (0) printf ("clnt_call(): %s", clnt_sperrno(ret)
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
551, GF_LOG_ERROR, "clnt_call(): %s", clnt_sperrno(ret)); } while
(0)
551 clnt_sperrno(ret))do { do { if (0) printf ("clnt_call(): %s", clnt_sperrno(ret)
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
551, GF_LOG_ERROR, "clnt_call(): %s", clnt_sperrno(ret)); } while
(0)
;
552 goto out;
553 }
554
555out:
556 GF_FREE(nsm_mon.mon_id.mon_name)__gf_free (nsm_mon.mon_id.mon_name);
557 GF_FREE(nsm_mon.mon_id.my_id.my_name)__gf_free (nsm_mon.mon_id.my_id.my_name);
558 if (clnt != NULL((void*)0))
559 clnt_destroy(clnt)((*(clnt)->cl_ops->cl_destroy)(clnt));
560 return NULL((void*)0);
561}
562
563nlm_client_t *
564__nlm_get_uniq (char *caller_name)
565{
566 nlm_client_t *nlmclnt = NULL((void*)0);
567
568 if (!caller_name)
569 return NULL((void*)0);
570
571 list_for_each_entry (nlmclnt, &nlm_client_list, nlm_clients)for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
{
572 if (!strcmp(caller_name, nlmclnt->caller_name))
573 return nlmclnt;
574 }
575
576 return NULL((void*)0);
577}
578
579nlm_client_t *
580nlm_get_uniq (char *caller_name)
581{
582 nlm_client_t *nlmclnt = NULL((void*)0);
583
584 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
585 nlmclnt = __nlm_get_uniq (caller_name);
586 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
587
588 return nlmclnt;
589}
590
591
592int
593nlm4_file_open_and_resume(nfs3_call_state_t *cs, nlm4_resume_fn_t resume)
594{
595 fd_t *fd = NULL((void*)0);
596 int ret = -1;
597 int flags = 0;
598 nlm_client_t *nlmclnt = NULL((void*)0);
599 call_frame_t *frame = NULL((void*)0);
600
601 if (cs->args.nlm4_lockargs.exclusive == _gf_false)
602 flags = O_RDONLY00;
603 else
604 flags = O_WRONLY01;
605
606 nlmclnt = nlm_get_uniq (cs->args.nlm4_lockargs.alock.caller_name);
607 if (nlmclnt == NULL((void*)0)) {
608 gf_log (GF_NLM, GF_LOG_ERROR, "nlm_get_uniq() returned NULL")do { do { if (0) printf ("nlm_get_uniq() returned NULL"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 608, GF_LOG_ERROR
, "nlm_get_uniq() returned NULL"); } while (0)
;
609 ret = -ENOLCK37;
610 goto err;
611 }
612 cs->resume_fn = resume;
613 fd = fd_lookup_uint64 (cs->resolvedloc.inode, (uint64_t)nlmclnt);
614 if (fd) {
615 cs->fd = fd;
616 cs->resolve_ret = 0;
617 cs->resume_fn(cs);
618 ret = 0;
619 goto err;
620 }
621
622 fd = fd_create_uint64 (cs->resolvedloc.inode, (uint64_t)nlmclnt);
623 if (fd == NULL((void*)0)) {
624 gf_log (GF_NLM, GF_LOG_ERROR, "fd_create_uint64() returned NULL")do { do { if (0) printf ("fd_create_uint64() returned NULL");
} while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 624
, GF_LOG_ERROR, "fd_create_uint64() returned NULL"); } while (
0)
;
625 ret = -ENOLCK37;
626 goto err;
627 }
628
629 cs->fd = fd;
630
631 frame = create_frame (cs->nfsx, cs->nfsx->ctx->pool);
632 if (!frame) {
633 gf_log (GF_NLM, GF_LOG_ERROR, "unable to create frame")do { do { if (0) printf ("unable to create frame"); } while (
0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 633, GF_LOG_ERROR
, "unable to create frame"); } while (0)
;
634 ret = -ENOMEM12;
635 goto err;
636 }
637
638 frame->root->pid = NFS_PID1;
639 frame->root->uid = rpcsvc_request_uid (cs->req)((cs->req)->uid);
640 frame->root->gid = rpcsvc_request_gid (cs->req)((cs->req)->gid);
641 frame->local = cs;
642 nfs_fix_groups (cs->nfsx, frame->root);
643
644 STACK_WIND_COOKIE (frame, nlm4_file_open_cbk, cs->vol, cs->vol,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "nlm4.c", __FUNCTION__, 646, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( cs->vol->
fops->open_cbk) tmp_cbk = nlm4_file_open_cbk; _new->root
= frame->root; _new->this = cs->vol; _new->ret =
(ret_fn_t) tmp_cbk; _new->parent = frame; _new->cookie
= cs->vol; _new->wind_from = __FUNCTION__; _new->wind_to
= "cs->vol->fops->open"; _new->unwind_to = "nlm4_file_open_cbk"
; pthread_spin_init (&_new->lock, 0); pthread_spin_lock
(&frame->root->stack_lock); { frame->ref_count++
; _new->next = frame->root->frames.next; _new->prev
= &frame->root->frames; if (frame->root->frames
.next) frame->root->frames.next->prev = _new; frame->
root->frames.next = _new; } pthread_spin_unlock (&frame
->root->stack_lock); cs->vol->fops->open_cbk =
nlm4_file_open_cbk; old_THIS = (*__glusterfs_this_location()
); (*__glusterfs_this_location()) = cs->vol; if (cs->vol
->ctx->measure_latency) gf_latency_begin (_new, cs->
vol->fops->open); cs->vol->fops->open (_new, cs
->vol, &cs->resolvedloc, flags, cs->fd, ((void*)
0)); (*__glusterfs_this_location()) = old_THIS; } while (0)
645 cs->vol->fops->open, &cs->resolvedloc, flags,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "nlm4.c", __FUNCTION__, 646, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( cs->vol->
fops->open_cbk) tmp_cbk = nlm4_file_open_cbk; _new->root
= frame->root; _new->this = cs->vol; _new->ret =
(ret_fn_t) tmp_cbk; _new->parent = frame; _new->cookie
= cs->vol; _new->wind_from = __FUNCTION__; _new->wind_to
= "cs->vol->fops->open"; _new->unwind_to = "nlm4_file_open_cbk"
; pthread_spin_init (&_new->lock, 0); pthread_spin_lock
(&frame->root->stack_lock); { frame->ref_count++
; _new->next = frame->root->frames.next; _new->prev
= &frame->root->frames; if (frame->root->frames
.next) frame->root->frames.next->prev = _new; frame->
root->frames.next = _new; } pthread_spin_unlock (&frame
->root->stack_lock); cs->vol->fops->open_cbk =
nlm4_file_open_cbk; old_THIS = (*__glusterfs_this_location()
); (*__glusterfs_this_location()) = cs->vol; if (cs->vol
->ctx->measure_latency) gf_latency_begin (_new, cs->
vol->fops->open); cs->vol->fops->open (_new, cs
->vol, &cs->resolvedloc, flags, cs->fd, ((void*)
0)); (*__glusterfs_this_location()) = old_THIS; } while (0)
646 cs->fd, NULL)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "nlm4.c", __FUNCTION__, 646, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( cs->vol->
fops->open_cbk) tmp_cbk = nlm4_file_open_cbk; _new->root
= frame->root; _new->this = cs->vol; _new->ret =
(ret_fn_t) tmp_cbk; _new->parent = frame; _new->cookie
= cs->vol; _new->wind_from = __FUNCTION__; _new->wind_to
= "cs->vol->fops->open"; _new->unwind_to = "nlm4_file_open_cbk"
; pthread_spin_init (&_new->lock, 0); pthread_spin_lock
(&frame->root->stack_lock); { frame->ref_count++
; _new->next = frame->root->frames.next; _new->prev
= &frame->root->frames; if (frame->root->frames
.next) frame->root->frames.next->prev = _new; frame->
root->frames.next = _new; } pthread_spin_unlock (&frame
->root->stack_lock); cs->vol->fops->open_cbk =
nlm4_file_open_cbk; old_THIS = (*__glusterfs_this_location()
); (*__glusterfs_this_location()) = cs->vol; if (cs->vol
->ctx->measure_latency) gf_latency_begin (_new, cs->
vol->fops->open); cs->vol->fops->open (_new, cs
->vol, &cs->resolvedloc, flags, cs->fd, ((void*)
0)); (*__glusterfs_this_location()) = old_THIS; } while (0)
;
647 ret = 0;
648err:
649 return ret;
650}
651
652int
653nlm4_generic_reply (rpcsvc_request_t *req, netobj cookie, nlm4_stats stat)
654{
655 nlm4_res res;
656
657 memset (&res, 0, sizeof (res));
658 res.cookie = cookie;
659 res.stat.stat = stat;
660
661 nlm4svc_submit_reply (req, (void *)&res,
662 (nlm4_serializer)xdr_serialize_nlm4_res);
663 return 0;
664}
665
666int
667nlm4svc_null (rpcsvc_request_t *req)
668{
669 struct iovec dummyvec = {0, };
670
671 if (!req) {
672 gf_log (GF_NLM, GF_LOG_ERROR, "Got NULL request!")do { do { if (0) printf ("Got NULL request!"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 672, GF_LOG_ERROR, "Got NULL request!"
); } while (0)
;
673 return 0;
674 }
675 rpcsvc_submit_generic (req, &dummyvec, 1, NULL((void*)0), 0, NULL((void*)0));
676 return 0;
677}
678
679int
680nlm4_gf_flock_to_holder (nlm4_holder *holder, struct gf_flock *flock)
681{
682 switch (flock->l_type) {
683 case GF_LK_F_WRLCK:
684 holder->exclusive = 1;
685 break;
686 }
687
688 holder->svid = flock->l_pid;
689 holder->l_offset = flock->l_start;
690 holder->l_len = flock->l_len;
691 return 0;
692}
693
694int
695nlm4_lock_to_gf_flock (struct gf_flock *flock, nlm4_lock *lock, int excl)
696{
697 flock->l_pid = lock->svid;
698 flock->l_start = lock->l_offset;
699 flock->l_len = lock->l_len;
700 if (excl)
701 flock->l_type = F_WRLCK1;
702 else
703 flock->l_type = F_RDLCK0;
704 flock->l_whence = SEEK_SET0;
705 nlm_copy_lkowner (&flock->l_owner, &lock->oh);
706 return 0;
707}
708
709rpc_clnt_procedure_t nlm4_clnt_actors[NLM4_PROC_COUNT24] = {
710 [NLM4_NULL0] = {"NULL", NULL((void*)0)},
711 [NLM4_GRANTED5] = {"GRANTED", NULL((void*)0)},
712};
713
714char *nlm4_clnt_names[NLM4_PROC_COUNT24] = {
715 [NLM4_NULL0] = "NULL",
716 [NLM4_GRANTED5] = "GRANTED",
717};
718
719rpc_clnt_prog_t nlm4clntprog = {
720 .progname = "NLMv4",
721 .prognum = NLM_PROGRAM100021,
722 .progver = NLM_V44,
723 .numproc = NLM4_PROC_COUNT24,
724 .proctable = nlm4_clnt_actors,
725 .procnames = nlm4_clnt_names,
726};
727
728int
729nlm4_test_reply (nfs3_call_state_t *cs, nlm4_stats stat, struct gf_flock *flock)
730{
731 nlm4_testres res;
732
733 memset (&res, 0, sizeof (res));
734 res.cookie = cs->args.nlm4_testargs.cookie;
735 res.stat.stat = stat;
736 if (stat == nlm4_denied)
737 nlm4_gf_flock_to_holder (&res.stat.nlm4_testrply_u.holder,
738 flock);
739
740 nlm4svc_submit_reply (cs->req, (void *)&res,
741 (nlm4_serializer)xdr_serialize_nlm4_testres);
742 return 0;
743}
744
745int
746nlm4svc_test_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
747 int32_t op_ret, int32_t op_errno, struct gf_flock *flock,
748 dict_t *xdata)
749{
750 nlm4_stats stat = nlm4_denied;
751 nfs3_call_state_t *cs = NULL((void*)0);
752
753 cs = frame->local;
754 if (op_ret == -1) {
755 stat = nlm4_errno_to_nlm4stat (op_errno);
756 goto err;
757 } else if (flock->l_type == F_UNLCK2)
758 stat = nlm4_granted;
759
760err:
761 nlm4_test_reply (cs, stat, flock);
762 nfs3_call_state_wipe (cs);
763 return 0;
764}
765
766int
767nlm4_test_fd_resume (void *carg)
768{
769 int ret = -EFAULT14;
770 nfs_user_t nfu = {0, };
771 nfs3_call_state_t *cs = NULL((void*)0);
772 struct gf_flock flock = {0, };
773
774 if (!carg)
775 return ret;
776
777 cs = (nfs3_call_state_t *)carg;
778 nfs_request_user_init (&nfu, cs->req);
779 nlm4_lock_to_gf_flock (&flock, &cs->args.nlm4_testargs.alock,
780 cs->args.nlm4_testargs.exclusive);
781 nlm_copy_lkowner (&nfu.lk_owner, &cs->args.nlm4_testargs.alock.oh);
782 ret = nfs_lk (cs->nfsx, cs->vol, &nfu, cs->fd, F_GETLK12, &flock,
783 nlm4svc_test_cbk, cs);
784
785 return ret;
786}
787
788
789int
790nlm4_test_resume (void *carg)
791{
792 nlm4_stats stat = nlm4_failed;
793 int ret = -1;
794 nfs3_call_state_t *cs = NULL((void*)0);
795 fd_t *fd = NULL((void*)0);
796
797 if (!carg)
798 return ret;
799
800 cs = (nfs3_call_state_t *)carg;
801 nlm4_check_fh_resolve_status (cs, stat, nlm4err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
801, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nlm4_errno_to_nlm4stat (cs->resolve_errno); goto
nlm4err; } } while (0)
;
802 fd = fd_anonymous (cs->resolvedloc.inode);
803 if (!fd)
804 goto nlm4err;
805 cs->fd = fd;
806 ret = nlm4_test_fd_resume (cs);
807
808nlm4err:
809 if (ret < 0) {
810 gf_log (GF_NLM, GF_LOG_ERROR, "unable to open_and_resume")do { do { if (0) printf ("unable to open_and_resume"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 810, GF_LOG_ERROR
, "unable to open_and_resume"); } while (0)
;
811 stat = nlm4_errno_to_nlm4stat (-ret);
812 nlm4_test_reply (cs, stat, NULL((void*)0));
813 nfs3_call_state_wipe (cs);
814 }
815
816 return ret;
817}
818
819int
820nlm4svc_test (rpcsvc_request_t *req)
821{
822 xlator_t *vol = NULL((void*)0);
823 nlm4_stats stat = nlm4_failed;
824 struct nfs_state *nfs = NULL((void*)0);
825 nfs3_state_t *nfs3 = NULL((void*)0);
826 nfs3_call_state_t *cs = NULL((void*)0);
827 int ret = RPCSVC_ACTOR_ERROR(-1);
828 struct nfs3_fh fh = {{0}, };
829
830 if (!req)
831 return ret;
832
833 nlm4_validate_nfs3_state (req, nfs3, stat, rpcerr, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
833, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); (req)->rpc_err = SYSTEM_ERR; stat = nlm4_failed
; goto rpcerr; } } while (0);
;
834 nfs = nfs_state (nfs3->nfsx)(nfs3->nfsx)->private;
835 nlm4_handle_call_state_init (nfs->nfs3state, cs, req,do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
836, GF_LOG_ERROR, "Failed to " "init call state"); } while (
0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto rpcerr
; } } while (0)
836 stat, rpcerr)do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
836, GF_LOG_ERROR, "Failed to " "init call state"); } while (
0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto rpcerr
; } } while (0)
;
837
838 nlm4_prep_nlm4_testargs (&cs->args.nlm4_testargs, &fh, &cs->lkowner,
839 cs->cookiebytes);
840 if (xdr_to_nlm4_testargs(req->msg[0], &cs->args.nlm4_testargs) <= 0) {
841 gf_log (GF_NLM, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 841, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
842 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
843 goto rpcerr;
844 }
845
846 nlm4_validate_gluster_fh (&fh, stat, nlm4err)do { if (!nfs3_fh_validate (&fh)) { stat = nlm4_stale_fh;
goto nlm4err; } } while (0)
;
847 nlm4_map_fh_to_volume (cs->nfs3state, fh, req, vol, stat, nlm4err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((cs->nfs3state), &
fh); if (!vol) { uuid_unparse (fh.exportid, exportid); uuid_unparse
(fh.gfid, gfid); trans = ((req)->trans); do { do { if (0)
printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 847, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 847, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = nlm4_stale_fh; goto
nlm4err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c",
__FUNCTION__, 847, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
848
849 if (nlm_grace_period) {
850 gf_log (GF_NLM, GF_LOG_WARNING, "NLM in grace period")do { do { if (0) printf ("NLM in grace period"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 850, GF_LOG_WARNING
, "NLM in grace period"); } while (0)
;
851 stat = nlm4_denied_grace_period;
852 nlm4_test_reply (cs, stat, NULL((void*)0));
853 nfs3_call_state_wipe (cs);
854 return 0;
855 }
856
857 cs->vol = vol;
858 nlm4_volume_started_check (nfs3, vol, ret, rpcerr)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 858, GF_LOG_ERROR, "Volume is disabled: %s", vol->name);
} while (0); ret = (-2); goto rpcerr; } } while (0)
;
859
860 ret = nfs3_fh_resolve_and_resume (cs, &fh,
861 NULL((void*)0), nlm4_test_resume);
862
863nlm4err:
864 if (ret < 0) {
865 gf_log (GF_NLM, GF_LOG_ERROR, "unable to resolve and resume")do { do { if (0) printf ("unable to resolve and resume"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 865, GF_LOG_ERROR
, "unable to resolve and resume"); } while (0)
;
866 nlm4_test_reply (cs, stat, NULL((void*)0));
867 nfs3_call_state_wipe (cs);
868 return 0;
869 }
870
871rpcerr:
872 if (ret < 0)
873 nfs3_call_state_wipe (cs);
874
875 return ret;
876}
877
878int
879nlm4svc_send_granted_cbk (struct rpc_req *req, struct iovec *iov, int count,
880 void *myframe)
881{
882 STACK_DESTROY (((call_frame_t*)myframe)->root);
883 return 0;
884}
885
886void
887nlm4svc_send_granted (nfs3_call_state_t *cs);
888
889int
890nlm_rpcclnt_notify (struct rpc_clnt *rpc_clnt, void *mydata,
891 rpc_clnt_event_t fn, void *data)
892{
893 int ret = 0;
894 char *caller_name = NULL((void*)0);
895 nfs3_call_state_t *cs = NULL((void*)0);
896
897 cs = mydata;
898 caller_name = cs->args.nlm4_lockargs.alock.caller_name;
899
900 switch (fn) {
901 case RPC_CLNT_CONNECT:
902 ret = nlm_set_rpc_clnt (rpc_clnt, caller_name);
903 if (ret == -1) {
904 gf_log (GF_NLM, GF_LOG_ERROR, "Failed to set rpc clnt")do { do { if (0) printf ("Failed to set rpc clnt"); } while (
0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 904, GF_LOG_ERROR
, "Failed to set rpc clnt"); } while (0)
;
905 goto err;
906 }
907 rpc_clnt_unref (rpc_clnt);
908 nlm4svc_send_granted (cs);
909
910 break;
911
912 case RPC_CLNT_MSG:
913 break;
914
915 case RPC_CLNT_DISCONNECT:
916 nlm_unset_rpc_clnt (rpc_clnt);
917 break;
918 }
919
920 err:
921 return 0;
922}
923
924void *
925nlm4_establish_callback (void *csarg)
926{
927 int ret = -1;
928 nfs3_call_state_t *cs = NULL((void*)0);
929 union gf_sock_union sock_union;
930 dict_t *options = NULL((void*)0);
931 char peerip[INET6_ADDRSTRLEN46+1] = {0};
932 char *portstr = NULL((void*)0);
933 char myip[INET6_ADDRSTRLEN46+1] = {0};
934 rpc_clnt_t *rpc_clnt = NULL((void*)0);
935 int port = -1;
936
937
938 cs = (nfs3_call_state_t *) csarg;
939 glusterfs_this_set (cs->nfsx);
940
941 rpc_transport_get_peeraddr (cs->trans, NULL((void*)0), 0, &sock_union.storage,
942 sizeof (sock_union.storage));
943
944 switch (sock_union.sa.sa_family) {
945 case AF_INET610:
946 /* can not come here as NLM listens on IPv4 */
947 gf_log (GF_NLM, GF_LOG_ERROR, "NLM is not supported on IPv6 in"do { do { if (0) printf ("NLM is not supported on IPv6 in" " this release"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
948, GF_LOG_ERROR, "NLM is not supported on IPv6 in" " this release"
); } while (0)
948 " this release")do { do { if (0) printf ("NLM is not supported on IPv6 in" " this release"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
948, GF_LOG_ERROR, "NLM is not supported on IPv6 in" " this release"
); } while (0)
;
949 goto err;
950/*
951 inet_ntop (AF_INET6,
952 &((struct sockaddr_in6 *)sockaddr)->sin6_addr,
953 peerip, INET6_ADDRSTRLEN+1);
954 break;
955*/
956 case AF_INET2:
957 inet_ntop (AF_INET2, &sock_union.sin.sin_addr, peerip,
958 INET6_ADDRSTRLEN46+1);
959 inet_ntop (AF_INET2, &(((struct sockaddr_in *)&cs->req->trans->myinfo.sockaddr)->sin_addr),
960 myip, INET6_ADDRSTRLEN46 + 1);
961
962 break;
963 default:
964 break;
965 /* FIXME: handle the error */
966 }
967
968 /* looks like libc rpc supports only ipv4 */
969 port = pmap_getport (&sock_union.sin, NLM_PROGRAM100021,
970 NLM_V44, IPPROTO_TCPIPPROTO_TCP);
971
972 if (port == 0) {
973 gf_log (GF_NLM, GF_LOG_ERROR, "Unable to get NLM port of the "do { do { if (0) printf ("Unable to get NLM port of the " "client. Is the firewall running on client?"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
974, GF_LOG_ERROR, "Unable to get NLM port of the " "client. Is the firewall running on client?"
); } while (0)
974 "client. Is the firewall running on client?")do { do { if (0) printf ("Unable to get NLM port of the " "client. Is the firewall running on client?"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
974, GF_LOG_ERROR, "Unable to get NLM port of the " "client. Is the firewall running on client?"
); } while (0)
;
975 goto err;
976 }
977
978 options = dict_new();
979 ret = dict_set_str (options, "transport-type", "socket");
980 if (ret == -1) {
981 gf_log (GF_NLM, GF_LOG_ERROR, "dict_set_str error")do { do { if (0) printf ("dict_set_str error"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 981, GF_LOG_ERROR, "dict_set_str error"
); } while (0)
;
982 goto err;
983 }
984
985 ret = dict_set_dynstr (options, "remote-host", gf_strdup (peerip));
986 if (ret == -1) {
987 gf_log (GF_NLM, GF_LOG_ERROR, "dict_set_str error")do { do { if (0) printf ("dict_set_str error"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 987, GF_LOG_ERROR, "dict_set_str error"
); } while (0)
;
988 goto err;
989 }
990
991 ret = gf_asprintf (&portstr, "%d", port);
992 if (ret == -1)
993 goto err;
994
995 ret = dict_set_dynstr (options, "remote-port",
996 portstr);
997 if (ret == -1) {
998 gf_log (GF_NLM, GF_LOG_ERROR, "dict_set_dynstr error")do { do { if (0) printf ("dict_set_dynstr error"); } while (0
); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 998, GF_LOG_ERROR
, "dict_set_dynstr error"); } while (0)
;
999 goto err;
1000 }
1001
1002 /* needed in case virtual IP is used */
1003 ret = dict_set_dynstr (options, "transport.socket.source-addr",
1004 gf_strdup (myip));
1005 if (ret == -1)
1006 goto err;
1007
1008 ret = dict_set_str (options, "auth-null", "on");
1009 if (ret == -1) {
1010 gf_log (GF_NLM, GF_LOG_ERROR, "dict_set_dynstr error")do { do { if (0) printf ("dict_set_dynstr error"); } while (0
); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1010, GF_LOG_ERROR
, "dict_set_dynstr error"); } while (0)
;
1011 goto err;
1012 }
1013
1014 /* TODO: is 32 frames in transit enough ? */
1015 rpc_clnt = rpc_clnt_new (options, cs->nfsx->ctx, "NLM-client", 32);
1016 if (rpc_clnt == NULL((void*)0)) {
1017 gf_log (GF_NLM, GF_LOG_ERROR, "rpc_clnt NULL")do { do { if (0) printf ("rpc_clnt NULL"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 1017, GF_LOG_ERROR, "rpc_clnt NULL"
); } while (0)
;
1018 goto err;
1019 }
1020
1021 ret = rpc_clnt_register_notify (rpc_clnt, nlm_rpcclnt_notify, cs);
1022 if (ret == -1) {
1023 gf_log (GF_NLM, GF_LOG_ERROR,"rpc_clnt_register_connect error")do { do { if (0) printf ("rpc_clnt_register_connect error"); }
while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1023
, GF_LOG_ERROR,"rpc_clnt_register_connect error"); } while (0
)
;
1024 goto err;
1025 }
1026
1027 /* After this connect succeeds, granted msg is sent in notify */
1028 ret = rpc_transport_connect (rpc_clnt->conn.trans, port);
1029
1030 if (ret == -1 && EINPROGRESS115 == errno(*__errno_location ()))
1031 ret = 0;
1032
1033err:
1034 if (ret == -1 && rpc_clnt) {
1035 rpc_clnt_unref (rpc_clnt);
1036 }
1037
1038 return rpc_clnt;
1039}
1040
1041void
1042nlm4svc_send_granted (nfs3_call_state_t *cs)
1043{
1044 int ret = -1;
1045 rpc_clnt_t *rpc_clnt = NULL((void*)0);
1046 struct iovec outmsg = {0, };
1047 nlm4_testargs testargs;
1048 struct iobuf *iobuf = NULL((void*)0);
1049 struct iobref *iobref = NULL((void*)0);
1050 char peerip[INET6_ADDRSTRLEN46+1];
1051 union gf_sock_union sock_union;
1052
1053 rpc_clnt = nlm_get_rpc_clnt (cs->args.nlm4_lockargs.alock.caller_name);
1054 if (rpc_clnt == NULL((void*)0)) {
1055 nlm4_establish_callback ((void*)cs);
1056 return;
1057 }
1058
1059 rpc_transport_get_peeraddr (cs->trans, NULL((void*)0), 0, &sock_union.storage,
1060 sizeof (sock_union.storage));
1061
1062 switch (sock_union.sa.sa_family) {
1063 case AF_INET610:
1064 inet_ntop (AF_INET610, &sock_union.sin6.sin6_addr, peerip,
1065 INET6_ADDRSTRLEN46+1);
1066 break;
1067 case AF_INET2:
1068 inet_ntop (AF_INET2, &sock_union.sin.sin_addr, peerip,
1069 INET6_ADDRSTRLEN46+1);
1070 break;
1071 default:
1072 break;
1073 }
1074
1075 testargs.cookie = cs->args.nlm4_lockargs.cookie;
1076 testargs.exclusive = cs->args.nlm4_lockargs.exclusive;
1077 testargs.alock = cs->args.nlm4_lockargs.alock;
1078
1079 iobuf = iobuf_get (cs->nfs3state->iobpool);
1080 if (!iobuf) {
1081 gf_log (GF_NLM, GF_LOG_ERROR, "Failed to get iobuf")do { do { if (0) printf ("Failed to get iobuf"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1081, GF_LOG_ERROR
, "Failed to get iobuf"); } while (0)
;
1082 goto ret;
1083 }
1084
1085 iobuf_to_iovec (iobuf, &outmsg);
1086 /* Use the given serializer to translate the give C structure in arg
1087 * to XDR format which will be written into the buffer in outmsg.
1088 */
1089 outmsg.iov_len = xdr_serialize_nlm4_testargs (outmsg, &testargs);
1090
1091 iobref = iobref_new ();
1092 if (iobref == NULL((void*)0)) {
1093 gf_log (GF_NLM, GF_LOG_ERROR, "Failed to get iobref")do { do { if (0) printf ("Failed to get iobref"); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1093, GF_LOG_ERROR
, "Failed to get iobref"); } while (0)
;
1094 goto ret;
1095 }
1096
1097 iobref_add (iobref, iobuf);
1098
1099 ret = rpc_clnt_submit (rpc_clnt, &nlm4clntprog, NLM4_GRANTED5,
1100 nlm4svc_send_granted_cbk, &outmsg, 1,
1101 NULL((void*)0), 0, iobref, cs->frame, NULL((void*)0), 0,
1102 NULL((void*)0), 0, NULL((void*)0));
1103
1104 if (ret < 0) {
1105 gf_log (GF_NLM, GF_LOG_ERROR, "rpc_clnt_submit error")do { do { if (0) printf ("rpc_clnt_submit error"); } while (0
); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1105, GF_LOG_ERROR
, "rpc_clnt_submit error"); } while (0)
;
1106 goto ret;
1107 }
1108ret:
1109 if (iobref)
1110 iobref_unref (iobref);
1111 if (iobuf)
1112 iobuf_unref (iobuf);
1113
1114 rpc_clnt_unref (rpc_clnt);
1115 nfs3_call_state_wipe (cs);
1116 return;
1117}
1118
1119int
1120nlm_cleanup_fds (char *caller_name)
1121{
1122 int nlmclnt_found = 0;
1123 nlm_fde_t *fde = NULL((void*)0), *tmp = NULL((void*)0);
1124 nlm_client_t *nlmclnt = NULL((void*)0);
1125
1126 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
1127 list_for_each_entry (nlmclnt,for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
1128 &nlm_client_list, nlm_clients)for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
{
1129 if (!strcmp(caller_name, nlmclnt->caller_name)) {
1130 nlmclnt_found = 1;
1131 break;
1132 }
1133 }
1134
1135 if (!nlmclnt_found)
1136 goto ret;
1137
1138 if (list_empty (&nlmclnt->fdes))
1139 goto ret;
1140
1141 list_for_each_entry_safe (fde, tmp, &nlmclnt->fdes, fde_list)for (fde = ((typeof(*fde) *)((char *)((&nlmclnt->fdes)
->next)-(unsigned long)(&((typeof(*fde) *)0)->fde_list
))), tmp = ((typeof(*fde) *)((char *)(fde->fde_list.next)-
(unsigned long)(&((typeof(*fde) *)0)->fde_list))); &
fde->fde_list != (&nlmclnt->fdes); fde = tmp, tmp =
((typeof(*tmp) *)((char *)(tmp->fde_list.next)-(unsigned long
)(&((typeof(*tmp) *)0)->fde_list))))
{
1142 fd_unref (fde->fd);
1143 list_del (&fde->fde_list);
1144 GF_FREE (fde)__gf_free (fde);
1145 }
1146
1147ret:
1148 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
1149 return 0;
1150}
1151
1152void
1153nlm_search_and_delete (fd_t *fd, char *caller_name)
1154{
1155 nlm_fde_t *fde = NULL((void*)0);
1156 nlm_client_t *nlmclnt = NULL((void*)0);
1157 int nlmclnt_found = 0;
1158 int fde_found = 0;
1159 int transit_cnt = 0;
1160
1161 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
1162 list_for_each_entry (nlmclnt,for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
1163 &nlm_client_list, nlm_clients)for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
{
1164 if (!strcmp(caller_name, nlmclnt->caller_name)) {
1165 nlmclnt_found = 1;
1166 break;
1167 }
1168 }
1169
1170 if (!nlmclnt_found)
1171 goto ret;
1172
1173 list_for_each_entry (fde, &nlmclnt->fdes, fde_list)for (fde = ((typeof(*fde) *)((char *)((&nlmclnt->fdes)
->next)-(unsigned long)(&((typeof(*fde) *)0)->fde_list
))); &fde->fde_list != (&nlmclnt->fdes); fde = (
(typeof(*fde) *)((char *)(fde->fde_list.next)-(unsigned long
)(&((typeof(*fde) *)0)->fde_list))))
{
1174 if (fde->fd == fd) {
1175 fde_found = 1;
1176 break;
1177 }
1178 }
1179
1180 if (!fde_found)
1181 goto ret;
1182 transit_cnt = fde->transit_cnt;
1183 if (transit_cnt)
1184 goto ret;
1185 list_del (&fde->fde_list);
1186
1187ret:
1188 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
1189
1190 if (fde_found && !transit_cnt) {
1191 fd_unref (fde->fd);
1192 GF_FREE (fde)__gf_free (fde);
1193 }
1194 return;
1195}
1196
1197int
1198nlm_dec_transit_count (fd_t *fd, char *caller_name)
1199{
1200 nlm_fde_t *fde = NULL((void*)0);
1201 nlm_client_t *nlmclnt = NULL((void*)0);
1202 int nlmclnt_found = 0;
1203 int fde_found = 0;
1204 int transit_cnt = -1;
1205
1206 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
1207 list_for_each_entry (nlmclnt,for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
1208 &nlm_client_list, nlm_clients)for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
{
1209 if (!strcmp(caller_name, nlmclnt->caller_name)) {
1210 nlmclnt_found = 1;
1211 break;
1212 }
1213 }
1214
1215 if (!nlmclnt_found) {
1216 gf_log (GF_NLM, GF_LOG_ERROR, "nlmclnt not found")do { do { if (0) printf ("nlmclnt not found"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 1216, GF_LOG_ERROR, "nlmclnt not found"
); } while (0)
;
1217 nlmclnt = NULL((void*)0);
1218 goto ret;
1219 }
1220
1221 list_for_each_entry (fde, &nlmclnt->fdes, fde_list)for (fde = ((typeof(*fde) *)((char *)((&nlmclnt->fdes)
->next)-(unsigned long)(&((typeof(*fde) *)0)->fde_list
))); &fde->fde_list != (&nlmclnt->fdes); fde = (
(typeof(*fde) *)((char *)(fde->fde_list.next)-(unsigned long
)(&((typeof(*fde) *)0)->fde_list))))
{
1222 if (fde->fd == fd) {
1223 fde_found = 1;
1224 break;
1225 }
1226 }
1227
1228 if (fde_found) {
1229 transit_cnt = --fde->transit_cnt;
1230 goto ret;
1231 }
1232ret:
1233
1234 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
1235 return transit_cnt;
1236}
1237
1238
1239nlm_client_t *
1240nlm_search_and_add (fd_t *fd, char *caller_name)
1241{
1242 nlm_fde_t *fde = NULL((void*)0);
1243 nlm_client_t *nlmclnt = NULL((void*)0);
1244 int nlmclnt_found = 0;
1245 int fde_found = 0;
1246
1247 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
1248 list_for_each_entry (nlmclnt,for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
1249 &nlm_client_list, nlm_clients)for (nlmclnt = ((typeof(*nlmclnt) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->
nlm_clients))); &nlmclnt->nlm_clients != (&nlm_client_list
); nlmclnt = ((typeof(*nlmclnt) *)((char *)(nlmclnt->nlm_clients
.next)-(unsigned long)(&((typeof(*nlmclnt) *)0)->nlm_clients
))))
{
1250 if (!strcmp(caller_name, nlmclnt->caller_name)) {
1251 nlmclnt_found = 1;
1252 break;
1253 }
1254 }
1255
1256 if (!nlmclnt_found) {
1257 gf_log (GF_NLM, GF_LOG_ERROR, "nlmclnt not found")do { do { if (0) printf ("nlmclnt not found"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 1257, GF_LOG_ERROR, "nlmclnt not found"
); } while (0)
;
1258 nlmclnt = NULL((void*)0);
1259 goto ret;
1260 }
1261
1262 list_for_each_entry (fde, &nlmclnt->fdes, fde_list)for (fde = ((typeof(*fde) *)((char *)((&nlmclnt->fdes)
->next)-(unsigned long)(&((typeof(*fde) *)0)->fde_list
))); &fde->fde_list != (&nlmclnt->fdes); fde = (
(typeof(*fde) *)((char *)(fde->fde_list.next)-(unsigned long
)(&((typeof(*fde) *)0)->fde_list))))
{
1263 if (fde->fd == fd) {
1264 fde_found = 1;
1265 break;
1266 }
1267 }
1268
1269 if (fde_found)
1270 goto ret;
1271
1272 fde = GF_CALLOC (1, sizeof (*fde), gf_nfs_mt_nlm4_fde)__gf_calloc (1, sizeof (*fde), gf_nfs_mt_nlm4_fde);
1273
1274 fde->fd = fd_ref (fd);
1275 list_add (&fde->fde_list, &nlmclnt->fdes);
1276ret:
1277 if (nlmclnt_found && fde)
1278 fde->transit_cnt++;
1279 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
1280 return nlmclnt;
1281}
1282
1283int
1284nlm4svc_lock_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1285 int32_t op_ret, int32_t op_errno, struct gf_flock *flock,
1286 dict_t *xdata)
1287{
1288 nlm4_stats stat = nlm4_denied;
1289 int transit_cnt = -1;
1290 char *caller_name = NULL((void*)0);
1291 nfs3_call_state_t *cs = NULL((void*)0);
1292 pthread_t thr;
1293
1294 cs = frame->local;
1295 caller_name = cs->args.nlm4_lockargs.alock.caller_name;
1296 transit_cnt = nlm_dec_transit_count (cs->fd, caller_name);
1297
1298 if (op_ret == -1) {
1299 if (transit_cnt == 0)
1300 nlm_search_and_delete (cs->fd, caller_name);
1301 stat = nlm4_errno_to_nlm4stat (op_errno);
1302 goto err;
1303 } else {
1304 stat = nlm4_granted;
1305 if (cs->monitor && !nlm_monitor (caller_name)) {
1306 /* FIXME: handle nsm_monitor failure */
1307 pthread_create (&thr, NULL((void*)0), nsm_monitor, (void*)caller_name);
1308 }
1309 }
1310
1311err:
1312 if (cs->args.nlm4_lockargs.block) {
1313 cs->frame = copy_frame (frame);
1314 frame->local = NULL((void*)0);
1315 nlm4svc_send_granted (cs);
1316 } else {
1317 nlm4_generic_reply (cs->req, cs->args.nlm4_lockargs.cookie,
1318 stat);
1319 nfs3_call_state_wipe (cs);
1320 }
1321 return 0;
1322}
1323
1324int
1325nlm4_lock_fd_resume (void *carg)
1326{
1327 nlm4_stats stat = nlm4_denied;
1328 int ret = -EFAULT14;
1329 nfs_user_t nfu = {0, };
1330 nfs3_call_state_t *cs = NULL((void*)0);
1331 struct gf_flock flock = {0, };
1332
1333 if (!carg)
1334 return ret;
1335
1336 cs = (nfs3_call_state_t *)carg;
1337 nlm4_check_fh_resolve_status (cs, stat, nlm4err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1337, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nlm4_errno_to_nlm4stat (cs->resolve_errno); goto
nlm4err; } } while (0)
;
1338 (void) nlm_search_and_add (cs->fd,
1339 cs->args.nlm4_lockargs.alock.caller_name);
1340 nfs_request_user_init (&nfu, cs->req);
1341 nlm4_lock_to_gf_flock (&flock, &cs->args.nlm4_lockargs.alock,
1342 cs->args.nlm4_lockargs.exclusive);
1343 nlm_copy_lkowner (&nfu.lk_owner, &cs->args.nlm4_lockargs.alock.oh);
1344 if (cs->args.nlm4_lockargs.block) {
1345 nlm4_generic_reply (cs->req, cs->args.nlm4_lockargs.cookie,
1346 nlm4_blocked);
1347 ret = nfs_lk (cs->nfsx, cs->vol, &nfu, cs->fd, F_SETLKW14,
1348 &flock, nlm4svc_lock_cbk, cs);
1349 /* FIXME: handle error from nfs_lk() specially by just
1350 * cleaning up cs and unblock the client lock request.
1351 */
1352 ret = 0;
1353 } else
1354 ret = nfs_lk (cs->nfsx, cs->vol, &nfu, cs->fd, F_SETLK13,
1355 &flock, nlm4svc_lock_cbk, cs);
1356
1357nlm4err:
1358 if (ret < 0) {
1359 stat = nlm4_errno_to_nlm4stat (-ret);
1360 gf_log (GF_NLM, GF_LOG_ERROR, "unable to call lk()")do { do { if (0) printf ("unable to call lk()"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1360, GF_LOG_ERROR
, "unable to call lk()"); } while (0)
;
1361 nlm4_generic_reply (cs->req, cs->args.nlm4_lockargs.cookie,
1362 stat);
1363 nfs3_call_state_wipe (cs);
1364 }
1365
1366 return ret;
1367}
1368
1369
1370int
1371nlm4_lock_resume (void *carg)
1372{
1373 nlm4_stats stat = nlm4_failed;
1374 int ret = -1;
1375 nfs3_call_state_t *cs = NULL((void*)0);
1376
1377 if (!carg)
1378 return ret;
1379
1380 cs = (nfs3_call_state_t *)carg;
1381 nlm4_check_fh_resolve_status (cs, stat, nlm4err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1381, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nlm4_errno_to_nlm4stat (cs->resolve_errno); goto
nlm4err; } } while (0)
;
1382 ret = nlm4_file_open_and_resume (cs, nlm4_lock_fd_resume);
1383
1384nlm4err:
1385 if (ret < 0) {
1386 gf_log (GF_NLM, GF_LOG_ERROR, "unable to open and resume")do { do { if (0) printf ("unable to open and resume"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1386, GF_LOG_ERROR
, "unable to open and resume"); } while (0)
;
1387 stat = nlm4_errno_to_nlm4stat (-ret);
1388 nlm4_generic_reply (cs->req, cs->args.nlm4_lockargs.cookie,
1389 stat);
1390 nfs3_call_state_wipe (cs);
1391 }
1392
1393 return ret;
1394}
1395
1396int
1397nlm4svc_lock_common (rpcsvc_request_t *req, int mon)
1398{
1399 int ret = RPCSVC_ACTOR_ERROR(-1);
1400 nlm4_stats stat = nlm4_failed;
1401 struct nfs3_fh fh = {{0}, };
1402 xlator_t *vol = NULL((void*)0);
1403 nfs3_state_t *nfs3 = NULL((void*)0);
1404 nfs3_call_state_t *cs = NULL((void*)0);
1405 struct nfs_state *nfs = NULL((void*)0);
1406
1407 if (!req)
1408 return ret;
1409
1410 nlm4_validate_nfs3_state (req, nfs3, stat, rpcerr, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1410, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); (req)->rpc_err = SYSTEM_ERR; stat = nlm4_failed
; goto rpcerr; } } while (0);
;
1411 nfs = nfs_state (nfs3->nfsx)(nfs3->nfsx)->private;
1412 nlm4_handle_call_state_init (nfs->nfs3state, cs, req,do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1413, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
rpcerr; } } while (0)
1413 stat, rpcerr)do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1413, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
rpcerr; } } while (0)
;
1414
1415 nlm4_prep_nlm4_lockargs (&cs->args.nlm4_lockargs, &cs->lockfh,
1416 &cs->lkowner, cs->cookiebytes);
1417 if (xdr_to_nlm4_lockargs(req->msg[0], &cs->args.nlm4_lockargs) <= 0) {
1418 gf_log (GF_NLM, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1418, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
1419 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
1420 goto rpcerr;
1421 }
1422
1423 fh = cs->lockfh;
1424 cs->monitor = mon;
1425 nlm4_validate_gluster_fh (&fh, stat, nlm4err)do { if (!nfs3_fh_validate (&fh)) { stat = nlm4_stale_fh;
goto nlm4err; } } while (0)
;
1426 nlm4_map_fh_to_volume (cs->nfs3state, fh, req, vol, stat, nlm4err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((cs->nfs3state), &
fh); if (!vol) { uuid_unparse (fh.exportid, exportid); uuid_unparse
(fh.gfid, gfid); trans = ((req)->trans); do { do { if (0)
printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1426, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 1426, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = nlm4_stale_fh; goto
nlm4err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c",
__FUNCTION__, 1426, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
1427
1428 if (nlm_grace_period && !cs->args.nlm4_lockargs.reclaim) {
1429 gf_log (GF_NLM, GF_LOG_WARNING, "NLM in grace period")do { do { if (0) printf ("NLM in grace period"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1429, GF_LOG_WARNING
, "NLM in grace period"); } while (0)
;
1430 stat = nlm4_denied_grace_period;
1431 nlm4_generic_reply (req, cs->args.nlm4_unlockargs.cookie, stat);
1432 nfs3_call_state_wipe (cs);
1433 return 0;
1434 }
1435
1436 cs->vol = vol;
1437 cs->trans = rpcsvc_request_transport_ref(req)(rpc_transport_ref((req)->trans));
1438 nlm4_volume_started_check (nfs3, vol, ret, rpcerr)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 1438, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto rpcerr; } } while (0)
;
1439
1440 ret = nlm_add_nlmclnt (cs->args.nlm4_lockargs.alock.caller_name);
1441
1442 ret = nfs3_fh_resolve_and_resume (cs, &fh,
1443 NULL((void*)0), nlm4_lock_resume);
1444
1445nlm4err:
1446 if (ret < 0) {
1447 gf_log (GF_NLM, GF_LOG_ERROR, "unable to resolve and resume")do { do { if (0) printf ("unable to resolve and resume"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1447, GF_LOG_ERROR
, "unable to resolve and resume"); } while (0)
;
1448 nlm4_generic_reply (cs->req, cs->args.nlm4_lockargs.cookie,
1449 stat);
1450 nfs3_call_state_wipe (cs);
1451 return 0;
1452 }
1453
1454rpcerr:
1455 if (ret < 0) {
1456 nfs3_call_state_wipe (cs);
1457 }
1458
1459 return ret;
1460}
1461
1462int
1463nlm4svc_lock (rpcsvc_request_t *req)
1464{
1465 return nlm4svc_lock_common (req, 1);
1466}
1467
1468int
1469nlm4svc_nm_lock (rpcsvc_request_t *req)
1470{
1471 return nlm4svc_lock_common (req, 0);
1472}
1473
1474int
1475nlm4svc_cancel_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1476 int32_t op_ret, int32_t op_errno, struct gf_flock *flock,
1477 dict_t *xdata)
1478{
1479 nlm4_stats stat = nlm4_denied;
1480 nfs3_call_state_t *cs = NULL((void*)0);
1481
1482 cs = frame->local;
1483 if (op_ret == -1) {
1484 stat = nlm4_errno_to_nlm4stat (op_errno);
1485 goto err;
1486 } else
1487 stat = nlm4_granted;
1488
1489err:
1490 nlm4_generic_reply (cs->req, cs->args.nlm4_cancargs.cookie,
1491 stat);
1492 nfs3_call_state_wipe (cs);
1493 return 0;
1494}
1495
1496int
1497nlm4_cancel_fd_resume (void *carg)
1498{
1499 int ret = -EFAULT14;
1500 nfs_user_t nfu = {0, };
1501 nfs3_call_state_t *cs = NULL((void*)0);
1502 struct gf_flock flock = {0, };
1503
1504 if (!carg)
1505 return ret;
1506
1507 cs = (nfs3_call_state_t *)carg;
1508 nfs_request_user_init (&nfu, cs->req);
1509 nlm4_lock_to_gf_flock (&flock, &cs->args.nlm4_cancargs.alock,
1510 cs->args.nlm4_cancargs.exclusive);
1511 nlm_copy_lkowner (&nfu.lk_owner, &cs->args.nlm4_cancargs.alock.oh);
1512 flock.l_type = F_UNLCK2;
1513 ret = nfs_lk (cs->nfsx, cs->vol, &nfu, cs->fd, F_SETLK13,
1514 &flock, nlm4svc_cancel_cbk, cs);
1515
1516 return ret;
1517}
1518
1519int
1520nlm4_cancel_resume (void *carg)
1521{
1522 nlm4_stats stat = nlm4_failed;
1523 int ret = -EFAULT14;
1524 nfs3_call_state_t *cs = NULL((void*)0);
1525 nlm_client_t *nlmclnt = NULL((void*)0);
1526
1527 if (!carg)
1528 return ret;
1529
1530 cs = (nfs3_call_state_t *)carg;
1531 nlm4_check_fh_resolve_status (cs, stat, nlm4err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1531, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nlm4_errno_to_nlm4stat (cs->resolve_errno); goto
nlm4err; } } while (0)
;
1532
1533 nlmclnt = nlm_get_uniq (cs->args.nlm4_cancargs.alock.caller_name);
1534 if (nlmclnt == NULL((void*)0)) {
1535 gf_log (GF_NLM, GF_LOG_ERROR, "nlm_get_uniq() returned NULL")do { do { if (0) printf ("nlm_get_uniq() returned NULL"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1535, GF_LOG_ERROR
, "nlm_get_uniq() returned NULL"); } while (0)
;
1536 goto nlm4err;
1537 }
1538 cs->fd = fd_lookup_uint64 (cs->resolvedloc.inode, (uint64_t)nlmclnt);
1539 if (cs->fd == NULL((void*)0)) {
1540 gf_log (GF_NLM, GF_LOG_ERROR, "fd_lookup_uint64 retrned NULL")do { do { if (0) printf ("fd_lookup_uint64 retrned NULL"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1540, GF_LOG_ERROR
, "fd_lookup_uint64 retrned NULL"); } while (0)
;
1541 goto nlm4err;
1542 }
1543 ret = nlm4_cancel_fd_resume (cs);
1544
1545nlm4err:
1546 if (ret < 0) {
1547 gf_log (GF_NLM, GF_LOG_WARNING, "unable to unlock_fd_resume()")do { do { if (0) printf ("unable to unlock_fd_resume()"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1547, GF_LOG_WARNING
, "unable to unlock_fd_resume()"); } while (0)
;
1548 stat = nlm4_errno_to_nlm4stat (-ret);
1549 nlm4_generic_reply (cs->req, cs->args.nlm4_cancargs.cookie,
1550 stat);
1551
1552 nfs3_call_state_wipe (cs);
1553 }
1554 /* clean up is taken care of */
1555 return 0;
1556}
1557
1558int
1559nlm4svc_cancel (rpcsvc_request_t *req)
1560{
1561 xlator_t *vol = NULL((void*)0);
1562 nlm4_stats stat = nlm4_failed;
1563 struct nfs_state *nfs = NULL((void*)0);
1564 nfs3_state_t *nfs3 = NULL((void*)0);
1565 nfs3_call_state_t *cs = NULL((void*)0);
1566 int ret = RPCSVC_ACTOR_ERROR(-1);
1567 struct nfs3_fh fh = {{0}, };
1568
1569 if (!req)
1570 return ret;
1571
1572 nlm4_validate_nfs3_state (req, nfs3, stat, rpcerr, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1572, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); (req)->rpc_err = SYSTEM_ERR; stat = nlm4_failed
; goto rpcerr; } } while (0);
;
1573 nfs = nfs_state (nfs3->nfsx)(nfs3->nfsx)->private;
1574 nlm4_handle_call_state_init (nfs->nfs3state, cs, req,do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1575, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
rpcerr; } } while (0)
1575 stat, rpcerr)do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1575, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
rpcerr; } } while (0)
;
1576
1577 nlm4_prep_nlm4_cancargs (&cs->args.nlm4_cancargs, &fh, &cs->lkowner,
1578 cs->cookiebytes);
1579 if (xdr_to_nlm4_cancelargs(req->msg[0], &cs->args.nlm4_cancargs) <= 0) {
1580 gf_log (GF_NLM, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1580, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
1581 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
1582 goto rpcerr;
1583 }
1584
1585 nlm4_validate_gluster_fh (&fh, stat, nlm4err)do { if (!nfs3_fh_validate (&fh)) { stat = nlm4_stale_fh;
goto nlm4err; } } while (0)
;
1586 nlm4_map_fh_to_volume (cs->nfs3state, fh, req, vol, stat, nlm4err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((cs->nfs3state), &
fh); if (!vol) { uuid_unparse (fh.exportid, exportid); uuid_unparse
(fh.gfid, gfid); trans = ((req)->trans); do { do { if (0)
printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1586, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 1586, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = nlm4_stale_fh; goto
nlm4err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c",
__FUNCTION__, 1586, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
1587
1588 if (nlm_grace_period) {
1589 gf_log (GF_NLM, GF_LOG_WARNING, "NLM in grace period")do { do { if (0) printf ("NLM in grace period"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1589, GF_LOG_WARNING
, "NLM in grace period"); } while (0)
;
1590 stat = nlm4_denied_grace_period;
1591 nlm4_generic_reply (req, cs->args.nlm4_unlockargs.cookie, stat);
1592 nfs3_call_state_wipe (cs);
1593 return 0;
1594 }
1595
1596 cs->vol = vol;
1597 nlm4_volume_started_check (nfs3, vol, ret, rpcerr)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 1597, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto rpcerr; } } while (0)
;
1598
1599 ret = nfs3_fh_resolve_and_resume (cs, &fh,
1600 NULL((void*)0), nlm4_cancel_resume);
1601
1602nlm4err:
1603 if (ret < 0) {
1604 gf_log (GF_NLM, GF_LOG_ERROR, "unable to resolve and resume")do { do { if (0) printf ("unable to resolve and resume"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1604, GF_LOG_ERROR
, "unable to resolve and resume"); } while (0)
;
1605 nlm4_generic_reply (cs->req, cs->args.nlm4_cancargs.cookie,
1606 stat);
1607 nfs3_call_state_wipe (cs);
1608 return 0;
1609 }
1610
1611rpcerr:
1612 if (ret < 0) {
1613 nfs3_call_state_wipe (cs);
1614 }
1615 return ret;
1616}
1617
1618int
1619nlm4svc_unlock_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1620 int32_t op_ret, int32_t op_errno, struct gf_flock *flock,
1621 dict_t *xdata)
1622{
1623 nlm4_stats stat = nlm4_denied;
1624 nfs3_call_state_t *cs = NULL((void*)0);
1625
1626 cs = frame->local;
1627 if (op_ret == -1) {
1628 stat = nlm4_errno_to_nlm4stat (op_errno);
1629 goto err;
1630 } else {
1631 stat = nlm4_granted;
1632 if (flock->l_type == F_UNLCK2)
1633 nlm_search_and_delete (cs->fd,
1634 cs->args.nlm4_unlockargs.alock.caller_name);
1635 }
1636
1637err:
1638 nlm4_generic_reply (cs->req, cs->args.nlm4_unlockargs.cookie, stat);
1639 nfs3_call_state_wipe (cs);
1640 return 0;
1641}
1642
1643int
1644nlm4_unlock_fd_resume (void *carg)
1645{
1646 int ret = -EFAULT14;
1647 nfs_user_t nfu = {0, };
1648 nfs3_call_state_t *cs = NULL((void*)0);
1649 struct gf_flock flock = {0, };
1650
1651 if (!carg)
1652 return ret;
1653 cs = (nfs3_call_state_t *)carg;
1654 nfs_request_user_init (&nfu, cs->req);
1655 nlm4_lock_to_gf_flock (&flock, &cs->args.nlm4_unlockargs.alock, 0);
1656 nlm_copy_lkowner (&nfu.lk_owner, &cs->args.nlm4_unlockargs.alock.oh);
1657 flock.l_type = F_UNLCK2;
1658 ret = nfs_lk (cs->nfsx, cs->vol, &nfu, cs->fd, F_SETLK13,
1659 &flock, nlm4svc_unlock_cbk, cs);
1660
1661 return ret;
1662}
1663
1664int
1665nlm4_unlock_resume (void *carg)
1666{
1667 nlm4_stats stat = nlm4_failed;
1668 int ret = -1;
1669 nfs3_call_state_t *cs = NULL((void*)0);
1670 nlm_client_t *nlmclnt = NULL((void*)0);
1671
1672 if (!carg)
1673 return ret;
1674
1675 cs = (nfs3_call_state_t *)carg;
1676 nlm4_check_fh_resolve_status (cs, stat, nlm4err)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1676, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nlm4_errno_to_nlm4stat (cs->resolve_errno); goto
nlm4err; } } while (0)
;
1677
1678 nlmclnt = nlm_get_uniq (cs->args.nlm4_unlockargs.alock.caller_name);
1679 if (nlmclnt == NULL((void*)0)) {
1680 stat = nlm4_granted;
1681 gf_log (GF_NLM, GF_LOG_WARNING, "nlm_get_uniq() returned NULL")do { do { if (0) printf ("nlm_get_uniq() returned NULL"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1681, GF_LOG_WARNING
, "nlm_get_uniq() returned NULL"); } while (0)
;
1682 goto nlm4err;
1683 }
1684 cs->fd = fd_lookup_uint64 (cs->resolvedloc.inode, (uint64_t)nlmclnt);
1685 if (cs->fd == NULL((void*)0)) {
1686 stat = nlm4_granted;
1687 gf_log (GF_NLM, GF_LOG_WARNING, "fd_lookup_uint64() returned "do { do { if (0) printf ("fd_lookup_uint64() returned " "NULL"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1688, GF_LOG_WARNING, "fd_lookup_uint64() returned " "NULL")
; } while (0)
1688 "NULL")do { do { if (0) printf ("fd_lookup_uint64() returned " "NULL"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1688, GF_LOG_WARNING, "fd_lookup_uint64() returned " "NULL")
; } while (0)
;
1689 goto nlm4err;
1690 }
1691 ret = nlm4_unlock_fd_resume (cs);
1692
1693nlm4err:
1694 if (ret < 0) {
1695 gf_log (GF_NLM, GF_LOG_WARNING, "unable to unlock_fd_resume")do { do { if (0) printf ("unable to unlock_fd_resume"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1695, GF_LOG_WARNING
, "unable to unlock_fd_resume"); } while (0)
;
1696 stat = nlm4_errno_to_nlm4stat (-ret);
1697 nlm4_generic_reply (cs->req, cs->args.nlm4_unlockargs.cookie,
1698 stat);
1699
1700 nfs3_call_state_wipe (cs);
1701 }
1702 /* we have already taken care of cleanup */
1703 return 0;
1704}
1705
1706int
1707nlm4svc_unlock (rpcsvc_request_t *req)
1708{
1709 xlator_t *vol = NULL((void*)0);
1710 nlm4_stats stat = nlm4_failed;
1711 struct nfs_state *nfs = NULL((void*)0);
1712 nfs3_state_t *nfs3 = NULL((void*)0);
1713 nfs3_call_state_t *cs = NULL((void*)0);
1714 int ret = RPCSVC_ACTOR_ERROR(-1);
1715 struct nfs3_fh fh = {{0}, };
1716
1717 if (!req)
1718 return ret;
1719
1720 nlm4_validate_nfs3_state (req, nfs3, stat, rpcerr, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1720, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); (req)->rpc_err = SYSTEM_ERR; stat = nlm4_failed
; goto rpcerr; } } while (0);
;
1721 nfs = nfs_state (nfs3->nfsx)(nfs3->nfsx)->private;
1722 nlm4_handle_call_state_init (nfs->nfs3state, cs, req,do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1723, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
rpcerr; } } while (0)
1723 stat, rpcerr)do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1723, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
rpcerr; } } while (0)
;
1724
1725 nlm4_prep_nlm4_unlockargs (&cs->args.nlm4_unlockargs, &fh, &cs->lkowner,
1726 cs->cookiebytes);
1727 if (xdr_to_nlm4_unlockargs(req->msg[0], &cs->args.nlm4_unlockargs) <= 0)
1728 {
1729 gf_log (GF_NLM, GF_LOG_ERROR, "Error decoding args")do { do { if (0) printf ("Error decoding args"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1729, GF_LOG_ERROR
, "Error decoding args"); } while (0)
;
1730 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
1731 goto rpcerr;
1732 }
1733
1734 nlm4_validate_gluster_fh (&fh, stat, nlm4err)do { if (!nfs3_fh_validate (&fh)) { stat = nlm4_stale_fh;
goto nlm4err; } } while (0)
;
1735 nlm4_map_fh_to_volume (cs->nfs3state, fh, req, vol, stat, nlm4err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((cs->nfs3state), &
fh); if (!vol) { uuid_unparse (fh.exportid, exportid); uuid_unparse
(fh.gfid, gfid); trans = ((req)->trans); do { do { if (0)
printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1735, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 1735, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = nlm4_stale_fh; goto
nlm4err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c",
__FUNCTION__, 1735, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
1736
1737 if (nlm_grace_period) {
1738 gf_log (GF_NLM, GF_LOG_WARNING, "NLM in grace period")do { do { if (0) printf ("NLM in grace period"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1738, GF_LOG_WARNING
, "NLM in grace period"); } while (0)
;
1739 stat = nlm4_denied_grace_period;
1740 nlm4_generic_reply (req, cs->args.nlm4_unlockargs.cookie, stat);
1741 nfs3_call_state_wipe (cs);
1742 return 0;
1743 }
1744
1745 cs->vol = vol;
1746 /* FIXME: check if trans is being used at all for unlock */
1747 cs->trans = rpcsvc_request_transport_ref(req)(rpc_transport_ref((req)->trans));
1748 nlm4_volume_started_check (nfs3, vol, ret, rpcerr)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 1748, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto rpcerr; } } while (0)
;
1749
1750 ret = nfs3_fh_resolve_and_resume (cs, &fh,
1751 NULL((void*)0), nlm4_unlock_resume);
1752
1753nlm4err:
1754 if (ret < 0) {
1755 gf_log (GF_NLM, GF_LOG_ERROR, "unable to resolve and resume")do { do { if (0) printf ("unable to resolve and resume"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 1755, GF_LOG_ERROR
, "unable to resolve and resume"); } while (0)
;
1756 nlm4_generic_reply (req, cs->args.nlm4_unlockargs.cookie, stat);
1757 nfs3_call_state_wipe (cs);
1758 return 0;
1759 }
1760
1761rpcerr:
1762 if (ret < 0) {
1763 nfs3_call_state_wipe (cs);
1764 }
1765 return ret;
1766}
1767
1768int
1769nlm4_share_reply (nfs3_call_state_t *cs, nlm4_stats stat)
1770{
1771 nlm4_shareres res = {{0}, 0, 0};
1772
1773 if (!cs)
1774 return -1;
1775
1776 res.cookie = cs->args.nlm4_shareargs.cookie;
1777 res.stat = stat;
1778 res.sequence = 0;
1779
1780 nlm4svc_submit_reply (cs->req, (void *)&res,
1781 (nlm4_serializer)xdr_serialize_nlm4_shareres);
1782 return 0;
1783}
1784
1785nlm_share_t *
1786nlm4_share_new ()
1787{
1788 nlm_share_t *share = NULL((void*)0);
1789
1790 share = GF_CALLOC (1, sizeof (nlm_share_t),__gf_calloc (1, sizeof (nlm_share_t), gf_nfs_mt_nlm4_share)
1791 gf_nfs_mt_nlm4_share)__gf_calloc (1, sizeof (nlm_share_t), gf_nfs_mt_nlm4_share);
1792 if (!share)
1793 goto out;
1794
1795 INIT_LIST_HEAD (&share->client_list)do { (&share->client_list)->next = (&share->
client_list)->prev = &share->client_list; } while (
0)
;
1796 INIT_LIST_HEAD (&share->inode_list)do { (&share->inode_list)->next = (&share->inode_list
)->prev = &share->inode_list; } while (0)
;
1797 out:
1798 return share;
1799}
1800
1801int
1802nlm4_add_share_to_inode (nlm_share_t *share)
1803{
1804 int ret = -1;
1805 uint64_t ctx = 0;
1806 struct list_head *head = NULL((void*)0);
1807 xlator_t *this = NULL((void*)0);
1808 inode_t *inode = NULL((void*)0);
1809 struct nfs_inode_ctx *ictx = NULL((void*)0);
1810 struct nfs_state *priv = NULL((void*)0);
1811
1812 this = THIS(*__glusterfs_this_location());
1813 priv = this->private;
1814 inode = share->inode;
1815 ret = inode_ctx_get (inode, this, &ctx)inode_ctx_get2(inode,this,&ctx,0);
1816
1817 if (ret || !head) {
1818 ictx = GF_CALLOC (1, sizeof (struct nfs_inode_ctx),__gf_calloc (1, sizeof (struct nfs_inode_ctx), gf_nfs_mt_inode_ctx
)
1819 gf_nfs_mt_inode_ctx)__gf_calloc (1, sizeof (struct nfs_inode_ctx), gf_nfs_mt_inode_ctx
)
;
1820 if (!ictx ) {
1821 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("could not allocate nfs inode ctx");
} while (0); _gf_log (this->name, "nlm4.c", __FUNCTION__,
1822, GF_LOG_ERROR, "could not allocate nfs inode ctx"); } while
(0)
1822 "could not allocate nfs inode ctx")do { do { if (0) printf ("could not allocate nfs inode ctx");
} while (0); _gf_log (this->name, "nlm4.c", __FUNCTION__,
1822, GF_LOG_ERROR, "could not allocate nfs inode ctx"); } while
(0)
;
1823 ret = -1;
1824 goto out;
1825 }
1826 ictx->generation = priv->generation;
1827
1828 head = &ictx->shares;
1829 INIT_LIST_HEAD (head)do { (head)->next = (head)->prev = head; } while (0);
1830
1831 ret = inode_ctx_put (inode, this, (uint64_t)ictx);
1832 if (ret) {
1833 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("could not store share list"); } while
(0); _gf_log (this->name, "nlm4.c", __FUNCTION__, 1834, GF_LOG_ERROR
, "could not store share list"); } while (0)
1834 "could not store share list")do { do { if (0) printf ("could not store share list"); } while
(0); _gf_log (this->name, "nlm4.c", __FUNCTION__, 1834, GF_LOG_ERROR
, "could not store share list"); } while (0)
;
1835 goto out;
1836 }
1837 }
1838 else {
1839 ictx = (struct nfs_inode_ctx *)ctx;
1840 head = &ictx->shares;
1841 }
1842
1843 list_add (&share->inode_list, head);
1844
1845 out:
1846 if (ret && head)
1847 GF_FREE (head)__gf_free (head);
1848
1849 return ret;
1850}
1851
1852int
1853nlm4_approve_share_reservation (nfs3_call_state_t *cs)
1854{
1855 int ret = -1;
1856 uint64_t ctx = 0;
1857 fsh_mode req_mode = 0;
1858 fsh_access req_access = 0;
1859 inode_t *inode = NULL((void*)0);
1860 nlm_share_t *share = NULL((void*)0);
1861 struct list_head *head = NULL((void*)0);
1862 struct nfs_inode_ctx *ictx = NULL((void*)0);
1863
1864 if (!cs)
1865 goto out;
1866
1867 inode = cs->resolvedloc.inode;
1868
1869 ret = inode_ctx_get (inode, THIS, &ctx)inode_ctx_get2(inode,(*__glusterfs_this_location()),&ctx,
0)
;
1870 if (ret) {
1871 ret = 0;
1872 goto out;
1873 }
1874 ictx = (struct nfs_inode_ctx *)ctx;
1875
1876 head = &ictx->shares;
1877 if (!head || list_empty (head))
1878 goto out;
1879
1880 req_mode = cs->args.nlm4_shareargs.share.mode;
1881 req_access = cs->args.nlm4_shareargs.share.access;
1882
1883 list_for_each_entry (share, head, inode_list)for (share = ((typeof(*share) *)((char *)((head)->next)-(unsigned
long)(&((typeof(*share) *)0)->inode_list))); &share
->inode_list != (head); share = ((typeof(*share) *)((char *
)(share->inode_list.next)-(unsigned long)(&((typeof(*share
) *)0)->inode_list))))
{
1884 ret = (((req_mode & share->access) == 0) &&
1885 ((req_access & share->mode) == 0));
1886 if (!ret) {
1887 ret = -1;
1888 goto out;
1889 }
1890 }
1891 ret = 0;
1892
1893 out:
1894 return ret;
1895}
1896
1897int
1898nlm4_create_share_reservation (nfs3_call_state_t *cs)
1899{
1900 int ret = -1;
1901 nlm_share_t *share = NULL((void*)0);
1902 nlm_client_t *client = NULL((void*)0);
1903 inode_t *inode = NULL((void*)0);
1904
1905 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
1906
1907 inode = inode_ref (cs->resolvedloc.inode);
1908 if (!inode) {
1909 gf_log (GF_NLM, GF_LOG_ERROR, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 1909, GF_LOG_ERROR, "inode not found"
); } while (0)
;
1910 goto out;
1911 }
1912
1913 client = __nlm_get_uniq (cs->args.nlm4_shareargs.share.caller_name);
1914 if (!client) {
1915 /* DO NOT add client. the client is supposed
1916 to be here, since nlm4svc_share adds it */
1917 gf_log (GF_NLM, GF_LOG_ERROR, "client not found")do { do { if (0) printf ("client not found"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 1917, GF_LOG_ERROR, "client not found"
); } while (0)
;
1918 goto out;
1919 }
1920
1921 ret = nlm4_approve_share_reservation (cs);
1922 if (ret)
1923 goto out;
1924
1925 share = nlm4_share_new ();
1926 if (!share) {
1927 ret = -1;
1928 goto out;
1929 }
1930
1931 share->inode = inode;
1932 share->mode = cs->args.nlm4_shareargs.share.mode;
1933 share->access = cs->args.nlm4_shareargs.share.access;
1934 nlm_copy_lkowner (&share->lkowner,
1935 &cs->args.nlm4_shareargs.share.oh);
1936
1937 ret = nlm4_add_share_to_inode (share);
1938 if (ret)
1939 goto out;
1940
1941 list_add (&share->client_list, &client->shares);
1942
1943 out:
1944 if (ret && inode) {
1945 inode_unref (inode);
1946 GF_FREE (share)__gf_free (share);
1947 }
1948
1949 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
1950 return ret;
1951}
1952
1953/*
1954 SHARE and UNSHARE calls DO NOT perform STACK_WIND,
1955 the (non-monitored) share reservations are maintained
1956 at *nfs xlator level only*, in memory
1957*/
1958int
1959nlm4_share_resume (void *call_state)
1960{
1961 int ret = -1;
1962 nlm4_stats stat = nlm4_failed;
1963 nfs3_call_state_t *cs = NULL((void*)0);
1964
1965 if (!call_state)
1966 return ret;
1967
1968 cs = (nfs3_call_state_t *)call_state;
1969 nlm4_check_fh_resolve_status (cs, stat, out)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1969, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nlm4_errno_to_nlm4stat (cs->resolve_errno); goto
out; } } while (0)
;
1970
1971 ret = nlm4_create_share_reservation (cs);
1972 if (!ret)
1973 stat = nlm4_granted;
1974
1975 out:
1976 nlm4_share_reply (cs, stat);
1977 nfs3_call_state_wipe (cs);
1978 return 0;
1979}
1980
1981int
1982nlm4svc_share (rpcsvc_request_t *req)
1983{
1984 nlm4_stats stat = nlm4_failed;
1985 xlator_t *vol = NULL((void*)0);
1986 nfs3_state_t *nfs3 = NULL((void*)0);
1987 nfs3_call_state_t *cs = NULL((void*)0);
1988 struct nfs_state *nfs = NULL((void*)0);
1989 struct nfs3_fh fh = {{0}, };
1990 int ret = RPCSVC_ACTOR_ERROR(-1);
1991
1992 if (!req)
1993 return ret;
1994
1995 nlm4_validate_nfs3_state (req, nfs3, stat, rpcerr, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1995, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); (req)->rpc_err = SYSTEM_ERR; stat = nlm4_failed
; goto rpcerr; } } while (0);
;
1996 nfs = nfs_state (nfs3->nfsx)(nfs3->nfsx)->private;
1997 nlm4_handle_call_state_init (nfs->nfs3state, cs, req,do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1998, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
rpcerr; } } while (0)
1998 stat, rpcerr)do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
1998, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
rpcerr; } } while (0)
;
1999
2000 nlm4_prep_shareargs (&cs->args.nlm4_shareargs, &cs->lockfh,
2001 &cs->lkowner, cs->cookiebytes);
2002
2003 if (xdr_to_nlm4_shareargs (req->msg[0],
2004 &cs->args.nlm4_shareargs) <= 0) {
2005 gf_log (GF_NLM, GF_LOG_ERROR, "Error decoding SHARE args")do { do { if (0) printf ("Error decoding SHARE args"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2005, GF_LOG_ERROR
, "Error decoding SHARE args"); } while (0)
;
2006 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
2007 goto rpcerr;
2008 }
2009
2010 fh = cs->lockfh;
2011 nlm4_validate_gluster_fh (&fh, stat, nlm4err)do { if (!nfs3_fh_validate (&fh)) { stat = nlm4_stale_fh;
goto nlm4err; } } while (0)
;
2012 nlm4_map_fh_to_volume (cs->nfs3state, fh, req,do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((cs->nfs3state), &
fh); if (!vol) { uuid_unparse (fh.exportid, exportid); uuid_unparse
(fh.gfid, gfid); trans = ((req)->trans); do { do { if (0)
printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2013, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 2013, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = nlm4_stale_fh; goto
nlm4err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c",
__FUNCTION__, 2013, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
2013 vol, stat, nlm4err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((cs->nfs3state), &
fh); if (!vol) { uuid_unparse (fh.exportid, exportid); uuid_unparse
(fh.gfid, gfid); trans = ((req)->trans); do { do { if (0)
printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2013, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 2013, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = nlm4_stale_fh; goto
nlm4err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c",
__FUNCTION__, 2013, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
2014
2015 if (nlm_grace_period && !cs->args.nlm4_shareargs.reclaim) {
2016 gf_log (GF_NLM, GF_LOG_DEBUG, "NLM in grace period")do { do { if (0) printf ("NLM in grace period"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2016, GF_LOG_DEBUG
, "NLM in grace period"); } while (0)
;
2017 stat = nlm4_denied_grace_period;
2018 nlm4_share_reply (cs, stat);
2019 nfs3_call_state_wipe (cs);
2020 return 0;
2021 }
2022
2023 cs->vol = vol;
2024 cs->trans = rpcsvc_request_transport_ref(req)(rpc_transport_ref((req)->trans));
2025 nlm4_volume_started_check (nfs3, vol, ret, rpcerr)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 2025, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto rpcerr; } } while (0)
;
2026
2027 ret = nlm_add_nlmclnt (cs->args.nlm4_shareargs.share.caller_name);
2028
2029 ret = nfs3_fh_resolve_and_resume (cs, &fh, NULL((void*)0), nlm4_share_resume);
2030
2031 nlm4err:
2032 if (ret < 0) {
2033 gf_log (GF_NLM, GF_LOG_ERROR, "SHARE call failed")do { do { if (0) printf ("SHARE call failed"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 2033, GF_LOG_ERROR, "SHARE call failed"
); } while (0)
;
2034 nlm4_share_reply (cs, stat);
2035 nfs3_call_state_wipe (cs);
2036 return 0;
2037 }
2038
2039 rpcerr:
2040 if (ret < 0)
2041 nfs3_call_state_wipe (cs);
2042
2043 return ret;
2044}
2045
2046int
2047nlm4_remove_share_reservation (nfs3_call_state_t *cs)
2048{
2049 int ret = -1;
2050 uint64_t ctx = 0;
2051 fsh_mode req_mode = 0;
2052 fsh_access req_access = 0;
2053 nlm_share_t *share = NULL((void*)0);
2054 nlm_share_t *tmp = NULL((void*)0);
2055 nlm_client_t *client = NULL((void*)0);
2056 char *caller = NULL((void*)0);
2057 inode_t *inode = NULL((void*)0);
2058 xlator_t *this = NULL((void*)0);
2059 struct list_head *head = NULL((void*)0);
2060 nlm4_shareargs *args = NULL((void*)0);
2061 struct nfs_inode_ctx *ictx = NULL((void*)0);
2062
2063 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
2064
2065 args = &cs->args.nlm4_shareargs;
2066 caller = args->share.caller_name;
2067
2068 client = __nlm_get_uniq (caller);
2069 if (!client) {
2070 gf_log (GF_NLM, GF_LOG_ERROR,do { do { if (0) printf ("client not found: %s", caller); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2071, GF_LOG_ERROR
, "client not found: %s", caller); } while (0)
2071 "client not found: %s", caller)do { do { if (0) printf ("client not found: %s", caller); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2071, GF_LOG_ERROR
, "client not found: %s", caller); } while (0)
;
2072 goto out;
2073 }
2074
2075 inode = cs->resolvedloc.inode;
2076 if (!inode) {
2077 gf_log (GF_NLM, GF_LOG_ERROR,do { do { if (0) printf ("inode not found: client: %s", caller
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
2078, GF_LOG_ERROR, "inode not found: client: %s", caller); }
while (0)
2078 "inode not found: client: %s", caller)do { do { if (0) printf ("inode not found: client: %s", caller
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
2078, GF_LOG_ERROR, "inode not found: client: %s", caller); }
while (0)
;
2079 goto out;
2080 }
2081
2082 this = THIS(*__glusterfs_this_location());
2083 ret = inode_ctx_get (inode, this, &ctx)inode_ctx_get2(inode,this,&ctx,0);
2084 if (ret) {
2085 gf_log (GF_NLM, GF_LOG_ERROR,do { do { if (0) printf ("no shares found for inode:" "gfid: %s; client: %s"
, inode->gfid, caller); } while (0); _gf_log ("nfs""-NLM",
"nlm4.c", __FUNCTION__, 2088, GF_LOG_ERROR, "no shares found for inode:"
"gfid: %s; client: %s", inode->gfid, caller); } while (0)
2086 "no shares found for inode:"do { do { if (0) printf ("no shares found for inode:" "gfid: %s; client: %s"
, inode->gfid, caller); } while (0); _gf_log ("nfs""-NLM",
"nlm4.c", __FUNCTION__, 2088, GF_LOG_ERROR, "no shares found for inode:"
"gfid: %s; client: %s", inode->gfid, caller); } while (0)
2087 "gfid: %s; client: %s",do { do { if (0) printf ("no shares found for inode:" "gfid: %s; client: %s"
, inode->gfid, caller); } while (0); _gf_log ("nfs""-NLM",
"nlm4.c", __FUNCTION__, 2088, GF_LOG_ERROR, "no shares found for inode:"
"gfid: %s; client: %s", inode->gfid, caller); } while (0)
2088 inode->gfid, caller)do { do { if (0) printf ("no shares found for inode:" "gfid: %s; client: %s"
, inode->gfid, caller); } while (0); _gf_log ("nfs""-NLM",
"nlm4.c", __FUNCTION__, 2088, GF_LOG_ERROR, "no shares found for inode:"
"gfid: %s; client: %s", inode->gfid, caller); } while (0)
;
2089 goto out;
2090 }
2091 ictx = (struct nfs_inode_ctx *)ctx;
2092
2093 head = &ictx->shares;
2094 if (list_empty (head)) {
2095 ret = -1;
2096 goto out;
2097 }
2098
2099 ret = 0;
2100 req_mode = args->share.mode;
2101 req_access = args->share.access;
2102
2103 list_for_each_entry_safe (share, tmp, head, inode_list)for (share = ((typeof(*share) *)((char *)((head)->next)-(unsigned
long)(&((typeof(*share) *)0)->inode_list))), tmp = ((
typeof(*share) *)((char *)(share->inode_list.next)-(unsigned
long)(&((typeof(*share) *)0)->inode_list))); &share
->inode_list != (head); share = tmp, tmp = ((typeof(*tmp) *
)((char *)(tmp->inode_list.next)-(unsigned long)(&((typeof
(*tmp) *)0)->inode_list))))
{
2104 ret = ((req_mode == share->mode) &&
2105 (req_access == share->access) &&
2106 nlm_is_oh_same_lkowner (&share->lkowner, &args->share.oh));
2107 if (ret) {
2108 list_del (&share->client_list);
2109 list_del (&share->inode_list);
2110 inode_unref (share->inode);
2111 GF_FREE (share)__gf_free (share);
2112 break;
2113 }
2114 }
2115
2116 ret = 0;
2117 out:
2118 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
2119 return ret;
2120
2121}
2122
2123int
2124nlm4_unshare_resume (void *call_state)
2125{
2126 int ret = -1;
2127 nlm4_stats stat = nlm4_failed;
2128 nfs3_call_state_t *cs = NULL((void*)0);
2129
2130 if (!call_state)
2131 return ret;
2132
2133 cs = (nfs3_call_state_t *)call_state;
2134
2135 nlm4_check_fh_resolve_status (cs, stat, out)do { xlator_t *xlatorp = ((void*)0); char buf[256], gfid[256]
; rpc_transport_t *trans = ((void*)0); if ((cs)->resolve_ret
< 0) { trans = ((cs->req)->trans); xlatorp = nfs3_fh_to_xlator
(cs->nfs3state, &cs->resolvefh); uuid_unparse (cs->
resolvefh.gfid, gfid); sprintf (buf, "(%s) %s : %s", trans->
peerinfo.identifier, xlatorp ? xlatorp->name : "ERR", gfid
); do { do { if (0) printf ("Unable to resolve FH" ": %s", buf
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
2135, GF_LOG_ERROR, "Unable to resolve FH" ": %s", buf); } while
(0); stat = nlm4_errno_to_nlm4stat (cs->resolve_errno); goto
out; } } while (0)
;
2136 ret = nlm4_remove_share_reservation (cs);
2137 if (!ret)
2138 stat = nlm4_granted;
2139
2140 out:
2141 nlm4_share_reply (cs, stat);
2142 nfs3_call_state_wipe (cs);
2143 return 0;
2144}
2145
2146int
2147nlm4svc_unshare (rpcsvc_request_t *req)
2148{
2149 nlm4_stats stat = nlm4_failed;
2150 xlator_t *vol = NULL((void*)0);
2151 nfs3_state_t *nfs3 = NULL((void*)0);
2152 nfs3_call_state_t *cs = NULL((void*)0);
2153 struct nfs_state *nfs = NULL((void*)0);
2154 struct nfs3_fh fh = {{0}, };
2155 int ret = RPCSVC_ACTOR_ERROR(-1);
2156
2157 if (!req)
2158 return ret;
2159
2160 nlm4_validate_nfs3_state (req, nfs3, stat, rpcerr, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
2160, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); (req)->rpc_err = SYSTEM_ERR; stat = nlm4_failed
; goto rpcerr; } } while (0);
;
2161 nfs = nfs_state (nfs3->nfsx)(nfs3->nfsx)->private;
2162 nlm4_handle_call_state_init (nfs->nfs3state, cs, req,do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
2163, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
rpcerr; } } while (0)
2163 stat, rpcerr)do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
2163, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
rpcerr; } } while (0)
;
2164
2165 nlm4_prep_shareargs (&cs->args.nlm4_shareargs, &cs->lockfh,
2166 &cs->lkowner, cs->cookiebytes);
2167
2168 if (xdr_to_nlm4_shareargs (req->msg[0],
2169 &cs->args.nlm4_shareargs) <= 0) {
2170 gf_log (GF_NLM, GF_LOG_ERROR, "Error decoding UNSHARE args")do { do { if (0) printf ("Error decoding UNSHARE args"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2170, GF_LOG_ERROR
, "Error decoding UNSHARE args"); } while (0)
;
2171 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
2172 goto rpcerr;
2173 }
2174
2175 fh = cs->lockfh;
2176 nlm4_validate_gluster_fh (&fh, stat, nlm4err)do { if (!nfs3_fh_validate (&fh)) { stat = nlm4_stale_fh;
goto nlm4err; } } while (0)
;
2177 nlm4_map_fh_to_volume (cs->nfs3state, fh, req,do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((cs->nfs3state), &
fh); if (!vol) { uuid_unparse (fh.exportid, exportid); uuid_unparse
(fh.gfid, gfid); trans = ((req)->trans); do { do { if (0)
printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2178, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 2178, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = nlm4_stale_fh; goto
nlm4err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c",
__FUNCTION__, 2178, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
2178 vol, stat, nlm4err)do { char exportid[256], gfid[256]; rpc_transport_t *trans = (
(void*)0); vol = nfs3_fh_to_xlator ((cs->nfs3state), &
fh); if (!vol) { uuid_unparse (fh.exportid, exportid); uuid_unparse
(fh.gfid, gfid); trans = ((req)->trans); do { do { if (0)
printf ("Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2178, GF_LOG_ERROR
, "Failed to map " "FH to vol: client=%s, exportid=%s, gfid=%s"
, trans->peerinfo.identifier, exportid, gfid); } while (0)
; do { do { if (0) printf ("Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); _gf_log ("nfs""-NLM", "nlm4.c"
, __FUNCTION__, 2178, GF_LOG_ERROR, "Stale nfs client %s must be trying to "
"connect to a deleted volume, please " "unmount it.", trans->
peerinfo.identifier); } while (0); stat = nlm4_stale_fh; goto
nlm4err; } else { do { do { if (0) printf ("FH to Volume: %s"
,vol->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c",
__FUNCTION__, 2178, GF_LOG_TRACE, "FH to Volume: %s" ,vol->
name); } while (0); (req)->private = (void *)(vol); } } while
(0);
;
2179
2180 if (nlm_grace_period && !cs->args.nlm4_shareargs.reclaim) {
2181 gf_log (GF_NLM, GF_LOG_DEBUG, "NLM in grace period")do { do { if (0) printf ("NLM in grace period"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2181, GF_LOG_DEBUG
, "NLM in grace period"); } while (0)
;
2182 stat = nlm4_denied_grace_period;
2183 nlm4_share_reply (cs, stat);
2184 nfs3_call_state_wipe (cs);
2185 return 0;
2186 }
2187
2188 cs->vol = vol;
2189 cs->trans = rpcsvc_request_transport_ref(req)(rpc_transport_ref((req)->trans));
2190 nlm4_volume_started_check (nfs3, vol, ret, rpcerr)do { if ((!nfs_subvolume_started ((nfs3->nfsx)->private
, vol))){ do { do { if (0) printf ("Volume is disabled: %s", vol
->name); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__
, 2190, GF_LOG_ERROR, "Volume is disabled: %s", vol->name)
; } while (0); ret = (-2); goto rpcerr; } } while (0)
;
2191
2192 ret = nfs3_fh_resolve_and_resume (cs, &fh, NULL((void*)0),
2193 nlm4_unshare_resume);
2194
2195 nlm4err:
2196 if (ret < 0) {
2197 gf_log (GF_NLM, GF_LOG_ERROR, "UNSHARE call failed")do { do { if (0) printf ("UNSHARE call failed"); } while (0);
_gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2197, GF_LOG_ERROR
, "UNSHARE call failed"); } while (0)
;
2198 nlm4_share_reply (cs, stat);
2199 ret = 0;
Value stored to 'ret' is never read
2200 return 0;
2201 }
2202
2203 rpcerr:
2204 if (ret < 0)
2205 nfs3_call_state_wipe (cs);
2206
2207 return ret;
2208}
2209
2210int
2211nlm4_free_all_shares (char *caller_name)
2212{
2213 nlm_share_t *share = NULL((void*)0);
2214 nlm_share_t *tmp = NULL((void*)0);
2215 nlm_client_t *client = NULL((void*)0);
2216
2217 LOCK (&nlm_client_list_lk)pthread_spin_lock (&nlm_client_list_lk);
2218
2219 client = __nlm_get_uniq (caller_name);
2220 if (!client) {
2221 gf_log (GF_NLM, GF_LOG_DEBUG,do { do { if (0) printf ("client not found: %s", caller_name)
; } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2222
, GF_LOG_DEBUG, "client not found: %s", caller_name); } while
(0)
2222 "client not found: %s", caller_name)do { do { if (0) printf ("client not found: %s", caller_name)
; } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2222
, GF_LOG_DEBUG, "client not found: %s", caller_name); } while
(0)
;
2223 goto out;
2224 }
2225
2226 list_for_each_entry_safe (share, tmp, &client->shares, client_list)for (share = ((typeof(*share) *)((char *)((&client->shares
)->next)-(unsigned long)(&((typeof(*share) *)0)->client_list
))), tmp = ((typeof(*share) *)((char *)(share->client_list
.next)-(unsigned long)(&((typeof(*share) *)0)->client_list
))); &share->client_list != (&client->shares); share
= tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->client_list.
next)-(unsigned long)(&((typeof(*tmp) *)0)->client_list
))))
{
2227 list_del (&share->inode_list);
2228 list_del (&share->client_list);
2229 inode_unref (share->inode);
2230 GF_FREE (share)__gf_free (share);
2231 }
2232 out:
2233 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
2234 return 0;
2235}
2236
2237int
2238nlm4svc_free_all (rpcsvc_request_t *req)
2239{
2240 int ret = RPCSVC_ACTOR_ERROR(-1);
2241 nlm4_stats stat = nlm4_failed;
2242 nfs3_state_t *nfs3 = NULL((void*)0);
2243 nfs3_call_state_t *cs = NULL((void*)0);
2244 struct nfs_state *nfs = NULL((void*)0);
2245
2246 nlm4_validate_nfs3_state (req, nfs3, stat, err, ret)do { nfs3 = (((rpcsvc_program_t *)((req)->prog))->private
); if (!nfs3) { do { do { if (0) printf ("NFSv3 state " "missing from RPC request"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
2246, GF_LOG_ERROR, "NFSv3 state " "missing from RPC request"
); } while (0); (req)->rpc_err = SYSTEM_ERR; stat = nlm4_failed
; goto err; } } while (0);
;
2247 nfs = nfs_state (nfs3->nfsx)(nfs3->nfsx)->private;
2248 nlm4_handle_call_state_init (nfs->nfs3state, cs,do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
2249, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
err; } } while (0)
2249 req, stat, err)do { cs = nlm4_call_state_init ((nfs->nfs3state), (req)); if
(!cs) { do { do { if (0) printf ("Failed to " "init call state"
); } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__,
2249, GF_LOG_ERROR, "Failed to " "init call state"); } while
(0); stat = nlm4_failed; (req)->rpc_err = SYSTEM_ERR; goto
err; } } while (0)
;
2250
2251 nlm4_prep_freeallargs (&cs->args.nlm4_freeallargs,
2252 &cs->lkowner);
2253
2254 if (xdr_to_nlm4_freeallargs (req->msg[0],
2255 &cs->args.nlm4_freeallargs) <= 0) {
2256 gf_log (GF_NLM, GF_LOG_ERROR, "Error decoding FREE_ALL args")do { do { if (0) printf ("Error decoding FREE_ALL args"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2256, GF_LOG_ERROR
, "Error decoding FREE_ALL args"); } while (0)
;
2257 rpcsvc_request_seterr (req, GARBAGE_ARGS)(req)->rpc_err = GARBAGE_ARGS;
2258 goto err;
2259 }
2260
2261 ret = nlm4_free_all_shares (cs->args.nlm4_freeallargs.name);
2262 if (ret)
2263 goto err;
2264
2265 ret = nlm_cleanup_fds (cs->args.nlm4_freeallargs.name);
2266 if (ret)
2267 goto err;
2268
2269 err:
2270 nfs3_call_state_wipe (cs);
2271 if (ret)
2272 gf_log (GF_NLM, GF_LOG_DEBUG,do { do { if (0) printf ("error in free all; stat: %d", stat)
; } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2273
, GF_LOG_DEBUG, "error in free all; stat: %d", stat); } while
(0)
2273 "error in free all; stat: %d", stat)do { do { if (0) printf ("error in free all; stat: %d", stat)
; } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2273
, GF_LOG_DEBUG, "error in free all; stat: %d", stat); } while
(0)
;
2274 return ret;
2275
2276}
2277
2278void
2279nlm4svc_sm_notify (struct nlm_sm_status *status)
2280{
2281 gf_log (GF_NLM, GF_LOG_INFO, "sm_notify: %s, state: %d",do { do { if (0) printf ("sm_notify: %s, state: %d", status->
mon_name, status->state); } while (0); _gf_log ("nfs""-NLM"
, "nlm4.c", __FUNCTION__, 2283, GF_LOG_INFO, "sm_notify: %s, state: %d"
, status->mon_name, status->state); } while (0)
2282 status->mon_name,do { do { if (0) printf ("sm_notify: %s, state: %d", status->
mon_name, status->state); } while (0); _gf_log ("nfs""-NLM"
, "nlm4.c", __FUNCTION__, 2283, GF_LOG_INFO, "sm_notify: %s, state: %d"
, status->mon_name, status->state); } while (0)
2283 status->state)do { do { if (0) printf ("sm_notify: %s, state: %d", status->
mon_name, status->state); } while (0); _gf_log ("nfs""-NLM"
, "nlm4.c", __FUNCTION__, 2283, GF_LOG_INFO, "sm_notify: %s, state: %d"
, status->mon_name, status->state); } while (0)
;
2284 nlm_cleanup_fds (status->mon_name);
2285}
2286
2287rpcsvc_actor_t nlm4svc_actors[NLM4_PROC_COUNT24] = {
2288 /* 0 */
2289 {"NULL", NLM4_NULL0, nlm4svc_null, NULL((void*)0)},
2290 {"TEST", NLM4_TEST1, nlm4svc_test, NULL((void*)0)},
2291 {"LOCK", NLM4_LOCK2, nlm4svc_lock, NULL((void*)0)},
2292 {"CANCEL", NLM4_CANCEL3, nlm4svc_cancel, NULL((void*)0)},
2293 {"UNLOCK", NLM4_UNLOCK4, nlm4svc_unlock, NULL((void*)0)},
2294 /* 5 */
2295 {"GRANTED", NLM4_GRANTED5, NULL((void*)0), NULL((void*)0)},
2296 {"TEST", NLM4_TEST_MSG6, NULL((void*)0), NULL((void*)0)},
2297 {"LOCK", NLM4_LOCK_MSG7, NULL((void*)0), NULL((void*)0)},
2298 {"CANCEL", NLM4_CANCEL_MSG8, NULL((void*)0), NULL((void*)0)},
2299 {"UNLOCK", NLM4_UNLOCK_MSG9, NULL((void*)0), NULL((void*)0)},
2300 /* 10 */
2301 {"GRANTED", NLM4_GRANTED_MSG10, NULL((void*)0), NULL((void*)0)},
2302 {"TEST", NLM4_TEST_RES11, NULL((void*)0), NULL((void*)0)},
2303 {"LOCK", NLM4_LOCK_RES12, NULL((void*)0), NULL((void*)0)},
2304 {"CANCEL", NLM4_CANCEL_RES13, NULL((void*)0), NULL((void*)0)},
2305 {"UNLOCK", NLM4_UNLOCK_RES14, NULL((void*)0), NULL((void*)0)},
2306 /* 15 ; procedures 17,18,19 are not defined by nlm */
2307 {"GRANTED", NLM4_GRANTED_RES15, NULL((void*)0), NULL((void*)0)},
2308 {"SM_NOTIFY", NLM4_SM_NOTIFY16, NULL((void*)0), NULL((void*)0)},
2309 {"SEVENTEEN", NLM4_SEVENTEEN17, NULL((void*)0), NULL((void*)0)},
2310 {"EIGHTEEN", NLM4_EIGHTEEN18, NULL((void*)0), NULL((void*)0)},
2311 {"NINETEEN", NLM4_NINETEEN19, NULL((void*)0), NULL((void*)0)},
2312 /* 20 */
2313 {"SHARE", NLM4_SHARE20, nlm4svc_share, NULL((void*)0)},
2314 {"UNSHARE", NLM4_UNSHARE21, nlm4svc_unshare, NULL((void*)0)},
2315 {"NM_LOCK", NLM4_NM_LOCK22, nlm4svc_nm_lock, NULL((void*)0)},
2316 {"FREE_ALL", NLM4_FREE_ALL23, nlm4svc_free_all, NULL((void*)0)},
2317};
2318
2319rpcsvc_program_t nlm4prog = {
2320 .progname = "NLM4",
2321 .prognum = NLM_PROGRAM100021,
2322 .progver = NLM_V44,
2323 .progport = GF_NLM4_PORT38468,
2324 .actors = nlm4svc_actors,
2325 .numactors = NLM4_PROC_COUNT24,
2326 .min_auth = AUTH_NULL0,
2327};
2328
2329
2330int
2331nlm4_init_state (xlator_t *nfsx)
2332{
2333 return 0;
2334}
2335
2336extern void *nsm_thread (void *argv);
2337
2338void nlm_grace_period_over(void *arg)
2339{
2340 nlm_grace_period = 0;
2341}
2342
2343rpcsvc_program_t *
2344nlm4svc_init(xlator_t *nfsx)
2345{
2346 struct nfs3_state *ns = NULL((void*)0);
2347 struct nfs_state *nfs = NULL((void*)0);
2348 dict_t *options = NULL((void*)0);
2349 int ret = -1;
2350 char *portstr = NULL((void*)0);
2351 pthread_t thr;
2352 struct timeval timeout = {0,};
2353 FILE *pidfile = NULL((void*)0);
2354 pid_t pid = -1;
2355
2356 nfs = (struct nfs_state*)nfsx->private;
2357
2358 ns = nfs->nfs3state;
2359 if (!ns) {
2360 gf_log (GF_NLM, GF_LOG_ERROR, "NLM4 init failed")do { do { if (0) printf ("NLM4 init failed"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 2360, GF_LOG_ERROR, "NLM4 init failed"
); } while (0)
;
2361 goto err;
2362 }
2363 nlm4prog.private = ns;
2364
2365 options = dict_new ();
2366
2367 ret = gf_asprintf (&portstr, "%d", GF_NLM4_PORT38468);
2368 if (ret == -1)
2369 goto err;
2370
2371 ret = dict_set_dynstr (options, "transport.socket.listen-port",
2372 portstr);
2373 if (ret == -1)
2374 goto err;
2375 ret = dict_set_str (options, "transport-type", "socket");
2376 if (ret == -1) {
2377 gf_log (GF_NLM, GF_LOG_ERROR, "dict_set_str error")do { do { if (0) printf ("dict_set_str error"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 2377, GF_LOG_ERROR, "dict_set_str error"
); } while (0)
;
2378 goto err;
2379 }
2380
2381 if (nfs->allow_insecure) {
2382 ret = dict_set_str (options, "rpc-auth-allow-insecure", "on");
2383 if (ret == -1) {
2384 gf_log (GF_NLM, GF_LOG_ERROR, "dict_set_str error")do { do { if (0) printf ("dict_set_str error"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 2384, GF_LOG_ERROR, "dict_set_str error"
); } while (0)
;
2385 goto err;
2386 }
2387 ret = dict_set_str (options, "rpc-auth.ports.insecure", "on");
2388 if (ret == -1) {
2389 gf_log (GF_NLM, GF_LOG_ERROR, "dict_set_str error")do { do { if (0) printf ("dict_set_str error"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 2389, GF_LOG_ERROR, "dict_set_str error"
); } while (0)
;
2390 goto err;
2391 }
2392 }
2393
2394 ret = dict_set_str (options, "transport.address-family", "inet");
2395 if (ret == -1) {
2396 gf_log (GF_NLM, GF_LOG_ERROR, "dict_set_str error")do { do { if (0) printf ("dict_set_str error"); } while (0); _gf_log
("nfs""-NLM", "nlm4.c", __FUNCTION__, 2396, GF_LOG_ERROR, "dict_set_str error"
); } while (0)
;
2397 goto err;
2398 }
2399
2400 rpcsvc_create_listeners (nfs->rpcsvc, options, "NLM");
2401 if (ret == -1) {
2402 gf_log (GF_NLM, GF_LOG_ERROR, "Unable to create listeners")do { do { if (0) printf ("Unable to create listeners"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2402, GF_LOG_ERROR
, "Unable to create listeners"); } while (0)
;
2403 dict_unref (options);
2404 goto err;
2405 }
2406 INIT_LIST_HEAD(&nlm_client_list)do { (&nlm_client_list)->next = (&nlm_client_list)
->prev = &nlm_client_list; } while (0)
;
2407 LOCK_INIT (&nlm_client_list_lk)pthread_spin_init (&nlm_client_list_lk, 0);
2408
2409 /* unlink sm-notify.pid so that when we restart rpc.statd/sm-notify
2410 * it thinks that the machine has restarted and sends NOTIFY to clients.
2411 */
2412 ret = unlink ("/var/run/sm-notify.pid");
2413 if (ret == -1 && errno(*__errno_location ()) != ENOENT2) {
2414 gf_log (GF_NLM, GF_LOG_ERROR, "unable to unlink sm-notify")do { do { if (0) printf ("unable to unlink sm-notify"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2414, GF_LOG_ERROR
, "unable to unlink sm-notify"); } while (0)
;
2415 goto err;
2416 }
2417 /* temporary work around to restart statd, not distro/OS independant.
2418 * Need to figure out a more graceful way
2419 * killall will cause problems on solaris.
2420 */
2421
2422 pidfile = fopen ("/var/run/rpc.statd.pid", "r");
2423 if (pidfile) {
2424 ret = fscanf (pidfile, "%d", &pid);
2425 if (ret <= 0) {
2426 gf_log (GF_NLM, GF_LOG_WARNING, "unable to get pid of "do { do { if (0) printf ("unable to get pid of " "rpc.statd")
; } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2427
, GF_LOG_WARNING, "unable to get pid of " "rpc.statd"); } while
(0)
2427 "rpc.statd")do { do { if (0) printf ("unable to get pid of " "rpc.statd")
; } while (0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2427
, GF_LOG_WARNING, "unable to get pid of " "rpc.statd"); } while
(0)
;
2428 ret = runcmd ("killall", "-9", "rpc.statd", NULL((void*)0));
2429 } else
2430 kill (pid, SIGKILL9);
2431
2432 fclose (pidfile);
2433 } else {
2434 gf_log (GF_NLM, GF_LOG_WARNING, "opening the pid file of "do { do { if (0) printf ("opening the pid file of " "rpc.statd failed (%s)"
, strerror ((*__errno_location ()))); } while (0); _gf_log ("nfs"
"-NLM", "nlm4.c", __FUNCTION__, 2435, GF_LOG_WARNING, "opening the pid file of "
"rpc.statd failed (%s)", strerror ((*__errno_location ())));
} while (0)
2435 "rpc.statd failed (%s)", strerror (errno))do { do { if (0) printf ("opening the pid file of " "rpc.statd failed (%s)"
, strerror ((*__errno_location ()))); } while (0); _gf_log ("nfs"
"-NLM", "nlm4.c", __FUNCTION__, 2435, GF_LOG_WARNING, "opening the pid file of "
"rpc.statd failed (%s)", strerror ((*__errno_location ())));
} while (0)
;
2436 /* if ret == -1, do nothing - case either statd was not
2437 * running or was running in valgrind mode
2438 */
2439 ret = runcmd ("killall", "-9", "rpc.statd", NULL((void*)0));
2440 }
2441
2442 ret = unlink ("/var/run/rpc.statd.pid");
2443 if (ret == -1 && errno(*__errno_location ()) != ENOENT2) {
2444 gf_log (GF_NLM, GF_LOG_ERROR, "unable to unlink rpc.statd")do { do { if (0) printf ("unable to unlink rpc.statd"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2444, GF_LOG_ERROR
, "unable to unlink rpc.statd"); } while (0)
;
2445 goto err;
2446 }
2447
2448 ret = runcmd ("/sbin/rpc.statd", NULL((void*)0));
2449 if (ret == -1) {
2450 gf_log (GF_NLM, GF_LOG_ERROR, "unable to start rpc.statd")do { do { if (0) printf ("unable to start rpc.statd"); } while
(0); _gf_log ("nfs""-NLM", "nlm4.c", __FUNCTION__, 2450, GF_LOG_ERROR
, "unable to start rpc.statd"); } while (0)
;
2451 goto err;
2452 }
2453 pthread_create (&thr, NULL((void*)0), nsm_thread, (void*)NULL((void*)0));
2454
2455 timeout.tv_sec = nlm_grace_period;
2456 gf_timer_call_after (nfsx->ctx, timeout, nlm_grace_period_over, NULL((void*)0));
2457 return &nlm4prog;
2458err:
2459 return NULL((void*)0);
2460}
2461
2462int32_t
2463nlm_priv (xlator_t *this)
2464{
2465 int32_t ret = -1;
2466 uint32_t client_count = 0;
2467 uint64_t file_count = 0;
2468 nlm_client_t *client = NULL((void*)0);
2469 nlm_fde_t *fde = NULL((void*)0);
2470 char key[GF_DUMP_MAX_BUF_LEN4096] = {0};
2471 char gfid_str[64] = {0};
2472
2473 gf_proc_dump_add_section("nfs.nlm");
2474
2475 if (TRY_LOCK (&nlm_client_list_lk)pthread_spin_trylock (&nlm_client_list_lk))
2476 goto out;
2477
2478 list_for_each_entry (client, &nlm_client_list, nlm_clients)for (client = ((typeof(*client) *)((char *)((&nlm_client_list
)->next)-(unsigned long)(&((typeof(*client) *)0)->nlm_clients
))); &client->nlm_clients != (&nlm_client_list); client
= ((typeof(*client) *)((char *)(client->nlm_clients.next)
-(unsigned long)(&((typeof(*client) *)0)->nlm_clients)
)))
{
2479
2480 gf_proc_dump_build_key (key, "client", "%d.hostname", client_count){ _gf_proc_dump_build_key(key, "client", "%d.hostname", client_count
); }
;
2481 gf_proc_dump_write (key, "%s\n", client->caller_name);
2482
2483 file_count = 0;
2484 list_for_each_entry (fde, &client->fdes, fde_list)for (fde = ((typeof(*fde) *)((char *)((&client->fdes)->
next)-(unsigned long)(&((typeof(*fde) *)0)->fde_list))
); &fde->fde_list != (&client->fdes); fde = ((typeof
(*fde) *)((char *)(fde->fde_list.next)-(unsigned long)(&
((typeof(*fde) *)0)->fde_list))))
{
2485 gf_proc_dump_build_key (key, "file", "%ld.gfid", file_count){ _gf_proc_dump_build_key(key, "file", "%ld.gfid", file_count
); }
;
2486 memset (gfid_str, 0, 64);
2487 uuid_utoa_r (fde->fd->inode->gfid, gfid_str);
2488 gf_proc_dump_write (key, "%s", gfid_str);
2489 file_count++;
2490 }
2491
2492 gf_proc_dump_build_key (key, "client", "files-locked"){ _gf_proc_dump_build_key(key, "client", "files-locked"); };
2493 gf_proc_dump_write (key, "%ld\n", file_count);
2494 client_count++;
2495 }
2496
2497 gf_proc_dump_build_key (key, "nlm", "client-count"){ _gf_proc_dump_build_key(key, "nlm", "client-count"); };
2498 gf_proc_dump_write (key, "%d", client_count);
2499 ret = 0;
2500 UNLOCK (&nlm_client_list_lk)pthread_spin_unlock (&nlm_client_list_lk);
2501
2502 out:
2503 if (ret) {
2504 gf_proc_dump_build_key (key, "nlm", "statedump_error"){ _gf_proc_dump_build_key(key, "nlm", "statedump_error"); };
2505 gf_proc_dump_write (key, "Unable to dump nlm state because "
2506 "nlm_client_list_lk lock couldn't be acquired");
2507 }
2508
2509 return ret;
2510}