4 * XDR support for lockd and the lock client.
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
9 #include <linux/types.h>
10 #include <linux/sched.h>
11 #include <linux/nfs.h>
13 #include <linux/sunrpc/xdr.h>
14 #include <linux/sunrpc/clnt.h>
15 #include <linux/sunrpc/svc.h>
16 #include <linux/sunrpc/stats.h>
17 #include <linux/lockd/lockd.h>
19 #include <uapi/linux/nfs2.h>
21 #define NLMDBG_FACILITY NLMDBG_XDR
25 s32_to_loff_t(__s32 offset
)
27 return (loff_t
)offset
;
31 loff_t_to_s32(loff_t offset
)
34 if (offset
>= NLM_OFFSET_MAX
)
36 else if (offset
<= -NLM_OFFSET_MAX
)
37 res
= -NLM_OFFSET_MAX
;
44 * XDR functions for basic NLM types
46 static __be32
*nlm_decode_cookie(__be32
*p
, struct nlm_cookie
*c
)
55 memset(c
->data
, 0, 4); /* hockeypux brain damage */
57 else if(len
<=NLM_MAXCOOKIELEN
)
60 memcpy(c
->data
, p
, len
);
65 dprintk("lockd: bad cookie size %d (only cookies under "
66 "%d bytes are supported.)\n",
67 len
, NLM_MAXCOOKIELEN
);
73 static inline __be32
*
74 nlm_encode_cookie(__be32
*p
, struct nlm_cookie
*c
)
77 memcpy(p
, c
->data
, c
->len
);
78 p
+=XDR_QUADLEN(c
->len
);
83 nlm_decode_fh(__be32
*p
, struct nfs_fh
*f
)
87 if ((len
= ntohl(*p
++)) != NFS2_FHSIZE
) {
88 dprintk("lockd: bad fhandle size %d (should be %d)\n",
92 f
->size
= NFS2_FHSIZE
;
93 memset(f
->data
, 0, sizeof(f
->data
));
94 memcpy(f
->data
, p
, NFS2_FHSIZE
);
95 return p
+ XDR_QUADLEN(NFS2_FHSIZE
);
98 static inline __be32
*
99 nlm_encode_fh(__be32
*p
, struct nfs_fh
*f
)
101 *p
++ = htonl(NFS2_FHSIZE
);
102 memcpy(p
, f
->data
, NFS2_FHSIZE
);
103 return p
+ XDR_QUADLEN(NFS2_FHSIZE
);
107 * Encode and decode owner handle
109 static inline __be32
*
110 nlm_decode_oh(__be32
*p
, struct xdr_netobj
*oh
)
112 return xdr_decode_netobj(p
, oh
);
115 static inline __be32
*
116 nlm_encode_oh(__be32
*p
, struct xdr_netobj
*oh
)
118 return xdr_encode_netobj(p
, oh
);
122 nlm_decode_lock(__be32
*p
, struct nlm_lock
*lock
)
124 struct file_lock
*fl
= &lock
->fl
;
127 if (!(p
= xdr_decode_string_inplace(p
, &lock
->caller
,
130 || !(p
= nlm_decode_fh(p
, &lock
->fh
))
131 || !(p
= nlm_decode_oh(p
, &lock
->oh
)))
133 lock
->svid
= ntohl(*p
++);
136 fl
->fl_owner
= current
->files
;
137 fl
->fl_pid
= (pid_t
)lock
->svid
;
138 fl
->fl_flags
= FL_POSIX
;
139 fl
->fl_type
= F_RDLCK
; /* as good as anything else */
142 end
= start
+ len
- 1;
144 fl
->fl_start
= s32_to_loff_t(start
);
146 if (len
== 0 || end
< 0)
147 fl
->fl_end
= OFFSET_MAX
;
149 fl
->fl_end
= s32_to_loff_t(end
);
154 * Encode result of a TEST/TEST_MSG call
157 nlm_encode_testres(__be32
*p
, struct nlm_res
*resp
)
161 if (!(p
= nlm_encode_cookie(p
, &resp
->cookie
)))
165 if (resp
->status
== nlm_lck_denied
) {
166 struct file_lock
*fl
= &resp
->lock
.fl
;
168 *p
++ = (fl
->fl_type
== F_RDLCK
)? xdr_zero
: xdr_one
;
169 *p
++ = htonl(resp
->lock
.svid
);
171 /* Encode owner handle. */
172 if (!(p
= xdr_encode_netobj(p
, &resp
->lock
.oh
)))
175 start
= loff_t_to_s32(fl
->fl_start
);
176 if (fl
->fl_end
== OFFSET_MAX
)
179 len
= loff_t_to_s32(fl
->fl_end
- fl
->fl_start
+ 1);
190 * First, the server side XDR functions
193 nlmsvc_decode_testargs(struct svc_rqst
*rqstp
, __be32
*p
, nlm_args
*argp
)
197 if (!(p
= nlm_decode_cookie(p
, &argp
->cookie
)))
200 exclusive
= ntohl(*p
++);
201 if (!(p
= nlm_decode_lock(p
, &argp
->lock
)))
204 argp
->lock
.fl
.fl_type
= F_WRLCK
;
206 return xdr_argsize_check(rqstp
, p
);
210 nlmsvc_encode_testres(struct svc_rqst
*rqstp
, __be32
*p
, struct nlm_res
*resp
)
212 if (!(p
= nlm_encode_testres(p
, resp
)))
214 return xdr_ressize_check(rqstp
, p
);
218 nlmsvc_decode_lockargs(struct svc_rqst
*rqstp
, __be32
*p
, nlm_args
*argp
)
222 if (!(p
= nlm_decode_cookie(p
, &argp
->cookie
)))
224 argp
->block
= ntohl(*p
++);
225 exclusive
= ntohl(*p
++);
226 if (!(p
= nlm_decode_lock(p
, &argp
->lock
)))
229 argp
->lock
.fl
.fl_type
= F_WRLCK
;
230 argp
->reclaim
= ntohl(*p
++);
231 argp
->state
= ntohl(*p
++);
232 argp
->monitor
= 1; /* monitor client by default */
234 return xdr_argsize_check(rqstp
, p
);
238 nlmsvc_decode_cancargs(struct svc_rqst
*rqstp
, __be32
*p
, nlm_args
*argp
)
242 if (!(p
= nlm_decode_cookie(p
, &argp
->cookie
)))
244 argp
->block
= ntohl(*p
++);
245 exclusive
= ntohl(*p
++);
246 if (!(p
= nlm_decode_lock(p
, &argp
->lock
)))
249 argp
->lock
.fl
.fl_type
= F_WRLCK
;
250 return xdr_argsize_check(rqstp
, p
);
254 nlmsvc_decode_unlockargs(struct svc_rqst
*rqstp
, __be32
*p
, nlm_args
*argp
)
256 if (!(p
= nlm_decode_cookie(p
, &argp
->cookie
))
257 || !(p
= nlm_decode_lock(p
, &argp
->lock
)))
259 argp
->lock
.fl
.fl_type
= F_UNLCK
;
260 return xdr_argsize_check(rqstp
, p
);
264 nlmsvc_decode_shareargs(struct svc_rqst
*rqstp
, __be32
*p
, nlm_args
*argp
)
266 struct nlm_lock
*lock
= &argp
->lock
;
268 memset(lock
, 0, sizeof(*lock
));
269 locks_init_lock(&lock
->fl
);
270 lock
->svid
= ~(u32
) 0;
271 lock
->fl
.fl_pid
= (pid_t
)lock
->svid
;
273 if (!(p
= nlm_decode_cookie(p
, &argp
->cookie
))
274 || !(p
= xdr_decode_string_inplace(p
, &lock
->caller
,
275 &lock
->len
, NLM_MAXSTRLEN
))
276 || !(p
= nlm_decode_fh(p
, &lock
->fh
))
277 || !(p
= nlm_decode_oh(p
, &lock
->oh
)))
279 argp
->fsm_mode
= ntohl(*p
++);
280 argp
->fsm_access
= ntohl(*p
++);
281 return xdr_argsize_check(rqstp
, p
);
285 nlmsvc_encode_shareres(struct svc_rqst
*rqstp
, __be32
*p
, struct nlm_res
*resp
)
287 if (!(p
= nlm_encode_cookie(p
, &resp
->cookie
)))
290 *p
++ = xdr_zero
; /* sequence argument */
291 return xdr_ressize_check(rqstp
, p
);
295 nlmsvc_encode_res(struct svc_rqst
*rqstp
, __be32
*p
, struct nlm_res
*resp
)
297 if (!(p
= nlm_encode_cookie(p
, &resp
->cookie
)))
300 return xdr_ressize_check(rqstp
, p
);
304 nlmsvc_decode_notify(struct svc_rqst
*rqstp
, __be32
*p
, struct nlm_args
*argp
)
306 struct nlm_lock
*lock
= &argp
->lock
;
308 if (!(p
= xdr_decode_string_inplace(p
, &lock
->caller
,
309 &lock
->len
, NLM_MAXSTRLEN
)))
311 argp
->state
= ntohl(*p
++);
312 return xdr_argsize_check(rqstp
, p
);
316 nlmsvc_decode_reboot(struct svc_rqst
*rqstp
, __be32
*p
, struct nlm_reboot
*argp
)
318 if (!(p
= xdr_decode_string_inplace(p
, &argp
->mon
, &argp
->len
, SM_MAXSTRLEN
)))
320 argp
->state
= ntohl(*p
++);
321 memcpy(&argp
->priv
.data
, p
, sizeof(argp
->priv
.data
));
322 p
+= XDR_QUADLEN(SM_PRIV_SIZE
);
323 return xdr_argsize_check(rqstp
, p
);
327 nlmsvc_decode_res(struct svc_rqst
*rqstp
, __be32
*p
, struct nlm_res
*resp
)
329 if (!(p
= nlm_decode_cookie(p
, &resp
->cookie
)))
332 return xdr_argsize_check(rqstp
, p
);
336 nlmsvc_decode_void(struct svc_rqst
*rqstp
, __be32
*p
, void *dummy
)
338 return xdr_argsize_check(rqstp
, p
);
342 nlmsvc_encode_void(struct svc_rqst
*rqstp
, __be32
*p
, void *dummy
)
344 return xdr_ressize_check(rqstp
, p
);
This page took 0.040045 seconds and 6 git commands to generate.