From patchwork Wed Sep 18 14:08:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13806923 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2520EF9CB for ; Wed, 18 Sep 2024 14:09:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668547; cv=none; b=VV3zZyqRuYEQcW7ecmwNrP9FLsfom43KhFBdiWWKgNc9YiqGPvyJwhzGdIMHJMuqvo1eR7PbaQwc5Emd0SJDqmsRYmchqNEJB2rT669ujB5ezaUfJyg5Lw7vu1rmTd+Dn+YL3b3RqHjebaIc2vmwusQjTOOu1IaUmMPIMxY7/iQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668547; c=relaxed/simple; bh=6tnYlSsMuoT2rLJTiBlBoiWKCGvAffky89H0sQRKFT8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j98QRZyb9go2or7Q64PJwdObsdYX0reMqw8IFma2tIN0IEEYAJEQ/X8bauMH+aYALcEQHrH3Qx+sC19OehDQanLVuUu9Dm4QPqEF2kYtySK9wHAQqKQYUPXVFmvTdmdXs8SbO0I3WizSUscZI0aGRym41uKY84iT9H5XsVWNlVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-42cb8dac900so66921285e9.3 for ; Wed, 18 Sep 2024 07:09:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726668544; x=1727273344; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M6/9NvyV28MezKBTULTWOn1KxDnMQ2m0K9DWObo8thk=; b=B2FJP1DRg5cYXU/qfKVd6+ICjxEwuAM1NT9LScYnTlq4WLa1VrtYEkwfwi8IcRXGUj zWZ4e5WDlvBExrsHstLVZh1sykqp7ViaCz1Kguz2UYnI3zzU4YsjK2D68Lhrka+zoOGF ETPq2Fo5UfqIUBhe0TwBq7oOxxGXh3jej/syiwpW4/dzPPILdT+HAr1QIuTEPpHj8Orp IC9veR7u74F1C3d8sKCic3oTAo/NKJiBhr+JjOuN1Uj0SZjrz9YFhMfk3NeTVzYcWtEB bFrre+UpCTXfTeMkT/kMJVr2eOp3Pxu6vDFm7l32AY62T7VL+p2vcrGQjhP54jkhNd0N grBg== X-Gm-Message-State: AOJu0YwzZXloTqfMwdbCqrlQZ+y7vu7hmqwEkYYIGBQa+FTSjgik9k+P RXEUD9gBa0ruxqxEexgZw05MZ7Y2r1TKDPQ8ftoTjtiCT8Nc7VVn X-Google-Smtp-Source: AGHT+IFPc/dsTyBcpiPMZtX+V6EWENTsNcTkvwjr4Z0ZFgGoNRpV1FJVbMv2XTsALrn3/yhAWTynVA== X-Received: by 2002:a05:600c:1e1d:b0:426:5fbc:f319 with SMTP id 5b1f17b1804b1-42cdb5783d9mr159465375e9.33.1726668544093; Wed, 18 Sep 2024 07:09:04 -0700 (PDT) Received: from nuc.fritz.box (p200300f6f72a2100fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72a:2100:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e704f2698sm18282125e9.24.2024.09.18.07.09.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 07:09:03 -0700 (PDT) From: Johannes Thumshirn To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [RFC 1/2] btrfs: introduce dummy RAID stripes for preallocated data Date: Wed, 18 Sep 2024 16:08:49 +0200 Message-ID: <20240918140850.27261-2-jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240918140850.27261-1-jth@kernel.org> References: <85888aaa-c8f5-453b-8344-6cabc82f537e@gmx.com> <20240918140850.27261-1-jth@kernel.org> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Johannes Thumshirn Introduce BTRFS_RAID_STRIPE_DUMMY_KEY which describes a range in the RAID stripe-tree that is backed by meta-data but no data. For instance for preallocated extents. On read, we can simply ignore the contents of the stripe_extent as we're not interested in the physical address and device id of these stripe_extents. Signed-off-by: Johannes Thumshirn --- fs/btrfs/raid-stripe-tree.c | 43 +++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 2 ++ include/uapi/linux/btrfs_tree.h | 1 + 3 files changed, 46 insertions(+) diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index 075fecd08d87..bbe0689b1d17 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -158,6 +158,40 @@ static int update_raid_extent_item(struct btrfs_trans_handle *trans, return ret; } +int btrfs_insert_dummy_raid_extent(struct btrfs_trans_handle *trans, + u64 logical, u64 length) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_key stripe_key; + struct btrfs_root *stripe_root = fs_info->stripe_root; + struct btrfs_path *path; + int ret; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + + stripe_key.objectid = logical; + stripe_key.type = BTRFS_RAID_STRIPE_DUMMY_KEY; + stripe_key.offset = length; + + ret = btrfs_insert_empty_item(trans, stripe_root, path, &stripe_key, 0); + if (ret == -EEXIST) { + struct extent_buffer *leaf = path->nodes[0]; + int slot = path->slots[0]; + struct btrfs_key found_key; + + btrfs_item_key_to_cpu(leaf, &found_key, slot); + found_key.objectid = logical; + found_key.offset = length; + btrfs_mark_buffer_dirty(trans, leaf); + ret = 0; + } + btrfs_free_path(path); + + return ret; +} + static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_io_context *bioc) { @@ -305,6 +339,15 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, if (end > found_end) *length -= end - found_end; + /* + * If we have a BTRFS_RAID_STRIPE_DUMMY_KEY it means we've hit + * an entry for a preallocated extent. Noone will ever check + * the physical, only logical and length, so we're good to + * bail out from here. + */ + if (found_key.type == BTRFS_RAID_STRIPE_DUMMY_KEY) + goto out; + num_stripes = btrfs_num_raid_stripes(btrfs_item_size(leaf, slot)); stripe_extent = btrfs_item_ptr(leaf, slot, struct btrfs_stripe_extent); diff --git a/fs/btrfs/raid-stripe-tree.h b/fs/btrfs/raid-stripe-tree.h index 1ac1c21aac2f..dbe52789f201 100644 --- a/fs/btrfs/raid-stripe-tree.h +++ b/fs/btrfs/raid-stripe-tree.h @@ -27,6 +27,8 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info, u32 stripe_index, struct btrfs_io_stripe *stripe); int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans, struct btrfs_ordered_extent *ordered_extent); +int btrfs_insert_dummy_raid_extent(struct btrfs_trans_handle *trans, + u64 logical, u64 length); static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info, u64 map_type) diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h index fc29d273845d..76b18013b394 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h @@ -281,6 +281,7 @@ #define BTRFS_CHUNK_ITEM_KEY 228 #define BTRFS_RAID_STRIPE_KEY 230 +#define BTRFS_RAID_STRIPE_DUMMY_KEY 231 /* * Records the overall state of the qgroups. From patchwork Wed Sep 18 14:08:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13806924 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE9B2189914 for ; Wed, 18 Sep 2024 14:09:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668548; cv=none; b=KdIhC77zJ8vXjPM159wLlevYQxIi6HpZP09EAnnlJIcduLDTNlmdbtygDmMSMkIJBlOkEfnJyEoJ8EfDIu7bP9gMuCYzCTBHEbNXXxOkoFLWuvFj1zql1U8ByFMpomWV8SgTTGNwou/LsscMuEKf8nWZ4qTR2Zfh6UwzYY3usT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726668548; c=relaxed/simple; bh=0WNv+65dOiIOviCNJzCuUggZHu9ojjNYgMRaqHgQw+Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DsBaDKk8vYs+AmvLrT9eID1aB4nmQMOf9FH7uVQXyisglviDiw7l5Nzu8W66xkkwbxoTZEMxGuVVICEyIaeHtCByowd5yalG/onLUt0cLok0yiD4eCjDWm/VxS1/xmnBeS2xheR44e4SPlrZEvxIo5KhqfS6GXoSKhMrMtZaumQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-42ca4e0299eso53847625e9.2 for ; Wed, 18 Sep 2024 07:09:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726668545; x=1727273345; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QbwsKGHs5K9UGuhFgwWUG6p1ChJGXLMF8cq52ZvMgp4=; b=Zo7O1hAaUlfYY4BijiqJptNt4BVPTQ1u+UTgbAAv+cTxi4GTiWfivO7H/rhVvr66TK aEZegWuyYQkOeSpcMqt7EdNUIJ0WTMYLStgAM1sM+Kl5PvemSlub28aw2odPSYBOt+N3 +xwuVO8l1XxUCpAP1oUG7AouqkkkMDaLcws05R1/rPR6ZL+RxrIlBnUZqPUexG5hhwcC oEjzeLtCiCdzBEFhPWcXZYCjmfPBVKeca2EyMgWXHm6byFqeTOBXOUF17rqSh/vFxWHE J3hBhbx4vN1k4HkcJFC4KE8lyFeCg9EnDSIwPrOzWGYgbG7BeaWuqKPMxnKd57AMXXRS 1pCg== X-Gm-Message-State: AOJu0YxJrHJzguuaU5SvAm+x/Evy9ZfWR2M8amh/yJAEllUALlLvC04V 34UzUip2DbZdYNX0DBKwljd+4dU62olwY3DDY2Qd7L1j9PL7fgyE X-Google-Smtp-Source: AGHT+IGmBoZI8Tz/fI+S5Uo4E2Ubbhgzr6CEdUj0Ntjgr6nLblefzSENEAc+SOsvSo2PYaO95ATwlw== X-Received: by 2002:a05:600c:1c27:b0:428:150e:4f13 with SMTP id 5b1f17b1804b1-42cdb572754mr153206865e9.33.1726668545049; Wed, 18 Sep 2024 07:09:05 -0700 (PDT) Received: from nuc.fritz.box (p200300f6f72a2100fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f72a:2100:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e704f2698sm18282125e9.24.2024.09.18.07.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 07:09:04 -0700 (PDT) From: Johannes Thumshirn To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [RFC 2/2] btrfs: insert dummy RAID stripe extents for preallocated data Date: Wed, 18 Sep 2024 16:08:50 +0200 Message-ID: <20240918140850.27261-3-jth@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240918140850.27261-1-jth@kernel.org> References: <85888aaa-c8f5-453b-8344-6cabc82f537e@gmx.com> <20240918140850.27261-1-jth@kernel.org> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Johannes Thumshirn Preallocated extents are not backed by a RAID stripe-tree entry (in case the filesystem is using the RAID stripe-tree), because there is no real logical to physical mapping needed for them. But for instance scrub is performing RAID stripe-tree lookups for all extents in the extent-tree, even for preallocated ones, so the stripe-tree lookup code will return -ENOENT for them. This is causing scrub to mark these extents as I/O errors. To solve this issue, add a dummy RAID stripe-tree entry for these extents, so the block mapping performed for scrub operations doesn't fail. Signed-off-by: Johannes Thumshirn --- fs/btrfs/inode.c | 47 +++++++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.c | 4 ++++ 2 files changed, 51 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index edac499fd83d..a8e119809670 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -71,6 +71,7 @@ #include "backref.h" #include "raid-stripe-tree.h" #include "fiemap.h" +#include "volumes.h" struct btrfs_iget_args { u64 ino; @@ -8679,6 +8680,44 @@ static int btrfs_symlink(struct mnt_idmap *idmap, struct inode *dir, return err; } +static int insert_prealloc_rst_entry(struct btrfs_fs_info *fs_info, + struct btrfs_trans_handle *trans_in, + u64 start, u64 len) +{ + struct btrfs_trans_handle *trans; + struct btrfs_chunk_map *map; + u64 map_type; + int ret; + + if (!btrfs_fs_incompat(fs_info, RAID_STRIPE_TREE)) + return 0; + + if (trans_in) + trans = trans_in; + else + trans = btrfs_join_transaction(fs_info->stripe_root); + + map = btrfs_find_chunk_map(fs_info, start, len); + if (!map) + return -ENOENT; + + map_type = map->type; + btrfs_free_chunk_map(map); + + if (!btrfs_need_stripe_tree_update(fs_info, map_type)) + return 0; + ret = btrfs_insert_dummy_raid_extent(trans, start, len); + if (ret) { + btrfs_abort_transaction(trans, ret); + return ret; + } + + if (trans != trans_in) + btrfs_end_transaction(trans); + + return 0; +} + static struct btrfs_trans_handle *insert_prealloc_file_extent( struct btrfs_trans_handle *trans_in, struct btrfs_inode *inode, @@ -8817,6 +8856,14 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode, break; } + ret = insert_prealloc_rst_entry(fs_info, trans, ins.objectid, + cur_offset); + if (ret) { + btrfs_free_reserved_extent(fs_info, ins.objectid, + ins.offset, 0); + break; + } + em = alloc_extent_map(); if (!em) { btrfs_drop_extent_map_range(BTRFS_I(inode), cur_offset, diff --git a/fs/btrfs/raid-stripe-tree.c b/fs/btrfs/raid-stripe-tree.c index bbe0689b1d17..f559ea14976f 100644 --- a/fs/btrfs/raid-stripe-tree.c +++ b/fs/btrfs/raid-stripe-tree.c @@ -61,6 +61,9 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le trace_btrfs_raid_extent_delete(fs_info, start, end, found_start, found_end); + if (key.type == BTRFS_RAID_STRIPE_DUMMY_KEY) + goto delete; + if (found_start < start) { struct btrfs_key prev; u64 diff = start - found_start; @@ -112,6 +115,7 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le break; } +delete: ret = btrfs_del_item(trans, stripe_root, path); if (ret) break;