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

[Xen-changelog] [xen-unstable] blktap: Fix check_sharing() in blktapctrl



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1256288529 -3600
# Node ID c7381d04e2b3882a1cd5d0fc6abb13786c88b9ee
# Parent  6d38985b00fcd809c3d0e5090fac5420f3a92293
blktap: Fix check_sharing() in blktapctrl

check_sharing() in blktapctrl does not work.
 - It accesses to xenstore by using wrong paths.
 - It compares image paths including image types.
 - It misjudges a return value of strcmp().

This patch fixes those mistakes.

Signed-off-by: Masaki Kanno <kanno.masaki@xxxxxxxxxxxxxx>
---
 tools/blktap/lib/xenbus.c |   69 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 50 insertions(+), 19 deletions(-)

diff -r 6d38985b00fc -r c7381d04e2b3 tools/blktap/lib/xenbus.c
--- a/tools/blktap/lib/xenbus.c Fri Oct 23 10:00:22 2009 +0100
+++ b/tools/blktap/lib/xenbus.c Fri Oct 23 10:02:09 2009 +0100
@@ -107,6 +107,24 @@ static int get_be_id(const char *str)
        return atoi(num);
 }
 
+static int get_be_domid(const char *str)
+{
+       int len1, len2;
+       const char *ptr;
+       char *tptr, num[10];
+
+       len2 = strsep_len(str, '/', 3);
+       if ( len2 < 0 ) return -1;
+       len1 = strsep_len(str, '/', 2);
+
+       ptr = str + len1 + 1;
+       strncpy(num, ptr, len2 - len1 - 1);
+       tptr = num + (len2 - len1 - 1);
+       *tptr = '\0';
+
+       return atoi(num);
+}
+
 static struct backend_info *be_lookup_be(const char *bepath)
 {
        struct backend_info *be;
@@ -148,6 +166,24 @@ static int backend_remove(struct xs_hand
                free(be->backpath);
        free(be);
        return 0;
+}
+
+static const char *get_image_path(const char *path)
+{
+       const char *tmp;
+
+       /* Strip off the image type */
+       if (!strncmp(path, "tapdisk:", strlen("tapdisk:"))) {
+               path += strlen("tapdisk:");
+       } else if (!strncmp(path, "ioemu:", strlen("ioemu:"))) {
+               path += strlen("ioemu:");
+       }
+
+       tmp = strchr(path, ':');
+       if (tmp != NULL)
+               path = tmp + 1;
+
+       return path;
 }
 
 static int check_sharing(struct xs_handle *h, struct backend_info *be)
@@ -161,8 +197,12 @@ static int check_sharing(struct xs_handl
        char **devices;
        int i, j;
        unsigned int num_dom, num_dev;
-       blkif_info_t *info;
+       blkif_info_t *info = be->blkif->info;
        int ret = 0;
+       const char *image_path[2];
+       int be_domid = get_be_domid(be->backpath);
+
+       image_path[0] = get_image_path(info->params);
 
        /* If the mode contains '!' or doesn't contain 'w' don't check anything 
*/
        xs_gather(h, be->backpath, "mode", NULL, &mode, NULL);
@@ -178,7 +218,10 @@ static int check_sharing(struct xs_handl
        free(path);
 
        /* Iterate through the devices of all VMs */
-       domains = xs_directory(h, XBT_NULL, "backend/tap", &num_dom);
+       if (asprintf(&path, "/local/domain/%d/backend/tap", be_domid) == -1)
+               goto fail;
+       domains = xs_directory(h, XBT_NULL, path, &num_dom);
+       free(path);
        if (domains == NULL)
                num_dom = 0;
 
@@ -198,7 +241,7 @@ static int check_sharing(struct xs_handl
                }
 
                /* Check the devices */
-               if (asprintf(&path, "backend/tap/%s", domains[i]) == -1) {
+               if (asprintf(&path, "/local/domain/%d/backend/tap/%s", 
be_domid, domains[i]) == -1) {
                        ret = -1;
                        free(cur_dom_uuid);
                        break;
@@ -209,15 +252,15 @@ static int check_sharing(struct xs_handl
                free(path);
 
                for (j = 0; !ret && (j < num_dev); j++) {
-                       if (asprintf(&path, "backend/tap/%s/%s", domains[i], 
devices[j]) == -1) {
+                       if (asprintf(&path, 
"/local/domain/%d/backend/tap/%s/%s", be_domid, domains[i], devices[j]) == -1) {
                                ret = -1;
                                break;
                        }
                        xs_gather(h, path, "params", NULL, &params, NULL);
                        free(path);
 
-                       info =  be->blkif->info;
-                       if (strcmp(params, info->params)) {
+                       image_path[1] = get_image_path(params);
+                       if (!strcmp(image_path[0], image_path[1])) {
                                ret = -1;
                        }
 
@@ -241,24 +284,12 @@ static int check_image(struct xs_handle 
 static int check_image(struct xs_handle *h, struct backend_info *be,
        const char** errmsg)
 {
-       const char *tmp;
        const char *path;
        int mode;
        blkif_t *blkif = be->blkif;
        blkif_info_t *info = blkif->info;
 
-       /* Strip off the image type */
-       path = info->params;
-
-       if (!strncmp(path, "tapdisk:", strlen("tapdisk:"))) {
-               path += strlen("tapdisk:");
-       } else if (!strncmp(path, "ioemu:", strlen("ioemu:"))) {
-               path += strlen("ioemu:");
-       }
-
-       tmp = strchr(path, ':');
-       if (tmp != NULL)
-               path = tmp + 1;
+       path = get_image_path(info->params);
 
        /* Check if the image exists and access is permitted */
        mode = R_OK;

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