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

[Xen-changelog] [xen-unstable] blktap: portability cleanup



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1216026189 -3600
# Node ID b01303f598720dfe372bd26cd316ea45662cfaac
# Parent  f5d23ee2134ec7f14d59a327b86268f046ad802e
blktap: portability cleanup
Signed-off-by: Christoph Egger <Christoph.Egger@xxxxxxx>
---
 tools/blktap/drivers/Makefile           |    7 +
 tools/blktap/drivers/blktapctrl.c       |  113 ++++++++------------------------
 tools/blktap/drivers/blktapctrl.h       |   23 ------
 tools/blktap/drivers/blktapctrl_linux.c |  109 ++++++++++++++++++++++++++++++
 4 files changed, 146 insertions(+), 106 deletions(-)

diff -r f5d23ee2134e -r b01303f59872 tools/blktap/drivers/Makefile
--- a/tools/blktap/drivers/Makefile     Mon Jul 14 10:00:47 2008 +0100
+++ b/tools/blktap/drivers/Makefile     Mon Jul 14 10:03:09 2008 +0100
@@ -36,11 +36,14 @@ BLK-OBJS-y  += block-qcow2.o
 BLK-OBJS-y  += block-qcow2.o
 BLK-OBJS-y  += aes.o
 BLK-OBJS-y  += tapaio.o
-BLK-OBJS-$(CONFIG_Linux) += blk_linux.c
+BLK-OBJS-$(CONFIG_Linux) += blk_linux.o
+
+BLKTAB-OBJS-y := blktapctrl.o
+BLKTAB-OBJS-$(CONFIG_Linux) += blktapctrl_linux.o
 
 all: $(IBIN) qcow-util
 
-blktapctrl: blktapctrl.o
+blktapctrl: $(BLKTAB-OBJS-y)
        $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDFLAGS_blktapctrl)
 
 tapdisk: tapdisk.o $(BLK-OBJS-y)
diff -r f5d23ee2134e -r b01303f59872 tools/blktap/drivers/blktapctrl.c
--- a/tools/blktap/drivers/blktapctrl.c Mon Jul 14 10:00:47 2008 +0100
+++ b/tools/blktap/drivers/blktapctrl.c Mon Jul 14 10:03:09 2008 +0100
@@ -37,7 +37,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/mman.h>
-#include <sys/stat.h>
 #include <err.h>
 #include <errno.h>
 #include <sys/types.h>
@@ -77,6 +76,32 @@ static int read_msg(int fd, int msgtype,
 static int read_msg(int fd, int msgtype, void *ptr);
 static driver_list_entry_t *active_disks[MAX_DISK_TYPES];
 
+
+static unsigned long long tapdisk_get_size(blkif_t *blkif)
+{
+       image_t *img = (image_t *)blkif->prv;
+       return img->size;
+}
+
+static unsigned long tapdisk_get_secsize(blkif_t *blkif)
+{
+       image_t *img = (image_t *)blkif->prv;
+       return img->secsize;
+}
+
+static unsigned int tapdisk_get_info(blkif_t *blkif)
+{
+       image_t *img = (image_t *)blkif->prv;
+       return img->info;
+}
+
+struct blkif_ops tapdisk_ops = {
+       .get_size = tapdisk_get_size,
+       .get_secsize = tapdisk_get_secsize,
+       .get_info = tapdisk_get_info,
+};
+
+
 static void init_driver_list(void)
 {
        int i;
@@ -95,74 +120,6 @@ static void init_rng(void)
        seed = tv.tv_usec;
        srand48(seed);
        return;
-}
-
-static void make_blktap_dev(char *devname, int major, int minor)
-{
-       struct stat st;
-       
-       if (lstat(devname, &st) != 0) {
-               /*Need to create device*/
-               if (mkdir(BLKTAP_DEV_DIR, 0755) == 0)
-                       DPRINTF("Created %s directory\n",BLKTAP_DEV_DIR);
-               if (mknod(devname, S_IFCHR|0600,
-                       makedev(major, minor)) == 0)
-                       DPRINTF("Created %s device\n",devname);
-       } else {
-               DPRINTF("%s device already exists\n",devname);
-               /* it already exists, but is it the same major number */
-               if (((st.st_rdev>>8) & 0xff) != major) {
-                       DPRINTF("%s has old major %d\n",
-                               devname,
-                               (unsigned int)((st.st_rdev >> 8) & 0xff));
-                       /* only try again if we succed in deleting it */
-                       if (!unlink(devname))
-                               make_blktap_dev(devname, major, minor);
-               }
-       }
-}
-
-static int get_new_dev(int *major, int *minor, blkif_t *blkif)
-{
-       domid_translate_t tr;
-       domid_translate_ext_t tr_ext;
-       int ret;
-       char *devname;
-       
-       if (blkif->be_id >= (1<<28)) {
-               /* new-style backend-id, so use the extended structure */
-               tr_ext.domid = blkif->domid;
-               tr_ext.busid = blkif->be_id;
-               ret = ioctl(ctlfd, BLKTAP_IOCTL_NEWINTF_EXT, &tr_ext);
-               DPRINTF("Sent domid %d and be_id %d\n", tr_ext.domid,
-                       tr_ext.busid);
-       }
-       else {
-               /* old-style backend-id; use the old structure */
-               tr.domid = blkif->domid;
-               tr.busid = (unsigned short)blkif->be_id;
-               ret = ioctl(ctlfd, BLKTAP_IOCTL_NEWINTF, tr);
-               DPRINTF("Sent domid %d and be_id %d\n", tr.domid, tr.busid);
-       }
-       
-       if ( (ret <= 0)||(ret > MAX_TAP_DEV) ) {
-               DPRINTF("Incorrect Dev ID [%d]\n",ret);
-               return -1;
-       }
-       
-       *minor = ret;
-       *major = ioctl(ctlfd, BLKTAP_IOCTL_MAJOR, ret );
-       if (*major < 0) {
-               DPRINTF("Incorrect Major ID [%d]\n",*major);
-               return -1;
-       }
-
-       if (asprintf(&devname,"%s/%s%d",BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, 
*minor) == -1)
-               return -1;
-       make_blktap_dev(devname,*major,*minor); 
-       DPRINTF("Received device id %d and major %d\n",
-               *minor, *major);
-       return 0;
 }
 
 static int get_tapdisk_pid(blkif_t *blkif)
@@ -651,7 +608,7 @@ static int blktapctrl_new_blkif(blkif_t 
 
        DPRINTF("Received a poll for a new vbd\n");
        if ( ((blk=blkif->info) != NULL) && (blk->params != NULL) ) {
-               if (get_new_dev(&major, &minor, blkif)<0)
+               if (blktap_interface_create(ctlfd, &major, &minor, blkif) < 0)
                        return -1;
 
                if (test_path(blk->params, &ptr, &type, &exist) != 0) {
@@ -843,21 +800,11 @@ int main(int argc, char *argv[])
        register_new_devmap_hook(map_new_blktapctrl);
        register_new_unmap_hook(unmap_blktapctrl);
 
-       /* Attach to blktap0 */
-       if (asprintf(&devname,"%s/%s0", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME) == -1)
-                goto open_failed;
-       if ((ret = xc_find_device_number("blktap0")) < 0) {
-               DPRINTF("couldn't find device number for 'blktap0'\n");
+       ctlfd = blktap_interface_open();
+       if (ctlfd < 0) {
+               DPRINTF("couldn't open blktap interface\n");
                goto open_failed;
        }
-       blktap_major = major(ret);
-       make_blktap_dev(devname,blktap_major,0);
-       ctlfd = open(devname, O_RDWR);
-       if (ctlfd == -1) {
-               DPRINTF("blktap0 open failed\n");
-               goto open_failed;
-       }
-
 
  retry:
        /* Set up store connection and watch. */
diff -r f5d23ee2134e -r b01303f59872 tools/blktap/drivers/blktapctrl.h
--- a/tools/blktap/drivers/blktapctrl.h Mon Jul 14 10:00:47 2008 +0100
+++ b/tools/blktap/drivers/blktapctrl.h Mon Jul 14 10:03:09 2008 +0100
@@ -30,26 +30,7 @@
  */
 
 
-static inline unsigned long long tapdisk_get_size(blkif_t *blkif)
-{
-       image_t *img = (image_t *)blkif->prv;
-       return img->size;
-}
+int blktap_interface_open(void);
 
-static inline unsigned long tapdisk_get_secsize(blkif_t *blkif)
-{
-       image_t *img = (image_t *)blkif->prv;
-       return img->secsize;
-}
+int blktap_interface_create(int ctlfd, int *major, int *minor, blkif_t *blkif);
 
-static inline unsigned int tapdisk_get_info(blkif_t *blkif)
-{
-       image_t *img = (image_t *)blkif->prv;
-       return img->info;
-}
-
-struct blkif_ops tapdisk_ops = {
-       .get_size = tapdisk_get_size,
-       .get_secsize = tapdisk_get_secsize,
-       .get_info = tapdisk_get_info,
-};
diff -r f5d23ee2134e -r b01303f59872 tools/blktap/drivers/blktapctrl_linux.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap/drivers/blktapctrl_linux.c   Mon Jul 14 10:03:09 2008 +0100
@@ -0,0 +1,109 @@
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+
+#include "tapdisk.h"
+#include "blktaplib.h"
+#include "blktapctrl.h"
+
+static void make_blktap_dev(char *devname, int major, int minor)
+{
+       struct stat st;
+ 
+       if (lstat(devname, &st) != 0) {
+               /*Need to create device*/
+               if (mkdir(BLKTAP_DEV_DIR, 0755) == 0)
+                       DPRINTF("Created %s directory\n",BLKTAP_DEV_DIR);
+               if (mknod(devname, S_IFCHR|0600,
+                       makedev(major, minor)) == 0)
+                       DPRINTF("Created %s device\n",devname);
+       } else {
+               DPRINTF("%s device already exists\n",devname); 
+               /* it already exists, but is it the same major number */
+               if (((st.st_rdev>>8) & 0xff) != major) {
+                       DPRINTF("%s has old major %d\n",
+                               devname,
+                               (unsigned int)((st.st_rdev >> 8) & 0xff));
+                       /* only try again if we succed in deleting it */
+                       if (!unlink(devname))
+                               make_blktap_dev(devname, major, minor);
+               }
+       }
+}
+
+int blktap_interface_create(int ctlfd, int *major, int *minor, blkif_t *blkif)
+{       
+        domid_translate_t tr;
+        domid_translate_ext_t tr_ext;
+        int ret; 
+        char *devname;
+
+        if (blkif->be_id >= (1<<28)) {
+                /* new-style backend-id, so use the extended structure */
+                tr_ext.domid = blkif->domid;
+                tr_ext.busid = blkif->be_id;
+                ret = ioctl(ctlfd, BLKTAP_IOCTL_NEWINTF_EXT, &tr_ext);
+                DPRINTF("Sent domid %d and be_id %d\n", tr_ext.domid,
+                        tr_ext.busid);
+        }
+        else {
+                /* old-style backend-id; use the old structure */
+                tr.domid = blkif->domid;
+                tr.busid = (unsigned short)blkif->be_id;
+                ret = ioctl(ctlfd, BLKTAP_IOCTL_NEWINTF, tr);
+                DPRINTF("Sent domid %d and be_id %d\n", tr.domid, tr.busid);
+        }
+
+        if ( (ret <= 0)||(ret > MAX_TAP_DEV) ) {
+                DPRINTF("Incorrect Dev ID [%d]\n",ret);
+                return -1;
+        }
+
+        *minor = ret;
+        *major = ioctl(ctlfd, BLKTAP_IOCTL_MAJOR, ret );
+        if (*major < 0) {
+                DPRINTF("Incorrect Major ID [%d]\n",*major);
+                return -1;
+        }
+
+        if (asprintf(&devname,"%s/%s%d",BLKTAP_DEV_DIR, BLKTAP_DEV_NAME, 
*minor) == -1)
+                return -1;
+        make_blktap_dev(devname,*major,*minor);
+        DPRINTF("Received device id %d and major %d\n",
+                *minor, *major);
+        return 0;
+}
+
+
+int blktap_interface_open(void)
+{
+       char *devname;
+       int ret;
+       int ctlfd;
+
+       /* Attach to blktap0 */
+       if (asprintf(&devname,"%s/%s0", BLKTAP_DEV_DIR, BLKTAP_DEV_NAME) == -1)
+               goto open_failed;
+
+       ret = xc_find_device_number("blktap0");
+       if (ret < 0) {
+               DPRINTF("couldn't find device number for 'blktap0'\n");
+               goto open_failed;
+       }
+
+       blktap_major = major(ret);
+       make_blktap_dev(devname,blktap_major, 0);
+
+       ctlfd = open(devname, O_RDWR);
+       if (ctlfd == -1) {
+               DPRINTF("blktap0 open failed\n");
+               goto open_failed;
+       }
+
+       return ctlfd;
+
+open_failed:
+       return -1;
+}

_______________________________________________
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®.