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

With all other NLMv4 procedures now converted to xdrgen-generated
XDR functions, the FREE_ALL procedure can be converted as well.
This conversion allows the removal of nlm4svc_retrieve_args(),
a 79-line helper function that was used only by FREE_ALL to
retrieve client information from lockd's internal data
structures.

Replace the NLMPROC4_FREE_ALL 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 structure (nlm4_notify_wrapper) and call
nlm4svc_lookup_host() directly, eliminating the need for the
now-removed helper function.

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>

+33 -92
+33 -92
fs/lockd/svc4proc.c
··· 69 69 70 70 static_assert(offsetof(struct nlm4_notifyargs_wrapper, xdrgen) == 0); 71 71 72 + struct nlm4_notify_wrapper { 73 + struct nlm4_notify xdrgen; 74 + }; 75 + 76 + static_assert(offsetof(struct nlm4_notify_wrapper, xdrgen) == 0); 77 + 72 78 struct nlm4_testres_wrapper { 73 79 struct nlm4_testres xdrgen; 74 80 struct nlm_lock lock; ··· 195 189 return nlm_lck_denied_nolocks; 196 190 197 191 return nlm_granted; 198 - } 199 - 200 - /* 201 - * Obtain client and file from arguments 202 - */ 203 - static __be32 204 - nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, 205 - struct nlm_host **hostp, struct nlm_file **filp) 206 - { 207 - struct nlm_host *host = NULL; 208 - struct nlm_file *file = NULL; 209 - struct nlm_lock *lock = &argp->lock; 210 - __be32 error = 0; 211 - 212 - /* nfsd callbacks must have been installed for this procedure */ 213 - if (!nlmsvc_ops) 214 - return nlm_lck_denied_nolocks; 215 - 216 - if (lock->lock_start > OFFSET_MAX || 217 - (lock->lock_len && ((lock->lock_len - 1) > (OFFSET_MAX - lock->lock_start)))) 218 - return nlm4_fbig; 219 - 220 - /* Obtain host handle */ 221 - if (!(host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len)) 222 - || (argp->monitor && nsm_monitor(host) < 0)) 223 - goto no_locks; 224 - *hostp = host; 225 - 226 - /* Obtain file pointer. Not used by FREE_ALL call. */ 227 - if (filp != NULL) { 228 - int mode = lock_to_openmode(&lock->fl); 229 - 230 - lock->fl.c.flc_flags = FL_POSIX; 231 - 232 - error = nlm_lookup_file(rqstp, &file, lock); 233 - if (error) 234 - goto no_locks; 235 - *filp = file; 236 - 237 - /* Set up the missing parts of the file_lock structure */ 238 - lock->fl.c.flc_file = file->f_file[mode]; 239 - lock->fl.c.flc_pid = current->tgid; 240 - lock->fl.fl_start = (loff_t)lock->lock_start; 241 - lock->fl.fl_end = lock->lock_len ? 242 - (loff_t)(lock->lock_start + lock->lock_len - 1) : 243 - OFFSET_MAX; 244 - lock->fl.fl_lmops = &nlmsvc_lock_operations; 245 - nlmsvc_locks_init_private(&lock->fl, host, (pid_t)lock->svid); 246 - if (!lock->fl.c.flc_owner) { 247 - /* lockowner allocation has failed */ 248 - nlmsvc_release_host(host); 249 - return nlm_lck_denied_nolocks; 250 - } 251 - } 252 - 253 - return 0; 254 - 255 - no_locks: 256 - nlmsvc_release_host(host); 257 - switch (error) { 258 - case nlm_granted: 259 - return nlm_lck_denied_nolocks; 260 - case nlm__int__stale_fh: 261 - return nlm4_stale_fh; 262 - case nlm__int__failed: 263 - return nlm4_failed; 264 - default: 265 - if (be32_to_cpu(error) >= 30000) { 266 - pr_warn_once("lockd: unhandled internal status %u\n", 267 - be32_to_cpu(error)); 268 - return nlm4_failed; 269 - } 270 - return error; 271 - } 272 192 } 273 193 274 194 /** ··· 1123 1191 return nlm4svc_do_lock(rqstp, false); 1124 1192 } 1125 1193 1126 - /* 1127 - * FREE_ALL: Release all locks and shares held by client 1194 + /** 1195 + * nlm4svc_proc_free_all - FREE_ALL: Discard client's lock and share state 1196 + * @rqstp: RPC transaction context 1197 + * 1198 + * Returns: 1199 + * %rpc_success: RPC executed successfully. 1200 + * 1201 + * RPC synopsis: 1202 + * void NLMPROC4_FREE_ALL(nlm4_notify) = 23; 1128 1203 */ 1129 - static __be32 1130 - nlm4svc_proc_free_all(struct svc_rqst *rqstp) 1204 + static __be32 nlm4svc_proc_free_all(struct svc_rqst *rqstp) 1131 1205 { 1132 - struct nlm_args *argp = rqstp->rq_argp; 1206 + struct nlm4_notify_wrapper *argp = rqstp->rq_argp; 1133 1207 struct nlm_host *host; 1134 1208 1135 - /* Obtain client */ 1136 - if (nlm4svc_retrieve_args(rqstp, argp, &host, NULL)) 1137 - return rpc_success; 1209 + host = nlm4svc_lookup_host(rqstp, argp->xdrgen.name, false); 1210 + if (!host) 1211 + goto out; 1138 1212 1139 1213 nlmsvc_free_host_resources(host); 1214 + 1140 1215 nlmsvc_release_host(host); 1216 + 1217 + out: 1141 1218 return rpc_success; 1142 1219 } 1143 1220 ··· 1393 1452 .pc_xdrressize = NLM4_nlm4_res_sz, 1394 1453 .pc_name = "NM_LOCK", 1395 1454 }, 1396 - [NLMPROC_FREE_ALL] = { 1397 - .pc_func = nlm4svc_proc_free_all, 1398 - .pc_decode = nlm4svc_decode_notify, 1399 - .pc_encode = nlm4svc_encode_void, 1400 - .pc_argsize = sizeof(struct nlm_args), 1401 - .pc_argzero = sizeof(struct nlm_args), 1402 - .pc_ressize = sizeof(struct nlm_void), 1403 - .pc_xdrressize = St, 1404 - .pc_name = "FREE_ALL", 1455 + [NLMPROC4_FREE_ALL] = { 1456 + .pc_func = nlm4svc_proc_free_all, 1457 + .pc_decode = nlm4_svc_decode_nlm4_notify, 1458 + .pc_encode = nlm4_svc_encode_void, 1459 + .pc_argsize = sizeof(struct nlm4_notify_wrapper), 1460 + .pc_argzero = 0, 1461 + .pc_ressize = 0, 1462 + .pc_xdrressize = XDR_void, 1463 + .pc_name = "FREE_ALL", 1405 1464 }, 1406 1465 }; 1407 1466 ··· 1415 1474 struct nlm4_unlockargs_wrapper unlockargs; 1416 1475 struct nlm4_notifyargs_wrapper notifyargs; 1417 1476 struct nlm4_shareargs_wrapper shareargs; 1477 + struct nlm4_notify_wrapper notify; 1418 1478 struct nlm4_testres_wrapper testres; 1419 1479 struct nlm4_res_wrapper res; 1420 1480 struct nlm4_shareres_wrapper shareres; 1421 - struct nlm_args args; 1422 1481 }; 1423 1482 1424 1483 static DEFINE_PER_CPU_ALIGNED(unsigned long,