From patchwork Fri Apr 13 17:01:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10340621 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A63DE6039A for ; Fri, 13 Apr 2018 17:02:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93D0528926 for ; Fri, 13 Apr 2018 17:02:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 882952893B; Fri, 13 Apr 2018 17:02:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EB0928926 for ; Fri, 13 Apr 2018 17:02:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752639AbeDMRCJ (ORCPT ); Fri, 13 Apr 2018 13:02:09 -0400 Received: from mx142.netapp.com ([216.240.21.19]:53402 "EHLO mx142.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752584AbeDMRCI (ORCPT ); Fri, 13 Apr 2018 13:02:08 -0400 X-IronPort-AV: E=Sophos;i="5.48,446,1517904000"; d="scan'208";a="247710194" Received: from vmwexchts04-prd.hq.netapp.com ([10.122.105.32]) by mx142-out.netapp.com with ESMTP; 13 Apr 2018 10:02:08 -0700 Received: from smtp2.corp.netapp.com (10.122.76.114) by VMWEXCHTS04-PRD.hq.netapp.com (10.122.105.32) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Fri, 13 Apr 2018 10:02:08 -0700 Received: from localhost.localdomain ([10.249.128.146]) by smtp2.corp.netapp.com (8.14.9+Sun/8.13.1/NTAP-1.6) with ESMTP id w3DH1xvB023812; Fri, 13 Apr 2018 10:02:07 -0700 (PDT) From: Olga Kornievskaia To: CC: Subject: [PATCH v8 7/9] NFSD handle OFFLOAD_CANCEL op Date: Fri, 13 Apr 2018 13:01:56 -0400 Message-ID: <20180413170158.17589-8-kolga@netapp.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20180413170158.17589-1-kolga@netapp.com> References: <20180413170158.17589-1-kolga@netapp.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Olga Kornievskaia --- fs/nfsd/nfs4proc.c | 40 +++++++++++++++++++++++++++++++++++++--- fs/nfsd/state.h | 1 + fs/nfsd/xdr4.h | 1 + 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index 9d5f0d0..cebc087 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c @@ -1100,11 +1100,19 @@ static int fill_in_write_vector(struct kvec *vec, struct nfsd4_write *write) out: return status; } + +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); - kfree(copy); + nfs4_put_copy(copy); } static int nfsd4_cb_offload_done(struct nfsd4_callback *cb, @@ -1135,6 +1143,8 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy) u64 dst_pos = copy->cp_dst_pos; do { + if (signalled() || kthread_should_stop()) + break; bytes_copied = nfsd_copy_file_range(copy->file_src, src_pos, copy->file_dst, dst_pos, bytes_total); if (bytes_copied <= 0) @@ -1188,7 +1198,7 @@ static void cleanup_async_copy(struct nfsd4_copy *copy) spin_lock(©->cp_clp->async_lock); list_del(©->copies); spin_unlock(©->cp_clp->async_lock); - kfree(copy); + nfs4_put_copy(copy); } static int nfsd4_do_async_copy(void *data) @@ -1238,6 +1248,7 @@ static int nfsd4_do_async_copy(void *data) goto out; if (!nfs4_init_cp_state(nn, copy)) goto out; + refcount_set(&async_copy->refcount, 1); memcpy(©->cp_res.cb_stateid, ©->cp_stateid, sizeof(copy->cp_stateid)); dup_copy_fields(copy, async_copy); @@ -1266,7 +1277,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/state.h b/fs/nfsd/state.h index d8893427..0ee2ed3 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -641,6 +641,7 @@ extern struct nfs4_client_reclaim *nfs4_client_to_reclaim(const char *name, struct nfs4_file *find_file(struct knfsd_fh *fh); void put_nfs4_file(struct nfs4_file *fi); +extern void nfs4_put_copy(struct nfsd4_copy *copy); static inline void get_nfs4_file(struct nfs4_file *fi) { refcount_inc(&fi->fi_ref); diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h index 5af9eae..249d883 100644 --- a/fs/nfsd/xdr4.h +++ b/fs/nfsd/xdr4.h @@ -542,6 +542,7 @@ struct nfsd4_copy { struct list_head copies; struct task_struct *copy_task; + refcount_t refcount; }; struct nfsd4_seek {