[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 14/55] sheepdog: Pass old and new size to sd_prealloc
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 14/55] sheepdog: Pass old and new size to sd_prealloc() |
Date: |
Tue, 13 Feb 2018 18:04:48 +0100 |
From: Max Reitz <address@hidden>
sd_prealloc() will now preallocate the area [old_size, new_size). As
before, it rounds to buf_size and may thus overshoot and preallocate
areas that were not requested to be preallocated. For image creation,
this is no change in behavior. For truncation, this is in accordance
with the documentation for preallocated truncation.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/sheepdog.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index cc1d37b3da..d300fb69c0 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1826,14 +1826,14 @@ static int do_sd_create(BDRVSheepdogState *s, uint32_t
*vdi_id, int snapshot,
return 0;
}
-static int sd_prealloc(BlockDriverState *bs, Error **errp)
+static int sd_prealloc(BlockDriverState *bs, int64_t old_size, int64_t
new_size,
+ Error **errp)
{
BlockBackend *blk = NULL;
BDRVSheepdogState *base = bs->opaque;
unsigned long buf_size;
uint32_t idx, max_idx;
uint32_t object_size;
- int64_t vdi_size;
void *buf = NULL;
int ret;
@@ -1847,19 +1847,13 @@ static int sd_prealloc(BlockDriverState *bs, Error
**errp)
blk_set_allow_write_beyond_eof(blk, true);
- vdi_size = blk_getlength(blk);
- if (vdi_size < 0) {
- ret = vdi_size;
- goto out;
- }
-
object_size = (UINT32_C(1) << base->inode.block_size_shift);
buf_size = MIN(object_size, SD_DATA_OBJ_SIZE);
buf = g_malloc0(buf_size);
- max_idx = DIV_ROUND_UP(vdi_size, buf_size);
+ max_idx = DIV_ROUND_UP(new_size, buf_size);
- for (idx = 0; idx < max_idx; idx++) {
+ for (idx = old_size / buf_size; idx < max_idx; idx++) {
/*
* The created image can be a cloned image, so we need to read
* a data from the source image.
@@ -2119,7 +2113,7 @@ static int sd_create(const char *filename, QemuOpts *opts,
goto out;
}
- ret = sd_prealloc(bs, errp);
+ ret = sd_prealloc(bs, 0, s->inode.vdi_size, errp);
bdrv_unref(bs);
}
--
2.13.6
- [Qemu-block] [PULL 11/55] gluster: Query current size in do_truncate(), (continued)
- [Qemu-block] [PULL 11/55] gluster: Query current size in do_truncate(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 04/55] docs: Document share-rw property more thoroughly, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 10/55] gluster: Pull truncation from qemu_gluster_create, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 06/55] block: early check for blockers on drive-mirror, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 05/55] qcow2: Use g_try_realloc() in qcow2_expand_zero_clusters(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 08/55] qemu-io: fix EOF Ctrl-D handling in qemu-io readline code, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 07/55] iotests: Use virtio-blk in 155, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 15/55] sheepdog: Allow fully preallocated truncation, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 13/55] sheepdog: Make sd_prealloc() take a BDS, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 17/55] qcow2: Fix documentation of get_cluster_table(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 14/55] sheepdog: Pass old and new size to sd_prealloc(),
Kevin Wolf <=
- [Qemu-block] [PULL 12/55] gluster: Add preallocated truncation, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 18/55] qcow2: Add table size field to Qcow2Cache, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 19/55] qcow2: Remove BDS parameter from qcow2_cache_get_table_addr(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 20/55] qcow2: Remove BDS parameter from qcow2_cache_get_table_idx(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 21/55] qcow2: Remove BDS parameter from qcow2_cache_table_release(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 26/55] qcow2: Remove BDS parameter from qcow2_cache_discard(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 16/55] block: maintain persistent disabled bitmaps, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 23/55] qcow2: Remove BDS parameter from qcow2_cache_put(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 22/55] qcow2: Remove BDS parameter from qcow2_cache_entry_mark_dirty(), Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 29/55] qcow2: Add l2_slice_size field to BDRVQcow2State, Kevin Wolf, 2018/02/13