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 SHARE procedure

Now that the share helpers have been decoupled from the
NLMv3-specific struct nlm_args and file_lock initialization
has been hoisted into the procedure handler, the NLMv4 SHARE
procedure can be converted to use xdrgen-generated XDR
functions.

Replace the NLMPROC4_SHARE entry in the nlm_procedures4 array
with an entry that uses xdrgen-built XDR decoders and encoders.
The procedure handler is updated to use the new wrapper
structures (nlm4_shareargs_wrapper and nlm4_shareres_wrapper)
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>

+81 -37
+81 -37
fs/lockd/svc4proc.c
··· 74 74 struct nlm_lock lock; 75 75 }; 76 76 77 + struct nlm4_shareargs_wrapper { 78 + struct nlm4_shareargs xdrgen; 79 + struct nlm_lock lock; 80 + }; 81 + 82 + static_assert(offsetof(struct nlm4_shareargs_wrapper, xdrgen) == 0); 83 + 77 84 static_assert(offsetof(struct nlm4_testres_wrapper, xdrgen) == 0); 78 85 79 86 struct nlm4_res_wrapper { ··· 89 82 }; 90 83 91 84 static_assert(offsetof(struct nlm4_res_wrapper, xdrgen) == 0); 85 + 86 + struct nlm4_shareres_wrapper { 87 + struct nlm4_shareres xdrgen; 88 + }; 89 + 90 + static_assert(offsetof(struct nlm4_shareres_wrapper, xdrgen) == 0); 92 91 93 92 static __be32 94 93 nlm4_netobj_to_cookie(struct nlm_cookie *cookie, netobj *object) ··· 1054 1041 return rpc_proc_unavail; 1055 1042 } 1056 1043 1057 - /* 1058 - * SHARE: create a DOS share or alter existing share. 1044 + /** 1045 + * nlm4svc_proc_share - SHARE: Open a file using DOS file-sharing modes 1046 + * @rqstp: RPC transaction context 1047 + * 1048 + * Returns: 1049 + * %rpc_success: RPC executed successfully. 1050 + * %rpc_drop_reply: Do not send an RPC reply. 1051 + * 1052 + * RPC synopsis: 1053 + * nlm4_shareres NLMPROC4_SHARE(nlm4_shareargs) = 20; 1054 + * 1055 + * Permissible procedure status codes: 1056 + * %NLM4_GRANTED: The requested share lock was granted. 1057 + * %NLM4_DENIED: The requested lock conflicted with existing 1058 + * lock reservations for the file. 1059 + * %NLM4_DENIED_GRACE_PERIOD: The server has recently restarted and is 1060 + * re-establishing existing locks, and is not 1061 + * yet ready to accept normal service requests. 1062 + * 1063 + * The Linux NLM server implementation also returns: 1064 + * %NLM4_DENIED_NOLOCKS: A needed resource could not be allocated. 1065 + * %NLM4_STALE_FH: The request specified an invalid file handle. 1066 + * %NLM4_FBIG: The request specified a length or offset 1067 + * that exceeds the range supported by the 1068 + * server. 1069 + * %NLM4_FAILED: The request failed for an unspecified reason. 1059 1070 */ 1060 - static __be32 1061 - nlm4svc_proc_share(struct svc_rqst *rqstp) 1071 + static __be32 nlm4svc_proc_share(struct svc_rqst *rqstp) 1062 1072 { 1063 - struct nlm_args *argp = rqstp->rq_argp; 1064 - struct nlm_res *resp = rqstp->rq_resp; 1073 + struct nlm4_shareargs_wrapper *argp = rqstp->rq_argp; 1074 + struct nlm4_shareres_wrapper *resp = rqstp->rq_resp; 1065 1075 struct nlm_lock *lock = &argp->lock; 1066 - struct nlm_host *host; 1067 - struct nlm_file *file; 1076 + struct nlm_host *host = NULL; 1077 + struct nlm_file *file = NULL; 1078 + struct nlm4_lock xdr_lock = { 1079 + .fh = argp->xdrgen.share.fh, 1080 + .oh = argp->xdrgen.share.oh, 1081 + .svid = ~(u32)0, 1082 + }; 1068 1083 1069 - dprintk("lockd: SHARE called\n"); 1084 + resp->xdrgen.cookie = argp->xdrgen.cookie; 1070 1085 1071 - resp->cookie = argp->cookie; 1086 + resp->xdrgen.stat = nlm_lck_denied_grace_period; 1087 + if (locks_in_grace(SVC_NET(rqstp)) && !argp->xdrgen.reclaim) 1088 + goto out; 1072 1089 1073 - /* Don't accept new lock requests during grace period */ 1074 - if (locks_in_grace(SVC_NET(rqstp)) && !argp->reclaim) { 1075 - resp->status = nlm_lck_denied_grace_period; 1076 - return rpc_success; 1077 - } 1090 + resp->xdrgen.stat = nlm_lck_denied_nolocks; 1091 + host = nlm4svc_lookup_host(rqstp, argp->xdrgen.share.caller_name, true); 1092 + if (!host) 1093 + goto out; 1078 1094 1079 - /* Obtain client and file */ 1080 - locks_init_lock(&lock->fl); 1081 - lock->svid = ~(u32)0; 1082 - resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file); 1083 - if (resp->status) 1084 - return resp->status == nlm__int__drop_reply ? 1085 - rpc_drop_reply : rpc_success; 1095 + resp->xdrgen.stat = nlm4svc_lookup_file(rqstp, host, lock, &file, 1096 + &xdr_lock, F_RDLCK); 1097 + if (resp->xdrgen.stat) 1098 + goto out; 1086 1099 1087 - /* Now try to create the share */ 1088 - resp->status = nlmsvc_share_file(host, file, &lock->oh, 1089 - argp->fsm_access, argp->fsm_mode); 1100 + resp->xdrgen.stat = nlmsvc_share_file(host, file, &lock->oh, 1101 + argp->xdrgen.share.access, 1102 + argp->xdrgen.share.mode); 1090 1103 1091 - dprintk("lockd: SHARE status %d\n", ntohl(resp->status)); 1092 1104 nlmsvc_release_lockowner(lock); 1105 + 1106 + out: 1107 + if (file) 1108 + nlm_release_file(file); 1093 1109 nlmsvc_release_host(host); 1094 - nlm_release_file(file); 1095 - return rpc_success; 1110 + return resp->xdrgen.stat == nlm__int__drop_reply ? 1111 + rpc_drop_reply : rpc_success; 1096 1112 } 1097 1113 1098 1114 /* ··· 1409 1367 .pc_xdrressize = XDR_void, 1410 1368 .pc_name = "UNUSED", 1411 1369 }, 1412 - [NLMPROC_SHARE] = { 1413 - .pc_func = nlm4svc_proc_share, 1414 - .pc_decode = nlm4svc_decode_shareargs, 1415 - .pc_encode = nlm4svc_encode_shareres, 1416 - .pc_argsize = sizeof(struct nlm_args), 1417 - .pc_argzero = sizeof(struct nlm_args), 1418 - .pc_ressize = sizeof(struct nlm_res), 1419 - .pc_xdrressize = Ck+St+1, 1420 - .pc_name = "SHARE", 1370 + [NLMPROC4_SHARE] = { 1371 + .pc_func = nlm4svc_proc_share, 1372 + .pc_decode = nlm4_svc_decode_nlm4_shareargs, 1373 + .pc_encode = nlm4_svc_encode_nlm4_shareres, 1374 + .pc_argsize = sizeof(struct nlm4_shareargs_wrapper), 1375 + .pc_argzero = 0, 1376 + .pc_ressize = sizeof(struct nlm4_shareres_wrapper), 1377 + .pc_xdrressize = NLM4_nlm4_shareres_sz, 1378 + .pc_name = "SHARE", 1421 1379 }, 1422 1380 [NLMPROC_UNSHARE] = { 1423 1381 .pc_func = nlm4svc_proc_unshare, ··· 1460 1418 struct nlm4_cancargs_wrapper cancargs; 1461 1419 struct nlm4_unlockargs_wrapper unlockargs; 1462 1420 struct nlm4_notifyargs_wrapper notifyargs; 1421 + struct nlm4_shareargs_wrapper shareargs; 1463 1422 struct nlm4_testres_wrapper testres; 1464 1423 struct nlm4_res_wrapper res; 1424 + struct nlm4_shareres_wrapper shareres; 1465 1425 struct nlm_args args; 1466 1426 }; 1467 1427