aboutsummaryrefslogtreecommitdiff
path: root/block/sheepdog.c
diff options
context:
space:
mode:
authorMax Reitz <mreitz@redhat.com>2018-02-13 14:03:56 +0100
committerKevin Wolf <kwolf@redhat.com>2018-02-13 16:18:41 +0100
commit74f1eabf9cbdd168f0aceae97a0f6645d1ce7ebd (patch)
tree66564049067b2f18a8b1728140ae2bc04c478a53 /block/sheepdog.c
parent1a62baf62bdc30ec4856ac569cefb9d831808253 (diff)
downloadqemu-74f1eabf9cbdd168f0aceae97a0f6645d1ce7ebd.zip
qemu-74f1eabf9cbdd168f0aceae97a0f6645d1ce7ebd.tar.gz
qemu-74f1eabf9cbdd168f0aceae97a0f6645d1ce7ebd.tar.bz2
sheepdog: Allow fully preallocated truncation
Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/sheepdog.c')
-rw-r--r--block/sheepdog.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/block/sheepdog.c b/block/sheepdog.c
index d300fb6..ac02b10 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2180,15 +2180,16 @@ static int sd_truncate(BlockDriverState *bs, int64_t offset,
int ret, fd;
unsigned int datalen;
uint64_t max_vdi_size;
+ int64_t old_size = s->inode.vdi_size;
- if (prealloc != PREALLOC_MODE_OFF) {
+ if (prealloc != PREALLOC_MODE_OFF && prealloc != PREALLOC_MODE_FULL) {
error_setg(errp, "Unsupported preallocation mode '%s'",
PreallocMode_str(prealloc));
return -ENOTSUP;
}
max_vdi_size = (UINT64_C(1) << s->inode.block_size_shift) * MAX_DATA_OBJS;
- if (offset < s->inode.vdi_size) {
+ if (offset < old_size) {
error_setg(errp, "shrinking is not supported");
return -EINVAL;
} else if (offset > max_vdi_size) {
@@ -2211,9 +2212,17 @@ static int sd_truncate(BlockDriverState *bs, int64_t offset,
if (ret < 0) {
error_setg_errno(errp, -ret, "failed to update an inode");
+ return ret;
}
- return ret;
+ if (prealloc == PREALLOC_MODE_FULL) {
+ ret = sd_prealloc(bs, old_size, offset, errp);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+
+ return 0;
}
/*