Skip to contentSkip to conversation

GlusterFS support in QEMU

RFC PATCH In review Bharata B Rao 4 participants 17 messages Jun 11, 2012 – Jul 6, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover GlusterFS support in QEMU

Hi,

This set of patches enables QEMU to boot VM images from gluster volumes. This is achieved by adding gluster as a new block backend driver in QEMU. Its already possible to boot from VM images on gluster volumes using Fuse mount, but this patchset provides the ability to boot VM images from gluster volumes by by-passing the FUSE layer in gluster. In case the image is present on the local system, it is possible to even bypass client and server translator and hence the RPC overhead.

QEMU with gluster backend support will take the volume file on command line and then link to libglusterfs library to perform IO to image on gluster volume. block/gluster-helpers.c has bare minimum gluster code that is necessary for QEMU to boot and work with image on gluster volume. I have implemented routines like gluster_create, gluster_open, gluster_aio_readv etc which will eventually not be necessary when we have equivalent routines in libglusterfsclient working. While I have this implementation here, we are also working actively on resurrecting libglusterfsclient and using QEMU with it. In addition to posix routines, block/gluster-helpers.c has some elaborate lookup code which also will become redundant with libglusterfsclient.

The patches are experimental in nature and I have only verified that I can boot an image from gluster volume using these patches in fuse-bypass and rpc-bypass modes. I haven't tested with full-blown version of volume file (that is generated by gluster CLI), but have always use only hand crafted volume files with just posix translator in it.

How to use this patchset
========================
1. Compiling GlusterFS

- Get GlusterFS source from git://git.gluster.com/glusterfs.git
- Compile and install
# ./autogen.sh; ./configure; make; make install
- Copy a few required header files and libraries

  # mkdir /usr/local/include/glusterfs/
  # cp glusterfs/libglusterfs/src/*.h /usr/local/include/glusterfs/
  # cp glusterfs/config.h /usr/local/include/glusterfs/
  # cp glusterfs/contrib/uuid/uuid.h /usr/local/include/glusterfs/

2. Compiling QEMU

- Get QEMU sources
- Apply the patches from this patchset.
- Configure

  # ./configure --disable-werror --target-list=x86_64-softmmu --enable-glusterfs --enable-uuid
- make; make install

Note: I have to resort to --disable-werror to mainly tide over the warnings in block/gluster-helpers.c. I didn't spent too much effort in cleaning this up since this code will be gone once we have a working libglusterfsclient.

3. Starting GlusterFS server

# glusterfsd -f s-qemu.vol
# cat s-qemu.vol
volume vm
  type storage/posix
  option directory /vm
end-volume

volume server
type protocol/server
subvolumes vm
option transport-type tcp
option auth.addr.vm.allow *
end-volume

Here /vm is the directory exported by the server. Ensure that this directory is present before GlusterFS server is started.

4. Creating VM image

# qemu-img create -f gluster gluster:c-qemu.vol:/F16 5G
# cat c-qemu.vol
volume client
  type protocol/client
  option transport-type tcp
  option remote-host bharata
  option remote-subvolume vm
end-volume

5. Install a distro (say Fedora16) on the VM image

# qemu-system-x86_64 --enable-kvm -smp 4 -m 1024 -drive file=gluster:c-qemu.vol:/F16,format=gluster -cdrom Fedora-16-x86_64-DVD.iso

After this follow the normal F16 installation.

Next time onwards, the following QEMU command can be used to directly start the VM.

6. Start the VM (Fuse-bypass)

# qemu-system-x86_64 --enable-kvm --nographic -smp 4 -m 1024 -drive file=gluster:c-qemu.vol:/F16,format=gluster

6a. Booting VM in RPC-bypass mode.

# cat c-qemu-rpcbypass.vol 
volume vm
  type storage/posix
  option directory /vm
end-volume
# qemu-system-x86_64 --enable-kvm --nographic -smp 4 -m 1024 -drive file=gluster:c-qemu-rpcbypass.vol:/F16,format=gluster

Note that in this case, its not necessary to run a gluster server.

Tests
=====
I have done some initial tests using fio. Here are the details:

Environment
-----------
Dual core x86_64 laptop
QEMU (f8687bab919672ccd)
GlusterFS (c40b73fc453caf12)
Guest: Fedora 16 (kernel 3.1.0-7.fc16.x86_64)
Host: Fedora 16 (kernel 3.4)
fio-HEAD-47ea504

