From 78b72c4bba06be7a7ec02d43b2bb8fb1427f6f96 Mon Sep 17 00:00:00 2001 Message-Id: <78b72c4bba06be7a7ec02d43b2bb8fb1427f6f96.1368098699.git.minovotn@redhat.com> In-Reply-To: <618a4b91ddb04b21f9dc0c1defe7693fb7cc1748.1368098699.git.minovotn@redhat.com> References: <618a4b91ddb04b21f9dc0c1defe7693fb7cc1748.1368098699.git.minovotn@redhat.com> From: Laszlo Ersek Date: Thu, 18 Apr 2013 19:04:40 +0200 Subject: [PATCH 16/24] block: bdrv_img_create(): add Error ** argument RH-Author: Laszlo Ersek Message-id: <1366311884-18091-2-git-send-email-lersek@redhat.com> Patchwork-id: 50689 O-Subject: [RHEL-6.5 qemu-kvm PATCH 1/5] block: bdrv_img_create(): add Error ** argument Bugzilla: 877240 RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Paolo Bonzini RH-Acked-by: Luiz Capitulino This commit adds an Error ** argument to bdrv_img_create() and set it appropriately on error. Callers of bdrv_img_create() pass NULL for the new argument and still rely on bdrv_img_create()'s return value. Next commits will change callers to use the Error object instead. Signed-off-by: Luiz Capitulino Signed-off-by: Kevin Wolf RHEL-6 note: manual backport of 71c79813d83b5b45ba934cf995436063da458f66. (Too many conflicts.) Signed-off-by: Laszlo Ersek --- block.h | 2 +- block.c | 22 +++++++++++++++++++++- blockdev.c | 4 ++-- qemu-img.c | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) Signed-off-by: Michal Novotny --- block.c | 22 +++++++++++++++++++++- block.h | 2 +- blockdev.c | 4 ++-- qemu-img.c | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index bbaa077..5d64f22 100644 --- a/block.c +++ b/block.c @@ -4027,7 +4027,7 @@ int bdrv_in_use(BlockDriverState *bs) int bdrv_img_create(const char *filename, const char *fmt, const char *base_filename, const char *base_fmt, - char *options, uint64_t img_size, int flags) + char *options, uint64_t img_size, int flags, Error **errp) { QEMUOptionParameter *param = NULL, *create_options = NULL; QEMUOptionParameter *backing_fmt, *backing_file; @@ -4040,6 +4040,7 @@ int bdrv_img_create(const char *filename, const char *fmt, drv = bdrv_find_format(fmt); if (!drv) { error_report("Unknown file format '%s'", fmt); + error_setg(errp, "Unknown file format '%s'", fmt); ret = -EINVAL; goto out; } @@ -4047,6 +4048,7 @@ int bdrv_img_create(const char *filename, const char *fmt, proto_drv = bdrv_find_protocol(filename); if (!proto_drv) { error_report("Unknown protocol '%s'", filename); + error_setg(errp, "Unknown protocol '%s'", filename); ret = -EINVAL; goto out; } @@ -4066,6 +4068,7 @@ int bdrv_img_create(const char *filename, const char *fmt, param = parse_option_parameters(options, create_options, param); if (param == NULL) { error_report("Invalid options for file format '%s'.", fmt); + error_setg(errp, "Invalid options for file format '%s'.", fmt); ret = -EINVAL; goto out; } @@ -4076,6 +4079,8 @@ int bdrv_img_create(const char *filename, const char *fmt, base_filename)) { error_report("Backing file not supported for file format '%s'", fmt); + error_setg(errp, "Backing file not supported for file format '%s'", + fmt); ret = -EINVAL; goto out; } @@ -4085,6 +4090,8 @@ int bdrv_img_create(const char *filename, const char *fmt, if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) { error_report("Backing file format not supported for file " "format '%s'", fmt); + error_setg(errp, "Backing file format not supported for file " + "format '%s'", fmt); ret = -EINVAL; goto out; } @@ -4095,6 +4102,8 @@ int bdrv_img_create(const char *filename, const char *fmt, if (!strcmp(filename, backing_file->value.s)) { error_report("Error: Trying to create an image with the " "same filename as the backing file"); + error_setg(errp, "Error: Trying to create an image with the " + "same filename as the backing file"); ret = -EINVAL; goto out; } @@ -4106,6 +4115,8 @@ int bdrv_img_create(const char *filename, const char *fmt, if (!backing_drv) { error_report("Unknown backing file format '%s'", backing_fmt->value.s); + error_setg(errp, "Unknown backing file format '%s'", + backing_fmt->value.s); ret = -EINVAL; goto out; } @@ -4128,6 +4139,8 @@ int bdrv_img_create(const char *filename, const char *fmt, ret = bdrv_open(bs, backing_file->value.s, back_flags, backing_drv); if (ret < 0) { error_report("Could not open '%s'", backing_file->value.s); + error_setg_errno(errp, -ret, "Could not open '%s'", + backing_file->value.s); goto out; } bdrv_get_geometry(bs, &size); @@ -4137,6 +4150,7 @@ int bdrv_img_create(const char *filename, const char *fmt, set_option_parameter(param, BLOCK_OPT_SIZE, buf); } else { error_report("Image creation needs a size parameter"); + error_setg(errp, "Image creation needs a size parameter"); ret = -EINVAL; goto out; } @@ -4152,12 +4166,18 @@ int bdrv_img_create(const char *filename, const char *fmt, if (ret == -ENOTSUP) { error_report("Formatting or formatting option not supported for " "file format '%s'", fmt); + error_setg(errp,"Formatting or formatting option not supported for " + "file format '%s'", fmt); } else if (ret == -EFBIG) { error_report("The image size is too large for file format '%s'", fmt); + error_setg(errp, "The image size is too large for file format '%s'", + fmt); } else { error_report("%s: error while creating %s: %s", filename, fmt, strerror(-ret)); + error_setg(errp, "%s: error while creating %s: %s", filename, fmt, + strerror(-ret)); } } diff --git a/block.h b/block.h index f60d232..f0afbd9 100644 --- a/block.h +++ b/block.h @@ -351,7 +351,7 @@ int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, int bdrv_img_create(const char *filename, const char *fmt, const char *base_filename, const char *base_fmt, - char *options, uint64_t img_size, int flags); + char *options, uint64_t img_size, int flags, Error **errp); struct HBitmapIter; void bdrv_set_dirty_tracking(BlockDriverState *bs, int granularity); diff --git a/blockdev.c b/blockdev.c index d96f1e6..c5213a9 100644 --- a/blockdev.c +++ b/blockdev.c @@ -975,7 +975,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp) bdrv_get_geometry(states->old_bs, &size); size *= 512; ret = bdrv_img_create(new_image_file, format, - NULL, NULL, NULL, size, flags); + NULL, NULL, NULL, size, flags, NULL); } else { /* create new image w/backing file */ switch (mode) { @@ -986,7 +986,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp) ret = bdrv_img_create(new_image_file, format, source->filename, source->drv->format_name, - NULL, -1, flags); + NULL, -1, flags, NULL); break; default: ret = -1; diff --git a/qemu-img.c b/qemu-img.c index f461c07..df76127 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -388,7 +388,7 @@ static int img_create(int argc, char **argv) } ret = bdrv_img_create(filename, fmt, base_filename, base_fmt, - options, img_size, BDRV_O_FLAGS); + options, img_size, BDRV_O_FLAGS, NULL); out: if (ret) { return 1; -- 1.7.11.7