* [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog
@ 2018-02-13 13:03 Max Reitz
2018-02-13 13:03 ` [Qemu-devel] [PATCH 1/7] gluster: Move glfs_close() to create's clean-up Max Reitz
` (7 more replies)
0 siblings, 8 replies; 16+ messages in thread
From: Max Reitz @ 2018-02-13 13:03 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Max Reitz, sheepdog, Kevin Wolf, Jeff Cody,
Hitoshi Mitake, Liu Yuan
As far as I can see, these are the only protocols beside file-posix that
support preallocated creation. In contrast to file-posix, however, they
have not supported preallocated truncation so far. This series brings
their truncation code to feature parity with their creation code in this
regard.
Note that I do not have a test setup for either of the two drivers, so I
do not actually know whether this works. Anyone with a setup is more
than welcome to test this series.
Max Reitz (7):
gluster: Move glfs_close() to create's clean-up
gluster: Pull truncation from qemu_gluster_create
gluster: Query current size in do_truncate()
gluster: Add preallocated truncation
sheepdog: Make sd_prealloc() take a BDS
sheepdog: Pass old and new size to sd_prealloc()
sheepdog: Allow fully preallocated truncation
block/gluster.c | 116 ++++++++++++++++++++++++++++++-------------------------
block/sheepdog.c | 56 +++++++++++++++++----------
2 files changed, 99 insertions(+), 73 deletions(-)
--
2.14.3
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Qemu-devel] [PATCH 1/7] gluster: Move glfs_close() to create's clean-up
2018-02-13 13:03 [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Max Reitz
@ 2018-02-13 13:03 ` Max Reitz
2018-02-13 14:54 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 2/7] gluster: Pull truncation from qemu_gluster_create Max Reitz
` (6 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Max Reitz @ 2018-02-13 13:03 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Max Reitz, sheepdog, Kevin Wolf, Jeff Cody,
Hitoshi Mitake, Liu Yuan
glfs_close() is a classical clean-up operation, as can be seen by the
fact that it is executed even if the truncation before it failed.
Also, moving it to clean-up makes it more clear that if it fails, we do
not want it to overwrite the current ret value if that signifies an
error already.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/gluster.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/block/gluster.c b/block/gluster.c
index d8decc41ad..7fab2dfa12 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -970,7 +970,7 @@ static int qemu_gluster_create(const char *filename,
{
BlockdevOptionsGluster *gconf;
struct glfs *glfs;
- struct glfs_fd *fd;
+ struct glfs_fd *fd = NULL;
int ret = 0;
PreallocMode prealloc;
int64_t total_size = 0;
@@ -1054,10 +1054,12 @@ static int qemu_gluster_create(const char *filename,
break;
}
- if (glfs_close(fd) != 0) {
- ret = -errno;
- }
out:
+ if (fd) {
+ if (glfs_close(fd) != 0 && ret == 0) {
+ ret = -errno;
+ }
+ }
qapi_free_BlockdevOptionsGluster(gconf);
glfs_clear_preopened(glfs);
return ret;
--
2.14.3
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [Qemu-devel] [PATCH 2/7] gluster: Pull truncation from qemu_gluster_create
2018-02-13 13:03 [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Max Reitz
2018-02-13 13:03 ` [Qemu-devel] [PATCH 1/7] gluster: Move glfs_close() to create's clean-up Max Reitz
@ 2018-02-13 13:03 ` Max Reitz
2018-02-13 14:56 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 3/7] gluster: Query current size in do_truncate() Max Reitz
` (5 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Max Reitz @ 2018-02-13 13:03 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Max Reitz, sheepdog, Kevin Wolf, Jeff Cody,
Hitoshi Mitake, Liu Yuan
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 <mreitz@redhat.com>
---
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.14.3
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [Qemu-devel] [PATCH 3/7] gluster: Query current size in do_truncate()
2018-02-13 13:03 [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Max Reitz
2018-02-13 13:03 ` [Qemu-devel] [PATCH 1/7] gluster: Move glfs_close() to create's clean-up Max Reitz
2018-02-13 13:03 ` [Qemu-devel] [PATCH 2/7] gluster: Pull truncation from qemu_gluster_create Max Reitz
@ 2018-02-13 13:03 ` Max Reitz
2018-02-13 14:57 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 4/7] gluster: Add preallocated truncation Max Reitz
` (4 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Max Reitz @ 2018-02-13 13:03 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Max Reitz, sheepdog, Kevin Wolf, Jeff Cody,
Hitoshi Mitake, Liu Yuan
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 <mreitz@redhat.com>
---
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
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [Qemu-devel] [PATCH 4/7] gluster: Add preallocated truncation
2018-02-13 13:03 [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Max Reitz
` (2 preceding siblings ...)
2018-02-13 13:03 ` [Qemu-devel] [PATCH 3/7] gluster: Query current size in do_truncate() Max Reitz
@ 2018-02-13 13:03 ` Max Reitz
2018-02-13 14:58 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 5/7] sheepdog: Make sd_prealloc() take a BDS Max Reitz
` (3 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Max Reitz @ 2018-02-13 13:03 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Max Reitz, sheepdog, Kevin Wolf, Jeff Cody,
Hitoshi Mitake, Liu Yuan
By using qemu_do_cluster_truncate() in qemu_cluster_truncate(), we now
automatically have preallocated truncation.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/gluster.c | 17 +----------------
1 file changed, 1 insertion(+), 16 deletions(-)
diff --git a/block/gluster.c b/block/gluster.c
index 806b894bc8..3f17b7819d 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -1122,23 +1122,8 @@ static coroutine_fn int qemu_gluster_co_rw(BlockDriverState *bs,
static int qemu_gluster_truncate(BlockDriverState *bs, int64_t offset,
PreallocMode prealloc, Error **errp)
{
- int ret;
BDRVGlusterState *s = bs->opaque;
-
- if (prealloc != PREALLOC_MODE_OFF) {
- error_setg(errp, "Unsupported preallocation mode '%s'",
- PreallocMode_str(prealloc));
- return -ENOTSUP;
- }
-
- ret = glfs_ftruncate(s->fd, offset);
- if (ret < 0) {
- ret = -errno;
- error_setg_errno(errp, -ret, "Failed to truncate file");
- return ret;
- }
-
- return 0;
+ return qemu_gluster_do_truncate(s->fd, offset, prealloc, errp);
}
static coroutine_fn int qemu_gluster_co_readv(BlockDriverState *bs,
--
2.14.3
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [Qemu-devel] [PATCH 5/7] sheepdog: Make sd_prealloc() take a BDS
2018-02-13 13:03 [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Max Reitz
` (3 preceding siblings ...)
2018-02-13 13:03 ` [Qemu-devel] [PATCH 4/7] gluster: Add preallocated truncation Max Reitz
@ 2018-02-13 13:03 ` Max Reitz
2018-02-13 15:02 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 6/7] sheepdog: Pass old and new size to sd_prealloc() Max Reitz
` (2 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Max Reitz @ 2018-02-13 13:03 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Max Reitz, sheepdog, Kevin Wolf, Jeff Cody,
Hitoshi Mitake, Liu Yuan
We want to use this function in sd_truncate() later on, so taking a
filename is not exactly ideal.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/sheepdog.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index af125a2c8d..cc1d37b3da 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -1826,10 +1826,10 @@ static int do_sd_create(BDRVSheepdogState *s, uint32_t *vdi_id, int snapshot,
return 0;
}
-static int sd_prealloc(const char *filename, Error **errp)
+static int sd_prealloc(BlockDriverState *bs, Error **errp)
{
BlockBackend *blk = NULL;
- BDRVSheepdogState *base = NULL;
+ BDRVSheepdogState *base = bs->opaque;
unsigned long buf_size;
uint32_t idx, max_idx;
uint32_t object_size;
@@ -1837,10 +1837,11 @@ static int sd_prealloc(const char *filename, Error **errp)
void *buf = NULL;
int ret;
- blk = blk_new_open(filename, NULL, NULL,
- BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, errp);
- if (blk == NULL) {
- ret = -EIO;
+ blk = blk_new(BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | BLK_PERM_RESIZE,
+ BLK_PERM_ALL);
+
+ ret = blk_insert_bs(blk, bs, errp);
+ if (ret < 0) {
goto out_with_err_set;
}
@@ -1852,7 +1853,6 @@ static int sd_prealloc(const char *filename, Error **errp)
goto out;
}
- base = blk_bs(blk)->opaque;
object_size = (UINT32_C(1) << base->inode.block_size_shift);
buf_size = MIN(object_size, SD_DATA_OBJ_SIZE);
buf = g_malloc0(buf_size);
@@ -2108,7 +2108,20 @@ static int sd_create(const char *filename, QemuOpts *opts,
}
if (prealloc) {
- ret = sd_prealloc(filename, errp);
+ BlockDriverState *bs;
+ QDict *opts;
+
+ opts = qdict_new();
+ qdict_put_str(opts, "driver", "sheepdog");
+ bs = bdrv_open(filename, NULL, opts, BDRV_O_PROTOCOL | BDRV_O_RDWR,
+ errp);
+ if (!bs) {
+ goto out;
+ }
+
+ ret = sd_prealloc(bs, errp);
+
+ bdrv_unref(bs);
}
out:
g_free(backing_file);
--
2.14.3
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [Qemu-devel] [PATCH 6/7] sheepdog: Pass old and new size to sd_prealloc()
2018-02-13 13:03 [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Max Reitz
` (4 preceding siblings ...)
2018-02-13 13:03 ` [Qemu-devel] [PATCH 5/7] sheepdog: Make sd_prealloc() take a BDS Max Reitz
@ 2018-02-13 13:03 ` Max Reitz
2018-02-13 15:04 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 7/7] sheepdog: Allow fully preallocated truncation Max Reitz
2018-02-13 15:19 ` [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Kevin Wolf
7 siblings, 1 reply; 16+ messages in thread
From: Max Reitz @ 2018-02-13 13:03 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Max Reitz, sheepdog, Kevin Wolf, Jeff Cody,
Hitoshi Mitake, Liu Yuan
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 <mreitz@redhat.com>
---
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.14.3
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [Qemu-devel] [PATCH 7/7] sheepdog: Allow fully preallocated truncation
2018-02-13 13:03 [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Max Reitz
` (5 preceding siblings ...)
2018-02-13 13:03 ` [Qemu-devel] [PATCH 6/7] sheepdog: Pass old and new size to sd_prealloc() Max Reitz
@ 2018-02-13 13:03 ` Max Reitz
2018-02-13 15:05 ` Eric Blake
2018-02-13 15:19 ` [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Kevin Wolf
7 siblings, 1 reply; 16+ messages in thread
From: Max Reitz @ 2018-02-13 13:03 UTC (permalink / raw)
To: qemu-block
Cc: qemu-devel, Max Reitz, sheepdog, Kevin Wolf, Jeff Cody,
Hitoshi Mitake, Liu Yuan
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/sheepdog.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index d300fb69c0..ac02b10fe0 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;
}
/*
--
2.14.3
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [PATCH 1/7] gluster: Move glfs_close() to create's clean-up
2018-02-13 13:03 ` [Qemu-devel] [PATCH 1/7] gluster: Move glfs_close() to create's clean-up Max Reitz
@ 2018-02-13 14:54 ` Eric Blake
0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2018-02-13 14:54 UTC (permalink / raw)
To: Max Reitz, qemu-block
Cc: Kevin Wolf, sheepdog, Hitoshi Mitake, Jeff Cody, qemu-devel,
Liu Yuan
On 02/13/2018 07:03 AM, Max Reitz wrote:
> glfs_close() is a classical clean-up operation, as can be seen by the
> fact that it is executed even if the truncation before it failed.
> Also, moving it to clean-up makes it more clear that if it fails, we do
> not want it to overwrite the current ret value if that signifies an
> error already.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/gluster.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [PATCH 2/7] gluster: Pull truncation from qemu_gluster_create
2018-02-13 13:03 ` [Qemu-devel] [PATCH 2/7] gluster: Pull truncation from qemu_gluster_create Max Reitz
@ 2018-02-13 14:56 ` Eric Blake
0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2018-02-13 14:56 UTC (permalink / raw)
To: Max Reitz, qemu-block
Cc: Kevin Wolf, sheepdog, Hitoshi Mitake, Jeff Cody, qemu-devel,
Liu Yuan
On 02/13/2018 07:03 AM, Max Reitz wrote:
> 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 <mreitz@redhat.com>
> ---
> block/gluster.c | 74 +++++++++++++++++++++++++++++++--------------------------
> 1 file changed, 40 insertions(+), 34 deletions(-)
>
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [PATCH 3/7] gluster: Query current size in do_truncate()
2018-02-13 13:03 ` [Qemu-devel] [PATCH 3/7] gluster: Query current size in do_truncate() Max Reitz
@ 2018-02-13 14:57 ` Eric Blake
0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2018-02-13 14:57 UTC (permalink / raw)
To: Max Reitz, qemu-block
Cc: Kevin Wolf, sheepdog, Hitoshi Mitake, Jeff Cody, qemu-devel,
Liu Yuan
On 02/13/2018 07:03 AM, Max Reitz wrote:
> 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 <mreitz@redhat.com>
> ---
> block/gluster.c | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
I don't have a gluster setup handy to test this, but the concept matches
file-posix and the change looks reasonable.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [PATCH 4/7] gluster: Add preallocated truncation
2018-02-13 13:03 ` [Qemu-devel] [PATCH 4/7] gluster: Add preallocated truncation Max Reitz
@ 2018-02-13 14:58 ` Eric Blake
0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2018-02-13 14:58 UTC (permalink / raw)
To: Max Reitz, qemu-block
Cc: Kevin Wolf, sheepdog, Hitoshi Mitake, Jeff Cody, qemu-devel,
Liu Yuan
On 02/13/2018 07:03 AM, Max Reitz wrote:
> By using qemu_do_cluster_truncate() in qemu_cluster_truncate(), we now
> automatically have preallocated truncation.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/gluster.c | 17 +----------------
> 1 file changed, 1 insertion(+), 16 deletions(-)
>
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [PATCH 5/7] sheepdog: Make sd_prealloc() take a BDS
2018-02-13 13:03 ` [Qemu-devel] [PATCH 5/7] sheepdog: Make sd_prealloc() take a BDS Max Reitz
@ 2018-02-13 15:02 ` Eric Blake
0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2018-02-13 15:02 UTC (permalink / raw)
To: Max Reitz, qemu-block
Cc: Kevin Wolf, sheepdog, Hitoshi Mitake, Jeff Cody, qemu-devel,
Liu Yuan
On 02/13/2018 07:03 AM, Max Reitz wrote:
> We want to use this function in sd_truncate() later on, so taking a
> filename is not exactly ideal.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/sheepdog.c | 29 +++++++++++++++++++++--------
> 1 file changed, 21 insertions(+), 8 deletions(-)
>
> @@ -1837,10 +1837,11 @@ static int sd_prealloc(const char *filename, Error **errp)
> void *buf = NULL;
> int ret;
>
> - blk = blk_new_open(filename, NULL, NULL,
> - BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, errp);
> - if (blk == NULL) {
> - ret = -EIO;
> + blk = blk_new(BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE | BLK_PERM_RESIZE,
> + BLK_PERM_ALL);
> +
> + ret = blk_insert_bs(blk, bs, errp);
> + if (ret < 0) {
> if (prealloc) {
> - ret = sd_prealloc(filename, errp);
> + BlockDriverState *bs;
> + QDict *opts;
> +
> + opts = qdict_new();
> + qdict_put_str(opts, "driver", "sheepdog");
> + bs = bdrv_open(filename, NULL, opts, BDRV_O_PROTOCOL | BDRV_O_RDWR,
> + errp);
I'm a bit weak on ensuring the same ending flags result after the new
bdrv_open()/blk_new() as what you used to get on blk_new_open(), so
someone that can actually test this is appreciated.
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [PATCH 6/7] sheepdog: Pass old and new size to sd_prealloc()
2018-02-13 13:03 ` [Qemu-devel] [PATCH 6/7] sheepdog: Pass old and new size to sd_prealloc() Max Reitz
@ 2018-02-13 15:04 ` Eric Blake
0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2018-02-13 15:04 UTC (permalink / raw)
To: Max Reitz, qemu-block
Cc: Kevin Wolf, sheepdog, Hitoshi Mitake, Jeff Cody, qemu-devel,
Liu Yuan
On 02/13/2018 07:03 AM, Max Reitz wrote:
> 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 <mreitz@redhat.com>
> ---
> block/sheepdog.c | 16 +++++-----------
> 1 file changed, 5 insertions(+), 11 deletions(-)
>
> @@ -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;
> - }
> -
> @@ -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);
Nice - you also got rid of a potential failure in blk_getlength().
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [PATCH 7/7] sheepdog: Allow fully preallocated truncation
2018-02-13 13:03 ` [Qemu-devel] [PATCH 7/7] sheepdog: Allow fully preallocated truncation Max Reitz
@ 2018-02-13 15:05 ` Eric Blake
0 siblings, 0 replies; 16+ messages in thread
From: Eric Blake @ 2018-02-13 15:05 UTC (permalink / raw)
To: Max Reitz, qemu-block
Cc: Kevin Wolf, sheepdog, Hitoshi Mitake, Jeff Cody, qemu-devel,
Liu Yuan
On 02/13/2018 07:03 AM, Max Reitz wrote:
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/sheepdog.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog
2018-02-13 13:03 [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Max Reitz
` (6 preceding siblings ...)
2018-02-13 13:03 ` [Qemu-devel] [PATCH 7/7] sheepdog: Allow fully preallocated truncation Max Reitz
@ 2018-02-13 15:19 ` Kevin Wolf
7 siblings, 0 replies; 16+ messages in thread
From: Kevin Wolf @ 2018-02-13 15:19 UTC (permalink / raw)
To: Max Reitz
Cc: qemu-block, qemu-devel, sheepdog, Jeff Cody, Hitoshi Mitake,
Liu Yuan
Am 13.02.2018 um 14:03 hat Max Reitz geschrieben:
> As far as I can see, these are the only protocols beside file-posix that
> support preallocated creation. In contrast to file-posix, however, they
> have not supported preallocated truncation so far. This series brings
> their truncation code to feature parity with their creation code in this
> regard.
>
> Note that I do not have a test setup for either of the two drivers, so I
> do not actually know whether this works. Anyone with a setup is more
> than welcome to test this series.
Thanks, applied to the block branch.
We'll see if someone screams once this hits master.
Kevin
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2018-02-13 15:19 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-13 13:03 [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Max Reitz
2018-02-13 13:03 ` [Qemu-devel] [PATCH 1/7] gluster: Move glfs_close() to create's clean-up Max Reitz
2018-02-13 14:54 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 2/7] gluster: Pull truncation from qemu_gluster_create Max Reitz
2018-02-13 14:56 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 3/7] gluster: Query current size in do_truncate() Max Reitz
2018-02-13 14:57 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 4/7] gluster: Add preallocated truncation Max Reitz
2018-02-13 14:58 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 5/7] sheepdog: Make sd_prealloc() take a BDS Max Reitz
2018-02-13 15:02 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 6/7] sheepdog: Pass old and new size to sd_prealloc() Max Reitz
2018-02-13 15:04 ` Eric Blake
2018-02-13 13:03 ` [Qemu-devel] [PATCH 7/7] sheepdog: Allow fully preallocated truncation Max Reitz
2018-02-13 15:05 ` Eric Blake
2018-02-13 15:19 ` [Qemu-devel] [PATCH 0/7] block: Preallocated truncation for gluster and sheepdog Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).