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] libxl: use libxl__device in libxl_devices

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl: use libxl__device in libxl_devices_destroy etc.
From: Xen patchbot-unstable <patchbot@xxxxxxx>
Date: Tue, 01 Nov 2011 23:55:17 +0000
Delivery-date: Tue, 01 Nov 2011 16:57:03 -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 Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1318941402 -3600
# Node ID 3d4e9f0daad6f6c6b5f18672ca6534bc5a56ceda
# Parent  b26fc82addde34fc36e95e21dc566a1104e5042a
libxl: use libxl__device in libxl_devices_destroy etc.

Use libxl__device in libxl_devices_destroy and
libxl__device_pci_remove_xenstore.

Doing this allows us to use the common functions for removing devices.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
---


diff -r b26fc82addde -r 3d4e9f0daad6 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c        Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/libxl_device.c        Tue Oct 18 13:36:42 2011 +0100
@@ -49,6 +49,25 @@
                           device->domid, device->devid);
 }
 
+int libxl__parse_backend_path(libxl__gc *gc,
+                              const char *path,
+                              libxl__device *dev)
+{
+    /* /local/domain/<domid>/backend/<kind>/<domid>/<devid> */
+    char strkind[16]; /* Longest is actually "console" */
+    uint32_t domain;
+    int rc = sscanf(path, "/local/domain/%d/backend/%15[^/]/%d/%d",
+                    &dev->backend_domid,
+                    strkind,
+                    &domain,
+                    &dev->backend_devid);
+
+    if (rc != 4)
+        return ERROR_FAIL;
+
+    return libxl__device_kind_from_string(strkind, &dev->backend_kind);
+}
+
 int libxl__device_generic_add(libxl__gc *gc, libxl__device *device,
                              char **bents, char **fents)
 {
@@ -348,10 +367,11 @@
     return -1;
 }
 
-int libxl__device_remove(libxl__gc *gc, char *be_path)
+int libxl__device_remove(libxl__gc *gc, libxl__device *dev)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     xs_transaction_t t;
+    char *be_path = libxl__device_backend_path(gc, dev);
     char *state_path = libxl__sprintf(gc, "%s/state", be_path);
     char *state = libxl__xs_read(gc, XBT_NULL, state_path);
     int rc = 0;
@@ -429,10 +449,12 @@
 int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
-    char *path, *be_path, *fe_path;
+    char *path;
     unsigned int num1, num2;
     char **l1 = NULL, **l2 = NULL;
     int i, j, n_watches = 0;
+    libxl__device dev;
+    libxl__device_kind kind;
 
     path = libxl__sprintf(gc, "/local/domain/%d/device", domid);
     l1 = libxl__xs_directory(gc, XBT_NULL, path, &num1);
@@ -445,22 +467,25 @@
         num1 = 0;
     }
     for (i = 0; i < num1; i++) {
-        if (!strcmp("vfs", l1[i]))
+        if (libxl__device_kind_from_string(l1[i], &kind))
             continue;
         path = libxl__sprintf(gc, "/local/domain/%d/device/%s", domid, l1[i]);
         l2 = libxl__xs_directory(gc, XBT_NULL, path, &num2);
         if (!l2)
             continue;
         for (j = 0; j < num2; j++) {
-            fe_path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s", 
domid, l1[i], l2[j]);
-            be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, 
"%s/backend", fe_path));
-            if (be_path != NULL) {
+            path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s/backend",
+                                  domid, l1[i], l2[j]);
+            path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, path));
+            if (path && libxl__parse_backend_path(gc, path, &dev) == 0) {
+                dev.domid = domid;
+                dev.kind = kind;
+                dev.devid = atoi(l2[j]);
+
                 if (force) {
-                    xs_rm(ctx->xsh, XBT_NULL, be_path);
-                    xs_rm(ctx->xsh, XBT_NULL, fe_path);
-                    libxl__device_destroy_tapdisk(gc, be_path);
+                    libxl__device_destroy(gc, &dev);
                 } else {
-                    if (libxl__device_remove(gc, be_path) > 0)
+                    if (libxl__device_remove(gc, &dev) > 0)
                         n_watches++;
                 }
             }
@@ -468,14 +493,18 @@
     }
 
     /* console 0 frontend directory is not under /local/domain/<domid>/device 
*/
-    fe_path = libxl__sprintf(gc, "/local/domain/%d/console", domid);
-    be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", 
fe_path));
-    if (be_path && strcmp(be_path, "")) {
+    path = libxl__sprintf(gc, "/local/domain/%d/console/backend", domid);
+    path = libxl__xs_read(gc, XBT_NULL, path);
+    if (path && strcmp(path, "") &&
+        libxl__parse_backend_path(gc, path, &dev) == 0) {
+        dev.domid = domid;
+        dev.kind = LIBXL__DEVICE_KIND_CONSOLE;
+        dev.devid = 0;
+
         if (force) {
-            xs_rm(ctx->xsh, XBT_NULL, be_path);
-            xs_rm(ctx->xsh, XBT_NULL, fe_path);
+            libxl__device_destroy(gc, &dev);
         } else {
-            if (libxl__device_remove(gc, be_path) > 0)
+            if (libxl__device_remove(gc, &dev) > 0)
                 n_watches++;
         }
     }
@@ -505,12 +534,9 @@
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     struct timeval tv;
-    char *backend_path;
     int rc;
 
-    backend_path = libxl__device_backend_path(gc, dev);
-
-    rc = libxl__device_remove(gc, backend_path);
+    rc = libxl__device_remove(gc, dev);
     if (rc == -1) {
         rc = ERROR_FAIL;
         goto out;
diff -r b26fc82addde -r 3d4e9f0daad6 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/libxl_internal.h      Tue Oct 18 13:36:42 2011 +0100
@@ -240,8 +240,10 @@
                              char **bents, char **fents);
 _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
 _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device 
*device);
+_hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path,
+                                      libxl__device *dev);
 _hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev);
-_hidden int libxl__device_remove(libxl__gc *gc, char *be_path);
+_hidden int libxl__device_remove(libxl__gc *gc, libxl__device *dev);
 _hidden int libxl__device_destroy(libxl__gc *gc, libxl__device *dev);
 _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force);
 _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);
diff -r b26fc82addde -r 3d4e9f0daad6 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c   Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/libxl_pci.c   Tue Oct 18 13:36:42 2011 +0100
@@ -410,9 +410,15 @@
             goto retry_transaction2;
 
     if (num == 1) {
-        char *fe_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, 
"%s/frontend", be_path));
-        xs_rm(ctx->xsh, XBT_NULL, be_path);
-        xs_rm(ctx->xsh, XBT_NULL, fe_path);
+        libxl__device dev;
+        if (libxl__parse_backend_path(gc, be_path, &dev) != 0)
+            return ERROR_FAIL;
+
+        dev.domid = domid;
+        dev.kind = LIBXL__DEVICE_KIND_PCI;
+        dev.devid = 0;
+
+        libxl__device_destroy(gc, &dev);
         return 0;
     }
 

_______________________________________________
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] libxl: use libxl__device in libxl_devices_destroy etc., Xen patchbot-unstable <=