From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFQp1-00053Z-5G for qemu-devel@nongnu.org; Mon, 17 Feb 2014 11:13:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFQos-0002wt-UH for qemu-devel@nongnu.org; Mon, 17 Feb 2014 11:13:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13659) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFQos-0002wE-LU for qemu-devel@nongnu.org; Mon, 17 Feb 2014 11:13:22 -0500 From: Jeff Cody Date: Mon, 17 Feb 2014 11:11:11 -0500 Message-Id: <3a11a1884b2f90c0ab9138edc86bad0c283a3e4e.1392653229.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH v2 1/2] block: gluster - code movements, state storage changes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, benoit.canet@irqsave.net, stefanha@redhat.com, bharata@linux.vnet.ibm.com In preparation for supporting reopen on gluster, move flag parsing out to a function. Also, store open_flags and filename in the gluster state storage struct, and add a NULL check in the gconf cleanup. Signed-off-by: Jeff Cody --- block/gluster.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index a009b15..bcc9b89 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -45,11 +45,13 @@ typedef struct GlusterConf { static void qemu_gluster_gconf_free(GlusterConf *gconf) { - g_free(gconf->server); - g_free(gconf->volname); - g_free(gconf->image); - g_free(gconf->transport); - g_free(gconf); + if (gconf) { + g_free(gconf->server); + g_free(gconf->volname); + g_free(gconf->image); + g_free(gconf->transport); + g_free(gconf); + } } static int parse_volume_options(GlusterConf *gconf, char *path) @@ -269,11 +271,28 @@ static QemuOptsList runtime_opts = { }, }; +static void qemu_gluster_parse_flags(int bdrv_flags, int *open_flags) +{ + assert(open_flags != NULL); + + *open_flags |= O_BINARY; + + if (bdrv_flags & BDRV_O_RDWR) { + *open_flags |= O_RDWR; + } else { + *open_flags |= O_RDONLY; + } + + if ((bdrv_flags & BDRV_O_NOCACHE)) { + *open_flags |= O_DIRECT; + } +} + static int qemu_gluster_open(BlockDriverState *bs, QDict *options, int bdrv_flags, Error **errp) { BDRVGlusterState *s = bs->opaque; - int open_flags = O_BINARY; + int open_flags = 0; int ret = 0; GlusterConf *gconf = g_malloc0(sizeof(GlusterConf)); QemuOpts *opts; @@ -297,15 +316,7 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options, goto out; } - if (bdrv_flags & BDRV_O_RDWR) { - open_flags |= O_RDWR; - } else { - open_flags |= O_RDONLY; - } - - if ((bdrv_flags & BDRV_O_NOCACHE)) { - open_flags |= O_DIRECT; - } + qemu_gluster_parse_flags(bdrv_flags, &open_flags); s->fd = glfs_open(s->glfs, gconf->image, open_flags); if (!s->fd) { -- 1.8.3.1