[03/15] btrfs-progs: lowmem check: find filetype in repair_inode_missing()
diff mbox

Message ID 20180126083519.28373-4-suy.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Su Yue Jan. 26, 2018, 8:35 a.m. UTC
If parameter @filetype is 0, repair_inode_missing will find filetype
automatically.

And let it return -EEXIST instead of 0 if inode item is existed.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 cmds-check.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

Comments

Qu Wenruo Jan. 26, 2018, 9:22 a.m. UTC | #1
On 2018年01月26日 16:35, Su Yue wrote:
> If parameter @filetype is 0, repair_inode_missing will find filetype
> automatically.
> 
> And let it return -EEXIST instead of 0 if inode item is existed.
> 
> Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>  cmds-check.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/cmds-check.c b/cmds-check.c
> index b200fdccf0e5..08a2662e603c 100644
> --- a/cmds-check.c
> +++ b/cmds-check.c
> @@ -5161,6 +5161,9 @@ out:
>  /*
>   * Insert the missing inode item.
>   *
> + * @filetype: if 0, find file type automatically.
> + *                  if find nothing, set inode as regular file.
> + *
>   * Returns 0 means success.
>   * Returns <0 means error.
>   */
> @@ -5176,6 +5179,19 @@ static int repair_inode_item_missing(struct btrfs_root *root, u64 ino,
>  	key.type = BTRFS_INODE_ITEM_KEY;
>  	key.offset = 0;
>  
> +	if (!filetype) {
> +		ret = find_file_type_lowmem(root, ino, &filetype);
> +		if (ret) {
> +			ret = guess_file_type_lowmem(root, ino, &filetype);
> +			if (ret) {
> +				filetype = BTRFS_FT_REG_FILE;
> +				error(
> +		"can't get file type for inode %llu, using FILE as fallback",
> +				      ino);
> +			}
> +		}
> +	}
> +
>  	btrfs_init_path(&path);
>  	trans = btrfs_start_transaction(root, 1);
>  	if (IS_ERR(trans)) {
> @@ -5184,7 +5200,9 @@ static int repair_inode_item_missing(struct btrfs_root *root, u64 ino,
>  	}
>  
>  	ret = btrfs_search_slot(trans, root, &key, &path, 1, 1);
> -	if (ret < 0 || !ret)
> +	if (!ret)
> +		ret = -EEXIST;
> +	if (ret < 0)
>  		goto fail;
>  
>  	/* insert inode item */
>

Patch
diff mbox

diff --git a/cmds-check.c b/cmds-check.c
index b200fdccf0e5..08a2662e603c 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -5161,6 +5161,9 @@  out:
 /*
  * Insert the missing inode item.
  *
+ * @filetype: if 0, find file type automatically.
+ *                  if find nothing, set inode as regular file.
+ *
  * Returns 0 means success.
  * Returns <0 means error.
  */
@@ -5176,6 +5179,19 @@  static int repair_inode_item_missing(struct btrfs_root *root, u64 ino,
 	key.type = BTRFS_INODE_ITEM_KEY;
 	key.offset = 0;
 
+	if (!filetype) {
+		ret = find_file_type_lowmem(root, ino, &filetype);
+		if (ret) {
+			ret = guess_file_type_lowmem(root, ino, &filetype);
+			if (ret) {
+				filetype = BTRFS_FT_REG_FILE;
+				error(
+		"can't get file type for inode %llu, using FILE as fallback",
+				      ino);
+			}
+		}
+	}
+
 	btrfs_init_path(&path);
 	trans = btrfs_start_transaction(root, 1);
 	if (IS_ERR(trans)) {
@@ -5184,7 +5200,9 @@  static int repair_inode_item_missing(struct btrfs_root *root, u64 ino,
 	}
 
 	ret = btrfs_search_slot(trans, root, &key, &path, 1, 1);
-	if (ret < 0 || !ret)
+	if (!ret)
+		ret = -EEXIST;
+	if (ret < 0)
 		goto fail;
 
 	/* insert inode item */