There can be a need to turn output to stdout off. This patch adds a -q option
that enable "Quiet mode". In Quiet mode, only errors are printed out.
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
void bdrv_img_create(const char *filename, const char *fmt,
const char *base_filename, const char *base_fmt,
void 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, Error **errp)
+ char *options, uint64_t img_size, int flags,
+ Error **errp, bool quiet)
{
QEMUOptionParameter *param = NULL, *create_options = NULL;
QEMUOptionParameter *backing_fmt, *backing_file, *size;
{
QEMUOptionParameter *param = NULL, *create_options = NULL;
QEMUOptionParameter *backing_fmt, *backing_file, *size;
- printf("Formatting '%s', fmt=%s ", filename, fmt);
- print_option_parameters(param);
- puts("");
-
+ if (!quiet) {
+ printf("Formatting '%s', fmt=%s ", filename, fmt);
+ print_option_parameters(param);
+ puts("");
+ }
ret = bdrv_create(drv, filename, param);
if (ret < 0) {
if (ret == -ENOTSUP) {
ret = bdrv_create(drv, filename, param);
if (ret < 0) {
if (ret == -ENOTSUP) {
bdrv_img_create(new_image_file, format,
states->old_bs->filename,
states->old_bs->drv->format_name,
bdrv_img_create(new_image_file, format,
states->old_bs->filename,
states->old_bs->drv->format_name,
- NULL, -1, flags, &local_err);
+ NULL, -1, flags, &local_err, false);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
goto delete_and_fail;
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
goto delete_and_fail;
/* create new image w/o backing file */
assert(format && drv);
bdrv_img_create(target, format,
/* create new image w/o backing file */
assert(format && drv);
bdrv_img_create(target, format,
- NULL, NULL, NULL, size, flags, &local_err);
+ NULL, NULL, NULL, size, flags, &local_err, false);
} else {
switch (mode) {
case NEW_IMAGE_MODE_EXISTING:
} else {
switch (mode) {
case NEW_IMAGE_MODE_EXISTING:
bdrv_img_create(target, format,
source->filename,
source->drv->format_name,
bdrv_img_create(target, format,
source->filename,
source->drv->format_name,
- NULL, size, flags, &local_err);
+ NULL, size, flags, &local_err, false);
void bdrv_img_create(const char *filename, const char *fmt,
const char *base_filename, const char *base_fmt,
void 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, Error **errp);
+ char *options, uint64_t img_size, int flags,
+ Error **errp, bool quiet);
void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
void *qemu_blockalign(BlockDriverState *bs, size_t size);
void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
void *qemu_blockalign(BlockDriverState *bs, size_t size);
ETEXI
DEF("check", img_check,
ETEXI
DEF("check", img_check,
- "check [-f fmt] [--output=ofmt] [-r [leaks | all]] filename")
+ "check [-q] [-f fmt] [--output=ofmt] [-r [leaks | all]] filename")
-@item check [-f @var{fmt}] [--output=@var{ofmt}] [-r [leaks | all]] @var{filename}
+@item check [-q] [-f @var{fmt}] [--output=@var{ofmt}] [-r [leaks | all]] @var{filename}
ETEXI
DEF("create", img_create,
ETEXI
DEF("create", img_create,
- "create [-f fmt] [-o options] filename [size]")
+ "create [-q] [-f fmt] [-o options] filename [size]")
-@item create [-f @var{fmt}] [-o @var{options}] @var{filename} [@var{size}]
+@item create [-q] [-f @var{fmt}] [-o @var{options}] @var{filename} [@var{size}]
ETEXI
DEF("commit", img_commit,
ETEXI
DEF("commit", img_commit,
- "commit [-f fmt] [-t cache] filename")
+ "commit [-q] [-f fmt] [-t cache] filename")
-@item commit [-f @var{fmt}] [-t @var{cache}] @var{filename}
+@item commit [-q] [-f @var{fmt}] [-t @var{cache}] @var{filename}
ETEXI
DEF("convert", img_convert,
ETEXI
DEF("convert", img_convert,
- "convert [-c] [-p] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename")
+ "convert [-c] [-p] [-q] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename")
-@item convert [-c] [-p] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
+@item convert [-c] [-p] [-q] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
ETEXI
DEF("info", img_info,
ETEXI
DEF("info", img_info,
ETEXI
DEF("snapshot", img_snapshot,
ETEXI
DEF("snapshot", img_snapshot,
- "snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename")
+ "snapshot [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename")
-@item snapshot [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
+@item snapshot [-q] [-l | -a @var{snapshot} | -c @var{snapshot} | -d @var{snapshot}] @var{filename}
ETEXI
DEF("rebase", img_rebase,
ETEXI
DEF("rebase", img_rebase,
- "rebase [-f fmt] [-t cache] [-p] [-u] -b backing_file [-F backing_fmt] filename")
+ "rebase [-q] [-f fmt] [-t cache] [-p] [-u] -b backing_file [-F backing_fmt] filename")
-@item rebase [-f @var{fmt}] [-t @var{cache}] [-p] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename}
+@item rebase [-q] [-f @var{fmt}] [-t @var{cache}] [-p] [-u] -b @var{backing_file} [-F @var{backing_fmt}] @var{filename}
ETEXI
DEF("resize", img_resize,
ETEXI
DEF("resize", img_resize,
- "resize filename [+ | -]size")
+ "resize [-q] filename [+ | -]size")
-@item resize @var{filename} [+ | -]@var{size}
+@item resize [-q] @var{filename} [+ | -]@var{size}
#include "block/block_int.h"
#include <getopt.h>
#include <stdio.h>
#include "block/block_int.h"
#include <getopt.h>
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#ifdef _WIN32
#include <windows.h>
" rebasing in this case (useful for renaming the backing file)\n"
" '-h' with or without a command shows this help and lists the supported formats\n"
" '-p' show progress of command (only certain commands)\n"
" rebasing in this case (useful for renaming the backing file)\n"
" '-h' with or without a command shows this help and lists the supported formats\n"
" '-p' show progress of command (only certain commands)\n"
+ " '-q' use Quiet mode - do not print any output (except errors)\n"
" '-S' indicates the consecutive number of bytes that must contain only zeros\n"
" for qemu-img to create a sparse image during conversion\n"
" '--output' takes the format in which the output must be done (human or json)\n"
" '-S' indicates the consecutive number of bytes that must contain only zeros\n"
" for qemu-img to create a sparse image during conversion\n"
" '--output' takes the format in which the output must be done (human or json)\n"
+static int qprintf(bool quiet, const char *fmt, ...)
+{
+ int ret = 0;
+ if (!quiet) {
+ va_list args;
+ va_start(args, fmt);
+ ret = vprintf(fmt, args);
+ va_end(args);
+ }
+ return ret;
+}
+
#if defined(WIN32)
/* XXX: put correct support for win32 */
static int read_password(char *buf, int buf_size)
#if defined(WIN32)
/* XXX: put correct support for win32 */
static int read_password(char *buf, int buf_size)
static BlockDriverState *bdrv_new_open(const char *filename,
const char *fmt,
int flags,
static BlockDriverState *bdrv_new_open(const char *filename,
const char *fmt,
int flags,
+ bool require_io,
+ bool quiet)
{
BlockDriverState *bs;
BlockDriver *drv;
{
BlockDriverState *bs;
BlockDriver *drv;
}
if (bdrv_is_encrypted(bs) && require_io) {
}
if (bdrv_is_encrypted(bs) && require_io) {
- printf("Disk image '%s' is encrypted.\n", filename);
+ qprintf(quiet, "Disk image '%s' is encrypted.\n", filename);
if (read_password(password, sizeof(password)) < 0) {
error_report("No password given");
goto fail;
if (read_password(password, sizeof(password)) < 0) {
error_report("No password given");
goto fail;
const char *base_filename = NULL;
char *options = NULL;
Error *local_err = NULL;
const char *base_filename = NULL;
char *options = NULL;
Error *local_err = NULL;
- c = getopt(argc, argv, "F:b:f:he6o:");
+ c = getopt(argc, argv, "F:b:f:he6o:q");
case 'o':
options = optarg;
break;
case 'o':
options = optarg;
break;
+ case 'q':
+ quiet = true;
+ break;
}
bdrv_img_create(filename, fmt, base_filename, base_fmt,
}
bdrv_img_create(filename, fmt, base_filename, base_fmt,
- options, img_size, BDRV_O_FLAGS, &local_err);
+ options, img_size, BDRV_O_FLAGS, &local_err, quiet);
if (error_is_set(&local_err)) {
error_report("%s", error_get_pretty(local_err));
error_free(local_err);
if (error_is_set(&local_err)) {
error_report("%s", error_get_pretty(local_err));
error_free(local_err);
-static void dump_json_image_check(ImageCheck *check)
+static void dump_json_image_check(ImageCheck *check, bool quiet)
{
Error *errp = NULL;
QString *str;
{
Error *errp = NULL;
QString *str;
obj = qmp_output_get_qobject(ov);
str = qobject_to_json_pretty(obj);
assert(str != NULL);
obj = qmp_output_get_qobject(ov);
str = qobject_to_json_pretty(obj);
assert(str != NULL);
- printf("%s\n", qstring_get_str(str));
+ qprintf(quiet, "%s\n", qstring_get_str(str));
qobject_decref(obj);
qmp_output_visitor_cleanup(ov);
QDECREF(str);
}
qobject_decref(obj);
qmp_output_visitor_cleanup(ov);
QDECREF(str);
}
-static void dump_human_image_check(ImageCheck *check)
+static void dump_human_image_check(ImageCheck *check, bool quiet)
{
if (!(check->corruptions || check->leaks || check->check_errors)) {
{
if (!(check->corruptions || check->leaks || check->check_errors)) {
- printf("No errors were found on the image.\n");
+ qprintf(quiet, "No errors were found on the image.\n");
} else {
if (check->corruptions) {
} else {
if (check->corruptions) {
- printf("\n%" PRId64 " errors were found on the image.\n"
- "Data may be corrupted, or further writes to the image "
- "may corrupt it.\n",
- check->corruptions);
+ qprintf(quiet, "\n%" PRId64 " errors were found on the image.\n"
+ "Data may be corrupted, or further writes to the image "
+ "may corrupt it.\n",
+ check->corruptions);
- printf("\n%" PRId64 " leaked clusters were found on the image.\n"
- "This means waste of disk space, but no harm to data.\n",
- check->leaks);
+ qprintf(quiet,
+ "\n%" PRId64 " leaked clusters were found on the image.\n"
+ "This means waste of disk space, but no harm to data.\n",
+ check->leaks);
}
if (check->check_errors) {
}
if (check->check_errors) {
- printf("\n%" PRId64 " internal errors have occurred during the check.\n",
- check->check_errors);
+ qprintf(quiet,
+ "\n%" PRId64
+ " internal errors have occurred during the check.\n",
+ check->check_errors);
}
}
if (check->total_clusters != 0 && check->allocated_clusters != 0) {
}
}
if (check->total_clusters != 0 && check->allocated_clusters != 0) {
- printf("%" PRId64 "/%" PRId64 " = %0.2f%% allocated, "
- "%0.2f%% fragmented, %0.2f%% compressed clusters\n",
- check->allocated_clusters, check->total_clusters,
- check->allocated_clusters * 100.0 / check->total_clusters,
- check->fragmented_clusters * 100.0 / check->allocated_clusters,
- check->compressed_clusters * 100.0 / check->allocated_clusters);
+ qprintf(quiet, "%" PRId64 "/%" PRId64 " = %0.2f%% allocated, "
+ "%0.2f%% fragmented, %0.2f%% compressed clusters\n",
+ check->allocated_clusters, check->total_clusters,
+ check->allocated_clusters * 100.0 / check->total_clusters,
+ check->fragmented_clusters * 100.0 / check->allocated_clusters,
+ check->compressed_clusters * 100.0 /
+ check->allocated_clusters);
}
if (check->image_end_offset) {
}
if (check->image_end_offset) {
- printf("Image end offset: %" PRId64 "\n", check->image_end_offset);
+ qprintf(quiet,
+ "Image end offset: %" PRId64 "\n", check->image_end_offset);
int fix = 0;
int flags = BDRV_O_FLAGS | BDRV_O_CHECK;
ImageCheck *check;
int fix = 0;
int flags = BDRV_O_FLAGS | BDRV_O_CHECK;
ImageCheck *check;
fmt = NULL;
output = NULL;
fmt = NULL;
output = NULL;
{"output", required_argument, 0, OPTION_OUTPUT},
{0, 0, 0, 0}
};
{"output", required_argument, 0, OPTION_OUTPUT},
{0, 0, 0, 0}
};
- c = getopt_long(argc, argv, "f:hr:",
+ c = getopt_long(argc, argv, "f:hr:q",
long_options, &option_index);
if (c == -1) {
break;
long_options, &option_index);
if (c == -1) {
break;
case OPTION_OUTPUT:
output = optarg;
break;
case OPTION_OUTPUT:
output = optarg;
break;
+ case 'q':
+ quiet = true;
+ break;
}
}
if (optind >= argc) {
}
}
if (optind >= argc) {
- bs = bdrv_new_open(filename, fmt, flags, true);
+ bs = bdrv_new_open(filename, fmt, flags, true, quiet);
corruptions_fixed = check->corruptions_fixed;
if (output_format == OFORMAT_HUMAN) {
corruptions_fixed = check->corruptions_fixed;
if (output_format == OFORMAT_HUMAN) {
- printf("The following inconsistencies were found and repaired:\n\n"
- " %" PRId64 " leaked clusters\n"
- " %" PRId64 " corruptions\n\n"
- "Double checking the fixed image now...\n",
- check->leaks_fixed,
- check->corruptions_fixed);
+ qprintf(quiet,
+ "The following inconsistencies were found and repaired:\n\n"
+ " %" PRId64 " leaked clusters\n"
+ " %" PRId64 " corruptions\n\n"
+ "Double checking the fixed image now...\n",
+ check->leaks_fixed,
+ check->corruptions_fixed);
}
ret = collect_image_check(bs, check, filename, fmt, 0);
}
ret = collect_image_check(bs, check, filename, fmt, 0);
switch (output_format) {
case OFORMAT_HUMAN:
switch (output_format) {
case OFORMAT_HUMAN:
- dump_human_image_check(check);
+ dump_human_image_check(check, quiet);
break;
case OFORMAT_JSON:
break;
case OFORMAT_JSON:
- dump_json_image_check(check);
+ dump_json_image_check(check, quiet);
int c, ret, flags;
const char *filename, *fmt, *cache;
BlockDriverState *bs;
int c, ret, flags;
const char *filename, *fmt, *cache;
BlockDriverState *bs;
fmt = NULL;
cache = BDRV_DEFAULT_CACHE;
for(;;) {
fmt = NULL;
cache = BDRV_DEFAULT_CACHE;
for(;;) {
- c = getopt(argc, argv, "f:ht:");
+ c = getopt(argc, argv, "f:ht:q");
case 't':
cache = optarg;
break;
case 't':
cache = optarg;
break;
+ case 'q':
+ quiet = true;
+ break;
}
}
if (optind >= argc) {
}
}
if (optind >= argc) {
- bs = bdrv_new_open(filename, fmt, flags, true);
+ bs = bdrv_new_open(filename, fmt, flags, true, quiet);
if (!bs) {
return 1;
}
ret = bdrv_commit(bs);
switch(ret) {
case 0:
if (!bs) {
return 1;
}
ret = bdrv_commit(bs);
switch(ret) {
case 0:
- printf("Image committed.\n");
+ qprintf(quiet, "Image committed.\n");
break;
case -ENOENT:
error_report("No disk inserted");
break;
case -ENOENT:
error_report("No disk inserted");
const char *snapshot_name = NULL;
float local_progress = 0;
int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
const char *snapshot_name = NULL;
float local_progress = 0;
int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
fmt = NULL;
out_fmt = "raw";
fmt = NULL;
out_fmt = "raw";
out_baseimg = NULL;
compress = 0;
for(;;) {
out_baseimg = NULL;
compress = 0;
for(;;) {
- c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:");
+ c = getopt(argc, argv, "f:O:B:s:hce6o:pS:t:q");
case 't':
cache = optarg;
break;
case 't':
cache = optarg;
break;
+ case 'q':
+ quiet = true;
+ break;
+ if (quiet) {
+ progress = 0;
+ }
+
bs_n = argc - optind - 1;
if (bs_n < 1) {
help();
bs_n = argc - optind - 1;
if (bs_n < 1) {
help();
total_sectors = 0;
for (bs_i = 0; bs_i < bs_n; bs_i++) {
total_sectors = 0;
for (bs_i = 0; bs_i < bs_n; bs_i++) {
- bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, BDRV_O_FLAGS, true);
+ bs[bs_i] = bdrv_new_open(argv[optind + bs_i], fmt, BDRV_O_FLAGS, true,
+ quiet);
if (!bs[bs_i]) {
error_report("Could not open '%s'", argv[optind + bs_i]);
ret = -1;
if (!bs[bs_i]) {
error_report("Could not open '%s'", argv[optind + bs_i]);
ret = -1;
- out_bs = bdrv_new_open(out_filename, out_fmt, flags, true);
+ out_bs = bdrv_new_open(out_filename, out_fmt, flags, true, quiet);
if (!out_bs) {
ret = -1;
goto out;
if (!out_bs) {
ret = -1;
goto out;
g_hash_table_insert(filenames, (gpointer)filename, NULL);
bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_NO_BACKING,
g_hash_table_insert(filenames, (gpointer)filename, NULL);
bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_NO_BACKING,
int c, ret = 0, bdrv_oflags;
int action = 0;
qemu_timeval tv;
int c, ret = 0, bdrv_oflags;
int action = 0;
qemu_timeval tv;
bdrv_oflags = BDRV_O_FLAGS | BDRV_O_RDWR;
/* Parse commandline parameters */
for(;;) {
bdrv_oflags = BDRV_O_FLAGS | BDRV_O_RDWR;
/* Parse commandline parameters */
for(;;) {
- c = getopt(argc, argv, "la:c:d:h");
+ c = getopt(argc, argv, "la:c:d:hq");
action = SNAPSHOT_DELETE;
snapshot_name = optarg;
break;
action = SNAPSHOT_DELETE;
snapshot_name = optarg;
break;
+ case 'q':
+ quiet = true;
+ break;
filename = argv[optind++];
/* Open the image */
filename = argv[optind++];
/* Open the image */
- bs = bdrv_new_open(filename, NULL, bdrv_oflags, true);
+ bs = bdrv_new_open(filename, NULL, bdrv_oflags, true, quiet);
int c, flags, ret;
int unsafe = 0;
int progress = 0;
int c, flags, ret;
int unsafe = 0;
int progress = 0;
/* Parse commandline parameters */
fmt = NULL;
/* Parse commandline parameters */
fmt = NULL;
out_baseimg = NULL;
out_basefmt = NULL;
for(;;) {
out_baseimg = NULL;
out_basefmt = NULL;
for(;;) {
- c = getopt(argc, argv, "uhf:F:b:pt:");
+ c = getopt(argc, argv, "uhf:F:b:pt:q");
case 't':
cache = optarg;
break;
case 't':
cache = optarg;
break;
+ case 'q':
+ quiet = true;
+ break;
+ if (quiet) {
+ progress = 0;
+ }
+
if ((optind >= argc) || (!unsafe && !out_baseimg)) {
help();
}
if ((optind >= argc) || (!unsafe && !out_baseimg)) {
help();
}
* Ignore the old backing file for unsafe rebase in case we want to correct
* the reference to a renamed or moved backing file.
*/
* Ignore the old backing file for unsafe rebase in case we want to correct
* the reference to a renamed or moved backing file.
*/
- bs = bdrv_new_open(filename, fmt, flags, true);
+ bs = bdrv_new_open(filename, fmt, flags, true, quiet);
int c, ret, relative;
const char *filename, *fmt, *size;
int64_t n, total_size;
int c, ret, relative;
const char *filename, *fmt, *size;
int64_t n, total_size;
BlockDriverState *bs = NULL;
QemuOpts *param;
static QemuOptsList resize_options = {
BlockDriverState *bs = NULL;
QemuOpts *param;
static QemuOptsList resize_options = {
/* Parse getopt arguments */
fmt = NULL;
for(;;) {
/* Parse getopt arguments */
fmt = NULL;
for(;;) {
- c = getopt(argc, argv, "f:h");
+ c = getopt(argc, argv, "f:hq");
case 'f':
fmt = optarg;
break;
case 'f':
fmt = optarg;
break;
+ case 'q':
+ quiet = true;
+ break;
}
}
if (optind >= argc) {
}
}
if (optind >= argc) {
n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);
qemu_opts_del(param);
n = qemu_opt_get_size(param, BLOCK_OPT_SIZE, 0);
qemu_opts_del(param);
- bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR, true);
+ bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
if (!bs) {
ret = -1;
goto out;
if (!bs) {
ret = -1;
goto out;
ret = bdrv_truncate(bs, total_size);
switch (ret) {
case 0:
ret = bdrv_truncate(bs, total_size);
switch (ret) {
case 0:
- printf("Image resized.\n");
+ qprintf(quiet, "Image resized.\n");
break;
case -ENOTSUP:
error_report("This image does not support resize");
break;
case -ENOTSUP:
error_report("This image does not support resize");
with or without a command shows help and lists the supported formats
@item -p
display progress bar (convert and rebase commands only)
with or without a command shows help and lists the supported formats
@item -p
display progress bar (convert and rebase commands only)
+@item -q
+Quiet mode - do not print any output (except errors). There's no progress bar
+in case both @var{-q} and @var{-p} options are used.
@item -S @var{size}
indicates the consecutive number of bytes that must contain only zeros
for qemu-img to create a sparse image during conversion. This value is rounded
@item -S @var{size}
indicates the consecutive number of bytes that must contain only zeros
for qemu-img to create a sparse image during conversion. This value is rounded