From: Olga Kornievskaia <kolga@netapp.com>
To: <bfields@redhat.com>
Cc: <linux-nfs@vger.kernel.org>
Subject: [PATCH v7 08/10] NFSD handle OFFLOAD_CANCEL op
Date: Tue, 20 Feb 2018 11:42:27 -0500 [thread overview]
Message-ID: <20180220164229.65404-9-kolga@netapp.com> (raw)
In-Reply-To: <20180220164229.65404-1-kolga@netapp.com>
Upon receiving OFFLOAD_CANCEL search the list of copy stateids,
if found then set the SIGPENDING signal so that do_splice stops
copying and also send kthread_stop to the copy thread to stop
and wait for it. Take a reference on the copy from the
offload_cancel thread so that it won't go away while we are
trying to process it. Server won't be sending CB_OFFLOAD to the
client since it received a cancel.
Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
---
fs/nfsd/nfs4proc.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
fs/nfsd/xdr4.h | 1 +
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index eb9f528..3d190b3 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1088,6 +1088,14 @@ static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write)
out:
return status;
}
+
+static void nfs4_put_copy(struct nfsd4_copy *copy)
+{
+ if (!refcount_dec_and_test(©->refcount))
+ return;
+ kfree(copy);
+}
+
static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
{
struct nfsd4_copy *copy = container_of(cb, struct nfsd4_copy, cp_cb);
@@ -1125,6 +1133,8 @@ static int _nfsd_copy_file_range(struct nfsd4_copy *copy)
u64 dst_pos = copy->cp_dst_pos;
do {
+ if (signalled() || kthread_should_stop())
+ return -1;
bytes_copied = nfsd_copy_file_range(copy->fh_src, src_pos,
copy->fh_dst, dst_pos, bytes_total);
if (bytes_copied <= 0)
@@ -1143,11 +1153,16 @@ static int nfsd4_do_copy(struct nfsd4_copy *copy, bool sync)
ssize_t bytes;
bytes = _nfsd_copy_file_range(copy);
+ if (signalled() || kthread_should_stop()) {
+ status = -1;
+ goto cleanup;
+ }
if (bytes < 0 && !copy->cp_res.wr_bytes_written)
status = nfserrno(bytes);
else
status = nfsd4_init_copy_res(copy, sync);
+cleanup:
fput(copy->fh_src);
fput(copy->fh_dst);
return status;
@@ -1187,7 +1202,7 @@ static void cleanup_async_copy(struct nfsd4_copy *copy, bool remove)
spin_unlock(©->cp_clp->async_lock);
}
atomic_dec(©->cp_clp->cl_refcount);
- kfree(copy);
+ nfs4_put_copy(copy);
}
static int nfsd4_do_async_copy(void *data)
@@ -1196,6 +1211,9 @@ static int nfsd4_do_async_copy(void *data)
struct nfsd4_copy *cb_copy;
copy->nfserr = nfsd4_do_copy(copy, 0);
+ if (signalled() || kthread_should_stop())
+ goto out;
+
cb_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
if (!cb_copy)
goto out;
@@ -1278,7 +1296,30 @@ static int nfsd4_do_async_copy(void *data)
struct nfsd4_compound_state *cstate,
union nfsd4_op_u *u)
{
- return 0;
+ struct nfsd4_offload_status *os = &u->offload_status;
+ __be32 status = 0;
+ struct nfsd4_copy *copy;
+ bool found = false;
+ struct nfs4_client *clp = cstate->clp;
+
+ spin_lock(&clp->async_lock);
+ list_for_each_entry(copy, &clp->async_copies, copies) {
+ if (memcmp(©->cps->cp_stateid, &os->stateid,
+ NFS4_STATEID_SIZE))
+ continue;
+ found = true;
+ refcount_inc(©->refcount);
+ break;
+ }
+ spin_unlock(&clp->async_lock);
+ if (found) {
+ set_tsk_thread_flag(copy->copy_task, TIF_SIGPENDING);
+ kthread_stop(copy->copy_task);
+ nfs4_put_copy(copy);
+ } else
+ status = nfserr_bad_stateid;
+
+ return status;
}
static __be32
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index 5d493b9..47bfe64 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -540,6 +540,7 @@ struct nfsd4_copy {
struct list_head copies;
struct task_struct *copy_task;
+ refcount_t refcount;
};
struct nfsd4_seek {
--
1.8.3.1
next prev parent reply other threads:[~2018-02-20 16:52 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-20 16:42 [PATCH v7 00/10] NFSD support for asynchronous COPY Olga Kornievskaia
2018-02-20 16:42 ` [PATCH v7 01/10] NFSD CB_OFFLOAD xdr Olga Kornievskaia
2018-02-20 16:42 ` [PATCH v7 02/10] NFSD OFFLOAD_STATUS xdr Olga Kornievskaia
2018-02-20 16:42 ` [PATCH v7 03/10] NFSD OFFLOAD_CANCEL xdr Olga Kornievskaia
2018-02-20 16:42 ` [PATCH v7 04/10] NFSD xdr callback stateid in async COPY reply Olga Kornievskaia
2018-02-20 16:42 ` [PATCH v7 05/10] NFSD introduce asynch copy feature Olga Kornievskaia
2018-03-06 21:27 ` J. Bruce Fields
2018-03-07 20:48 ` Olga Kornievskaia
2018-03-07 20:38 ` J. Bruce Fields
2018-03-07 20:50 ` Olga Kornievskaia
2018-03-07 21:05 ` J. Bruce Fields
2018-03-07 22:06 ` Olga Kornievskaia
2018-03-08 15:07 ` J. Bruce Fields
2018-03-22 15:08 ` Olga Kornievskaia
2018-02-20 16:42 ` [PATCH v7 06/10] NFSD return nfs4_stid in nfs4_preprocess_stateid_op Olga Kornievskaia
2018-03-07 21:43 ` J. Bruce Fields
2018-03-07 21:54 ` Olga Kornievskaia
2018-03-08 15:14 ` J. Bruce Fields
2018-02-20 16:42 ` [PATCH v7 07/10] NFSD create new stateid for async copy Olga Kornievskaia
2018-03-08 16:31 ` J. Bruce Fields
2018-03-22 15:12 ` Olga Kornievskaia
2018-03-22 15:17 ` J. Bruce Fields
2018-03-22 16:40 ` Olga Kornievskaia
2018-02-20 16:42 ` Olga Kornievskaia [this message]
2018-02-20 16:42 ` [PATCH v7 09/10] NFSD support OFFLOAD_STATUS Olga Kornievskaia
2018-02-20 16:42 ` [PATCH v7 10/10] NFSD stop queued async copies on client shutdown Olga Kornievskaia
2018-03-08 17:05 ` J. Bruce Fields
2018-04-10 20:09 ` Olga Kornievskaia
2018-04-10 20:21 ` J. Bruce Fields
2018-04-10 21:07 ` Olga Kornievskaia
2018-04-10 21:13 ` J. Bruce Fields
2018-04-11 17:33 ` J. Bruce Fields
2018-04-12 20:05 ` Olga Kornievskaia
2018-04-12 20:06 ` J. Bruce Fields
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180220164229.65404-9-kolga@netapp.com \
--to=kolga@netapp.com \
--cc=bfields@redhat.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).