]> xenbits.xensource.com Git - people/dstodden/blktap.git/commitdiff
latest.diff xcp/volatile/xenio
authorDaniel Stodden <daniel.stodden@citrix.com>
Thu, 1 Sep 2011 13:20:00 +0000 (14:20 +0100)
committerDaniel Stodden <daniel.stodden@citrix.com>
Thu, 1 Sep 2011 14:03:07 +0000 (15:03 +0100)
Signed-off-by: Daniel Stodden <daniel.stodden@citrix.com>
14 files changed:
.gitignore
configure.ac
control/tap-ctl-xen.c
control/tap-ctl-xen.h
drivers/Makefile.am
drivers/tapdisk-control.c
drivers/tapdisk-xenblkif.c
drivers/tapdisk-xenblkif.h
include/tapdisk-message.h
xenio/Makefile [deleted file]
xenio/Makefile.am [new file with mode: 0644]
xenio/blkback.c
xenio/xenio-ctx.c
xenio/xenio.h

index dcb78caee7c7f6bc98d4ee644290ef9949bc43ee..d70ea80d81e955e888bb319e39ada93063c333a0 100644 (file)
@@ -46,6 +46,7 @@ Makefile.in
 /part/Makefile
 /drivers/Makefile
 /control/Makefile
+/xenio/Makefile
 /include/Makefile
 /vhd/Makefile
 /vhd/lib/Makefile
index f0416d0b8618a7e758cdf6cf41ed507c8d3ab50a..11a5b192fab970d2b41184e740797361c2237558 100644 (file)
@@ -11,6 +11,7 @@ AC_PROG_MAKE_SET
 AC_CANONICAL_HOST
 AC_CHECK_HEADERS([uuid/uuid.h], [], [Need uuid-dev])
 AC_CHECK_HEADERS([libaio.h], [], [Need libaio-dev])
