]> code.ossystems Code Review - openembedded-core.git/blob
cf8700723fed52ea0d6a2ad7a5b0c1b662e787c3
[openembedded-core.git] /
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
6
7 Signed-off-by: Chris Mason <chris.mason@oracle.com>
8 ---
9  btrfsck.c |   10 ++++++++--
10  convert.c |   20 ++++++++++++++------
11  disk-io.c |   57 +++++++++++++++++++++++++++++++++++++++++----------------
12  disk-io.h |    5 +++--
13  4 files changed, 66 insertions(+), 26 deletions(-)
14
15 diff --git a/btrfsck.c b/btrfsck.c
16 index 63e44d1..f760706 100644
17 --- a/btrfsck.c
18 +++ b/btrfsck.c
19 @@ -2820,6 +2820,7 @@ int main(int ac, char **av)
20  {
21         struct cache_tree root_cache;
22         struct btrfs_root *root;
23 +       struct btrfs_fs_info *info;
24         u64 bytenr = 0;
25         int ret;
26         int num;
27 @@ -2856,11 +2857,16 @@ int main(int ac, char **av)
28                 return -EBUSY;
29         }
30  
31 -       root = open_ctree(av[optind], bytenr, 0);
32 +       info = open_fs_info(av[optind], bytenr, 0, 1);
33  
34 -       if (root == NULL)
35 +       if (info == NULL)
36                 return 1;
37  
38 +       root = info->fs_root;
39 +       if (!root) {
40 +               fprintf(stderr, "failed to read the filesystem\n");
41 +               exit(1);
42 +       }
43         ret = check_extents(root);
44         if (ret)
45                 goto out;
46 diff --git a/convert.c b/convert.c
47 index fbcf4a3..72e3cdc 100644
48 --- a/convert.c
49 +++ b/convert.c
50 @@ -2342,6 +2342,7 @@ int do_convert(const char *devname, int datacsum, int packing, int noxattr)
51         ext2_filsys ext2_fs;
52         struct btrfs_root *root;
53         struct btrfs_root *ext2_root;
54 +       struct btrfs_fs_info *fs_info;
55  
56         ret = open_ext2fs(devname, &ext2_fs);
57         if (ret) {
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");
60                 goto fail;
61         }
62 -       root = open_ctree_fd(fd, devname, super_bytenr, O_RDWR);
63 -       if (!root) {
64 +       fs_info = open_ctree_fd(fd, devname, super_bytenr, O_RDWR, 0);
65 +       if (!fs_info) {
66                 fprintf(stderr, "unable to open ctree\n");
67                 goto fail;
68         }
69 +       root = fs_info->fs_root;
70         ret = cache_free_extents(root, ext2_fs);
71         if (ret) {
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)
74                 goto fail;
75         }
76  
77 -       root = open_ctree_fd(fd, devname, 0, O_RDWR);
78 -       if (!root) {
79 +       fs_info = open_ctree_fd(fd, devname, 0, O_RDWR, 0);
80 +       if (!fs_info) {
81                 fprintf(stderr, "unable to open ctree\n");
82                 goto fail;
83         }
84 +       root = fs_info->fs_root;
85 +
86         /* move chunk tree into system chunk. */
87         ret = fixup_chunk_mapping(root);
88         if (ret) {
89 @@ -2525,6 +2529,7 @@ int do_rollback(const char *devname, int force)
90         struct btrfs_key key;
91         struct btrfs_path path;
92         struct extent_io_tree io_tree;
93 +       struct btrfs_fs_info *fs_info;
94         char *buf;
95         char *name;
96         u64 bytenr;
97 @@ -2546,11 +2551,14 @@ int do_rollback(const char *devname, int force)
98                 fprintf(stderr, "unable to open %s\n", devname);
99                 goto fail;
100         }
101 -       root = open_ctree_fd(fd, devname, 0, O_RDWR);
102 -       if (!root) {
103 +
104 +       fs_info = open_ctree_fd(fd, devname, 0, O_RDWR, 0);
105 +       if (!fs_info) {
106                 fprintf(stderr, "unable to open ctree\n");
107                 goto fail;
108         }
109 +       root = fs_info->fs_root;
110 +
111         ret = may_rollback(root);
112         if (ret < 0) {
113                 fprintf(stderr, "unable to do rollback\n");
114 diff --git a/disk-io.c b/disk-io.c
115 index f4368f3..dc100b0 100644
116 --- a/disk-io.c
117 +++ b/disk-io.c
118 @@ -441,7 +441,8 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
119                                      btrfs_super_generation(disk_super) + 1);
120  
121         fs_info->log_root_tree = log_root;
122 -       BUG_ON(!log_root->node);
123 +       if (!log_root->node)
124 +               return -EIO;
125         return 0;
126  }
127  
128 @@ -571,10 +572,11 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info,
129         return root;
130  }
131  
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)
135  {
136         int fp;
137 -       struct btrfs_root *root;
138 +       struct btrfs_fs_info *fs_info;
139         int flags = O_CREAT | O_RDWR;
140  
141         if (!writes)
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);
144                 return NULL;
145         }
146 -       root = open_ctree_fd(fp, filename, sb_bytenr, writes);
147 +       fs_info = open_ctree_fd(fp, filename, sb_bytenr, writes, partial);
148 +
149         close(fp);
150 +       return fs_info;
151 +}
152  
153 -       return root;
154 +
155 +struct btrfs_root *open_ctree(const char *filename, u64 sb_bytenr, int writes)
156 +{
157 +       struct btrfs_fs_info *fs_info;
158 +
159 +       fs_info = open_fs_info(filename, sb_bytenr, writes, 0);
160 +       if (fs_info)
161 +               return fs_info->fs_root;
162 +       return NULL;
163  }
164  
165 -struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
166 -                                int writes)
167 +struct btrfs_fs_info *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
168 +                                   int writes, int partial)
169  {
170         u32 sectorsize;
171         u32 nodesize;
172 @@ -727,7 +740,8 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
173  
174         if (!(btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_METADUMP)) {
175                 ret = btrfs_read_chunk_tree(chunk_root);
176 -               BUG_ON(ret);
177 +               if (ret)
178 +                       goto fail;
179         }
180  
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)
188 +               goto fail;
189 +
190         ret = find_and_setup_root(tree_root, fs_info,
191                                   BTRFS_EXTENT_TREE_OBJECTID, extent_root);
192 -       BUG_ON(ret);
193 +       if (ret)
194 +               goto fail;
195 +
196         extent_root->track_dirty = 1;
197  
198         ret = find_and_setup_root(tree_root, fs_info,
199                                   BTRFS_DEV_TREE_OBJECTID, dev_root);
200 -       BUG_ON(ret);
201 +       if (ret)
202 +               goto fail;
203 +
204         dev_root->track_dirty = 1;
205  
206         ret = find_and_setup_root(tree_root, fs_info,
207                                   BTRFS_CSUM_TREE_OBJECTID, csum_root);
208 -       BUG_ON(ret);
209 +       if (ret)
210 +               goto fail;
211         csum_root->track_dirty = 1;
212  
213 -       BUG_ON(ret);
214 -
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);
217 +       if (ret)
218 +               goto fail;
219  
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;
225  
226 -       return fs_info->fs_root;
227 +       return fs_info;
228 +fail:
229 +       if (partial)
230 +               return fs_info;
231 +       return NULL;
232  }
233  
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
237 --- a/disk-io.h
238 +++ b/disk-io.h
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,
244 -                                int writes);
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,
251 -- 
252 1.7.2.3
253