WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] blktap: Move error signaling to blktapctr

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] blktap: Move error signaling to blktapctrl
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 12 Mar 2009 11:55:15 -0700
Delivery-date: Thu, 12 Mar 2009 11:55:29 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1236883689 0
# Node ID c30742011bb8bde453478143a66af811a7de78d6
# Parent  d8741d4dd05a4aec44bbdbf67deb2f26e1c934ad
blktap: Move error signaling to blktapctrl

Until now the udev script for blktap devices needs to decide if to
signal success or failure to xend. As this script runs completely
independent of blktapctrl and tapdisk/ioemu which do the real work,
the udev script can't even theoretically know if tapdisk is happy.

This patch removes the udev script and replaces its checks by new
ones in libblktap.

Signed-off-by: Kevin Wolf <kwolf@xxxxxxx>
---
 tools/hotplug/Linux/blktap            |   93 ---------------------
 tools/blktap/drivers/blktapctrl.c     |   16 +--
 tools/blktap/lib/xenbus.c             |  150 +++++++++++++++++++++++++++++++++-
 tools/hotplug/Linux/Makefile          |    1 
 tools/hotplug/Linux/xen-backend.rules |    1 
 5 files changed, 156 insertions(+), 105 deletions(-)

diff -r d8741d4dd05a -r c30742011bb8 tools/blktap/drivers/blktapctrl.c
--- a/tools/blktap/drivers/blktapctrl.c Thu Mar 12 18:46:26 2009 +0000
+++ b/tools/blktap/drivers/blktapctrl.c Thu Mar 12 18:48:09 2009 +0000
@@ -659,9 +659,6 @@ 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 (blktap_interface_create(ctlfd, &major, &minor, blkif) < 0)
-                       return -1;
-
                if (test_path(blk->params, &ptr, &type, &exist, &use_ioemu) != 
0) {
                         DPRINTF("Error in blktap device string(%s).\n",
                                 blk->params);
@@ -685,10 +682,6 @@ static int blktapctrl_new_blkif(blkif_t 
                        blkif->fds[WRITE] = exist->fds[WRITE];
                }
 
-               add_disktype(blkif, type);
-               blkif->major = major;
-               blkif->minor = minor;
-
                image = (image_t *)malloc(sizeof(image_t));
                blkif->prv = (void *)image;
                blkif->ops = &tapdisk_ops;
@@ -712,11 +705,18 @@ static int blktapctrl_new_blkif(blkif_t 
                        goto fail;
                }
 
+               if (blktap_interface_create(ctlfd, &major, &minor, blkif) < 0)
+                       return -1;
+
+               blkif->major = major;
+               blkif->minor = minor;
+
+               add_disktype(blkif, type);
+
        } else return -1;
 
        return 0;
 fail:
-       ioctl(ctlfd, BLKTAP_IOCTL_FREEINTF, minor);
        return -EINVAL;
 }
 
diff -r d8741d4dd05a -r c30742011bb8 tools/blktap/lib/xenbus.c
--- a/tools/blktap/lib/xenbus.c Thu Mar 12 18:46:26 2009 +0000
+++ b/tools/blktap/lib/xenbus.c Thu Mar 12 18:48:09 2009 +0000
@@ -48,6 +48,7 @@
 #include <poll.h>
 #include <time.h>
 #include <sys/time.h>
+#include <unistd.h>
 #include "blktaplib.h"
 #include "list.h"
 #include "xs_api.h"
@@ -149,6 +150,137 @@ static int backend_remove(struct xs_hand
        return 0;
 }
 
+static int check_sharing(struct xs_handle *h, struct backend_info *be)
+{
+       char *dom_uuid;
+       char *cur_dom_uuid;
+       char *path;
+       char *mode;
+       char *params;
+       char **domains;
+       char **devices;
+       int i, j;
+       unsigned int num_dom, num_dev;
+       blkif_info_t *info;
+       int ret = 0;
+
+       /* If the mode contains '!' or doesn't contain 'w' don't check anything 
*/
+       xs_gather(h, be->backpath, "mode", NULL, &mode, NULL);
+       if (strchr(mode, '!'))
+               goto out;
+       if (strchr(mode, 'w') == NULL)
+               goto out;
+
+       /* Get the UUID of the domain we want to attach to */
+       if (asprintf(&path, "/local/domain/%ld", be->frontend_id) == -1)
+               goto fail;
+       xs_gather(h, path, "vm", NULL, &dom_uuid, NULL);
+       free(path);
+
+       /* Iterate through the devices of all VMs */
+       domains = xs_directory(h, XBT_NULL, "backend/tap", &num_dom);
+       if (domains == NULL)
+               num_dom = 0;
+
+       for (i = 0; !ret && (i < num_dom); i++) {
+
+               /* If it's the same VM, no action needed */
+               if (asprintf(&path, "/local/domain/%s", domains[i]) == -1) {
+                       ret = -1;
+                       break;
+               }
+               xs_gather(h, path, "vm", NULL, &cur_dom_uuid, NULL);
+               free(path);
+
+               if (!strcmp(cur_dom_uuid, dom_uuid)) {
+                       free(cur_dom_uuid);
+                       continue;
+               }
+
+               /* Check the devices */
+               if (asprintf(&path, "backend/tap/%s", domains[i]) == -1) {
+                       ret = -1;
+                       free(cur_dom_uuid);
+                       break;
+               }
+               devices = xs_directory(h, XBT_NULL, path, &num_dev);
+               if (devices == NULL)
+                       num_dev = 0;
+               free(path);
+
+               for (j = 0; !ret && (j < num_dev); j++) {
+                       if (asprintf(&path, "backend/tap/%s/%s", 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)) {
+                               ret = -1;
+                       }
+
+                       free(params);
+               }
+
+               free(cur_dom_uuid);
+               free(devices);
+       }
+       free(domains);
+       free(dom_uuid);
+       goto out;
+
+fail:
+       ret = -1;
+out:
+       free(mode);
+       return ret;
+}
+
+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;
+
+       /* Check if the image exists and access is permitted */
+       mode = R_OK;
+       if (!be->readonly)
+               mode |= W_OK;
+       if (access(path, mode)) {
+               if (errno == ENOENT)
+                       *errmsg = "File not found.";
+               else
+                       *errmsg = "Insufficient file permissions.";
+               return -1;
+       }
+
+       /* Check that the image is not attached to a different VM */
+       if (check_sharing(h, be)) {
+               *errmsg = "File already in use by other domain";
+               return -1;
+       }
+
+       return 0;
+}
+
 static void ueblktap_setup(struct xs_handle *h, char *bepath)
 {
        struct backend_info *be;
@@ -156,6 +288,7 @@ static void ueblktap_setup(struct xs_han
        int len, er, deverr;
        long int pdev = 0, handle;
        blkif_info_t *blk;
+       const char* errmsg = NULL;
        
        be = be_lookup_be(bepath);
        if (be == NULL)
@@ -211,6 +344,9 @@ static void ueblktap_setup(struct xs_han
                        be->pdev = pdev;
                }
 
+               if (check_image(h, be, &errmsg))
+                       goto fail;
+
                er = blkif_init(be->blkif, handle, be->pdev, be->readonly);
                if (er != 0) {
                        DPRINTF("Unable to open device %s\n",blk->params);
@@ -246,12 +382,21 @@ static void ueblktap_setup(struct xs_han
        }
 
        be->blkif->state = CONNECTED;
+       xs_printf(h, be->backpath, "hotplug-status", "connected");
+
        DPRINTF("[SETUP] Complete\n\n");
        goto close;
        
 fail:
-       if ( (be != NULL) && (be->blkif != NULL) ) 
+       if (be) {
+               if (errmsg == NULL)
+                       errmsg = "Setting up the backend failed. See the log "
+                               "files in /var/log/xen/ for details.";
+               xs_printf(h, be->backpath, "hotplug-error", errmsg);
+               xs_printf(h, be->backpath, "hotplug-status", "error");
+
                backend_remove(h, be);
+       }
 close:
        if (path)
                free(path);
@@ -286,7 +431,8 @@ static void ueblktap_probe(struct xs_han
        len = strsep_len(bepath, '/', 7);
        if (len < 0) 
                goto free_be;
-       bepath[len] = '\0';
+       if (bepath[len] != '\0')
+               goto free_be;
        
        be = malloc(sizeof(*be));
        if (!be) {
diff -r d8741d4dd05a -r c30742011bb8 tools/hotplug/Linux/Makefile
--- a/tools/hotplug/Linux/Makefile      Thu Mar 12 18:46:26 2009 +0000
+++ b/tools/hotplug/Linux/Makefile      Thu Mar 12 18:48:09 2009 +0000
@@ -16,7 +16,6 @@ XEN_SCRIPTS += network-nat vif-nat
 XEN_SCRIPTS += network-nat vif-nat
 XEN_SCRIPTS += block
 XEN_SCRIPTS += block-enbd block-nbd
-XEN_SCRIPTS += blktap
 XEN_SCRIPTS += vtpm vtpm-delete
 XEN_SCRIPTS += xen-hotplug-cleanup
 XEN_SCRIPTS += external-device-migrate
diff -r d8741d4dd05a -r c30742011bb8 tools/hotplug/Linux/blktap
--- a/tools/hotplug/Linux/blktap        Thu Mar 12 18:46:26 2009 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,93 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2005, XenSource Ltd.
-
-dir=$(dirname "$0")
-. "$dir/xen-hotplug-common.sh"
-. "$dir/block-common.sh"
-
-findCommand "$@"
-
-##
-# check_blktap_sharing file mode
-#
-# Perform the sharing check for the given blktap and mode.
-#
-check_blktap_sharing()
-{
-    local file="$1"
-    local mode="$2"
-
-    local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE"
-    for dom in $(xenstore-list "$base_path")
-    do
-        for dev in $(xenstore-list "$base_path/$dom")
-        do
-            params=$(xenstore_read "$base_path/$dom/$dev/params" | cut -d: -f2)
-            if [ "$file" = "$params" ]
-            then
-
-                if [ "$mode" = 'w' ]
-                then
-                    if ! same_vm "$dom" 
-                    then
-                        echo 'guest'
-                        return
-                    fi
-                else 
-                    local m=$(xenstore_read "$base_path/$dom/$dev/mode")
-                    m=$(canonicalise_mode "$m")
-
-                    if [ "$m" = 'w' ] 
-                    then
-                        if ! same_vm "$dom"
-                        then
-                            echo 'guest'
-                            return
-                        fi
-                    fi
-                fi
-            fi
-        done
-    done
-
-    echo 'ok'
-}
-
-
-t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING')
-if [ -n "$t" ]
-then
-    p=$(xenstore_read "$XENBUS_PATH/params")
-    # if we have a ':', chew from head including :
-    if echo $p | grep -q \:
-    then
-        p=${p#*:}
-    fi
-fi
-# some versions of readlink cannot be passed a regular file
-if [ -L "$p" ]; then
-    file=$(readlink -f "$p") || fatal "$p link does not exist."
-else
-    file="$p"
-fi
-
-if [ "$command" = 'add' ]
-then
-    [ -e "$file" ] || { fatal $file does not exist; }
-
-    FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id")
-    FRONTEND_UUID=$(xenstore_read "/local/domain/$FRONTEND_ID/vm")
-    mode=$(xenstore_read "$XENBUS_PATH/mode")
-    mode=$(canonicalise_mode "$mode")
-
-    if [ "$mode" != '!' ] 
-    then
-        result=$(check_blktap_sharing "$file" "$mode")
-        [ "$result" = 'ok' ] || ebusy "$file already in use by other domain"
-    fi
-
-    success
-fi
-
-exit 0
diff -r d8741d4dd05a -r c30742011bb8 tools/hotplug/Linux/xen-backend.rules
--- a/tools/hotplug/Linux/xen-backend.rules     Thu Mar 12 18:46:26 2009 +0000
+++ b/tools/hotplug/Linux/xen-backend.rules     Thu Mar 12 18:48:09 2009 +0000
@@ -1,4 +1,3 @@ SUBSYSTEM=="xen-backend", KERNEL=="tap*"
-SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap 
$env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block 
$env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm 
$env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} 
online"

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] blktap: Move error signaling to blktapctrl, Xen patchbot-unstable <=