[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 3/7] gluster: Query current size in do_truncate()
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH 3/7] gluster: Query current size in do_truncate() |
Date: |
Tue, 13 Feb 2018 14:03:52 +0100 |
Instead of expecting the current size to be 0, query it and allocate
only the area [current_size, offset) if preallocation is requested.
Signed-off-by: Max Reitz <address@hidden>
---
block/gluster.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/block/gluster.c b/block/gluster.c
index 8178541416..806b894bc8 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -968,10 +968,27 @@ static coroutine_fn int
qemu_gluster_co_pwrite_zeroes(BlockDriverState *bs,
static int qemu_gluster_do_truncate(struct glfs_fd *fd, int64_t offset,
PreallocMode prealloc, Error **errp)
{
+ int64_t current_length;
+
+ current_length = glfs_lseek(fd, 0, SEEK_END);
+ if (current_length < 0) {
+ error_setg_errno(errp, errno, "Failed to determine current size");
+ return -errno;
+ }
+
+ if (current_length > offset && prealloc != PREALLOC_MODE_OFF) {
+ error_setg(errp, "Cannot use preallocation for shrinking files");
+ return -ENOTSUP;
+ }
+
+ if (current_length == offset) {
+ return 0;
+ }
+
switch (prealloc) {
#ifdef CONFIG_GLUSTERFS_FALLOCATE
case PREALLOC_MODE_FALLOC:
- if (glfs_fallocate(fd, 0, 0, offset)) {
+ if (glfs_fallocate(fd, 0, current_length, offset - current_length)) {
error_setg_errno(errp, errno, "Could not preallocate data");
return -errno;
}
@@ -983,7 +1000,7 @@ static int qemu_gluster_do_truncate(struct glfs_fd *fd,
int64_t offset,
error_setg_errno(errp, errno, "Could not resize file");
return -errno;
}
- if (glfs_zerofill(fd, 0, offset)) {
+ if (glfs_zerofill(fd, current_length, offset - current_length)) {
error_setg_errno(errp, errno, "Could not zerofill the new area");
return -errno;
}
--
2.14.3
- [Qemu-block] [PATCH 2/7] gluster: Pull truncation from qemu_gluster_create, (continued)
- [Qemu-block] [PATCH 2/7] gluster: Pull truncation from qemu_gluster_create, Max Reitz, 2018/02/13
- [Qemu-block] [PATCH 4/7] gluster: Add preallocated truncation, Max Reitz, 2018/02/13
- [Qemu-block] [PATCH 1/7] gluster: Move glfs_close() to create's clean-up, Max Reitz, 2018/02/13
- [Qemu-block] [PATCH 5/7] sheepdog: Make sd_prealloc() take a BDS, Max Reitz, 2018/02/13
- [Qemu-block] [PATCH 7/7] sheepdog: Allow fully preallocated truncation, Max Reitz, 2018/02/13
- [Qemu-block] [PATCH 3/7] gluster: Query current size in do_truncate(),
Max Reitz <=
- [Qemu-block] [PATCH 6/7] sheepdog: Pass old and new size to sd_prealloc(), Max Reitz, 2018/02/13
- Re: [Qemu-block] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog, Kevin Wolf, 2018/02/13