]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
NFSD: Free async copy information in nfsd4_cb_offload_release()
authorChuck Lever <chuck.lever@oracle.com>
Thu, 31 Oct 2024 13:40:04 +0000 (09:40 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Tue, 19 Nov 2024 01:23:10 +0000 (20:23 -0500)
RFC 7862 Section 4.8 states:

> A copy offload stateid will be valid until either (A) the client
> or server restarts or (B) the client returns the resource by
> issuing an OFFLOAD_CANCEL operation or the client replies to a
> CB_OFFLOAD operation.

Currently, NFSD purges the metadata for an async COPY operation as
soon as the CB_OFFLOAD callback has been sent. It does not wait even
for the client's CB_OFFLOAD response, as the paragraph above
suggests that it should.

This makes the OFFLOAD_STATUS operation ineffective during the
window between the completion of an asynchronous COPY and the
server's receipt of the corresponding CB_OFFLOAD response. This is
important if, for example, the client responds with NFS4ERR_DELAY,
or the transport is lost before the server receives the response. A
client might use OFFLOAD_STATUS to query the server about the still
pending asynchronous COPY, but NFSD will respond to OFFLOAD_STATUS
as if it had never heard of the presented copy stateid.

This patch starts to address this issue by extending the lifetime of
struct nfsd4_copy at least until the server has seen the client's
CB_OFFLOAD response, or the CB_OFFLOAD has timed out.

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

index 5ad55b73454111e4c219ef3567715f09418cb253..5c10131410957d1ec2beabda8d5d4ca0f8a71eed 100644 (file)
@@ -57,6 +57,8 @@ module_param(inter_copy_offload_enable, bool, 0644);
 MODULE_PARM_DESC(inter_copy_offload_enable,
                 "Enable inter server to server copy offload. Default: false");
 
+static void cleanup_async_copy(struct nfsd4_copy *copy);
+
 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
 static int nfsd4_ssc_umount_timeout = 900000;          /* default to 15 mins */
 module_param(nfsd4_ssc_umount_timeout, int, 0644);
@@ -1602,8 +1604,10 @@ static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
 {
        struct nfsd4_cb_offload *cbo =
                container_of(cb, struct nfsd4_cb_offload, co_cb);
+       struct nfsd4_copy *copy =
+               container_of(cbo, struct nfsd4_copy, cp_cb_offload);
 
-       kfree(cbo);
+       cleanup_async_copy(copy);
 }
 
 static int nfsd4_cb_offload_done(struct nfsd4_callback *cb,
@@ -1736,11 +1740,7 @@ static void cleanup_async_copy(struct nfsd4_copy *copy)
 
 static void nfsd4_send_cb_offload(struct nfsd4_copy *copy)
 {
-       struct nfsd4_cb_offload *cbo;
-
-       cbo = kzalloc(sizeof(*cbo), GFP_KERNEL);
-       if (!cbo)
-               return;
+       struct nfsd4_cb_offload *cbo = &copy->cp_cb_offload;
 
        memcpy(&cbo->co_res, &copy->cp_res, sizeof(copy->cp_res));
        memcpy(&cbo->co_fh, &copy->fh, sizeof(copy->fh));
@@ -1790,10 +1790,13 @@ static int nfsd4_do_async_copy(void *data)
        }
 
 do_callback:
+       /* The kthread exits forthwith. Ensure that a subsequent
+        * OFFLOAD_CANCEL won't try to kill it again. */
+       set_bit(NFSD4_COPY_F_STOPPED, &copy->cp_flags);
+
        set_bit(NFSD4_COPY_F_COMPLETED, &copy->cp_flags);
        trace_nfsd_copy_async_done(copy);
        nfsd4_send_cb_offload(copy);
-       cleanup_async_copy(copy);
        return 0;
 }
 
index d5bb9a3c2da426d7305b19d98d722c7a670d7291..08e5d280f887f985e03f630a77ccdad5ae7b4208 100644 (file)
@@ -700,6 +700,9 @@ struct nfsd4_copy {
        struct nfsd42_write_res cp_res;
        struct knfsd_fh         fh;
 
+       /* offload callback */
+       struct nfsd4_cb_offload cp_cb_offload;
+
        struct nfs4_client      *cp_clp;
 
        struct nfsd_file        *nf_src;