[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] blktap: make memshr optional



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1263279681 0
# Node ID 5b45d08b7abf9316be1cc2b510631736a739064f
# Parent  5e1971bec8819c4ea55af24dfe8b30762e00965d
blktap: make memshr optional

Attached patch makes memshr optional for blktap/blktap2.
This fixes build for platforms where memshr isn't build on.
While there, make indentation consistent.

Signed-off-by: Christoph Egger <Christoph.Egger@xxxxxxx>
---
 tools/blktap/drivers/Makefile         |    8 +++
 tools/blktap/drivers/blktapctrl.c     |    4 +
 tools/blktap2/drivers/Makefile        |    8 +++
 tools/blktap2/drivers/tapdisk-image.c |   10 +++-
 tools/blktap2/drivers/tapdisk-vbd.c   |   78 ++++++++++++++++++----------------
 tools/blktap2/drivers/tapdisk.h       |    4 +
 tools/blktap2/drivers/tapdisk2.c      |   15 ++++--
 7 files changed, 82 insertions(+), 45 deletions(-)

diff -r 5e1971bec881 -r 5b45d08b7abf tools/blktap/drivers/Makefile
--- a/tools/blktap/drivers/Makefile     Tue Jan 12 06:56:56 2010 +0000
+++ b/tools/blktap/drivers/Makefile     Tue Jan 12 07:01:21 2010 +0000
@@ -23,7 +23,13 @@ CRYPT_LIB := -lcrypto
 $(warning === libgcrypt not installed: falling back to libcrypto ===)
 endif
 
-LDFLAGS_blktapctrl := $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenstore) 
$(MEMSHR_DIR)/libmemshr.a -L../lib -lblktap -lrt -lm
+MEMSHRLIBS :=
+ifeq ($(CONFIG_Linux), y)
+CFLAGS += -DMEMSHR
+MEMSHRLIBS += $(MEMSHR_DIR)/libmemshr.a
+endif
+
+LDFLAGS_blktapctrl := $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenstore) 
$(MEMSHRLIBS) -L../lib -lblktap -lrt -lm
 LDFLAGS_img := $(LIBAIO_DIR)/libaio.a $(CRYPT_LIB) -lpthread -lz
 
 BLK-OBJS-y  := block-aio.o
diff -r 5e1971bec881 -r 5b45d08b7abf tools/blktap/drivers/blktapctrl.c
--- a/tools/blktap/drivers/blktapctrl.c Tue Jan 12 06:56:56 2010 +0000
+++ b/tools/blktap/drivers/blktapctrl.c Tue Jan 12 07:01:21 2010 +0000
@@ -859,7 +859,9 @@ int main(int argc, char *argv[])
                goto open_failed;
        }
 
-    memshr_daemon_initialize();
+#ifdef MEMSHR
+       memshr_daemon_initialize();
+#endif
 
  retry:
        /* Set up store connection and watch. */
diff -r 5e1971bec881 -r 5b45d08b7abf tools/blktap2/drivers/Makefile
--- a/tools/blktap2/drivers/Makefile    Tue Jan 12 06:56:56 2010 +0000
+++ b/tools/blktap2/drivers/Makefile    Tue Jan 12 07:01:21 2010 +0000
@@ -55,7 +55,13 @@ REMUS-OBJS  += hashtable_utility.o
 
 LIBAIO_DIR = $(XEN_ROOT)/tools/libaio/src
 MEMSHR_DIR = $(XEN_ROOT)/tools/memshr
-MEMSHRLIBS := $(MEMSHR_DIR)/libmemshr.a
+
+MEMSHRLIBS :=
+ifeq ($(CONFIG_Linux), y)
+CFLAGS += -DMEMSHR
+MEMSHRLIBS += $(MEMSHR_DIR)/libmemshr.a
+endif
+
 tapdisk2 tapdisk-stream tapdisk-diff $(QCOW_UTIL): AIOLIBS := 
