Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp205612lqj; Wed, 10 Apr 2024 08:12:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUk4lozidJYSPgfuSblNNzRX79RyMpjj1VyZ2nG8TkVZQhJ88QpLuMif+TB2K46wRsBrZaKjHgDJUA1FVYfFxPWQ1epT4gPWd5tESGtpw== X-Google-Smtp-Source: AGHT+IEc3gU0fZ3/rCw2qCoOrfLfK1xxeEcPy7ql5IqHf1QHIpdKP5mmy6bavb3J0ftJV+QuH83r X-Received: by 2002:a17:90b:30d6:b0:2a2:dd53:828b with SMTP id hi22-20020a17090b30d600b002a2dd53828bmr2768690pjb.43.1712761926486; Wed, 10 Apr 2024 08:12:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712761926; cv=pass; d=google.com; s=arc-20160816; b=PeYdHqGMF8EaByZfHzGyqJgAEiULw6khfv8+YFhvNDuInuSthjhY3EKO3ZkPNe6EW2 d5n7e6ZVxjGwdzGRKJfk27q6bw5wW24AzNf/K0qlPvtKf7gW5EGUMmSirQfZC/ajjN60 YsrwS3YUbct06LlZmsXFaCjSB3Lk2upkR1Hv7p81c0bpVXRxOsvR43WivMOzfXPM92Yj FD14ae0+YrLfZWPBF6bDpiO+CgGmbtYvNJk+wSa7mxTOAXS/t+RYV49FEysMBRmIrKe+ 9gsDUftHVU2hM3CCa1N86FsRuoagZxl6rq0umJY/XXSZXXR9htVFJxFLYvby7wxMnsKE d3OQ== ARC-Message-Signature: i=2; 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=G63A/1vzHT8HBZ1GnRpYOGjnssd8Ud0KFI6wZDe0IEA=; fh=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=J49x2IMne+LOuJ356ZopD/IWCSP0okbj309wKQuO+d9oCKPyViXkiJqG9L1FGSBHi+ yP8KJyJLkca9jK25YRysho5I8xiXE1m5mpt0aqLcCVo3ihqBrdMmh0jmYxlvC4s+rL8R /t/VjtACgE2hHkv9Ze+5BnxeN92UcVQPiyykoRctT0qhZVhl2IyPBkKB6wfYY0lF8pUr LW/OOVCCIEF6UZv3QBERJRT+jt2oh8yElsXS6UVUSgH45TiFxWlkNEhe55IC9Q7VecbS oMVDQmvhxZJdw77Nr99xR1L3LBg7uvg/XRB8iHXAPbvQqlVeGnoWT0n+zxJgSaHFCSGf //Wg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2001-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2001-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 l3-20020a17090a408300b002a5a407e79csi1686042pjg.159.2024.04.10.08.12.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 08:12:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2001-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; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2001-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2001-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 2F760289690 for ; Wed, 10 Apr 2024 15:12:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F86116E874; Wed, 10 Apr 2024 15:11:55 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (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 ED7B916DEB3; Wed, 10 Apr 2024 15:11:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712761915; cv=none; b=F/ixcgKAfcp5OUoT2bdbcm3UOubK+YTksr4QeRrpz8j8FnoqdI6PXL80A+e6aiinnCFophoJjq6da8WZAu6N/W2N9vnhDa30D7FuCL6EeI3eaORy8U1wfXPlcfNbgu3o+/4hQnME+Uj8CfbcdoRcUFeJhEmIidvnOlB3z32mPzg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712761915; c=relaxed/simple; bh=2L9ruEgKU7GYbMGJOT2FsQxcS+TeocaV5OhumlCSjAk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kCqamYHrAB0mpIKw3hFH/mHRRNw+5gaFOegCxju5VhCwt/YvzskFZ9GSN2DP+LHTvwZIZ6WelQm5tHsoDqciccUWGEL/MK3ojCZNPIE2Gr4+7VaqRRen1ZbZ4pqBAw4pqKatUcdcsz17euUnNQL2wCRb2ROa0Nz9/+aFK+EGhbk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF5rs57vfz4f3khg; Wed, 10 Apr 2024 23:11:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 8B4C61A0175; Wed, 10 Apr 2024 23:11:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S4; Wed, 10 Apr 2024 23:11:48 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, david@fromorbit.com, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v4 29/34] ext4: fall back to buffer_head path for defrag Date: Wed, 10 Apr 2024 23:03:08 +0800 Message-Id: <20240410150313.2820364-1-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-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:cCh0CgAn9g4orBZmFSt+Jg--.51485S4 X-Coremail-Antispam: 1UD129KBjvJXoW7uw45KryfZr4UWr15ZF1xuFg_yoW8Kry5pr 9Ikr15Kr4DXas29Fn3ta4UZr1rK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M-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Online defrag doesn't support iomap path yet, we have to fall back to buffer_head path for the inode which has been using iomap. Changing active inode is dangerous, before we start, we must hold the inode lock and the mapping->invalidate_lock, and writeback all dirty folios and drop the inode's pagecache. 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 7cd4afa4de1d..3db255385367 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