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] Tidy up use of environment variables in xenbus-hotplug i

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Tidy up use of environment variables in xenbus-hotplug interaction.
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 07 Dec 2005 14:20:14 +0000
Delivery-date: Wed, 07 Dec 2005 17:00:33 +0000
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/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/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 emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 5f574f9cb4bd2b5eebd98ce6fc43ce0c33d7b1d4
# Parent  91046e4a49dd4ab33451d7fee479a450a32d8684
Tidy up use of environment variables in xenbus-hotplug interaction.

I've changed this to only write "backend" (xenbus_backend.root) into
XENBUS_BASE_PATH.  After appending XENBUS_TYPE (also exported) you can
construct the "base path" easily in the scripts.  I've completely
removed writing XENBUS_FRONTEND_ID in favour of reading it from the
store at "$XENBUS_PATH/frontend-id".

Avoid re-reading the store over and over for the frontend domain's vm-path.

The patch also fixes a memory leak in backend_bus_id where we
leak the memory referenced by frontend if the function succeeds.

This work is by Christian Limpach.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>

diff -r 91046e4a49dd -r 5f574f9cb4bd 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Wed Dec  7 
11:51:31 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Wed Dec  7 
11:57:26 2005
@@ -59,8 +59,6 @@
 
 #define streq(a, b) (strcmp((a), (b)) == 0)
 
-static char *kasprintf(const char *fmt, ...);
-
 static struct notifier_block *xenstore_chain;
 
 /* If something in array of ids matches this device, return it. */
@@ -209,14 +207,13 @@
                return err;
        if (strlen(frontend) == 0)
                err = -ERANGE;
-
        if (!err && !xenbus_exists(NULL, frontend, ""))
                err = -ENOENT;
 
-       if (err) {
-               kfree(frontend);
+       kfree(frontend);
+
+       if (err)
                return err;
-       }
 
        if (snprintf(bus_id, BUS_ID_SIZE,
                     "%.*s-%i-%s", typelen, type, domid, devid) >= BUS_ID_SIZE)
@@ -225,69 +222,7 @@
 }
 
 static int xenbus_hotplug_backend(struct device *dev, char **envp,
-                                 int num_envp, char *buffer, int buffer_size)
-{
-       struct xenbus_device *xdev;
-       struct xenbus_driver *drv = NULL;
-       int i = 0;
-       int length = 0;
-       char *basepath_end;
-       char *frontend_id;
-
-       DPRINTK("");
-
-       if (dev == NULL)
-               return -ENODEV;
-
-       xdev = to_xenbus_device(dev);
-       if (xdev == NULL)
-               return -ENODEV;
-
-       if (dev->driver)
-               drv = to_xenbus_driver(dev->driver);
-
-       /* stuff we want to pass to /sbin/hotplug */
-       add_hotplug_env_var(envp, num_envp, &i,
-                           buffer, buffer_size, &length,
-                           "XENBUS_TYPE=%s", xdev->devicetype);
-
-       add_hotplug_env_var(envp, num_envp, &i,
-                           buffer, buffer_size, &length,
-                           "XENBUS_PATH=%s", xdev->nodename);
-
-       add_hotplug_env_var(envp, num_envp, &i,
-                           buffer, buffer_size, &length,
-                           "XENBUS_BASE_PATH=%s", xdev->nodename);
-
-       basepath_end = strrchr(envp[i - 1], '/');
-       length -= strlen(basepath_end);
-       *basepath_end = '\0';
-       basepath_end = strrchr(envp[i - 1], '/');
-       length -= strlen(basepath_end);
-       *basepath_end = '\0';
-
-       basepath_end++;
-       frontend_id = kmalloc(strlen(basepath_end) + 1, GFP_KERNEL);
-       strcpy(frontend_id, basepath_end);
-       add_hotplug_env_var(envp, num_envp, &i,
-                           buffer, buffer_size, &length,
-                           "XENBUS_FRONTEND_ID=%s", frontend_id);
-       kfree(frontend_id);
-
-       /* terminate, set to next free slot, shrink available space */
-       envp[i] = NULL;
-       envp = &envp[i];
-       num_envp -= i;
-       buffer = &buffer[length];
-       buffer_size -= length;
-
-       if (drv && drv->hotplug)
-               return drv->hotplug(xdev, envp, num_envp, buffer,
-                                   buffer_size);
-
-       return 0;
-}
-
+                                 int num_envp, char *buffer, int buffer_size);
 static int xenbus_probe_backend(const char *type, const char *domid);
 static struct xen_bus_type xenbus_backend = {
        .root = "backend",
@@ -304,6 +239,52 @@
        },
 };
 
