1 Upstream-Status: Inappropriate [Backport]
2 From 238f88bb6c4b9ebad727c6bffb57f542e7e412c1 Mon Sep 17 00:00:00 2001
3 From: Chris Mason <chris.mason@oracle.com>
4 Date: Sun, 19 Dec 2010 16:22:31 -0500
5 Subject: [PATCH 4/5] Allow partial FS opens for btrfsck scanning
7 Signed-off-by: Chris Mason <chris.mason@oracle.com>
9 btrfsck.c | 10 ++++++++--
10 convert.c | 20 ++++++++++++++------
11 disk-io.c | 57 +++++++++++++++++++++++++++++++++++++++++----------------
13 4 files changed, 66 insertions(+), 26 deletions(-)
15 diff --git a/btrfsck.c b/btrfsck.c
16 index 63e44d1..f760706 100644
19 @@ -2820,6 +2820,7 @@ int main(int ac, char **av)
21 struct cache_tree root_cache;
22 struct btrfs_root *root;
23 + struct btrfs_fs_info *info;
27 @@ -2856,11 +2857,16 @@ int main(int ac, char **av)
31 - root = open_ctree(av[optind], bytenr, 0);
32 + info = open_fs_info(av[optind], bytenr, 0, 1);
38 + root = info->fs_root;
40 + fprintf(stderr, "failed to read the filesystem\n");
43 ret = check_extents(root);
46 diff --git a/convert.c b/convert.c
47 index fbcf4a3..72e3cdc 100644
50 @@ -2342,6 +2342,7 @@ int do_convert(const char *devname, int datacsum, int packing, int noxattr)
52 struct btrfs_root *root;
53 struct btrfs_root *ext2_root;
54 + struct btrfs_fs_info *fs_info;
56 ret = open_ext2fs(devname, &ext2_fs);
58 @@ -2386,11 +2387,12 @@ int do_convert(const char *devname, int datacsum, int packing, int noxattr)
59 fprintf(stderr, "unable to update system chunk\n");
62 - root = open_ctree_fd(fd, devname, super_bytenr, O_RDWR);
64 + fs_info = open_ctree_fd(fd, devname, super_bytenr, O_RDWR, 0);
66 fprintf(stderr, "unable to open ctree\n");
69 + root = fs_info->fs_root;
70 ret = cache_free_extents(root, ext2_fs);
72 fprintf(stderr, "error during cache_free_extents %d\n", ret);
73 @@ -2447,11 +2449,13 @@ int do_convert(const char *devname, int datacsum, int packing, int noxattr)
77 - root = open_ctree_fd(fd, devname, 0, O_RDWR);
79 + fs_info = open_ctree_fd(fd, devname, 0, O_RDWR, 0);
81 fprintf(stderr, "unable to open ctree\n");
84 + root = fs_info->fs_root;
86 /* move chunk tree into system chunk. */
87 ret = fixup_chunk_mapping(root);
89 @@ -2525,6 +2529,7 @@ int do_rollback(const char *devname, int force)
91 struct btrfs_path path;
92 struct extent_io_tree io_tree;
93 + struct btrfs_fs_info *fs_info;
97 @@ -2546,11 +2551,14 @@ int do_rollback(const char *devname, int force)
98 fprintf(stderr, "unable to open %s\n", devname);
101 - root = open_ctree_fd(fd, devname, 0, O_RDWR);
104 + fs_info = open_ctree_fd(fd, devname, 0, O_RDWR, 0);
106 fprintf(stderr, "unable to open ctree\n");
109 + root = fs_info->fs_root;
111 ret = may_rollback(root);
113 fprintf(stderr, "unable to do rollback\n");
114 diff --git a/disk-io.c b/disk-io.c
115 index f4368f3..dc100b0 100644
118 @@ -441,7 +441,8 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
119 btrfs_super_generation(disk_super) + 1);
121 fs_info->log_root_tree = log_root;
122 - BUG_ON(!log_root->node);
123 + if (!log_root->node)
128 @@ -571,10 +572,11 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
132 -struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes)
133 +struct btrfs_fs_info *open_fs_info(const char *filename, u64 sb_bytenr,
134 + int writes, int partial)
137 - struct btrfs_root *root;
138 + struct btrfs_fs_info *fs_info;
139 int flags = O_CREAT | O_RDWR;
142 @@ -585,14 +587,25 @@ struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes)
143 fprintf (stderr, "Could not open %s\n", filename);
146 - root = open_ctree_fd(fp, filename, sb_bytenr, writes);
147 + fs_info = open_ctree_fd(fp, filename, sb_bytenr, writes, partial);
155 +struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes)
157 + struct btrfs_fs_info *fs_info;
159 + fs_info = open_fs_info(filename, sb_bytenr, writes, 0);
161 + return fs_info->fs_root;
165 -struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
167 +struct btrfs_fs_info *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
168 + int writes, int partial)
172 @@ -727,7 +740,8 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
174 if (!(btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_METADUMP)) {
175 ret = btrfs_read_chunk_tree(chunk_root);
181 blocksize = btrfs_level_size(tree_root,
182 @@ -737,25 +751,32 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
183 tree_root->node = read_tree_block(tree_root,
184 btrfs_super_root(disk_super),
185 blocksize, generation);
186 - BUG_ON(!tree_root->node);
187 + if (!tree_root->node)
190 ret = find_and_setup_root(tree_root, fs_info,
191 BTRFS_EXTENT_TREE_OBJECTID, extent_root);
196 extent_root->track_dirty = 1;
198 ret = find_and_setup_root(tree_root, fs_info,
199 BTRFS_DEV_TREE_OBJECTID, dev_root);
204 dev_root->track_dirty = 1;
206 ret = find_and_setup_root(tree_root, fs_info,
207 BTRFS_CSUM_TREE_OBJECTID, csum_root);
211 csum_root->track_dirty = 1;
215 - find_and_setup_log_root(tree_root, fs_info, disk_super);
216 + ret = find_and_setup_log_root(tree_root, fs_info, disk_super);
220 fs_info->generation = generation + 1;
221 btrfs_read_block_groups(fs_info->tree_root);
222 @@ -769,7 +790,11 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
223 fs_info->metadata_alloc_profile = (u64)-1;
224 fs_info->system_alloc_profile = fs_info->metadata_alloc_profile;
226 - return fs_info->fs_root;
234 int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
235 diff --git a/disk-io.h b/disk-io.h
236 index 7ebec24..03c5eee 100644
239 @@ -44,8 +44,9 @@ struct extent_buffer *btrfs_find_create_tree_block(struct btrfs_root *root,
240 int clean_tree_block(struct btrfs_trans_handle *trans,
241 struct btrfs_root *root, struct extent_buffer *buf);
242 struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes);
243 -struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
245 +struct btrfs_fs_info *open_fs_info(const char *filename, u64 sb_bytenr, int writes, int partial);
246 +struct btrfs_fs_info *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
247 + int writes, int partial);
248 int close_ctree(struct btrfs_root *root);
249 int write_all_supers(struct btrfs_root *root);
250 int write_ctree_super(struct btrfs_trans_handle *trans,