fio jobfile
-----------

# cat aio-read-direct-seq 
; Read 4 files with aio at different depths
[global]
ioengine=libaio
direct=1
rw=read
bs=128k
size=512m
directory=/data1

[file1]
iodepth=4

[file2]
iodepth=32

[file3]
iodepth=8

[file4]
iodepth=16

Base
----
QEMU: qemu-system-x86_64 --enable-kvm --nographic -m 1024 -smp 4 -drive file=/vm/dir1/F16,cache=none

Fuse mount
----------
Server: glusterfsd -f s-qemu.vol
Client: glusterfs -f c-qemu.vol /mnt
QEMU: qemu-system-x86_64 --enable-kvm --nographic -m 1024 -smp 4 -drive file=/mnt/dir1/F16,cache=none

Fuse bypass
-----------
Server: glusterfsd -f s-qemu.vol
QEMU: qemu-system-x86_64 --enable-kvm --nographic -m 1024 -smp 4 -drive file=gluster:/c-qemu.vol:/dir1/F16,format=gluster,cache=none

RPC bypass
----------
QEMU: qemu-system-x86_64 --enable-kvm --nographic -m 1024 -smp 4 -drive file=gluster:/c-qemu-rpcbypass.vol:/dir1/F16,format=gluster,cache=none

Numbers (aggrb, minb and maxb in kB/s. mint and maxt in msec)
-------
aggrb minb maxb mint maxt
Base 72916 18229 18945 27673 28761
Fuse mount 8211 2052 3094 169433 255396
Fuse bypass 66591 16647 17806 29444 31493
RPC bypass 70940 17735 18782 27914 29562

Note that these are just indicative numbers and I haven't really tuned QEMU or GlusterFS or fio to achieve best results. However with this test we can see that Fuse mount case is not ideal and Fuse bypass and RPC bypass help.

Regards,
Bharata.

#1 lore raw

RFC PATCH 1/3 qemu: Add a config option for GlusterFS as block backend

qemu: Add a config option for GlusterFS as block backend

From: Bharata B Rao <[email protected]>

---

 configure |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
configure +36 -0
index b55a792..dc89592 100755
@@ -824,6 +824,10 @@ for opt do
   ;;
   --disable-guest-agent) guest_agent="no"
   ;;
+  --disable-glusterfs) glusterfs="no"
+  ;;
+  --enable-glusterfs) glusterfs="yes"
+  ;;
   *) echo "ERROR: unknown option $opt"; show_help="yes"
   ;;
   esac
@@ -1110,6 +1114,8 @@ echo "  --disable-guest-agent    disable building of the QEMU Guest Agent"
 echo "  --enable-guest-agent     enable building of the QEMU Guest Agent"
 echo "  --with-coroutine=BACKEND coroutine backend. Supported options:"
 echo "                           gthread, ucontext, sigaltstack, windows"
+echo "  --enable-glusterfs       enable GlusterFS backend"
+echo "  --disable-glusterfs      disable GlusterFS backend"
 echo ""
 echo "NOTE: The object files are built at the place where configure is launched"
 exit 1
@@ -2240,6 +2246,31 @@ EOF
   fi
 fi
 
+##########################################
+# glusterfs probe
+if test "$glusterfs" != "no" ; then
+  cat > $TMPC <<EOF
+#include <stdio.h>
+#include <glusterfs/xlator.h>
+int main(void) {
+    xlator_t xlator;
+    xlator_init(&xlator);
+    return 0;
+}
+EOF
+  glusterfs_libs="-lglusterfs"
+  if compile_prog "" "$glusterfs_libs" ; then
+    glusterfs=yes
+    libs_tools="$glusterfs_libs $libs_tools"
+    libs_softmmu="$glusterfs_libs $libs_softmmu"
+  else
+    if test "$glusterfs" = "yes" ; then
+      feature_not_found "GlusterFS backend support"
+    fi
+    glusterfs=no
+  fi
+fi
+
 #
 # Check for xxxat() functions when we are building linux-user
 # emulator.  This is done because older glibc versions don't
@@ -3014,6 +3045,7 @@ echo "OpenGL support    $opengl"
 echo "libiscsi support  $libiscsi"
 echo "build guest agent $guest_agent"
 echo "coroutine backend $coroutine_backend"
