* [PATCH] btrfs-progs: deal with drop_progress properly in fsck
@ 2019-02-06 20:49 Josef Bacik
2019-07-22 13:07 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Josef Bacik @ 2019-02-06 20:49 UTC (permalink / raw)
To: linux-btrfs
While testing snapshot deletion with dm-log-writes I saw that I was
failing the fsck sometimes when the fs was actually in the correct
state. This is because we only skip blocks on the same level of
root_item->drop_level. If the drop_level < the root level then we could
very well walk into nodes that we wouldn't actually walk into on fs
mount, because the drop_progress is further ahead in the slot of the
root. Instead only process the slots of the nodes that are above the
drop_progress key. With this patch in place we no longer improperly
fail to check fs'es that have a drop_progress set with a drop_level <
root level.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
check/main.c | 19 ++++++++++++++++---
ctree.c | 6 +++---
ctree.h | 2 ++
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/check/main.c b/check/main.c
index 7547209c5604..89f0ce75e13d 100644
--- a/check/main.c
+++ b/check/main.c
@@ -6325,15 +6325,28 @@ static int run_next_block(struct btrfs_root *root,
int level;
level = btrfs_header_level(buf);
- for (i = 0; i < nritems; i++) {
+ i = 0;
+
+ /*
+ * If we have a drop key we need to not walk down any slots we
+ * would have ignored when mounting the fs. These blocks are
+ * technically unreferenced and don't need to be worried about.
+ */
+ if (ri != NULL && ri->drop_level && level > ri->drop_level) {
+ ret = btrfs_bin_search(buf, &ri->drop_key, level, &i);
+ if (ret && i > 0)
+ i--;
+ }
+
+ for (; i < nritems; i++) {
struct extent_record tmpl;
ptr = btrfs_node_blockptr(buf, i);
size = root->fs_info->nodesize;
btrfs_node_key_to_cpu(buf, &key, i);
if (ri != NULL) {
- if ((level == ri->drop_level)
- && is_dropped_key(&key, &ri->drop_key)) {
+ if ((level == ri->drop_level) &&
+ is_dropped_key(&key, &ri->drop_key)) {
continue;
}
}
diff --git a/ctree.c b/ctree.c
index 7cb3f8451542..a086d59d6a1c 100644
--- a/ctree.c
+++ b/ctree.c
@@ -638,8 +638,8 @@ static int generic_bin_search(struct extent_buffer *eb, unsigned long p,
* simple bin_search frontend that does the right thing for
* leaves vs nodes
*/
-static int bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
- int level, int *slot)
+int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
+ int level, int *slot)
{
if (level == 0)
return generic_bin_search(eb,
@@ -1172,7 +1172,7 @@ again:
ret = check_block(root, p, level);
if (ret)
return -1;
- ret = bin_search(b, key, level, &slot);
+ ret = btrfs_bin_search(b, key, level, &slot);
if (level != 0) {
if (ret && slot > 0)
slot -= 1;
diff --git a/ctree.h b/ctree.h
index abc20e283fdc..f31a680eb473 100644
--- a/ctree.h
+++ b/ctree.h
@@ -2616,6 +2616,8 @@ int btrfs_search_slot_for_read(struct btrfs_root *root,
const struct btrfs_key *key,
struct btrfs_path *p, int find_higher,
int return_any);
+int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
+ int level, int *slot);
int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *found_path,
u64 iobjectid, u64 ioff, u8 key_type,
struct btrfs_key *found_key);
--
2.14.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs-progs: deal with drop_progress properly in fsck
2019-02-06 20:49 [PATCH] btrfs-progs: deal with drop_progress properly in fsck Josef Bacik
@ 2019-07-22 13:07 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2019-07-22 13:07 UTC (permalink / raw)
To: Josef Bacik; +Cc: linux-btrfs
On Wed, Feb 06, 2019 at 03:49:24PM -0500, Josef Bacik wrote:
> While testing snapshot deletion with dm-log-writes I saw that I was
> failing the fsck sometimes when the fs was actually in the correct
> state. This is because we only skip blocks on the same level of
> root_item->drop_level. If the drop_level < the root level then we could
> very well walk into nodes that we wouldn't actually walk into on fs
> mount, because the drop_progress is further ahead in the slot of the
> root. Instead only process the slots of the nodes that are above the
> drop_progress key. With this patch in place we no longer improperly
> fail to check fs'es that have a drop_progress set with a drop_level <
> root level.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Now applied to devel, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-22 13:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-06 20:49 [PATCH] btrfs-progs: deal with drop_progress properly in fsck Josef Bacik
2019-07-22 13:07 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).