summaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
authorDimitri John Ledkov <xnox@ubuntu.com>2017-07-31 14:54:24 +0100
committerDimitri John Ledkov <xnox@ubuntu.com>2017-07-31 14:54:24 +0100
commit6a0440391da7a99ffab94ccc66264af9b5f3ce34 (patch)
tree1c7cf4f07b08c4965ab19819ebce367be16fb980 /image
parent5f2e2384443a09e3f1fec71940e9e32b70789102 (diff)
New upstream release.
Diffstat (limited to 'image')
-rw-r--r--image/main.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/image/main.c b/image/main.c
index 0158844b..80588e81 100644
--- a/image/main.c
+++ b/image/main.c
@@ -35,6 +35,7 @@
#include "utils.h"
#include "volumes.h"
#include "extent_io.h"
+#include "help.h"
#define HEADER_MAGIC 0xbd5c25e27295668bULL
#define MAX_PENDING_SIZE (256 * 1024)
@@ -875,6 +876,7 @@ static int read_data_extent(struct metadump_struct *md,
struct async_work *async)
{
struct btrfs_root *root = md->root;
+ struct btrfs_fs_info *fs_info = root->fs_info;
u64 bytes_left = async->size;
u64 logical = async->start;
u64 offset = 0;
@@ -883,14 +885,13 @@ static int read_data_extent(struct metadump_struct *md,
int cur_mirror;
int ret;
- num_copies = btrfs_num_copies(&root->fs_info->mapping_tree, logical,
- bytes_left);
+ num_copies = btrfs_num_copies(root->fs_info, logical, bytes_left);
/* Try our best to read data, just like read_tree_block() */
for (cur_mirror = 0; cur_mirror < num_copies; cur_mirror++) {
while (bytes_left) {
read_len = bytes_left;
- ret = read_extent_data(root,
+ ret = read_extent_data(fs_info,
(char *)(async->buffer + offset),
logical, &read_len, cur_mirror);
if (ret < 0)
@@ -918,7 +919,7 @@ static int flush_pending(struct metadump_struct *md, int done)
{
struct async_work *async = NULL;
struct extent_buffer *eb;
- u64 blocksize = md->root->nodesize;
+ u64 blocksize = md->root->fs_info->nodesize;
u64 start = 0;
u64 size;
size_t offset;
@@ -972,7 +973,8 @@ static int flush_pending(struct metadump_struct *md, int done)
while (!md->data && size > 0) {
u64 this_read = min(blocksize, size);
- eb = read_tree_block(md->root, start, this_read, 0);
+ eb = read_tree_block(md->root->fs_info, start,
+ this_read, 0);
if (!extent_buffer_uptodate(eb)) {
free(async->buffer);
free(async);
@@ -1027,7 +1029,7 @@ static int add_extent(u64 start, u64 size, struct metadump_struct *md,
return ret;
md->pending_start = start;
}
- readahead_tree_block(md->root, start, size, 0);
+ readahead_tree_block(md->root->fs_info, start, size, 0);
md->pending_size += size;
md->data = data;
return 0;
@@ -1076,13 +1078,15 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb,
struct extent_buffer *tmp;
struct btrfs_root_item *ri;
struct btrfs_key key;
+ struct btrfs_fs_info *fs_info = root->fs_info;
u64 bytenr;
int level;
int nritems = 0;
int i = 0;
int ret;
- ret = add_extent(btrfs_header_bytenr(eb), root->nodesize, metadump, 0);
+ ret = add_extent(btrfs_header_bytenr(eb), fs_info->nodesize,
+ metadump, 0);
if (ret) {
error("unable to add metadata block %llu: %d",
btrfs_header_bytenr(eb), ret);
@@ -1101,7 +1105,8 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb,
continue;
ri = btrfs_item_ptr(eb, i, struct btrfs_root_item);
bytenr = btrfs_disk_root_bytenr(eb, ri);
- tmp = read_tree_block(root, bytenr, root->nodesize, 0);
+ tmp = read_tree_block(fs_info, bytenr,
+ fs_info->nodesize, 0);
if (!extent_buffer_uptodate(tmp)) {
error("unable to read log root block");
return -EIO;
@@ -1112,7 +1117,8 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb,
return ret;
} else {
bytenr = btrfs_node_blockptr(eb, i);
- tmp = read_tree_block(root, bytenr, root->nodesize, 0);
+ tmp = read_tree_block(fs_info, bytenr,
+ fs_info->nodesize, 0);
if (!extent_buffer_uptodate(tmp)) {
error("unable to read log root block");
return -EIO;
@@ -1128,8 +1134,7 @@ static int copy_tree_blocks(struct btrfs_root *root, struct extent_buffer *eb,
}
static int copy_log_trees(struct btrfs_root *root,
- struct metadump_struct *metadump,
- struct btrfs_path *path)
+ struct metadump_struct *metadump)
{
u64 blocknr = btrfs_super_log_root(root->fs_info->super_copy);
@@ -1260,7 +1265,7 @@ static int copy_from_extent_tree(struct metadump_struct *metadump,
bytenr = key.objectid;
if (key.type == BTRFS_METADATA_ITEM_KEY) {
- num_bytes = extent_root->nodesize;
+ num_bytes = extent_root->fs_info->nodesize;
} else {
num_bytes = key.offset;
}
@@ -1374,7 +1379,7 @@ static int create_metadump(const char *input, FILE *out, int num_threads,
}
}
- ret = copy_log_trees(root, &metadump, &path);
+ ret = copy_log_trees(root, &metadump);
if (ret) {
err = ret;
goto out;
@@ -1500,6 +1505,7 @@ static int update_super(struct mdrestore_struct *mdres, u8 *buffer)
flags |= BTRFS_SUPER_FLAG_METADUMP_V2;
btrfs_set_super_flags(super, flags);
btrfs_set_super_sys_array_size(super, new_array_size);
+ btrfs_set_super_num_devices(super, 1);
csum_block(buffer, BTRFS_SUPER_INFO_SIZE);
return 0;
@@ -1714,14 +1720,15 @@ static void *restore_worker(void *data)
}
async = list_entry(mdres->list.next, struct async_work, list);
list_del_init(&async->list);
- pthread_mutex_unlock(&mdres->mutex);
if (mdres->compress_method == COMPRESS_ZLIB) {
size = compress_size;
+ pthread_mutex_unlock(&mdres->mutex);
ret = uncompress(buffer, (unsigned long *)&size,
async->buffer, async->bufsize);
+ pthread_mutex_lock(&mdres->mutex);
if (ret != Z_OK) {
- error("decompressiion failed with %d", ret);
+ error("decompression failed with %d", ret);
err = -EIO;
}
outbuf = buffer;
@@ -1797,7 +1804,6 @@ error:
if (!mdres->multi_devices && async->start == BTRFS_SUPER_INFO_OFFSET)
write_backup_supers(outfd, outbuf);
- pthread_mutex_lock(&mdres->mutex);
if (err && !mdres->error)
mdres->error = err;
mdres->num_items--;
@@ -1898,7 +1904,7 @@ static int fill_mdres_info(struct mdrestore_struct *mdres,
ret = uncompress(buffer, (unsigned long *)&size,
async->buffer, async->bufsize);
if (ret != Z_OK) {
- error("decompressiion failed with %d", ret);
+ error("decompression failed with %d", ret);
free(buffer);
return -EIO;
}
@@ -1927,7 +1933,9 @@ static int add_cluster(struct meta_cluster *cluster,
u32 i, nritems;
int ret;
+ pthread_mutex_lock(&mdres->mutex);
mdres->compress_method = header->compress;
+ pthread_mutex_unlock(&mdres->mutex);
bytenr = le64_to_cpu(header->bytenr) + BLOCK_SIZE;
nritems = le32_to_cpu(header->nritems);
@@ -2170,7 +2178,7 @@ static int search_for_chunk_blocks(struct mdrestore_struct *mdres,
continue;
}
error(
- "unknown state after reading cluster at %llu, probably crrupted data",
+ "unknown state after reading cluster at %llu, probably corrupted data",
cluster_bytenr);
ret = -EIO;
break;
@@ -2219,7 +2227,7 @@ static int search_for_chunk_blocks(struct mdrestore_struct *mdres,
(unsigned long *)&size, tmp,
bufsize);
if (ret != Z_OK) {
- error("decompressiion failed with %d",
+ error("decompression failed with %d",
ret);
ret = -EIO;
break;
@@ -2339,7 +2347,7 @@ static int build_chunk_tree(struct mdrestore_struct *mdres,
ret = uncompress(tmp, (unsigned long *)&size,
buffer, le32_to_cpu(item->size));
if (ret != Z_OK) {
- error("decompressiion failed with %d", ret);
+ error("decompression failed with %d", ret);
free(buffer);
free(tmp);
return -EIO;