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 UNSHARE 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 UNSHARE
procedure can be converted to use xdrgen-generated XDR
functions.

Replace the NLMPROC4_UNSHARE 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>

+62 -36
+62 -36
fs/lockd/svc4proc.c
··· 1124 1124 rpc_drop_reply : rpc_success; 1125 1125 } 1126 1126 1127 - /* 1128 - * UNSHARE: Release a DOS share. 1127 + /** 1128 + * nlm4svc_proc_unshare - UNSHARE: Release a share reservation 1129 + * @rqstp: RPC transaction context 1130 + * 1131 + * Returns: 1132 + * %rpc_success: RPC executed successfully. 1133 + * %rpc_drop_reply: Do not send an RPC reply. 1134 + * 1135 + * RPC synopsis: 1136 + * nlm4_shareres NLMPROC4_UNSHARE(nlm4_shareargs) = 21; 1137 + * 1138 + * Permissible procedure status codes: 1139 + * %NLM4_GRANTED: The share reservation was released. 1140 + * %NLM4_DENIED_GRACE_PERIOD: The server has recently restarted and is 1141 + * re-establishing existing locks, and is not 1142 + * yet ready to accept normal service requests. 1143 + * 1144 + * The Linux NLM server implementation also returns: 1145 + * %NLM4_DENIED_NOLOCKS: A needed resource could not be allocated. 1146 + * %NLM4_STALE_FH: The request specified an invalid file handle. 1147 + * %NLM4_FBIG: The request specified a length or offset 1148 + * that exceeds the range supported by the 1149 + * server. 1150 + * %NLM4_FAILED: The request failed for an unspecified reason. 1129 1151 */ 1130 - static __be32 1131 - nlm4svc_proc_unshare(struct svc_rqst *rqstp) 1152 + static __be32 nlm4svc_proc_unshare(struct svc_rqst *rqstp) 1132 1153 { 1133 - struct nlm_args *argp = rqstp->rq_argp; 1134 - struct nlm_res *resp = rqstp->rq_resp; 1154 + struct nlm4_shareargs_wrapper *argp = rqstp->rq_argp; 1155 + struct nlm4_shareres_wrapper *resp = rqstp->rq_resp; 1135 1156 struct nlm_lock *lock = &argp->lock; 1136 - struct nlm_host *host; 1137 - struct nlm_file *file; 1157 + struct nlm4_lock xdr_lock = { 1158 + .fh = argp->xdrgen.share.fh, 1159 + .oh = argp->xdrgen.share.oh, 1160 + .svid = ~(u32)0, 1161 + }; 1162 + struct nlm_host *host = NULL; 1163 + struct nlm_file *file = NULL; 1138 1164 1139 - dprintk("lockd: UNSHARE called\n"); 1165 + resp->xdrgen.cookie = argp->xdrgen.cookie; 1140 1166 1141 - resp->cookie = argp->cookie; 1167 + resp->xdrgen.stat = nlm_lck_denied_grace_period; 1168 + if (locks_in_grace(SVC_NET(rqstp))) 1169 + goto out; 1142 1170 1143 - /* Don't accept requests during grace period */ 1144 - if (locks_in_grace(SVC_NET(rqstp))) { 1145 - resp->status = nlm_lck_denied_grace_period; 1146 - return rpc_success; 1147 - } 1171 + resp->xdrgen.stat = nlm_lck_denied_nolocks; 1172 + host = nlm4svc_lookup_host(rqstp, argp->xdrgen.share.caller_name, true); 1173 + if (!host) 1174 + goto out; 1148 1175 1149 - /* Obtain client and file */ 1150 - locks_init_lock(&lock->fl); 1151 - lock->svid = ~(u32)0; 1152 - resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file); 1153 - if (resp->status) 1154 - return resp->status == nlm__int__drop_reply ? 1155 - rpc_drop_reply : rpc_success; 1176 + resp->xdrgen.stat = nlm4svc_lookup_file(rqstp, host, lock, &file, 1177 + &xdr_lock, F_RDLCK); 1178 + if (resp->xdrgen.stat) 1179 + goto out; 1156 1180 1157 - /* Now try to unshare the file */ 1158 - resp->status = nlmsvc_unshare_file(host, file, &lock->oh); 1181 + resp->xdrgen.stat = nlmsvc_unshare_file(host, file, &lock->oh); 1159 1182 1160 - dprintk("lockd: UNSHARE status %d\n", ntohl(resp->status)); 1161 1183 nlmsvc_release_lockowner(lock); 1184 + 1185 + out: 1186 + if (file) 1187 + nlm_release_file(file); 1162 1188 nlmsvc_release_host(host); 1163 - nlm_release_file(file); 1164 - return rpc_success; 1189 + return resp->xdrgen.stat == nlm__int__drop_reply ? 1190 + rpc_drop_reply : rpc_success; 1165 1191 } 1166 1192 1167 1193 /* ··· 1445 1419 .pc_xdrressize = NLM4_nlm4_shareres_sz, 1446 1420 .pc_name = "SHARE", 1447 1421 }, 1448 - [NLMPROC_UNSHARE] = { 1449 - .pc_func = nlm4svc_proc_unshare, 1450 - .pc_decode = nlm4svc_decode_shareargs, 1451 - .pc_encode = nlm4svc_encode_shareres, 1452 - .pc_argsize = sizeof(struct nlm_args), 1453 - .pc_argzero = sizeof(struct nlm_args), 1454 - .pc_ressize = sizeof(struct nlm_res), 1455 - .pc_xdrressize = Ck+St+1, 1456 - .pc_name = "UNSHARE", 1422 + [NLMPROC4_UNSHARE] = { 1423 + .pc_func = nlm4svc_proc_unshare, 1424 + .pc_decode = nlm4_svc_decode_nlm4_shareargs, 1425 + .pc_encode = nlm4_svc_encode_nlm4_shareres, 1426 + .pc_argsize = sizeof(struct nlm4_shareargs_wrapper), 1427 + .pc_argzero = 0, 1428 + .pc_ressize = sizeof(struct nlm4_shareres_wrapper), 1429 + .pc_xdrressize = NLM4_nlm4_shareres_sz, 1430 + .pc_name = "UNSHARE", 1457 1431 }, 1458 1432 [NLMPROC_NM_LOCK] = { 1459 1433 .pc_func = nlm4svc_proc_nm_lock,