aboutsummaryrefslogtreecommitdiff
path: root/qemu-img.c
diff options
context:
space:
mode:
Diffstat (limited to 'qemu-img.c')
-rw-r--r--qemu-img.c127
1 files changed, 62 insertions, 65 deletions
diff --git a/qemu-img.c b/qemu-img.c
index 0ff179f00b..0b871d842c 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -41,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);
@@ -197,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;
}
@@ -226,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;
}
}
@@ -267,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;
}
}
@@ -310,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':
@@ -334,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;
}
@@ -400,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;
}
@@ -482,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;
}
@@ -614,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':
@@ -643,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;
}
@@ -654,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;
}
@@ -664,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;
}
@@ -678,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;
}
@@ -698,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;
}
@@ -724,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;
}
@@ -740,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;
}
@@ -764,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;
}
@@ -810,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;
}
@@ -828,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;
}
@@ -887,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
@@ -906,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;
}
}
@@ -1148,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;
@@ -1156,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;
@@ -1164,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;
@@ -1241,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;
}
@@ -1250,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;
}
@@ -1269,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;
}
@@ -1277,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;
}
}
@@ -1321,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;
}
@@ -1342,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;
}
@@ -1363,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));
}
@@ -1465,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;
}
@@ -1476,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: