From patchwork Tue Oct 5 06:22:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12535667 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46DECC433EF for ; Tue, 5 Oct 2021 06:23:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26E746121F for ; Tue, 5 Oct 2021 06:23:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232108AbhJEGZT (ORCPT ); Tue, 5 Oct 2021 02:25:19 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:61147 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230526AbhJEGZS (ORCPT ); Tue, 5 Oct 2021 02:25:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1633415008; x=1664951008; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xkOZzVuaaa34XAOELRY3PAn+4zw/JTz3Eo2eWbT34NE=; b=UdXD1OkkaAD5azTD43KJR9aVmBZEhFrVtICWZrBx42Jw6GcgPk9+RnJ/ rUDHQjvQ9hgCpHYURJhB2HQpVQq/nGwUMja11F/q//bRBAwyM132yrJgh jhgFZbmhkgh/C+69cItrHV3gk5ro5q2HsUH9WXPa/nYoFZmVZSh3munxf Rtk/ut7lvirulx84arzFwwsRcmL5x/8VWFpRFNmjJme/UezT1r1QaAcnf fyDxD4eW4BPKUigC4Q/giz6MbTbX+zQQ7cHAL1BKPhZB5CF5I6M07MEqS ldFhme2tHl0/1rLeIsXACzHovIv/tZjQf2wR2tQH2o6+b3c1wIN2AuR0I A==; X-IronPort-AV: E=Sophos;i="5.85,347,1624291200"; d="scan'208";a="186648910" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Oct 2021 14:23:28 +0800 IronPort-SDR: B1GJAYAK6W5vvjuOnKiq9U90+7awDecDwlxpuAiShKu2c+LlxMYGiAMWSZa5Rbi3CVngoMgjoh EcAQcGk+hG/8lxpFykeMbQZ3aJ1VAGjpsyIm9tPTbHav2VF6F4HK1KYY49f02oYn84KGay+UlG XZ7Oe9LvhTGfpJqo92xqoW25yvpF2+2coTiprXunTj6VKfhqXidIgimVsDodqNRwPoCTYrsFZa I8LKzL0IJipDjW484HN8zwQXLkQQddYbUKT1TT5/mpPjHl7MaoEHduvvm05E1VVzPegxTZAtOx VPn/auSebuaXCyxluE3MFDd6 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 22:57:52 -0700 IronPort-SDR: Y1W2rjn35dCkGFkR5YA8teOlIpRWgEguIRgj7WYfZRGgr1BquifFPHyyINIHbXJw1Ldn6UbgVs 9w/GbkyQYmXblckSHvHe1NhW98bjjc76dd/MzmiasZty9qvOSpr6D9CuJ7O/kUZ1PLpaxyrzmh WSxjW38iV5TR3sbhHgfgdmTDDE2v/gfoj0okinct39y05zkjTu/Bg1v0jC8Zk67QcJ1v8TQeno dRTSjYz0dHldf7NzAQKsG8T/DSQtGc4p2evdSt4rM/tm31JWju9ucasEf8VnKObolgSDFabqRS 1D8= WDCIronportException: Internal Received: from g8961f3.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.178]) by uls-op-cesaip01.wdc.com with ESMTP; 04 Oct 2021 23:23:28 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: David Sterba , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v2 1/7] btrfs-progs: mkfs: do not set zone size on non-zoned mode Date: Tue, 5 Oct 2021 15:22:59 +0900 Message-Id: <20211005062305.549871-2-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211005062305.549871-1-naohiro.aota@wdc.com> References: <20211005062305.549871-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Since zone_size() returns an emulated zone size even for non-zoned device, we cannot use cfg.zone_size to determine the device is zoned or not. Set zone_size = 0 on non-zoned mode. Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota Signed-off-by: David Sterba --- mkfs/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mkfs/main.c b/mkfs/main.c index 8a4c9523d601..314d608a5cc5 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -1357,7 +1357,10 @@ int BOX_MAIN(mkfs)(int argc, char **argv) mkfs_cfg.features = features; mkfs_cfg.runtime_features = runtime_features; mkfs_cfg.csum_type = csum_type; - mkfs_cfg.zone_size = zone_size(file); + if (zoned) + mkfs_cfg.zone_size = zone_size(file); + else + mkfs_cfg.zone_size = 0; ret = make_btrfs(fd, &mkfs_cfg); if (ret) { From patchwork Tue Oct 5 06:23:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12535669 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59735C4332F for ; Tue, 5 Oct 2021 06:23:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3620561181 for ; Tue, 5 Oct 2021 06:23:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232290AbhJEGZU (ORCPT ); Tue, 5 Oct 2021 02:25:20 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:61147 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232130AbhJEGZT (ORCPT ); Tue, 5 Oct 2021 02:25:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1633415009; x=1664951009; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0stDaJyqrlnljh3g28efsfKMlgZ1scXXQJ6Tjh6+ao8=; b=VIBUXkct2BWlukiu0cH5U5c7+s4NMC3avGUduApKt2ObNrkm8C9XW5dm uTaFOeX6Y27Cg0ntHsHhdM+jkgc44yokqebts4sxFgClhPVHJl/EWJGfl +Weka+IBN824gkVGAV5jZ0uD2eBA+/6IBLlcAhAxrD6kCz+ZXcwPy3qzc NcuQ1dx5AJxnUsduaVq3LtYKixs+C0M4NHpeC0qsImu8PU6UqUKrPmNqe R/iKvUtgOnCjqZehhq/EZ2SIGce0nuH2tf3nIJUl//boG8YIlhC5kGVlv RHYY+us14mbB7Qo0px8ufmhRDNC94W8O6uaj089Stpt1czSXkIlncNLWB Q==; X-IronPort-AV: E=Sophos;i="5.85,347,1624291200"; d="scan'208";a="186648911" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Oct 2021 14:23:29 +0800 IronPort-SDR: t9OSMgBMCgPKDjEPPOLRIhMpIr2EBuTMBLVanVA6wnh7K7tnnOBOqn7kIg/6ff64/Amwrkd9rh LUksJ1mIPcAAseBb37H801ek/56kU7taAWTc2aoBisyryFz98t/Oj0uqitokeDQ+qVp2VebTcH VBrSlEbNboF1U1OT0j+L1e7rjJAuxA3l/y0BZVZ87s0SyWOBX8c9/PFgMJj6M7+uyqEN6GlSR1 eIrAq2Yl2ImLhSiba6M9WZeWJ7GiKRR7E/bUoKZK5GTXs07AwyDsW3Cnwy6zJ9r8jKQUQQxCFp 2Sh5VhIvZqLShSVHR6csK60H Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 22:57:53 -0700 IronPort-SDR: IRQUFgtdG2oaxyh1ypeQKFS7ZbqR+q73tuHKzBDDKvOY1QNRnIS5we2PD07CLE6usnGudlBG7l iQrWCPoVe5KNleRyNFzIhDi0hWlaCC4NdTmx7clwF4VIitUmYPQkoJTyUB5cetuoh3vw19r6+y AnNz9XulObpAl3+x3XMZxGjzjSeqR7seNum0V9QuZDYYkKdEN+v56N5sY/MB0YVyto9Qtz1JN/ UOvchCDB89FC+6RSOdwzjGgdvZqYRwmezftxrgvZNzsl9se+SzUkwpUINb3Fyz36PiQ50Ytk2B 3ZI= WDCIronportException: Internal Received: from g8961f3.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.178]) by uls-op-cesaip01.wdc.com with ESMTP; 04 Oct 2021 23:23:29 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: David Sterba , Naohiro Aota Subject: [PATCH v2 2/7] btrfs-progs: set eb->fs_info properly Date: Tue, 5 Oct 2021 15:23:00 +0900 Message-Id: <20211005062305.549871-3-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211005062305.549871-1-naohiro.aota@wdc.com> References: <20211005062305.549871-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Several extent_buffer initialization misses fs_info setting. This is OK before the following patch ("btrfs-progs: use direct-io for zoned device") as eb->fs_info is not always necessary. But, after that patch, we will use fs_info to determine it is zoned or not and that causes segfault in such cases. Properly set fs_info when initializing extent_buffers to fix the issue. Signed-off-by: Naohiro Aota --- convert/main.c | 1 + kernel-shared/volumes.c | 2 ++ mkfs/rootdir.c | 1 + 3 files changed, 4 insertions(+) diff --git a/convert/main.c b/convert/main.c index b705946b1312..223eebad2e72 100644 --- a/convert/main.c +++ b/convert/main.c @@ -397,6 +397,7 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans, } eb->start = key.objectid; eb->len = key.offset; + eb->fs_info = root->fs_info; /* Write the data */ ret = write_and_map_eb(root->fs_info, eb); diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index b2a6b04f8e3d..2ef2a8618d1f 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -2567,6 +2567,7 @@ static int split_eb_for_raid56(struct btrfs_fs_info *info, eb->flags = 0; eb->fd = -1; eb->dev_bytenr = (u64)-1; + eb->fs_info = info; this_eb_start = raid_map[i]; @@ -2638,6 +2639,7 @@ int write_raid56_with_parity(struct btrfs_fs_info *info, new_eb->fd = multi->stripes[i].dev->fd; multi->stripes[i].dev->total_ios++; new_eb->len = stripe_len; + new_eb->fs_info = info; if (raid_map[i] == BTRFS_RAID5_P_STRIPE) p_eb = new_eb; diff --git a/mkfs/rootdir.c b/mkfs/rootdir.c index c2e14daf6663..16ff257ac408 100644 --- a/mkfs/rootdir.c +++ b/mkfs/rootdir.c @@ -397,6 +397,7 @@ again: eb->start = first_block + bytes_read; eb->len = sectorsize; + eb->fs_info = root->fs_info; /* * we're doing the csum before we record the extent, but From patchwork Tue Oct 5 06:23:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12535665 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 137A8C43219 for ; Tue, 5 Oct 2021 06:23:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3AFE61181 for ; Tue, 5 Oct 2021 06:23:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232331AbhJEGZY (ORCPT ); Tue, 5 Oct 2021 02:25:24 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:61147 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232251AbhJEGZU (ORCPT ); Tue, 5 Oct 2021 02:25:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1633415010; x=1664951010; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=O9+wBmea7KVoNCvNn4QTRtHx3+jF1SBvnLQ97OVdusI=; b=PDTZxy/cAMLD1ze9Mp69rjfQW37oFafsyTVRdloH1W/VLRZx2JQLCLiw Sw9wPqTdovY8ZSRfIlRaKiomOdEAKrT+EneRs4ghoHRSiOGdhnsYFtyVU WBrA/plyc3iI3F9w8CzEsqXMdMnvAt/IiwwRGhUghkyhTYgeoDckFwlhw nU7WupIHdReeFuCptbTHQgltUdbcUQYu2jXCwFFigHe55/3ImjQSp0jwy tACqJEqP4t3R5hplSZ0dLwnjZAllgbZTCfyvSyAR3mqb1uq1AgiAFwn7L HPDzXOVhR2w1KIPWzJRmMXFHLKVrk0OxZWVFNOru1gPEN2ba/xwOmGDyR Q==; X-IronPort-AV: E=Sophos;i="5.85,347,1624291200"; d="scan'208";a="186648914" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Oct 2021 14:23:30 +0800 IronPort-SDR: DjODtX1FDTaOSnmHrYLaXSJAzDm24TunhwQnQLHB2vwoxI0uUpaelVe7GwtGXgi+PgLM92IIYU FdXH5sJiu8R2ENdTsUFBOKaAYu6kSiOSZVO1muyXuivjXYvLReVwVYPsxmed2H3wS8bQbd9BBw n467fZhT9sFpg7xcZUeI8Sq5pvw3b9D6Iu0mV8RdBgT9kk2ceXFNxR1qJ2CcWL5V/VWwdaK7mW zkNWZD+wiKA9HDixDsNIn2Fxi/MoiEJtGC049JLScnnug33Qkd4jafHNOkVy9W8gLNDUAVWhSZ tZ/GUqg74f2zu3rwIJsRldzf Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 22:57:54 -0700 IronPort-SDR: k9AwSUKoyXfKgZLQV4Zpe8husFuLdtcy3aYhjOuxLTlUZv6kyFskaLazH3hcFVFbTh1x+ROCu6 cwKqB7ZqnxgZ4PEvoWxQSvQ+uYQBtlG2CJPsWai8nAOIVRRFsQmCDkOkFrmHggd6Ka1QHgutgb 9pOOf7BKFh12GEzMTFaITUGDa2DQkrjIeS1KiLNLPjaZ9In188sQmIcwdObW1HMslUNG8nlu+A L0uW5WPexQ6qJ4qK/6a9z6PXID9YUIuB6lpybbPLq6q5kmLnZvUs8/ew6KV1+fD0eG8ekoGLmG Vog= WDCIronportException: Internal Received: from g8961f3.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.178]) by uls-op-cesaip01.wdc.com with ESMTP; 04 Oct 2021 23:23:30 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: David Sterba , Naohiro Aota Subject: [PATCH v2 3/7] btrfs-progs: drop ZONED flag from BTRFS_CONVERT_ALLOWED_FEATURES Date: Tue, 5 Oct 2021 15:23:01 +0900 Message-Id: <20211005062305.549871-4-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211005062305.549871-1-naohiro.aota@wdc.com> References: <20211005062305.549871-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Since we cannot create ext*/reiserfs on a zoned device, it is useless to allow ZONED feature when converting a file system. Drop ZONED flag from BTRFS_CONVERT_ALLOWED_FEATURES. Signed-off-by: Naohiro Aota --- common/fsfeatures.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/fsfeatures.h b/common/fsfeatures.h index 163588e52933..9e39c667b900 100644 --- a/common/fsfeatures.h +++ b/common/fsfeatures.h @@ -39,8 +39,7 @@ | BTRFS_FEATURE_INCOMPAT_BIG_METADATA \ | BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF \ | BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA \ - | BTRFS_FEATURE_INCOMPAT_NO_HOLES \ - | BTRFS_FEATURE_INCOMPAT_ZONED) + | BTRFS_FEATURE_INCOMPAT_NO_HOLES) #define BTRFS_FEATURE_LIST_ALL (1ULL << 63) From patchwork Tue Oct 5 06:23:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12535673 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D95F8C433FE for ; Tue, 5 Oct 2021 06:23:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF4D16121F for ; Tue, 5 Oct 2021 06:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232327AbhJEGZZ (ORCPT ); Tue, 5 Oct 2021 02:25:25 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:61147 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232305AbhJEGZV (ORCPT ); Tue, 5 Oct 2021 02:25:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1633415011; x=1664951011; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jv8pLMxV6PhfaH3nN9tKbSuoN7QYNwbyOFCiv7B8Qg0=; b=ajCcBE3APYyHvgj3ZI57ZJUgs/gRQ3eLIDaQbSsL1PEZhB1syzIrrkB/ TE4Rbz8HZRMN0g86EF1F+0Qmj0EaN7RqjaTp4tGdwToKboZWT5tPN9gXH Uo7AWlEyhmZT4B7mwGJ9cVwFmPo4qm8GeUGk8qDanwQJilCAbWGlgSINc 06tzhsa10XU4dTqezNWCTMYfd6fzQa4jw4TQBk/kJGJ1uXNldpvGRVEAw qJbutI9rq0Y2iWz8mXGU8cJ7ZLYMrgOjDW3PN7h+icN+JCA/2ZBmAqfyp SqECemfLBhAq7YhO2ZkJMU1GJY89Lb9/jCSnmKZunk/KbrO62UXdBL0lE Q==; X-IronPort-AV: E=Sophos;i="5.85,347,1624291200"; d="scan'208";a="186648915" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Oct 2021 14:23:31 +0800 IronPort-SDR: 46R/hzNX8aMn1Pw566l5WUCl3GvPKoj9iZI30LQHWWmWN8rwLMB1EyQjSzhdSbsiHUHxwi3NR2 K0IPWc9ww+rw3RoxVJaDZknODVlw6V+LTeNClpQIhJSydzyB+nKnQF35YGiu3sBqVk1jp7wRnl a8JdTKzHfe0hncDfx20QB3Ed7VMLRHW+fqt9a14m03OtSrh5BZsVBtDXe06Id6x+9HPZvzM5rq vDlpUvGoukZZXMpr8EEzY5rSEkM0kKAwec8hwZu3gzDExuywrOF7of/wHHYjBbpY7PgpBZxsVd Aao8DpcnqPG+Oqzf02pLF4DF Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 22:57:55 -0700 IronPort-SDR: AVZfgq8XXanzZoD9y94d5wm0tLXD/mPApTWk//fXG/WteR3xq5Wy95pNbfjOCGhLaXR3hJfjAk p2v0x7egbyp7C2DQZkXLwEcbRGYc4PcUsvqZZMD+QOo4fYag875BvkXIXRXTL11CPbufJw4LeW zjv7JNMl5oNRCj20UNBEsxQGGHIVXPR4NJoZwH+TgulbUhMK2hJFePCZ0hAvk4a4WBhNJyTp+T Z4dY14Nrlo5q3VeMbssiLGrvacCHiwdz+O2vTAJgWH4vr0F0Xa7SHY2YLqdPXAlqjlH7kA3OaI Qfc= WDCIronportException: Internal Received: from g8961f3.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.178]) by uls-op-cesaip01.wdc.com with ESMTP; 04 Oct 2021 23:23:31 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: David Sterba , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v2 4/7] btrfs-progs: introduce btrfs_pwrite wrapper for pwrite Date: Tue, 5 Oct 2021 15:23:02 +0900 Message-Id: <20211005062305.549871-5-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211005062305.549871-1-naohiro.aota@wdc.com> References: <20211005062305.549871-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Wrap pwrite with btrfs_pwrite(). It simply calls pwrite() on non-zoned btrfs (= opened without O_DIRECT). On zoned mode (= opened with O_DIRECT), it allocates an aligned bounce buffer, copy the contents and use it for direct-IO writing. Writes in device_zero_blocks() and btrfs_wipe_existing_sb() are a little tricky. We don't have fs_info on our hands, so use zinfo to determine it is a zoned device or not. Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota Signed-off-by: David Sterba --- common/device-utils.c | 76 ++++++++++++++++++++++++++++++++++++--- common/device-utils.h | 19 +++++++++- kernel-shared/extent_io.c | 7 ++-- kernel-shared/zoned.c | 4 +-- mkfs/common.c | 14 +++++--- 5 files changed, 106 insertions(+), 14 deletions(-) diff --git a/common/device-utils.c b/common/device-utils.c index 366154b98218..3e58d6d0a412 100644 --- a/common/device-utils.c +++ b/common/device-utils.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "kernel-lib/sizes.h" #include "kernel-shared/disk-io.h" @@ -95,7 +96,7 @@ int device_discard_blocks(int fd, u64 start, u64 len) /* * Write zeros to the given range [start, start + len) */ -int device_zero_blocks(int fd, off_t start, size_t len) +int device_zero_blocks(int fd, off_t start, size_t len, const bool direct) { char *buf = malloc(len); int ret = 0; @@ -104,7 +105,7 @@ int device_zero_blocks(int fd, off_t start, size_t len) if (!buf) return -ENOMEM; memset(buf, 0, len); - written = pwrite(fd, buf, len, start); + written = btrfs_pwrite(fd, buf, len, start, direct); if (written != len) ret = -EIO; free(buf); @@ -134,7 +135,7 @@ static int zero_dev_clamped(int fd, struct btrfs_zoned_device_info *zinfo, if (zinfo && zinfo->model == ZONED_HOST_MANAGED) return zero_zone_blocks(fd, zinfo, start, end - start); - return device_zero_blocks(fd, start, end - start); + return device_zero_blocks(fd, start, end - start, false); } /* @@ -176,8 +177,10 @@ static int btrfs_wipe_existing_sb(int fd, struct btrfs_zoned_device_info *zinfo) len = sizeof(buf); if (!zone_is_sequential(zinfo, offset)) { + const bool direct = zinfo && zinfo->model == ZONED_HOST_MANAGED; + memset(buf, 0, len); - ret = pwrite(fd, buf, len, offset); + ret = btrfs_pwrite(fd, buf, len, offset, direct); if (ret < 0) { error("cannot wipe existing superblock: %m"); ret = -1; @@ -510,3 +513,68 @@ out: close(sysfs_fd); return ret; } + +ssize_t btrfs_direct_pio(int rw, int fd, void *buf, size_t count, off_t offset) +{ + int alignment; + size_t iosize; + void *bounce_buf = NULL; + struct stat stat_buf; + unsigned long req; + int ret; + ssize_t ret_rw; + + ASSERT(rw == READ || rw == WRITE); + + if (fstat(fd, &stat_buf) == -1) { + error("fstat failed (%m)"); + return 0; + } + + if ((stat_buf.st_mode & S_IFMT) == S_IFBLK) + req = BLKSSZGET; + else + req = FIGETBSZ; + + if (ioctl(fd, req, &alignment)) { + error("failed to get block size: %m"); + return 0; + } + + if (IS_ALIGNED((size_t)buf, alignment) && IS_ALIGNED(count, alignment)) { + if (rw == WRITE) + return pwrite(fd, buf, count, offset); + else + return pread(fd, buf, count, offset); + } + + /* Cannot do anything if the write size is not aligned */ + if (rw == WRITE && !IS_ALIGNED(count, alignment)) { + error("%lu is not aligned to %d", count, alignment); + return 0; + } + + iosize = round_up(count, alignment); + + ret = posix_memalign(&bounce_buf, alignment, iosize); + if (ret) { + error("failed to allocate bounce buffer: %m"); + errno = ret; + return 0; + } + + if (rw == WRITE) { + ASSERT(iosize == count); + memcpy(bounce_buf, buf, count); + ret_rw = pwrite(fd, bounce_buf, iosize, offset); + } else { + ret_rw = pread(fd, bounce_buf, iosize, offset); + if (ret_rw >= count) { + ret_rw = count; + memcpy(buf, bounce_buf, count); + } + } + + free(bounce_buf); + return ret_rw; +} diff --git a/common/device-utils.h b/common/device-utils.h index 099520bf9737..767dab4370e1 100644 --- a/common/device-utils.h +++ b/common/device-utils.h @@ -17,6 +17,8 @@ #ifndef __DEVICE_UTILS_H__ #define __DEVICE_UTILS_H__ +#include +#include #include "kerncompat.h" #include "sys/stat.h" @@ -35,7 +37,7 @@ * Generic block device helpers */ int device_discard_blocks(int fd, u64 start, u64 len); -int device_zero_blocks(int fd, off_t start, size_t len); +int device_zero_blocks(int fd, off_t start, size_t len, const bool direct); u64 device_get_partition_size(const char *dev); u64 device_get_partition_size_fd(int fd); int device_get_queue_param(const char *file, const char *param, char *buf, size_t len); @@ -47,5 +49,20 @@ u64 device_get_zone_size(int fd, const char *name); u64 btrfs_device_size(int fd, struct stat *st); int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret, u64 max_block_count, unsigned opflags); +ssize_t btrfs_direct_pio(int rw, int fd, void *buf, size_t count, off_t offset); + +#ifdef BTRFS_ZONED +static inline ssize_t btrfs_pwrite(int fd, void *buf, size_t count, + off_t offset, bool direct) +{ + if (!direct) + return pwrite(fd, buf, count, offset); + + return btrfs_direct_pio(WRITE, fd, buf, count, offset); +} +#else +#define btrfs_pwrite(fd, buf, count, offset, direct) \ + ({ (void)(direct); pwrite(fd, buf, count, offset); }) +#endif #endif diff --git a/kernel-shared/extent_io.c b/kernel-shared/extent_io.c index d3d79bc8f748..b5984949f431 100644 --- a/kernel-shared/extent_io.c +++ b/kernel-shared/extent_io.c @@ -29,6 +29,7 @@ #include "kernel-shared/ctree.h" #include "kernel-shared/volumes.h" #include "common/utils.h" +#include "common/device-utils.h" #include "common/internal.h" void extent_io_tree_init(struct extent_io_tree *tree) @@ -809,7 +810,8 @@ out: int write_extent_to_disk(struct extent_buffer *eb) { int ret; - ret = pwrite(eb->fd, eb->data, eb->len, eb->dev_bytenr); + ret = btrfs_pwrite(eb->fd, eb->data, eb->len, eb->dev_bytenr, + eb->fs_info->zoned); if (ret < 0) goto out; if (ret != eb->len) { @@ -932,7 +934,8 @@ int write_data_to_disk(struct btrfs_fs_info *info, void *buf, u64 offset, this_len = min(this_len, bytes_left); dev_nr++; - ret = pwrite(device->fd, buf + total_write, this_len, dev_bytenr); + ret = btrfs_pwrite(device->fd, buf + total_write, + this_len, dev_bytenr, info->zoned); if (ret != this_len) { if (ret < 0) { fprintf(stderr, "Error writing to " diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 8d94f98a7fce..c2cce3b5f366 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -424,7 +424,7 @@ int zero_zone_blocks(int fd, struct btrfs_zoned_device_info *zinfo, off_t start, count = zone_len - (ofst & (zone_len - 1)); if (!zone_is_sequential(zinfo, ofst)) { - ret = device_zero_blocks(fd, ofst, count); + ret = device_zero_blocks(fd, ofst, count, true); if (ret != 0) return ret; } @@ -595,7 +595,7 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw) if (rw == READ) ret_sz = pread64(fd, buf, count, mapped); else - ret_sz = pwrite64(fd, buf, count, mapped); + ret_sz = btrfs_pwrite(fd, buf, count, mapped, true); if (ret_sz != count) return ret_sz; diff --git a/mkfs/common.c b/mkfs/common.c index 20a7d1155972..5c8d6ac13a3b 100644 --- a/mkfs/common.c +++ b/mkfs/common.c @@ -54,7 +54,7 @@ static int btrfs_write_empty_tree(int fd, struct btrfs_mkfs_config *cfg, btrfs_set_header_nritems(buf, 0); csum_tree_block_size(buf, btrfs_csum_type_size(cfg->csum_type), 0, cfg->csum_type); - ret = pwrite(fd, buf->data, cfg->nodesize, block); + ret = btrfs_pwrite(fd, buf->data, cfg->nodesize, block, cfg->zone_size); if (ret != cfg->nodesize) return ret < 0 ? -errno : -EIO; return 0; @@ -134,7 +134,8 @@ static int btrfs_create_tree_root(int fd, struct btrfs_mkfs_config *cfg, cfg->csum_type); /* write back root tree */ - ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_ROOT_TREE]); + ret = btrfs_pwrite(fd, buf->data, cfg->nodesize, + cfg->blocks[MKFS_ROOT_TREE], cfg->zone_size); if (ret != cfg->nodesize) return (ret < 0 ? -errno : -EIO); @@ -422,7 +423,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) btrfs_set_header_nritems(buf, nritems); csum_tree_block_size(buf, btrfs_csum_type_size(cfg->csum_type), 0, cfg->csum_type); - ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_EXTENT_TREE]); + ret = btrfs_pwrite(fd, buf->data, cfg->nodesize, + cfg->blocks[MKFS_EXTENT_TREE], cfg->zone_size); if (ret != cfg->nodesize) { ret = (ret < 0 ? -errno : -EIO); goto out; @@ -510,7 +512,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) btrfs_set_header_nritems(buf, nritems); csum_tree_block_size(buf, btrfs_csum_type_size(cfg->csum_type), 0, cfg->csum_type); - ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_CHUNK_TREE]); + ret = btrfs_pwrite(fd, buf->data, cfg->nodesize, + cfg->blocks[MKFS_CHUNK_TREE], cfg->zone_size); if (ret != cfg->nodesize) { ret = (ret < 0 ? -errno : -EIO); goto out; @@ -550,7 +553,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) btrfs_set_header_nritems(buf, nritems); csum_tree_block_size(buf, btrfs_csum_type_size(cfg->csum_type), 0, cfg->csum_type); - ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_DEV_TREE]); + ret = btrfs_pwrite(fd, buf->data, cfg->nodesize, + cfg->blocks[MKFS_DEV_TREE], cfg->zone_size); if (ret != cfg->nodesize) { ret = (ret < 0 ? -errno : -EIO); goto out; From patchwork Tue Oct 5 06:23:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12535677 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE28BC433EF for ; Tue, 5 Oct 2021 06:23:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5F1061181 for ; Tue, 5 Oct 2021 06:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232305AbhJEGZ0 (ORCPT ); Tue, 5 Oct 2021 02:25:26 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:61155 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232307AbhJEGZW (ORCPT ); Tue, 5 Oct 2021 02:25:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1633415012; x=1664951012; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8a0p9tHuZEgvLVcGi902v3FJhMIjJqUyXJToqh9LM5I=; b=MX1aTuV9ct/0R4KG0zHHPfru+XamslQHtytKJHgShBnel/uwfVsh0KCo cvMIPmb714OUwukMkJkyxnzjvekVSu+xyk2gDJY2F7FC2lKAQefErElST qrnOlBRIUM0oh6Pw+87/ogcpsO33FqoUJ7JvfHAqs0c8pITfvBRPnCcfV ZQaV/r39FqKaANpMwpHlrGxvF7rE6YQJLTC/tEzrC1HXNhkys2+e9jo6G 8gk6DlLG9O45/oOcoxgblBiTpr9eRAI7GIoZ/uFpeDy3aBvvhyJm/Jl+C 8l7a5RluAqJS09t7tI0Q1RbHZWzed/TcE+dNLsZ8x5ZnIOgwP1QVEas1k g==; X-IronPort-AV: E=Sophos;i="5.85,347,1624291200"; d="scan'208";a="186648916" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Oct 2021 14:23:32 +0800 IronPort-SDR: /dfe4MjhQrTlY44vqpVkYtOShHIFxjkGki0uhl0804aYTkTbe/5ySDo56/HGTmjtdO79GTwN8X lqiCOojxl30ZX2LXgLLKTKIsCzyhhd23QACRMpCOURXg2gvshKKejWx6QyYnT59p39LPb04nuH BFVf6d7Wcqoi5eb6qb2Iw8PuTzk23Qje3lTuk4T8Ww2lCJUgnBSYEs9049akxv5At2ht6QruOB Q9Q8XN0f2lawK37FSBKVKSr10TWP2zkwMYweDQxwv5s7rETNrZWDqq90/0B0rSThram98XhC6x U/MIsbqPwzxiR1RJ9cn0o6Kl Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 22:57:56 -0700 IronPort-SDR: 9w98P12zR0AGdu5LwEivnV2QmThAkWDusjy8qJ+NeXVvkuZtSGiVZjelNffmMDzJhuru+Qs0Ub LcKiqZ/Wt/ylNWpQ/7wUKQgmtkULP/sgI/KO3a4FahZVrzM5lCdqcM4Tav4VwbPG3qZfn2aQw/ A1j3lviV9iedUI7sLPzi+hu0c7+stOjTAbQBKBqzrTbb1ZfnVnbwy6jDHe/VATwL3eKbYXjSXR HphJQm/i/qrYarw3KCdyrOhgBmKoKIlIBaKAzDaxyMpkA6erfl8NfIqQ501Lfo9VIdPo+LMuOH 4hE= WDCIronportException: Internal Received: from g8961f3.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.178]) by uls-op-cesaip01.wdc.com with ESMTP; 04 Oct 2021 23:23:32 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: David Sterba , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v2 5/7] btrfs-progs: introduce btrfs_pread wrapper for pread Date: Tue, 5 Oct 2021 15:23:03 +0900 Message-Id: <20211005062305.549871-6-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211005062305.549871-1-naohiro.aota@wdc.com> References: <20211005062305.549871-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Wrap pread with btrfs_pread as well. Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota Signed-off-by: David Sterba --- common/device-utils.h | 10 ++++++++++ kernel-shared/disk-io.c | 4 +++- kernel-shared/extent_io.c | 7 ++++--- kernel-shared/zoned.c | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/common/device-utils.h b/common/device-utils.h index 767dab4370e1..f79e746840fc 100644 --- a/common/device-utils.h +++ b/common/device-utils.h @@ -60,9 +60,19 @@ static inline ssize_t btrfs_pwrite(int fd, void *buf, size_t count, return btrfs_direct_pio(WRITE, fd, buf, count, offset); } +static inline ssize_t btrfs_pread(int fd, void *buf, size_t count, off_t offset, + bool direct) +{ + if (!direct) + return pread(fd, buf, count, offset); + + return btrfs_direct_pio(READ, fd, buf, count, offset); +} #else #define btrfs_pwrite(fd, buf, count, offset, direct) \ ({ (void)(direct); pwrite(fd, buf, count, offset); }) +#define btrfs_pread(fd, buf, count, offset, direct) \ + ({ (void)(direct); pread(fd, buf, count, offset); }) #endif #endif diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index 1cda6f3a98af..740500f9fdc9 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -35,6 +35,7 @@ #include "kernel-shared/print-tree.h" #include "common/rbtree-utils.h" #include "common/device-scan.h" +#include "common/device-utils.h" #include "crypto/hash.h" /* specified errno for check_tree_block */ @@ -476,7 +477,8 @@ int read_extent_data(struct btrfs_fs_info *fs_info, char *data, u64 logical, goto err; } - ret = pread64(device->fd, data, *len, multi->stripes[0].physical); + ret = btrfs_pread(device->fd, data, *len, multi->stripes[0].physical, + fs_info->zoned); if (ret != *len) ret = -EIO; else diff --git a/kernel-shared/extent_io.c b/kernel-shared/extent_io.c index b5984949f431..af09ade4025f 100644 --- a/kernel-shared/extent_io.c +++ b/kernel-shared/extent_io.c @@ -793,7 +793,8 @@ int read_extent_from_disk(struct extent_buffer *eb, unsigned long offset, unsigned long len) { int ret; - ret = pread(eb->fd, eb->data + offset, len, eb->dev_bytenr); + ret = btrfs_pread(eb->fd, eb->data + offset, len, eb->dev_bytenr, + eb->fs_info->zoned); if (ret < 0) { ret = -errno; goto out; @@ -850,8 +851,8 @@ int read_data_from_disk(struct btrfs_fs_info *info, void *buf, u64 offset, return -EIO; } - ret = pread(device->fd, buf + total_read, read_len, - multi->stripes[0].physical); + ret = btrfs_pread(device->fd, buf + total_read, read_len, + multi->stripes[0].physical, info->zoned); kfree(multi); if (ret < 0) { fprintf(stderr, "Error reading %llu, %d\n", offset, diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index c2cce3b5f366..f5d2299fc744 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -593,7 +593,7 @@ size_t btrfs_sb_io(int fd, void *buf, off_t offset, int rw) return ret; if (rw == READ) - ret_sz = pread64(fd, buf, count, mapped); + ret_sz = btrfs_pread(fd, buf, count, mapped, true); else ret_sz = btrfs_pwrite(fd, buf, count, mapped, true); From patchwork Tue Oct 5 06:23:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12535671 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFA37C433F5 for ; Tue, 5 Oct 2021 06:23:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2BFB61181 for ; Tue, 5 Oct 2021 06:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232391AbhJEGZY (ORCPT ); Tue, 5 Oct 2021 02:25:24 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:61157 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232327AbhJEGZX (ORCPT ); Tue, 5 Oct 2021 02:25:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1633415013; x=1664951013; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K1fB5ICnOv9vPqUZ94BhSkHs5ngbM4t7Ik+Z0/PVlT0=; b=f96bQ2ACkzRnEg+R9VEOETV0KRMaW21s4bRDydKZqfAh4fdFXTUQPqoO KLLfuBOesg3k9bpPHM7EWUsaAx2LAiLrzXRxdGEFKvwsLAyvQa90q/tGG pARJPf3082CU3roN3QdbflZ0ZKbByJ/DNXSZQsTBIZ1G8JDoPs5WPlsI4 fcWzTDWC178Q/FBUy3gOFQyXGvo7KCUvSrkN0lxTC4DVnhZrql6CTCCwO 04cVr2jBi2TPTmLigQPmxR0oG3WeRQNsW3m1Zm+jSBaFckQVOcSng4zhQ 0f4xTsfRbB/9M0gj7hZyUet0AfOvJXkaTsjC8Tr31Z+pAK3t5AxRlLy1t w==; X-IronPort-AV: E=Sophos;i="5.85,347,1624291200"; d="scan'208";a="186648917" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Oct 2021 14:23:33 +0800 IronPort-SDR: 3P/rPhSG0yB9cC3MzhHFzevXwnBuYZMmaEWlwhYl1FcFm2Zju5Q5NerS3M4GopGv6AEx26FDS7 S8L1yAez81RqF3PSq/bGwEWDd2yUPzeWpyoqV8EhRQf33L/3EbwkiRKBP8qfqT2rEKxe1wJdNF A34lRJCdmv6b0lg4OXD2SdNAvkYvba1Ka1qwmxSF2IaRZhw238eg7K9TcGf9SPXB0DAPsOxs0y KqLqw6Deq03ilrivR6ste5A5Wff/10mXDYbJN7l8UGGvpf94UVj8a446mg6jI2k8SgBcU4CUis O3DEj1kbfuGWhOTXuqgJuhBc Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 22:57:57 -0700 IronPort-SDR: TeMTui04gHF062zZuAX2voYonImexxrW0HuKEa+ChV3SimtMBR33GqOtQukoNl3Qw+20gVETWS 6pFzg2rb/2PALyfF8ew60IAo96QMwWdZR84tYcE6p979IwD11cFO1J88brHOLNY3sQT2J0nA/n KdcDwjOvI4dKN1HU5SdifIHw4h1dB12co1XQGi9rOnXdkTAbyWiFXhL2xIRiTOvY6lOacRbPDH xUds3F7pDmX3TKNDseip2Pi2U2toCB9y4GGw7JcJo2S1JfZZkoVQWvmquEKdbgluaJYci9TJi3 j3M= WDCIronportException: Internal Received: from g8961f3.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.178]) by uls-op-cesaip01.wdc.com with ESMTP; 04 Oct 2021 23:23:33 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: David Sterba , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v2 6/7] btrfs-progs: temporally set zoned flag for initial tree reading Date: Tue, 5 Oct 2021 15:23:04 +0900 Message-Id: <20211005062305.549871-7-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211005062305.549871-1-naohiro.aota@wdc.com> References: <20211005062305.549871-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Functions to read data/metadata e.g. read_extent_from_disk() now depend on the fs_info->zoned flag to determine if they do direct-IO or not. The flag (and zone_size) is not known before reading the chunk tree and it set to 0 while in the initial chunk tree setup process. That will cause btrfs_pread() to fail because it does not align the buffer. Use fcntl() to find out the file descriptor is opened with O_DIRECT or not, and if it is, set the zoned flag to 1 temporally for this initial process. Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota Signed-off-by: David Sterba --- kernel-shared/disk-io.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index 740500f9fdc9..dd48599a5f1f 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -1302,10 +1302,22 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, struct open_ctree_flags *oc if (ret) goto out_devices; + /* + * fs_info->zone_size (and zoned) are not known before reading the + * chunk tree, so it's 0 at this point. But, fs_info->zoned == 0 + * will cause btrfs_pread() not to use an aligned bounce buffer, + * causing EINVAL when the file is opened with O_DIRECT. Temporally + * set zoned = 1 in that case. + */ + if (fcntl(fp, F_GETFL) & O_DIRECT) + fs_info->zoned = 1; + ret = btrfs_setup_chunk_tree_and_device_map(fs_info, ocf->chunk_tree_bytenr); if (ret) goto out_chunk; + fs_info->zoned = 0; + /* Chunk tree root is unable to read, return directly */ if (!fs_info->chunk_root) return fs_info; From patchwork Tue Oct 5 06:23:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12535675 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0933CC4332F for ; Tue, 5 Oct 2021 06:23:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E48A76121F for ; Tue, 5 Oct 2021 06:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232469AbhJEGZ1 (ORCPT ); Tue, 5 Oct 2021 02:25:27 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:61157 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232361AbhJEGZY (ORCPT ); Tue, 5 Oct 2021 02:25:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1633415014; x=1664951014; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=coGRL6ere+uLYVXkW4YuQGcH68/yaIyRKc16YOLoH4I=; b=FOt2L/9W9/Yv8BtoihJ8j8hOQaOriipi6gYQM2iJ/78fFmloC/U3TdLa ZtRtYhmGaqsmOQCMDORFSgw7or2fHJixwp/xDoED2nI+YHMLqg/zTa+IN escsRe2h9Kl5mjt2LTAEpQhIJRugHZScID8OcTKcGi7/CRJp0EwPArLka lT3EU71+upfVCPRFgGbx0OvfJv2A3E4cYZTdjIyT96h3jihXnnpG2/q+1 TXmGkzs4BMr++NX8IgrqjK+cYjCd/7UFHJGHWA9W9ItCoJzLA/HRy14bU Cnak63jT4iQi5PRiwq4R+th9IQXZWM4XC2kFLlqWwsQtwqNNLzebjQvFe g==; X-IronPort-AV: E=Sophos;i="5.85,347,1624291200"; d="scan'208";a="186648918" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Oct 2021 14:23:34 +0800 IronPort-SDR: HYX8jOO2nrj9FyUi5js1yQ1NfltzMyxGc87YYJdAi/9tETLL7OUn0NqMUikBQq/LDDGTIO3wNg TUM0+0bbpjk15u6gqhBU1AmJVabhr2JcgksUPFtvfPH9lvTatnvJmvbkeef1tfbqTGHVPZuznx uv4XzfmHw2iSehganyhGIP6Vk+Oa32xT8aifweLu/iSwKj60FmwDykNguO4IrbVX8O18XkBtEy waCSLU/t3jIR0yar0gDWfNXPUfOm4uCxftDN4axsLnBSDo0krIp64DzYf+Kxq2nsbWNpVHqODx 1XC6OS8RJBUCqo3wVRGIrWNX Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2021 22:57:58 -0700 IronPort-SDR: enm0BsSvdhB5+n1Myyh1Bg0O7+yAfBUz2OSR6t1Mt6eVwjFTcdgydY2IfpMrCE7Hc06PXbsLED 3RAT4jBmRHEVLI8qmWNzUI5Stw2VHk46gj/yTQX98Ok7Xz0RWyaamxRVUhqZTEprehiSZjkOXH TO1/WnpK0/KlHk4OOXZ5RXNtO80DbZGjw7x/3qdcK16TnYUfUckXMYN1Kr+m3ijnfBw7mHb/Be liWjKeO5YcyqV+jQEU4iFHVcvCQ2zoQKWXR8EClEPkyiWGuvlJYh/Wb3w6GrscDkHpFc2fHTxK ydg= WDCIronportException: Internal Received: from g8961f3.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.178]) by uls-op-cesaip01.wdc.com with ESMTP; 04 Oct 2021 23:23:34 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: David Sterba , Naohiro Aota Subject: [PATCH v2 7/7] btrfs-progs: use direct-io for zoned device Date: Tue, 5 Oct 2021 15:23:05 +0900 Message-Id: <20211005062305.549871-8-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211005062305.549871-1-naohiro.aota@wdc.com> References: <20211005062305.549871-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We need to use direct-IO for zoned devices to preserve the write ordering. Instead of detecting if the device is zoned or not, we simply use direct-IO for any kind of device (even if emulated zoned mode on a regular device). Signed-off-by: Naohiro Aota Signed-off-by: David Sterba --- kernel-shared/disk-io.c | 3 +++ kernel-shared/volumes.c | 4 ++++ mkfs/main.c | 7 ++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index dd48599a5f1f..aabeba7821ed 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -1382,6 +1382,9 @@ struct btrfs_fs_info *open_ctree_fs_info(struct open_ctree_flags *ocf) if (!(ocf->flags & OPEN_CTREE_WRITES)) oflags = O_RDONLY; + if ((oflags & O_RDWR) && zoned_model(ocf->filename) == ZONED_HOST_MANAGED) + oflags |= O_DIRECT; + fp = open(ocf->filename, oflags); if (fp < 0) { error("cannot open '%s': %m", ocf->filename); diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 2ef2a8618d1f..bfa60812ef97 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -455,6 +455,10 @@ int btrfs_open_devices(struct btrfs_fs_info *fs_info, continue; } + if ((flags & O_RDWR) && + zoned_model(device->name) == ZONED_HOST_MANAGED) + flags |= O_DIRECT; + fd = open(device->name, flags); if (fd < 0) { ret = -errno; diff --git a/mkfs/main.c b/mkfs/main.c index 314d608a5cc5..11a0989be281 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -893,6 +893,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) bool ssd = false; bool zoned = false; bool force_overwrite = false; + int oflags; char *source_dir = NULL; bool source_dir_set = false; bool shrink_rootdir = false; @@ -1305,12 +1306,16 @@ int BOX_MAIN(mkfs)(int argc, char **argv) dev_cnt--; + oflags = O_RDWR; + if (zoned && zoned_model(file) == ZONED_HOST_MANAGED) + oflags |= O_DIRECT; + /* * Open without O_EXCL so that the problem should not occur by the * following operation in kernel: * (btrfs_register_one_device() fails if O_EXCL is on) */ - fd = open(file, O_RDWR); + fd = open(file, oflags); if (fd < 0) { error("unable to open %s: %m", file); goto error;