From patchwork Mon Sep 4 14:30:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13373518 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47BE1CA0FE9 for ; Mon, 4 Sep 2023 06:30:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352353AbjIDGaw (ORCPT ); Mon, 4 Sep 2023 02:30:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344692AbjIDGar (ORCPT ); Mon, 4 Sep 2023 02:30:47 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FCFD109; Sun, 3 Sep 2023 23:30:41 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4RfJfj2mMbz4f3k6P; Mon, 4 Sep 2023 14:30:37 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP1 (Coremail) with SMTP id cCh0CgDnFDGLefVkRQ7ICA--.14846S3; Mon, 04 Sep 2023 14:30:37 +0800 (CST) From: Kemeng Shi To: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: shikemeng@huaweicloud.com Subject: [PATCH 1/3] fuse: move FR_WAITING set from fuse_request_queue_background to fuse_simple_background Date: Mon, 4 Sep 2023 22:30:16 +0800 Message-Id: <20230904143018.5709-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230904143018.5709-1-shikemeng@huaweicloud.com> References: <20230904143018.5709-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgDnFDGLefVkRQ7ICA--.14846S3 X-Coremail-Antispam: 1UD129KBjvJXoW7tw1UGw1UJr4rXry5CFW7Jwb_yoW8Cry5pr 48G3WYyFZrXF4UGr90g3yxZw1ag3yIyr4fCryfGasIyr45Jwsa9rn5GFy5X3WxAr4xZr4a g3ZxW3y3Z34ava7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_Jr4l82xGYIkIc2x26xkF7I0E14v26r1Y6r1xM28lY4IEw2IIxxk0rwA2 F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjx v20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2 z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRPrc3UUUUU = X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Current way to set FR_WAITING in fuse_simple_background: fuse_simple_background if (args->force) fuse_request_alloc /* need to increase num_waiting before request is queued */ else fuse_get_req atomic_inc(&fc->num_waiting); __set_bit(FR_WAITING, &req->flags); fuse_request_queue_background if (!test_bit(FR_WAITING, &req->flags) __set_bit(FR_WAITING, &req->flags); atomic_inc(&fc->num_waiting); We only need to increase num_waiting for force allocated reqeust in fuse_request_queue_background. Simply increase num_waiting in force block to remove unnecessary test_bit(FR_WAITING). This patch also makes it more intuitive to remove FR_WATING usage in next commit. Signed-off-by: Kemeng Shi --- fs/fuse/dev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 1a8f82f478cb..59e1357d4880 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -528,10 +528,6 @@ static bool fuse_request_queue_background(struct fuse_req *req) bool queued = false; WARN_ON(!test_bit(FR_BACKGROUND, &req->flags)); - if (!test_bit(FR_WAITING, &req->flags)) { - __set_bit(FR_WAITING, &req->flags); - atomic_inc(&fc->num_waiting); - } __set_bit(FR_ISREPLY, &req->flags); spin_lock(&fc->bg_lock); if (likely(fc->connected)) { @@ -553,10 +549,14 @@ int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args, struct fuse_req *req; if (args->force) { + struct fuse_conn *fc = fm->fc; + WARN_ON(!args->nocreds); req = fuse_request_alloc(fm, gfp_flags); if (!req) return -ENOMEM; + atomic_inc(&fc->num_waiting); + __set_bit(FR_WAITING, &req->flags); __set_bit(FR_BACKGROUND, &req->flags); } else { WARN_ON(args->nocreds); From patchwork Mon Sep 4 14:30:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13373516 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16013C83F33 for ; Mon, 4 Sep 2023 06:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352346AbjIDGau (ORCPT ); Mon, 4 Sep 2023 02:30:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244166AbjIDGar (ORCPT ); Mon, 4 Sep 2023 02:30:47 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3594F4; Sun, 3 Sep 2023 23:30:40 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4RfJff3YD5z4f3jM0; Mon, 4 Sep 2023 14:30:34 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP1 (Coremail) with SMTP id cCh0CgDnFDGLefVkRQ7ICA--.14846S4; Mon, 04 Sep 2023 14:30:38 +0800 (CST) From: Kemeng Shi To: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: shikemeng@huaweicloud.com Subject: [PATCH 2/3] fuse: remove usage of FR_WATING flag Date: Mon, 4 Sep 2023 22:30:17 +0800 Message-Id: <20230904143018.5709-3-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230904143018.5709-1-shikemeng@huaweicloud.com> References: <20230904143018.5709-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgDnFDGLefVkRQ7ICA--.14846S4 X-Coremail-Antispam: 1UD129KBjvJXoW7KrW7XryDJrWDAw4xKw47twb_yoW8Kw1kpF WxCa1jyFW7Xr4UW34fW34xZw1aq3yfAF93KryrGasIvFs8trZIkFn5KFyUWF17Zr4xXrsI g390grs7Zw1Yq37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_Jryl82xGYIkIc2x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2 F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjx v20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2 z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErc IFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRsXo7UUUUU = X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Each allocated request from fuse_request_alloc counts to num_waiting before request is freed. Simply drop num_waiting without FR_WAITING flag check in fuse_put_request to remove unneeded usage of FR_WAITING flag. Signed-off-by: Kemeng Shi --- fs/fuse/dev.c | 9 +-------- fs/fuse/fuse_i.h | 2 -- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 59e1357d4880..4f49b1946635 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -139,7 +139,6 @@ static struct fuse_req *fuse_get_req(struct fuse_mount *fm, bool for_background) req->in.h.gid = from_kgid(fc->user_ns, current_fsgid()); req->in.h.pid = pid_nr_ns(task_pid(current), fc->pid_ns); - __set_bit(FR_WAITING, &req->flags); if (for_background) __set_bit(FR_BACKGROUND, &req->flags); @@ -171,11 +170,7 @@ static void fuse_put_request(struct fuse_req *req) spin_unlock(&fc->bg_lock); } - if (test_bit(FR_WAITING, &req->flags)) { - __clear_bit(FR_WAITING, &req->flags); - fuse_drop_waiting(fc); - } - + fuse_drop_waiting(fc); fuse_request_free(req); } } @@ -495,7 +490,6 @@ ssize_t fuse_simple_request(struct fuse_mount *fm, struct fuse_args *args) if (!args->nocreds) fuse_force_creds(req); - __set_bit(FR_WAITING, &req->flags); __set_bit(FR_FORCE, &req->flags); } else { WARN_ON(args->nocreds); @@ -556,7 +550,6 @@ int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args, if (!req) return -ENOMEM; atomic_inc(&fc->num_waiting); - __set_bit(FR_WAITING, &req->flags); __set_bit(FR_BACKGROUND, &req->flags); } else { WARN_ON(args->nocreds); diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 9b7fc7d3c7f1..45da5553bae3 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -307,7 +307,6 @@ struct fuse_io_priv { * FR_ISREPLY: set if the request has reply * FR_FORCE: force sending of the request even if interrupted * FR_BACKGROUND: request is sent in the background - * FR_WAITING: request is counted as "waiting" * FR_ABORTED: the request was aborted * FR_INTERRUPTED: the request has been interrupted * FR_LOCKED: data is being copied to/from the request @@ -321,7 +320,6 @@ enum fuse_req_flag { FR_ISREPLY, FR_FORCE, FR_BACKGROUND, - FR_WAITING, FR_ABORTED, FR_INTERRUPTED, FR_LOCKED, From patchwork Mon Sep 4 14:30:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 13373517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF2B7CA0FE3 for ; Mon, 4 Sep 2023 06:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352324AbjIDGav (ORCPT ); Mon, 4 Sep 2023 02:30:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345916AbjIDGar (ORCPT ); Mon, 4 Sep 2023 02:30:47 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1A0E106; Sun, 3 Sep 2023 23:30:40 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4RfJff5Hmqz4f3kF7; Mon, 4 Sep 2023 14:30:34 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP1 (Coremail) with SMTP id cCh0CgDnFDGLefVkRQ7ICA--.14846S5; Mon, 04 Sep 2023 14:30:38 +0800 (CST) From: Kemeng Shi To: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: shikemeng@huaweicloud.com Subject: [PATCH 3/3] fuse: move fuse_put_request a bit to remove forward declaration Date: Mon, 4 Sep 2023 22:30:18 +0800 Message-Id: <20230904143018.5709-4-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230904143018.5709-1-shikemeng@huaweicloud.com> References: <20230904143018.5709-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgDnFDGLefVkRQ7ICA--.14846S5 X-Coremail-Antispam: 1UD129KBjvJXoW7ZFyruF47Xr1fJF1DKF17ZFb_yoW8Cr4Upr WfCa12vFZ7XFW7W3y3J34DX3W5tw4xA347tryxJa4fZF15Awn5Z3Z5tFy8XryrJrWxXrsx Xr4DKr17urWYvw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPSb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUWwA2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zV CS5cI20VAGYxC7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E 5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAV WUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY 1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI 0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7s RNBT5UUUUUU== X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Move fuse_put_request before fuse_get_req to remove forward declaration. Signed-off-by: Kemeng Shi --- fs/fuse/dev.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 4f49b1946635..deda8b036de7 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -101,7 +101,26 @@ static void fuse_drop_waiting(struct fuse_conn *fc) } } -static void fuse_put_request(struct fuse_req *req); +static void fuse_put_request(struct fuse_req *req) +{ + struct fuse_conn *fc = req->fm->fc; + + if (refcount_dec_and_test(&req->count)) { + if (test_bit(FR_BACKGROUND, &req->flags)) { + /* + * We get here in the unlikely case that a background + * request was allocated but not sent + */ + spin_lock(&fc->bg_lock); + if (!fc->blocked) + wake_up(&fc->blocked_waitq); + spin_unlock(&fc->bg_lock); + } + + fuse_drop_waiting(fc); + fuse_request_free(req); + } +} static struct fuse_req *fuse_get_req(struct fuse_mount *fm, bool for_background) { @@ -154,27 +173,6 @@ static struct fuse_req *fuse_get_req(struct fuse_mount *fm, bool for_background) return ERR_PTR(err); } -static void fuse_put_request(struct fuse_req *req) -{ - struct fuse_conn *fc = req->fm->fc; - - if (refcount_dec_and_test(&req->count)) { - if (test_bit(FR_BACKGROUND, &req->flags)) { - /* - * We get here in the unlikely case that a background - * request was allocated but not sent - */ - spin_lock(&fc->bg_lock); - if (!fc->blocked) - wake_up(&fc->blocked_waitq); - spin_unlock(&fc->bg_lock); - } - - fuse_drop_waiting(fc); - fuse_request_free(req); - } -} - unsigned int fuse_len_args(unsigned int numargs, struct fuse_arg *args) { unsigned nbytes = 0;