[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 28/30] parallels: Rework truncation logic
From: |
Kevin Wolf |
Subject: |
[PULL 28/30] parallels: Rework truncation logic |
Date: |
Fri, 8 May 2020 14:41:33 +0200 |
From: Eric Blake <address@hidden>
The parallels driver tries to use truncation for image growth, but can
only do so when reads are guaranteed as zero. Now that we have a way
to request zero contents from truncation, we can defer the decision to
actual allocation attempts rather than up front, reducing the number
of places that still use bdrv_has_zero_init_truncate.
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Denis V. Lunev <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/parallels.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/block/parallels.c b/block/parallels.c
index 8db64a55e3..e7717c508e 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -166,7 +166,7 @@ static int64_t block_status(BDRVParallelsState *s, int64_t
sector_num,
static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, int *pnum)
{
- int ret;
+ int ret = 0;
BDRVParallelsState *s = bs->opaque;
int64_t pos, space, idx, to_allocate, i, len;
@@ -196,14 +196,24 @@ static int64_t allocate_clusters(BlockDriverState *bs,
int64_t sector_num,
}
if (s->data_end + space > (len >> BDRV_SECTOR_BITS)) {
space += s->prealloc_size;
+ /*
+ * We require the expanded size to read back as zero. If the
+ * user permitted truncation, we try that; but if it fails, we
+ * force the safer-but-slower fallocate.
+ */
+ if (s->prealloc_mode == PRL_PREALLOC_MODE_TRUNCATE) {
+ ret = bdrv_truncate(bs->file,
+ (s->data_end + space) << BDRV_SECTOR_BITS,
+ false, PREALLOC_MODE_OFF, BDRV_REQ_ZERO_WRITE,
+ NULL);
+ if (ret == -ENOTSUP) {
+ s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
+ }
+ }
if (s->prealloc_mode == PRL_PREALLOC_MODE_FALLOCATE) {
ret = bdrv_pwrite_zeroes(bs->file,
s->data_end << BDRV_SECTOR_BITS,
space << BDRV_SECTOR_BITS, 0);
- } else {
- ret = bdrv_truncate(bs->file,
- (s->data_end + space) << BDRV_SECTOR_BITS,
- false, PREALLOC_MODE_OFF, 0, NULL);
}
if (ret < 0) {
return ret;
@@ -828,6 +838,7 @@ static int parallels_open(BlockDriverState *bs, QDict
*options, int flags,
qemu_opt_get_size_del(opts, PARALLELS_OPT_PREALLOC_SIZE, 0);
s->prealloc_size = MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BITS);
buf = qemu_opt_get_del(opts, PARALLELS_OPT_PREALLOC_MODE);
+ /* prealloc_mode can be downgraded later during allocate_clusters */
s->prealloc_mode = qapi_enum_parse(&prealloc_mode_lookup, buf,
PRL_PREALLOC_MODE_FALLOCATE,
&local_err);
@@ -836,10 +847,6 @@ static int parallels_open(BlockDriverState *bs, QDict
*options, int flags,
goto fail_options;
}
- if (!bdrv_has_zero_init_truncate(bs->file->bs)) {
- s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
- }
-
if ((flags & BDRV_O_RDWR) && !(flags & BDRV_O_INACTIVE)) {
s->header->inuse = cpu_to_le32(HEADER_INUSE_MAGIC);
ret = parallels_update_header(bs);
--
2.25.3
- [PULL 17/30] backup: Improve error for bdrv_getlength() failure, (continued)
- [PULL 17/30] backup: Improve error for bdrv_getlength() failure, Kevin Wolf, 2020/05/08
- [PULL 26/30] sheepdog: Support BDRV_REQ_ZERO_WRITE for truncate, Kevin Wolf, 2020/05/08
- [PULL 30/30] block: Drop unused .bdrv_has_zero_init_truncate, Kevin Wolf, 2020/05/08
- [PULL 29/30] vhdx: Rework truncation logic, Kevin Wolf, 2020/05/08
- [PULL 21/30] qcow2: Fix preallocation on block devices, Kevin Wolf, 2020/05/08
- [PULL 23/30] file-win32: Support BDRV_REQ_ZERO_WRITE for truncate, Kevin Wolf, 2020/05/08
- [PULL 19/30] iotests: Backup with different source/target size, Kevin Wolf, 2020/05/08
- [PULL 25/30] rbd: Support BDRV_REQ_ZERO_WRITE for truncate, Kevin Wolf, 2020/05/08
- [PULL 27/30] ssh: Support BDRV_REQ_ZERO_WRITE for truncate, Kevin Wolf, 2020/05/08
- [PULL 24/30] nfs: Support BDRV_REQ_ZERO_WRITE for truncate, Kevin Wolf, 2020/05/08
- [PULL 28/30] parallels: Rework truncation logic,
Kevin Wolf <=
- [PULL 22/30] gluster: Drop useless has_zero_init callback, Kevin Wolf, 2020/05/08
- Re: [PULL 00/30] Block layer patches, Peter Maydell, 2020/05/08