+echo "GlusterFS support $glusterfs"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -3342,6 +3374,10 @@ if test "$linux_magic_h" = "yes" ; then
   echo "CONFIG_LINUX_MAGIC_H=y" >> $config_host_mak
 fi
 
+if test "$glusterfs" = "yes" ; then
+  echo "CONFIG_GLUSTERFS=y" >> $config_host_mak
+fi
+
 # USB host support
 case "$usb" in
 linux)
#2 lore raw

RFC PATCH 2/3 block: GlusterFS helpers to interface with libglusterfs

In reply to Bharata B Rao

block: GlusterFS helpers to interface with libglusterfs

From: Bharata B Rao <[email protected]>

This patch does two things:

- Adds GlusterFS specific init routines that enable QEMU to load volume file and load necessary translators.
- Implements routines like gluster_open(), gluster_read(), gluster_write() and gluster_close() that will be used by block layer of QEMU to do IO on VM images exported by GlusterFS server.

When libglusterfsclient is resurrected, this entire patch becomes redundant. Gluster init routines and other POSIX calls are present in libglusterfsclient.

---

 Makefile.objs           |    1 
 block/gluster-helpers.c | 1018 +++++++++++++++++++++++++++++++++++++++++++++++
 block/gluster-helpers.h |   40 ++
 3 files changed, 1059 insertions(+), 0 deletions(-)
 create mode 100644 block/gluster-helpers.c
 create mode 100644 block/gluster-helpers.h
Makefile.objs +1 -0
index 70c5c79..25190ba 100644
@@ -59,6 +59,7 @@ block-nested-$(CONFIG_POSIX) += raw-posix.o
 block-nested-$(CONFIG_LIBISCSI) += iscsi.o
 block-nested-$(CONFIG_CURL) += curl.o
 block-nested-$(CONFIG_RBD) += rbd.o
+block-nested-$(CONFIG_GLUSTERFS) += gluster-helpers.o
 
 block-obj-y +=  $(addprefix block/, $(block-nested-y))
 
block/gluster-helpers.c new file +1018 -0

1,018 lines not on this page · raw message

block/gluster-helpers.h new file +40 -0
new file mode 100644
index 0000000..612f0f2
@@ -0,0 +1,40 @@
+/*
+ * Helper routines for GlusterFS backend
+ * (Based on libglusterfsclient)
+ *
+ * Copyright (C) 2012 Bharata B Rao <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#include <glusterfs/glusterfs.h>
+#include <glusterfs/common-utils.h>
+#include <glusterfs/iobuf.h>
+#include <glusterfs/stack.h>
+#include <glusterfs/event.h>
+#include <glusterfs/call-stub.h>
+#include <glusterfs/mem-pool.h>
+#include <glusterfs/globals.h>
+#include <glusterfs/fd.h>
+
+#include <libgen.h>
+
+typedef void * gluster_file_t;
+
+typedef struct {
+    char *buf;
+    size_t size;
+    off_t offset;
+    int ret;
+    void (*completion_fn)(void *arg);
+    void *opaque;
+} gluster_aiocb_t;
+	
+extern glusterfs_ctx_t *gluster_init(char *volfile);
+extern int gluster_aio_readv(fd_t *fd, gluster_aiocb_t *gaiocb);
+extern int gluster_aio_writev(fd_t *fd, gluster_aiocb_t *gaiocb);
+extern gluster_file_t gluster_open(const char *path, int flags, int mode);
+extern int gluster_fstat(gluster_file_t fd, struct stat *buf);
+extern int gluster_close(gluster_file_t fd);
+extern gluster_file_t gluster_creat(const char *path, int mode);
+extern int gluster_ftruncate(gluster_file_t fd, off_t length);
#7 lore raw

RFC PATCH 3/3 block: gluster as block backend

In reply to Bharata B Rao

block: gluster as block backend

From: Bharata B Rao <[email protected]>

This patch adds gluster as the new block backend in QEMU. This gives QEMU the ability to boot VM images from gluster volumes.

---

 Makefile.objs   |    2 
 block/gluster.c |  435 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 436 insertions(+), 1 deletions(-)
 create mode 100644 block/gluster.c
Makefile.objs +1 -1
index 25190ba..859b88a 100644
@@ -59,7 +59,7 @@ block-nested-$(CONFIG_POSIX) += raw-posix.o
 block-nested-$(CONFIG_LIBISCSI) += iscsi.o
 block-nested-$(CONFIG_CURL) += curl.o
 block-nested-$(CONFIG_RBD) += rbd.o
-block-nested-$(CONFIG_GLUSTERFS) += gluster-helpers.o
+block-nested-$(CONFIG_GLUSTERFS) += gluster-helpers.o gluster.o
 
 block-obj-y +=  $(addprefix block/, $(block-nested-y))
 
block/gluster.c new file +435 -0

435 lines not on this page · raw message

#14 lore raw
In reply to Bharata B Rao
Quoted 3 lines · Bharata B Rao

4. Creating VM image

# qemu-img create -f gluster gluster:c-qemu.vol:/F16 5G

Do you really need "-f gluster"? The format should be "raw" (default) and the protocol should be "gluster". Specifying "gluster:..." as the filename takes care of hooking up the GlusterFS protocol.

Stefan

#8 lore raw

Re: [Qemu-devel] [RFC PATCH 3/3] block: gluster as block backend

In reply to Bharata B Rao

block/gluster.c line 15

Quoted 4 lines · Bharata B Rao
block/gluster.c new file +4 -0
+#include "block_int.h"
+#include "gluster-helpers.h"
+
+typedef void *gluster_file_t;

This typedef is already in gluster-helpers.h. It's ugly BTW, "typedef struct gluster_file gluster_file_t" is nicer since it won't cast to other pointer types automatically.

block/gluster.c line 20

Quoted 5 lines
block/gluster.c new file +5 -0
+
+typedef struct glusterConf {
+    char volfile[PATH_MAX];
+    char image[PATH_MAX];
+} glusterConf;

QEMU coding style always uses UpperCase for struct names.

block/gluster.c line 144

Quoted 7 lines
block/gluster.c new file +7 -0
+static void qemu_gluster_aio_event_reader(void *opaque)
+{
+    BDRVGlusterState *s = opaque;
+    ssize_t ret;
+
+    do {
+        char *p = (char *)&s->event_gaiocb;

Why make this a BDRVGlusterState field? It could be a local, I think.

Quoted 6 lines

+    /* Use O_DSYNC for write-through caching, no flags for write-back caching,
+     * and O_DIRECT for no caching. */
+    if ((bdrv_flags & BDRV_O_NOCACHE))
+        s->open_flags |= O_DIRECT;
+    if (!(bdrv_flags & BDRV_O_CACHE_WB))
+        s->open_flags |= O_DSYNC;

