Add a PreallocMode parameter to the bdrv_truncate() function implemented
by each block driver. Currently, we always pass PREALLOC_MODE_OFF and no
driver accepts anything else.
Signed-off-by: Max Reitz
---
include/block/block_int.h | 3 ++-
block.c | 2 +-
block/blkdebug.c | 9 -
block/crypto.c| 8 +++-
block/file-posix.c| 9 -
block/file-win32.c| 9 -
block/gluster.c | 8 +++-
block/iscsi.c | 9 -
block/nfs.c | 9 -
block/qcow2.c | 9 -
block/qed.c | 9 -
block/raw-format.c| 9 -
block/rbd.c | 9 -
block/sheepdog.c | 11 +--
14 files changed, 98 insertions(+), 15 deletions(-)
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 08063c10c8..10a2bef5b0 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -196,7 +196,8 @@ struct BlockDriver {
int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs);
const char *protocol_name;
-int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset, Error **errp);
+int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset,
+ PreallocMode prealloc, Error **errp);
int64_t (*bdrv_getlength)(BlockDriverState *bs);
bool has_variable_length;
diff --git a/block.c b/block.c
index 6df9723da7..30aed5ffb5 100644
--- a/block.c
+++ b/block.c
@@ -3285,7 +3285,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error
**errp)
return -EACCES;
}
-ret = drv->bdrv_truncate(bs, offset, errp);
+ret = drv->bdrv_truncate(bs, offset, PREALLOC_MODE_OFF, errp);
if (ret == 0) {
ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);
bdrv_dirty_bitmap_truncate(bs);
diff --git a/block/blkdebug.c b/block/blkdebug.c
index c795ae9e72..31a71a34d3 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -661,8 +661,15 @@ static int64_t blkdebug_getlength(BlockDriverState *bs)
return bdrv_getlength(bs->file->bs);
}
-static int blkdebug_truncate(BlockDriverState *bs, int64_t offset, Error
**errp)
+static int blkdebug_truncate(BlockDriverState *bs, int64_t offset,
+ PreallocMode prealloc, Error **errp)
{
+if (prealloc != PREALLOC_MODE_OFF) {
+error_setg(errp, "Unsupported preallocation mode '%s'",
+ PreallocMode_lookup[prealloc]);
+return -ENOTSUP;
+}
+
return bdrv_truncate(bs->file, offset, errp);
}
diff --git a/block/crypto.c b/block/crypto.c
index 17b3140998..fa61aef380 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -382,12 +382,18 @@ static int block_crypto_create_generic(QCryptoBlockFormat
format,
}
static int block_crypto_truncate(BlockDriverState *bs, int64_t offset,
- Error **errp)
+ PreallocMode prealloc, Error **errp)
{
BlockCrypto *crypto = bs->opaque;
size_t payload_offset =
qcrypto_block_get_payload_offset(crypto->block);
+if (prealloc != PREALLOC_MODE_OFF) {
+error_setg(errp, "Unsupported preallocation mode '%s'",
+ PreallocMode_lookup[prealloc]);
+return -ENOTSUP;
+}
+
offset += payload_offset;
return bdrv_truncate(bs->file, offset, errp);
diff --git a/block/file-posix.c b/block/file-posix.c
index 1941fb6749..3e9c416668 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1407,12 +1407,19 @@ static void raw_close(BlockDriverState *bs)
}
}
-static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
+static int raw_truncate(BlockDriverState *bs, int64_t offset,
+PreallocMode prealloc, Error **errp)
{
BDRVRawState *s = bs->opaque;
struct stat st;
int ret;
+if (prealloc != PREALLOC_MODE_OFF) {
+error_setg(errp, "Unsupported preallocation mode '%s'",
+ PreallocMode_lookup[prealloc]);
+return -ENOTSUP;
+}
+
if (fstat(s->fd, &st)) {
ret = -errno;
error_setg_errno(errp, -ret, "Failed to fstat() the file");
diff --git a/block/file-win32.c b/block/file-win32.c
index 7872e00a21..cd5033371c 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -460,12 +460,19 @@ static void raw_close(BlockDriverState *bs)
}
}
-static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
+static int raw_truncate(BlockDriverState *bs, int64_t offset,
+PreallocMode prealloc, Error **errp)
{
BDRVRawState *s = bs->opaque;
LONG low, high;
DWORD dwPtrLow;
+if (prealloc != PREALLOC_MODE_OFF) {
+error_setg(errp, "Unsupported preallocation mode '%s'",
+ PreallocMode_lookup[prealloc]);
+return -ENOTSUP;
+}
+
low = offset;
high = offset >> 3