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-devel

[Xen-devel] [PATCH 15 of 27 v3] libxl: use IDL to define device front- a

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 15 of 27 v3] libxl: use IDL to define device front- and back-end kinds
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Tue, 18 Oct 2011 13:55:10 +0100
Cc: ian.jackson@xxxxxxxxxx
Delivery-date: Tue, 18 Oct 2011 06:35:43 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1318942495@xxxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1318942495@xxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1318941402 -3600
# Node ID 7f1e0391462078ee1bf572722e958b2ed0e966ef
# Parent  89233ed65eced3ca2ef6cc1cce7abcdd3e5439e9
libxl: use IDL to define device front- and back-end kinds

I'd like to use the from_string functionality...

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 89233ed65ece -r 7f1e03914620 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/libxl.c       Tue Oct 18 13:36:42 2011 +0100
@@ -962,7 +962,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
     device.backend_domid = disk->backend_domid;
     device.devid = devid;
     device.domid = domid;
-    device.kind = DEVICE_VBD;
+    device.kind = LIBXL__DEVICE_KIND_VBD;
 
     switch (disk->backend) {
         case LIBXL_DISK_BACKEND_PHY:
@@ -975,7 +975,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
             flexarray_append(back, "params");
             flexarray_append(back, dev);
 
-            device.backend_kind = DEVICE_VBD;
+            device.backend_kind = LIBXL__DEVICE_KIND_VBD;
             break;
         case LIBXL_DISK_BACKEND_TAP:
             dev = libxl__blktap_devpath(&gc, disk->pdev_path, disk->format);
@@ -994,7 +994,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
             flexarray_append(back, "params");
             flexarray_append(back, libxl__sprintf(&gc, "%s:%s",
                           libxl__device_disk_string_of_format(disk->format), 
disk->pdev_path));
-            device.backend_kind = DEVICE_QDISK;
+            device.backend_kind = LIBXL__DEVICE_KIND_QDISK;
             break;
         default:
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: 
%d\n", disk->backend);
@@ -1057,13 +1057,13 @@ int libxl_device_disk_del(libxl_ctx *ctx
 
     switch (disk->backend) {
         case LIBXL_DISK_BACKEND_PHY:
-            device.backend_kind = DEVICE_VBD;
+            device.backend_kind = LIBXL__DEVICE_KIND_VBD;
             break;
         case LIBXL_DISK_BACKEND_TAP:
-            device.backend_kind = DEVICE_VBD;
+            device.backend_kind = LIBXL__DEVICE_KIND_VBD;
             break;
         case LIBXL_DISK_BACKEND_QDISK:
-            device.backend_kind = DEVICE_QDISK;
+            device.backend_kind = LIBXL__DEVICE_KIND_QDISK;
             break;
         default:
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: 
%d\n",
@@ -1073,7 +1073,7 @@ int libxl_device_disk_del(libxl_ctx *ctx
     }
     device.domid            = domid;
     device.devid            = devid;
-    device.kind             = DEVICE_VBD;
+    device.kind             = LIBXL__DEVICE_KIND_VBD;
     if (wait)
         rc = libxl__device_del(&gc, &device);
     else
@@ -1221,10 +1221,10 @@ int libxl_device_nic_add(libxl_ctx *ctx,
 
     device.backend_devid = nic->devid;
     device.backend_domid = nic->backend_domid;
-    device.backend_kind = DEVICE_VIF;
+    device.backend_kind = LIBXL__DEVICE_KIND_VIF;
     device.devid = nic->devid;
     device.domid = domid;
-    device.kind = DEVICE_VIF;
+    device.kind = LIBXL__DEVICE_KIND_VIF;
 
     flexarray_append(back, "frontend-id");
     flexarray_append(back, libxl__sprintf(&gc, "%d", domid));
@@ -1284,10 +1284,10 @@ int libxl_device_nic_del(libxl_ctx *ctx,
 
     device.backend_devid    = nic->devid;
     device.backend_domid    = nic->backend_domid;
-    device.backend_kind     = DEVICE_VIF;
+    device.backend_kind     = LIBXL__DEVICE_KIND_VIF;
     device.devid            = nic->devid;
     device.domid            = domid;
-    device.kind             = DEVICE_VIF;
+    device.kind             = LIBXL__DEVICE_KIND_VIF;
 
     if (wait)
         rc = libxl__device_del(&gc, &device);
@@ -1486,10 +1486,10 @@ int libxl__device_console_add(libxl__gc 
 
     device.backend_devid = console->devid;
     device.backend_domid = console->backend_domid;
-    device.backend_kind = DEVICE_CONSOLE;
+    device.backend_kind = LIBXL__DEVICE_KIND_CONSOLE;
     device.devid = console->devid;
     device.domid = domid;
-    device.kind = DEVICE_CONSOLE;
+    device.kind = LIBXL__DEVICE_KIND_CONSOLE;
 
     flexarray_append(back, "frontend-id");
     flexarray_append(back, libxl__sprintf(gc, "%d", domid));
@@ -1577,10 +1577,10 @@ int libxl_device_vkb_add(libxl_ctx *ctx,
 
     device.backend_devid = vkb->devid;
     device.backend_domid = vkb->backend_domid;
-    device.backend_kind = DEVICE_VKBD;
+    device.backend_kind = LIBXL__DEVICE_KIND_VKBD;
     device.devid = vkb->devid;
     device.domid = domid;
-    device.kind = DEVICE_VKBD;
+    device.kind = LIBXL__DEVICE_KIND_VKBD;
 
     flexarray_append(back, "frontend-id");
     flexarray_append(back, libxl__sprintf(&gc, "%d", domid));
@@ -1864,10 +1864,10 @@ int libxl_device_vfb_add(libxl_ctx *ctx,
 
     device.backend_devid = vfb->devid;
     device.backend_domid = vfb->backend_domid;
-    device.backend_kind = DEVICE_VFB;
+    device.backend_kind = LIBXL__DEVICE_KIND_VFB;
     device.devid = vfb->devid;
     device.domid = domid;
-    device.kind = DEVICE_VFB;
+    device.kind = LIBXL__DEVICE_KIND_VFB;
 
     flexarray_append_pair(back, "frontend-id", libxl__sprintf(&gc, "%d", 
domid));
     flexarray_append_pair(back, "online", "1");
diff -r 89233ed65ece -r 7f1e03914620 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
@@ -24,30 +24,20 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-
 #include "libxl.h"
 #include "libxl_internal.h"
 
-static const char *string_of_kinds[] = {
-    [DEVICE_VIF] = "vif",
-    [DEVICE_VBD] = "vbd",
-    [DEVICE_QDISK] = "qdisk",
-    [DEVICE_PCI] = "pci",
-    [DEVICE_VFB] = "vfb",
-    [DEVICE_VKBD] = "vkbd",
-    [DEVICE_CONSOLE] = "console",
-};
-
 char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device)
 {
     char *dom_path = libxl__xs_get_dompath(gc, device->domid);
 
     /* Console 0 is a special case */
-    if (device->kind == DEVICE_CONSOLE && device->devid == 0)
+    if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0)
         return libxl__sprintf(gc, "%s/console", dom_path);
 
     return libxl__sprintf(gc, "%s/device/%s/%d", dom_path,
-                          string_of_kinds[device->kind], device->devid);
+                          libxl__device_kind_to_string(device->kind),
+                          device->devid);
 }
 
 char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device)
@@ -55,7 +45,7 @@ char *libxl__device_backend_path(libxl__
     char *dom_path = libxl__xs_get_dompath(gc, device->backend_domid);
 
     return libxl__sprintf(gc, "%s/backend/%s/%u/%d", dom_path,
-                          string_of_kinds[device->backend_kind],
+                          libxl__device_kind_to_string(device->backend_kind),
                           device->domid, device->devid);
 }
 
@@ -67,12 +57,6 @@ int libxl__device_generic_add(libxl__gc 
     xs_transaction_t t;
     struct xs_permissions frontend_perms[2];
     struct xs_permissions backend_perms[2];
-    int rc;
-
-    if (!is_valid_device_kind(device->backend_kind) || 
!is_valid_device_kind(device->kind)) {
-        rc = ERROR_INVAL;
-        goto out;
-    }
 
     frontend_path = libxl__device_frontend_path(gc, device);
     backend_path = libxl__device_backend_path(gc, device);
@@ -113,9 +97,8 @@ retry_transaction:
         else
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xs transaction failed");
     }
-    rc = 0;
-out:
-    return rc;
+
+    return 0;
 }
 
 typedef struct {
diff -r 89233ed65ece -r 7f1e03914620 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
@@ -97,25 +97,13 @@ struct libxl__ctx {
     libxl_version_info version_info;
 };
 
-typedef enum {
-    DEVICE_VIF = 1,
-    DEVICE_VBD,
-    DEVICE_QDISK,
-    DEVICE_PCI,
-    DEVICE_VFB,
-    DEVICE_VKBD,
-    DEVICE_CONSOLE,
-} libxl__device_kinds;
-
-#define is_valid_device_kind(kind) (((kind) >= DEVICE_VIF) && ((kind) <= 
DEVICE_CONSOLE))
-
 typedef struct {
     uint32_t backend_devid;
     uint32_t backend_domid;
     uint32_t devid;
     uint32_t domid;
-    libxl__device_kinds backend_kind;
-    libxl__device_kinds kind;
+    libxl__device_kind backend_kind;
+    libxl__device_kind kind;
 } libxl__device;
 
 #define XC_PCI_BDF             "0x%x, 0x%x, 0x%x, 0x%x"
diff -r 89233ed65ece -r 7f1e03914620 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
@@ -244,10 +244,10 @@ int libxl__create_pci_backend(libxl__gc 
     /* add pci device */
     device.backend_devid = 0;
     device.backend_domid = 0;
-    device.backend_kind = DEVICE_PCI;
+    device.backend_kind = LIBXL__DEVICE_KIND_PCI;
     device.devid = 0;
     device.domid = domid;
-    device.kind = DEVICE_PCI;
+    device.kind = LIBXL__DEVICE_KIND_PCI;
 
     flexarray_append_pair(back, "frontend-id", libxl__sprintf(gc, "%d", 
domid));
     flexarray_append_pair(back, "online", "1");
diff -r 89233ed65ece -r 7f1e03914620 tools/libxl/libxl_types_internal.idl
--- a/tools/libxl/libxl_types_internal.idl      Tue Oct 18 13:36:42 2011 +0100
+++ b/tools/libxl/libxl_types_internal.idl      Tue Oct 18 13:36:42 2011 +0100
@@ -1,9 +1,19 @@
 namespace("libxl__")
 
-libxl__qmp_message_type  = Enumeration("qmp_message_type", [
+libxl__qmp_message_type = Enumeration("qmp_message_type", [
     (1, "QMP"),
     (2, "return"),
     (3, "error"),
     (4, "event"),
     (5, "invalid"),
     ])
+
+libxl__device_kind = Enumeration("device_kind", [
+    (1, "VIF"),
+    (2, "VBD"),
+    (3, "QDISK"),
+    (4, "PCI"),
+    (5, "VFB"),
+    (6, "VKBD"),
+    (7, "CONSOLE"),
+    ])

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