All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: nborisov@suse.com
Subject: [PATCH v2.1 2/3] btrfs-progs: dir-item: Don't do extra filetype validaction check for btrfs_match_dir_item_name
Date: Mon, 22 Jan 2018 13:45:29 +0800	[thread overview]
Message-ID: <20180122054529.7055-1-wqu@suse.com> (raw)
In-Reply-To: <20180119072536.22286-3-wqu@suse.com>

verify_dir_item() is called in btrfs_match_dir_item_name() to ensure we
won't search beyond item boundary and does extra filetype check.

However in the follow call chain, such extra filetype check can cause
problems:

1) btrfs_add_link()
   |- check_dir_conflict()
      |- btrfs_lookup_dir_index()
         |- btrfs_match_dir_item_name()

   And if we have an offending dir index whose filetype is invalid,
   btrfs_match_dir_item_name() will return NULL, meaning no match dir
   index is found.
   So btrfs_add_link() will still try to insert a dir index, which may
   have same key->offset and leading to duplicated dir index.

2) btrfs_unlink()
   |- btrfs_lookup_dir_index()
      |- btrfs_lookup_dir_index()
         |- btrfs_match_dir_item_name()

   For the same offending dir index with invalid filetype, this will
   return NULL, and btrfs_unlink() will just consider there is no
   existing dir_index and do nothing.
   Leave an orphan and invalid dir_index hanging there forever.

The patch removes the extra filetype check, as "btrfs check" can already
handle invalid filetype correctly for both modes.

And this makes "btrfs check --repair --mode=lowmem" to delete the
offending dir index to repair it correctly.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
v2:
  Get rid of the new parameter.
v2.1:
  Better commit message.
---
 dir-item.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/dir-item.c b/dir-item.c
index 462546c0eaf4..e0a0ab4d7a5d 100644
--- a/dir-item.c
+++ b/dir-item.c
@@ -294,12 +294,6 @@ static int verify_dir_item(struct btrfs_root *root,
 	u16 namelen = BTRFS_NAME_LEN;
 	u8 type = btrfs_dir_type(leaf, dir_item);
 
-	if (type >= BTRFS_FT_MAX) {
-		fprintf(stderr, "invalid dir item type: %d\n",
-		       (int)type);
-		return 1;
-	}
-
 	if (type == BTRFS_FT_XATTR)
 		namelen = XATTR_NAME_MAX;
 
-- 
2.15.1


  parent reply	other threads:[~2018-01-22  5:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-19  7:25 [PATCH v2 0/3] Lowmem fsck repair to fix filetype mismatch Qu Wenruo
2018-01-19  7:25 ` [PATCH v2 1/3] btrfs-progs: lowmem fsck: Remove corupted link before re-add correct link Qu Wenruo
2018-01-19  7:40   ` Su Yue
2018-01-19  7:25 ` [PATCH v2 2/3] btrfs-progs: dir-item: Don't do extra filetype validaction check for btrfs_match_dir_item_name Qu Wenruo
2018-01-19  7:39   ` Su Yue
2018-01-19  7:38     ` Qu Wenruo
2018-01-19  8:07       ` Su Yue
2018-01-19  9:40   ` Nikolay Borisov
2018-01-19 10:03     ` Qu Wenruo
2018-01-19 10:21       ` Nikolay Borisov
2018-01-19 10:39         ` Qu Wenruo
2018-01-19 12:34           ` Nikolay Borisov
2018-01-22  5:45   ` Qu Wenruo [this message]
2018-01-22  8:09     ` [PATCH v2.1 " Nikolay Borisov
2018-01-19  7:25 ` [PATCH v2 3/3] btrfs-progs: dir-item: Make btrfs_delete_one_dir_name more robust to handle corrupted name len Qu Wenruo
2018-01-19  7:40   ` Su Yue
2018-01-19  9:43   ` Nikolay Borisov

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=20180122054529.7055-1-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /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.