[PATCH 13/20] btrfs-progs: cmds-check.c: repair_inode_item_missing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Introduce 'repair_inode_item_missing' to fix INODE_ITEM_MISSING
This patch is for further repair.

Signed-off-by: Su Yue <suy.fnst@xxxxxxxxxxxxxx>
---
 cmds-check.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/cmds-check.c b/cmds-check.c
index 256bfbc9..6dafbd7d 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -5463,6 +5463,49 @@ out:
 }
 
 /*
+ * Insert the missing inode item.
+ *
+ * Returns 0 means success.
+ * Returns <0 means error.
+ */
+static int repair_inode_item_missing(struct btrfs_root *root, u64 ino,
+				     u8 filetype, int err)
+{
+	struct btrfs_key key;
+	struct btrfs_trans_handle *trans;
+	struct btrfs_path path;
+	int ret;
+
+	if (!err)
+		return 0;
+
+	key.objectid = ino;
+	key.type = BTRFS_INODE_ITEM_KEY;
+	key.offset = 0;
+
+	btrfs_init_path(&path);
+	trans = btrfs_start_transaction(root, 1);
+	if (IS_ERR(trans)) {
+		ret = -EIO;
+		goto out;
+	}
+
+	ret = btrfs_search_slot(trans, root, &key, &path, 1, 1);
+	if (ret < 0 || !ret)
+		goto out;
+	/* insert inode item */
+	create_inode_item_lowmem(trans, root, ino, filetype);
+	ret = 0;
+	btrfs_commit_transaction(trans, root);
+out:
+	if (ret)
+		error("Failed to repair root %llu INODE ITEM[%llu] missing",
+		      root->objectid, ino);
+	btrfs_release_path(&path);
+	return ret;
+}
+
+/*
  * check first root dir's inode_item, inde_ref
  *
  * returns 0 means no error
-- 
2.11.1



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




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux