[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 08/93] gluster: Add support for creating zero-filled
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 08/93] gluster: Add support for creating zero-filled image |
Date: |
Fri, 24 Jan 2014 18:20:51 +0100 |
From: Bharata B Rao <address@hidden>
GlusterFS supports creation of zero-filled file on GlusterFS volume
by means of an API called glfs_zerofill(). Use this API from QEMU to
create an image that is filled with zeroes by using the preallocation
option of qemu-img.
qemu-img create gluster://server/volume/image -o preallocation=full 10G
The allowed values for preallocation are 'full' and 'off'. By default
preallocation is off and image is not zero-filled.
glfs_zerofill() offloads the writing of zeroes to the server and if
the storage supports SCSI WRITESAME, GlusterFS server can issue
BLKZEROOUT ioctl to achieve the zeroing.
Signed-off-by: Bharata B Rao <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/gluster.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/block/gluster.c b/block/gluster.c
index c11f60c..a009b15 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -354,6 +354,29 @@ out:
g_slice_free(GlusterAIOCB, acb);
return ret;
}
+
+static inline bool gluster_supports_zerofill(void)
+{
+ return 1;
+}
+
+static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset,
+ int64_t size)
+{
+ return glfs_zerofill(fd, offset, size);
+}
+
+#else
+static inline bool gluster_supports_zerofill(void)
+{
+ return 0;
+}
+
+static inline int qemu_gluster_zerofill(struct glfs_fd *fd, int64_t offset,
+ int64_t size)
+{
+ return 0;
+}
#endif
static int qemu_gluster_create(const char *filename,
@@ -362,6 +385,7 @@ static int qemu_gluster_create(const char *filename,
struct glfs *glfs;
struct glfs_fd *fd;
int ret = 0;
+ int prealloc = 0;
int64_t total_size = 0;
GlusterConf *gconf = g_malloc0(sizeof(GlusterConf));
@@ -374,6 +398,19 @@ static int qemu_gluster_create(const char *filename,
while (options && options->name) {
if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
total_size = options->value.n / BDRV_SECTOR_SIZE;
+ } else if (!strcmp(options->name, BLOCK_OPT_PREALLOC)) {
+ if (!options->value.s || !strcmp(options->value.s, "off")) {
+ prealloc = 0;
+ } else if (!strcmp(options->value.s, "full") &&
+ gluster_supports_zerofill()) {
+ prealloc = 1;
+ } else {
+ error_setg(errp, "Invalid preallocation mode: '%s'"
+ " or GlusterFS doesn't support zerofill API",
+ options->value.s);
+ ret = -EINVAL;
+ goto out;
+ }
}
options++;
}
@@ -383,9 +420,15 @@ static int qemu_gluster_create(const char *filename,
if (!fd) {
ret = -errno;
} else {
- if (glfs_ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
+ if (!glfs_ftruncate(fd, total_size * BDRV_SECTOR_SIZE)) {
+ if (prealloc && qemu_gluster_zerofill(fd, 0,
+ total_size * BDRV_SECTOR_SIZE)) {
+ ret = -errno;
+ }
+ } else {
ret = -errno;
}
+
if (glfs_close(fd) != 0) {
ret = -errno;
}
@@ -560,6 +603,11 @@ static QEMUOptionParameter qemu_gluster_create_options[] =
{
.type = OPT_SIZE,
.help = "Virtual disk size"
},
+ {
+ .name = BLOCK_OPT_PREALLOC,
+ .type = OPT_STRING,
+ .help = "Preallocation mode (allowed values: off, full)"
+ },
{ NULL }
};
--
1.8.1.4
- [Qemu-devel] [PULL v2 00/93] Block patches, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 01/93] rbd: switch from pipe to QEMUBH completion notification, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 02/93] qemu-iotests: Introduce _unsupported_imgopts, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 03/93] qemu-iotests: Add _unsupported_imgopts for vmdk subformats, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 05/93] block/iscsi: return -ENOMEM if an async call fails immediately, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 04/93] qemu-iotests: Clean up all extents for vmdk, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 08/93] gluster: Add support for creating zero-filled image,
Kevin Wolf <=
- [Qemu-devel] [PULL 06/93] gluster: Convert aio routines into coroutines, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 09/93] sheepdog: fix clone operation by 'qemu-img create -b', Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 07/93] gluster: Implement .bdrv_co_write_zeroes for gluster, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 10/93] qtest: Fix the bug about disable vnc causes "make check" fail, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 11/93] docs: qcow2 compat=1.1 is now the default, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 12/93] vmdk: Fix big flat extent IO, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 13/93] readline: decouple readline from the monitor, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 14/93] readline: move readline to a generic location, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 15/93] osdep: add qemu_set_tty_echo(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 16/93] qemu-io: use readline.c, Kevin Wolf, 2014/01/24