From patchwork Fri Nov 30 12:52:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 202948 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EAC1F2C008F for ; Sat, 1 Dec 2012 00:17:22 +1100 (EST) Received: from localhost ([::1]:60100 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeQ5X-0008Gv-83 for incoming@patchwork.ozlabs.org; Fri, 30 Nov 2012 07:53:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeQ4u-0006g6-Ck for qemu-devel@nongnu.org; Fri, 30 Nov 2012 07:52:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TeQ4n-0000Ki-Rd for qemu-devel@nongnu.org; Fri, 30 Nov 2012 07:52:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:6301) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TeQ4n-0000KU-Jj for qemu-devel@nongnu.org; Fri, 30 Nov 2012 07:52:17 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAUCqGYp015549 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 30 Nov 2012 07:52:17 -0500 Received: from localhost (ovpn-113-88.phx2.redhat.com [10.3.113.88]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qAUCqF6c031328; Fri, 30 Nov 2012 07:52:16 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 30 Nov 2012 10:52:04 -0200 Message-Id: <1354279929-568-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1354279929-568-1-git-send-email-lcapitulino@redhat.com> References: <1354279929-568-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, pbonzini@redhat.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 1/6] block: bdrv_img_create(): add Error ** argument X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- block.c | 22 +++++++++++++++++++++- block.h | 2 +- blockdev.c | 6 +++--- qemu-img.c | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index c05875f..9ee0036 100644 --- a/block.c +++ b/block.c @@ -4410,7 +4410,7 @@ bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie) 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, *size; @@ -4423,6 +4423,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; } @@ -4430,6 +4431,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; } @@ -4449,6 +4451,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; } @@ -4459,6 +4462,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; } @@ -4468,6 +4473,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; } @@ -4478,6 +4485,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; } @@ -4489,6 +4498,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; } @@ -4512,6 +4523,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); @@ -4521,6 +4534,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; } @@ -4536,12 +4550,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 722c620..ff54d15 100644 --- a/block.h +++ b/block.h @@ -345,7 +345,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); void bdrv_set_buffer_alignment(BlockDriverState *bs, int align); void *qemu_blockalign(BlockDriverState *bs, size_t size); diff --git a/blockdev.c b/blockdev.c index e73fd6e..2ec02ac 100644 --- a/blockdev.c +++ b/blockdev.c @@ -789,7 +789,7 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **errp) ret = bdrv_img_create(new_image_file, format, states->old_bs->filename, states->old_bs->drv->format_name, - NULL, -1, flags); + NULL, -1, flags, NULL); if (ret) { error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file); goto delete_and_fail; @@ -1264,7 +1264,7 @@ void qmp_drive_mirror(const char *device, const char *target, bdrv_get_geometry(bs, &size); size *= 512; ret = bdrv_img_create(target, format, - NULL, NULL, NULL, size, flags); + NULL, NULL, NULL, size, flags, NULL); } else { switch (mode) { case NEW_IMAGE_MODE_EXISTING: @@ -1275,7 +1275,7 @@ void qmp_drive_mirror(const char *device, const char *target, ret = bdrv_img_create(target, format, source->filename, source->drv->format_name, - NULL, -1, flags); + NULL, -1, flags, NULL); break; default: abort(); diff --git a/qemu-img.c b/qemu-img.c index e29e01b..3896689 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -362,7 +362,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;