#include "qemu-common.h"
#include "qemu-option.h"
#include "osdep.h"
+#include "sysemu.h"
#include "block_int.h"
#include <stdio.h>
/* Default to cache=writeback as data integrity is not important for qemu-tcg. */
#define BDRV_O_FLAGS BDRV_O_CACHE_WB
-static void error(const char *fmt, ...)
+static void GCC_FMT_ATTR(1, 2) error(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
const uint8_t *buf1;
BlockDriverInfo bdi;
QEMUOptionParameter *param = NULL, *create_options = NULL;
+ QEMUOptionParameter *out_baseimg_param;
char *options = NULL;
+ const char *snapshot_name = NULL;
fmt = NULL;
out_fmt = "raw";
out_baseimg = NULL;
flags = 0;
for(;;) {
- c = getopt(argc, argv, "f:O:B:hce6o:");
+ c = getopt(argc, argv, "f:O:B:s:hce6o:");
if (c == -1)
break;
switch(c) {
case 'o':
options = optarg;
break;
+ case 's':
+ snapshot_name = optarg;
+ break;
}
}
total_sectors += bs_sectors;
}
+ if (snapshot_name != NULL) {
+ if (bs_n > 1) {
+ error("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");
+ ret = -1;
+ goto out;
+ }
+ }
+
/* Find driver and parse its options */
drv = bdrv_find_format(out_fmt);
if (!drv) {
goto out;
}
+ /* Get backing file name if -o backing_file was used */
+ out_baseimg_param = get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
+ if (out_baseimg_param) {
+ out_baseimg = out_baseimg_param->value.s;
+ }
+
/* Check if compression is supported */
if (flags & BLOCK_FLAG_COMPRESS) {
QEMUOptionParameter *encryption =
goto out;
}
- out_bs = bdrv_new_open(out_filename, out_fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
+ out_bs = bdrv_new_open(out_filename, out_fmt,
+ BDRV_O_FLAGS | BDRV_O_RDWR | BDRV_O_NO_FLUSH);
if (!out_bs) {
ret = -1;
goto out;
}
bs_new_backing = bdrv_new("new_backing");
- ret = bdrv_open(bs_new_backing, out_baseimg, BDRV_O_FLAGS | BDRV_O_RDWR,
+ 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);