aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2017-06-13 22:20:53 +0200
committerMax Reitz <mreitz@redhat.com>2017-07-11 17:45:01 +0200
commit7ea37c30660d4cd6aca21a324fabefe23b89f931 (patch)
tree897afd4ead51179dfb1473bfa44a92a4de121f1f
parent8243ccb7433e59a3faa3cca27fb6c40d6da2b37c (diff)
block: Add PreallocMode to bdrv_truncate()
For block drivers that just pass a truncate request to the underlying protocol, we can now pass the preallocation mode instead of aborting if it is not PREALLOC_MODE_OFF. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-id: 20170613202107.10125-3-mreitz@redhat.com Signed-off-by: Max Reitz <mreitz@redhat.com>
-rw-r--r--block.c5
-rw-r--r--block/blkdebug.c8
-rw-r--r--block/block-backend.c2
-rw-r--r--block/crypto.c8
-rw-r--r--block/parallels.c11
-rw-r--r--block/qcow.c6
-rw-r--r--block/qcow2-refcount.c2
-rw-r--r--block/qcow2.c4
-rw-r--r--block/raw-format.c8
-rw-r--r--block/vhdx-log.c2
-rw-r--r--block/vhdx.c3
-rw-r--r--include/block/block.h3
12 files changed, 26 insertions, 36 deletions
diff --git a/block.c b/block.c
index 37e7b3d30a..d24ae85868 100644
--- a/block.c
+++ b/block.c
@@ -3411,7 +3411,8 @@ exit:
/**
* Truncate file to 'offset' bytes (needed only for file protocols)
*/
-int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)
+int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc,
+ Error **errp)
{
BlockDriverState *bs = child->bs;
BlockDriver *drv = bs->drv;
@@ -3434,7 +3435,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)
assert(!(bs->open_flags & BDRV_O_INACTIVE));
- ret = drv->bdrv_truncate(bs, offset, PREALLOC_MODE_OFF, errp);
+ ret = drv->bdrv_truncate(bs, offset, prealloc, 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 a9b03ff0a2..c19ab28f07 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -824,13 +824,7 @@ static int64_t blkdebug_getlength(BlockDriverState *bs)
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);
+ return bdrv_truncate(bs->file, offset, prealloc, errp);
}
static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options)
diff --git a/block/block-backend.c b/block/block-backend.c
index 0df3457a09..3c1b75648a 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1780,7 +1780,7 @@ int blk_truncate(BlockBackend *blk, int64_t offset, Error **errp)
return -ENOMEDIUM;
}
- return bdrv_truncate(blk->root, offset, errp);
+ return bdrv_truncate(blk->root, offset, PREALLOC_MODE_OFF, errp);
}
static void blk_pdiscard_entry(void *opaque)
diff --git a/block/crypto.c b/block/crypto.c
index 33f690f6d8..58ef6f2f52 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -367,15 +367,9 @@ static int block_crypto_truncate(BlockDriverState *bs, int64_t offset,
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);
+ return bdrv_truncate(bs->file, offset, prealloc, errp);
}
static void block_crypto_close(BlockDriverState *bs)
diff --git a/block/parallels.c b/block/parallels.c
index 8be46a7d48..5a38998cbb 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -224,7 +224,7 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
} else {
ret = bdrv_truncate(bs->file,
(s->data_end + space) << BDRV_SECTOR_BITS,
- NULL);
+ PREALLOC_MODE_OFF, NULL);
}
if (ret < 0) {
return ret;
@@ -458,7 +458,8 @@ static int parallels_check(BlockDriverState *bs, BdrvCheckResult *res,
res->leaks += count;
if (fix & BDRV_FIX_LEAKS) {
Error *local_err = NULL;
- ret = bdrv_truncate(bs->file, res->image_end_offset, &local_err);
+ ret = bdrv_truncate(bs->file, res->image_end_offset,
+ PREALLOC_MODE_OFF, &local_err);
if (ret < 0) {
error_report_err(local_err);
res->check_errors++;
@@ -699,7 +700,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
}
if (!(flags & BDRV_O_RESIZE) || !bdrv_has_zero_init(bs->file->bs) ||
- bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs), NULL) != 0) {
+ bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs),
+ PREALLOC_MODE_OFF, NULL) != 0) {
s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
}
@@ -742,7 +744,8 @@ static void parallels_close(BlockDriverState *bs)
}
if (bs->open_flags & BDRV_O_RDWR) {
- bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS, NULL);
+ bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS,
+ PREALLOC_MODE_OFF, NULL);
}
g_free(s->bat_dirty_bmap);
diff --git a/block/qcow.c b/block/qcow.c
index 2002c169be..10c96b86aa 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -443,7 +443,8 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
/* round to cluster size */
cluster_offset = (cluster_offset + s->cluster_size - 1) &
~(s->cluster_size - 1);
- bdrv_truncate(bs->file, cluster_offset + s->cluster_size, NULL);
+ bdrv_truncate(bs->file, cluster_offset + s->cluster_size,
+ PREALLOC_MODE_OFF, NULL);
/* if encrypted, we must initialize the cluster
content which won't be written */
if (bs->encrypted &&
@@ -923,7 +924,8 @@ static int qcow_make_empty(BlockDriverState *bs)
if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table,
l1_length) < 0)
return -1;
- ret = bdrv_truncate(bs->file, s->l1_table_offset + l1_length, NULL);
+ ret = bdrv_truncate(bs->file, s->l1_table_offset + l1_length,
+ PREALLOC_MODE_OFF, NULL);
if (ret < 0)
return ret;
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index ceb08bc16f..e82e155208 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -1732,7 +1732,7 @@ static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,
}
ret = bdrv_truncate(bs->file, offset + s->cluster_size,
- &local_err);
+ PREALLOC_MODE_OFF, &local_err);
if (ret < 0) {
error_report_err(local_err);
goto resize_fail;
diff --git a/block/qcow2.c b/block/qcow2.c
index b7c5994f0d..7391b497f7 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3133,7 +3133,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uint64_t offset,
/* align end of file to a sector boundary to ease reading with
sector based I/Os */
cluster_offset = bdrv_getlength(bs->file->bs);
- return bdrv_truncate(bs->file, cluster_offset, NULL);
+ return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, NULL);
}
buf = qemu_blockalign(bs, s->cluster_size);
@@ -3349,7 +3349,7 @@ static int make_completely_empty(BlockDriverState *bs)
}
ret = bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size,
- &local_err);
+ PREALLOC_MODE_OFF, &local_err);
if (ret < 0) {
error_report_err(local_err);
goto fail;
diff --git a/block/raw-format.c b/block/raw-format.c
index 721c9a025b..142649ed56 100644
--- a/block/raw-format.c
+++ b/block/raw-format.c
@@ -357,12 +357,6 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset,
{
BDRVRawState *s = bs->opaque;
- if (prealloc != PREALLOC_MODE_OFF) {
- error_setg(errp, "Unsupported preallocation mode '%s'",
- PreallocMode_lookup[prealloc]);
- return -ENOTSUP;
- }
-
if (s->has_size) {
error_setg(errp, "Cannot resize fixed-size raw disks");
return -ENOTSUP;
@@ -375,7 +369,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset,
s->size = offset;
offset += s->offset;
- return bdrv_truncate(bs->file, offset, errp);
+ return bdrv_truncate(bs->file, offset, prealloc, errp);
}
static int raw_media_changed(BlockDriverState *bs)
diff --git a/block/vhdx-log.c b/block/vhdx-log.c
index 3f4c2aa095..01278f3fc9 100644
--- a/block/vhdx-log.c
+++ b/block/vhdx-log.c
@@ -548,7 +548,7 @@ static int vhdx_log_flush(BlockDriverState *bs, BDRVVHDXState *s,
if (new_file_size % (1024*1024)) {
/* round up to nearest 1MB boundary */
new_file_size = ((new_file_size >> 20) + 1) << 20;
- bdrv_truncate(bs->file, new_file_size, NULL);
+ bdrv_truncate(bs->file, new_file_size, PREALLOC_MODE_OFF, NULL);
}
}
qemu_vfree(desc_entries);
diff --git a/block/vhdx.c b/block/vhdx.c
index 8b270b57c9..85c476a152 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1171,7 +1171,8 @@ static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s,
/* per the spec, the address for a block is in units of 1MB */
*new_offset = ROUND_UP(*new_offset, 1024 * 1024);
- return bdrv_truncate(bs->file, *new_offset + s->block_size, NULL);
+ return bdrv_truncate(bs->file, *new_offset + s->block_size,
+ PREALLOC_MODE_OFF, NULL);
}
/*
diff --git a/include/block/block.h b/include/block/block.h
index 96edc85129..b3e2674845 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -302,7 +302,8 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
const char *backing_file);
int bdrv_get_backing_file_depth(BlockDriverState *bs);
void bdrv_refresh_filename(BlockDriverState *bs);
-int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp);
+int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc,
+ Error **errp);
int64_t bdrv_nb_sectors(BlockDriverState *bs);
int64_t bdrv_getlength(BlockDriverState *bs);
int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);