+AC_CHECK_HEADERS([xen/xen.h], [], [Need libxen-dev])
 
 AC_ARG_WITH([libiconv],
             [AS_HELP_STRING([--with-libiconv],
@@ -36,6 +37,10 @@ AS_IF([test x$with_libiconv != xno],
                     [:],
                    AC_MSG_ERROR([Missing iconv in libc]))])
 
+AC_CHECK_LIB([xenctrl], [main],
+             [:],
+            AC_MSG_ERROR([Need libxen-dev]))
+
 AC_ARG_ENABLE([tests],
              [AS_HELP_STRING([--enable-tests],
                              [build test programs])],
@@ -66,6 +71,7 @@ AC_CONFIG_FILES([
 Makefile
 lvm/Makefile
 part/Makefile
+xenio/Makefile
 vhd/Makefile
 vhd/lib/Makefile
 vhd/lib/test/Makefile
index cafa818295393a2905c693ac5db0f4372d38a013..6c50cf2f6c7bfaf84e8f3186b54e9c0b4e9e778b 100644 (file)
@@ -36,8 +36,9 @@ int
 tap_ctl_connect_xenblkif(pid_t pid, int minor,
                         domid_t domid, int devid,
                         const grant_ref_t *grefs, int order,
+                        evtchn_port_t port,
                         int proto,
-                        evtchn_port_t port)
+                        const char *pool)
 {
        tapdisk_message_t message;
        int i, err;
@@ -48,11 +49,12 @@ tap_ctl_connect_xenblkif(pid_t pid, int minor,
 
        message.u.blkif.domid = domid;
        message.u.blkif.devid = devid;
-       message.u.blkif.order = order;
-       message.u.blkif.port  = port;
-
        for (i = 0; i < 1<<order; i++)
                message.u.blkif.gref[i] = grefs[i];
+       message.u.blkif.order = order;
+       message.u.blkif.port  = port;
+       message.u.blkif.proto = proto;
+       strncpy(message.u.blkif.pool, pool, sizeof(message.u.blkif.pool));
 
        err = tap_ctl_connect_send_and_receive(pid, &message, NULL);
        if (err)
index bbe3c7ab6c9f9f54e79757379a93229b9c45b8c9..212d539edde64cf22b15bab35b0a1a10527c2041 100644 (file)
@@ -36,8 +36,9 @@
 int tap_ctl_connect_xenblkif(pid_t pid, int minor,
                             domid_t domid, int devid,
                             const grant_ref_t *grefs, int order,
+                            evtchn_port_t port,
                             int proto,
-                            evtchn_port_t port);
+                            const char *pool);
 
 int tap_ctl_disconnect_xenblkif(pid_t pid, int minor,
                                domid_t domid, int devid,
index 1a06b68f3987b58be07cb30a3b3a0380433daf7d..c7ff019d7792395542979a6171fd68b692e75cb2 100644 (file)
@@ -83,3 +83,4 @@ libtapdisk_la_SOURCES += block-llcache.c
 
 libtapdisk_la_LIBADD  = ../vhd/lib/libvhd.la
 libtapdisk_la_LIBADD += -laio
+libtapdisk_la_LIBADD += ../xenio/libxenio.la
index a23a118eadbae2f05678284daade17ac15087ef3..fbf74946fb8a1cd1afeac7812e479801c8e37f5b 100644 (file)
@@ -485,7 +485,7 @@ tapdisk_control_write_message(struct tapdisk_ctl_conn *conn,
                if (flags & TAPDISK_MSG_VERBOSE_ERROR)
                        DBG("sending '%s' message (uuid = %u): %d",
                            tapdisk_message_name(message->type), message->cookie,
-                           message->u.response.error); 
+                           -message->u.response.error);
                else
                        DBG("sending '%s' message (uuid = %u)",
                            tapdisk_message_name(message->type), message->cookie);
@@ -972,21 +972,37 @@ tapdisk_control_xenblkif_connect(struct tapdisk_ctl_conn *conn,
        tapdisk_message_blkif_t *blkif = &request->u.blkif;
        tapdisk_message_t response;
        td_vbd_t *vbd;
+       const char *pool;
+       size_t len;
        int err;
 
+
        vbd = tapdisk_server_get_vbd(request->cookie);
        if (!vbd) {
                err = -ENODEV;
                goto out;
        }
 
-       DPRINTF("connecting vbd-%d-%d to vbd %d\n",
-               blkif->domid, blkif->devid, request->cookie);
-
-       err = tapdisk_xenblkif_connect(blkif->domid, blkif->devid,
-                                      blkif->gref, blkif->order,
-                                      blkif->proto, blkif->port,
-                                      NULL, vbd);
+       len = strnlen(blkif->pool, sizeof(blkif->pool));
+       if (!len)
+               pool = NULL;
+       else if (len >= sizeof(blkif->pool)) {
+               err = -EINVAL;
+               goto out;
+       } else
+               pool = blkif->pool;
+
+       DPRINTF("connecting vbd-%d-%d to minor %d, pool %s, evt %d\n",
+               blkif->domid, blkif->devid, request->cookie, pool, blkif->port);
+
+       err = tapdisk_xenblkif_connect(blkif->domid,
+                                      blkif->devid,
+                                      blkif->gref,
+                                      blkif->order,
+                                      blkif->port,
+                                      blkif->proto,
+                                      pool,
+                                      vbd);
 out:
        memset(&response, 0, sizeof(response));
        response.type = TAPDISK_MESSAGE_XENBLKIF_CONNECT_RSP;
@@ -1008,7 +1024,6 @@ tapdisk_control_xenblkif_disconnect(struct tapdisk_ctl_conn *conn,
 
        err = tapdisk_xenblkif_disconnect(blkif->domid, blkif->devid);
 
-out:
        memset(&response, 0, sizeof(response));
        response.type = TAPDISK_MESSAGE_XENBLKIF_DISCONNECT_RSP;
        response.cookie = request->cookie;
index bea4e6fc11b1138d579a692db17c3321c4cc4d1b..4a185a29f86340b85128ee0d19577fcce36925b3 100644 (file)
@@ -46,7 +46,9 @@
 #include "xenio.h"
 #include "list.h"
 
-#define unlikely(_cond)         (_cond)
+/* NB. may be NULL, but then the image must be bouncing I/O */
+#define TD_XENBLKIF_DEFAULT_POOL "td-xenio-default"
+
 #define BUG_ON(_cond)           if (unlikely(_cond)) { td_panic(); }
 
 #define WARN(_fmt, _args ...)                                          \
@@ -73,9 +75,6 @@
        __cond;                                                 \
 })
 
-#define containerof(_ptr, _type, _member)                      \
-       ((_type*)((void*)(_ptr) - offsetof(_type, _member)))
-
 typedef struct td_xenio_ctx td_xenio_ctx_t;
 typedef struct td_xenblkif td_xenblkif_t;
 typedef struct td_xenblkif_req td_xenblkif_req_t;
@@ -369,7 +368,7 @@ tapdisk_xenblkif_queue_requests(td_xenblkif_t *blkif,
 void
 tapdisk_xenblkif_ring_event(td_xenblkif_t *blkif)
 {
-       int n_reqs, final, err;
+       int n_reqs, final;
 
        blkif->stats.kicks.in++;
 
@@ -407,7 +406,6 @@ tapdisk_xenio_ctx_ring_event(event_id_t id, char mode, void *private)
        td_xenio_ctx_t *ctx = private;
        xenio_blkif_t *xenio;
        td_xenblkif_t *blkif;
-       void *data;
 
        xenio = xenio_pending_blkif(ctx->xenio,
                                    (void**)&blkif);
@@ -510,6 +508,10 @@ tapdisk_xenio_ctx_open(const char *pool)
                goto fail;
        }
 
+       /*
+        * attach to some frame pool
+        */
+
        if (pool) {
                ctx->pool = strdup(pool);
                if (!ctx->pool) {
@@ -521,6 +523,7 @@ tapdisk_xenio_ctx_open(const char *pool)
 
        if (ctx->pool) {
                err = xenio_bind_frame_pool(ctx->xenio, ctx->pool);
+               WARN_ON_WITH_ERRNO(err);
                if (err) {
                        err = -errno;
                        goto fail;
@@ -553,16 +556,16 @@ tapdisk_xenio_ctx_get(const char *pool, td_xenio_ctx_t **_ctx)
        td_xenio_ctx_t *ctx;
        int err = 0;
 
-retry:
-       tapdisk_xenio_find_ctx(ctx,
-                              __td_xenio_ctx_match(ctx, pool));
-       if (!ctx) {
-               err = tapdisk_xenio_ctx_open(pool);
-               if (!err)
-                       goto retry;
-       }
+       do {
+               tapdisk_xenio_find_ctx(ctx,
+                                      __td_xenio_ctx_match(ctx, pool));
+               if (ctx) {
+                       *_ctx = ctx;
+                       return 0;
+               }
 
-       *_ctx = ctx;
+               err = tapdisk_xenio_ctx_open(pool);
+       } while (!err);
 
        return err;
 }
@@ -627,8 +630,11 @@ tapdisk_xenblkif_disconnect(domid_t domid, int devid)
 
 int
 tapdisk_xenblkif_connect(domid_t domid, int devid,
-                        const grant_ref_t *grefs, int order, int proto,
-                        evtchn_port_t port, const char *pool, td_vbd_t *vbd)
+                        const grant_ref_t *grefs, int order,
+                        evtchn_port_t port,
+                        int proto,
+                        const char *pool,
+                        td_vbd_t *vbd)
 {
        td_xenblkif_t *blkif = NULL;
        td_xenio_ctx_t *ctx;
@@ -656,9 +662,10 @@ tapdisk_xenblkif_connect(domid_t domid, int devid,
        list_add_tail(&blkif->ctx_entry, &ctx->blkifs);
 
        blkif->xenio = xenio_blkif_connect(ctx->xenio,
-                                          domid, grefs, order, port,
-                                          proto,
+                                          domid,
+                                          grefs, order, port, proto,
                                           blkif);
+       WARN_ON_WITH_ERRNO(!blkif->xenio);
        if (!blkif->xenio) {
                err = -errno;
                goto fail;
index ba08dc61cf53c33e86575735c55c76c9904b1f20..9a13902477fdf223375f5986c77e20a750822e70 100644 (file)
 #ifndef _TAPDISK_XENBLKIF_H_
 #define _TAPDISK_XENBLKIF_H_
 
-/* NB. may be NULL, but then the image must be bouncing I/O */
-#define TD_XENBLKIF_DEFAULT_POOL "td-xenio-default"
+#include <xen/xen.h>
+#include <xen/grant_table.h>
+#include <xen/event_channel.h>
 
 int tapdisk_xenblkif_connect(domid_t domid, int devid,
                             const grant_ref_t *grefs, int order,
-                            int proto, evtchn_port_t port,
-                            const char *pool, td_vbd_t *vbd);
+                            evtchn_port_t port,
+                            int proto,
+                            const char *pool,
+                            td_vbd_t *vbd);
 
 int tapdisk_xenblkif_disconnect(domid_t domid, int devid);
 
index b6bd12774f339cae2a891aad7c49a28146256390..db6925ce73c49b7ee3709daae2b4d639fe48205c 100644 (file)
@@ -106,6 +106,7 @@ struct tapdisk_message_blkif {
        uint32_t                         gref[8];
        uint32_t                         order;
        uint32_t                         proto;
+       char                             pool[TAPDISK_MESSAGE_STRING_LENGTH];
        uint32_t                         port;
 };
 
diff --git a/xenio/Makefile b/xenio/Makefile
deleted file mode 100644 (file)
index 4a0e58a..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-
-CC        = gcc
-
-CFLAGS    = -O2 -Wall -Werror -g
-CFLAGS   += -Wp,-MD,.$(@F).d
-DEPS      = .*.d
-
-CPPFLAGS  = -I.
-CPPFLAGS += -D_GNU_SOURCE
-CPPFLAGS += -D_LARGEFILE64_SOURCE
-
-XENIO-OBJS  = xenio-ctx.o
-XENIO-OBJS += xenio-blkif.o
-
-all: libxenio.a
-
-libxenio.a: libxenio.a($(XENIO-OBJS))
-
-clean:
-       rm -f libxenio.a
-       rm -f $(XENIO-OBJS)
-       rm -f $(DEPS)
-       rm -f *~
-
--include $(DEPS)
diff --git a/xenio/Makefile.am b/xenio/Makefile.am
new file mode 100644 (file)
index 0000000..5f8234e
--- /dev/null
@@ -0,0 +1,20 @@
+
+AM_CFLAGS  = -Wall
+AM_CFLAGS += -Werror
+
+AM_CPPFLAGS  = -D_GNU_SOURCE
+AM_CPPFLAGS += -D_FILE_OFFSET_BITS=64
+AM_CPPFLAGS += -I$(top_srcdir)/include
+AM_CPPFLAGS += -I$(top_srcdir)/xenio
+
+lib_LTLIBRARIES = libxenio.la
+
+libxenio_la_SOURCES  = xenio.h
+libxenio_la_SOURCES += xenio-private.h
+libxenio_la_SOURCES += xenio-ctx.c
+libxenio_la_SOURCES += xenio-blkif.c
+libxenio_la_SOURCES += gntdev.h
+
+libxenio_la_LIBADD = -lxenctrl -lpthread
+
+libxenio_la_LDFLAGS = -version-info 0:1:0
index 639bc36b240bbba8c45fbe7a669bbf05bf1a5fea..2967965d5af94f32fc5804a07cdcd8878a02a9a2 100644 (file)
@@ -960,6 +960,7 @@ blkback_connect_tap(xenio_device_t *xbdev)
        evtchn_port_t port;
        grant_ref_t gref;
        int n, proto, err;
+       char *pool;
 
        n = xenio_device_scanf_otherend(xbdev, "ring-ref",
                                        "%u", &gref);
@@ -975,13 +976,16 @@ blkback_connect_tap(xenio_device_t *xbdev)
        if (proto < 0)
                goto fail;
 
+       pool = xenio_device_read(xbdev, "sm-data/frame-pool");
+
        err = blkback_find_tapdisk(bdev);
        if (err)
                goto fail;
 
-       DBG("connecting vbd-%d-%d (gnt %d, evt %d) to tapdisk %d minor %d\n",
+       DBG("connecting vbd-%d-%d (gnt %d, evt %d, proto %d, pool %s)"
+           " to tapdisk %d minor %d\n",
            bdev->domid, bdev->devid,
-           gref, port,
+           gref, port, proto, pool,
            bdev->tap.pid, bdev->tap.minor);
 
        err = tap_ctl_connect_xenblkif(bdev->tap.pid,
@@ -989,8 +993,8 @@ blkback_connect_tap(xenio_device_t *xbdev)
                                       bdev->domid,
                                       bdev->devid,
                                       &gref, 0,
-                                      proto,
-                                      bdev->port);
+                                      port, proto,
+                                      pool);
        DBG("err=%d errno=%d\n", err, errno);
        if (err)
                goto fail;
index bd06276a6a22432618e69978f91573aba9f75602..5dddca444c2025656e46711418fd852cc4a61bc9 100644 (file)
@@ -88,18 +88,25 @@ int
 xenio_bind_frame_pool(xenio_ctx_t *ctx, const char *name)
 {
        struct ioctl_gntdev_bind_pool bind;
-       const size_t max = sizeof(bind.name) - 1;
+       const size_t max = sizeof(bind.name);
        int err;
 
-       if (strnlen(name, max) >= max)
-               return -EINVAL;
+       if (strnlen(name, max) >= max) {
+               err = -EINVAL;
+               goto fail;
+
+       }
 
        strcpy(bind.name, name);
 
        err = ioctl(ctx->xcg_handle, IOCTL_GNTDEV_BIND_POOL, &bind);
        if (err)
-               err = -errno;
+               return -errno;
 
+       return 0;
+
+fail:
+       errno = -err;
        return err;
 }
 
index 0f06ef185547208c7a0d25ddf59a09939482b768..590e173052ce806957f03a057ab59d642ddf37db 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef _XENIO_H
 #define _XENIO_H
 
+#define _FILE_OFFSET_BITS 64
+
 #include <stdint.h>
 #include <sys/types.h>
 #include <sys/mman.h>
@@ -149,7 +151,7 @@ struct xenio_blkif_req {
        uint64_t                id;
        int                     status;
 
-       off64_t                 offset;
+       off_t                   offset;
        struct xenio_blkif_seg {
                uint8_t         first;
                uint8_t         last;