Skip to contentSkip to conversation

more solidification work

PATCH New Vincent Hanquez 1 participant 6 messages Jan 13, 2010

lore
Share & tools
lore
#0 lore raw

cover more solidification work

more solidification work around return values in stubdom, invalid device kinds, and fix name to domid. nothing ground breaking but quite nice to have.

Vincent Hanquez (5):
add some return values testing in stubdom
initialize enum to 1, to prevent defaulting to the 0 values when
structure when not properly initialized by the client.
add fuse around generic_device_add related to invalid kinds add error in disk_add if phystype is not recognized fix name to domid conversion.

 tools/libxl/libxl.c          |   38 ++++++++++++++++++++++++++++----------
 tools/libxl/libxl.h          |    6 +++---
 tools/libxl/libxl_device.c   |    5 ++++-
 tools/libxl/libxl_internal.h |    4 ++--
 tools/libxl/libxl_utils.c    |   33 +++++++++++----------------------
 tools/libxl/xl.c             |    4 +---
 6 files changed, 49 insertions(+), 41 deletions(-)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

PATCH 1/5 add some return values testing in stubdom

---
 tools/libxl/libxl.c |   35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)
tools/libxl/libxl.c +25 -10
index df3ddc0..ede485b 100644
@@ -824,7 +824,7 @@ static int libxl_create_stubdom(struct libxl_ctx *ctx,
                                 libxl_device_vkb *vkb,
                                 libxl_device_model_starting **starting_r)
 {
-    int i, num_console = 1;
+    int i, num_console = 1, ret;
     libxl_device_console *console;
     libxl_domain_create_info c_info;
     libxl_domain_build_info b_info;
@@ -855,12 +855,18 @@ static int libxl_create_stubdom(struct libxl_ctx *ctx,
     b_info.u.pv.features = "";
     b_info.hvm = 0;
 
-    libxl_domain_make(ctx, &c_info, &domid);
-    libxl_domain_build(ctx, &b_info, domid, &state);
+    ret = libxl_domain_make(ctx, &c_info, &domid);
+    if (ret) return ret;
+    ret = libxl_domain_build(ctx, &b_info, domid, &state);
+    if (ret) return ret;
 
     libxl_write_dmargs(ctx, domid, info->domid, args);
-    libxl_xs_write(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/image/device-model-domid", libxl_xs_get_dompath(ctx, info->domid)), "%d", domid);
-    libxl_xs_write(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/target", libxl_xs_get_dompath(ctx, domid)), "%d", info->domid);
+    libxl_xs_write(ctx, XBT_NULL,
+                   libxl_sprintf(ctx, "%s/image/device-model-domid", libxl_xs_get_dompath(ctx, info->domid)),
+                   "%d", domid);
+    libxl_xs_write(ctx, XBT_NULL,
+                   libxl_sprintf(ctx, "%s/target", libxl_xs_get_dompath(ctx, domid)),
+                   "%d", info->domid);
     xc_domain_set_target(ctx->xch, domid, info->domid);
     xs_set_target(ctx->xsh, domid, info->domid);
 
@@ -880,27 +886,36 @@ retry_transaction:
 
     for (i = 0; i < num_disks; i++) {
         disks[i].domid = domid;
-        libxl_device_disk_add(ctx, domid, &disks[i]);
+        ret = libxl_device_disk_add(ctx, domid, &disks[i]);
+        if (ret) return ret;
     }
     for (i = 0; i < num_vifs; i++) {
         vifs[i].domid = domid;
-        libxl_device_nic_add(ctx, domid, &vifs[i]);
+        ret = libxl_device_nic_add(ctx, domid, &vifs[i]);
+        if (ret) return ret;
     }
     vfb->domid = domid;
-    libxl_device_vfb_add(ctx, domid, vfb);
+    ret = libxl_device_vfb_add(ctx, domid, vfb);
+    if (ret) return ret;
     vkb->domid = domid;
-    libxl_device_vkb_add(ctx, domid, vkb);
+    ret = libxl_device_vkb_add(ctx, domid, vkb);
+    if (ret) return ret;
 
     if (info->serial)
         num_console++;
+
     console = libxl_calloc(ctx, num_console, sizeof(libxl_device_console));
+    if (!console)
+        return ERROR_NOMEM;
+
     for (i = 0; i < num_console; i++) {
         console[i].devid = i;
         console[i].constype = CONSTYPE_IOEMU;
         console[i].domid = domid;
         if (!i)
             console[i].build_state = &state;
-        libxl_device_console_add(ctx, domid, &console[i]);
+        ret = libxl_device_console_add(ctx, domid, &console[i]);
+        if (ret) return ret;
     }
     if (libxl_create_xenpv_qemu(ctx, vfb, num_console, console, &dm_starting) < 0) {
         free(args);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw

PATCH 2/5 initialize enum to 1, to prevent defaulting to the 0 values when structure when not properly initialized by the client.

In reply to Vincent Hanquez
---
 tools/libxl/libxl.h          |    6 +++---
 tools/libxl/libxl_internal.h |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
tools/libxl/libxl.h +3 -3
index 529dbd6..25a66d9 100644
@@ -104,7 +104,7 @@ typedef struct {
 } libxl_domain_suspend_info;
 
 typedef enum {
-    XENFV,
+    XENFV = 1,
     XENPV,
 } libxl_qemu_machine_type;
 
@@ -169,7 +169,7 @@ typedef struct {
 } libxl_device_console;
 
 typedef enum {
-    PHYSTYPE_QCOW,
+    PHYSTYPE_QCOW = 1,
     PHYSTYPE_QCOW2,
     PHYSTYPE_VHD,
     PHYSTYPE_AIO,
@@ -189,7 +189,7 @@ typedef struct {
 } libxl_device_disk;
 
 typedef enum {
-    NICTYPE_IOEMU,
+    NICTYPE_IOEMU = 1,
     NICTYPE_VIF,
 } libxl_nic_type;
 
tools/libxl/libxl_internal.h +1 -1
index 7664e59..11698bc 100644
@@ -59,7 +59,7 @@ void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file,
 
 
 typedef enum {
-    DEVICE_VIF,
+    DEVICE_VIF = 1,
     DEVICE_VBD,
     DEVICE_TAP,
     DEVICE_PCI,

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw

PATCH 3/5 add fuse around generic_device_add related to invalid kinds

In reply to Vincent Hanquez

prevent segfault in case the backend or frontend kinds have not been set to a correct kind value (or not initilized).

---
 tools/libxl/libxl_device.c   |    5 ++++-
 tools/libxl/libxl_internal.h |    2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)
tools/libxl/libxl_device.c +4 -1
index 7bbc924..726c543 100644
@@ -26,7 +26,7 @@
 #include "libxl.h"
 #include "libxl_internal.h"
 
-const char *string_of_kinds[] = {
+static const char *string_of_kinds[] = {
     [DEVICE_VIF] = "vif",
     [DEVICE_VBD] = "vbd",
     [DEVICE_TAP] = "tap",
@@ -45,6 +45,9 @@ int libxl_device_generic_add(struct libxl_ctx *ctx, libxl_device *device,
     struct xs_permissions backend_perms[2];
     struct xs_permissions hotplug_perms[1];
 
+    if (!is_valid_device_kind(device->backend_kind) || !is_valid_device_kind(device->kind))
+        return ERROR_INVAL;
+
     dom_path_backend = libxl_xs_get_dompath(ctx, device->backend_domid);
     dom_path = libxl_xs_get_dompath(ctx, device->domid);
 
tools/libxl/libxl_internal.h +1 -1
index 11698bc..34f2e38 100644
@@ -68,7 +68,7 @@ typedef enum {
     DEVICE_CONSOLE,
 } libxl_device_kinds;
 
-extern const char *string_of_kinds[];
+#define is_valid_device_kind(kind) (((kind) >= DEVICE_VIF) && ((kind) <= DEVICE_CONSOLE))
 
 typedef struct {
     uint32_t backend_devid;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#4 lore raw

PATCH 4/5 add error in disk_add if phystype is not recognized

In reply to Vincent Hanquez
---
 tools/libxl/libxl.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
tools/libxl/libxl.c +3 -0
index ede485b..909bd17 100644
@@ -1162,6 +1162,9 @@ int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_di
 
             device.backend_kind = DEVICE_TAP;
             break;
+        default:
+            XL_LOG(ctx, XL_LOG_ERROR, "unrecognized disk physical type: %d\n", disk->phystype);
+            return ERROR_INVAL;
     }
 
     flexarray_set(back, boffset++, "frontend-id");

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw

PATCH 5/5 fix name to domid conversion.

In reply to Vincent Hanquez

also simplify massively the function that iterate over all domains to find the corresponding domid to a name.

---
 tools/libxl/libxl_utils.c |   33 +++++++++++----------------------
 tools/libxl/xl.c          |    4 +---
 2 files changed, 12 insertions(+), 25 deletions(-)
tools/libxl/libxl_utils.c +12 -23
index 36c1c47..eca4347 100644
@@ -56,34 +56,23 @@ char *libxl_domid_to_name(struct libxl_ctx *ctx, uint32_t domid)
 
 int libxl_name_to_domid(struct libxl_ctx *ctx, char *name, uint32_t *domid)
 {
-    unsigned int num, len;
-    char path[strlen("/local/domain") + 12];
-    int i, j, nb_domains;
-    char *domname, **l;
+    int i, nb_domains;
+    char *domname;
     struct libxl_dominfo *dominfo;
 
     dominfo = libxl_domain_list(ctx, &nb_domains);
-
-    l = xs_directory(ctx->xsh, XBT_NULL, "/local/domain", &num);
-    for (i = 0; i < num; i++) {
-        snprintf(path, sizeof(path), "/local/domain/%s/name", l[i]);
-        domname = xs_read(ctx->xsh, XBT_NULL, path, &len);
-        if (domname != NULL && len == strlen(name) && !strncmp(domname, name, len)) {
-            int domid_i = atoi(l[i]);
-            for (j = 0; j < nb_domains; j++) {
-                if (dominfo[j].domid == domid_i) {
-                    *domid = domid_i;
-                    free(dominfo);
-                    free(l);
-                    free(domname);
-                    return 0;
-                }
-            }
+    if (!dominfo)
+        return ERROR_NOMEM;
+
+    for (i = 0; i < nb_domains; i++) {
+        domname = libxl_domid_to_name(ctx, dominfo[i].domid);
+        if (!domname)
+            continue;
+        if (strcmp(domname, name) == 0) {
+            *domid = dominfo[i].domid;
+            return 0;
         }
-        free(domname);
     }
-    free(dominfo);
-    free(l);
     return -1;
 }
 
tools/libxl/xl.c +1 -3
index 90896f3..1e95ac5 100644
@@ -59,9 +59,7 @@ static int domain_qualifier_to_domid(struct libxl_ctx *ctx, char *p, uint32_t *d
         }
     }
 
-    if (i == 0)
-        return -1;
-    if (alldigit) {
+    if (i > 0 && alldigit) {
         *domid = strtoul(p, NULL, 10);
         return 0;
     } else {

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel