]> git.proxmox.com Git - pve-qemu.git/blobdiff - debian/patches/pve/0010-PVE-Up-qemu-img-dd-add-osize-and-read-from-to-stdin-.patch
update submodule and patches to 7.1.0
[pve-qemu.git] / debian / patches / pve / 0010-PVE-Up-qemu-img-dd-add-osize-and-read-from-to-stdin-.patch
index 7163f0fd1b1bdafd7d023bd349823d4fa9c6a34f..bed5c250b189de9f8088c3925601299c37f852b6 100644 (file)
@@ -31,10 +31,11 @@ override the output file's size.
 
 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
+Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
 ---
  qemu-img-cmds.hx |   4 +-
- qemu-img.c       | 187 +++++++++++++++++++++++++++++------------------
- 2 files changed, 119 insertions(+), 72 deletions(-)
+ qemu-img.c       | 202 ++++++++++++++++++++++++++++++-----------------
+ 2 files changed, 133 insertions(+), 73 deletions(-)
 
 diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
 index 1b1dab5b17..d1616c045a 100644
@@ -53,10 +54,10 @@ index 1b1dab5b17..d1616c045a 100644
  
  DEF("info", img_info,
 diff --git a/qemu-img.c b/qemu-img.c
-index 2782e181c0..8cd43b3601 100644
+index bb36f42dd2..74afcb79ef 100644
 --- a/qemu-img.c
 +++ b/qemu-img.c
-@@ -4821,10 +4821,12 @@ static int img_bitmap(int argc, char **argv)
+@@ -4826,10 +4826,12 @@ static int img_bitmap(int argc, char **argv)
  #define C_IF      04
  #define C_OF      010
  #define C_SKIP    020
@@ -69,7 +70,7 @@ index 2782e181c0..8cd43b3601 100644
  };
  
  struct DdIo {
-@@ -4900,6 +4902,19 @@ static int img_dd_skip(const char *arg,
+@@ -4905,6 +4907,19 @@ static int img_dd_skip(const char *arg,
      return 0;
  }
  
@@ -89,7 +90,7 @@ index 2782e181c0..8cd43b3601 100644
  static int img_dd(int argc, char **argv)
  {
      int ret = 0;
-@@ -4940,6 +4955,7 @@ static int img_dd(int argc, char **argv)
+@@ -4945,6 +4960,7 @@ static int img_dd(int argc, char **argv)
          { "if", img_dd_if, C_IF },
          { "of", img_dd_of, C_OF },
          { "skip", img_dd_skip, C_SKIP },
@@ -97,7 +98,7 @@ index 2782e181c0..8cd43b3601 100644
          { NULL, NULL, 0 }
      };
      const struct option long_options[] = {
-@@ -5015,91 +5031,112 @@ static int img_dd(int argc, char **argv)
+@@ -5020,91 +5036,112 @@ static int img_dd(int argc, char **argv)
          arg = NULL;
      }
  
@@ -153,9 +154,9 @@ index 2782e181c0..8cd43b3601 100644
      }
 -    create_opts = qemu_opts_append(create_opts, drv->create_opts);
 -    create_opts = qemu_opts_append(create_opts, proto_drv->create_opts);
--    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
 -
+-    opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
 -    size = blk_getlength(blk1);
 -    if (size < 0) {
 -        error_report("Failed to get size for '%s'", in.filename);
@@ -274,41 +275,54 @@ index 2782e181c0..8cd43b3601 100644
      }
  
      if (dd.flags & C_SKIP && (in.offset > INT64_MAX / in.bsz ||
-@@ -5117,11 +5154,17 @@ static int img_dd(int argc, char **argv)
+@@ -5121,20 +5158,43 @@ static int img_dd(int argc, char **argv)
+     in.buf = g_new(uint8_t, in.bsz);
  
      for (out_pos = 0; in_pos < size; block_count++) {
-         int in_ret, out_ret;
++        int in_ret, out_ret;
+         int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
 -
--        if (in_pos + in.bsz > size) {
--            in_ret = blk_pread(blk1, in_pos, in.buf, size - in_pos);
-+        size_t in_bsz = in_pos + in.bsz > size ? size - in_pos : in.bsz;
+-        ret = blk_pread(blk1, in_pos, bytes, in.buf, 0);
+-        if (ret < 0) {
 +        if (blk1) {
-+            in_ret = blk_pread(blk1, in_pos, in.buf, in_bsz);
-         } else {
--            in_ret = blk_pread(blk1, in_pos, in.buf, in.bsz);
-+            in_ret = read(STDIN_FILENO, in.buf, in_bsz);
++            in_ret = blk_pread(blk1, in_pos, bytes, in.buf, 0);
++            if (in_ret == 0) {
++                in_ret = bytes;
++            }
++        } else {
++            in_ret = read(STDIN_FILENO, in.buf, bytes);
 +            if (in_ret == 0) {
 +                /* early EOF is considered an error */
 +                error_report("Input ended unexpectedly");
 +                ret = -1;
 +                goto out;
 +            }
-         }
-         if (in_ret < 0) {
++        }
++        if (in_ret < 0) {
              error_report("error while reading from input image file: %s",
-@@ -5131,9 +5174,13 @@ static int img_dd(int argc, char **argv)
+-                         strerror(-ret));
++                         strerror(-in_ret));
++            ret = -1;
+             goto out;
          }
-         in_pos += in_ret;
+         in_pos += bytes;
  
--        out_ret = blk_pwrite(blk2, out_pos, in.buf, in_ret, 0);
+-        ret = blk_pwrite(blk2, out_pos, bytes, in.buf, 0);
+-        if (ret < 0) {
 +        if (blk2) {
-+            out_ret = blk_pwrite(blk2, out_pos, in.buf, in_ret, 0);
++            out_ret = blk_pwrite(blk2, out_pos, in_ret, in.buf, 0);
++            if (out_ret == 0) {
++                out_ret = in_ret;
++            }
 +        } else {
 +            out_ret = write(STDOUT_FILENO, in.buf, in_ret);
 +        }
--        if (out_ret < 0) {
++
 +        if (out_ret != in_ret) {
              error_report("error while writing to output image file: %s",
-                          strerror(-out_ret));
-             ret = -1;
+-                         strerror(-ret));
++                         strerror(-out_ret));
++            ret = -1;
+             goto out;
+         }
+         out_pos += bytes;