Re: [PATCH v2 3/3] btrfs: Cleanup existing name_len checks

2017-11-15 Thread David Sterba
On Wed, Nov 08, 2017 at 08:54:26AM +0800, Qu Wenruo wrote:
> Since tree-checker has verified leaf when reading from disk, we don't
> need the existing verify_dir_item() or btrfs_is_name_len_valid().
> 
> Signed-off-by: Qu Wenruo 

Reviewed-by: David Sterba 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/3] btrfs: Cleanup existing name_len checks

2017-11-07 Thread Qu Wenruo
Since tree-checker has verified leaf when reading from disk, we don't
need the existing verify_dir_item() or btrfs_is_name_len_valid().

Signed-off-by: Qu Wenruo 
---
Unlike checks in btrfs_mark_buffer_dirty(), the existing checks all
happen in read routine, so there is no need to worry about losing early
warning.
---
 fs/btrfs/ctree.h |   5 ---
 fs/btrfs/dir-item.c  | 108 ---
 fs/btrfs/export.c|   5 ---
 fs/btrfs/inode.c |   4 --
 fs/btrfs/props.c |   7 
 fs/btrfs/root-tree.c |   7 
 fs/btrfs/send.c  |   6 ---
 fs/btrfs/tree-log.c  |  47 +-
 fs/btrfs/xattr.c |   6 ---
 9 files changed, 9 insertions(+), 186 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index f7df5536ab61..8835188a8d51 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3060,15 +3060,10 @@ struct btrfs_dir_item *btrfs_lookup_xattr(struct 
btrfs_trans_handle *trans,
  struct btrfs_path *path, u64 dir,
  const char *name, u16 name_len,
  int mod);
-int verify_dir_item(struct btrfs_fs_info *fs_info,
-   struct extent_buffer *leaf, int slot,
-   struct btrfs_dir_item *dir_item);
 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_fs_info *fs_info,
 struct btrfs_path *path,
 const char *name,
 int name_len);
-bool btrfs_is_name_len_valid(struct extent_buffer *leaf, int slot,
-unsigned long start, u16 name_len);
 
 /* orphan.c */
 int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c
index 41cb9196eaa8..cbe421605cd5 100644
--- a/fs/btrfs/dir-item.c
+++ b/fs/btrfs/dir-item.c
@@ -403,8 +403,6 @@ struct btrfs_dir_item *btrfs_match_dir_item_name(struct 
btrfs_fs_info *fs_info,
btrfs_dir_data_len(leaf, dir_item);
name_ptr = (unsigned long)(dir_item + 1);
 
-   if (verify_dir_item(fs_info, leaf, path->slots[0], dir_item))
-   return NULL;
if (btrfs_dir_name_len(leaf, dir_item) == name_len &&
memcmp_extent_buffer(leaf, name, name_ptr, name_len) == 0)
return dir_item;
@@ -450,109 +448,3 @@ int btrfs_delete_one_dir_name(struct btrfs_trans_handle 
*trans,
}
return ret;
 }
-
-int verify_dir_item(struct btrfs_fs_info *fs_info,
-   struct extent_buffer *leaf,
-   int slot,
-   struct btrfs_dir_item *dir_item)
-{
-   u16 namelen = BTRFS_NAME_LEN;
-   int ret;
-   u8 type = btrfs_dir_type(leaf, dir_item);
-
-   if (type >= BTRFS_FT_MAX) {
-   btrfs_crit(fs_info, "invalid dir item type: %d", (int)type);
-   return 1;
-   }
-
-   if (type == BTRFS_FT_XATTR)
-   namelen = XATTR_NAME_MAX;
-
-   if (btrfs_dir_name_len(leaf, dir_item) > namelen) {
-   btrfs_crit(fs_info, "invalid dir item name len: %u",
-  (unsigned)btrfs_dir_name_len(leaf, dir_item));
-   return 1;
-   }
-
-   namelen = btrfs_dir_name_len(leaf, dir_item);
-   ret = btrfs_is_name_len_valid(leaf, slot,
- (unsigned long)(dir_item + 1), namelen);
-   if (!ret)
-   return 1;
-
-   /* BTRFS_MAX_XATTR_SIZE is the same for all dir items */
-   if ((btrfs_dir_data_len(leaf, dir_item) +
-btrfs_dir_name_len(leaf, dir_item)) >
-   BTRFS_MAX_XATTR_SIZE(fs_info)) {
-   btrfs_crit(fs_info, "invalid dir item name + data len: %u + %u",
-  (unsigned)btrfs_dir_name_len(leaf, dir_item),
-  (unsigned)btrfs_dir_data_len(leaf, dir_item));
-   return 1;
-   }
-
-   return 0;
-}
-
-bool btrfs_is_name_len_valid(struct extent_buffer *leaf, int slot,
-unsigned long start, u16 name_len)
-{
-   struct btrfs_fs_info *fs_info = leaf->fs_info;
-   struct btrfs_key key;
-   u32 read_start;
-   u32 read_end;
-   u32 item_start;
-   u32 item_end;
-   u32 size;
-   bool ret = true;
-
-   ASSERT(start > BTRFS_LEAF_DATA_OFFSET);
-
-   read_start = start - BTRFS_LEAF_DATA_OFFSET;
-   read_end = read_start + name_len;
-   item_start = btrfs_item_offset_nr(leaf, slot);
-   item_end = btrfs_item_end_nr(leaf, slot);
-
-   btrfs_item_key_to_cpu(leaf, , slot);
-
-   switch (key.type) {
-   case BTRFS_DIR_ITEM_KEY:
-   case BTRFS_XATTR_ITEM_KEY:
-   case BTRFS_DIR_INDEX_KEY:
-   size = sizeof(struct