|
|
9ae3a8 |
From b24bec7c4477946f17bf4628608b60d4960b4247 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Date: Thu, 6 Mar 2014 21:13:15 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 05/16] block: gluster - add reopen support.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Message-id: <2f1e357ca27ef45d16e62fbe44b0ce9cef2602fe.1394129674.git.jcody@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 58041
|
|
|
9ae3a8 |
O-Subject: [RHEL7 qemu-kvm PATCH 2/2] block: gluster - add reopen support.
|
|
|
9ae3a8 |
Bugzilla: 1031526
|
|
|
9ae3a8 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Gluster does parse open flags in its .bdrv_open() implementation,
|
|
|
9ae3a8 |
and the .bdrv_reopen_* implementations need to do the same.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
A new gluster connection to the image file to be created is established
|
|
|
9ae3a8 |
in the .bdrv_reopen_prepare(), and the image file opened with the new
|
|
|
9ae3a8 |
flags.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
If this is successful, then the old image file is closed, and the
|
|
|
9ae3a8 |
old connection torn down. The relevant structure pointers in the gluster
|
|
|
9ae3a8 |
state structure are updated to the new connection.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
If it is not successful, then the new file handle and connection is
|
|
|
9ae3a8 |
abandoned (if it exists), while the old connection is not modified at
|
|
|
9ae3a8 |
all.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
With reopen supported, block-commit (and offline commit) is now also
|
|
|
9ae3a8 |
supported for image files whose base image uses the native gluster
|
|
|
9ae3a8 |
protocol driver.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Jeff Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit adccfbcd6020e928db93b2b4faf0dbd05ffbe016)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
block/gluster.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RHEL7 Note: Conflict was in contextual information, as RHEL7 does not
|
|
|
9ae3a8 |
have gluster zerofill support.
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/gluster.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
1 file changed, 102 insertions(+)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/gluster.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9ae3a8 |
1 files changed, 102 insertions(+), 0 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/gluster.c b/block/gluster.c
|
|
|
9ae3a8 |
index 95cb05a..f43d3a6 100644
|
|
|
9ae3a8 |
--- a/block/gluster.c
|
|
|
9ae3a8 |
+++ b/block/gluster.c
|
|
|
9ae3a8 |
@@ -376,6 +376,96 @@ out:
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+typedef struct BDRVGlusterReopenState {
|
|
|
9ae3a8 |
+ struct glfs *glfs;
|
|
|
9ae3a8 |
+ struct glfs_fd *fd;
|
|
|
9ae3a8 |
+} BDRVGlusterReopenState;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static int qemu_gluster_reopen_prepare(BDRVReopenState *state,
|
|
|
9ae3a8 |
+ BlockReopenQueue *queue, Error **errp)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ int ret = 0;
|
|
|
9ae3a8 |
+ BDRVGlusterReopenState *reop_s;
|
|
|
9ae3a8 |
+ GlusterConf *gconf = NULL;
|
|
|
9ae3a8 |
+ int open_flags = 0;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ assert(state != NULL);
|
|
|
9ae3a8 |
+ assert(state->bs != NULL);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ state->opaque = g_malloc0(sizeof(BDRVGlusterReopenState));
|
|
|
9ae3a8 |
+ reop_s = state->opaque;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ qemu_gluster_parse_flags(state->flags, &open_flags);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ gconf = g_malloc0(sizeof(GlusterConf));
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ reop_s->glfs = qemu_gluster_init(gconf, state->bs->filename);
|
|
|
9ae3a8 |
+ if (reop_s->glfs == NULL) {
|
|
|
9ae3a8 |
+ ret = -errno;
|
|
|
9ae3a8 |
+ goto exit;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ reop_s->fd = glfs_open(reop_s->glfs, gconf->image, open_flags);
|
|
|
9ae3a8 |
+ if (reop_s->fd == NULL) {
|
|
|
9ae3a8 |
+ /* reops->glfs will be cleaned up in _abort */
|
|
|
9ae3a8 |
+ ret = -errno;
|
|
|
9ae3a8 |
+ goto exit;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+exit:
|
|
|
9ae3a8 |
+ /* state->opaque will be freed in either the _abort or _commit */
|
|
|
9ae3a8 |
+ qemu_gluster_gconf_free(gconf);
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void qemu_gluster_reopen_commit(BDRVReopenState *state)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BDRVGlusterReopenState *reop_s = state->opaque;
|
|
|
9ae3a8 |
+ BDRVGlusterState *s = state->bs->opaque;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* close the old */
|
|
|
9ae3a8 |
+ if (s->fd) {
|
|
|
9ae3a8 |
+ glfs_close(s->fd);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ if (s->glfs) {
|
|
|
9ae3a8 |
+ glfs_fini(s->glfs);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* use the newly opened image / connection */
|
|
|
9ae3a8 |
+ s->fd = reop_s->fd;
|
|
|
9ae3a8 |
+ s->glfs = reop_s->glfs;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ g_free(state->opaque);
|
|
|
9ae3a8 |
+ state->opaque = NULL;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void qemu_gluster_reopen_abort(BDRVReopenState *state)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ BDRVGlusterReopenState *reop_s = state->opaque;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (reop_s == NULL) {
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (reop_s->fd) {
|
|
|
9ae3a8 |
+ glfs_close(reop_s->fd);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (reop_s->glfs) {
|
|
|
9ae3a8 |
+ glfs_fini(reop_s->glfs);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ g_free(state->opaque);
|
|
|
9ae3a8 |
+ state->opaque = NULL;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
static int qemu_gluster_create(const char *filename,
|
|
|
9ae3a8 |
QEMUOptionParameter *options, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
@@ -605,6 +695,9 @@ static BlockDriver bdrv_gluster = {
|
|
|
9ae3a8 |
.protocol_name = "gluster",
|
|
|
9ae3a8 |
.instance_size = sizeof(BDRVGlusterState),
|
|
|
9ae3a8 |
.bdrv_file_open = qemu_gluster_open,
|
|
|
9ae3a8 |
+ .bdrv_reopen_prepare = qemu_gluster_reopen_prepare,
|
|
|
9ae3a8 |
+ .bdrv_reopen_commit = qemu_gluster_reopen_commit,
|
|
|
9ae3a8 |
+ .bdrv_reopen_abort = qemu_gluster_reopen_abort,
|
|
|
9ae3a8 |
.bdrv_close = qemu_gluster_close,
|
|
|
9ae3a8 |
.bdrv_create = qemu_gluster_create,
|
|
|
9ae3a8 |
.bdrv_getlength = qemu_gluster_getlength,
|
|
|
9ae3a8 |
@@ -622,6 +715,9 @@ static BlockDriver bdrv_gluster_tcp = {
|
|
|
9ae3a8 |
.protocol_name = "gluster+tcp",
|
|
|
9ae3a8 |
.instance_size = sizeof(BDRVGlusterState),
|
|
|
9ae3a8 |
.bdrv_file_open = qemu_gluster_open,
|
|
|
9ae3a8 |
+ .bdrv_reopen_prepare = qemu_gluster_reopen_prepare,
|
|
|
9ae3a8 |
+ .bdrv_reopen_commit = qemu_gluster_reopen_commit,
|
|
|
9ae3a8 |
+ .bdrv_reopen_abort = qemu_gluster_reopen_abort,
|
|
|
9ae3a8 |
.bdrv_close = qemu_gluster_close,
|
|
|
9ae3a8 |
.bdrv_create = qemu_gluster_create,
|
|
|
9ae3a8 |
.bdrv_getlength = qemu_gluster_getlength,
|
|
|
9ae3a8 |
@@ -639,6 +735,9 @@ static BlockDriver bdrv_gluster_unix = {
|
|
|
9ae3a8 |
.protocol_name = "gluster+unix",
|
|
|
9ae3a8 |
.instance_size = sizeof(BDRVGlusterState),
|
|
|
9ae3a8 |
.bdrv_file_open = qemu_gluster_open,
|
|
|
9ae3a8 |
+ .bdrv_reopen_prepare = qemu_gluster_reopen_prepare,
|
|
|
9ae3a8 |
+ .bdrv_reopen_commit = qemu_gluster_reopen_commit,
|
|
|
9ae3a8 |
+ .bdrv_reopen_abort = qemu_gluster_reopen_abort,
|
|
|
9ae3a8 |
.bdrv_close = qemu_gluster_close,
|
|
|
9ae3a8 |
.bdrv_create = qemu_gluster_create,
|
|
|
9ae3a8 |
.bdrv_getlength = qemu_gluster_getlength,
|
|
|
9ae3a8 |
@@ -656,6 +755,9 @@ static BlockDriver bdrv_gluster_rdma = {
|
|
|
9ae3a8 |
.protocol_name = "gluster+rdma",
|
|
|
9ae3a8 |
.instance_size = sizeof(BDRVGlusterState),
|
|
|
9ae3a8 |
.bdrv_file_open = qemu_gluster_open,
|
|
|
9ae3a8 |
+ .bdrv_reopen_prepare = qemu_gluster_reopen_prepare,
|
|
|
9ae3a8 |
+ .bdrv_reopen_commit = qemu_gluster_reopen_commit,
|
|
|
9ae3a8 |
+ .bdrv_reopen_abort = qemu_gluster_reopen_abort,
|
|
|
9ae3a8 |
.bdrv_close = qemu_gluster_close,
|
|
|
9ae3a8 |
.bdrv_create = qemu_gluster_create,
|
|
|
9ae3a8 |
.bdrv_getlength = qemu_gluster_getlength,
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|