btrfs_super_chunk_root(sb),
blocksize, generation);
if (!extent_buffer_uptodate(fs_info->chunk_root->node)) {
- fprintf(stderr, "Couldn't read chunk root\n");
- return -EIO;
+ if (fs_info->ignore_chunk_tree_error) {
+ warning("cannot read chunk root, continue anyway");
+ fs_info->chunk_root = NULL;
+ return 0;
+ } else {
+ error("cannot read chunk root");
+ return -EIO;
+ }
}
if (!(btrfs_super_flags(sb) & BTRFS_SUPER_FLAG_METADUMP)) {
fs_info->suppress_check_block_errors = 1;
if (flags & OPEN_CTREE_IGNORE_FSID_MISMATCH)
fs_info->ignore_fsid_mismatch = 1;
+ if (flags & OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR)
+ fs_info->ignore_chunk_tree_error = 1;
ret = btrfs_scan_fs_devices(fp, path, &fs_devices, sb_bytenr,
(flags & OPEN_CTREE_RECOVER_SUPER),
if (ret)
goto out_chunk;
+ /* Chunk tree root is unable to read, return directly */
+ if (!fs_info->chunk_root)
+ return fs_info;
+
eb = fs_info->chunk_root->node;
read_extent_buffer(eb, fs_info->chunk_tree_uuid,
btrfs_header_chunk_tree_uuid(eb),
BTRFS_UUID_SIZE);
ret = btrfs_setup_all_roots(fs_info, root_tree_bytenr, flags);
- if (ret && !(flags & __OPEN_CTREE_RETURN_CHUNK_ROOT))
+ if (ret && !(flags & __OPEN_CTREE_RETURN_CHUNK_ROOT) &&
+ !fs_info->ignore_chunk_tree_error)
goto out_chunk;
return fs_info;
{
struct btrfs_fs_info *info;
+ /* This flags may not return fs_info with any valid root */
+ BUG_ON(flags & OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR);
info = open_ctree_fs_info(filename, sb_bytenr, 0, flags);
if (!info)
return NULL;
enum btrfs_open_ctree_flags flags)
{
struct btrfs_fs_info *info;
+
+ /* This flags may not return fs_info with any valid root */
+ BUG_ON(flags & OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR);
info = __open_ctree_fd(fp, path, sb_bytenr, 0, flags);
if (!info)
return NULL;
return ret;
}
-int close_ctree(struct btrfs_root *root)
+int close_ctree_fs_info(struct btrfs_fs_info *fs_info)
{
int ret;
struct btrfs_trans_handle *trans;
- struct btrfs_fs_info *fs_info = root->fs_info;
+ struct btrfs_root *root = fs_info->tree_root;
if (fs_info->last_trans_committed !=
fs_info->generation) {
+ BUG_ON(!root);
trans = btrfs_start_transaction(root, 1);
btrfs_commit_transaction(trans, root);
trans = btrfs_start_transaction(root, 1);
* Like split PARTIAL into SKIP_CSUM/SKIP_EXTENT
*/
- OPEN_CTREE_IGNORE_FSID_MISMATCH = (1 << 10)
+ OPEN_CTREE_IGNORE_FSID_MISMATCH = (1 << 10),
+
+ /*
+ * Allow open_ctree_fs_info() to return a incomplete fs_info with
+ * system chunks from super block only.
+ * It's useful for chunk corruption case.
+ * Makes no sense for open_ctree variants returning btrfs_root.
+ */
+ OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR = (1 << 11)
};
static inline u64 btrfs_sb_offset(int mirror)
struct btrfs_fs_info *open_ctree_fs_info(const char *filename,
u64 sb_bytenr, u64 root_tree_bytenr,
enum btrfs_open_ctree_flags flags);
-int close_ctree(struct btrfs_root *root);
+int close_ctree_fs_info(struct btrfs_fs_info *fs_info);
+static inline int close_ctree(struct btrfs_root *root)
+{
+ BUG_ON(!root);
+ return close_ctree_fs_info(root->fs_info);
+}
+
int write_all_supers(struct btrfs_root *root);
int write_ctree_super(struct btrfs_trans_handle *trans,
struct btrfs_root *root);