+static int xenbus_hotplug_backend(struct device *dev, char **envp,
+                                 int num_envp, char *buffer, int buffer_size)
+{
+       struct xenbus_device *xdev;
+       struct xenbus_driver *drv;
+       int i = 0;
+       int length = 0;
+
+       DPRINTK("");
+
+       if (dev == NULL)
+               return -ENODEV;
+
+       xdev = to_xenbus_device(dev);
+       if (xdev == NULL)
+               return -ENODEV;
+
+       /* stuff we want to pass to /sbin/hotplug */
+       add_hotplug_env_var(envp, num_envp, &i,
+                           buffer, buffer_size, &length,
+                           "XENBUS_TYPE=%s", xdev->devicetype);
+
+       add_hotplug_env_var(envp, num_envp, &i,
+                           buffer, buffer_size, &length,
+                           "XENBUS_PATH=%s", xdev->nodename);
+
+       add_hotplug_env_var(envp, num_envp, &i,
+                           buffer, buffer_size, &length,
+                           "XENBUS_BASE_PATH=%s", xenbus_backend.root);
+
+       /* terminate, set to next free slot, shrink available space */
+       envp[i] = NULL;
+       envp = &envp[i];
+       num_envp -= i;
+       buffer = &buffer[length];
+       buffer_size -= length;
+
+       if (dev->driver) {
+               drv = to_xenbus_driver(dev->driver);
+               if (drv && drv->hotplug)
+                       return drv->hotplug(xdev, envp, num_envp, buffer,
+                                           buffer_size);
+       }
+
+       return 0;
+}
 
 static void otherend_changed(struct xenbus_watch *watch,
                             const char **vec, unsigned int len)
diff -r 91046e4a49dd -r 5f574f9cb4bd tools/examples/block
--- a/tools/examples/block      Wed Dec  7 11:51:31 2005
+++ b/tools/examples/block      Wed Dec  7 11:57:26 2005
@@ -89,12 +89,12 @@
     fi
   done
 
-  for dom in $(xenstore-list "$XENBUS_BASE_PATH")
+  local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE"
+  for dom in $(xenstore-list "$base_path")
   do
-    for dev in $(xenstore-list "$XENBUS_BASE_PATH/$dom")
+    for dev in $(xenstore-list "$base_path/$dom")
     do
-      d=$(xenstore_read_default \
-            "$XENBUS_BASE_PATH/$dom/$dev/physical-device" "")
+      d=$(xenstore_read_default "$base_path/$dom/$dev/physical-device" "")
 
       if [ "$d" == "$devmm" ]
       then
@@ -106,7 +106,7 @@
             return
           fi
         else
-          local m=$(xenstore_read "$XENBUS_BASE_PATH/$dom/$dev/mode")
+          local m=$(xenstore_read "$base_path/$dom/$dev/mode")
           m=$(canonicalise_mode "$m")
 
           if [ "$m" == 'w' ]
@@ -128,12 +128,10 @@
 
 same_vm()
 {
-  local thisdom="$XENBUS_FRONTEND_ID"
   local otherdom="$1"
-  local thisvm=$(xenstore-read "/local/domain/$thisdom/vm")
   local othervm=$(xenstore-read "/local/domain/$otherdom/vm")
 
-  [ "$thisvm" == "$othervm" ]
+  [ "$FRONTEND_UUID" == "$othervm" ]
 }
 
 
@@ -240,6 +238,9 @@
     case $t in 
       phy)
         dev=$(expand_dev $p)
+        FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id")
+        FRONTEND_UUID=$(xenstore_read_default \
+            "/local/domain/$FRONTEND_ID/vm" 'unknown')
         claim_lock "block"
         check_device_sharing "$dev" "$mode"
        write_dev "$dev"

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Tidy up use of environment variables in xenbus-hotplug interaction., Xen patchbot -unstable <=