Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2386992rwb; Wed, 5 Oct 2022 13:21:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5pCh8BtSBgHgA7u3tK4+d6u8tDdz3y5aKrhvz5AA1NTV/RhbnO7zoN4qSl0gYEVfywhW1J X-Received: by 2002:a17:90b:3b41:b0:202:8e4b:f532 with SMTP id ot1-20020a17090b3b4100b002028e4bf532mr6894411pjb.231.1665001284272; Wed, 05 Oct 2022 13:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665001284; cv=none; d=google.com; s=arc-20160816; b=iGNZ4gy8oPDWk4YfaFmXLRN2UKsoyzoOUrA17BS6ATcQPeupfGoaeXp6kwFnMKUnXz heL7AoPybAOLGjcZ6WxLbvVMa1iL/F6LsL45NnRZzBW5O/7C3bOQEIbqyRBqfkcmI1NY 4V8TLk2L64hR7F4JIfhSooRRtHka0Q4u/7iVs3oSz0QUvAeOfz6CeMFbWYlzhHgnUuxc RBpepVv9yKIvTeQAHI+WV2eOe58RaTzRkRdnY8IwGXzilbXe8c/mJr/DF1OkKdQvbpcT lwkMN0ae1IFeQp7neeHP8nQwpJMe+yBHJlkUZ+hA087bUtSEjrWjISEljMX7XBlCI1zM JwVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O4E9Y/LTU7axI5W2RklcCQMk1fstqCAehR1DfMGlBU8=; b=nl5MBXCYpyLI7hivOZXD5sBp5CnYbX6iD5aoACVJikaudYehknB1mu85zvmVGloaCU 2xFqYbMtz/7rFWuZe2UZXVIwNVsjDNRzlgy/PJqUPq3NjbYx6IPy9DHnDT8EiSdbDcoQ AwpKUkQfNKAtkpoPAKXeLT4oCEbDK5puiwg4TBictAz5m9ssN/Sv5R1uTTgPd0qi+V8T wa+B5zSgsuzoQA5Ix0J78MWDEsJ/uW+Xo9Gx4aphZe4F4gdstUp4rIOrslImYWdq4KFv OETKZI93u7+uVDGits1+Smad9hnRJYy4bM+UxMQ3HIPmtPJegngA/cLD+TMSe7gMbxKr Z/gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JqO5aDqV; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f21-20020a63e315000000b004391c09ba03si16795991pgh.370.2022.10.05.13.21.11; Wed, 05 Oct 2022 13:21:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JqO5aDqV; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229674AbiJEUE3 (ORCPT + 99 others); Wed, 5 Oct 2022 16:04:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbiJEUE2 (ORCPT ); Wed, 5 Oct 2022 16:04:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43DDB27CDF for ; Wed, 5 Oct 2022 13:04:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C1BAD617AB for ; Wed, 5 Oct 2022 20:04:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0013C433D7; Wed, 5 Oct 2022 20:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665000266; bh=TCTbkROKxcuP5AbC6z8PIzfDcQY/k38E4qt0CvQilXU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JqO5aDqVQ9qRXnHcwyY9R+VaKd8BjxAPq1E9y6piHTMYgnKGdaPYT+X1XXI2hRw0U PwPo45SNc1X4AUEyU/JoHLuzMF0Db6Uh6y/GJdVWxl4/reTo/mlQ4CG8uD38enJ6xb RR4cqnnhRUVKDeZLW4KFrwB2QjicYWylm4W4xjd5ea+ubNin1v/hFyBsm/8H5Fh4zf 9BVIlM5PJNdsq9dKaRff4T2OOd9wh5muSkshUqTSPOIrm3IPS77MFBn1qYyXxzHIsq y4u3Dzpv3e5vpHEZqzgXeabR/O5zZZWxEcbT5VCrfk8IwEtZr9FEmwM9wuIJiSer6r lByzIqrPnqJhA== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/4] SUNRPC: Add a helper to allow pNFS drivers to selectively cancel RPC calls Date: Wed, 5 Oct 2022 15:57:36 -0400 Message-Id: <20221005195738.4552-3-trondmy@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221005195738.4552-2-trondmy@kernel.org> References: <20221005195738.4552-1-trondmy@kernel.org> <20221005195738.4552-2-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Add the helper rpc_cancel_tasks(), which uses a caller-defined selection function to define a set of in-flight RPC calls to cancel. This is mainly intended for pNFS drivers which are subject to a layout recall, and which may therefore want to cancel all pending I/O using that layout in order to redrive it after the layout recall has been satisfied. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/sched.h | 5 +++++ net/sunrpc/clnt.c | 37 ++++++++++++++++++++++++++++++++++++ net/sunrpc/sched.c | 11 +++++++++++ 3 files changed, 53 insertions(+) diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h index 647247040ef9..cdcf0fe56a6f 100644 --- a/include/linux/sunrpc/sched.h +++ b/include/linux/sunrpc/sched.h @@ -210,11 +210,16 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req); void rpc_put_task(struct rpc_task *); void rpc_put_task_async(struct rpc_task *); bool rpc_task_set_rpc_status(struct rpc_task *task, int rpc_status); +void rpc_task_try_cancel(struct rpc_task *task, int error); void rpc_signal_task(struct rpc_task *); void rpc_exit_task(struct rpc_task *); void rpc_exit(struct rpc_task *, int); void rpc_release_calldata(const struct rpc_call_ops *, void *); void rpc_killall_tasks(struct rpc_clnt *); +unsigned long rpc_cancel_tasks(struct rpc_clnt *clnt, int error, + bool (*fnmatch)(const struct rpc_task *, + const void *), + const void *data); void rpc_execute(struct rpc_task *); void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *); void rpc_init_wait_queue(struct rpc_wait_queue *, const char *); diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 77a44118c0da..3bee30cf8a7d 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -873,6 +873,43 @@ void rpc_killall_tasks(struct rpc_clnt *clnt) } EXPORT_SYMBOL_GPL(rpc_killall_tasks); +/** + * rpc_cancel_tasks - try to cancel a set of RPC tasks + * @clnt: Pointer to RPC client + * @error: RPC task error value to set + * @fnmatch: Pointer to selector function + * @data: User data + * + * Uses @fnmatch to define a set of RPC tasks that are to be cancelled. + * The argument @error must be a negative error value. + */ +unsigned long rpc_cancel_tasks(struct rpc_clnt *clnt, int error, + bool (*fnmatch)(const struct rpc_task *, + const void *), + const void *data) +{ + struct rpc_task *task; + unsigned long count = 0; + + if (list_empty(&clnt->cl_tasks)) + return 0; + /* + * Spin lock all_tasks to prevent changes... + */ + spin_lock(&clnt->cl_lock); + list_for_each_entry(task, &clnt->cl_tasks, tk_task) { + if (!RPC_IS_ACTIVATED(task)) + continue; + if (!fnmatch(task, data)) + continue; + rpc_task_try_cancel(task, error); + count++; + } + spin_unlock(&clnt->cl_lock); + return count; +} +EXPORT_SYMBOL_GPL(rpc_cancel_tasks); + /* * Properly shut down an RPC client, terminating all outstanding * requests. diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index f388bfaf6ff0..de912e02371b 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -872,6 +872,17 @@ void rpc_signal_task(struct rpc_task *task) rpc_wake_up_queued_task(queue, task); } +void rpc_task_try_cancel(struct rpc_task *task, int error) +{ + struct rpc_wait_queue *queue; + + if (!rpc_task_set_rpc_status(task, error)) + return; + queue = READ_ONCE(task->tk_waitqueue); + if (queue) + rpc_wake_up_queued_task(queue, task); +} + void rpc_exit(struct rpc_task *task, int status) { task->tk_status = status; -- 2.37.3