]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
lockd: Use xdrgen XDR functions for the NLMv3 GRANTED_MSG procedure
authorChuck Lever <chuck.lever@oracle.com>
Tue, 12 May 2026 18:13:59 +0000 (14:13 -0400)
committerChuck Lever <cel@kernel.org>
Tue, 9 Jun 2026 20:32:59 +0000 (16:32 -0400)
Continue the xdrgen migration by converting NLMv3 GRANTED_MSG,
the async counterpart to GRANTED that a remote NLM uses to tell
this lockd that a previously blocked client lock request has
become available. The procedure now uses
nlm_svc_decode_nlm_testargs and nlm_svc_encode_void, generated
from the NLM version 3 protocol specification. The procedure
handler reaches the xdrgen types through the
nlm_testargs_wrapper structure, which bridges between generated
code and the legacy lockd_lock representation.

Setting pc_argzero to zero is safe because the generated decoder
fills the argp->xdrgen subfields before the procedure runs, so
the zeroing memset performed by the dispatch layer is not
needed. The lock member of the wrapper is populated explicitly
in __nlmsvc_proc_granted_msg() by nlm_lock_to_lockd_lock()
rather than relying on zero-initialization.

The NLM async callback mechanism uses client-side functions
which continue to take legacy results like struct lockd_res,
preventing GRANTED and GRANTED_MSG from sharing code for now.

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

index d059accfdebd1bb5405b6ea58a45e03d900f56df..21a363450d59e30e3c670bf0fb2b5ec25986b1f1 100644 (file)
@@ -594,23 +594,6 @@ out:
                rpc_drop_reply : rpc_success;
 }
 
-/*
- * GRANTED: A server calls us to tell that a process' lock request
- * was granted
- */
-static __be32
-__nlmsvc_proc_granted(struct svc_rqst *rqstp, struct lockd_res *resp)
-{
-       struct lockd_args *argp = rqstp->rq_argp;
-
-       resp->cookie = argp->cookie;
-
-       dprintk("lockd: GRANTED       called\n");
-       resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock);
-       dprintk("lockd: GRANTED       status %d\n", ntohl(resp->status));
-       return rpc_success;
-}
-
 /**
  * nlmsvc_proc_granted - GRANTED: Blocked lock has been granted
  * @rqstp: RPC transaction context
@@ -966,19 +949,52 @@ static __be32 nlmsvc_proc_unlock_msg(struct svc_rqst *rqstp)
                               __nlmsvc_proc_unlock_msg);
 }
 
+static __be32
+__nlmsvc_proc_granted_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
+{
+       struct nlm_testargs_wrapper *argp = rqstp->rq_argp;
+
+       resp->status = nlm_lck_denied;
+       if (nlm_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
+               goto out;
+
+       if (nlm_lock_to_lockd_lock(&argp->lock, &argp->xdrgen.alock))
+               goto out;
+
+       resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock);
+
+out:
+       return rpc_success;
+}
+
+/**
+ * nlmsvc_proc_granted_msg - GRANTED_MSG: Blocked lock has been granted
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:             RPC executed successfully.
+ *   %rpc_garbage_args:        The request arguments are malformed.
+ *   %rpc_system_err:          RPC execution failed.
+ *
+ * RPC synopsis:
+ *   void NLMPROC_GRANTED_MSG(nlm_testargs) = 10;
+ *
+ * The response to this request is delivered via the GRANTED_RES procedure.
+ */
 static __be32 nlmsvc_proc_granted_msg(struct svc_rqst *rqstp)
 {
-       struct lockd_args *argp = rqstp->rq_argp;
-       struct nlm_host *host;
+       struct nlm_testargs_wrapper *argp = rqstp->rq_argp;
+       struct nlm_host *host;
 
-       dprintk("lockd: GRANTED_MSG   called\n");
+       if (argp->xdrgen.cookie.len > NLM_MAXCOOKIELEN)
+               return rpc_garbage_args;
 
-       host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+       host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
        if (!host)
                return rpc_system_err;
 
        return nlmsvc_callback(rqstp, host, NLMPROC_GRANTED_RES,
-                              __nlmsvc_proc_granted);
+                              __nlmsvc_proc_granted_msg);
 }
 
 /*
@@ -1244,15 +1260,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
                .pc_xdrressize  = XDR_void,
                .pc_name        = "UNLOCK_MSG",
        },
-       [NLMPROC_GRANTED_MSG] = {
-               .pc_func = nlmsvc_proc_granted_msg,
-               .pc_decode = nlmsvc_decode_testargs,
-               .pc_encode = nlmsvc_encode_void,
-               .pc_argsize = sizeof(struct lockd_args),
-               .pc_argzero = sizeof(struct lockd_args),
-               .pc_ressize = sizeof(struct nlm_void),
-               .pc_xdrressize = St,
-               .pc_name = "GRANTED_MSG",
+       [NLM_GRANTED_MSG] = {
+               .pc_func        = nlmsvc_proc_granted_msg,
+               .pc_decode      = nlm_svc_decode_nlm_testargs,
+               .pc_encode      = nlm_svc_encode_void,
+               .pc_argsize     = sizeof(struct nlm_testargs_wrapper),
+               .pc_argzero     = 0,
+               .pc_ressize     = 0,
+               .pc_xdrressize  = XDR_void,
+               .pc_name        = "GRANTED_MSG",
        },
        [NLMPROC_TEST_RES] = {
                .pc_func = nlmsvc_proc_null,