All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josef Bacik <jbacik@fb.com>
To: <linux-btrfs@vger.kernel.org>, <dsterba@suse.cz>
Subject: [PATCH 02/16] btrfs-progs: deal with no extent info
Date: Mon, 9 Feb 2015 15:03:05 -0500	[thread overview]
Message-ID: <1423512199-16552-3-git-send-email-jbacik@fb.com> (raw)
In-Reply-To: <1423512199-16552-1-git-send-email-jbacik@fb.com>

Previously we used to just set FULL_BACKREF if we couldn't lookup an extent info
for an extent.  Now we just bail out if we can't lookup the extent info, which
is less than good since fsck is supposed to fix these very problems.  So instead
figure out the flag we are supposed to use and pass that along instead.  This
patch also provides a test image to test this functionality.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
---
 cmds-check.c                                       |  43 +++++++++------------
 .../fsck-tests/014-no-extent-info/default_case.img | Bin 0 -> 4096 bytes
 2 files changed, 19 insertions(+), 24 deletions(-)
 create mode 100644 tests/fsck-tests/014-no-extent-info/default_case.img

diff --git a/cmds-check.c b/cmds-check.c
index 73d7866..ca40e35 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -5686,6 +5686,7 @@ static int run_next_block(struct btrfs_trans_handle *trans,
 			  struct root_item_record *ri)
 {
 	struct extent_buffer *buf;
+	struct extent_record *rec = NULL;
 	u64 bytenr;
 	u32 size;
 	u64 parent;
@@ -5738,8 +5739,6 @@ static int run_next_block(struct btrfs_trans_handle *trans,
 	}
 	cache = lookup_cache_extent(extent_cache, bytenr, size);
 	if (cache) {
-		struct extent_record *rec;
-
 		rec = container_of(cache, struct extent_record, cache);
 		gen = rec->parent_generation;
 	}
@@ -5758,20 +5757,30 @@ static int run_next_block(struct btrfs_trans_handle *trans,
 	 * FIXME, this only works only if we don't have any full
 	 * backref mode.
 	 */
+	flags = 0;
 	if (!init_extent_tree) {
 		ret = btrfs_lookup_extent_info(NULL, root, bytenr,
 				       btrfs_header_level(buf), 1, NULL,
 				       &flags);
-		if (ret < 0)
-			goto out;
+		if (ret < 0) {
+			ret = calc_extent_flag(root, extent_cache, buf, ri, &flags);
+			if (ret < 0) {
+				fprintf(stderr, "Couldn't calc extent flags\n");
+				flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
+			}
+		}
 	} else {
 		flags = 0;
 		ret = calc_extent_flag(root, extent_cache, buf, ri, &flags);
-		if (ret < 0)
-			goto out;
+		if (ret < 0) {
+			fprintf(stderr, "Couldn't calc extent flags\n");
+			flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
+		}
 	}
 
 	if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
+		if (rec)
+			rec->flag_block_full_backref = 1;
 		parent = bytenr;
 		owner = 0;
 	} else {
@@ -7030,21 +7039,8 @@ static int fixup_extent_refs(struct btrfs_trans_handle *trans,
 	int allocated = 0;
 	u64 flags = 0;
 
-	/*
-	 * remember our flags for recreating the extent.
-	 * FIXME, if we have cleared extent tree, we can not
-	 * lookup extent info in extent tree.
-	 */
-	if (!init_extent_tree) {
-		ret = btrfs_lookup_extent_info(NULL, info->extent_root,
-					rec->start, rec->max_size,
-					rec->metadata, NULL, &flags);
-		if (ret < 0)
-			return ret;
-	} else {
-		if (rec->flag_block_full_backref)
-			flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
-	}
+	if (rec->flag_block_full_backref)
+		flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF;
 
 	path = btrfs_alloc_path();
 	if (!path)
@@ -7691,8 +7687,6 @@ static int deal_root_from_list(struct list_head *list,
 		 * one by one, otherwise we deal with node firstly which
 		 * can maximize readahead.
 		 */
-		if (!init_extent_tree && !rec->drop_level)
-			goto skip;
 		while (1) {
 			ret = run_next_block(trans, root, bits, bits_nr, &last,
 					     pending, seen, reada,
@@ -7703,10 +7697,11 @@ static int deal_root_from_list(struct list_head *list,
 			if (ret != 0)
 				break;
 		}
-skip:
 		free_extent_buffer(buf);
 		list_del(&rec->list);
 		free(rec);
+		if (ret < 0)
+			break;
 	}
 	while (ret >= 0) {
 		ret = run_next_block(trans, root, bits, bits_nr, &last,
diff --git a/tests/fsck-tests/014-no-extent-info/default_case.img b/tests/fsck-tests/014-no-extent-info/default_case.img
new file mode 100644
index 0000000000000000000000000000000000000000..1ff27434a59f0b94ce18109690525aadf017b9ad
GIT binary patch
literal 4096
zcmeHJc{CJU8@CNAOBhjkv+oRP!dMz(DNEKELYkB<HOT&2MkrabWDjHPg^4VYeM!<J
zBxD_pWT!DB;~mV$yzgI~_xsNI{`vm+&U?>2zx%t-bI*C6`+J^q&y9CYzekXCY-RXs
z96eYW>GOa{954n39XiS$qD}{$uha2Q-bJ_5kztO0ypQf3Jj96ibe?)>kLaZH-|1)m
z<aLJ}({YFlH|SnE{RjS0;2#D4HwpwzcxqR)r!#WThEDCee7dgo^4eGQP;LH8`LoK(
zkv%61Hi>3uU>=>swkc&!E;fu6SAreqW$){a@kb1y2xi}LOqX{LlL*#=;}(?3N<n=p
z<I#s3`VA4C1xJt~9CLtlC&)2!XxMtcD~W0;>hU}K@QV0pZ_JQ5mrm*zzUW8HS+{hr
zbVlc96lC#0VhM)ch9^2y%$ecG(kv(mh+|n63K5H!8W==T3>8}4GJ=321TZ1eQu*j$
z=l!Tz`&52xh5^`|yP!{4Cp}On6Z%Mw+v{~r!7Fzo)|itiIirH>THfq7ZH$HJ-!e71
zF@0BXd7RRg{XOjF;NX~4mZ@OgW=#Q$Q|K~5%gI*vbw8a{>2Dud!CTh83kSg@m>6_L
zu1y9_tWCC?=vo3hh`y#kHR(=S-UbnOcJMn8?7?0kwm|YJP)Nv=kIFsKRgy9KN~A0%
z)exlv)3;z*<5YwN=bPh0rqSw+VNh?p<~BOy<Nb#AvaZcseZy9C7#ihuYl3aQdo)Bv
zy3mH^_}XK{Avf$f{srFAwrMhuwEdidLAw4hqkwQx0zg}X#IS5Nuc=E$x1d>rQjL@x
z@5>gith0Xj7!;o=SH3Y~^7mcSVZF33t~%8Og)T5t@#z5@&n&ZLA=Bm8K&$Io4ZI=O
zrN>JWmD*i#@!&V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2ld3gJZM=U
z+bk`wQ3+9<Y?Q5apCe5xqVt$wx<I2#&3nu$JjYpO`MYS^CW{qo3QnQ6t;(z{yxsS`
zk<W>?N9J=l@(k!sNZvjnw<22Nu~RVlMNyrT2G<yN<X-g#@^*|mZ3h<?5D*yFA}P9B
z<M)}p;M6Z|IEy!Z+OVTUV)4IvZsss0(W6}mhKFBi+$sT#6^K(=EL9lg0ETW*^&$_8
z7oy%_jK%Z?C-HbB!tT{kG3WH(W`hY-Vt>uL(7xeD&ce@nL3Bp&>kx^#Y9yhocSA^N
zc<8Qw))=*1F)`IsgR;l;OZ>sH(*;?)<b%llP!pyb2hF`;28;gg02rIa2n_mgu@1=r
zDXc=1p^U9jteF|^?*3NKu!_Y3JS@nsV&G_*UVm@SllpTD=fY4lv~;$kP>lA3m+i_*
zztLt;xJJv>S52a*xVUiZ#G)R{g{^xt`7=rAfiqm!C;F?JlkUoLZLKYj3@AiT+Am;^
zR#eLTlHIIukErQsC?{#d#TvKK+D;2rLvx1X{53sDl1c|Tf9T|l)Hx0qoX$F4uItgQ
zs-UAj!N~uGG4RL3-+a#9VB>-#2qAs0Qc%=Fc!-nmn#S%*#W3>yWMf*&FgO!y!sA!P
tUfxPfRJsX*Et{8wBE{?qeWvW%5`UHHm%RSJw;f7<Ftp4R#Qk@-{1@8MDog+X

literal 0
HcmV?d00001

-- 
1.8.3.1


  parent reply	other threads:[~2015-02-09 20:03 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-09 20:03 [GIT PULL] btrfsck and btrfs-image fixes Josef Bacik
2015-02-09 20:03 ` [PATCH 01/16] Btrfs-progs: let btrfs-corrupt-block specify a root Josef Bacik
2015-02-09 20:03 ` Josef Bacik [this message]
2015-02-09 20:03 ` [PATCH 03/16] Btrfs-progs: handle -eagain properly Josef Bacik
2015-02-09 20:03 ` [PATCH 04/16] Btrfs-progs: read super properly in btrfs-image Josef Bacik
2015-02-09 20:03 ` [PATCH 05/16] Btrfs-progs: don't try to repair reloc roots Josef Bacik
2015-02-09 20:03 ` [PATCH 06/16] Btrfs-progs: don't check csums for data reloc root Josef Bacik
2015-02-09 20:03 ` [PATCH 07/16] btrfs-progs: fix btrfs-image overlapping chunks Josef Bacik
2015-02-09 20:03 ` [PATCH 08/16] Btrfs-progs: multi-thread btrfs-image restore Josef Bacik
2015-02-09 20:03 ` [PATCH 09/16] Btrfs-progs: Introduce metadump_v2 Josef Bacik
2015-02-10 18:28   ` Eric Sandeen
2015-02-10 18:39     ` Josef Bacik
2015-02-10 19:14   ` David Sterba
2015-02-10 20:12     ` Josef Bacik
2015-02-09 20:03 ` [PATCH 10/16] Btrfs-progs: only build space info's for the main flags Josef Bacik
2015-02-09 20:03 ` [PATCH 11/16] Btrfs-progs: remove global transaction from fsck Josef Bacik
2015-02-09 20:03 ` [PATCH 12/16] Btrfs-progs: unpin excluded extents as we fix things Josef Bacik
2015-02-09 20:03 ` [PATCH 13/16] Btrfs-progs: make restore update dev items Josef Bacik
2015-02-09 20:03 ` [PATCH 14/16] Btrfs-progs: make debug-tree spit out full_backref flag Josef Bacik
2015-02-09 20:03 ` [PATCH 15/16] Btrfs-progs: skip opening all devices with restore Josef Bacik
2015-02-09 20:03 ` [PATCH 16/16] Btrfs-progs: fix bad extent flag Josef Bacik
2015-02-10 14:29 ` [GIT PULL] btrfsck and btrfs-image fixes David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1423512199-16552-3-git-send-email-jbacik@fb.com \
    --to=jbacik@fb.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.