Paolo has changed this recently, you might need to use bs->enable_write_cache instead.

Quoted 4 lines

+out:
+    if (c) {
+        g_free(c);
+    }

g_free(NULL) is a nop, you never need to test that the pointer is non-NULL.

block/gluster.c line 309

Quoted 9 lines
block/gluster.c new file +9 -0
+static void gluster_finish_aiocb(void *arg)
+{
+    int ret;
+    gluster_aiocb_t *gaiocb = (gluster_aiocb_t *)arg;
+    BDRVGlusterState *s = ((glusterAIOCB *)gaiocb->opaque)->s;
+
+    ret = qemu_gluster_send_pipe(s, gaiocb);
+    if (ret < 0) {
+        g_free(gaiocb);

What about the glusterAIOCB? You need to invoke the callback with an error value.

What about decrementing the in-flight I/O request count?

Quoted 20 lines
block/gluster.c new file +20 -0
+static BlockDriverAIOCB *qemu_gluster_aio_rw(BlockDriverState *bs,
+        int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
+        BlockDriverCompletionFunc *cb, void *opaque, int write)
+{
+    int ret;
+    glusterAIOCB *acb;
+    gluster_aiocb_t *gaiocb;
+    BDRVGlusterState *s = bs->opaque;
+    char *buf;
+    size_t size;
+    off_t offset;
+
+    acb = qemu_aio_get(&gluster_aio_pool, bs, cb, opaque);
+    acb->write = write;
+    acb->qiov = qiov;
+    acb->bounce = qemu_blockalign(bs, qiov->size);
+    acb->ret = 0;
+    acb->bh = NULL;
+    acb->s = s;
+

block/gluster.c line 342

Quoted 10 lines
block/gluster.c new file +10 -0
+    if (write) {
+        qemu_iovec_to_buffer(acb->qiov, acb->bounce);
+    }
+
+    buf = acb->bounce;
+    offset = sector_num * BDRV_SECTOR_SIZE;
+    size = nb_sectors * BDRV_SECTOR_SIZE;
+    s->qemu_aio_count++;
+
+    gaiocb = g_malloc(sizeof(gluster_aiocb_t));

Can you make this a field of glusterAIOCB? Then you don't need to worry about freeing gaiocb later.

block/gluster.c line 390

Quoted 10 lines
block/gluster.c new file +10 -0
+static int64_t qemu_gluster_getlength(BlockDriverState *bs)
+{
+    BDRVGlusterState *s = bs->opaque;
+    gluster_file_t fd = s->fd;
+    struct stat st;
+    int ret;
+
+    ret = gluster_fstat(fd, &st);
+    if (ret < 0) {
+        return -1;

Please return a negative errno instead of -1.

Stefan

#3 lore raw

Re: [Qemu-devel] [RFC PATCH 2/3] block: GlusterFS helpers to interface with libglusterfs

In reply to Bharata B Rao
Quoted 2 lines · Bharata B Rao

+    ret = pthread_create(&thread, NULL, gluster_handle_poll,
+    (void *)gctx);

Please use qemu-thread.h. QEMU uses signals so you almost certainly want to mask signals for this thread (qemu_thread_create() does that).

Stefan

#15 lore raw
In reply to Stefan Hajnoczi
Quoted 7 lines · Stefan Hajnoczi
Quoted 3 lines · Bharata B Rao

4. Creating VM image

# qemu-img create -f gluster gluster:c-qemu.vol:/F16 5G

Do you really need "-f gluster"?

I realized that we don't. I was picked it up from the semantics of rbd.

Quoted 3 lines

The format should be "raw" (default)
and the protocol should be "gluster". Specifying "gluster:..." as the filename takes care of hooking up the GlusterFS protocol.

You are right. The current patches work w/o explicit specification of gluster as format, but I will update the documentation in the next version.

Regards,
Bharata.

#9 lore raw

Re: [Qemu-devel] [RFC PATCH 3/3] block: gluster as block backend

In reply to Stefan Hajnoczi
Quoted 10 lines · Stefan Hajnoczi

block/gluster.c line 15

Quoted 4 lines · Bharata B Rao
block/gluster.c new file +4 -0
+#include "block_int.h"
+#include "gluster-helpers.h"
+
+typedef void *gluster_file_t;

This typedef is already in gluster-helpers.h. It's ugly BTW, "typedef struct gluster_file gluster_file_t" is nicer since it won't cast to other pointer types automatically.

gluster_file_t can only be cast to a NACK since names ending with _t are reserved by the C runtime.

Signature · 1 line
error compiling committee.c: too many arguments to function
#10 lore raw

Re: [Qemu-devel] [RFC PATCH 3/3] block: gluster as block backend

In reply to Stefan Hajnoczi
Quoted 8 lines · Stefan Hajnoczi

block/gluster.c line 15

Quoted 4 lines · Bharata B Rao
block/gluster.c new file +4 -0
+#include "block_int.h"
+#include "gluster-helpers.h"
+
+typedef void *gluster_file_t;

This typedef is already in gluster-helpers.h.

Yes, will fix that.

Quoted 3 lines

It's ugly BTW, "typedef
struct gluster_file gluster_file_t" is nicer since it won't cast to other pointer types automatically.

Gluster routines in libglusterfsclient operate on gluster specific descriptor called fd_t.

glusterfs_open returns a pointer to fd_t and rest of the read/write routines take that pointer as input. libglusterfsclient hides this pointer by doing

typedef void *glusterfs_file_t.

I wanted to return an integer fd from open and then use them with read and write. But that would need some code in gluster backend to convert integer fd to fd_t and vice versa. Since libglusterfsclient doesn't deal with integer fd's, I retained this ugly typedef.

Quoted 8 lines

block/gluster.c line 20

Quoted 6 lines
block/gluster.c new file +5 -0
+
+typedef struct glusterConf {
+    char volfile[PATH_MAX];
+    char image[PATH_MAX];
+} glusterConf;

QEMU coding style always uses UpperCase for struct names.

Ok, will fix.

Quoted 10 lines

block/gluster.c line 144

Quoted 8 lines
block/gluster.c new file +7 -0
+static void qemu_gluster_aio_event_reader(void *opaque)
+{
+    BDRVGlusterState *s = opaque;
+    ssize_t ret;
+
+    do {
+        char *p = (char *)&s->event_gaiocb;

Why make this a BDRVGlusterState field? It could be a local, I think.

I could I guess, I was just following what rbd does.

Quoted 10 lines
Quoted 7 lines

+    /* Use O_DSYNC for write-through caching, no flags for write-back caching,
+     * and O_DIRECT for no caching. */
+    if ((bdrv_flags & BDRV_O_NOCACHE))
+        s->open_flags |= O_DIRECT;
+    if (!(bdrv_flags & BDRV_O_CACHE_WB))
+        s->open_flags |= O_DSYNC;

Paolo has changed this recently, you might need to use bs->enable_write_cache instead.

I picked up this logic from block/raw-posix.c:raw_open_common(). Don't see anything related to bs->enable_write_cache there. Will find out more about bs->enable_write_cache.

Quoted 7 lines
Quoted 5 lines

+out:
+    if (c) {
+        g_free(c);
+    }

g_free(NULL) is a nop, you never need to test that the pointer is non-NULL.

Ok.

Quoted 14 lines

block/gluster.c line 309

Quoted 10 lines
block/gluster.c new file +9 -0
+static void gluster_finish_aiocb(void *arg)
+{
+    int ret;
+    gluster_aiocb_t *gaiocb = (gluster_aiocb_t *)arg;
+    BDRVGlusterState *s = ((glusterAIOCB *)gaiocb->opaque)->s;
+
+    ret = qemu_gluster_send_pipe(s, gaiocb);
+    if (ret < 0) {
+        g_free(gaiocb);

What about the glusterAIOCB? You need to invoke the callback with an error value.

Quoted 1 line

What about decrementing the in-flight I/O request count?

Again, this comes from rbd. gluster_finish_aiocb() is the callback that we have registered with gluster. I am not doing any error handling when we even fail to write to the pipe. An even reader would be waiting to read from the other end of the pipe. Typically error handling and decrementing the in-flight IO request count is done by that event reader. But in this case, we even failed to kick (via pipe write) the even reader.

Quoted 26 lines
Quoted 26 lines
block/gluster.c new file +25 -0
+static BlockDriverAIOCB *qemu_gluster_aio_rw(BlockDriverState *bs,
+        int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
+        BlockDriverCompletionFunc *cb, void *opaque, int write)
+{
+    int ret;
+    glusterAIOCB *acb;
+    gluster_aiocb_t *gaiocb;
+    BDRVGlusterState *s = bs->opaque;
+    char *buf;
+    size_t size;
+    off_t offset;
+
+    acb = qemu_aio_get(&gluster_aio_pool, bs, cb, opaque);
+    acb->write = write;
+    acb->qiov = qiov;
+    acb->bounce = qemu_blockalign(bs, qiov->size);
+    acb->ret = 0;
+    acb->bh = NULL;
+    acb->s = s;
+
+    if (write) {
+        qemu_iovec_to_buffer(acb->qiov, acb->bounce);
+    }
+
+    buf = acb->bounce;
Quoted 8 lines
Quoted 5 lines

+    offset = sector_num * BDRV_SECTOR_SIZE;
+    size = nb_sectors * BDRV_SECTOR_SIZE;
+    s->qemu_aio_count++;
+
+    gaiocb = g_malloc(sizeof(gluster_aiocb_t));

Can you make this a field of glusterAIOCB? Then you don't need to worry about freeing gaiocb later.

Hmm, I already have glusterAIOCB as part of gaiocb.

Quoted 13 lines

block/gluster.c line 390

Quoted 11 lines
block/gluster.c new file +10 -0
+static int64_t qemu_gluster_getlength(BlockDriverState *bs)
+{
+    BDRVGlusterState *s = bs->opaque;
+    gluster_file_t fd = s->fd;
+    struct stat st;
+    int ret;
+
+    ret = gluster_fstat(fd, &st);
+    if (ret < 0) {
+        return -1;

Please return a negative errno instead of -1.

Ok. May be I could just return value from gluster_fstat().

Thanks for your review.

Regards,
Bharata.

#4 lore raw

Re: [Qemu-devel] [RFC PATCH 2/3] block: GlusterFS helpers to interface with libglusterfs

In reply to Stefan Hajnoczi
Quoted 7 lines · Stefan Hajnoczi
Quoted 2 lines · Bharata B Rao

+    ret = pthread_create(&thread, NULL, gluster_handle_poll,
+    (void *)gctx);

Please use qemu-thread.h. QEMU uses signals so you almost certainly want to mask signals for this thread (qemu_thread_create() does that).

Ok. This is temporary since this entire patch (2/3) would be redundant when we have libglusterfsclient working.

Regards,
Bharata.

#11 lore raw

Re: [Qemu-devel] [RFC PATCH 3/3] block: gluster as block backend

In reply to Bharata B Rao
Quoted 10 lines · Bharata B Rao
Quoted 9 lines · Stefan Hajnoczi
Quoted 6 lines · Bharata B Rao

+ á á/* Use O_DSYNC for write-through caching, no flags for write-back caching,
+ á á * and O_DIRECT for no caching. */
+ á áif ((bdrv_flags & BDRV_O_NOCACHE))
+ á á á ás->open_flags |= O_DIRECT;
+ á áif (!(bdrv_flags & BDRV_O_CACHE_WB))
+ á á á ás->open_flags |= O_DSYNC;

Quoted 6 lines
Quoted 2 lines

Paolo has changed this recently, you might need to use bs->enable_write_cache instead.

I picked up this logic from block/raw-posix.c:raw_open_common(). Don't see anything related to bs->enable_write_cache there. Will find out more about bs->enable_write_cache.

If you fetch the latest qemu.git and check bdrv_open_common() there is new code that stashes BDRV_O_CACHE_WB in bs->enable_write_cache and then opens the actual block driver with BDRV_O_CACHE_WB set. You can use bdrv_enable_write_cache() to test the original flag.

Quoted 13 lines
Quoted 13 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+static void gluster_finish_aiocb(void *arg)
+{
+ á áint ret;
+ á ágluster_aiocb_t *gaiocb = (gluster_aiocb_t *)arg;
+ á áBDRVGlusterState *s = ((glusterAIOCB *)gaiocb->opaque)->s;
+
+ á áret = qemu_gluster_send_pipe(s, gaiocb);
+ á áif (ret < 0) {
+ á á á ág_free(gaiocb);

What about the glusterAIOCB?  You need to invoke the callback with an error value.

Quoted 8 lines
Quoted 1 line

What about decrementing the in-flight I/O request count?

Again, this comes from rbd. gluster_finish_aiocb() is the callback that we have registered with gluster. I am not doing any error handling when we even fail to write to the pipe. An even reader would be waiting to read from the other end of the pipe. Typically error handling and decrementing the in-flight IO request count is done by that event reader. But in this case, we even failed to kick (via pipe write) the even reader.

It sounds like you're saying the request is not properly cleaned up and completed on failure. Please fix :).

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
block/gluster.c new file +4 -0
+static int64_t qemu_gluster_getlength(BlockDriverState *bs)
+{
+ á áBDRVGlusterState *s = bs->opaque;
+ á ágluster_file_t fd = s->fd;
Quoted 8 lines
Quoted 6 lines

+ á ástruct stat st;
+ á áint ret;
+
+ á áret = gluster_fstat(fd, &st);
+ á áif (ret < 0) {
+ á á á áreturn -1;

Please return a negative errno instead of -1.

Quoted 1 line

Ok. May be I could just return value from gluster_fstat().

The gluster_fstat() code also does not return negative errnos (at least in the first case I checked, when CALLOC() fails).

Stefan

#13 lore raw

Re: [Qemu-devel] [RFC PATCH 3/3] block: gluster as block backend

In reply to Stefan Hajnoczi

Il 18/06/2012 19:35, Stefan Hajnoczi ha scritto:

Quoted 8 lines
Quoted 6 lines

block/gluster.c line 198

Quoted 6 lines
block/gluster.c new file +6 -0
+    /* Use O_DSYNC for write-through caching, no flags for write-back caching,
+     * and O_DIRECT for no caching. */
+    if ((bdrv_flags & BDRV_O_NOCACHE))
+        s->open_flags |= O_DIRECT;
+    if (!(bdrv_flags & BDRV_O_CACHE_WB))
+        s->open_flags |= O_DSYNC;

Paolo has changed this recently, you might need to use bs->enable_write_cache instead.

At the protocol (i.e. low-level backend) level you don't need to do anything really, if you implement bdrv_flush_to_disk correctly.

Looking at BDRV_O_CACHE_WB will do no harm, it's just dead code.

Paolo

#12 lore raw

Re: [Qemu-devel] [RFC PATCH 3/3] block: gluster as block backend

In reply to Stefan Hajnoczi

Il 19/06/2012 13:05, Stefan Hajnoczi ha scritto:

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

I picked up this logic from block/raw-posix.c:raw_open_common(). Don't see anything related to bs->enable_write_cache there. Will find out more about bs->enable_write_cache.

If you fetch the latest qemu.git and check bdrv_open_common() there is new code that stashes BDRV_O_CACHE_WB in bs->enable_write_cache and then opens the actual block driver with BDRV_O_CACHE_WB set. You can use bdrv_enable_write_cache() to test the original flag.

Yes, but you shouldn't do this when opening. You should always open for writeback.

Paolo

#5 lore raw

Re: [Qemu-devel] [RFC PATCH 2/3] block: GlusterFS helpers to interface with libglusterfs

In reply to Bharata B Rao

Il 19/06/2012 11:31, Bharata B Rao ha scritto:

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

block/gluster-helpers.c line 1001

Quoted 2 lines
block/gluster-helpers.c new file +2 -0
+    ret = pthread_create(&thread, NULL, gluster_handle_poll,
+    (void *)gctx);

Please use qemu-thread.h. QEMU uses signals so you almost certainly want to mask signals for this thread (qemu_thread_create() does that).

Ok. This is temporary since this entire patch (2/3) would be redundant when we have libglusterfsclient working.

Please make sure that libglusterfsclient also masks signals for its own threads. It's a pretty common source of bugs with threaded libraries, and masking the signals is harmless for programs that do not care.

Paolo

#6 lore raw

Re: [Qemu-devel] [RFC PATCH 2/3] block: GlusterFS helpers to interface with libglusterfs

Quoted 4 lines · Paolo Bonzini

Il 19/06/2012 11:31, Bharata B Rao ha scritto:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
block/gluster-helpers.c new file +2 -0
+    ret = pthread_create(&thread, NULL, gluster_handle_poll,
+    (void *)gctx);
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

Please use qemu-thread.h. QEMU uses signals so you almost certainly want to mask signals for this thread (qemu_thread_create() does that).

Ok. This is temporary since this entire patch (2/3) would be redundant when we have libglusterfsclient working.

Please make sure that libglusterfsclient also masks signals for its own threads. It's a pretty common source of bugs with threaded libraries, and masking the signals is harmless for programs that do not care.

Will take care of this. Thanks for your review.

Regards,
Bharata.

#16 lore raw
In reply to Bharata B Rao
Quoted 3 lines · Bharata B Rao
# qemu-system-x86_64 --enable-kvm --nographic -smp 4 -m 1024 -drive file=gluster:c-qemu.vol:/F16,format=gluster

If you notice above, I am directly feeding the gluster volume file to QEMU. During my discussions with GlusterFS developers, I realized that it is more relevant to use volume name than volume file directly. Hence I am proposing that QEMU should have the gluster specifications like this:

-drive file=gluster:volfileserver:volumename:imagename

Note that volfile server and volume name combination is the standard way of specifying a volume in gluster world.

QEMU would pass volfileserver:volumename to libglusterfsclient which will contact the server and fetch the right client volume file to use. This specification change has two side effects:

1. It limits the QEMU user to pick volfiles that are generated only by gluster CLI. This should be fine as long as gluster CLI provides the capability to generate or regenerate volume files for a given volume with the xlator set that QEMU user is interested in. GlusterFS developers tell me that this can be provided with some enhancements to glusterCLI/glusterd.

Note that custom volume files could be typically needed when GlusterFS server is co-located with QEMU in which case you would like to get rid of client-server overhead and RPC communication overhead.

2. As of now, the specification of volfileserver:volumename picks the default client volume file for the given volume name. Since we want to have the flexibility to pick the volfile of our choice, we could slightly extend the specification like this:

volfileserver:volumename.custom

that would instruct gluster to pick a custom volume file.

Eg. volfileserver:myvol.rpcbypass would pick myvol.rpcbypass.vol volume file for the volume myvol.

Here also, the creation of custom volume file is done by gluster CLI, so that gluster is in a position to pick the right volume file.

As per my current understanding, such custom volfile extensions works with gluster.

Request QEMU developers to comment on the new specification and point out any use cases that wouldn't be possible or would be hindered by this volfileserver:volumename specification.

I also request the GlusterFS developers (on CC) to validate my understanding of gluster here and let me know if the proposed enhancements to glusterCLI/glusterd are indeed feasible.

Regards,
Bharata.