Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2626670rwb; Wed, 30 Nov 2022 08:51:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf6jkx8wMhp8DwijmvFCuufkC6fW64uAZYfyXVFNePMhe8yf2zbDVCBWJmv8M9k+vrfBBNgp X-Received: by 2002:a17:90a:e28d:b0:219:26b6:e8d8 with SMTP id d13-20020a17090ae28d00b0021926b6e8d8mr21176019pjz.74.1669827067277; Wed, 30 Nov 2022 08:51:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669827067; cv=none; d=google.com; s=arc-20160816; b=PgFt6rk5BM+oPZoYFH2/C+nV45BI0FxpBkriHa8v9YHXANj+fw+y6OrOrvCnP1+Hgd l5qLponRqz7oGdS4amdGhwEW5xZ0I5u7TAZm1uLRss1J8Pv5PAVqgVDHs8NDZkG2zAEZ pSnOuXfQ1dqS5kWKpGofpd3wPLI9K9m5qVbVJthdHcnwVfxDC1rZCJdiE7gTCdYCA72E eUxCgvYrmmFI/Cjz2YB7k0S5PJLfaxScDazNJ/iOtu9qsBHD+cs7Hg8lx7TTILjpw424 E4sKbHK14ieb9xs4aJxa/cM4lJpGfa3aNJk/Z4KwlEzMAj7qBFYs8vuIPhjGR34OM3EA 5EOw== 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:dkim-signature; bh=YMnxzDYESOmO1bsI+JVo/ClbyXf7eGdqOyTWrF8ARhk=; b=U+/JA2R2PEgb2kxemD4CgP046Az3U4zYPqVfLgom+8kh+yiWkoPRNLhKrIdS4TYxF2 JV4qbFPJ4D2rg1Tt4gDXh2Yke3K8FOsMYMf7h1cgBKT8BhPs3fGeRF6kMBdnKaL3HxO8 rN0d3fLvunlJk1Tzlr07P4JxfEWz4BFwvgSsp/+1knrIP6zaKKOHFS7u8U8bIXONc9OW TKbivOgXQ3/lOhAhtaSX3+ZqwLeNbyc7wXd55Y7XPQAHhmnEMnm2daCN5ffWUPJOyhtR FGnwhuB60LuX2sbdeaN9YtYaUk3+9UDiYXwCSE6onbJMM6a7OpqUoEcDNI3vwSBGLtMC 3nWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=WV2AjZfU; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a4-20020a621a04000000b0056ca60d51d6si2005283pfa.365.2022.11.30.08.50.51; Wed, 30 Nov 2022 08:51:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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=@suse.cz header.s=susede2_rsa header.b=WV2AjZfU; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230297AbiK3QgV (ORCPT + 99 others); Wed, 30 Nov 2022 11:36:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230302AbiK3QgM (ORCPT ); Wed, 30 Nov 2022 11:36:12 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18B91880F6 for ; Wed, 30 Nov 2022 08:36:10 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B0AF821B10; Wed, 30 Nov 2022 16:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1669826169; h=from:from:reply-to: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=YMnxzDYESOmO1bsI+JVo/ClbyXf7eGdqOyTWrF8ARhk=; b=WV2AjZfUaJPPA93O7pzvADWdN1lEVb1I3RHZAS+JL46t4AXX1QiPp+AqMttp2yS8OvNRBL fZLQIwxIvcaRz3yn1p+3LbYWzQ0DIRNNT30kRlLwair/b7eCYTq+E8exNe+s0SfuJcHFkY +Syxtdk0Z0Wtpm0Kw379evKpLQx4mU8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1669826169; h=from:from:reply-to: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=YMnxzDYESOmO1bsI+JVo/ClbyXf7eGdqOyTWrF8ARhk=; b=6MeaA6U5jVyrmeua7TECFnhkd60cbT8uzzoREHelYPbibYzL4veeMRKAoeApemMcwHbCDU 9qmIe5Xe7X4fFqBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A462A13A70; Wed, 30 Nov 2022 16:36:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id b4ofKHmGh2NeQgAAMHmgww (envelope-from ); Wed, 30 Nov 2022 16:36:09 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id BEA49A0719; Wed, 30 Nov 2022 17:36:08 +0100 (CET) From: Jan Kara To: Ted Tso Cc: , Christoph Hellwig , Jan Kara Subject: [PATCH 5/9] ext4: Add support for writepages calls that cannot map blocks Date: Wed, 30 Nov 2022 17:35:56 +0100 Message-Id: <20221130163608.29034-5-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221130162435.2324-1-jack@suse.cz> References: <20221130162435.2324-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2791; i=jack@suse.cz; h=from:subject; bh=1Ip3MZjlyQjO60nkOhMQw/8deboRByYPhqa834ojFow=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjh4ZsQqJ+Yyih4Pr4qSNHh0Qv4DOctXgRNexz81Pr hoXkrZ6JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY4eGbAAKCRCcnaoHP2RA2TTcB/ 0bIOrYuL+kJoM6060hsDO9oKmw2zfzjBcmbJON3Ags0AsqwUwQN/TUAeALhfEw5Ykw77ZEPeoRSfJV Zzh5ZYFfKngTxi1CxqrGbXnqXP4C8sWOAMgXyGFtO3ULNhb68pzRqFmnM7s/F+leDdkT0g8ZbfIarl ShKFRIxIajhiD8kROLuVbMypvOLE6BZK6Czp3ntgHMwTr+JZjNCngLcVIsM4WE5U56VpGsHRegYL7h nnoHj8OE6gfz0jHcr+jkwVMPH1/WE1ScH7YO9nWmVWS6UyR96I+CpWiXMK6BoCpCi3+cUkfBOdBQ/g Xsddc3+P1IGOaX8zRG6Dnp4SKS2mEw X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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-ext4@vger.kernel.org Add support for calls to ext4_writepages() than cannot map blocks. These will be issued from jbd2 transaction commit code. Signed-off-by: Jan Kara --- fs/ext4/inode.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 43eb175d0c1c..1cde20eb6500 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1557,6 +1557,7 @@ struct mpage_da_data { struct ext4_map_blocks map; struct ext4_io_submit io_submit; /* IO submission data */ unsigned int do_map:1; + unsigned int can_map:1; /* Can writepages call map blocks? */ unsigned int scanned_until_end:1; }; @@ -2549,6 +2550,19 @@ static int ext4_da_writepages_trans_blocks(struct inode *inode) MAX_WRITEPAGES_EXTENT_LEN + bpp - 1, bpp); } +/* Return true if the page needs to be written as part of transaction commit */ +static bool ext4_page_nomap_can_writeout(struct page *page) +{ + struct buffer_head *bh, *head; + + bh = head = page_buffers(page); + do { + if (buffer_dirty(bh) && buffer_mapped(bh) && !buffer_delay(bh)) + return true; + } while ((bh = bh->b_this_page) != head); + return false; +} + /* * mpage_prepare_extent_to_map - find & lock contiguous range of dirty pages * and underlying extent to map @@ -2651,14 +2665,30 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) if (mpd->map.m_len == 0) mpd->first_page = page->index; mpd->next_page = page->index + 1; - /* Add all dirty buffers to mpd */ - lblk = ((ext4_lblk_t)page->index) << - (PAGE_SHIFT - blkbits); - head = page_buffers(page); - err = mpage_process_page_bufs(mpd, head, head, lblk); - if (err <= 0) - goto out; - err = 0; + /* + * Writeout for transaction commit where we cannot + * modify metadata is simple. Just submit the page. + */ + if (!mpd->can_map) { + if (ext4_page_nomap_can_writeout(page)) { + err = mpage_submit_page(mpd, page); + if (err < 0) + goto out; + } else { + unlock_page(page); + mpd->first_page++; + } + } else { + /* Add all dirty buffers to mpd */ + lblk = ((ext4_lblk_t)page->index) << + (PAGE_SHIFT - blkbits); + head = page_buffers(page); + err = mpage_process_page_bufs(mpd, head, head, + lblk); + if (err <= 0) + goto out; + err = 0; + } left--; } pagevec_release(&pvec); @@ -2778,6 +2808,7 @@ static int ext4_writepages(struct address_space *mapping, */ mpd.do_map = 0; mpd.scanned_until_end = 0; + mpd.can_map = 1; mpd.io_submit.io_end = ext4_init_io_end(inode, GFP_KERNEL); if (!mpd.io_submit.io_end) { ret = -ENOMEM; -- 2.35.3