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