[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 10/55] gluster: Pull truncation from qemu_gluster_cre
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 10/55] gluster: Pull truncation from qemu_gluster_create |
Date: |
Tue, 13 Feb 2018 18:04:44 +0100 |
From: Max Reitz <address@hidden>
Pull out the truncation code from the qemu_cluster_create() function so
we can later reuse it in qemu_gluster_truncate().
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/gluster.c | 74 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 40 insertions(+), 34 deletions(-)
diff --git a/block/gluster.c b/block/gluster.c
index 7fab2dfa12..8178541416 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -965,6 +965,45 @@ static coroutine_fn int
qemu_gluster_co_pwrite_zeroes(BlockDriverState *bs,
}
#endif
+static int qemu_gluster_do_truncate(struct glfs_fd *fd, int64_t offset,
+ PreallocMode prealloc, Error **errp)
+{
+ switch (prealloc) {
+#ifdef CONFIG_GLUSTERFS_FALLOCATE
+ case PREALLOC_MODE_FALLOC:
+ if (glfs_fallocate(fd, 0, 0, offset)) {
+ error_setg_errno(errp, errno, "Could not preallocate data");
+ return -errno;
+ }
+ break;
+#endif /* CONFIG_GLUSTERFS_FALLOCATE */
+#ifdef CONFIG_GLUSTERFS_ZEROFILL
+ case PREALLOC_MODE_FULL:
+ if (glfs_ftruncate(fd, offset)) {
+ error_setg_errno(errp, errno, "Could not resize file");
+ return -errno;
+ }
+ if (glfs_zerofill(fd, 0, offset)) {
+ error_setg_errno(errp, errno, "Could not zerofill the new area");
+ return -errno;
+ }
+ break;
+#endif /* CONFIG_GLUSTERFS_ZEROFILL */
+ case PREALLOC_MODE_OFF:
+ if (glfs_ftruncate(fd, offset)) {
+ error_setg_errno(errp, errno, "Could not resize file");
+ return -errno;
+ }
+ break;
+ default:
+ error_setg(errp, "Unsupported preallocation mode: %s",
+ PreallocMode_str(prealloc));
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static int qemu_gluster_create(const char *filename,
QemuOpts *opts, Error **errp)
{
@@ -1019,40 +1058,7 @@ static int qemu_gluster_create(const char *filename,
goto out;
}
- switch (prealloc) {
-#ifdef CONFIG_GLUSTERFS_FALLOCATE
- case PREALLOC_MODE_FALLOC:
- if (glfs_fallocate(fd, 0, 0, total_size)) {
- error_setg(errp, "Could not preallocate data for the new file");
- ret = -errno;
- }
- break;
-#endif /* CONFIG_GLUSTERFS_FALLOCATE */
-#ifdef CONFIG_GLUSTERFS_ZEROFILL
- case PREALLOC_MODE_FULL:
- if (!glfs_ftruncate(fd, total_size)) {
- if (glfs_zerofill(fd, 0, total_size)) {
- error_setg(errp, "Could not zerofill the new file");
- ret = -errno;
- }
- } else {
- error_setg(errp, "Could not resize file");
- ret = -errno;
- }
- break;
-#endif /* CONFIG_GLUSTERFS_ZEROFILL */
- case PREALLOC_MODE_OFF:
- if (glfs_ftruncate(fd, total_size) != 0) {
- ret = -errno;
- error_setg(errp, "Could not resize file");
- }
- break;
- default:
- ret = -EINVAL;
- error_setg(errp, "Unsupported preallocation mode: %s",
- PreallocMode_str(prealloc));
- break;
- }
+ ret = qemu_gluster_do_truncate(fd, total_size, prealloc, errp);
out:
if (fd) {
--
2.13.6
- [Qemu-block] [PULL 00/55] Block layer patches, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 01/55] iotests: Fix CID for VMDK afl image, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 03/55] qemu-img: Document --force-share / -U, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 02/55] qemu-img.texi: Clean up parameter list, Kevin Wolf, 2018/02/13
- [Qemu-block] [PULL 09/55] gluster: Move glfs_close() to create's clean-up, Kevin Wolf, 2018/02/13
- [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 <=
- [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, 2018/02/13
- [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