Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6513124rdb; Tue, 2 Jan 2024 04:45:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHi7+Vbrx+dF8Xo+GVF3H+LAcgzCzew6EsQaIDoPRTn9YZBF3z26e+yjLQ5muSV6Y4pUZ8+ X-Received: by 2002:a05:6e02:168a:b0:35f:bcc8:d578 with SMTP id f10-20020a056e02168a00b0035fbcc8d578mr23168989ila.27.1704199503035; Tue, 02 Jan 2024 04:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704199503; cv=none; d=google.com; s=arc-20160816; b=dm4mhHw5N71A8zFYWO+8UL9o6nqLHths0MhsYqeu7Ck6RwIpRXPUkGq3M9K+XZWiR8 zF+LNNPYvww1uyo8n6vj7zIDj3VgDZqJWJ5sVBwooXcqyAt5HnyFalqaAFhH8xKzeuqF 1kM0cwb9DjP+aS1VxbCBS7SkQT4UbnN3Jp/fUupYcwvHwW7iY2IRYqobx91wEGXnLUVx 4rdR5W3TLBZMUPqzMv08EFf2eKe15vL45FvQLsauUW92OdIihRaLewVrpqzsQiQEDcmx MuX51+51uafmrKGhOUyXRbsKjgvA+W54EDkD0JxtNwYkiSWWNlvgLdRmVOL9/ccnm2HP FHTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=DIcdqiMoOH5wnufmVPOCwbErzSVlQnTOpemmkCPNNtA=; fh=yWWoL3IRufgA/+2kSpO6uyfw9eN3ZOO7zvul0qbDPkA=; b=nf6ZPO8rCyjI5baWkJAJkBJo0MkP8oL7QIE78mSHPfn/nfuP6XSDssIlJAb4NxFI4K XJgJYxx6Iv6isTdWyIiqFQjsNOJ/+h+ItbrDf5q6G9iUcpr/etAEgLzsEiajhctUNEpB 5FZw26FBuONIBTQQ3c9hBBcJYcpBWClkf+nwgX21JjwwxDDQ1wWBRyETp1KW/UT3ooSa Mcji1E2yrFnDxFyxtsa0wpyO6dOXKJPlgyiqVKK5+9RKPHDPkYvz91ZPBvyyayCAZyDb HoUpAJ98N/RZxqzIflckT2feVs8VPDgoJUPk+oBYslpuxYr4emxqdlooBEprxfe36aEQ GusA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-616-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-616-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s5-20020a637705000000b005ce17149bb0si14647350pgc.843.2024.01.02.04.45.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 04:45:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-616-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-616-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-616-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D6F522817F8 for ; Tue, 2 Jan 2024 12:44:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E6CC156FB; Tue, 2 Jan 2024 12:42:22 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3769A154BB; Tue, 2 Jan 2024 12:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4T4CD73xCcz4f3l8D; Tue, 2 Jan 2024 20:42:15 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 442EF1A6C6A; Tue, 2 Jan 2024 20:42:17 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgBnwUGUBJRl+EvDFQ--.31823S26; Tue, 02 Jan 2024 20:42:17 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v2 22/25] ext4: fall back to buffer_head path for defrag Date: Tue, 2 Jan 2024 20:39:15 +0800 Message-Id: <20240102123918.799062-23-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240102123918.799062-1-yi.zhang@huaweicloud.com> References: <20240102123918.799062-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:gCh0CgBnwUGUBJRl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Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Online defrag doesn't support iomap path yet, so we have to fall back to buffer_head path for inodes which have been useing iomap. Fall back active inode is dangerous, we must writeback and drop all dirty pages under inode lock and mapping->invalidate_lock, those can protect us from adding new folios into mapping. Signed-off-by: Zhang Yi --- fs/ext4/move_extent.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 3aa57376d9c2..7a9ca71d4cac 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -538,6 +538,34 @@ mext_check_arguments(struct inode *orig_inode, return 0; } +/* + * Disable buffered iomap path for the inode that requiring move extents, + * fallback to buffer_head path. + */ +static int ext4_disable_buffered_iomap_aops(struct inode *inode) +{ + int err; + + /* + * The buffered_head aops don't know how to handle folios + * dirtied by iomap, so before falling back, flush all dirty + * folios the inode has. + */ + filemap_invalidate_lock(inode->i_mapping); + err = filemap_write_and_wait(inode->i_mapping); + if (err < 0) { + filemap_invalidate_unlock(inode->i_mapping); + return err; + } + truncate_inode_pages(inode->i_mapping, 0); + + ext4_clear_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + ext4_set_aops(inode); + filemap_invalidate_unlock(inode->i_mapping); + + return 0; +} + /** * ext4_move_extents - Exchange the specified range of a file * @@ -609,6 +637,12 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk, inode_dio_wait(orig_inode); inode_dio_wait(donor_inode); + /* Fallback to buffer_head aops for inodes with buffered iomap aops */ + if (ext4_test_inode_state(orig_inode, EXT4_STATE_BUFFERED_IOMAP)) + ext4_disable_buffered_iomap_aops(orig_inode); + if (ext4_test_inode_state(donor_inode, EXT4_STATE_BUFFERED_IOMAP)) + ext4_disable_buffered_iomap_aops(donor_inode); + /* Protect extent tree against block allocations via delalloc */ ext4_double_down_write_data_sem(orig_inode, donor_inode); /* Check the filesystem environment whether move_extent can be done */ -- 2.39.2