yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
902636
From 07a93e74efa4861f54dd3d4bec01885f7af2fee3 Mon Sep 17 00:00:00 2001
902636
From: Kevin Wolf <kwolf@redhat.com>
902636
Date: Mon, 8 Jun 2020 17:01:32 +0200
902636
Subject: [PATCH 04/17] block-backend: Add flags to blk_truncate()
902636
902636
RH-Author: Kevin Wolf <kwolf@redhat.com>
902636
Message-id: <20200608150140.38218-4-kwolf@redhat.com>
902636
Patchwork-id: 97450
902636
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 03/11] block-backend: Add flags to blk_truncate()
902636
Bugzilla: 1780574
902636
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
902636
RH-Acked-by: Eric Blake <eblake@redhat.com>
902636
RH-Acked-by: Max Reitz <mreitz@redhat.com>
902636
902636
Now that node level interface bdrv_truncate() supports passing request
902636
flags to the block driver, expose this on the BlockBackend level, too.
902636
902636
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
902636
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
902636
Reviewed-by: Alberto Garcia <berto@igalia.com>
902636
Reviewed-by: Max Reitz <mreitz@redhat.com>
902636
Message-Id: <20200424125448.63318-4-kwolf@redhat.com>
902636
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
902636
(cherry picked from commit 8c6242b6f383e43fd11d2c50f8bcdd2bba1100fc)
902636
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 block.c                        | 3 ++-
902636
 block/block-backend.c          | 4 ++--
902636
 block/commit.c                 | 4 ++--
902636
 block/crypto.c                 | 2 +-
902636
 block/mirror.c                 | 2 +-
902636
 block/qcow2.c                  | 4 ++--
902636
 block/qed.c                    | 2 +-
902636
 block/vdi.c                    | 2 +-
902636
 block/vhdx.c                   | 4 ++--
902636
 block/vmdk.c                   | 6 +++---
902636
 block/vpc.c                    | 2 +-
902636
 blockdev.c                     | 2 +-
902636
 include/sysemu/block-backend.h | 2 +-
902636
 qemu-img.c                     | 2 +-
902636
 qemu-io-cmds.c                 | 2 +-
902636
 15 files changed, 22 insertions(+), 21 deletions(-)
902636
902636
diff --git a/block.c b/block.c
902636
index d6a05da..12c8941 100644
902636
--- a/block.c
902636
+++ b/block.c
902636
@@ -547,7 +547,8 @@ static int64_t create_file_fallback_truncate(BlockBackend *blk,
902636
     int64_t size;
902636
     int ret;
902636
 
902636
-    ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, &local_err);
902636
+    ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, 0,
902636
+                       &local_err);
902636
     if (ret < 0 && ret != -ENOTSUP) {
902636
         error_propagate(errp, local_err);
902636
         return ret;
902636
diff --git a/block/block-backend.c b/block/block-backend.c
902636
index 8be2006..17ed6d8 100644
902636
--- a/block/block-backend.c
902636
+++ b/block/block-backend.c
902636
@@ -2137,14 +2137,14 @@ int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf,
902636
 }
902636
 
902636
 int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
902636
-                 PreallocMode prealloc, Error **errp)
902636
+                 PreallocMode prealloc, BdrvRequestFlags flags, Error **errp)
902636
 {
902636
     if (!blk_is_available(blk)) {
902636
         error_setg(errp, "No medium inserted");
902636
         return -ENOMEDIUM;
902636
     }
902636
 
902636
-    return bdrv_truncate(blk->root, offset, exact, prealloc, 0, errp);
902636
+    return bdrv_truncate(blk->root, offset, exact, prealloc, flags, errp);
902636
 }
902636
 
902636
 int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
902636
diff --git a/block/commit.c b/block/commit.c
902636
index 23c90b3..075ebf8 100644
902636
--- a/block/commit.c
902636
+++ b/block/commit.c
902636
@@ -155,7 +155,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
902636
     }
902636
 
