2018-02-23 12:31:40 +03:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
|
2020-04-07 17:53:19 +03:00
|
|
|
Date: Mon, 6 Apr 2020 12:16:41 +0200
|
|
|
|
Subject: [PATCH] PVE: [Up] qemu-img dd: add isize parameter
|
2018-02-23 12:31:40 +03:00
|
|
|
|
|
|
|
for writing small images from stdin to bigger ones
|
|
|
|
|
|
|
|
In order to distinguish between an actually unexpected and
|
|
|
|
an expected end of input.
|
|
|
|
|
|
|
|
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
|
2019-06-06 13:58:15 +03:00
|
|
|
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
|
update submodule and patches to 7.1.0
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>
2022-10-14 15:07:13 +03:00
|
|
|
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
|
2018-02-23 12:31:40 +03:00
|
|
|
---
|
2020-08-20 11:42:45 +03:00
|
|
|
qemu-img.c | 28 +++++++++++++++++++++++++---
|
|
|
|
1 file changed, 25 insertions(+), 3 deletions(-)
|
2018-02-23 12:31:40 +03:00
|
|
|
|
|
|
|
diff --git a/qemu-img.c b/qemu-img.c
|
2022-12-14 17:16:32 +03:00
|
|
|
index 221b9d6a16..c1306385a8 100644
|
2018-02-23 12:31:40 +03:00
|
|
|
--- a/qemu-img.c
|
|
|
|
+++ b/qemu-img.c
|
2022-12-14 17:16:32 +03:00
|
|
|
@@ -4830,11 +4830,13 @@ static int img_bitmap(int argc, char **argv)
|
2018-02-23 12:31:40 +03:00
|
|
|
#define C_OF 010
|
|
|
|
#define C_SKIP 020
|
|
|
|
#define C_OSIZE 040
|
|
|
|
+#define C_ISIZE 0100
|
|
|
|
|
|
|
|
struct DdInfo {
|
|
|
|
unsigned int flags;
|
|
|
|
int64_t count;
|
|
|
|
int64_t osize;
|
|
|
|
+ int64_t isize;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DdIo {
|
2022-12-14 17:16:32 +03:00
|
|
|
@@ -4923,6 +4925,19 @@ static int img_dd_osize(const char *arg,
|
2018-02-23 12:31:40 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static int img_dd_isize(const char *arg,
|
|
|
|
+ struct DdIo *in, struct DdIo *out,
|
|
|
|
+ struct DdInfo *dd)
|
|
|
|
+{
|
2020-08-20 11:42:45 +03:00
|
|
|
+ dd->isize = cvtnum("size", arg);
|
2018-02-23 12:31:40 +03:00
|
|
|
+
|
|
|
|
+ if (dd->isize < 0) {
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static int img_dd(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2022-12-14 17:16:32 +03:00
|
|
|
@@ -4937,12 +4952,14 @@ static int img_dd(int argc, char **argv)
|
2018-02-23 12:31:40 +03:00
|
|
|
int c, i;
|
|
|
|
const char *out_fmt = "raw";
|
|
|
|
const char *fmt = NULL;
|
|
|
|
- int64_t size = 0;
|
|
|
|
+ int64_t size = 0, readsize = 0;
|
2022-12-14 17:16:32 +03:00
|
|
|
int64_t out_pos, in_pos;
|
2018-02-23 12:31:40 +03:00
|
|
|
bool force_share = false;
|
|
|
|
struct DdInfo dd = {
|
|
|
|
.flags = 0,
|
|
|
|
.count = 0,
|
|
|
|
+ .osize = 0,
|
|
|
|
+ .isize = -1,
|
|
|
|
};
|
|
|
|
struct DdIo in = {
|
|
|
|
.bsz = 512, /* Block size is by default 512 bytes */
|
2022-12-14 17:16:32 +03:00
|
|
|
@@ -4964,6 +4981,7 @@ static int img_dd(int argc, char **argv)
|
2018-02-23 12:31:40 +03:00
|
|
|
{ "of", img_dd_of, C_OF },
|
|
|
|
{ "skip", img_dd_skip, C_SKIP },
|
|
|
|
{ "osize", img_dd_osize, C_OSIZE },
|
|
|
|
+ { "isize", img_dd_isize, C_ISIZE },
|
|
|
|
{ NULL, NULL, 0 }
|
|
|
|
};
|
|
|
|
const struct option long_options[] = {
|
2022-12-14 17:16:32 +03:00
|
|
|
@@ -5160,9 +5178,10 @@ static int img_dd(int argc, char **argv)
|
2018-02-23 12:31:40 +03:00
|
|
|
|
|
|
|
in.buf = g_new(uint8_t, in.bsz);
|
|
|
|
|
2022-12-14 17:16:32 +03:00
|
|
|
- for (out_pos = 0; in_pos < size; ) {
|
2018-02-23 12:31:40 +03:00
|
|
|
+ readsize = (dd.isize > 0) ? dd.isize : size;
|
2022-12-14 17:16:32 +03:00
|
|
|
+ for (out_pos = 0; in_pos < readsize; ) {
|
2018-02-23 12:31:40 +03:00
|
|
|
int in_ret, out_ret;
|
update submodule and patches to 7.1.0
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>
2022-10-14 15:07:13 +03:00
|
|
|
- int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
|
|
|
|
+ int bytes = (in_pos + in.bsz > readsize) ? readsize - in_pos : in.bsz;
|
2018-02-23 12:31:40 +03:00
|
|
|
if (blk1) {
|
update submodule and patches to 7.1.0
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>
2022-10-14 15:07:13 +03:00
|
|
|
in_ret = blk_pread(blk1, in_pos, bytes, in.buf, 0);
|
|
|
|
if (in_ret == 0) {
|
2022-12-14 17:16:32 +03:00
|
|
|
@@ -5171,6 +5190,9 @@ static int img_dd(int argc, char **argv)
|
2018-02-23 12:31:40 +03:00
|
|
|
} else {
|
update submodule and patches to 7.1.0
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>
2022-10-14 15:07:13 +03:00
|
|
|
in_ret = read(STDIN_FILENO, in.buf, bytes);
|
2018-02-23 12:31:40 +03:00
|
|
|
if (in_ret == 0) {
|
|
|
|
+ if (dd.isize == 0) {
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
/* early EOF is considered an error */
|
|
|
|
error_report("Input ended unexpectedly");
|
|
|
|
ret = -1;
|