Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lockd: Use xdrgen XDR functions for the NLMv4 NM_LOCK procedure

Now that nlm4svc_do_lock() has been introduced to handle both
monitored and non-monitored lock requests, the NLMv4 NM_LOCK
procedure can be converted to use xdrgen-generated XDR
functions. This conversion allows the removal of
__nlm4svc_proc_lock(), a helper function that was previously
shared between the LOCK and NM_LOCK procedures.

Replace the NLMPROC4_NM_LOCK entry in the nlm_procedures4
array with an entry that uses xdrgen-built XDR decoders and
encoders. The procedure handler is updated to call
nlm4svc_do_lock() directly and access arguments through the
argp->xdrgen hierarchy.

The .pc_argzero field is set to zero because xdrgen decoders
fully initialize all fields in argp->xdrgen, making the early
defensive memset unnecessary. The remaining argp fields that
fall outside the xdrgen structures are cleared explicitly as
needed.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>

+44 -57
+44 -57
fs/lockd/svc4proc.c
··· 359 359 } 360 360 361 361 static __be32 362 - __nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_res *resp) 363 - { 364 - struct nlm_args *argp = rqstp->rq_argp; 365 - struct nlm_host *host; 366 - struct nlm_file *file; 367 - __be32 rc = rpc_success; 368 - 369 - dprintk("lockd: LOCK called\n"); 370 - 371 - resp->cookie = argp->cookie; 372 - 373 - /* Obtain client and file */ 374 - if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file))) 375 - return resp->status == nlm__int__drop_reply ? 376 - rpc_drop_reply : rpc_success; 377 - 378 - /* Now try to lock the file */ 379 - resp->status = nlmsvc_lock(rqstp, file, host, &argp->lock, 380 - argp->block, &argp->cookie, 381 - argp->reclaim); 382 - switch (resp->status) { 383 - case nlm__int__drop_reply: 384 - rc = rpc_drop_reply; 385 - break; 386 - case nlm__int__deadlock: 387 - resp->status = nlm4_deadlock; 388 - fallthrough; 389 - default: 390 - dprintk("lockd: LOCK status %d\n", ntohl(resp->status)); 391 - } 392 - 393 - nlmsvc_release_lockowner(&argp->lock); 394 - nlmsvc_release_host(host); 395 - nlm_release_file(file); 396 - return rc; 397 - } 398 - 399 - static __be32 400 362 nlm4svc_do_lock(struct svc_rqst *rqstp, bool monitored) 401 363 { 402 364 struct nlm4_lockargs_wrapper *argp = rqstp->rq_argp; ··· 1152 1190 rpc_drop_reply : rpc_success; 1153 1191 } 1154 1192 1155 - /* 1156 - * NM_LOCK: Create an unmonitored lock 1193 + /** 1194 + * nlm4svc_proc_nm_lock - NM_LOCK: Establish a non-monitored lock 1195 + * @rqstp: RPC transaction context 1196 + * 1197 + * Returns: 1198 + * %rpc_success: RPC executed successfully. 1199 + * %rpc_drop_reply: Do not send an RPC reply. 1200 + * 1201 + * RPC synopsis: 1202 + * nlm4_res NLMPROC4_NM_LOCK(nlm4_lockargs) = 22; 1203 + * 1204 + * Permissible procedure status codes: 1205 + * %NLM4_GRANTED: The requested lock was granted. 1206 + * %NLM4_DENIED: The requested lock conflicted with existing 1207 + * lock reservations for the file. 1208 + * %NLM4_DENIED_NOLOCKS: The server could not allocate the resources 1209 + * needed to process the request. 1210 + * %NLM4_BLOCKED: The blocking request cannot be granted 1211 + * immediately. The server will send an 1212 + * NLMPROC4_GRANTED callback to the client when 1213 + * the lock can be granted. 1214 + * %NLM4_DENIED_GRACE_PERIOD: The server has recently restarted and is 1215 + * re-establishing existing locks, and is not 1216 + * yet ready to accept normal service requests. 1217 + * 1218 + * The Linux NLM server implementation also returns: 1219 + * %NLM4_DEADLCK: The request could not be granted and 1220 + * blocking would cause a deadlock. 1221 + * %NLM4_STALE_FH: The request specified an invalid file handle. 1222 + * %NLM4_FBIG: The request specified a length or offset 1223 + * that exceeds the range supported by the 1224 + * server. 1225 + * %NLM4_FAILED: The request failed for an unspecified reason. 1157 1226 */ 1158 - static __be32 1159 - nlm4svc_proc_nm_lock(struct svc_rqst *rqstp) 1227 + static __be32 nlm4svc_proc_nm_lock(struct svc_rqst *rqstp) 1160 1228 { 1161 - struct nlm_args *argp = rqstp->rq_argp; 1162 - 1163 - dprintk("lockd: NM_LOCK called\n"); 1164 - 1165 - argp->monitor = 0; /* just clean the monitor flag */ 1166 - return __nlm4svc_proc_lock(rqstp, rqstp->rq_resp); 1229 + return nlm4svc_do_lock(rqstp, false); 1167 1230 } 1168 1231 1169 1232 /* ··· 1442 1455 .pc_xdrressize = NLM4_nlm4_shareres_sz, 1443 1456 .pc_name = "UNSHARE", 1444 1457 }, 1445 - [NLMPROC_NM_LOCK] = { 1446 - .pc_func = nlm4svc_proc_nm_lock, 1447 - .pc_decode = nlm4svc_decode_lockargs, 1448 - .pc_encode = nlm4svc_encode_res, 1449 - .pc_argsize = sizeof(struct nlm_args), 1450 - .pc_argzero = sizeof(struct nlm_args), 1451 - .pc_ressize = sizeof(struct nlm_res), 1452 - .pc_xdrressize = Ck+St, 1453 - .pc_name = "NM_LOCK", 1458 + [NLMPROC4_NM_LOCK] = { 1459 + .pc_func = nlm4svc_proc_nm_lock, 1460 + .pc_decode = nlm4_svc_decode_nlm4_lockargs, 1461 + .pc_encode = nlm4_svc_encode_nlm4_res, 1462 + .pc_argsize = sizeof(struct nlm4_lockargs_wrapper), 1463 + .pc_argzero = 0, 1464 + .pc_ressize = sizeof(struct nlm4_res_wrapper), 1465 + .pc_xdrressize = NLM4_nlm4_res_sz, 1466 + .pc_name = "NM_LOCK", 1454 1467 }, 1455 1468 [NLMPROC_FREE_ALL] = { 1456 1469 .pc_func = nlm4svc_proc_free_all,