5b15e2ecaf
Notable changes: * The only big change is the switch to using a custom QIOChannel for savevm-async, because the previously used QEMUFileOps was dropped. Changes to the current implementation: * Switch to vector based methods as required for an IO channel. For short reads the passed-in IO vector is stuffed with zeroes at the end, just to be sure. * For reading: The documentation in include/io/channel.h states that at least one byte should be read, so also error out when whe are at the very end instead of returning 0. * For reading: Fix off-by-one error when request goes beyond end. The wrong code piece was: if ((pos + size) > maxlen) { size = maxlen - pos - 1; } Previously, the last byte would not be read. It's actually possible to get a snapshot .raw file that has content all the way up the final 512 byte (= BDRV_SECTOR_SIZE) boundary without any trailing zero bytes (I wrote a script to do it). Luckily, it didn't cause a real issue, because qemu_loadvm_state() is not interested in the final (i.e. QEMU_VM_VMDESCRIPTION) section. The buffer for reading it is simply freed up afterwards and the function will assume that it read the whole section, even if that's not the case. * For writing: Make use of the generated blk_pwritev() wrapper instead of manually wrapping the coroutine to simplify and save a few lines. * Adapt to changed interfaces for blk_{pread,pwrite}: * a9262f551e ("block: Change blk_{pread,pwrite}() param order") * 3b35d4542c ("block: Add a 'flags' param to blk_pread()") * bf5b16fa40 ("block: Make blk_{pread,pwrite}() return 0 on success") Those changes especially affected the qemu-img dd patches, because the context also changed, but also some of our block drivers used the functions. * Drop qemu-common.h include: it got renamed after essentially everything was moved to other headers. The only remaining user I could find for things dropped from the header between 7.0 and 7.1 was qemu_get_vm_name() in the iscsi-initiatorname patch, but it already includes the header to which the function was moved. Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
122 lines
4.5 KiB
Diff
122 lines
4.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Alexandre Derumier <aderumier@odiso.com>
|
|
Date: Mon, 6 Apr 2020 12:16:42 +0200
|
|
Subject: [PATCH] PVE: [Up] qemu-img dd: add -n skip_create
|
|
|
|
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
|
|
[FE: fix getopt-string + add documentation]
|
|
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
|
|
---
|
|
docs/tools/qemu-img.rst | 11 ++++++++++-
|
|
qemu-img-cmds.hx | 4 ++--
|
|
qemu-img.c | 23 ++++++++++++++---------
|
|
3 files changed, 26 insertions(+), 12 deletions(-)
|
|
|
|
diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst
|
|
index 85a6e05b35..699229eef6 100644
|
|
--- a/docs/tools/qemu-img.rst
|
|
+++ b/docs/tools/qemu-img.rst
|
|
@@ -208,6 +208,10 @@ Parameters to convert subcommand:
|
|
|
|
Parameters to dd subcommand:
|
|
|
|
+.. option:: -n
|
|
+
|
|
+ Skip the creation of the target volume
|
|
+
|
|
.. program:: qemu-img-dd
|
|
|
|
.. option:: bs=BLOCK_SIZE
|
|
@@ -488,7 +492,7 @@ Command description:
|
|
it doesn't need to be specified separately in this case.
|
|
|
|
|
|
-.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [bs=BLOCK_SIZE] [count=BLOCKS] [skip=BLOCKS] if=INPUT of=OUTPUT
|
|
+.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [-n] [bs=BLOCK_SIZE] [count=BLOCKS] [skip=BLOCKS] if=INPUT of=OUTPUT
|
|
|
|
dd copies from *INPUT* file to *OUTPUT* file converting it from
|
|
*FMT* format to *OUTPUT_FMT* format.
|
|
@@ -499,6 +503,11 @@ Command description:
|
|
|
|
The size syntax is similar to :manpage:`dd(1)`'s size syntax.
|
|
|
|
+ If the ``-n`` option is specified, the target volume creation will be
|
|
+ skipped. This is useful for formats such as ``rbd`` if the target
|
|
+ volume has already been created with site specific options that cannot
|
|
+ be supplied through ``qemu-img``.
|
|
+
|
|
.. option:: info [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=OFMT] [--backing-chain] [-U] FILENAME
|
|
|
|
Give information about the disk image *FILENAME*. Use it in
|
|
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
|
|
index d1616c045a..b5b0bb4467 100644
|
|
--- a/qemu-img-cmds.hx
|
|
+++ b/qemu-img-cmds.hx
|
|
@@ -58,9 +58,9 @@ SRST
|
|
ERST
|
|
|
|
DEF("dd", img_dd,
|
|
- "dd [--image-opts] [-U] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] [skip=blocks] [osize=output_size] if=input of=output")
|
|
+ "dd [--image-opts] [-U] [-f fmt] [-O output_fmt] [-n] [bs=block_size] [count=blocks] [skip=blocks] [osize=output_size] if=input of=output")
|
|
SRST
|
|
-.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [bs=BLOCK_SIZE] [count=BLOCKS] [skip=BLOCKS] [osize=OUTPUT_SIZE] if=INPUT of=OUTPUT
|
|
+.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [-n] [bs=BLOCK_SIZE] [count=BLOCKS] [skip=BLOCKS] [osize=OUTPUT_SIZE] if=INPUT of=OUTPUT
|
|
ERST
|
|
|
|
DEF("info", img_info,
|
|
diff --git a/qemu-img.c b/qemu-img.c
|
|
index 14594d44b6..c6b4a5567d 100644
|
|
--- a/qemu-img.c
|
|
+++ b/qemu-img.c
|
|
@@ -4951,7 +4951,7 @@ static int img_dd(int argc, char **argv)
|
|
const char *fmt = NULL;
|
|
int64_t size = 0, readsize = 0;
|
|
int64_t block_count = 0, out_pos, in_pos;
|
|
- bool force_share = false;
|
|
+ bool force_share = false, skip_create = false;
|
|
struct DdInfo dd = {
|
|
.flags = 0,
|
|
.count = 0,
|
|
@@ -4989,7 +4989,7 @@ static int img_dd(int argc, char **argv)
|
|
{ 0, 0, 0, 0 }
|
|
};
|
|
|
|
- while ((c = getopt_long(argc, argv, ":hf:O:U", long_options, NULL))) {
|
|
+ while ((c = getopt_long(argc, argv, ":hf:O:Un", long_options, NULL))) {
|
|
if (c == EOF) {
|
|
break;
|
|
}
|
|
@@ -5009,6 +5009,9 @@ static int img_dd(int argc, char **argv)
|
|
case 'h':
|
|
help();
|
|
break;
|
|
+ case 'n':
|
|
+ skip_create = true;
|
|
+ break;
|
|
case 'U':
|
|
force_share = true;
|
|
break;
|
|
@@ -5139,13 +5142,15 @@ static int img_dd(int argc, char **argv)
|
|
size - in.bsz * in.offset, &error_abort);
|
|
}
|
|
|
|
- ret = bdrv_create(drv, out.filename, opts, &local_err);
|
|
- if (ret < 0) {
|
|
- error_reportf_err(local_err,
|
|
- "%s: error while creating output image: ",
|
|
- out.filename);
|
|
- ret = -1;
|
|
- goto out;
|
|
+ if (!skip_create) {
|
|
+ ret = bdrv_create(drv, out.filename, opts, &local_err);
|
|
+ if (ret < 0) {
|
|
+ error_reportf_err(local_err,
|
|
+ "%s: error while creating output image: ",
|
|
+ out.filename);
|
|
+ ret = -1;
|
|
+ goto out;
|
|
+ }
|
|
}
|
|
|
|
/* TODO, we can't honour --image-opts for the target,
|