902636
     if (base_len < len) {
902636
-        ret = blk_truncate(s->base, len, false, PREALLOC_MODE_OFF, NULL);
902636
+        ret = blk_truncate(s->base, len, false, PREALLOC_MODE_OFF, 0, NULL);
902636
         if (ret) {
902636
             goto out;
902636
         }
902636
@@ -471,7 +471,7 @@ int bdrv_commit(BlockDriverState *bs)
902636
      * grow the backing file image if possible.  If not possible,
902636
      * we must return an error */
902636
     if (length > backing_length) {
902636
-        ret = blk_truncate(backing, length, false, PREALLOC_MODE_OFF,
902636
+        ret = blk_truncate(backing, length, false, PREALLOC_MODE_OFF, 0,
902636
                            &local_err);
902636
         if (ret < 0) {
902636
             error_report_err(local_err);
902636
diff --git a/block/crypto.c b/block/crypto.c
902636
index fcb4a97..83a8fc0 100644
902636
--- a/block/crypto.c
902636
+++ b/block/crypto.c
902636
@@ -115,7 +115,7 @@ static ssize_t block_crypto_init_func(QCryptoBlock *block,
902636
      * which will be used by the crypto header
902636
      */
902636
     return blk_truncate(data->blk, data->size + headerlen, false,
902636
-                        data->prealloc, errp);
902636
+                        data->prealloc, 0, errp);
902636
 }
902636
 
902636
 
902636
diff --git a/block/mirror.c b/block/mirror.c
902636
index 0d32fca..c8028cd 100644
902636
--- a/block/mirror.c
902636
+++ b/block/mirror.c
902636
@@ -886,7 +886,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
902636
     if (s->base == blk_bs(s->target)) {
902636
         if (s->bdev_length > target_length) {
902636
             ret = blk_truncate(s->target, s->bdev_length, false,
902636
-                               PREALLOC_MODE_OFF, NULL);
902636
+                               PREALLOC_MODE_OFF, 0, NULL);
902636
             if (ret < 0) {
902636
                 goto immediate_exit;
902636
             }
902636
diff --git a/block/qcow2.c b/block/qcow2.c
902636
index c0fdcb9..86aa74a 100644
902636
--- a/block/qcow2.c
902636
+++ b/block/qcow2.c
902636
@@ -3497,7 +3497,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
902636
 
902636
     /* Okay, now that we have a valid image, let's give it the right size */
902636
     ret = blk_truncate(blk, qcow2_opts->size, false, qcow2_opts->preallocation,
902636
-                       errp);
902636
+                       0, errp);
902636
     if (ret < 0) {
902636
         error_prepend(errp, "Could not resize image: ");
902636
         goto out;
902636
@@ -5347,7 +5347,7 @@ static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts,
902636
          * Amending image options should ensure that the image has
902636
          * exactly the given new values, so pass exact=true here.
902636
          */
902636
-        ret = blk_truncate(blk, new_size, true, PREALLOC_MODE_OFF, errp);
902636
+        ret = blk_truncate(blk, new_size, true, PREALLOC_MODE_OFF, 0, errp);
902636
         blk_unref(blk);
902636
         if (ret < 0) {
902636
             return ret;
902636
diff --git a/block/qed.c b/block/qed.c
902636
index fb6100b..b0fdb8f 100644
902636
--- a/block/qed.c
902636
+++ b/block/qed.c
902636
@@ -677,7 +677,7 @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCreateOptions *opts,
902636
      * The QED format associates file length with allocation status,
902636
      * so a new file (which is empty) must have a length of 0.
902636
      */
902636
-    ret = blk_truncate(blk, 0, true, PREALLOC_MODE_OFF, errp);
902636
+    ret = blk_truncate(blk, 0, true, PREALLOC_MODE_OFF, 0, errp);
902636
     if (ret < 0) {
902636
         goto out;
902636
     }
902636
diff --git a/block/vdi.c b/block/vdi.c
902636
index e1a11f2..0c7835a 100644
902636
--- a/block/vdi.c
902636
+++ b/block/vdi.c
902636
@@ -875,7 +875,7 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
902636
 
902636
     if (image_type == VDI_TYPE_STATIC) {
902636
         ret = blk_truncate(blk, offset + blocks * block_size, false,
902636
-                           PREALLOC_MODE_OFF, errp);
902636
+                           PREALLOC_MODE_OFF, 0, errp);
902636
         if (ret < 0) {
902636
             error_prepend(errp, "Failed to statically allocate file");
902636
             goto exit;
902636
diff --git a/block/vhdx.c b/block/vhdx.c
902636
index 5dfbb20..21497f7 100644
902636
--- a/block/vhdx.c
902636
+++ b/block/vhdx.c
902636
@@ -1703,13 +1703,13 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
902636
         /* All zeroes, so we can just extend the file - the end of the BAT
902636
          * is the furthest thing we have written yet */
902636
         ret = blk_truncate(blk, data_file_offset, false, PREALLOC_MODE_OFF,
902636
-                           errp);
902636
+                           0, errp);
902636
         if (ret < 0) {
902636
             goto exit;
902636
         }
902636
     } else if (type == VHDX_TYPE_FIXED) {
902636
         ret = blk_truncate(blk, data_file_offset + image_size, false,
902636
-                           PREALLOC_MODE_OFF, errp);
902636
+                           PREALLOC_MODE_OFF, 0, errp);
902636
         if (ret < 0) {
902636
             goto exit;
902636
         }
902636
diff --git a/block/vmdk.c b/block/vmdk.c
902636
index 1bbf937..1bd3991 100644
902636
--- a/block/vmdk.c
902636
+++ b/block/vmdk.c
902636
@@ -2118,7 +2118,7 @@ static int vmdk_init_extent(BlockBackend *blk,
902636
     int gd_buf_size;
902636
 
902636
     if (flat) {
902636
-        ret = blk_truncate(blk, filesize, false, PREALLOC_MODE_OFF, errp);
902636
+        ret = blk_truncate(blk, filesize, false, PREALLOC_MODE_OFF, 0, errp);
902636
         goto exit;
902636
     }
902636
     magic = cpu_to_be32(VMDK4_MAGIC);
902636
@@ -2182,7 +2182,7 @@ static int vmdk_init_extent(BlockBackend *blk,
902636
     }
902636
 
902636
     ret = blk_truncate(blk, le64_to_cpu(header.grain_offset) << 9, false,
902636
-                       PREALLOC_MODE_OFF, errp);
902636
+                       PREALLOC_MODE_OFF, 0, errp);
902636
     if (ret < 0) {
902636
         goto exit;
902636
     }
902636
@@ -2523,7 +2523,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
902636
     /* bdrv_pwrite write padding zeros to align to sector, we don't need that
902636
      * for description file */
902636
     if (desc_offset == 0) {
902636
-        ret = blk_truncate(blk, desc_len, false, PREALLOC_MODE_OFF, errp);
902636
+        ret = blk_truncate(blk, desc_len, false, PREALLOC_MODE_OFF, 0, errp);
902636
         if (ret < 0) {
902636
             goto exit;
902636
         }
902636
diff --git a/block/vpc.c b/block/vpc.c
902636
index 6df75e2..d5e7dc8 100644
902636
--- a/block/vpc.c
902636
+++ b/block/vpc.c
902636
@@ -898,7 +898,7 @@ static int create_fixed_disk(BlockBackend *blk, uint8_t *buf,
902636
     /* Add footer to total size */
902636
     total_size += HEADER_SIZE;
902636
 
902636
-    ret = blk_truncate(blk, total_size, false, PREALLOC_MODE_OFF, errp);
902636
+    ret = blk_truncate(blk, total_size, false, PREALLOC_MODE_OFF, 0, errp);
902636
     if (ret < 0) {
902636
         return ret;
902636
     }
902636
diff --git a/blockdev.c b/blockdev.c
902636
index 5128c9b..6dde52a 100644
902636
--- a/blockdev.c
902636
+++ b/blockdev.c
902636
@@ -3055,7 +3055,7 @@ void qmp_block_resize(bool has_device, const char *device,
902636
     }
902636
 
902636
     bdrv_drained_begin(bs);
902636
-    ret = blk_truncate(blk, size, false, PREALLOC_MODE_OFF, errp);
902636
+    ret = blk_truncate(blk, size, false, PREALLOC_MODE_OFF, 0, errp);
902636
     bdrv_drained_end(bs);
902636
 
902636
 out:
902636
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
902636
index 9bbdbd6..34de7fa 100644
902636
--- a/include/sysemu/block-backend.h
902636
+++ b/include/sysemu/block-backend.h
902636
@@ -237,7 +237,7 @@ int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
902636
 int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf,
902636
                           int bytes);
902636
 int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
902636
-                 PreallocMode prealloc, Error **errp);
902636
+                 PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
902636
 int blk_pdiscard(BlockBackend *blk, int64_t offset, int bytes);
902636
 int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
902636
                      int64_t pos, int size);
902636
diff --git a/qemu-img.c b/qemu-img.c
902636
index 6dc881b..a27ad70 100644
902636
--- a/qemu-img.c
902636
+++ b/qemu-img.c
902636
@@ -3939,7 +3939,7 @@ static int img_resize(int argc, char **argv)
902636
      * resizing, so pass @exact=true.  It is of no use to report
902636
      * success when the image has not actually been resized.
902636
      */
902636
-    ret = blk_truncate(blk, total_size, true, prealloc, &err;;
902636
+    ret = blk_truncate(blk, total_size, true, prealloc, 0, &err;;
902636
     if (!ret) {
902636
         qprintf(quiet, "Image resized.\n");
902636
     } else {
902636
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
902636
index 1b7e700..851f07e 100644
902636
--- a/qemu-io-cmds.c
902636
+++ b/qemu-io-cmds.c
902636
@@ -1715,7 +1715,7 @@ static int truncate_f(BlockBackend *blk, int argc, char **argv)
902636
      * exact=true.  It is better to err on the "emit more errors" side
902636
      * than to be overly permissive.
902636
      */
902636
-    ret = blk_truncate(blk, offset, true, PREALLOC_MODE_OFF, &local_err);
902636
+    ret = blk_truncate(blk, offset, true, PREALLOC_MODE_OFF, 0, &local_err);
902636
     if (ret < 0) {
902636
         error_report_err(local_err);
902636
         return ret;
902636
-- 
902636
1.8.3.1
902636