|
|
ddf19c |
From 13e2076f5c4adbc9a3f96c8978150aa5e423e14a Mon Sep 17 00:00:00 2001
|
|
|
ddf19c |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
ddf19c |
Date: Mon, 8 Jun 2020 15:01:30 +0100
|
|
|
ddf19c |
Subject: [PATCH 02/17] block: Add flags to BlockDriver.bdrv_co_truncate()
|
|
|
ddf19c |
|
|
|
ddf19c |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
ddf19c |
Message-id: <20200608150140.38218-2-kwolf@redhat.com>
|
|
|
ddf19c |
Patchwork-id: 97448
|
|
|
ddf19c |
O-Subject: [RHEL-AV-8.2.1 qemu-kvm PATCH 01/11] block: Add flags to BlockDriver.bdrv_co_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 |
This adds a new BdrvRequestFlags parameter to the .bdrv_co_truncate()
|
|
|
ddf19c |
driver callbacks, and a supported_truncate_flags field in
|
|
|
ddf19c |
BlockDriverState that allows drivers to advertise support for request
|
|
|
ddf19c |
flags in the context of truncate.
|
|
|
ddf19c |
|
|
|
ddf19c |
For now, we always pass 0 and no drivers declare support for any flag.
|
|
|
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-2-kwolf@redhat.com>
|
|
|
ddf19c |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
ddf19c |
(cherry picked from commit 92b92799dc8662b6f71809100a4aabc1ae408ebb)
|
|
|
ddf19c |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
ddf19c |
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
|
|
|
ddf19c |
---
|
|
|
ddf19c |
block/crypto.c | 3 ++-
|
|
|
ddf19c |
block/file-posix.c | 2 +-
|
|
|
ddf19c |
block/file-win32.c | 2 +-
|
|
|
ddf19c |
block/gluster.c | 1 +
|
|
|
ddf19c |
block/io.c | 8 +++++++-
|
|
|
ddf19c |
block/iscsi.c | 2 +-
|
|
|
ddf19c |
block/nfs.c | 3 ++-
|
|
|
ddf19c |
block/qcow2.c | 2 +-
|
|
|
ddf19c |
block/qed.c | 1 +
|
|
|
ddf19c |
block/raw-format.c | 2 +-
|
|
|
ddf19c |
block/rbd.c | 1 +
|
|
|
ddf19c |
block/sheepdog.c | 4 ++--
|
|
|
ddf19c |
block/ssh.c | 2 +-
|
|
|
ddf19c |
include/block/block_int.h | 10 +++++++++-
|
|
|
ddf19c |
tests/test-block-iothread.c | 3 ++-
|
|
|
ddf19c |
15 files changed, 33 insertions(+), 13 deletions(-)
|
|
|
ddf19c |
|
|
|
ddf19c |
diff --git a/block/crypto.c b/block/crypto.c
|
|
|
ddf19c |
index 5e3b15c..6e4b726 100644
|
|
|
ddf19c |
--- a/block/crypto.c
|
|
|
ddf19c |
+++ b/block/crypto.c
|
|
|
ddf19c |
@@ -299,7 +299,8 @@ static int block_crypto_co_create_generic(BlockDriverState *bs,
|
|
|
ddf19c |
|
|
|
ddf19c |
static int coroutine_fn
|
|
|
ddf19c |
block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
|
|
|
ddf19c |
- PreallocMode prealloc, Error **errp)
|
|
|
ddf19c |
+ PreallocMode prealloc, BdrvRequestFlags flags,
|
|
|
ddf19c |
+ Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
BlockCrypto *crypto = bs->opaque;
|
|
|
ddf19c |
uint64_t payload_offset =
|
|
|
ddf19c |
diff --git a/block/file-posix.c b/block/file-posix.c
|
|
|
ddf19c |
index 1609598..7551e8d 100644
|
|
|
ddf19c |
--- a/block/file-posix.c
|
|
|
ddf19c |
+++ b/block/file-posix.c
|
|
|
ddf19c |
@@ -2021,7 +2021,7 @@ raw_regular_truncate(BlockDriverState *bs, int fd, int64_t offset,
|
|
|
ddf19c |
|
|
|
ddf19c |
static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
|
|
|
ddf19c |
bool exact, PreallocMode prealloc,
|
|
|
ddf19c |
- Error **errp)
|
|
|
ddf19c |
+ BdrvRequestFlags flags, Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
BDRVRawState *s = bs->opaque;
|
|
|
ddf19c |
struct stat st;
|
|
|
ddf19c |
diff --git a/block/file-win32.c b/block/file-win32.c
|
|
|
ddf19c |
index 1585983..a6b0dda 100644
|
|
|
ddf19c |
--- a/block/file-win32.c
|
|
|
ddf19c |
+++ b/block/file-win32.c
|
|
|
ddf19c |
@@ -469,7 +469,7 @@ static void raw_close(BlockDriverState *bs)
|
|
|
ddf19c |
|
|
|
ddf19c |
static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
|
|
|
ddf19c |
bool exact, PreallocMode prealloc,
|
|
|
ddf19c |
- Error **errp)
|
|
|
ddf19c |
+ BdrvRequestFlags flags, Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
BDRVRawState *s = bs->opaque;
|
|
|
ddf19c |
LONG low, high;
|
|
|
ddf19c |
diff --git a/block/gluster.c b/block/gluster.c
|
|
|
ddf19c |
index 0aa1f2c..d06df90 100644
|
|
|
ddf19c |
--- a/block/gluster.c
|
|
|
ddf19c |
+++ b/block/gluster.c
|
|
|
ddf19c |
@@ -1228,6 +1228,7 @@ static coroutine_fn int qemu_gluster_co_truncate(BlockDriverState *bs,
|
|
|
ddf19c |
int64_t offset,
|
|
|
ddf19c |
bool exact,
|
|
|
ddf19c |
PreallocMode prealloc,
|
|
|
ddf19c |
+ BdrvRequestFlags flags,
|
|
|
ddf19c |
Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
BDRVGlusterState *s = bs->opaque;
|
|
|
ddf19c |
diff --git a/block/io.c b/block/io.c
|
|
|
ddf19c |
index f75777f..549e5a4 100644
|
|
|
ddf19c |
--- a/block/io.c
|
|
|
ddf19c |
+++ b/block/io.c
|
|
|
ddf19c |
@@ -3320,6 +3320,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
|
|
|
ddf19c |
BlockDriverState *bs = child->bs;
|
|
|
ddf19c |
BlockDriver *drv = bs->drv;
|
|
|
ddf19c |
BdrvTrackedRequest req;
|
|
|
ddf19c |
+ BdrvRequestFlags flags = 0;
|
|
|
ddf19c |
int64_t old_size, new_bytes;
|
|
|
ddf19c |
int ret;
|
|
|
ddf19c |
|
|
|
ddf19c |
@@ -3370,7 +3371,12 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
if (drv->bdrv_co_truncate) {
|
|
|
ddf19c |
- ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, errp);
|
|
|
ddf19c |
+ if (flags & ~bs->supported_truncate_flags) {
|
|
|
ddf19c |
+ error_setg(errp, "Block driver does not support requested flags");
|
|
|
ddf19c |
+ ret = -ENOTSUP;
|
|
|
ddf19c |
+ goto out;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ ret = drv->bdrv_co_truncate(bs, offset, exact, prealloc, flags, errp);
|
|
|
ddf19c |
} else if (bs->file && drv->is_filter) {
|
|
|
ddf19c |
ret = bdrv_co_truncate(bs->file, offset, exact, prealloc, errp);
|
|
|
ddf19c |
} else {
|
|
|
ddf19c |
diff --git a/block/iscsi.c b/block/iscsi.c
|
|
|
ddf19c |
index 16b0716..0bea2d3 100644
|
|
|
ddf19c |
--- a/block/iscsi.c
|
|
|
ddf19c |
+++ b/block/iscsi.c
|
|
|
ddf19c |
@@ -2125,7 +2125,7 @@ static void iscsi_reopen_commit(BDRVReopenState *reopen_state)
|
|
|
ddf19c |
|
|
|
ddf19c |
static int coroutine_fn iscsi_co_truncate(BlockDriverState *bs, int64_t offset,
|
|
|
ddf19c |
bool exact, PreallocMode prealloc,
|
|
|
ddf19c |
- Error **errp)
|
|
|
ddf19c |
+ BdrvRequestFlags flags, Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
IscsiLun *iscsilun = bs->opaque;
|
|
|
ddf19c |
int64_t cur_length;
|
|
|
ddf19c |
diff --git a/block/nfs.c b/block/nfs.c
|
|
|
ddf19c |
index cc2413d..2393fbf 100644
|
|
|
ddf19c |
--- a/block/nfs.c
|
|
|
ddf19c |
+++ b/block/nfs.c
|
|
|
ddf19c |
@@ -755,7 +755,8 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)
|
|
|
ddf19c |
|
|
|
ddf19c |
static int coroutine_fn
|
|
|
ddf19c |
nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
|
|
|
ddf19c |
- PreallocMode prealloc, Error **errp)
|
|
|
ddf19c |
+ PreallocMode prealloc, BdrvRequestFlags flags,
|
|
|
ddf19c |
+ Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
NFSClient *client = bs->opaque;
|
|
|
ddf19c |
int ret;
|
|
|
ddf19c |
diff --git a/block/qcow2.c b/block/qcow2.c
|
|
|
ddf19c |
index dbd870a..977445e 100644
|
|
|
ddf19c |
--- a/block/qcow2.c
|
|
|
ddf19c |
+++ b/block/qcow2.c
|
|
|
ddf19c |
@@ -3948,7 +3948,7 @@ fail:
|
|
|
ddf19c |
|
|
|
ddf19c |
static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
|
|
|
ddf19c |
bool exact, PreallocMode prealloc,
|
|
|
ddf19c |
- Error **errp)
|
|
|
ddf19c |
+ BdrvRequestFlags flags, Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
BDRVQcow2State *s = bs->opaque;
|
|
|
ddf19c |
uint64_t old_length;
|
|
|
ddf19c |
diff --git a/block/qed.c b/block/qed.c
|
|
|
ddf19c |
index 1af9b3c..fb6100b 100644
|
|
|
ddf19c |
--- a/block/qed.c
|
|
|
ddf19c |
+++ b/block/qed.c
|
|
|
ddf19c |
@@ -1467,6 +1467,7 @@ static int coroutine_fn bdrv_qed_co_truncate(BlockDriverState *bs,
|
|
|
ddf19c |
int64_t offset,
|
|
|
ddf19c |
bool exact,
|
|
|
ddf19c |
PreallocMode prealloc,
|
|
|
ddf19c |
+ BdrvRequestFlags flags,
|
|
|
ddf19c |
Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
BDRVQEDState *s = bs->opaque;
|
|
|
ddf19c |
diff --git a/block/raw-format.c b/block/raw-format.c
|
|
|
ddf19c |
index 4bb54f4..f994c4a 100644
|
|
|
ddf19c |
--- a/block/raw-format.c
|
|
|
ddf19c |
+++ b/block/raw-format.c
|
|
|
ddf19c |
@@ -371,7 +371,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
|
|
|
ddf19c |
|
|
|
ddf19c |
static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
|
|
|
ddf19c |
bool exact, PreallocMode prealloc,
|
|
|
ddf19c |
- Error **errp)
|
|
|
ddf19c |
+ BdrvRequestFlags flags, Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
BDRVRawState *s = bs->opaque;
|
|
|
ddf19c |
|
|
|
ddf19c |
diff --git a/block/rbd.c b/block/rbd.c
|
|
|
ddf19c |
index 8847259..fcdb60a 100644
|
|
|
ddf19c |
--- a/block/rbd.c
|
|
|
ddf19c |
+++ b/block/rbd.c
|
|
|
ddf19c |
@@ -1090,6 +1090,7 @@ static int coroutine_fn qemu_rbd_co_truncate(BlockDriverState *bs,
|
|
|
ddf19c |
int64_t offset,
|
|
|
ddf19c |
bool exact,
|
|
|
ddf19c |
PreallocMode prealloc,
|
|
|
ddf19c |
+ BdrvRequestFlags flags,
|
|
|
ddf19c |
Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
int r;
|
|
|
ddf19c |
diff --git a/block/sheepdog.c b/block/sheepdog.c
|
|
|
ddf19c |
index a8a7e32..077aed8 100644
|
|
|
ddf19c |
--- a/block/sheepdog.c
|
|
|
ddf19c |
+++ b/block/sheepdog.c
|
|
|
ddf19c |
@@ -2288,7 +2288,7 @@ static int64_t sd_getlength(BlockDriverState *bs)
|
|
|
ddf19c |
|
|
|
ddf19c |
static int coroutine_fn sd_co_truncate(BlockDriverState *bs, int64_t offset,
|
|
|
ddf19c |
bool exact, PreallocMode prealloc,
|
|
|
ddf19c |
- Error **errp)
|
|
|
ddf19c |
+ BdrvRequestFlags flags, Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
BDRVSheepdogState *s = bs->opaque;
|
|
|
ddf19c |
int ret, fd;
|
|
|
ddf19c |
@@ -2604,7 +2604,7 @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
|
|
|
ddf19c |
|
|
|
ddf19c |
assert(!flags);
|
|
|
ddf19c |
if (offset > s->inode.vdi_size) {
|
|
|
ddf19c |
- ret = sd_co_truncate(bs, offset, false, PREALLOC_MODE_OFF, NULL);
|
|
|
ddf19c |
+ ret = sd_co_truncate(bs, offset, false, PREALLOC_MODE_OFF, 0, NULL);
|
|
|
ddf19c |
if (ret < 0) {
|
|
|
ddf19c |
return ret;
|
|
|
ddf19c |
}
|
|
|
ddf19c |
diff --git a/block/ssh.c b/block/ssh.c
|
|
|
ddf19c |
index 84e9282..9eb33df 100644
|
|
|
ddf19c |
--- a/block/ssh.c
|
|
|
ddf19c |
+++ b/block/ssh.c
|
|
|
ddf19c |
@@ -1298,7 +1298,7 @@ static int64_t ssh_getlength(BlockDriverState *bs)
|
|
|
ddf19c |
|
|
|
ddf19c |
static int coroutine_fn ssh_co_truncate(BlockDriverState *bs, int64_t offset,
|
|
|
ddf19c |
bool exact, PreallocMode prealloc,
|
|
|
ddf19c |
- Error **errp)
|
|
|
ddf19c |
+ BdrvRequestFlags flags, Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
BDRVSSHState *s = bs->opaque;
|
|
|
ddf19c |
|
|
|
ddf19c |
diff --git a/include/block/block_int.h b/include/block/block_int.h
|
|
|
ddf19c |
index 876a83d..41f13ec 100644
|
|
|
ddf19c |
--- a/include/block/block_int.h
|
|
|
ddf19c |
+++ b/include/block/block_int.h
|
|
|
ddf19c |
@@ -356,7 +356,7 @@ struct BlockDriver {
|
|
|
ddf19c |
*/
|
|
|
ddf19c |
int coroutine_fn (*bdrv_co_truncate)(BlockDriverState *bs, int64_t offset,
|
|
|
ddf19c |
bool exact, PreallocMode prealloc,
|
|
|
ddf19c |
- Error **errp);
|
|
|
ddf19c |
+ BdrvRequestFlags flags, Error **errp);
|
|
|
ddf19c |
|
|
|
ddf19c |
int64_t (*bdrv_getlength)(BlockDriverState *bs);
|
|
|
ddf19c |
bool has_variable_length;
|
|
|
ddf19c |
@@ -849,6 +849,14 @@ struct BlockDriverState {
|
|
|
ddf19c |
/* Flags honored during pwrite_zeroes (so far: BDRV_REQ_FUA,
|
|
|
ddf19c |
* BDRV_REQ_MAY_UNMAP, BDRV_REQ_WRITE_UNCHANGED) */
|
|
|
ddf19c |
unsigned int supported_zero_flags;
|
|
|
ddf19c |
+ /*
|
|
|
ddf19c |
+ * Flags honoured during truncate (so far: BDRV_REQ_ZERO_WRITE).
|
|
|
ddf19c |
+ *
|
|
|
ddf19c |
+ * If BDRV_REQ_ZERO_WRITE is given, the truncate operation must make sure
|
|
|
ddf19c |
+ * that any added space reads as all zeros. If this can't be guaranteed,
|
|
|
ddf19c |
+ * the operation must fail.
|
|
|
ddf19c |
+ */
|
|
|
ddf19c |
+ unsigned int supported_truncate_flags;
|
|
|
ddf19c |
|
|
|
ddf19c |
/* the following member gives a name to every node on the bs graph. */
|
|
|
ddf19c |
char node_name[32];
|
|
|
ddf19c |
diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c
|
|
|
ddf19c |
index 0c86180..2f3b763 100644
|
|
|
ddf19c |
--- a/tests/test-block-iothread.c
|
|
|
ddf19c |
+++ b/tests/test-block-iothread.c
|
|
|
ddf19c |
@@ -46,7 +46,8 @@ static int coroutine_fn bdrv_test_co_pdiscard(BlockDriverState *bs,
|
|
|
ddf19c |
|
|
|
ddf19c |
static int coroutine_fn
|
|
|
ddf19c |
bdrv_test_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
|
|
|
ddf19c |
- PreallocMode prealloc, Error **errp)
|
|
|
ddf19c |
+ PreallocMode prealloc, BdrvRequestFlags flags,
|
|
|
ddf19c |
+ Error **errp)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
return 0;
|
|
|
ddf19c |
}
|
|
|
ddf19c |
--
|
|
|
ddf19c |
1.8.3.1
|
|
|
ddf19c |
|