diff options
author | Gui Hecheng <guihc.fnst@cn.fujitsu.com> | 2014-06-26 10:53:02 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2014-08-22 14:43:11 +0200 |
commit | aada0509618c3e358e1b2eb164647f0b9a12c646 (patch) | |
tree | 9ede5d9e8a8a4a8c1d8a7f9bd0b6aecdde98490b /btrfs-image.c | |
parent | ad70b55b66b516d0d8271a8f16bee7192c556987 (diff) |
btrfs-progs: deal with malloc failure in btrfs-image
Handle the malloc failure for dump_worker in the same way as
the restore worker.
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'btrfs-image.c')
-rw-r--r-- | btrfs-image.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/btrfs-image.c b/btrfs-image.c index c03a98d6..1a460ba8 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -107,6 +107,8 @@ struct metadump_struct { int done; int data; int sanitize_names; + + int error; }; struct name { @@ -602,6 +604,14 @@ static void *dump_worker(void *data) async->bufsize = compressBound(async->size); async->buffer = malloc(async->bufsize); + if (!async->buffer) { + fprintf(stderr, "Error allocing buffer\n"); + pthread_mutex_lock(&md->mutex); + if (!md->error) + md->error = -ENOMEM; + pthread_mutex_unlock(&md->mutex); + pthread_exit(NULL); + } ret = compress2(async->buffer, (unsigned long *)&async->bufsize, @@ -736,7 +746,7 @@ static int write_buffers(struct metadump_struct *md, u64 *next) goto out; /* wait until all buffers are compressed */ - while (md->num_items > md->num_ready) { + while (!err && md->num_items > md->num_ready) { struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000, @@ -744,6 +754,13 @@ static int write_buffers(struct metadump_struct *md, u64 *next) pthread_mutex_unlock(&md->mutex); nanosleep(&ts, NULL); pthread_mutex_lock(&md->mutex); + err = md->error; + } + + if (err) { + fprintf(stderr, "One of the threads errored out %s\n", + strerror(err)); + goto out; } /* setup and write index block */ |