Skip to contentSkip to conversation

backport libxl from xen-unstable to xen-4.0-testing

PATCH In review Gianni Tedesco 3 participants 9 messages Jul 5, 2010 – Jul 8, 2010

lore
Share & tools
lore
#0 lore raw

cover backport libxl from xen-unstable to xen-4.0-testing

Hi,

Following patch does what it says on the tin. It's a straightforward backport of libxl to xen-4.0-testing. This buys harmony of functionality between the two trees with the minimal of disruption to anything outside tools/libxl.

The backport is therefore modulo features such as blktap2, vif2, cpupools, numa, sched2, libxc logging API changes and so forth. To ease review process I have attached a patch between the post-backport libxl. DO NOT ATTEMPT TO APPLY THIS ONE :)

Makefile | 4

 libxl.c          |  320 +++++++++++++++++++++++++++++++++++++++++--------------
 libxl.h          |   57 ++++++++-
 libxl_device.c   |    6 -
 libxl_dom.c      |    6 -
 libxl_exec.c     |    3 
 libxl_internal.c |   44 +++----
 libxl_internal.h |   25 +++-
 libxl_utils.c    |   86 ++++++++++++++
 libxl_utils.h    |   11 -
 xenguest.c       |    2 
 xl.c             |   45 ++++---
 xl.h             |   12 +-
 xl_cmdimpl.c     |  300 +++++++++++++++++++++++++++++++++++++++++++++++++--
 xl_cmdtable.c    |   18 +++
 15 files changed, 777 insertions(+), 162 deletions(-)
tools/libxl/libxl.c +244 -76
diff -pud -x '*.d' xen-4.0-testing.hg/tools/libxl/libxl.c xen-unstable.hg/tools/libxl/libxl.c
@@ -33,28 +33,34 @@
 #include "libxl_utils.h"
 #include "libxl_internal.h"
 #include "flexarray.h"
+#include "tap-ctl.h"
 
 #define PAGE_TO_MEMKB(pages) ((pages) * 4)
 
-int libxl_ctx_init(struct libxl_ctx *ctx, int version)
+int libxl_ctx_init(struct libxl_ctx *ctx, int version, xentoollog_logger *lg)
 {
     if (version != LIBXL_VERSION)
         return ERROR_VERSION;
     memset(ctx, 0, sizeof(struct libxl_ctx));
+    ctx->lg = lg;
     ctx->alloc_maxsize = 256;
     ctx->alloc_ptrs = calloc(ctx->alloc_maxsize, sizeof(void *));
     if (!ctx->alloc_ptrs)
         return ERROR_NOMEM;
     memset(&ctx->version_info, 0, sizeof(libxl_version_info));
 
-    ctx->xch = xc_interface_open();
-    if (ctx->xch == -1) {
+    ctx->xch = xc_interface_open(lg,lg,0);
+    if (!ctx->xch) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, errno, 
+                        "cannot open libxc handle");
         free(ctx->alloc_ptrs);
         return ERROR_FAIL;
     }
 
     ctx->xsh = xs_daemon_open();
     if (!ctx->xsh) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, errno, 
+                        "cannot connect to xenstore");
         xc_interface_close(ctx->xch);
         free(ctx->alloc_ptrs);
         return ERROR_FAIL;
@@ -71,13 +77,6 @@ int libxl_ctx_free(struct libxl_ctx *ctx
     return 0;
 }
 
-int libxl_ctx_set_log(struct libxl_ctx *ctx, libxl_log_callback log_callback, void *log_data)
-{
-    ctx->log_callback = log_callback;
-    ctx->log_userdata = log_data;
-    return 0;
-}
-
 /******************************************************************************/
 
 int libxl_domain_make(struct libxl_ctx *ctx, libxl_domain_create_info *info,
@@ -111,6 +110,12 @@ int libxl_domain_make(struct libxl_ctx *
         return ERROR_FAIL;
     }
 
+    ret = xc_cpupool_movedomain(ctx->xch, info->poolid, *domid);
+    if (ret < 0) {
+        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, ret, "domain move fail");
+        return ERROR_FAIL;
+    }
+
     dom_path = libxl_xs_get_dompath(ctx, *domid);
     if (!dom_path)
         return ERROR_FAIL;
@@ -163,6 +168,8 @@ retry_transaction:
 
     xs_write(ctx->xsh, t, libxl_sprintf(ctx, "%s/uuid", vm_path), uuid_string, strlen(uuid_string));
     xs_write(ctx->xsh, t, libxl_sprintf(ctx, "%s/name", vm_path), info->name, strlen(info->name));
+    if (info->poolname)
+        xs_write(ctx->xsh, t, libxl_sprintf(ctx, "%s/pool_name", vm_path), info->poolname, strlen(info->poolname));
 
     libxl_xs_writev(ctx, t, dom_path, info->xsdata);
     libxl_xs_writev(ctx, t, libxl_sprintf(ctx, "%s/platform", dom_path), info->platformdata);
@@ -443,6 +450,26 @@ int libxl_domain_info(struct libxl_ctx *
     return 0;
 }
 