$(LIBAIO_DIR)/libaio.a 
 tapdisk-client tapdisk-stream tapdisk-diff $(QCOW_UTIL): CFLAGS  += 
-I$(LIBAIO_DIR) -I$(XEN_LIBXC)
 
diff -r 5e1971bec881 -r 5b45d08b7abf tools/blktap2/drivers/tapdisk-image.c
--- a/tools/blktap2/drivers/tapdisk-image.c     Tue Jan 12 06:56:56 2010 +0000
+++ b/tools/blktap2/drivers/tapdisk-image.c     Tue Jan 12 07:01:21 2010 +0000
@@ -28,7 +28,9 @@
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
+#ifdef MEMSHR
 #include <memshr.h>
+#endif
 
 #include "tapdisk-image.h"
 #include "tapdisk-driver.h"
@@ -57,7 +59,9 @@ tapdisk_image_allocate(char *file, int t
        image->flags     = flags;
        image->storage   = storage;
        image->private   = private;
-    image->memshr_id = memshr_vbd_image_get(file);
+#ifdef MEMSHR
+       image->memshr_id = memshr_vbd_image_get(file);
+#endif
        INIT_LIST_HEAD(&image->next);
 
        return image;
@@ -71,7 +75,9 @@ tapdisk_image_free(td_image_t *image)
 
        list_del(&image->next);
 
-    memshr_vbd_image_put(image->memshr_id);
+#ifdef MEMSHR
+       memshr_vbd_image_put(image->memshr_id);
+#endif
        free(image->name);
        tapdisk_driver_free(image->driver);
        free(image);
diff -r 5e1971bec881 -r 5b45d08b7abf tools/blktap2/drivers/tapdisk-vbd.c
--- a/tools/blktap2/drivers/tapdisk-vbd.c       Tue Jan 12 06:56:56 2010 +0000
+++ b/tools/blktap2/drivers/tapdisk-vbd.c       Tue Jan 12 07:01:21 2010 +0000
@@ -34,7 +34,9 @@
 #include <libgen.h>
 #include <sys/mman.h>
 #include <sys/ioctl.h>
+#ifdef MEMSHR
 #include <memshr.h>
+#endif
 
 #include "libvhd.h"
 #include "tapdisk-image.h"
@@ -107,7 +109,9 @@ tapdisk_vbd_initialize(int rfd, int wfd,
        vbd->callback = tapdisk_vbd_callback;
        vbd->argument = vbd;
     
-    memshr_vbd_initialize();
+#ifdef MEMSHR
+       memshr_vbd_initialize();
+#endif
 
        INIT_LIST_HEAD(&vbd->driver_stack);
        INIT_LIST_HEAD(&vbd->images);
@@ -1455,18 +1459,23 @@ __tapdisk_vbd_complete_td_request(td_vbd
                            (treq.op == TD_OP_WRITE ? "write" : "read"),
                            treq.secs, treq.sec);
                }
-       } else 
-    if(treq.op == TD_OP_READ && td_flag_test(image->flags, TD_OPEN_RDONLY)) {
-        uint64_t         hnd  = treq.memshr_hnd;
-        uint16_t         uid  = image->memshr_id;
-        blkif_request_t *breq = &vreq->req;
-        uint64_t         sec  = tapdisk_vbd_breq_get_sector(breq, treq);
-        int              secs = breq->seg[treq.sidx].last_sect -
-                                breq->seg[treq.sidx].first_sect + 1;
-
-        if(hnd != 0)
-            memshr_vbd_complete_ro_request(hnd, uid, sec, secs);
-    }
+       } else {
+#ifdef MEMSHR
+               if (treq.op == TD_OP_READ
+                  && td_flag_test(image->flags, TD_OPEN_RDONLY)) {
+                       uint64_t hnd  = treq.memshr_hnd;
+                       uint16_t uid  = image->memshr_id;
+                       blkif_request_t *breq = &vreq->req;
+                       uint64_t sec  = tapdisk_vbd_breq_get_sector(breq, treq);
+                       int secs = breq->seg[treq.sidx].last_sect -
+                           breq->seg[treq.sidx].first_sect + 1;
+
+                       if (hnd != 0)
+                               memshr_vbd_complete_ro_request(hnd, uid,
+                                                               sec, secs);
+               }
+#endif
+       }
 
        tapdisk_vbd_complete_vbd_request(vbd, vreq);
 }
