Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3295623imw; Wed, 6 Jul 2022 22:11:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vt+RmHy4+3k6N9PcLqoILmQEP0RKZpJeULRJcMi0/UmoHXv9J6wNLa3NvmcEhU1LxsoMjj X-Received: by 2002:a63:2a4e:0:b0:412:518c:213 with SMTP id q75-20020a632a4e000000b00412518c0213mr15928051pgq.42.1657170695326; Wed, 06 Jul 2022 22:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657170695; cv=none; d=google.com; s=arc-20160816; b=x+VztLq9Xf+BjZqxAXHptJXlXE8mHFByEZecVtEpZLFEph8MEC+TJjMD0JX6PZj2Mg SLWP4GT4E78x3Mto8k715X8egP9BdnBOYW59guES6vWQFd0ca/KpzypioF6EoV6F3R/B gAcn3tkZ4hNJV8fK9G9cFFGV/1+VSNaFFDz+3+dVGeTzwP35ujFWUmtS9/O4/eL5XtqM OVZhJZ1BZI9d9DWt0O2ulBGogXtMr8iya+d1cRJXAJWBVRNAmFWZPt7soNxv0vPsUhM3 pvTCj9NdRmnOgQWr72ibe+Ikf/SrCjH9GAMRFJoj0pt3CTiICM1P7e4SpdOW/pFYkb84 Ts/Q== 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=UQF+7Yf5/3TSdzO16pYmfQfFVL4rnmU2GihY3Suv1gQ=; b=bI5pNUvq3Sc0Qh8jU50PUUW3vj8RL3cuy84PvKM+hNFuYwM1iHhcLUN3fdINGD+J6s jzx2uaLqRwBs4cvVossRRbrxQs+2I2BRPUeFp+MUraI4cIxB43/FIIwnTg+CIsbbhO2C XEkeKEWeUGsdPR90o3XQ7NqmUxW5vSZZzfhECB3BWmc35JtvYZ2o4DTPhb4WT1OpXfeb mGlpdWLNug5jeO3W9mP0NPbjwTFW47SxeoKAAqfTDfcBh1QlCp2FuG+rhxG30DtE7tRC bN1aGHKaSEkJH9jUZ2gREoIpLcorv+gvxN47r5xB732FkdFjFhxCWVCAUaP5fxOpf5Td 2N2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XAsNhBCR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k10-20020a635a4a000000b0040d3fd7ddcesi25341579pgm.370.2022.07.06.22.11.22; Wed, 06 Jul 2022 22:11:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@redhat.com header.s=mimecast20190719 header.b=XAsNhBCR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235035AbiGGEv4 (ORCPT + 99 others); Thu, 7 Jul 2022 00:51:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234995AbiGGEvx (ORCPT ); Thu, 7 Jul 2022 00:51:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A5BF81F2 for ; Wed, 6 Jul 2022 21:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657169511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UQF+7Yf5/3TSdzO16pYmfQfFVL4rnmU2GihY3Suv1gQ=; b=XAsNhBCRcQQ4L9tSUtZdP9hvNXTGMCiCK0RIaXaVz0P4RKnH23quIeijR8wCeNRvrjTqYv F1osWAxilKWRt4Kh5O4S6oj0cmWczKlRJDxyOIsKH50/72n7VIwmGP+ETVj0QldzQMPdaR U5U+sHRzlKhuCXPdL6+qejnvNBGWXXg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646-8xFHNGfJN_2L8z37FQ7S0Q-1; Thu, 07 Jul 2022 00:51:48 -0400 X-MC-Unique: 8xFHNGfJN_2L8z37FQ7S0Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 89AD83C0E20F; Thu, 7 Jul 2022 04:51:47 +0000 (UTC) Received: from lxbceph1.gsslab.pek2.redhat.com (unknown [10.72.47.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86CA418EC9; Thu, 7 Jul 2022 04:51:42 +0000 (UTC) From: xiubli@redhat.com To: dhowells@redhat.com, idryomov@gmail.com, jlayton@kernel.org Cc: marc.dionne@auristor.com, willy@infradead.org, keescook@chromium.org, kirill.shutemov@linux.intel.com, william.kucharski@oracle.com, linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org, ceph-devel@vger.kernel.org, linux-cachefs@redhat.com, vshankar@redhat.com, Xiubo Li Subject: [PATCH v3 1/2] netfs: do not unlock and put the folio twice Date: Thu, 7 Jul 2022 12:51:11 +0800 Message-Id: <20220707045112.10177-2-xiubli@redhat.com> In-Reply-To: <20220707045112.10177-1-xiubli@redhat.com> References: <20220707045112.10177-1-xiubli@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org From: Xiubo Li check_write_begin() will unlock and put the folio when return non-zero. So we should avoid unlocking and putting it twice in netfs layer. At the same time pass a **folio to check_write_begin(), in which the folio should be cleared after being put. URL: https://tracker.ceph.com/issues/56423 Signed-off-by: Xiubo Li --- fs/afs/file.c | 2 +- fs/ceph/addr.c | 11 ++++++----- fs/netfs/buffered_read.c | 18 ++++++++++-------- include/linux/netfs.h | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/fs/afs/file.c b/fs/afs/file.c index 42118a4f3383..afacce797fb9 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -375,7 +375,7 @@ static int afs_begin_cache_operation(struct netfs_io_request *rreq) } static int afs_check_write_begin(struct file *file, loff_t pos, unsigned len, - struct folio *folio, void **_fsdata) + struct folio **folio, void **_fsdata) { struct afs_vnode *vnode = AFS_FS_I(file_inode(file)); diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c index 8095fc47230e..cf909b08907f 100644 --- a/fs/ceph/addr.c +++ b/fs/ceph/addr.c @@ -63,7 +63,7 @@ (CONGESTION_ON_THRESH(congestion_kb) >> 2)) static int ceph_netfs_check_write_begin(struct file *file, loff_t pos, unsigned int len, - struct folio *folio, void **_fsdata); + struct folio **folio, void **_fsdata); static inline struct ceph_snap_context *page_snap_context(struct page *page) { @@ -1280,18 +1280,19 @@ ceph_find_incompatible(struct page *page) } static int ceph_netfs_check_write_begin(struct file *file, loff_t pos, unsigned int len, - struct folio *folio, void **_fsdata) + struct folio **folio, void **_fsdata) { struct inode *inode = file_inode(file); struct ceph_inode_info *ci = ceph_inode(inode); struct ceph_snap_context *snapc; - snapc = ceph_find_incompatible(folio_page(folio, 0)); + snapc = ceph_find_incompatible(folio_page(*folio, 0)); if (snapc) { int r; - folio_unlock(folio); - folio_put(folio); + folio_unlock(*folio); + folio_put(*folio); + *folio = NULL; if (IS_ERR(snapc)) return PTR_ERR(snapc); diff --git a/fs/netfs/buffered_read.c b/fs/netfs/buffered_read.c index 42f892c5712e..308c2ad4da8e 100644 --- a/fs/netfs/buffered_read.c +++ b/fs/netfs/buffered_read.c @@ -319,8 +319,8 @@ static bool netfs_skip_folio_read(struct folio *folio, loff_t pos, size_t len, * conflicting writes once the folio is grabbed and locked. It is passed a * pointer to the fsdata cookie that gets returned to the VM to be passed to * write_end. It is permitted to sleep. It should return 0 if the request - * should go ahead; unlock the folio and return -EAGAIN to cause the folio to - * be regot; or return an error. + * should go ahead; otherwise unlock, put and clear the folio and then return + * an error, -EAGAIN will cause the folio to be regot. * * The calling netfs must initialise a netfs context contiguous to the vfs * inode before calling this. @@ -348,13 +348,14 @@ int netfs_write_begin(struct netfs_inode *ctx, if (ctx->ops->check_write_begin) { /* Allow the netfs (eg. ceph) to flush conflicts. */ - ret = ctx->ops->check_write_begin(file, pos, len, folio, _fsdata); + ret = ctx->ops->check_write_begin(file, pos, len, &folio, _fsdata); if (ret < 0) { trace_netfs_failure(NULL, NULL, ret, netfs_fail_check_write_begin); if (ret == -EAGAIN) goto retry; - goto error; + goto error_unlocked; } + BUG_ON(!folio); } if (folio_test_uptodate(folio)) @@ -375,7 +376,7 @@ int netfs_write_begin(struct netfs_inode *ctx, NETFS_READ_FOR_WRITE); if (IS_ERR(rreq)) { ret = PTR_ERR(rreq); - goto error; + goto error_locked; } rreq->no_unlock_folio = folio_index(folio); __set_bit(NETFS_RREQ_NO_UNLOCK_FOLIO, &rreq->flags); @@ -402,12 +403,12 @@ int netfs_write_begin(struct netfs_inode *ctx, ret = netfs_begin_read(rreq, true); if (ret < 0) - goto error; + goto error_locked; have_folio: ret = folio_wait_fscache_killable(folio); if (ret < 0) - goto error; + goto error_locked; have_folio_no_wait: *_folio = folio; _leave(" = 0"); @@ -415,9 +416,10 @@ int netfs_write_begin(struct netfs_inode *ctx, error_put: netfs_put_request(rreq, false, netfs_rreq_trace_put_failed); -error: +error_locked: folio_unlock(folio); folio_put(folio); +error_unlocked: _leave(" = %d", ret); return ret; } diff --git a/include/linux/netfs.h b/include/linux/netfs.h index 1773e5df8e65..88c4eb85c6f7 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -214,7 +214,7 @@ struct netfs_request_ops { void (*issue_read)(struct netfs_io_subrequest *subreq); bool (*is_still_valid)(struct netfs_io_request *rreq); int (*check_write_begin)(struct file *file, loff_t pos, unsigned len, - struct folio *folio, void **_fsdata); + struct folio **folio, void **_fsdata); void (*done)(struct netfs_io_request *rreq); }; -- 2.36.0.rc1