+struct libxl_poolinfo * libxl_list_pool(struct libxl_ctx *ctx, int *nb_pool)
+{
+    struct libxl_poolinfo *ptr;
+    int i, ret;
+    xc_cpupoolinfo_t info[256];
+    int size = 256;
+
+    ptr = calloc(size, sizeof(struct libxl_poolinfo));
+    if (!ptr) return NULL;
+
+    ret = xc_cpupool_getinfo(ctx->xch, 0, 256, info);
+    if (ret<0) return NULL;
+
+    for (i = 0; i < ret; i++) {
+        ptr[i].poolid = info[i].cpupool_id;
+    }
+    *nb_pool = ret;
+    return ptr;
+}
+
 /* this API call only list VM running on this host. a VM can be an aggregate of multiple domains. */
 struct libxl_vminfo * libxl_list_vm(struct libxl_ctx *ctx, int *nb_vm)
 {
@@ -1226,44 +1253,25 @@ int libxl_confirm_device_model_startup(s
 
 /******************************************************************************/
 
-static int is_blktap2_supported(void)
+static char *get_blktap2_device(struct libxl_ctx *ctx,
+				const char *name, const char *type)
 {
-    char buf[1024];
-    FILE *f = fopen("/proc/devices", "r");
-
-    
-    while (fgets(buf, sizeof(buf), f) != NULL) {
-        if (strstr(buf, "blktap2")) {
-            fclose(f);
-            return 1;
-        }
-    }
-    fclose(f);
-    return 0;
+    int minor = tap_ctl_find_minor(type, name);
+    if (minor < 0)
+        return NULL;
+    return libxl_sprintf(ctx, "/dev/xen/blktap-2/tapdev%d", minor);
 }
 
-static char *get_blktap2_device(struct libxl_ctx *ctx, char *name, char *type)
+static char *make_blktap2_device(struct libxl_ctx *ctx,
+				 const char *name, const char *type)
 {
-    char buf[1024];
-    char *p;
-    int devnum;
-    FILE *f = fopen("/sys/class/blktap2/devices", "r");
-
-    
-    while (!feof(f)) {
-        if (fscanf(f, "%d %s", &devnum, buf) != 2)
-            continue;
-        p = strchr(buf, ':');
-        if (p == NULL)
-            continue;
-        p++;
-        if (!strcmp(p, name) && !strncmp(buf, type, 3)) {
-            fclose(f);
-            return libxl_sprintf(ctx, "/dev/xen/blktap-2/tapdev%d", devnum);
-        }
-    }
-    fclose(f);
-    return NULL;
+    char *params, *devname = NULL;
+    int err;
+    params = libxl_sprintf(ctx, "%s:%s", type, name);
+    err = tap_ctl_create(params, &devname);
+    if (!err)
+        libxl_ptr_add(ctx, devname);
+    return err ? NULL : devname;
 }
 
 int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
@@ -1314,38 +1322,16 @@ int libxl_device_disk_add(struct libxl_c
         case PHYSTYPE_FILE:
             /* let's pretend is tap:aio for the moment */
             disk->phystype = PHYSTYPE_AIO;
-        case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case PHYSTYPE_VHD:
-            if (is_blktap2_supported()) {
-                int rc, c, p[2], tot;
-                char buf[1024], *dev;
-                dev = get_blktap2_device(ctx, disk->physpath, device_disk_string_of_phystype(disk->phystype));
-                if (dev == NULL) {
-                    rc= libxl_pipe(ctx, p);  if (rc==-1) return -1;
-                    rc= libxl_fork(ctx);  if (rc==-1) return -1;
-                    if (!rc) { /* child */
-                        int null_r, null_w;
-                        char *args[4];
-                        args[0] = "tapdisk2";
-                        args[1] = "-n";
-                        args[2] = libxl_sprintf(ctx, "%s:%s", device_disk_string_of_phystype(disk->phystype), disk->physpath);
-                        args[3] = NULL;
-
-                        null_r = open("/dev/null", O_RDONLY);
-                        null_w = open("/dev/null", O_WRONLY);
-                        libxl_exec(null_r, p[1], null_w,
-                                   libxl_abs_path(ctx, "tapdisk2",
-                                                  libxl_sbindir_path()),
-                                   args);
-                        XL_LOG(ctx, XL_LOG_ERROR, "Error execing tapdisk2");
-                    }
-                    close(p[1]);
-                    tot = 0;
-                    while ((c = read(p[0], buf + tot, sizeof(buf) - tot)) > 0)
-                        tot = tot + c;
-                    close(p[0]);
-                    buf[tot - 1] = '\0';
-                    dev = buf;
-                }
+        case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case PHYSTYPE_VHD: {
+            const char *msg;
+            if (!tap_ctl_check(&msg)) {
+                const char *type = device_disk_string_of_phystype(disk->phystype);
+                char *dev;
+                dev = get_blktap2_device(ctx, disk->physpath, type);
+                if (!dev)
+                    dev = make_blktap2_device(ctx, disk->physpath, type);
+                if (!dev)
+                    return -1;
                 flexarray_set(back, boffset++, "tapdisk-params");
                 flexarray_set(back, boffset++, libxl_sprintf(ctx, "%s:%s", device_disk_string_of_phystype(disk->phystype), disk->physpath));
                 flexarray_set(back, boffset++, "params");
@@ -1364,6 +1350,7 @@ int libxl_device_disk_add(struct libxl_c
 
             device.backend_kind = DEVICE_TAP;
             break;
+        }
         default:
             XL_LOG(ctx, XL_LOG_ERROR, "unrecognized disk physical type: %d\n", disk->phystype);
             return ERROR_INVAL;
@@ -1579,6 +1566,186 @@ libxl_nicinfo *libxl_list_nics(struct li
     return res;
 }
 
+/******************************************************************************/
+int libxl_device_net2_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_net2 *net2)
+{
+    flexarray_t *front, *back;
+    unsigned int boffset = 0, foffset = 0;
+    libxl_device device;
+    char *dompath, *dom, **l;
+    unsigned int nb;
+
+    front = flexarray_make(16, 1);
+    if (!front)
+        return ERROR_NOMEM;
+    back = flexarray_make(16, 1);
+    if (!back)
+        return ERROR_NOMEM;
+
+    if (!(dompath = libxl_xs_get_dompath(ctx, domid))) {
+        return ERROR_FAIL;
+    }
+    dom = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/name", dompath));
+
+    if (net2->devid == -1) {
+        if (!(l = libxl_xs_directory(ctx, XBT_NULL,
+                                     libxl_sprintf(ctx, "%s/device/vif2", dompath), &nb))) {
+            net2->devid = 0;
+        } else {
+            net2->devid = strtoul(l[nb - 1], NULL, 10) + 1;
+            libxl_free(ctx, l);
+        }
+    }
+
+    device.backend_devid = net2->devid;
+    device.backend_domid = net2->backend_domid;
+    device.backend_kind = DEVICE_VIF2;
+    device.devid = net2->devid;
+    device.domid = net2->domid;
+    device.kind = DEVICE_VIF2;
+
+    flexarray_set(back, boffset++, "domain");
+    flexarray_set(back, boffset++, dom);
+    flexarray_set(back, boffset++, "frontend-id");
+    flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", net2->domid));
+
+    flexarray_set(back, boffset++, "local-trusted");
+    flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", net2->back_trusted));
+    flexarray_set(back, boffset++, "mac");
+    flexarray_set(back, boffset++, libxl_sprintf(ctx, "%02x:%02x:%02x:%02x:%02x:%02x",
+                                                 net2->back_mac[0], net2->back_mac[1],
+                                                 net2->back_mac[2], net2->back_mac[3],
+                                                 net2->back_mac[4], net2->back_mac[5]));
+
+    flexarray_set(back, boffset++, "remote-trusted");
+    flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", net2->trusted));
+    flexarray_set(back, boffset++, "remote-mac");
+    flexarray_set(back, boffset++, libxl_sprintf(ctx, "%02x:%02x:%02x:%02x:%02x:%02x",
+                                                 net2->front_mac[0], net2->front_mac[1],
+                                                 net2->front_mac[2], net2->front_mac[3],
+                                                 net2->front_mac[4], net2->front_mac[5]));
+
+    flexarray_set(back, boffset++, "max-bypasses");
+    flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", net2->max_bypasses));
+    flexarray_set(back, boffset++, "filter-mac");
+    flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", !!(net2->filter_mac)));
+    flexarray_set(back, boffset++, "handle");
+    flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", net2->devid));
+    flexarray_set(back, boffset++, "online");
+    flexarray_set(back, boffset++, "1");
+    flexarray_set(back, boffset++, "state");
+    flexarray_set(back, boffset++, "1");
+
+    flexarray_set(front, foffset++, "backend-id");
+    flexarray_set(front, foffset++, libxl_sprintf(ctx, "%d", net2->backend_domid));
+
+    flexarray_set(front, foffset++, "local-trusted");
+    flexarray_set(front, foffset++, libxl_sprintf(ctx, "%d", net2->trusted));
+    flexarray_set(front, foffset++, "mac");
+    flexarray_set(front, foffset++, libxl_sprintf(ctx, "%02x:%02x:%02x:%02x:%02x:%02x",
+                                                  net2->front_mac[0], net2->front_mac[1],
+                                                  net2->front_mac[2], net2->front_mac[3],
+                                                  net2->front_mac[4], net2->front_mac[5]));
+
+    flexarray_set(front, foffset++, "remote-trusted");
+    flexarray_set(front, foffset++, libxl_sprintf(ctx, "%d", net2->back_trusted));
+    flexarray_set(front, foffset++, "remote-mac");
+    flexarray_set(front, foffset++, libxl_sprintf(ctx, "%02x:%02x:%02x:%02x:%02x:%02x",
+                                                  net2->back_mac[0], net2->back_mac[1],
+                                                  net2->back_mac[2], net2->back_mac[3],
+                                                  net2->back_mac[4], net2->back_mac[5]));
+
+    flexarray_set(front, foffset++, "filter-mac");
+    flexarray_set(front, foffset++, libxl_sprintf(ctx, "%d", !!(net2->filter_mac)));
+    flexarray_set(front, foffset++, "state");
+    flexarray_set(front, foffset++, "1");
+
+    libxl_device_generic_add(ctx, &device,
+                             libxl_xs_kvs_of_flexarray(ctx, back, boffset),
+                             libxl_xs_kvs_of_flexarray(ctx, front, foffset));
+
+    /* FIXME: wait for plug */
+    flexarray_free(back);
+    flexarray_free(front);
+    return 0;
+}
+
+libxl_net2info *libxl_device_net2_list(struct libxl_ctx *ctx, uint32_t domid, unsigned int *nb)
+{
+    char *dompath, *net2_path_fe;
+    char **l;
+    char *val, *tok;
+    unsigned int nb_net2s, i;
+    libxl_net2info *res, *net2s;
+
+    dompath = libxl_xs_get_dompath(ctx, domid);
+    if (!dompath) {
+        return NULL;
+    }
+    l = libxl_xs_directory(ctx, XBT_NULL,
+                           libxl_sprintf(ctx, "%s/device/vif2", dompath), &nb_net2s);
+    if (!l) {
+        return NULL;
+    }
+    res = libxl_calloc(ctx, nb_net2s, sizeof (libxl_net2info));
+    if (!res) {
+        libxl_free(ctx, l);
+        return NULL;
+    }
+    net2s = res;
+    for (*nb = nb_net2s; nb_net2s > 0; --nb_net2s, ++l, ++net2s) {
+        net2_path_fe = libxl_sprintf(ctx, "%s/device/vif2/%s", dompath, *l);
+
+        net2s->backend = libxl_xs_read(ctx, XBT_NULL,
+                                       libxl_sprintf(ctx, "%s/backend", net2_path_fe));
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend-id", net2_path_fe));
+        net2s->backend_id = val ? strtoul(val, NULL, 10) : -1;
+
+        net2s->devid = strtoul(*l, NULL, 10);
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/state", net2_path_fe));
+        net2s->state = val ? strtoul(val, NULL, 10) : -1;
+
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/mac", net2_path_fe));
+        for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
+             ++i, tok = strtok(NULL, ":")) {
+            net2s->mac[i] = strtoul(tok, NULL, 16);
+        }
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/remote-trusted", net2_path_fe));
+        net2s->trusted = val ? strtoul(val, NULL, 10) : -1;
+
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/remote-mac", net2_path_fe));
+        for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
+             ++i, tok = strtok(NULL, ":")) {
+            net2s->back_mac[i] = strtoul(tok, NULL, 16);
+        }
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/filter-mac", net2_path_fe));
+        net2s->filter_mac = val ? strtoul(val, NULL, 10) : -1;
+
+        net2s->frontend = libxl_xs_read(ctx, XBT_NULL,
+                                        libxl_sprintf(ctx, "%s/frontend", net2s->backend));
+        val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/frontend-id", net2s->backend));
+        net2s->frontend_id = val ? strtoul(val, NULL, 10) : -1;
+        libxl_free(ctx, net2_path_fe);
+    }
+
+    libxl_free(ctx, l);
+    return res;
+}
+
+int libxl_device_net2_del(struct libxl_ctx *ctx, libxl_device_net2 *net2, int wait)
+{
+    libxl_device device;
+
+    device.backend_devid    = net2->devid;
+    device.backend_domid    = net2->backend_domid;
+    device.backend_kind     = DEVICE_VIF2;
+    device.devid            = net2->devid;
+    device.domid            = net2->domid;
+    device.kind             = DEVICE_VIF2;
+
+    return libxl_device_del(ctx, &device, wait);
+}
+
 
 /******************************************************************************/
 int libxl_device_console_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_console *console)
@@ -2584,6 +2751,7 @@ int libxl_get_physinfo(struct libxl_ctx 
     physinfo->total_pages = xcphysinfo.total_pages;
     physinfo->free_pages = xcphysinfo.free_pages;
     physinfo->scrub_pages = xcphysinfo.scrub_pages;
+    physinfo->nr_nodes = xcphysinfo.nr_nodes;
     memcpy(physinfo->hw_cap,xcphysinfo.hw_cap, sizeof(physinfo->hw_cap));
     physinfo->phys_cap = xcphysinfo.capabilities;
 
tools/libxl/libxl_device.c +4 -2
diff -pud -x '*.d' xen-4.0-testing.hg/tools/libxl/libxl_device.c xen-unstable.hg/tools/libxl/libxl_device.c
@@ -24,11 +24,13 @@
 #include <unistd.h>
 #include <fcntl.h>
 
+
 #include "libxl.h"
 #include "libxl_internal.h"
 
 static const char *string_of_kinds[] = {
     [DEVICE_VIF] = "vif",
+    [DEVICE_VIF2] = "vif2",
     [DEVICE_VBD] = "vbd",
     [DEVICE_TAP] = "tap",
     [DEVICE_PCI] = "pci",
@@ -292,7 +294,7 @@ int libxl_devices_destroy(struct libxl_c
     flexarray_t *toremove;
     struct libxl_ctx clone;
 
-    if (libxl_ctx_init(&clone, LIBXL_VERSION)) {
+    if (libxl_ctx_init(&clone, LIBXL_VERSION, ctx->lg)) {
         return -1;
     }
 
@@ -355,7 +357,7 @@ int libxl_device_del(struct libxl_ctx *c
     int rc;
     struct libxl_ctx clone;
 
-    if (libxl_ctx_init(&clone, LIBXL_VERSION)) {
+    if (libxl_ctx_init(&clone, LIBXL_VERSION, ctx->lg)) {
         return -1;
     }
 
tools/libxl/libxl_dom.c +3 -3
diff -pud -x '*.d' xen-4.0-testing.hg/tools/libxl/libxl_dom.c xen-unstable.hg/tools/libxl/libxl_dom.c
@@ -148,7 +148,7 @@ int build_pv(struct libxl_ctx *ctx, uint
     int ret;
     int flags = 0;
 
-    dom = xc_dom_allocate(info->u.pv.cmdline, info->u.pv.features);
+    dom = xc_dom_allocate(ctx->xch, info->u.pv.cmdline, info->u.pv.features);
     if (!dom) {
         XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "xc_dom_allocate failed");
         return -1;
@@ -244,7 +244,7 @@ static int core_suspend_callback(void *d
             XL_LOG(si->ctx, XL_LOG_ERROR, "xc_evtchn_notify failed ret=%d", ret);
             return 0;
         }
-        ret = xc_await_suspend(si->xce, si->suspend_eventchn);
+        ret = xc_await_suspend(si->ctx->xch, si->xce, si->suspend_eventchn);
         if (ret < 0) {
             XL_LOG(si->ctx, XL_LOG_ERROR, "xc_await_suspend failed ret=%d", ret);
             return 0;
@@ -329,7 +329,7 @@ int core_suspend(struct libxl_ctx *ctx, 
                    &core_suspend_switch_qemu_logdirty);
 
     if (si.suspend_eventchn > 0)
-        xc_suspend_evtchn_release(si.xce, si.suspend_eventchn);
+        xc_suspend_evtchn_release(si.ctx->xch, si.xce, domid, si.suspend_eventchn);
     if (si.xce > 0)
         xc_evtchn_close(si.xce);
 
tools/libxl/libxl_exec.c +2 -1
diff -pud -x '*.d' xen-4.0-testing.hg/tools/libxl/libxl_exec.c xen-unstable.hg/tools/libxl/libxl_exec.c
@@ -57,7 +57,8 @@ void libxl_exec(int stdinfd, int stdoutf
     _exit(-1);
 }
 
-void libxl_report_child_exitstatus(struct libxl_ctx *ctx, int level,
+void libxl_report_child_exitstatus(struct libxl_ctx *ctx,
+                                   xentoollog_level level,
                                    const char *what, pid_t pid, int status)
 {
 
tools/libxl/libxl.h +48 -9

113 lines not on this page · raw message

tools/libxl/libxl_internal.c +18 -26

66 lines not on this page · raw message

tools/libxl/libxl_internal.h +21 -4
diff -pud -x '*.d' xen-4.0-testing.hg/tools/libxl/libxl_internal.h xen-unstable.hg/tools/libxl/libxl_internal.h
@@ -23,6 +23,7 @@
 
 #include <xs.h>
 #include <xenctrl.h>
+#include "xentoollog.h"
 
 #include "flexarray.h"
 #include "libxl_utils.h"
@@ -50,13 +51,24 @@
   /* all of these macros preserve errno (saving and restoring) */
 
 /* logging */
-void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, va_list al);
-void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, ...);
-  /* these functions preserve errno (saving and restoring) */
+void xl_logv(struct libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
+             const char *file /* may be 0 */, int line /* ignored if !file */,
+             const char *func /* may be 0 */,
+             char *fmt, va_list al)
+     __attribute__((format(printf,7,0)));
+
+void xl_log(struct libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,
+            const char *file /* may be 0 */, int line /* ignored if !file */,
+            const char *func /* may be 0 */,
+            char *fmt, ...)
+     __attribute__((format(printf,7,8)));
+
+     /* these functions preserve errno (saving and restoring) */
 
 
 typedef enum {
     DEVICE_VIF = 1,
+    DEVICE_VIF2,
     DEVICE_VBD,
     DEVICE_TAP,
     DEVICE_PCI,
@@ -154,7 +166,7 @@ int libxl_device_pci_reset(struct libxl_
                            unsigned int dev, unsigned int func);
 
 /* from xenguest (helper */
-int hvm_build_set_params(int handle, uint32_t domid,
+int hvm_build_set_params(xc_interface *handle, uint32_t domid,
                          libxl_domain_build_info *info,
                          int store_evtchn, unsigned long *store_mfn);
 
@@ -204,5 +216,10 @@ void libxl_log_child_exitstatus(struct l
 
 char *libxl_abs_path(struct libxl_ctx *ctx, char *s, const char *path);
 
+#define XL_LOG_DEBUG   XTL_DEBUG
+#define XL_LOG_INFO    XTL_INFO
+#define XL_LOG_WARNING XTL_WARN
+#define XL_LOG_ERROR   XTL_ERROR
+
 #endif
 
tools/libxl/libxl_utils.c +86 -0

95 lines not on this page · raw message

tools/libxl/libxl_utils.h +5 -6
diff -pud -x '*.d' xen-4.0-testing.hg/tools/libxl/libxl_utils.h xen-unstable.hg/tools/libxl/libxl_utils.h
@@ -50,7 +50,7 @@ pid_t libxl_fork(struct libxl_ctx *ctx);
 int libxl_pipe(struct libxl_ctx *ctx, int pipes[2]);
   /* Just like fork(2), pipe(2), but log errors. */
 
-void libxl_report_child_exitstatus(struct libxl_ctx *ctx, int level,
+void libxl_report_child_exitstatus(struct libxl_ctx *ctx, xentoollog_level,
                                    const char *what, pid_t pid, int status);
     /* treats all exit statuses as errors; if that's not what you want,
      * check status yourself first */
@@ -63,11 +63,10 @@ int libxl_devid_to_device_nic(struct lib
 int libxl_devid_to_device_disk(struct libxl_ctx *ctx, uint32_t domid,
                                const char *devid, libxl_device_disk *disk);
 
-/* log levels: */
-#define XL_LOG_DEBUG 3
-#define XL_LOG_INFO 2
-#define XL_LOG_WARNING 1
-#define XL_LOG_ERROR 0
+int libxl_strtomac(const char *mac_s, uint8_t *mac);
+
+int libxl_devid_to_device_net2(struct libxl_ctx *ctx, uint32_t domid,
+                               const char *devid, libxl_device_net2 *net2);
 
 #endif
 
tools/libxl/Makefile +2 -2
diff -pud -x '*.d' xen-4.0-testing.hg/tools/libxl/Makefile xen-unstable.hg/tools/libxl/Makefile
@@ -13,9 +13,9 @@ XLUMINOR = 0
 
 CFLAGS += -Werror
 CFLAGS += -I. -fPIC
-CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore)
+CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl)
 
-LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore)
+LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore) $(LDFLAGS_libblktapctl)
 
 LIBXL_OBJS-y = osdeps.o libxl_paths.o
 LIBXL_OBJS = flexarray.o libxl.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y)
tools/libxl/xenguest.c +1 -1
diff -pud -x '*.d' xen-4.0-testing.hg/tools/libxl/xenguest.c xen-unstable.hg/tools/libxl/xenguest.c
@@ -21,7 +21,7 @@
 
 #include "libxl.h"
 
-int hvm_build_set_params(int handle, uint32_t domid,
+int hvm_build_set_params(xc_interface *handle, uint32_t domid,
                          libxl_domain_build_info *info,
                          int store_evtchn, unsigned long *store_mfn)
 {
tools/libxl/xl.c +25 -20

69 lines not on this page · raw message

tools/libxl/xl_cmdimpl.c +290 -10

431 lines not on this page · raw message

tools/libxl/xl_cmdtable.c +18 -0
diff -pud -x '*.d' xen-4.0-testing.hg/tools/libxl/xl_cmdtable.c xen-unstable.hg/tools/libxl/xl_cmdtable.c
@@ -295,6 +295,24 @@ struct cmd_spec cmd_table[] = {
       "                                 (abcdef01-2345-6789-1234-567890abcdef)\n"
       "  -A AUTH                        0=auth,1=deauth",
     },
+    { "network2-attach",
+      &main_network2attach,
+      "Create a new version 2 virtual network device",
+      "<Domain> [front_mac=<mac>] [back_mac=<mac>] [backend=<BackDomain>]"
+      " [trusted=<0|1>] [back_trusted=<0|1>] [bridge=<bridge>]"
+      " [filter_mac=<0|1>] [front_filter_mac=<0|1>] [pdev=<PDEV>]"
+      " [max_bypasses=n]",
+    },
+    { "network2-list",
+      &main_network2list,
+      "list version 2 virtual network interfaces for a domain",
+      "<Domain(s)>",
+    },
+    { "network2-detach",
+      &main_network2detach,
+      "destroy a domain's version 2 virtual network device",
+      "<Domain> <DevId>",
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
tools/libxl/xl.h +10 -2
diff -pud -x '*.d' xen-4.0-testing.hg/tools/libxl/xl.h xen-unstable.hg/tools/libxl/xl.h
@@ -15,6 +15,8 @@
 #ifndef XL_H
 #define XL_H
 
+#include "xentoollog.h"
+
 struct cmd_spec {
     char *cmd_name;
     int (*cmd_impl)(int argc, char **argv);
@@ -70,12 +72,18 @@ int main_tmem_destroy(int argc, char **a
 int main_tmem_thaw(int argc, char **argv);
 int main_tmem_set(int argc, char **argv);
 int main_tmem_shared_auth(int argc, char **argv);
+int main_network2attach(int argc, char **argv);
+int main_network2list(int argc, char **argv);
+int main_network2detach(int argc, char **argv);
 
 void help(char *command);
 
-/* Look up a command in the table, allowing unambiguous truncation */
-struct cmd_spec *cmdtable_lookup(const char *s);
 extern struct cmd_spec cmd_table[];
 extern int cmdtable_len;
+/* Look up a command in the table, allowing unambiguous truncation */
+struct cmd_spec *cmdtable_lookup(const char *s);
+
+extern struct libxl_ctx ctx;
+extern xentoollog_logger_stdiostream *logger;
 
 #endif /* XL_H */
#1 lore raw

PATCH 1/1 backport libxl from xen-unstable to xen-4.0-testing

b/tools/libxl/bash-completion | 21

 b/tools/libxl/libxl_paths.c   |   61 
 b/tools/libxl/xl.h            |   81 
 b/tools/libxl/xl_cmdimpl.c    | 4243 ++++++++++++++++++++++++++++++++++++++++++
 b/tools/libxl/xl_cmdtable.c   |  322 +++
 tools/libxl/Makefile          |   28 
 tools/libxl/libxl.c           | 1030 ++++++++--
 tools/libxl/libxl.h           |  191 +
 tools/libxl/libxl_device.c    |   76 
 tools/libxl/libxl_dom.c       |  194 +
 tools/libxl/libxl_exec.c      |   34 
 tools/libxl/libxl_internal.c  |   13 
 tools/libxl/libxl_internal.h  |   24 
 tools/libxl/libxl_utils.c     |  297 ++
 tools/libxl/libxl_utils.h     |   45 
 tools/libxl/libxl_xshelp.c    |    6 
 tools/libxl/libxlu_cfg.c      |   37 
 tools/libxl/libxlutil.h       |    3 
 tools/libxl/xenguest.c        |   18 
 tools/libxl/xl.c              | 1750 -----------------
 tools/xenstore/xs.c           |   52 
 tools/xenstore/xs.h           |    3 
 22 files changed, 6555 insertions(+), 1974 deletions(-)
tools/libxl/Makefile +24 -4
diff -r 7dcfdd45bc9e -r a047b47a54ee tools/libxl/Makefile
@@ -11,13 +11,13 @@
 XLUMAJOR = 1.0
 XLUMINOR = 0
 
-#CFLAGS += -Werror
+CFLAGS += -Werror
 CFLAGS += -I. -fPIC
 CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore)
 
 LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore)
 
-LIBXL_OBJS-y = osdeps.o
+LIBXL_OBJS-y = osdeps.o libxl_paths.o
 LIBXL_OBJS = flexarray.o libxl.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y)
 
 AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h
@@ -43,6 +43,15 @@
 %.c: %.l
 	$(FLEX) --header-file=$*.h --outfile=$@ $<
 
+genpath-target = $(call buildmakevars2file,_libxl_paths.h)
+$(eval $(genpath-target))
+
+_libxl_paths.h: genpath
+	sed -e "s/\([^=]*\)=\(.*\)/#define \1 \2/g" $@ >_$@
+	mv _$@ $@
+
+libxl_paths.c: _libxl_paths.h
+
 libxenlight.so: libxenlight.so.$(MAJOR)
 	ln -sf $< $@
 
@@ -70,11 +79,21 @@
 xl.o: xl.c
 	$(CC) $(CFLAGS) -c xl.c
 
-$(CLIENTS): xl.o libxlutil.so libxenlight.so
+xl_cmdimpl.o: xl_cmdimpl.c
+	$(CC) $(CFLAGS) -c xl_cmdimpl.c
+
+xl_cmdtable.o: xl_cmdtable.c
+	$(CC) $(CFLAGS) -c xl_cmdtable.c
+
+$(CLIENTS): xl.o xl_cmdimpl.o xl_cmdtable.o libxlutil.so libxenlight.so
 	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
 
 .PHONY: install
 install: all
+	$(INSTALL_DIR) $(DESTDIR)$(SBINDIR)
+	$(INSTALL_DIR) $(DESTDIR)$(LIBDIR)
+	$(INSTALL_DIR) $(DESTDIR)$(INCLUDEDIR)
+	$(INSTALL_DIR) $(DESTDIR)$(BASH_COMPLETION_DIR)
 	$(INSTALL_PROG) xl $(DESTDIR)$(SBINDIR)
 	$(INSTALL_PROG) libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)
 	ln -sf libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libxenlight.so.$(MAJOR)
@@ -85,10 +104,11 @@
 	ln -sf libxlutil.so.$(XLUMAJOR) $(DESTDIR)$(LIBDIR)/libxlutil.so
 	$(INSTALL_DATA) libxlutil.a $(DESTDIR)$(LIBDIR)
 	$(INSTALL_DATA) libxl.h $(DESTDIR)$(INCLUDEDIR)
+	$(INSTALL_DATA) bash-completion $(DESTDIR)$(BASH_COMPLETION_DIR)/xl.sh
 
 .PHONY: clean
 clean:
-	$(RM) -f *.o *.so* *.a $(CLIENTS) $(DEPS)
+	$(RM) -f _*.h *.o *.so* *.a $(CLIENTS) $(DEPS)
 #	$(RM) -f $(AUTOSRCS) $(AUTOINCS)
 
 distclean: clean
tools/libxl/bash-completion new file +21 -0
diff -r 7dcfdd45bc9e -r a047b47a54ee tools/libxl/bash-completion
@@ -0,0 +1,21 @@
+#!/bin/bash
+# Copy this file to /etc/bash_completion.d/xl.sh
+
+_xl()
+{
+	local IFS=$'\n,'
+
+	local cur opts xl
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	xl=xl
+	
+	if [[ $COMP_CWORD == 1 ]] ; then
+		opts=`${xl} help 2>/dev/null | sed '1,4d' | awk '{print $1}' | sed 's/$/ ,/g'` && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+		return 0
+	fi
+
+	return 0
+}
+
+complete -F _xl -o nospace -o default xl
tools/libxl/libxl.c +909 -121

1,406 lines not on this page · raw message

tools/libxl/libxl.h +189 -2

287 lines not on this page · raw message

tools/libxl/libxl_device.c +46 -30

116 lines not on this page · raw message

tools/libxl/libxl_dom.c +171 -23

243 lines not on this page · raw message

tools/libxl/libxl_exec.c +12 -22
diff -r 7dcfdd45bc9e -r a047b47a54ee tools/libxl/libxl_exec.c
@@ -30,19 +30,6 @@
 #include "libxl.h"
 #include "libxl_internal.h"
 
-static pid_t libxl_fork(struct libxl_ctx *ctx)
-{
-    pid_t pid;
-
-    pid = fork();
-    if (pid == -1) {
-        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "fork failed");
-        return -1;
-    }
-
-    return pid;
-}
-
 static int call_waitpid(pid_t (*waitpid_cb)(pid_t, int *, int), pid_t pid, int *status, int options)
 {
     return (waitpid_cb) ? waitpid_cb(pid, status, options) : waitpid(pid, status, options);
@@ -61,38 +48,41 @@
         dup2(stderrfd, STDERR_FILENO);
     for (i = 4; i < 256; i++)
         close(i);
+
+    signal(SIGPIPE, SIG_DFL);
+    /* in case our caller set it to IGN.  subprocesses are entitled
+     * to assume they got DFL. */
+
     execv(arg0, args);
     _exit(-1);
 }
 
-void libxl_report_child_exitstatus(struct libxl_ctx *ctx,
+void libxl_report_child_exitstatus(struct libxl_ctx *ctx, int level,
                                    const char *what, pid_t pid, int status)
 {
-    /* treats all exit statuses as errors; if that's not what you want,
-     * check status yourself first */
 
     if (WIFEXITED(status)) {
         int st = WEXITSTATUS(status);
         if (st)
-            XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] exited"
+            XL_LOG(ctx, level, "%s [%ld] exited"
                    " with error status %d", what, (unsigned long)pid, st);
         else
-            XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] unexpectedly"
+            XL_LOG(ctx, level, "%s [%ld] unexpectedly"
                    " exited status zero", what, (unsigned long)pid);
     } else if (WIFSIGNALED(status)) {
         int sig = WTERMSIG(status);
         const char *str = strsignal(sig);
         const char *coredump = WCOREDUMP(status) ? " (core dumped)" : "";
         if (str)
-            XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] died due to"
+            XL_LOG(ctx, level, "%s [%ld] died due to"
                    " fatal signal %s%s", what, (unsigned long)pid,
                    str, coredump);
         else
-            XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] died due to unknown"
+            XL_LOG(ctx, level, "%s [%ld] died due to unknown"
                    " fatal signal number %d%s", what, (unsigned long)pid,
                    sig, coredump);
     } else {
-        XL_LOG(ctx, XL_LOG_ERROR, "%s [%ld] gave unknown"
+        XL_LOG(ctx, level, "%s [%ld] gave unknown"
                " wait status 0x%x", what, (unsigned long)pid, status);
     }
 }
@@ -153,7 +143,7 @@
         char *intermediate_what = libxl_sprintf(ctx,
                           "%s intermediate process (startup monitor)",
                           for_spawn->what);
-        libxl_report_child_exitstatus(ctx, intermediate_what,
+        libxl_report_child_exitstatus(ctx, XL_LOG_ERROR, intermediate_what,
                                       for_spawn->intermediate, status);
     }
 }
tools/libxl/libxl_internal.c +12 -1
diff -r 7dcfdd45bc9e -r a047b47a54ee tools/libxl/libxl_internal.c
@@ -156,11 +156,13 @@
 {
     char *enomem = "[out of memory formatting log message]";
     char *s;
-    int rc;
+    int rc, esave;
 
     if (!ctx->log_callback)
         return;
 
+    esave = errno;
+    
     rc = vasprintf(&s, fmt, ap);
     if (rc<0) { s = enomem; goto x; }
 
@@ -180,6 +182,7 @@
     ctx->log_callback(ctx->log_userdata, loglevel, file, line, func, s);
     if (s != enomem)
         free(s);
+    errno = esave;
 }
 
 void xl_log(struct libxl_ctx *ctx, int loglevel, int errnoval,
@@ -191,3 +194,11 @@
     xl_logv(ctx, loglevel, errnoval, file, line, func, fmt, ap);
     va_end(ap);
 }
+
+char *libxl_abs_path(struct libxl_ctx *ctx, char *s, const char *path)
+{
+    if (!s || s[0] == '/')
+        return s;
+    return libxl_sprintf(ctx, "%s/%s", path, s);
+}
+
tools/libxl/libxl_internal.h +12 -12
diff -r 7dcfdd45bc9e -r a047b47a54ee tools/libxl/libxl_internal.h
@@ -41,21 +41,18 @@
 #ifdef XL_LOGGING_ENABLED
 #define XL_LOG(ctx, loglevel, _f, _a...)   xl_log(ctx, loglevel, -1, __FILE__, __LINE__, __func__, _f, ##_a)
 #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...)   xl_log(ctx, loglevel, errno, __FILE__, __LINE__, __func__, _f, ##_a)
-#define XL_LOG_ERRNOVAL(ctx, errnoval, loglevel, _f, _a...)   xl_log(ctx, loglevel, errnoval, __FILE__, __LINE__, __func__, _f, ##_a)
+#define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...)   xl_log(ctx, loglevel, errnoval, __FILE__, __LINE__, __func__, _f, ##_a)
 #else
 #define XL_LOG(ctx, loglevel, _f, _a...)
 #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...)
 #define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...)
 #endif
-
-#define XL_LOG_DEBUG 3
-#define XL_LOG_INFO 2
-#define XL_LOG_WARNING 1
-#define XL_LOG_ERROR 0
+  /* all of these macros preserve errno (saving and restoring) */
 
 /* logging */
 void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, va_list al);
 void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, ...);
+  /* these functions preserve errno (saving and restoring) */
 
 
 typedef enum {
@@ -133,6 +130,7 @@
                    libxl_domain_build_info *info, libxl_domain_build_state *state, int fd);
 int core_suspend(struct libxl_ctx *ctx, uint32_t domid, int fd, int hvm, int live, int debug);
 int save_device_model(struct libxl_ctx *ctx, uint32_t domid, int fd);
+void libxl__userdata_destroyall(struct libxl_ctx *ctx, uint32_t domid);
 
 /* from xl_device */
 char *device_disk_backend_type_of_phystype(libxl_disk_phystype phystype);
@@ -152,13 +150,13 @@
                                                       void *userdata),
                                 void *check_callback_userdata);
 int libxl_wait_for_backend(struct libxl_ctx *ctx, char *be_path, char *state);
-int libxl_device_pci_flr(struct libxl_ctx *ctx, unsigned int domain, unsigned int bus,
-                         unsigned int dev, unsigned int func);
+int libxl_device_pci_reset(struct libxl_ctx *ctx, unsigned int domain, unsigned int bus,
+                           unsigned int dev, unsigned int func);
 
 /* from xenguest (helper */
 int hvm_build_set_params(int handle, uint32_t domid,
-                         int apic, int acpi, int pae, int nx, int viridian,
-                         int vcpus, int store_evtchn, unsigned long *store_mfn);
+                         libxl_domain_build_info *info,
+                         int store_evtchn, unsigned long *store_mfn);
 
 /* xl_exec */
 
@@ -183,8 +181,8 @@
                       void (*intermediate_hook)(void *for_spawn, pid_t innerchild));
   /* Logs errors.  A copy of "what" is taken.  Return values:
    *  < 0   error, for_spawn need not be detached
-   *   +1   caller is now the inner child, should probably call libxl_exec
-   *    0   caller is the parent, must call detach on *for_spawn eventually
+   *   +1   caller is the parent, must call detach on *for_spawn eventually
+   *    0   caller is now the inner child, should probably call libxl_exec
    * Caller, may pass 0 for for_spawn, in which case no need to detach.
    */
 int libxl_spawn_detach(struct libxl_ctx *ctx,
@@ -204,5 +202,7 @@
 void libxl_log_child_exitstatus(struct libxl_ctx *ctx,
                                 const char *what, pid_t pid, int status);
 
+char *libxl_abs_path(struct libxl_ctx *ctx, char *s, const char *path);
+
 #endif
 
tools/libxl/libxl_paths.c new file +61 -0

61 lines not on this page · raw message

tools/libxl/libxl_utils.c +293 -4

337 lines not on this page · raw message

tools/libxl/libxl_utils.h +44 -1

56 lines not on this page · raw message

tools/libxl/libxl_xshelp.c +4 -2
diff -r 7dcfdd45bc9e -r a047b47a54ee tools/libxl/libxl_xshelp.c
@@ -19,6 +19,7 @@
 #include <stddef.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <inttypes.h>
 
 #include "libxl.h"
 #include "libxl_internal.h"
@@ -32,7 +33,8 @@
         return 0;
 
     for (i = 0; kvs[i] != NULL; i += 2) {
-        asprintf(&path, "%s/%s", dir, kvs[i]);
+        if (asprintf(&path, "%s/%s", dir, kvs[i]) < 0)
+            return -1;
         if (path && kvs[i + 1]) {
             int length = strlen(kvs[i + 1]);
             xs_write(xsh, t, path, kvs[i + 1], length);
@@ -118,7 +120,7 @@
 {
     char *s = xs_get_domain_path(ctx->xsh, domid);
     if (!s) {
-        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "failed to get dompath for %lu",
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "failed to get dompath for %" PRIu32,
                      domid);
         return NULL;
     }
tools/libxl/libxlu_cfg.c +37 -0
diff -r 7dcfdd45bc9e -r a047b47a54ee tools/libxl/libxlu_cfg.c
@@ -53,6 +53,43 @@
     return ctx.err;
 }
 
+int xlu_cfg_readdata(XLU_Config *cfg, const char *data, int length) {
+    CfgParseContext ctx;
+    int e, r;
+    YY_BUFFER_STATE buf= 0;
+
+    ctx.scanner= 0;
+    ctx.cfg= cfg;
+    ctx.err= 0;
+    ctx.lexerrlineno= -1;
+
+    e= xlu__cfg_yylex_init_extra(&ctx, &ctx.scanner);
+    if (e) {
+        fprintf(cfg->report,"%s: unable to create scanner: %s\n",
+                cfg->filename, strerror(e));
+        ctx.err= e;
+        ctx.scanner= 0;
+        goto xe;
+    }
+
+    buf = xlu__cfg_yy_scan_bytes(data, length, ctx.scanner);
+    if (!buf) {
+        fprintf(cfg->report,"%s: unable to allocate scanner buffer\n",
+                cfg->filename);
+        ctx.err= ENOMEM;
+        goto xe;
+    }
+
+    r= xlu__cfg_yyparse(&ctx);
+    if (r) assert(ctx.err);
+
+ xe:
+    if (buf) xlu__cfg_yy_delete_buffer(buf, ctx.scanner);
+    if (ctx.scanner) xlu__cfg_yylex_destroy(ctx.scanner);
+
+    return ctx.err;
+}
+
 void xlu__cfg_set_free(XLU_ConfigSetting *set) {
     free(set->name);
     free(set->values);
tools/libxl/libxlutil.h +2 -1
diff -r 7dcfdd45bc9e -r a047b47a54ee tools/libxl/libxlutil.h
@@ -30,7 +30,8 @@
    *  until the Config is destroyed. */
 
 int xlu_cfg_readfile(XLU_Config*, const char *real_filename);
-  /* If this fails, then it is undefined behaviour to call xlu_cfg_get_...
+int xlu_cfg_readdata(XLU_Config*, const char *data, int length);
+  /* If these fail, then it is undefined behaviour to call xlu_cfg_get_...
    * functions.  You have to just xlu_cfg_destroy. */
  
 void xlu_cfg_destroy(XLU_Config*);
tools/libxl/xenguest.c +11 -7
diff -r 7dcfdd45bc9e -r a047b47a54ee tools/libxl/xenguest.c
@@ -17,10 +17,13 @@
 #include <xenguest.h>
 #include <sys/mman.h>
 #include <xen/hvm/hvm_info_table.h>
+#include <string.h>
+
+#include "libxl.h"
 
 int hvm_build_set_params(int handle, uint32_t domid,
-                         int apic, int acpi, int pae, int nx, int viridian,
-                         int vcpus, int store_evtchn, unsigned long *store_mfn)
+                         libxl_domain_build_info *info,
+                         int store_evtchn, unsigned long *store_mfn)
 {
     struct hvm_info_table *va_hvm;
     uint8_t *va_map, sum;
@@ -33,18 +36,19 @@
         return -1;
 
     va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
-    va_hvm->acpi_enabled = acpi;
-    va_hvm->apic_mode = apic;
-    va_hvm->nr_vcpus = vcpus;
+    va_hvm->acpi_enabled = info->u.hvm.acpi;
+    va_hvm->apic_mode = info->u.hvm.apic;
+    va_hvm->nr_vcpus = info->max_vcpus;
+    memcpy(va_hvm->vcpu_online, &info->cur_vcpus, sizeof(info->cur_vcpus));
     for (i = 0, sum = 0; i < va_hvm->length; i++)
         sum += ((uint8_t *) va_hvm)[i];
     va_hvm->checksum -= sum;
     munmap(va_map, XC_PAGE_SIZE);
 
     xc_get_hvm_param(handle, domid, HVM_PARAM_STORE_PFN, store_mfn);
-    xc_set_hvm_param(handle, domid, HVM_PARAM_PAE_ENABLED, pae);
+    xc_set_hvm_param(handle, domid, HVM_PARAM_PAE_ENABLED, info->u.hvm.pae);
 #if defined(__i386__) || defined(__x86_64__)
-    xc_set_hvm_param(handle, domid, HVM_PARAM_VIRIDIAN, viridian);
+    xc_set_hvm_param(handle, domid, HVM_PARAM_VIRIDIAN, info->u.hvm.viridian);
 #endif
     xc_set_hvm_param(handle, domid, HVM_PARAM_STORE_EVTCHN, store_evtchn);
     return 0;
tools/libxl/xl.c +26 -1724

121 lines not on this page · raw message

tools/libxl/xl.h new file +81 -0

81 lines not on this page · raw message

tools/libxl/xl_cmdimpl.c new file +4243 -0

4,243 lines not on this page · raw message

tools/libxl/xl_cmdtable.c new file +322 -0

322 lines not on this page · raw message

tools/xenstore/xs.c +32 -20

52 lines not on this page · raw message

tools/xenstore/xs.h +3 -0
diff -r 7dcfdd45bc9e -r a047b47a54ee tools/xenstore/xs.h

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#4 lore raw
In reply to Gianni Tedesco

Gianni Tedesco writes ("[Xen-devel] [PATCH 0/1] backport libxl from xen-unstable to xen-4.0-testing"):

Quoted 4 lines

Following patch does what it says on the tin. It's a straightforward backport of libxl to xen-4.0-testing. This buys harmony of functionality between the two trees with the minimal of disruption to anything outside tools/libxl.

With this patch xl create doesn't work any more in 4.0-testing:

2010-07-07 00:57:15 Z executing ssh ... [email protected] xl create /etc/xen/debian.guest.osstest.xl

Warning: Permanently added '10.80.249.102' (RSA) to the list of known hosts.
Usage: xl [-v] create <ConfigFile> [options] [vars]

Create a domain from config file <filename>.

Options:

-h                      Print this help.
-p                      Leave the domain paused after it is created.
-c                      Connect to the console after the domain is created.
-d                      Enable debug messages.
-f=FILE, --defconfig=FILE
                     Use the given configuration file.
-q, --quiet             Quiet.
-n, --dryrun            Dry run - prints the resulting configuration.
-d                      Enable debug messages.
-e                      Do not wait in the background for the death of the domain.
2010-07-07 00:57:15 Z command nonzero waitstatus 512: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o BatchMode=yes -o PasswordAuthentication=no -o ChallengeResponseAuthentication=no [email protected] xl create /etc/xen/debian.guest.osstest.xl

status 512 at Osstest.pm line 308.
+ rc=2

#5 lore raw
Quoted 7 lines · Ian Jackson

Gianni Tedesco writes ("[Xen-devel] [PATCH 0/1] backport libxl from xen-unstable to xen-4.0-testing"):

Quoted 4 lines

Following patch does what it says on the tin. It's a straightforward backport of libxl to xen-4.0-testing. This buys harmony of functionality between the two trees with the minimal of disruption to anything outside tools/libxl.

With this patch xl create doesn't work any more in 4.0-testing:

Wow, I find it BIZARRE that I didn't test that?! I was playing with this for several days. Anyway several other commands appear to have broken too due to incorrect getopt setup. I think this is the correct fix.

tools/libxl/xl.c +2 -0
diff -r 681dce2f9cb8 tools/libxl/xl.c
@@ -65,6 +65,8 @@
 
     srand(time(0));
 
+    optind = 2;
+
     cspec = cmdtable_lookup(argv[1]);
     if (cspec)
         return cspec->cmd_impl(argc, argv);
#6 lore raw
Quoted 18 lines · Gianni Tedesco
Quoted 7 lines · Ian Jackson

Gianni Tedesco writes ("[Xen-devel] [PATCH 0/1] backport libxl from xen-unstable to xen-4.0-testing"):

Quoted 4 lines

Following patch does what it says on the tin. It's a straightforward backport of libxl to xen-4.0-testing. This buys harmony of functionality between the two trees with the minimal of disruption to anything outside tools/libxl.

With this patch xl create doesn't work any more in 4.0-testing:

Wow, I find it BIZARRE that I didn't test that?! I was playing with this for several days. Anyway several other commands appear to have broken too due to incorrect getopt setup. I think this is the correct fix.

diff -r 681dce2f9cb8 tools/libxl/xl.c

tools/libxl/xl.c line 72

Quoted 8 lines
tools/libxl/xl.c +2 -0
@@ -65,6 +65,8 @@
 
     srand(time(0));
 
+    optind = 2;
+
     cspec = cmdtable_lookup(argv[1]);
     if (cspec)
         return cspec->cmd_impl(argc, argv);

Oops, also:

tools/libxl/xl.c +1 -1
diff -r a381819b54e7 tools/libxl/xl.c
@@ -71,7 +71,7 @@
     if (cspec)
         return cspec->cmd_impl(argc, argv);
     else if (!strcmp(argv[1], "help")) {
-        help(argv[optind]);
+        help(argv[1]);
         exit(0);
     } else {
         fprintf(stderr, "command not implemented\n");
#7 lore raw

Gianni Tedesco (3P) writes ("Re: [Xen-devel] [PATCH 0/1] backport libxl from xen-unstable to xen-4.0-testing"):

Quoted 1 line

Oops, also:

Yes, I think these fixes are good but you need to remove the "[-v]" from the general help message too.

Would you care to submit one revised patch ?

Ian.

#8 lore raw
Quoted 9 lines · Ian Jackson

Gianni Tedesco (3P) writes ("Re: [Xen-devel] [PATCH 0/1] backport libxl from xen-unstable to xen-4.0-testing"):

Quoted 1 line

Oops, also:

Yes, I think these fixes are good but you need to remove the "[-v]" from the general help message too.

Would you care to submit one revised patch ?

Ian.

Well spotted. Actually Keir went ahead and combined and committed the last two so here goes:

tools/libxl/xl_cmdimpl.c +1 -1
diff -r 61d705d61f20 tools/libxl/xl_cmdimpl.c
@@ -1214,7 +1214,7 @@
     struct cmd_spec *cmd;
 
     if (!command || !strcmp(command, "help")) {
-        printf("Usage xl [-v] <subcommand> [args]\n\n");
+        printf("Usage xl <subcommand> [args]\n\n");
         printf("xl full list of subcommands:\n\n");
         for (i = 0; i < cmdtable_len; i++)
             printf(" %-20s%s\n",