diff mbox

[1/2] btrfs-progs: lowmeme check: Fix false alert about backref lost for SHARED_DATA_REF

Message ID 20170317020634.29287-1-quwenruo@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Qu Wenruo March 17, 2017, 2:06 a.m. UTC
In check_extent_data_item(), after checking extent item of one data
extent, we search inlined data backref, then EXTENT_DATA_REF_KEY.

But we didn't search SHARED_DATA_REF, so if the backref is
SHARED_DATA_REF, then we will raise a false alert about backref lost.

Fix by also checking SHARED_DATA_REF_KEY in check_extent_data_item().

Reported-by: Chris Murphy <chris@colorremedies.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

Comments

Qu Wenruo March 17, 2017, 2:06 a.m. UTC | #1
Introduce a new image, which contains external SHARED_DATA_REF items to
trigger a lowmem mode false alert.

The image only contains external SHARED_DATA_REF and no inlined data
backref.

Before the image, we only have inlined shared data ref, which is not
enough to trigger lowmem mode false alert.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 .../020-extent-ref-cases/shared_data_ref_only.img        | Bin 0 -> 7168 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 tests/fsck-tests/020-extent-ref-cases/shared_data_ref_only.img

diff --git a/tests/fsck-tests/020-extent-ref-cases/shared_data_ref_only.img b/tests/fsck-tests/020-extent-ref-cases/shared_data_ref_only.img
new file mode 100644
index 0000000000000000000000000000000000000000..6d2b95e475188dba11fb4cd0996701e0a09bbf82
GIT binary patch
literal 7168
zcmeHKXH-+$)=eX{P(lqI=~5G#NDUw;RnUmE3!w-Ih@mJ&g-`{g3rIJBB27d<dX+96
zL=jP{6s1Y;`9Qt*jq$Gc#~b7OdCxdw@0s1Q_gs6fwax>(1h*-E^E$w<hvv8j{&<f8
z{1^df(I+Kf<fJfY{DFf{aLiAfe}apD;+rS9zwO7E>nG*vPwabwx!ZrVyPk|`{E0nI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2Jtx`{usCxz&pUI$6X>-;MbE!jz^3OhQ7y9l@>G#ojE2SUbwJ8O+
z*NJ<!hSN_5>XUCVCOZz{9Q%j*IJdt&e@3;CTxV<5k(YP0QsaC0IHG)RVh2lwyv8fb
zMrW#}=`KG-0>UK&ozHi|K;7y)4xL(&tTK*oa}BdKe}dDayDJh(IeAB123LvdosTv1
zH#6VUSZ!T<o@%9e9)COMCeh%5jEmeeGJ?7s@g>xM)oH2!HQmcRb6E;SNFy(vqyMR^
z74CjN**UTWpHl&8^o+c|?y;dz$Q}R!-(dhOJR-9I)2dB)17?EysFTP~L(t_xh*)wg
z0LTeA%Pb_j`H+5ZfQ4g#ym5$;svL}%4|n-`4RDIV5QsNt6AECN^5n(|;xP~y;D9X6
zgEr;?niNk5DF+z`p=I#ekT<}$JUA{qH>d(MkDicFfQ2m2M~={70UBjsvQx$6fIp8r
z+JKUSHMK9Q8g(`iUXhGPdg33r+Q=Ixu#0L_+wqe=j0-e8?wM&6K8p;m!@86OGArP;
zsTH;9ibMjJX_{5LfoHvNlqnpAaq!^k>#-4}GuYSEICzCzeW#f`g|rToF0jNd`>Rvu
zUdLk^wgK8@HQrK`-sMBC!P`fVqZfm{j)<_T?(v`|FE@3i4a?dyei7<1V-dW<JM*EM
zJ73i}l@I`5t%oQ)5Jw4}dch3d`Sf_27Vj5vlZ^1oT828guMOQ?aoq*FHp*54v)S6#
z%IiF?oEd2SywIE_eX()eP^eWb&BYyw_V|QT6)w>m3PNID8qLMagfhMn+rbM7Vk|EZ
X^PEx6o#Z?pRS+XyBERDH|8w<!mO~C1

literal 0
HcmV?d00001
David Sterba March 27, 2017, 5:23 p.m. UTC | #2
On Fri, Mar 17, 2017 at 10:06:33AM +0800, Qu Wenruo wrote:
> In check_extent_data_item(), after checking extent item of one data
> extent, we search inlined data backref, then EXTENT_DATA_REF_KEY.
> 
> But we didn't search SHARED_DATA_REF, so if the backref is
> SHARED_DATA_REF, then we will raise a false alert about backref lost.
> 
> Fix by also checking SHARED_DATA_REF_KEY in check_extent_data_item().
> 
> Reported-by: Chris Murphy <chris@colorremedies.com>
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Both applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-check.c b/cmds-check.c
index 5cc84690..17b7efbf 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -10229,10 +10229,8 @@  static int check_extent_data_item(struct btrfs_root *root,
 	dbref_key.offset = btrfs_file_extent_disk_num_bytes(eb, fi);
 
 	ret = btrfs_search_slot(NULL, extent_root, &dbref_key, &path, 0, 0);
-	if (ret) {
-		err |= BACKREF_MISSING;
-		goto error;
-	}
+	if (ret)
+		goto out;
 
 	leaf = path.nodes[0];
 	slot = path.slots[0];
@@ -10273,11 +10271,10 @@  static int check_extent_data_item(struct btrfs_root *root,
 		ptr += btrfs_extent_inline_ref_size(type);
 	}
 
-	/* Didn't found inlined data backref, try EXTENT_DATA_REF_KEY */
 	if (!found_dbackref) {
 		btrfs_release_path(&path);
 
-		btrfs_init_path(&path);
+		/* Didn't find inlined data backref, try EXTENT_DATA_REF_KEY */
 		dbref_key.objectid = btrfs_file_extent_disk_bytenr(eb, fi);
 		dbref_key.type = BTRFS_EXTENT_DATA_REF_KEY;
 		dbref_key.offset = hash_extent_data_ref(root->objectid,
@@ -10285,13 +10282,32 @@  static int check_extent_data_item(struct btrfs_root *root,
 
 		ret = btrfs_search_slot(NULL, root->fs_info->extent_root,
 					&dbref_key, &path, 0, 0);
-		if (!ret)
+		if (!ret) {
 			found_dbackref = 1;
+			goto out;
+		}
+
+		btrfs_release_path(&path);
+
+		/*
+		 * Neither inlined nor EXTENT_DATA_REF found, try
+		 * SHARED_DATA_REF as last chance.
+		 */
+		dbref_key.objectid = disk_bytenr;
+		dbref_key.type = BTRFS_SHARED_DATA_REF_KEY;
+		dbref_key.offset = eb->start;
+
+		ret = btrfs_search_slot(NULL, root->fs_info->extent_root,
+					&dbref_key, &path, 0, 0);
+		if (!ret) {
+			found_dbackref = 1;
+			goto out;
+		}
 	}
 
+out:
 	if (!found_dbackref)
 		err |= BACKREF_MISSING;
-error:
 	btrfs_release_path(&path);
 	if (err & BACKREF_MISSING) {
 		error("data extent[%llu %llu] backref lost",