From patchwork Thu Dec 16 13:31:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 75758 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C185A1007D3 for ; Fri, 17 Dec 2010 00:33:18 +1100 (EST) Received: from localhost ([127.0.0.1]:40563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PTDxG-0004Um-Hu for incoming@patchwork.ozlabs.org; Thu, 16 Dec 2010 08:33:10 -0500 Received: from [140.186.70.92] (port=60427 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PTDw6-0003wv-Dp for qemu-devel@nongnu.org; Thu, 16 Dec 2010 08:32:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PTDw4-0000Gf-Pd for qemu-devel@nongnu.org; Thu, 16 Dec 2010 08:31:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22703) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PTDw4-0000GV-9g for qemu-devel@nongnu.org; Thu, 16 Dec 2010 08:31:56 -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.13.8/8.13.8) with ESMTP id oBGDVtmt011415 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 16 Dec 2010 08:31:55 -0500 Received: from red-feather.redhat.com (ovpn-113-46.phx2.redhat.com [10.3.113.46]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oBGDVr16000679; Thu, 16 Dec 2010 08:31:54 -0500 From: Jes.Sorensen@redhat.com To: kwolf@redhat.com Date: Thu, 16 Dec 2010 14:31:53 +0100 Message-Id: <1292506313-13033-1-git-send-email-Jes.Sorensen@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] qemu.img.c: Use error_report() instead of own error() implementation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jes Sorensen Signed-off-by: Jes Sorensen --- qemu-img.c | 128 +++++++++++++++++++++++++++++------------------------------ 1 files changed, 63 insertions(+), 65 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 603bdb3..d3921b6 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -26,6 +26,7 @@ #include "osdep.h" #include "sysemu.h" #include "block_int.h" +#include "qerror.h" #include #ifdef _WIN32 @@ -40,16 +41,6 @@ typedef struct img_cmd_t { /* Default to cache=writeback as data integrity is not important for qemu-tcg. */ #define BDRV_O_FLAGS BDRV_O_CACHE_WB -static void GCC_FMT_ATTR(1, 2) error(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - fprintf(stderr, "qemu-img: "); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); - va_end(ap); -} - static void format_print(void *opaque, const char *name) { printf(" %s", name); @@ -196,13 +187,13 @@ static int print_block_option_help(const char *filename, const char *fmt) /* Find driver and parse its options */ drv = bdrv_find_format(fmt); if (!drv) { - error("Unknown file format '%s'", fmt); + error_report("Unknown file format '%s'", fmt); return 1; } proto_drv = bdrv_find_protocol(filename); if (!proto_drv) { - error("Unknown protocol '%s'", filename); + error_report("Unknown protocol '%s'", filename); return 1; } @@ -225,30 +216,30 @@ static BlockDriverState *bdrv_new_open(const char *filename, bs = bdrv_new(""); if (!bs) { - error("Not enough memory"); + error_report("Not enough memory"); goto fail; } if (fmt) { drv = bdrv_find_format(fmt); if (!drv) { - error("Unknown file format '%s'", fmt); + error_report("Unknown file format '%s'", fmt); goto fail; } } else { drv = NULL; } if (bdrv_open(bs, filename, flags, drv) < 0) { - error("Could not open '%s'", filename); + error_report("Could not open '%s'", filename); goto fail; } if (bdrv_is_encrypted(bs)) { printf("Disk image '%s' is encrypted.\n", filename); if (read_password(password, sizeof(password)) < 0) { - error("No password given"); + error_report("No password given"); goto fail; } if (bdrv_set_key(bs, password) < 0) { - error("invalid password"); + error_report("invalid password"); goto fail; } } @@ -266,13 +257,15 @@ static int add_old_style_options(const char *fmt, QEMUOptionParameter *list, { if (base_filename) { if (set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename)) { - error("Backing file not supported for file format '%s'", fmt); + error_report("Backing file not supported for file format '%s'", + fmt); return -1; } } if (base_fmt) { if (set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt)) { - error("Backing file format not supported for file format '%s'", fmt); + error_report("Backing file format not supported for file " + "format '%s'", fmt); return -1; } } @@ -309,11 +302,11 @@ static int img_create(int argc, char **argv) fmt = optarg; break; case 'e': - error("qemu-img: option -e is deprecated, please use \'-o " + error_report("qemu-img: option -e is deprecated, please use \'-o " "encryption\' instead!"); return 1; case '6': - error("qemu-img: option -6 is deprecated, please use \'-o " + error_report("qemu-img: option -6 is deprecated, please use \'-o " "compat6\' instead!"); return 1; case 'o': @@ -333,9 +326,9 @@ static int img_create(int argc, char **argv) ssize_t sval; sval = strtosz_suffix(argv[optind++], NULL, STRTOSZ_DEFSUFFIX_B); if (sval < 0) { - error("Invalid image size specified! You may use k, M, G or " + error_report("Invalid image size specified! You may use k, M, G or " "T suffixes for "); - error("kilobytes, megabytes, gigabytes and terabytes."); + error_report("kilobytes, megabytes, gigabytes and terabytes."); ret = -1; goto out; } @@ -399,7 +392,7 @@ static int img_check(int argc, char **argv) ret = bdrv_check(bs, &result); if (ret == -ENOTSUP) { - error("This image format does not support checks"); + error_report("This image format does not support checks"); bdrv_delete(bs); return 1; } @@ -481,16 +474,16 @@ static int img_commit(int argc, char **argv) printf("Image committed.\n"); break; case -ENOENT: - error("No disk inserted"); + error_report("No disk inserted"); break; case -EACCES: - error("Image is read-only"); + error_report("Image is read-only"); break; case -ENOTSUP: - error("Image is already committed"); + error_report("Image is already committed"); break; default: - error("Error while committing image"); + error_report("Error while committing image"); break; } @@ -613,11 +606,11 @@ static int img_convert(int argc, char **argv) compress = 1; break; case 'e': - error("qemu-img: option -e is deprecated, please use \'-o " + error_report("qemu-img: option -e is deprecated, please use \'-o " "encryption\' instead!"); return 1; case '6': - error("qemu-img: option -6 is deprecated, please use \'-o " + error_report("qemu-img: option -6 is deprecated, please use \'-o " "compat6\' instead!"); return 1; case 'o': @@ -642,7 +635,8 @@ static int img_convert(int argc, char **argv) } if (bs_n > 1 && out_baseimg) { - error("-B makes no sense when concatenating multiple input images"); + error_report("-B makes no sense when concatenating multiple input " + "images"); ret = -1; goto out; } @@ -653,7 +647,7 @@ static int img_convert(int argc, char **argv) for (bs_i = 0; bs_i < bs_n; bs_i++) { bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, BDRV_O_FLAGS); if (!bs[bs_i]) { - error("Could not open '%s'", argv[optind + bs_i]); + error_report("Could not open '%s'", argv[optind + bs_i]); ret = -1; goto out; } @@ -663,12 +657,12 @@ static int img_convert(int argc, char **argv) if (snapshot_name != NULL) { if (bs_n > 1) { - error("No support for concatenating multiple snapshot\n"); + error_report("No support for concatenating multiple snapshot\n"); ret = -1; goto out; } if (bdrv_snapshot_load_tmp(bs[0], snapshot_name) < 0) { - error("Failed to load snapshot\n"); + error_report("Failed to load snapshot\n"); ret = -1; goto out; } @@ -677,14 +671,14 @@ static int img_convert(int argc, char **argv) /* Find driver and parse its options */ drv = bdrv_find_format(out_fmt); if (!drv) { - error("Unknown file format '%s'", out_fmt); + error_report("Unknown file format '%s'", out_fmt); ret = -1; goto out; } proto_drv = bdrv_find_protocol(out_filename); if (!proto_drv) { - error("Unknown protocol '%s'", out_filename); + error_report("Unknown protocol '%s'", out_filename); ret = -1; goto out; } @@ -697,7 +691,7 @@ static int img_convert(int argc, char **argv) if (options) { param = parse_option_parameters(options, create_options, param); if (param == NULL) { - error("Invalid options for file format '%s'.", out_fmt); + error_report("Invalid options for file format '%s'.", out_fmt); ret = -1; goto out; } @@ -723,13 +717,14 @@ static int img_convert(int argc, char **argv) get_option_parameter(param, BLOCK_OPT_ENCRYPT); if (!drv->bdrv_write_compressed) { - error("Compression not supported for this file format"); + error_report("Compression not supported for this file format"); ret = -1; goto out; } if (encryption && encryption->value.n) { - error("Compression and encryption not supported at the same time"); + error_report("Compression and encryption not supported at " + "the same time"); ret = -1; goto out; } @@ -739,11 +734,14 @@ static int img_convert(int argc, char **argv) ret = bdrv_create(drv, out_filename, param); if (ret < 0) { if (ret == -ENOTSUP) { - error("Formatting not supported for file format '%s'", out_fmt); + error_report("Formatting not supported for file format '%s'", + out_fmt); } else if (ret == -EFBIG) { - error("The image size is too large for file format '%s'", out_fmt); + error_report("The image size is too large for file format '%s'", + out_fmt); } else { - error("%s: error while converting %s: %s", out_filename, out_fmt, strerror(-ret)); + error_report("%s: error while converting %s: %s", + out_filename, out_fmt, strerror(-ret)); } goto out; } @@ -763,12 +761,12 @@ static int img_convert(int argc, char **argv) if (compress) { ret = bdrv_get_info(out_bs, &bdi); if (ret < 0) { - error("could not get block driver info"); + error_report("could not get block driver info"); goto out; } cluster_size = bdi.cluster_size; if (cluster_size <= 0 || cluster_size > IO_BUF_SIZE) { - error("invalid cluster size"); + error_report("invalid cluster size"); ret = -1; goto out; } @@ -809,7 +807,7 @@ static int img_convert(int argc, char **argv) ret = bdrv_read(bs[bs_i], bs_num, buf2, nlow); if (ret < 0) { - error("error while reading"); + error_report("error while reading"); goto out; } @@ -827,7 +825,7 @@ static int img_convert(int argc, char **argv) ret = bdrv_write_compressed(out_bs, sector_num, buf, cluster_sectors); if (ret != 0) { - error("error while compressing sector %" PRId64, + error_report("error while compressing sector %" PRId64, sector_num); goto out; } @@ -886,7 +884,7 @@ static int img_convert(int argc, char **argv) ret = bdrv_read(bs[bs_i], sector_num - bs_offset, buf, n); if (ret < 0) { - error("error while reading"); + error_report("error while reading"); goto out; } /* NOTE: at the same time we convert, we do not write zero @@ -905,7 +903,7 @@ static int img_convert(int argc, char **argv) is_allocated_sectors(buf1, n, &n1)) { ret = bdrv_write(out_bs, sector_num, buf1, n1); if (ret < 0) { - error("error while writing"); + error_report("error while writing"); goto out; } } @@ -1147,7 +1145,7 @@ static int img_snapshot(int argc, char **argv) ret = bdrv_snapshot_create(bs, &sn); if (ret) { - error("Could not create snapshot '%s': %d (%s)", + error_report("Could not create snapshot '%s': %d (%s)", snapshot_name, ret, strerror(-ret)); } break; @@ -1155,7 +1153,7 @@ static int img_snapshot(int argc, char **argv) case SNAPSHOT_APPLY: ret = bdrv_snapshot_goto(bs, snapshot_name); if (ret) { - error("Could not apply snapshot '%s': %d (%s)", + error_report("Could not apply snapshot '%s': %d (%s)", snapshot_name, ret, strerror(-ret)); } break; @@ -1163,7 +1161,7 @@ static int img_snapshot(int argc, char **argv) case SNAPSHOT_DELETE: ret = bdrv_snapshot_delete(bs, snapshot_name); if (ret) { - error("Could not delete snapshot '%s': %d (%s)", + error_report("Could not delete snapshot '%s': %d (%s)", snapshot_name, ret, strerror(-ret)); } break; @@ -1240,7 +1238,7 @@ static int img_rebase(int argc, char **argv) if (!unsafe && bs->backing_format[0] != '\0') { old_backing_drv = bdrv_find_format(bs->backing_format); if (old_backing_drv == NULL) { - error("Invalid format name: '%s'", bs->backing_format); + error_report("Invalid format name: '%s'", bs->backing_format); ret = -1; goto out; } @@ -1249,7 +1247,7 @@ static int img_rebase(int argc, char **argv) if (out_basefmt != NULL) { new_backing_drv = bdrv_find_format(out_basefmt); if (new_backing_drv == NULL) { - error("Invalid format name: '%s'", out_basefmt); + error_report("Invalid format name: '%s'", out_basefmt); ret = -1; goto out; } @@ -1268,7 +1266,7 @@ static int img_rebase(int argc, char **argv) ret = bdrv_open(bs_old_backing, backing_name, BDRV_O_FLAGS, old_backing_drv); if (ret) { - error("Could not open old backing file '%s'", backing_name); + error_report("Could not open old backing file '%s'", backing_name); goto out; } @@ -1276,7 +1274,7 @@ static int img_rebase(int argc, char **argv) ret = bdrv_open(bs_new_backing, out_baseimg, BDRV_O_FLAGS, new_backing_drv); if (ret) { - error("Could not open new backing file '%s'", out_baseimg); + error_report("Could not open new backing file '%s'", out_baseimg); goto out; } } @@ -1320,12 +1318,12 @@ static int img_rebase(int argc, char **argv) /* Read old and new backing file */ ret = bdrv_read(bs_old_backing, sector, buf_old, n); if (ret < 0) { - error("error while reading from old backing file"); + error_report("error while reading from old backing file"); goto out; } ret = bdrv_read(bs_new_backing, sector, buf_new, n); if (ret < 0) { - error("error while reading from new backing file"); + error_report("error while reading from new backing file"); goto out; } @@ -1341,7 +1339,7 @@ static int img_rebase(int argc, char **argv) ret = bdrv_write(bs, sector + written, buf_old + written * 512, pnum); if (ret < 0) { - error("Error while writing to COW image: %s", + error_report("Error while writing to COW image: %s", strerror(-ret)); goto out; } @@ -1362,10 +1360,10 @@ static int img_rebase(int argc, char **argv) */ ret = bdrv_change_backing_file(bs, out_baseimg, out_basefmt); if (ret == -ENOSPC) { - error("Could not change the backing file to '%s': No space left in " - "the file header", out_baseimg); + error_report("Could not change the backing file to '%s': No " + "space left in the file header", out_baseimg); } else if (ret < 0) { - error("Could not change the backing file to '%s': %s", + error_report("Could not change the backing file to '%s': %s", out_baseimg, strerror(-ret)); } @@ -1464,7 +1462,7 @@ static int img_resize(int argc, char **argv) total_size = n; } if (total_size <= 0) { - error("New image size must be positive"); + error_report("New image size must be positive"); ret = -1; goto out; } @@ -1475,13 +1473,13 @@ static int img_resize(int argc, char **argv) printf("Image resized.\n"); break; case -ENOTSUP: - error("This image format does not support resize"); + error_report("This image format does not support resize"); break; case -EACCES: - error("Image is read-only"); + error_report("Image is read-only"); break; default: - error("Error resizing image (%d)", -ret); + error_report("Error resizing image (%d)", -ret); break; } out: