]> xenbits.xensource.com Git - people/dstodden/blktap.git/commitdiff
blktap: Fix tapdisk disktype issues.
authorDaniel Stodden <daniel.stodden@citrix.com>
Sat, 5 Jun 2010 02:05:01 +0000 (19:05 -0700)
committerDaniel Stodden <daniel.stodden@citrix.com>
Sat, 5 Jun 2010 02:05:01 +0000 (19:05 -0700)
Stop coercing drivers/disktype code into the tool stack. Make both
blktapctrl and tap-ctl transfer type/path pairs as "<type>:<path>"
strings. Remove the message.disktype integer altogether.

25 files changed:
control/tap-ctl-create.c
control/tap-ctl-list.c
control/tap-ctl-open.c
control/tap-ctl-unpause.c
control/tap-ctl.c
control/tap-ctl.h
daemon/tapdisk-channel.c
daemon/tapdisk-daemon.c
daemon/tapdisk-dispatch.h
drivers/Makefile
drivers/block-vhd.c
drivers/disktypes.h [deleted file]
drivers/tapdisk-control.c
drivers/tapdisk-diff.c
drivers/tapdisk-disktype.c [new file with mode: 0644]
drivers/tapdisk-disktype.h [new file with mode: 0644]
drivers/tapdisk-driver.c
drivers/tapdisk-driver.h
drivers/tapdisk-ipc.c
drivers/tapdisk-server.c
drivers/tapdisk-stream.c
drivers/tapdisk-utils.c
drivers/tapdisk-vbd.c
drivers/tapdisk-vbd.h
include/tapdisk-message.h

index ca3bcfa1058794f41c30ba5728359800583f42ef..9d2e5d7414807d75278f895bfb1e52f9a00c7213 100644 (file)
 static void
 usage(void)
 {
-       printf("usage: create <-t type> <-f file> [-d device name]\n");
+       printf("usage: create <-a args> [-d device name]\n");
 }
 
 int
-_tap_ctl_create(const int type, const char *file, char **devname)
+_tap_ctl_create(const char *params, char **devname)
 {
        int err, id;
 
@@ -57,7 +57,7 @@ _tap_ctl_create(const int type, const char *file, char **devname)
        if (err)
                goto destroy;
 
-       err = tap_ctl_open(id, id, type, file);
+       err = tap_ctl_open(id, id, params);
        if (err)
                goto detach;
 
@@ -74,20 +74,16 @@ int
 tap_ctl_create(int argc, char **argv)
 {
        int c, err, type;
-       char *file, *devname;
+       char *args, *devname;
 
-       type    = -1;
-       file    = NULL;
+       args    = NULL;
        devname = NULL;
 
        optind = 0;
-       while ((c = getopt(argc, argv, "t:f:d:h")) != -1) {
+       while ((c = getopt(argc, argv, "a:d:h")) != -1) {
                switch (c) {
-               case 't':
-                       type = atoi(optarg);
-                       break;
-               case 'f':
-                       file = optarg;
+               case 'a':
+                       args = optarg;
                        break;
                case 'd':
                        devname = optarg;
@@ -98,12 +94,12 @@ tap_ctl_create(int argc, char **argv)
                }
        }
 
-       if (!file || type == -1) {
+       if (!args) {
                usage();
                return EINVAL;
        }
 
-       err = _tap_ctl_create(type, file, &devname);
+       err = _tap_ctl_create(args, &devname);
        if (!err)
                printf("%s\n", devname);
 
index 451544b311c493d40ea45e0a718d9156e0f63975..6f65b680833615bfad2ab99e826e2b0b114cee76 100644 (file)
 #include "tap-ctl.h"
 #include "blktap2.h"
 #include "list.h"
-#include "disktypes.h"
+#include "tapdisk-disktype.h"
 
 static void
 free_list(tap_list_t *entry)
 {
+       if (entry->type) {
+               free(entry->type);
+               entry->type = NULL;
+       }
+
        if (entry->path) {
                free(entry->path);
                entry->path = NULL;
@@ -49,46 +54,50 @@ free_list(tap_list_t *entry)
        free(entry);
 }
 
-static int
-init_list(tap_list_t *entry,
-         int tap_id, pid_t tap_pid, int vbd_minor, int vbd_state,
-         const char *driver, const char *vdi_path)
+int
+_parse_params(const char *params, char **type, char **path)
 {
+       char *ptr;
+       size_t len;
 
-       entry->id     = tap_id;
-       entry->pid    = tap_pid;
-       entry->minor  = vbd_minor;
-       entry->state  = vbd_state;
-       entry->driver = driver;
-       entry->path   = vdi_path ? strdup(vdi_path) : NULL;
+       ptr = strchr(params, ':');
+       if (!ptr)
+               return -EINVAL;
+
+       len = ptr - params;
+
+       *type = strndup(params, len);
+       *path =  strdup(params + len + 1);
 
-       if (vdi_path && !entry->path)
-               return -ENOMEM;
+       if (!*type || !*path) {
+               free(*type);
+               *type = NULL;
+
+               free(*path);
+               *path = NULL;
+
+               return -errno;
+       }
 
        return 0;
 }
 
-static tap_list_t *
-alloc_list(int tap_id, pid_t tap_pid, int vbd_minor, int vbd_state, const char *vdi_driver, const char *vdi_path)
+static int
+init_list(tap_list_t *entry,
+         int tap_id, pid_t tap_pid, int vbd_minor, int vbd_state,
+         const char *params)
 {
-       tap_list_t *entry;
-       int err;
+       int err = 0;
 
-       entry = malloc(sizeof(tap_list_t));
-       if (!entry)
-               goto fail;
-
-       err = init_list(entry, tap_id, tap_pid, vbd_minor, vbd_state, vdi_driver, vdi_path);
-       if (err)
-               goto fail;
-
-       return entry;
+       entry->id     = tap_id;
+       entry->pid    = tap_pid;
+       entry->minor  = vbd_minor;
+       entry->state  = vbd_state;
 
-fail:
-       if (entry)
-               free_list(entry);
+       if (params)
+               err = _parse_params(params, &entry->type, &entry->path);
 
-       return NULL;
+       return err;
 }
 
 void
@@ -302,36 +311,10 @@ fail:
 struct tapdisk_list {
        int  minor;
        int  state;
-       const char *driver;
-       char *path;
+       char *params;
        struct list_head entry;
 };
 
-static int
-_tap_ctl_get_driver_handle(int id, const char **_handle)
-{
-       disk_info_t *info;
-       int n_drivers, i;
-
-       n_drivers = sizeof(dtypes) / sizeof(dtypes[0]);
-
-       for (i = 0; i < n_drivers; ++i) {
-               info = dtypes[i];
-               if (info->idnum == id)
-                       break;
-       }
-
-       if (i == n_drivers)
-               return -ENOENT;
-
-       if (info->idnum < 0)
-               return -EINVAL;
-
-       *_handle = info->handle;
-
-       return 0;
-}
-
 int
 _tap_ctl_list_tapdisk(int id, struct list_head *_list)
 {
@@ -371,28 +354,23 @@ _tap_ctl_list_tapdisk(int id, struct list_head *_list)
 
                tl->minor  = message.u.list.minor;
                tl->state  = message.u.list.state;
-               tl->path   = NULL;
-               tl->driver = NULL;
                if (message.u.list.path[0] != 0) {
-                       tl->path = strndup(message.u.list.path,
-                                          sizeof(message.u.list.path));
-                       if (!tl->path) {
+                       tl->params = strndup(message.u.list.path,
+                                            sizeof(message.u.list.path));
+                       if (!tl->params) {
                                err = -errno;
                                break;
                        }
+               } else
+                       tl->params = NULL;
 
-                       err = _tap_ctl_get_driver_handle(message.drivertype,
-                                                        &tl->driver);
-                       if (err)
-                               break;
-               }
                list_add(&tl->entry, &list);
        } while (1);
 
        if (err)
                list_for_each_entry_safe(tl, next, &list, entry) {
                        list_del(&tl->entry);
-                       free(tl->path);
+                       free(tl->params);
                        free(tl);
                }
 
@@ -409,8 +387,10 @@ _tap_ctl_free_tapdisks(struct tapdisk *tapv, int n_taps)
        for (tap = tapv; tap < &tapv[n_taps]; ++tap) {
                struct tapdisk_list *tl;
 
-               list_for_each_entry(tl, &tap->list, entry)
+               list_for_each_entry(tl, &tap->list, entry) {
+                       free(tl->params);
                        free(tl);
+               }
        }
 
        free(tapv);
@@ -437,7 +417,7 @@ _tap_list_join3(int n_minors, int *minorv, int n_taps, struct tapdisk *tapv,
 
                /* orphaned tapdisk */
                if (list_empty(&tap->list)) {
-                       err = init_list(*_entry++, tap->id, tap->pid, -1, -1, NULL, NULL);
+                       err = init_list(*_entry++, tap->id, tap->pid, -1, -1, NULL);
                        if (err)
                                goto fail;
                        continue;
@@ -447,7 +427,7 @@ _tap_list_join3(int n_minors, int *minorv, int n_taps, struct tapdisk *tapv,
 
                        err = init_list(*_entry++,
                                        tap->id, tap->pid,
-                                       tl->minor, tl->state, tl->driver, tl->path);
+                                       tl->minor, tl->state, tl->params);
                        if (err)
                                goto fail;
 
@@ -467,7 +447,7 @@ _tap_list_join3(int n_minors, int *minorv, int n_taps, struct tapdisk *tapv,
        for (_m = 0; _m < n_minors; ++_m) {
                int minor = minorv[_m];
                if (minor >= 0) {
-                       err = init_list(*_entry++, -1, -1, minor, -1, NULL, NULL);
+                       err = init_list(*_entry++, -1, -1, minor, -1, NULL);
                        if (err)
                                goto fail;
                }
index e139f2971cde308fd64316fce14a9dd5435b2215..e54e02b7faf31fd136d78cbaa58120a2c8106a89 100644 (file)
 
 #include "tap-ctl.h"
 #include "blktaplib.h"
-#include "disktypes.h"
 
 int
-tap_ctl_open(const int id, const int minor, const int type, const char *file)
+tap_ctl_open(const int id, const int minor, const char *args)
 {
        int err;
        tapdisk_message_t message;
@@ -45,12 +44,11 @@ tap_ctl_open(const int id, const int minor, const int type, const char *file)
        memset(&message, 0, sizeof(message));
        message.type = TAPDISK_MESSAGE_OPEN;
        message.cookie = minor;
-       message.drivertype = type;
        message.u.params.storage = TAPDISK_STORAGE_TYPE_DEFAULT;
        message.u.params.devnum = minor;
 
        err = snprintf(message.u.params.path,
-                      sizeof(message.u.params.path) - 1, "%s", file);
+                      sizeof(message.u.params.path) - 1, "%s", args);
        if (err >= sizeof(message.u.params.path)) {
                printf("name too long\n");
                return ENAMETOOLONG;
@@ -75,26 +73,3 @@ tap_ctl_open(const int id, const int minor, const int type, const char *file)
 
        return err;
 }
-
-int
-tap_ctl_get_driver_id(const char *handle)
-{
-       disk_info_t *info;
-       int n_drivers, i;
-
-       n_drivers = sizeof(dtypes) / sizeof(dtypes[0]);
-
-       for (i = 0; i < n_drivers; ++i) {
-               info = dtypes[i];
-               if (!strncmp(handle, info->handle, sizeof(info->handle)))
-                       break;
-       }
-
-       if (i == n_drivers)
-               return -ENOENT;
-
-       if (info->idnum < 0)
-               return -EINVAL;
-
-       return info->idnum;
-}
index 08d9364a3aefbd5010e63107a4f6d45a01eb5c55..4a922f271e45eb8f5195d78d6c3ce8998bfa4939 100644 (file)
@@ -35,7 +35,7 @@
 #include "tap-ctl.h"
 
 int
-tap_ctl_unpause(const int id, const int minor, const int type, const char *file)
+tap_ctl_unpause(const int id, const int minor, const char *params)
 {
        int err;
        tapdisk_message_t message;
@@ -43,16 +43,10 @@ tap_ctl_unpause(const int id, const int minor, const int type, const char *file)
        memset(&message, 0, sizeof(message));
        message.type = TAPDISK_MESSAGE_RESUME;
        message.cookie = minor;
-       message.drivertype = type;
 
-       if (file) {
-               if (snprintf(message.u.params.path,
-                            sizeof(message.u.params.path) - 1, "%s", file) >=
-                   sizeof(message.u.params.path) - 1) {
-                       printf("invalid name\n");
-                       return ENAMETOOLONG;
-               }
-       }
+       if (params)
+               strncpy(message.u.params.path, params,
+                       sizeof(message.u.params.path) - 1);
 
        err = tap_ctl_connect_send_and_receive(id, &message, 15);
        if (err)
index 019635a4b750eae82802654ea9472c2a61102e57..a4a734028e0062afe774b8ffc0182d0158214f56 100644 (file)
@@ -40,18 +40,6 @@ struct command {
        tap_ctl_func_t            func;
 };
 
-static int
-tap_cli_get_driver_id(const char *handle)
-{
-       int type;
-
-       type = tap_ctl_get_driver_id(handle);
-       if (type < 0)
-               fprintf(stderr, "No such driver '%s': %d\n", handle, type);
-
-       return type;
-}
-
 static void
 tap_cli_list_usage(FILE *stream)
 {
@@ -63,8 +51,8 @@ int
 tap_cli_list(int argc, char **argv)
 {
        tap_list_t **list, **_entry;
-       int c, id, minor, type, err;
-       const char *driver, *file;
+       int c, id, minor, err;
+       const char *type, *file;
        pid_t pid;
 
        err = tap_ctl_list(&list);
@@ -74,8 +62,7 @@ tap_cli_list(int argc, char **argv)
        id     = -1;
        minor  = -1;
        pid    = -1;
-       type   = -1;
-       driver = NULL;
+       type   = NULL;
        file   = NULL;
 
        while ((c = getopt(argc, argv, "m:i:p:t:f:h")) != -1) {
@@ -90,10 +77,7 @@ tap_cli_list(int argc, char **argv)
                        pid = atoi(optarg);
                        break;
                case 't':
-                       driver = optarg;
-                       type = tap_cli_get_driver_id(driver);
-                       if (type < 0)
-                               return -type;
+                       type = optarg;
                        break;
                case 'f':
                        file = optarg;
@@ -120,7 +104,7 @@ tap_cli_list(int argc, char **argv)
                if (pid >= 0 && entry->pid != pid)
                        continue;
 
-               if (driver && entry->driver && strcmp(entry->driver, driver))
+               if (type && entry->type && strcmp(entry->type, type))
                        continue;
 
                if (file && entry->path && strcmp(entry->path, file))
@@ -140,7 +124,7 @@ tap_cli_list(int argc, char **argv)
 
                printf("%-3s %2s %8s %4s %10s %s\n",
                       minor_str, id_str, pid_str, state_str,
-                      entry->driver ? : "-", entry->path ? : "-");
+                      entry->type ? : "-", entry->path ? : "-");
        }
 
        tap_ctl_free_list(list);
@@ -192,22 +176,21 @@ tap_cli_pause(int argc, char **argv)
 static void
 tap_cli_unpause_usage(FILE *stream)
 {
-       fprintf(stream, "usage: unpause <-i id> <-m minor> <-t type> <-f file>\n");
+       fprintf(stream, "usage: unpause <-p pid> <-m minor> [-a args]\n");
 }
 
 int
 tap_cli_unpause(int argc, char **argv)
 {
-       char *file;
+       char *args;
        int c, id, minor, type;
 
        id    = -1;
        minor = -1;
-       type  = -1;
-       file  = NULL;
+       args  = NULL;
 
        optind = 0;
-       while ((c = getopt(argc, argv, "i:m:t:f:h")) != -1) {
+       while ((c = getopt(argc, argv, "i:m:a:h")) != -1) {
                switch (c) {
                case 'i':
                        id = atoi(optarg);
@@ -215,11 +198,8 @@ tap_cli_unpause(int argc, char **argv)
                case 'm':
                        minor = atoi(optarg);
                        break;
-               case 't':
-                       type = atoi(optarg);
-                       break;
-               case 'f':
-                       file = optarg;
+               case 'a':
+                       args = optarg;
                        break;
                case 'h':
                        tap_cli_unpause_usage(stdout);
@@ -227,12 +207,14 @@ tap_cli_unpause(int argc, char **argv)
                }
        }
 
-       if (id == -1 || minor == -1) {
-               tap_cli_unpause_usage(stderr);
-               return EINVAL;
-       }
+       if (id == -1 || minor == -1)
+               goto usage;
 
-       return tap_ctl_unpause(id, minor, type, file);
+       return tap_ctl_unpause(id, minor, args);
+
+usage:
+       tap_cli_unpause_usage(stderr);
+       return EINVAL;
 }
 
 static void
@@ -284,22 +266,21 @@ usage:
 static void
 tap_cli_open_usage(FILE *stream)
 {
-       fprintf(stream, "usage: open <-t type> <-f file> <-i id> <-m minor>\n");
+       fprintf(stream, "usage: open <-i id> <-m minor> <-a args>\n");
 }
 
 static int
 tap_cli_open(int argc, char **argv)
 {
-       const char *file;
-       int c, id, minor, type;
+       const char *args;
+       int c, id, minor;
 
        id    = -1;
-       type  = -1;
        minor = -1;
-       file  = NULL;
+       args  = NULL;
 
        optind = 0;
-       while ((c = getopt(argc, argv, "i:m:t:f:h")) != -1) {
+       while ((c = getopt(argc, argv, "i:m:a:h")) != -1) {
                switch (c) {
                case 'i':
                        id = atoi(optarg);
@@ -307,13 +288,8 @@ tap_cli_open(int argc, char **argv)
                case 'm':
                        minor = atoi(optarg);
                        break;
-               case 't':
-                       type = tap_cli_get_driver_id(optarg);
-                       if (type < 0)
-                               return -type;
-                       break;
-               case 'f':
-                       file = optarg;
+               case 'a':
+                       args = optarg;
                        break;
                case 'h':
                        tap_cli_open_usage(stdout);
@@ -321,10 +297,10 @@ tap_cli_open(int argc, char **argv)
                }
        }
 
-       if (id == -1 || minor == -1 || type == -1 || !file)
+       if (id == -1 || minor == -1 || !args)
                goto usage;
 
-       return tap_ctl_open(id, minor, type, file);
+       return tap_ctl_open(id, minor, args);
 
 usage:
        tap_cli_open_usage(stderr);
index dc0f594268fd88736cbac094c4c58a0070bbb473..dfb08f098aad3af1f69ef10d9fbf39e16a730f42 100644 (file)
@@ -57,7 +57,7 @@ typedef struct {
        pid_t       pid;
        int         minor;
        int         state;
-       const char *driver;
+       char       *type;
        char       *path;
 } tap_list_t;
 
@@ -73,7 +73,7 @@ int tap_ctl_free(int argc, char **argv);
 int _tap_ctl_free(const int minor);
 
 int tap_ctl_create(int argc, char **argv);
-int _tap_ctl_create(const int type, const char *name, char **devname);
+int _tap_ctl_create(const char *params, char **devname);
 
 int tap_ctl_destroy(int argc, char **argv);
 int _tap_ctl_destroy(const int id, const int minor);
@@ -88,14 +88,14 @@ int _tap_ctl_attach(const int id, const int minor);
 int tap_ctl_detach(int argc, char **argv);
 int _tap_ctl_detach(const int id, const int minor);
 
-int tap_ctl_open(const int id, const int minor, const int type, const char *file);
+int tap_ctl_open(const int id, const int minor, const char *params);
 
 int tap_ctl_close(int argc, char **argv);
 int _tap_ctl_close(const int id, const int minor, const int force);
 
 int tap_ctl_pause(const int id, const int minor);
 
-int tap_ctl_unpause(const int id, const int minor, const int type, const char *file);
+int tap_ctl_unpause(const int id, const int minor, const char *args);
 
 int tap_ctl_blk_major(void);
 
index 4b4a013275a78935e320602a22dce0036da8ae9e..14426c02132a7a65a6474441411df3ffe4729abc 100644 (file)
@@ -37,7 +37,6 @@
 #include <sys/resource.h>
 
 #include <xs.h>
-#include "disktypes.h"
 #include "tapdisk-dispatch.h"
 
 static inline const char*
@@ -524,16 +523,13 @@ tapdisk_channel_send_open_request(tapdisk_channel_t *channel)
 
        memset(&message, 0, sizeof(tapdisk_message_t));
 
-       len = strlen(channel->vdi_path);
-
        message.type              = TAPDISK_MESSAGE_OPEN;
        message.cookie            = channel->cookie;
-       message.drivertype        = channel->drivertype;
        message.u.params.storage  = channel->storage;
        message.u.params.devnum   = channel->minor;
        message.u.params.domid    = channel->domid;
-       message.u.params.path_len = len;
-       strncpy(message.u.params.path, channel->vdi_path, len);
+       snprintf(message.u.params.path, sizeof(message.u.params.path),
+                "%s:%s", channel->vdi_type, channel->vdi_path);
 
        if (channel->mode == 'r')
                message.u.params.flags |= TAPDISK_MESSAGE_FLAG_RDONLY;
@@ -581,7 +577,6 @@ tapdisk_channel_send_shutdown_request(tapdisk_channel_t *channel)
        memset(&message, 0, sizeof(tapdisk_message_t));
 
        message.type       = TAPDISK_MESSAGE_CLOSE;
-       message.drivertype = channel->drivertype;
        message.cookie     = channel->cookie;
 
        return tapdisk_channel_send_message(channel, &message, 2);
@@ -595,9 +590,8 @@ tapdisk_channel_send_force_shutdown_request(tapdisk_channel_t *channel)
        memset(&message, 0, sizeof(tapdisk_message_t));
 
        message.type       = TAPDISK_MESSAGE_FORCE_SHUTDOWN;
-       message.drivertype = channel->drivertype;
        message.cookie     = channel->cookie;
-       
+
        return tapdisk_channel_send_message(channel, &message, 2);
 }
 
@@ -629,7 +623,6 @@ tapdisk_channel_send_pid_request(tapdisk_channel_t *channel)
        memset(&message, 0, sizeof(tapdisk_message_t));
 
        message.type       = TAPDISK_MESSAGE_PID;
-       message.drivertype = channel->drivertype;
        message.cookie     = channel->cookie;
 
        err = tapdisk_channel_send_message(channel, &message, 2);
@@ -667,7 +660,6 @@ tapdisk_channel_send_pause_request(tapdisk_channel_t *channel)
        DPRINTF("pausing %s\n", channel->path);
 
        message.type       = TAPDISK_MESSAGE_PAUSE;
-       message.drivertype = channel->drivertype;
        message.cookie     = channel->cookie;
 
        return tapdisk_channel_send_message(channel, &message, 2);
@@ -796,10 +788,9 @@ tapdisk_channel_send_resume_request(tapdisk_channel_t *channel)
        DPRINTF("resuming %s\n", channel->path);
 
        message.type              = TAPDISK_MESSAGE_RESUME;
-       message.drivertype        = channel->drivertype;
        message.cookie            = channel->cookie;
-       message.u.params.path_len = len;
-       strncpy(message.u.params.path, channel->vdi_path, len);
+       snprintf(message.u.params.path, sizeof(message.u.params.path),
+                "%s:%s", channel->vdi_type, channel->vdi_path);
 
        return tapdisk_channel_send_message(channel, &message, 2);
 }
@@ -1545,59 +1536,49 @@ out:
 static int
 tapdisk_channel_parse_params(tapdisk_channel_t *channel)
 {
-       int i, size, err;
-       unsigned int len;
-       char *ptr, *path, handle[10];
-       char *vdi_type;
-       char *vtype;
+       char *vdi_type_path;
+       char *ptr, *path;
+       size_t len;
+       int err;
 
        path = channel->params;
-       size = sizeof(dtypes) / sizeof(disk_info_t *);
-
-       if (strlen(path) + 1 >= TAPDISK_MESSAGE_MAX_PATH_LENGTH)
-               goto fail;
 
        ptr = strchr(path, ':');
        if (!ptr)
                goto fail;
 
        channel->vdi_path = ptr + 1;
-       memcpy(handle, path, (ptr - path));
-       ptr  = handle + (ptr - path);
-       *ptr = '\0';
+       channel->vdi_type = strndup(path, ptr - path);
 
-       err = asprintf(&vdi_type, "%s/sm-data/vdi-type", channel->path);
+       err = asprintf(&vdi_type_path, "%s/sm-data/vdi-type", channel->path);
        if (err == -1)
                goto fail;
 
-       if (xs_exists(channel->xsh, vdi_type)) {
-               vtype = xs_read(channel->xsh, XBT_NULL, vdi_type, &len);
-               free(vdi_type);
-               if (!vtype)
-                       goto fail;
-               if (len >= sizeof(handle) - 1) {
-                       free(vtype);
+       if (xs_exists(channel->xsh, vdi_type_path)) {
+               free(channel->vdi_type);
+
+               channel->vdi_type =
+                       xs_read(channel->xsh, XBT_NULL, vdi_type_path, &len);
+               free(vdi_type_path);
+
+               if (!channel->vdi_type)
                        goto fail;
-               }
-               sprintf(handle, "%s", vtype);
-               free(vtype);
        }
 
-       for (i = 0; i < size; i++) {
-               if (strncmp(handle, dtypes[i]->handle, (ptr - path)))
-                       continue;
+       len  = strlen(channel->vdi_type);
+       len += strlen(":");
+       len += strlen(channel->vdi_path);
 
-               if (dtypes[i]->idnum == -1)
-                       goto fail;
+       if (len + 1 >= TAPDISK_MESSAGE_MAX_PATH_LENGTH)
+               goto fail;
 
-               channel->drivertype = dtypes[i]->idnum;
-               return 0;
-       }
+       return 0;
 
 fail:
        EPRINTF("%s: invalid blktap params: %s\n",
                channel->path, channel->params);
        channel->vdi_path = NULL;
+       channel->vdi_type = NULL;
        return -EINVAL;
 }
 
index 4090596dd9f9c98188ad6d0a9085b04a0e7c96d7..3dc5619f3b2655b657a8f02c260c04bada0fc311 100644 (file)
@@ -39,7 +39,6 @@
 #include <syslog.h>
 
 #include <xs.h>
-#include "disktypes.h"
 #include "tapdisk-dispatch.h"
 
 #define TAPDISK_DAEMON_DOMID_WATCH   "domid-watch"
@@ -73,10 +72,6 @@ tapdisk_daemon_print_drivers(void)
 
        DPRINTF("blktap-daemon: v1.0.2\n");
        DPRINTF("Syslog facility %d\n", tapdisk_daemon_log_facility);
-
-       size = sizeof(dtypes) / sizeof(disk_info_t *);
-       for (i = 0; i < size; i++)
-               DPRINTF("Found driver: [%s]\n", dtypes[i]->name);
 }
 
 static int
@@ -680,7 +675,7 @@ tapdisk_daemon_maybe_clone_channel(tapdisk_channel_t *channel)
 
        /* check if we already have a process started */
        tapdisk_daemon_for_each_channel(c, tmp)
-               if (c->drivertype == channel->drivertype) {
+               if (!strcmp(c->vdi_type, channel->vdi_type)) {
                        channel->write_fd    = c->write_fd;
                        channel->read_fd     = c->read_fd;
                        channel->channel_id  = c->channel_id;
index c91f52848552d9bcaa32885cb4886ac375412e43..efe134efb5d83127556c13c6ce326e77b4c46f0c 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/select.h>
 
 #include "xs_api.h"
+#define TAPDISK
 #include "blktaplib.h"
 #include "tapdisk-message.h"
 
@@ -104,6 +105,7 @@ struct tapdisk_channel {
        char                     *path;
        char                     *frontpath;
        char                     *params;
+       char                     *vdi_type;
        char                     *vdi_path;
        char                     *uuid_str;
        char                     *start_str;
index 63d7553a3494b30b48e12da2b72c6dec7b7d96c1..76d7ba8b443febda2f21276dd343ed5c833d3352 100644 (file)
@@ -40,6 +40,7 @@ TAP-OBJS  += tapdisk-ipc.o
 TAP-OBJS  += tapdisk-vbd.o
 TAP-OBJS  += tapdisk-image.o
 TAP-OBJS  += tapdisk-driver.o
+TAP-OBJS  += tapdisk-disktype.o
 TAP-OBJS  += tapdisk-interface.o
 TAP-OBJS  += tapdisk-server.o
 TAP-OBJS  += tapdisk-queue.o
index 3be46200f27c8cb831ae45761a96c19b7e271c69..eeca5fac528834e9ddd6fc280dc9f30d40de0689 100644 (file)
@@ -67,7 +67,7 @@
 #include "tapdisk.h"
 #include "tapdisk-driver.h"
 #include "tapdisk-interface.h"
-#include "disktypes.h"
+#include "tapdisk-disktype.h"
 
 unsigned int SPB;
 
diff --git a/drivers/disktypes.h b/drivers/disktypes.h
deleted file mode 100644 (file)
index 829a004..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-/* 
- * Copyright (c) 2007, XenSource Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in the
- *       documentation and/or other materials provided with the distribution.
- *     * Neither the name of XenSource Inc. nor the names of its contributors
- *       may be used to endorse or promote products derived from this software
- *       without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
- * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __DISKTYPES_H__
-#define __DISKTYPES_H__
-
-typedef struct disk_info {
-       int  idnum;
-       char name[50];       /* e.g. "RAMDISK" */
-       char handle[10];     /* xend handle, e.g. 'ram' */
-       int  single_handler; /* is there a single controller for all */
-                            /* instances of disk type? */
-#ifdef TAPDISK
-       struct tap_disk *drv;
-#endif
-} disk_info_t;
-
-extern struct tap_disk tapdisk_aio;
-/* extern struct tap_disk tapdisk_sync;    */
-/* extern struct tap_disk tapdisk_vmdk;    */
-/* extern struct tap_disk tapdisk_vhdsync; */
-extern struct tap_disk tapdisk_vhd;
-extern struct tap_disk tapdisk_ram;
-/* extern struct tap_disk tapdisk_qcow;    */
-extern struct tap_disk tapdisk_block_cache;
-extern struct tap_disk tapdisk_vhd_index;
-extern struct tap_disk tapdisk_log;
-
-#define MAX_DISK_TYPES        20
-
-#define DISK_TYPE_AIO         0
-#define DISK_TYPE_SYNC        1
-#define DISK_TYPE_VMDK        2
-#define DISK_TYPE_VHDSYNC     3
-#define DISK_TYPE_VHD         4
-#define DISK_TYPE_RAM         5
-#define DISK_TYPE_QCOW        6
-#define DISK_TYPE_BLOCK_CACHE 7
-#define DISK_TYPE_VINDEX      8
-#define DISK_TYPE_LOG         9
-
-/*Define Individual Disk Parameters here */
-static disk_info_t null_disk = {
-       -1,
-       "null disk",
-       "null",
-       0,
-#ifdef TAPDISK
-       0,
-#endif
-};
-
-static disk_info_t aio_disk = {
-       DISK_TYPE_AIO,
-       "raw image (aio)",
-       "aio",
-       0,
-#ifdef TAPDISK
-       &tapdisk_aio,
-#endif
-};
-/*
-static disk_info_t sync_disk = {
-       DISK_TYPE_SYNC,
-       "raw image (sync)",
-       "sync",
-       0,
-#ifdef TAPDISK
-       &tapdisk_sync,
-#endif
-};
-
-static disk_info_t vmdk_disk = {
-       DISK_TYPE_VMDK,
-       "vmware image (vmdk)",
-       "vmdk",
-       1,
-#ifdef TAPDISK
-       &tapdisk_vmdk,
-#endif
-};
-
-static disk_info_t vhdsync_disk = {
-       DISK_TYPE_VHDSYNC,
-       "virtual server image (vhd) - synchronous",
-       "vhdsync",
-       1,
-#ifdef TAPDISK
-       &tapdisk_vhdsync,
-#endif
-};
-*/
-
-static disk_info_t vhd_disk = {
-       DISK_TYPE_VHD,
-       "virtual server image (vhd)",
-       "vhd",
-       0,
-#ifdef TAPDISK
-       &tapdisk_vhd,
-#endif
-};
-
-
-static disk_info_t ram_disk = {
-       DISK_TYPE_RAM,
-       "ramdisk image (ram)",
-       "ram",
-       1,
-#ifdef TAPDISK
-       &tapdisk_ram,
-#endif
-};
-
-
-/*
-static disk_info_t qcow_disk = {
-       DISK_TYPE_QCOW,
-       "qcow disk (qcow)",
-       "qcow",
-       0,
-#ifdef TAPDISK
-       &tapdisk_qcow,
-#endif
-};
-*/
-
-static disk_info_t block_cache_disk = {
-       DISK_TYPE_BLOCK_CACHE,
-       "block cache image (bc)",
-       "bc",
-       1,
-#ifdef TAPDISK
-       &tapdisk_block_cache,
-#endif
-};
-
-static disk_info_t vhd_index_disk = {
-       DISK_TYPE_VINDEX,
-       "vhd index image (vhdi)",
-       "vhdi",
-       1,
-#ifdef TAPDISK
-       &tapdisk_vhd_index,
-#endif
-};
-
-static disk_info_t log_disk = {
-       DISK_TYPE_LOG,
-       "write logger (log)",
-       "log",
-       0,
-#ifdef TAPDISK
-       &tapdisk_log,
-#endif
-};
-
-/*Main disk info array */
-static disk_info_t *dtypes[] = {
-       &aio_disk,
-       &null_disk, /* &sync_disk, */
-       &null_disk, /* &vmdk_disk, */
-        &null_disk, /* &vhdsync_disk, */
-       &vhd_disk,
-       &ram_disk,
-       &null_disk, /* &qcow_disk, */
-       &block_cache_disk,
-       &vhd_index_disk,
-       &log_disk,
-};
-
-#endif
index 0f441c6a00a75f00f08039c12120ea18ff6f43f2..d72dfbfeb949e6f17ca14a1fdab8db5cb4e3cc5a 100644 (file)
@@ -46,6 +46,7 @@
 #include "tapdisk-utils.h"
 #include "tapdisk-server.h"
 #include "tapdisk-message.h"
+#include "tapdisk-disktype.h"
 
 struct tapdisk_control {
        char              *path;
@@ -265,15 +266,17 @@ tapdisk_control_list(struct tapdisk_control_connection *connection,
                count++;
 
        list_for_each_entry(vbd, head, next) {
-               response.drivertype     = vbd->type;
                response.u.list.count   = count--;
                response.u.list.minor   = vbd->minor;
                response.u.list.state   = vbd->state;
                response.u.list.path[0] = 0;
 
                if (vbd->name)
-                       strncpy(response.u.list.path, vbd->name,
-                               sizeof(response.u.list.path));
+                       snprintf(response.u.list.path,
+                                sizeof(response.u.list.path),
+                                "%s:%s",
+                                tapdisk_disk_types[vbd->type]->name,
+                                vbd->name);
 
                tapdisk_control_write_message(connection->socket, &response, 2);
        }
@@ -379,6 +382,11 @@ tapdisk_control_detach_vbd(struct tapdisk_control_connection *connection,
                goto out;
        }
 
+       if (vbd->name) {
+               err = -EBUSY;
+               goto out;
+       }
+
        tapdisk_vbd_detach(vbd);
 
        if (list_empty(&vbd->images)) {
@@ -401,12 +409,13 @@ static void
 tapdisk_control_open_image(struct tapdisk_control_connection *connection,
                           tapdisk_message_t *request)
 {
-       int err;
+       int err, type;
        image_t image;
        td_vbd_t *vbd;
        td_flag_t flags;
        tapdisk_message_t response;
        struct blktap2_params params;
+       const char *path;
 
        vbd = tapdisk_server_get_vbd(request->cookie);
        if (!vbd) {
@@ -436,9 +445,14 @@ tapdisk_control_open_image(struct tapdisk_control_connection *connection,
        if (request->u.params.flags & TAPDISK_MESSAGE_FLAG_LOG_DIRTY)
                flags |= TD_OPEN_LOG_DIRTY;
 
+       type = tapdisk_disktype_parse_params(request->u.params.path, &path);
+       if (type < 0) {
+               err = type;
+               goto out;
+       }
+
        err = tapdisk_vbd_open_vdi(vbd,
-                                  request->u.params.path,
-                                  request->drivertype,
+                                  type, path,
                                   request->u.params.storage,
                                   flags);
        if (err)
@@ -576,8 +590,8 @@ tapdisk_control_resume_vbd(struct tapdisk_control_connection *connection,
        int err;
        td_vbd_t *vbd;
        tapdisk_message_t response;
-       const char *path;
-       uint16_t type;
+       const char *path = NULL;
+       int type = -1;
        size_t len;
 
        memset(&response, 0, sizeof(response));
@@ -591,12 +605,15 @@ tapdisk_control_resume_vbd(struct tapdisk_control_connection *connection,
        }
 
        len = strnlen(request->u.params.path, sizeof(request->u.params.path));
-       if (len)
-               path = request->u.params.path;
-       else
-               path = NULL;
+       if (len) {
+               type = tapdisk_disktype_parse_params(request->u.params.path, &path);
+               if (type < 0) {
+                       err = type;
+                       goto out;
+               }
+       }
 
-       err = tapdisk_vbd_resume(vbd, path, request->drivertype);
+       err = tapdisk_vbd_resume(vbd, type, path);
 
 out:
        response.cookie = request->cookie;
index 4c2ea9e1094d4ebc1b2b201485e4359f3b1761c0..b02847272958e7ce7877678e481dfcca3347af04 100644 (file)
@@ -39,8 +39,8 @@
 #include "scheduler.h"
 #include "tapdisk-vbd.h"
 #include "tapdisk-server.h"
+#include "tapdisk-disktype.h"
 #include "libvhd.h"
-#include "disktypes.h"
 
 #define POLL_READ                        0
 #define POLL_WRITE                       1
@@ -571,7 +571,7 @@ tapdisk_stream_open_image(struct tapdisk_stream *s, const char *path, int type)
 
        tapdisk_vbd_set_callback(s->vbd, tapdisk_stream_dequeue, s);
 
-       err = tapdisk_vbd_open_vdi(s->vbd, path, type,
+       err = tapdisk_vbd_open_vdi(s->vbd, type, path,
                                   TAPDISK_STORAGE_TYPE_DEFAULT,
                                   TD_OPEN_RDONLY);
        if (err)
@@ -689,11 +689,11 @@ static int
 tapdisk_stream_open(struct tapdisk_stream *s, const char *arg)
 {
        int err, type;
-       char *path;
+       const char *path;
 
-       err = tapdisk_parse_disk_type(arg, &path, &type);
-       if (err)
-               return err;
+       type = tapdisk_disktype_parse_params(arg, &path);
+       if (type < 0)
+               return type;
 
        tapdisk_stream_initialize(s);
 
@@ -735,7 +735,8 @@ main(int argc, char *argv[])
 {
        int c, err, type1;
        const char *arg1 = NULL, *arg2 = NULL;
-       char *path1;
+       const disk_info_t *info;
+       const char *path1;
 
        err    = 0;
 
@@ -760,9 +761,10 @@ main(int argc, char *argv[])
        if (!arg1 || !arg2)
                goto fail_usage;
 
-       err = tapdisk_parse_disk_type(arg1, &path1, &type1);
-       if (err)
-               return err;
+       type1 = tapdisk_disktype_parse_params(arg1, &path1);
+       if (type1 < 0)
+               return type1;
+
        if (type1 != DISK_TYPE_VHD) {
                printf("error: first VDI is not VHD\n");
                return EINVAL;
diff --git a/drivers/tapdisk-disktype.c b/drivers/tapdisk-disktype.c
new file mode 100644 (file)
index 0000000..c87b123
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2007, 2010, XenSource Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of XenSource Inc. nor the names of its contributors
+ *       may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stddef.h>
+#include <string.h>
+#include <errno.h>
+
+#include "tapdisk-disktype.h"
+
+static const disk_info_t aio_disk = {
+       "aio",
+       "raw image (aio)",
+       0,
+};
+
+static const disk_info_t sync_disk = {
+       "sync",
+       "raw image (sync)",
+       0,
+};
+
+static const disk_info_t vmdk_disk = {
+       "vmdk",
+       "vmware image (vmdk)",
+       1,
+};
+
+static const disk_info_t vhdsync_disk = {
+       "vhdsync",
+       "virtual server image (vhd) - synchronous",
+       1,
+};
+
+static const disk_info_t vhd_disk = {
+       "vhd",
+       "virtual server image (vhd)",
+       0,
+};
+
+
+static const disk_info_t ram_disk = {
+       "ram",
+       "ramdisk image (ram)",
+       1,
+};
+
+static const disk_info_t qcow_disk = {
+       "qcow",
+       "qcow disk (qcow)",
+       0,
+};
+
+static const disk_info_t block_cache_disk = {
+       "bc",
+       "block cache image (bc)",
+       1,
+};
+
+static const disk_info_t vhd_index_disk = {
+       "vhdi",
+       "vhd index image (vhdi)",
+       1,
+};
+
+static const disk_info_t log_disk = {
+       "log",
+       "write logger (log)",
+       0,
+};
+
+const disk_info_t *tapdisk_disk_types[] = {
+       [DISK_TYPE_AIO] = &aio_disk,
+       [DISK_TYPE_SYNC]        = &sync_disk,
+       [DISK_TYPE_VMDK]        = &vmdk_disk,
+       [DISK_TYPE_VHDSYNC]     = &vhdsync_disk,
+       [DISK_TYPE_VHD] = &vhd_disk,
+       [DISK_TYPE_RAM] = &ram_disk,
+       [DISK_TYPE_QCOW]        = &qcow_disk,
+       [DISK_TYPE_BLOCK_CACHE] = &block_cache_disk,
+       [DISK_TYPE_VINDEX]      = &vhd_index_disk,
+       [DISK_TYPE_LOG] = &log_disk,
+       0,
+};
+
+extern struct tap_disk tapdisk_aio;
+#if 0
+extern struct tap_disk tapdisk_sync;
+extern struct tap_disk tapdisk_vmdk;
+extern struct tap_disk tapdisk_vhdsync;
+#endif
+extern struct tap_disk tapdisk_vhd;
+extern struct tap_disk tapdisk_ram;
+#if 0
+extern struct tap_disk tapdisk_qcow;
+#endif
+extern struct tap_disk tapdisk_block_cache;
+extern struct tap_disk tapdisk_vhd_index;
+extern struct tap_disk tapdisk_log;
+
+const struct tap_disk *tapdisk_disk_drivers[] = {
+       [DISK_TYPE_AIO]         = &tapdisk_aio,
+#if 0
+       [DISK_TYPE_SYNC]        = &tapdisk_sync,
+       [DISK_TYPE_VMDK]        = &tapdisk_vmdk,
+       [DISK_TYPE_VHDSYNC]     = &tapdisk_vhdsync_disk
+#endif
+       [DISK_TYPE_VHD]         = &tapdisk_vhd,
+       [DISK_TYPE_RAM]         = &tapdisk_ram,
+#if 0
+       [DISK_TYPE_QCOW]        = &tapdisk_qcow,
+#endif
+       [DISK_TYPE_BLOCK_CACHE] = &tapdisk_block_cache,
+       [DISK_TYPE_VINDEX]      = &tapdisk_vhd_index,
+       [DISK_TYPE_LOG]         = &tapdisk_log,
+       0,
+};
+
+int
+tapdisk_disktype_find(const char *name)
+{
+       const disk_info_t *info;
+       int i;
+
+       for (i = 0; info = tapdisk_disk_types[i], info != NULL; ++i) {
+               if (strcmp(name, info->name))
+                       continue;
+
+               if (!tapdisk_disk_drivers[i])
+                       return -ENOSYS;
+
+               return i;
+       }
+
+       return -ENOENT;
+}
+
+int
+tapdisk_disktype_parse_params(const char *params, const char **_path)
+{
+       char name[DISK_TYPE_NAME_MAX], *ptr;
+       size_t len;
+       int type;
+
+       ptr = strchr(params, ':');
+       if (!ptr)
+               return -EINVAL;
+
+       len = ptr - params;
+
+       if (len > sizeof(name) - 1)
+               return -ENAMETOOLONG;
+
+       memset(name, 0, sizeof(name));
+       strncpy(name, params, len);
+
+       type = tapdisk_disktype_find(name);
+
+       if (type >= 0)
+               *_path = params + len + 1;
+
+       return type;
+}
diff --git a/drivers/tapdisk-disktype.h b/drivers/tapdisk-disktype.h
new file mode 100644 (file)
index 0000000..7a7d51a
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2007, 2010, XenSource Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of XenSource Inc. nor the names of its contributors
+ *       may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __DISKTYPES_H__
+#define __DISKTYPES_H__
+
+#define DISK_TYPE_AIO         0
+#define DISK_TYPE_SYNC        1
+#define DISK_TYPE_VMDK        2
+#define DISK_TYPE_VHDSYNC     3
+#define DISK_TYPE_VHD         4
+#define DISK_TYPE_RAM         5
+#define DISK_TYPE_QCOW        6
+#define DISK_TYPE_BLOCK_CACHE 7
+#define DISK_TYPE_VINDEX      8
+#define DISK_TYPE_LOG         9
+#define DISK_TYPE_REMUS       10
+
+#define DISK_TYPE_NAME_MAX    32
+
+typedef struct disk_info {
+       const char     *name; /* driver name, e.g. 'aio' */
+       char           *desc;  /* e.g. "raw image" */
+       unsigned int    flags; 
+} disk_info_t;
+
+extern const disk_info_t     *tapdisk_disk_types[];
+extern const struct tap_disk *tapdisk_disk_drivers[];
+
+/* one single controller for all instances of disk type */
+#define DISK_TYPE_SINGLE_CONTROLLER (1<<0)
+
+int tapdisk_disktype_find(const char *name);
+int tapdisk_disktype_parse_params(const char *params, const char **_path);
+
+#endif
index ca5629ab7334fb14f651a5eda7f753b354108009..aa1ed15f40ad6a96676f132c9a02bb08b70ff006 100644 (file)
 
 #include "tapdisk-driver.h"
 #include "tapdisk-server.h"
+#include "tapdisk-disktype.h"
 
 td_driver_t *
 tapdisk_driver_allocate(int type, char *name, td_flag_t flags, int storage)
 {
        int err;
        td_driver_t *driver;
-       struct tap_disk *ops;
+       const struct tap_disk *ops;
 
-       ops = tapdisk_server_find_driver_interface(type);
+       ops = tapdisk_disk_drivers[type];
        if (!ops)
                return NULL;
 
index de0a9be23343c7eeb56c742a9d9a05982f952a29..42de05db1d620dde11d6a165a4df28113e7cd893 100644 (file)
@@ -47,7 +47,7 @@ struct td_driver_handle {
        td_disk_info_t               info;
 
        void                        *data;
-       struct tap_disk             *ops;
+       const struct tap_disk       *ops;
 
        struct list_head             next;
 };
index 537fa0560ee1c5a8e9ca9a48c08854db2440d1ef..83c94bdc268b7e116f0bd2f0bd1029f48e8c6f63 100644 (file)
@@ -36,6 +36,7 @@
 #include "tapdisk-ipc.h"
 #include "tapdisk-vbd.h"
 #include "tapdisk-server.h"
+#include "tapdisk-disktype.h"
 
 static void
 tapdisk_ipc_read_event(event_id_t id, char mode, void *private)
@@ -277,6 +278,8 @@ tapdisk_ipc_read(td_ipc_t *ipc)
                image_t image;
                char *devname;
                td_flag_t flags;
+               int type;
+               const char *path;
 
                flags = 0;
 
@@ -297,9 +300,14 @@ tapdisk_ipc_read(td_ipc_t *ipc)
                if (err == -1)
                        goto fail;
 
+               type = tapdisk_disktype_parse_params(message.u.params.path, &path);
+               if (type < 0) {
+                       err = type;
+                       goto fail;
+               }
+
                err   = tapdisk_vbd_open(vbd,
-                                        message.u.params.path,
-                                        message.drivertype,
+                                        type, path,
                                         message.u.params.storage,
                                         message.u.params.devnum,
                                         devname, flags);
@@ -325,12 +333,17 @@ tapdisk_ipc_read(td_ipc_t *ipc)
                tapdisk_vbd_pause(vbd);
                return 0; /* response written asynchronously */
 
-       case TAPDISK_MESSAGE_RESUME:
-               tapdisk_vbd_resume(vbd,
-                                  message.u.params.path,
-                                  message.drivertype);
-               return 0; /* response written asynchronously */
+       case TAPDISK_MESSAGE_RESUME: {
+               int type;
+               const char *path;
 
+               type = tapdisk_disktype_parse_params(message.u.params.path, &path);
+               if (type < 0)
+                       return type;
+
+               tapdisk_vbd_resume(vbd, type, path);
+               return 0; /* response written asynchronously */
+       }
        case TAPDISK_MESSAGE_CLOSE:
                tapdisk_vbd_close(vbd);
                return 0; /* response written asynchronously */
index 535b3c10e0cd98d8f07225c3c7a7e22fc0cd7165..c5e4d91154e3346576cbc37814ca960e11a141ed 100644 (file)
 #include <sys/ioctl.h>
 #include <sys/signal.h>
 
-#define TAPDISK
 #include "tapdisk-syslog.h"
 #include "tapdisk-server.h"
 #include "tapdisk-driver.h"
 #include "tapdisk-interface.h"
 #include "tapdisk-log.h"
-#include "disktypes.h"
 
 #define DBG(_level, _f, _a...)       tlog_write(_level, _f, ##_a)
 #define ERR(_err, _f, _a...)         tlog_error(_err, _f, ##_a)
@@ -61,18 +59,6 @@ static tapdisk_server_t server;
 #define tapdisk_server_for_each_vbd(vbd, tmp)                          \
        list_for_each_entry_safe(vbd, tmp, &server.vbds, next)
 
-struct tap_disk *
-tapdisk_server_find_driver_interface(int type)
-{
-       int n;
-
-       n = sizeof(dtypes) / sizeof(struct disk_info_t *);
-       if (type > n)
-               return NULL;
-
-       return dtypes[type]->drv;
-}
-
 td_image_t *
 tapdisk_server_get_shared_image(td_image_t *image)
 {
index 96abc9a22595b2de5a40dfac264a68c3bb87a6ac..9a3f7a2634bc34e493e2edfb85dea50f42cf6cbe 100644 (file)
@@ -37,6 +37,7 @@
 #include "scheduler.h"
 #include "tapdisk-vbd.h"
 #include "tapdisk-server.h"
+#include "tapdisk-disktype.h"
 
 #define POLL_READ                        0
 #define POLL_WRITE                       1
@@ -349,7 +350,7 @@ tapdisk_stream_open_image(struct tapdisk_stream *s, const char *path, int type)
 
        tapdisk_vbd_set_callback(s->vbd, tapdisk_stream_dequeue, s);
 
-       err = tapdisk_vbd_open_vdi(s->vbd, path, type,
+       err = tapdisk_vbd_open_vdi(s->vbd, type, path,
                                   TAPDISK_STORAGE_TYPE_DEFAULT,
                                   TD_OPEN_RDONLY);
        if (err)
@@ -545,7 +546,9 @@ int
 main(int argc, char *argv[])
 {
        int c, err, type;
-       char *params, *path;
+       const char *params;
+       const disk_info_t *info;
+       const char *path;
        uint64_t count, skip;
        struct tapdisk_stream stream;
 
@@ -575,8 +578,9 @@ main(int argc, char *argv[])
        if (!params)
                usage(argv[0], EINVAL);
 
-       err = tapdisk_parse_disk_type(params, &path, &type);
-       if (err) {
+       type = tapdisk_disktype_parse_params(params, &path);
+       if (type < 0) {
+               err = type;
                fprintf(stderr, "invalid argument %s: %d\n", params, err);
                return err;
        }
index 0d15bbfd10e87320df61ce3cda4973ae863c7e6b..6eff5dfe26891ef7b989f7dda32373c3e4cf1139 100644 (file)
@@ -45,7 +45,6 @@
 #include <syslog.h>
 
 #include "tapdisk.h"
-#include "disktypes.h"
 #include "blktaplib.h"
 #include "tapdisk-log.h"
 #include "tapdisk-utils.h"
@@ -182,40 +181,6 @@ tapdisk_namedup(char **dup, const char *name)
        return 0;
 }
 
-int
-tapdisk_parse_disk_type(const char *params, char **_path, int *_type)
-{
-       int i, err, size;
-       char *ptr, *path, handle[10];
-
-       if (strlen(params) + 1 >= MAX_NAME_LEN)
-               return -ENAMETOOLONG;
-
-       ptr = strchr(params, ':');
-       if (!ptr)
-               return -EINVAL;
-
-       path = ptr + 1;
-       memcpy(handle, params, (ptr - params));
-       handle[(ptr - params)] = '\0';
-
-       size = sizeof(dtypes) / sizeof(disk_info_t *);
-       for (i = 0; i < size; i++) {
-               if (strncmp(handle, dtypes[i]->handle, (ptr - params)))
-                       continue;
-
-               if (dtypes[i]->idnum == -1)
-                       return -ENODEV;
-
-               *_type = dtypes[i]->idnum;
-               *_path = path;
-
-               return 0;
-       }
-
-       return -ENODEV;
-}
-
 /*Get Image size, secsize*/
 int
 tapdisk_get_image_size(int fd, uint64_t *_sectors, uint32_t *_sector_size)
index d2486336829725e058ab0bb33dfc08a5c83f3e46..410df6f7529dcf35df392b02f91515bec757d4fa 100644 (file)
 #include "tapdisk-image.h"
 #include "tapdisk-driver.h"
 #include "tapdisk-server.h"
+#include "tapdisk-vbd.h"
+#include "tapdisk-disktype.h"
 #include "tapdisk-interface.h"
 
 #include "blktap2.h"
-#include "disktypes.h"
 
 #define DBG(_level, _f, _a...) tlog_write(_level, _f, ##_a)
 #define ERR(_err, _f, _a...) tlog_error(_err, _f, ##_a)
@@ -724,17 +725,18 @@ fail:
 }
 
 int
-tapdisk_vbd_open_vdi(td_vbd_t *vbd, const char *path,
-                    uint16_t drivertype, uint16_t storage, td_flag_t flags)
+tapdisk_vbd_open_vdi(td_vbd_t *vbd, int type, const char *path,
+                    uint16_t storage, td_flag_t flags)
 {
+       const disk_info_t *info;
        int i, err;
-       struct tap_disk *ops;
 
-       ops = tapdisk_server_find_driver_interface(drivertype);
-       if (!ops)
+       info = tapdisk_disk_types[type];
+       if (!info)
                return -EINVAL;
-       DPRINTF("Loaded %s driver for vbd %u %s 0x%08x\n",
-               ops->disk_type, vbd->uuid, path, flags);
+
+       DPRINTF("Loading driver '%s' for vbd %u %s 0x%08x\n",
+               info->name, vbd->uuid, path, flags);
 
        err = tapdisk_namedup(&vbd->name, path);
        if (err)
@@ -742,7 +744,7 @@ tapdisk_vbd_open_vdi(td_vbd_t *vbd, const char *path,
 
        vbd->flags   = flags;
        vbd->storage = storage;
-       vbd->type    = drivertype;
+       vbd->type    = type;
 
        for (i = 0; i < TD_VBD_EIO_RETRIES; i++) {
                err = __tapdisk_vbd_open_vdi(vbd, 0);
@@ -879,12 +881,12 @@ fail:
 }
 
 int
-tapdisk_vbd_open(td_vbd_t *vbd, const char *name, uint16_t type,
+tapdisk_vbd_open(td_vbd_t *vbd, int type, const char *path,
                 uint16_t storage, int minor, const char *ring, td_flag_t flags)
 {
        int err;
 
-       err = tapdisk_vbd_open_vdi(vbd, name, type, storage, flags);
+       err = tapdisk_vbd_open_vdi(vbd, type, path, storage, flags);
        if (err)
                goto out;
 
@@ -1165,7 +1167,7 @@ tapdisk_vbd_pause(td_vbd_t *vbd)
 }
 
 int
-tapdisk_vbd_resume(td_vbd_t *vbd, const char *path, uint16_t drivertype)
+tapdisk_vbd_resume(td_vbd_t *vbd, int type, const char *path)
 {
        int i, err;
 
@@ -1185,7 +1187,7 @@ tapdisk_vbd_resume(td_vbd_t *vbd, const char *path, uint16_t drivertype)
                        tapdisk_ipc_write(&vbd->ipc, TAPDISK_MESSAGE_ERROR);
                        return -EINVAL;
                }
-               vbd->type = drivertype;
+               vbd->type = type;
        }
 
        for (i = 0; i < TD_VBD_EIO_RETRIES; i++) {
@@ -1839,7 +1841,8 @@ static int
 tapdisk_vbd_resume_ring(td_vbd_t *vbd)
 {
        int i, err, type;
-       char *path, message[BLKTAP2_MAX_MESSAGE_LEN];
+       char message[BLKTAP2_MAX_MESSAGE_LEN];
+       const char *path;
 
        memset(message, 0, sizeof(message));
 
@@ -1854,8 +1857,9 @@ tapdisk_vbd_resume_ring(td_vbd_t *vbd)
                return err;
        }
 
-       err = tapdisk_parse_disk_type(message, &path, &type);
-       if (err) {
+       type = tapdisk_disktype_parse_params(message, &path);
+       if (type < 0) {
+               err = type;
                EPRINTF("%s: invalid resume string %s\n", vbd->name, message);
                goto out;
        }
index 5e7af9e0e9c30755b5384ed94435f19e0450debf..150fb86be133faa3d217d5dd6f70b0c1f7d520f4 100644 (file)
@@ -173,12 +173,11 @@ tapdisk_vbd_next_image(td_image_t *image)
 td_vbd_t *tapdisk_vbd_create(td_uuid_t);
 int tapdisk_vbd_initialize(int, int, td_uuid_t);
 void tapdisk_vbd_set_callback(td_vbd_t *, td_vbd_cb_t, void *);
-int tapdisk_vbd_open(td_vbd_t *, const char *, uint16_t,
+int tapdisk_vbd_open(td_vbd_t *, int, const char *,
                     uint16_t, int, const char *, td_flag_t);
 int tapdisk_vbd_close(td_vbd_t *);
 
-int tapdisk_vbd_open_vdi(td_vbd_t *, const char *,
-                        uint16_t, uint16_t, td_flag_t);
+int tapdisk_vbd_open_vdi(td_vbd_t *, int, const char *, uint16_t, td_flag_t);
 void tapdisk_vbd_close_vdi(td_vbd_t *);
 
 int tapdisk_vbd_attach(td_vbd_t *, const char *, int);
@@ -193,7 +192,7 @@ int tapdisk_vbd_start_queue(td_vbd_t *);
 int tapdisk_vbd_issue_requests(td_vbd_t *);
 int tapdisk_vbd_kill_queue(td_vbd_t *);
 int tapdisk_vbd_pause(td_vbd_t *);
-int tapdisk_vbd_resume(td_vbd_t *, const char *, uint16_t);
+int tapdisk_vbd_resume(td_vbd_t *, int, const char *);
 int tapdisk_vbd_kick(td_vbd_t *);
 void tapdisk_vbd_check_state(td_vbd_t *);
 void tapdisk_vbd_check_progress(td_vbd_t *);
index a32d85ecccb324c54daacd24909b6748c2a518c1..d9eb100bbef1f811b8aedc540e688231531d398e 100644 (file)
@@ -91,7 +91,6 @@ struct tapdisk_message_list {
 struct tapdisk_message {
        uint16_t                         type;
        uint16_t                         cookie;
-       uint16_t                         drivertype;
 
        union {
                pid_t                    tapdisk_pid;