@@ -1518,29 +1527,28 @@ __tapdisk_vbd_reissue_td_request(td_vbd_
                break;
 
        case TD_OP_READ:
-        if(td_flag_test(parent->flags, TD_OPEN_RDONLY))
-        {
-            int ret, seg = treq.sidx;
-            blkif_request_t *breq = &vreq->req;
+#ifdef MEMSHR
+               if(td_flag_test(parent->flags, TD_OPEN_RDONLY)) {
+                       int ret, seg = treq.sidx;
+                       blkif_request_t *breq = &vreq->req;
         
-            ret = memshr_vbd_issue_ro_request(treq.buf,
-                                              breq->seg[seg].gref,
-                                              parent->memshr_id,
-                                              treq.sec,
-                                              treq.secs,
-                                              &treq.memshr_hnd);
-            if(ret == 0)
-            {
-                /* Reset memshr handle. This'll prevent
-                 * memshr_vbd_complete_ro_request being called */
-                treq.memshr_hnd = 0;
-                td_complete_request(treq, 0);
-            }
-            else
-                       td_queue_read(parent, treq);
-        }
-        else
-                   td_queue_read(parent, treq);
+                       ret = memshr_vbd_issue_ro_request(treq.buf,
+                             breq->seg[seg].gref,
+                             parent->memshr_id,
+                             treq.sec,
+                             treq.secs,
+                             &treq.memshr_hnd);
+                       if(ret == 0) {
+                               /* Reset memshr handle. This'll prevent
+                                * memshr_vbd_complete_ro_request being called
+                                */
+                               treq.memshr_hnd = 0;
+                               td_complete_request(treq, 0);
+                       } else
+                               td_queue_read(parent, treq);
+               } else
+#endif
+                       td_queue_read(parent, treq);
                break;
        }
 
diff -r 5e1971bec881 -r 5b45d08b7abf tools/blktap2/drivers/tapdisk.h
--- a/tools/blktap2/drivers/tapdisk.h   Tue Jan 12 06:56:56 2010 +0000
+++ b/tools/blktap2/drivers/tapdisk.h   Tue Jan 12 07:01:21 2010 +0000
@@ -132,7 +132,9 @@ struct td_request {
        int                          sidx;
        void                        *private;
     
-    uint64_t                     memshr_hnd;
+#ifdef MEMSHR
+       uint64_t                     memshr_hnd;
+#endif
 };
 
 /* 
diff -r 5e1971bec881 -r 5b45d08b7abf tools/blktap2/drivers/tapdisk2.c
--- a/tools/blktap2/drivers/tapdisk2.c  Tue Jan 12 06:56:56 2010 +0000
+++ b/tools/blktap2/drivers/tapdisk2.c  Tue Jan 12 07:01:21 2010 +0000
@@ -34,7 +34,9 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
+#ifdef MEMSHR
 #include <memshr.h>
+#endif
 
 #include "tapdisk.h"
 #include "blktap2.h"
@@ -419,10 +421,15 @@ main(int argc, char *argv[])
                        break;
                case 'h':
                        usage(argv[0], 0);
-            break;
-        case 's':
-            memshr_set_domid(atoi(optarg));
-            break;
+                       break;
+               case 's':
+#ifdef MEMSHR
+                       memshr_set_domid(atoi(optarg));
+#else
+                       fprintf(stderr, "MEMSHR support not compiled in.\n");
+                       exit(EXIT_FAILURE);
+#endif
+                       break;
                default:
                        usage(argv[0], EINVAL);
                }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.