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