# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1317389248 -3600
# Node ID e8cff01ad4b5519be66e726db124cbdfab4f1e04
# Parent ed800095162c2d459ba6bdd651ef6f246858c458
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 ed800095162c -r e8cff01ad4b5 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c Fri Sep 30 14:27:28 2011 +0100
@@ -959,7 +959,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:
@@ -972,7 +972,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);
@@ -991,7 +991,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);
@@ -1054,13 +1054,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",
@@ -1070,7 +1070,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
@@ -1218,10 +1218,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));
@@ -1281,10 +1281,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);
@@ -1483,10 +1483,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));
@@ -1574,10 +1574,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));
@@ -1861,10 +1861,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 ed800095162c -r e8cff01ad4b5 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_device.c Fri Sep 30 14:27:28 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 ed800095162c -r e8cff01ad4b5 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_internal.h Fri Sep 30 14:27:28 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 ed800095162c -r e8cff01ad4b5 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_pci.c Fri Sep 30 14:27:28 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 ed800095162c -r e8cff01ad4b5 tools/libxl/libxl_types_internal.idl
--- a/tools/libxl/libxl_types_internal.idl Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_types_internal.idl Fri Sep 30 14:27:28 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
|