Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 00 of 27 V4] libxl: improved handling for default values in API
Introduce a mechanism for users of libxl to explicitly say "pick the default for me". To do this each field has a distinguished "init_val" and each struct has a "_setdefault" method which sets (idempotently) the defaults for fields which have not been set to an explicit value. Previously I went through some contortions (with "timer_mode" in particular but also with *_memkb fields) to try and arrange that this distinguished value was the all zeroes bit pattern. Instead of that pain this time I have arranged that the IDL supports the specification the distinguished val for each type/field and we autogenerate an _init function for each data type based on that. I have not updated the git branch I provided last time because iwj''s tree does not yet include the additional bios field in the IDL. The generated code hasn''t changed apart from that so I''ve left V3 at: The following changes since commit e4296962b0e5d913929164b913f47fe288ab783e: tools/hotplug: remove 4 from default runlevel in xencommons (2012-02-20 18:58:07 +0000) are available in the git repository at: git://xenbits.xen.org/people/ianc/xen-unstable.git for-ianj/libxl Changes since last time: * Rebase to latest head. Main change is the addition of the bios field in build info. Additional patch "libxl: Select BIOS using libxl_domain_build_info_setdefaults" relates to this Changes since last time: * Added two unrelated patches to remove Xen public headers from libxl''s API to the head of the queue * Produce _dispose and _init for all Aggregate types. * Be more assertive about why we should drop the 8M slack on PV. * Happens to fix stubdomains, broken by 24612:54000bca7a6a due to not setting the CPU affinity for the stub domain. Changes since the time before: * I have posted large parts of the previous series as * libxl: drop device_model_info * libxl: API updates + xl: JSON These have been committed thereby reducing the size of this series. * _init function support as described above * Dropped final patch to actually select stubdoms when possible -- this needs more investigation/sanity checking. This series has been lightly tested with PV domains (with and without PVFB) and HVM domains (with and without stubdom).
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 01 of 27 V4] libxl: remove sysctl.h from public interface
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533035 0 # Node ID 81854ea73a132154021df881c58aff6f870a4384 # Parent 5eebc98a4a7f22733e0dfb1fb982ecb64f0c0b31 libxl: remove sysctl.h from public interface Using sysctl.h is restricted to "node control tools only" and requires magic defines. Therefore make its use internal to libxl. Also removes an indirect include of domctl.h which has the same restrction. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 5eebc98a4a7f -r 81854ea73a13 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Feb 29 16:30:34 2012 +0000 +++ b/tools/libxl/libxl.c Wed Feb 29 16:30:35 2012 +0000 @@ -491,7 +491,7 @@ libxl_cpupoolinfo * libxl_list_cpupool(l } ptr = tmp; ptr[i].poolid = info->cpupool_id; - ptr[i].sched_id = info->sched_id; + ptr[i].sched = info->sched_id; ptr[i].n_dom = info->n_dom; if (libxl_cpumap_alloc(ctx, &ptr[i].cpumap)) { xc_cpupool_infofree(ctx->xch, info); @@ -2750,7 +2750,10 @@ int libxl_get_physinfo(libxl_ctx *ctx, l physinfo->sharing_used_frames = xc_sharing_used_frames(ctx->xch); physinfo->nr_nodes = xcphysinfo.nr_nodes; memcpy(physinfo->hw_cap,xcphysinfo.hw_cap, sizeof(physinfo->hw_cap)); - physinfo->phys_cap = xcphysinfo.capabilities; + + physinfo->cap_hvm = !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_hvm); + physinfo->cap_hvm_directio + !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_hvm_directio); return 0; } @@ -2961,14 +2964,11 @@ out: return rc; } -/* - * returns one of the XEN_SCHEDULER_* constants from public/domctl.h - */ -int libxl_get_sched_id(libxl_ctx *ctx) +libxl_scheduler libxl_get_scheduler(libxl_ctx *ctx) { - int sched, ret; - - if ((ret = xc_sched_id(ctx->xch, &sched)) != 0) { + libxl_scheduler sched, ret; + + if ((ret = xc_sched_id(ctx->xch, (int *)&sched)) != 0) { LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain info list"); return ERROR_FAIL; } @@ -3443,7 +3443,8 @@ int libxl_get_freecpus(libxl_ctx *ctx, l return 0; } -int libxl_cpupool_create(libxl_ctx *ctx, const char *name, int schedid, +int libxl_cpupool_create(libxl_ctx *ctx, const char *name, + libxl_scheduler sched, libxl_cpumap cpumap, libxl_uuid *uuid, uint32_t *poolid) { @@ -3459,7 +3460,7 @@ int libxl_cpupool_create(libxl_ctx *ctx, return ERROR_NOMEM; } - rc = xc_cpupool_create(ctx->xch, poolid, schedid); + rc = xc_cpupool_create(ctx->xch, poolid, sched); if (rc) { LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "Could not create cpupool"); diff -r 5eebc98a4a7f -r 81854ea73a13 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:34 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 @@ -138,7 +138,6 @@ #include <xentoollog.h> #include <xen/sched.h> -#include <xen/sysctl.h> #include <libxl_uuid.h> #include <_libxl_list.h> @@ -584,7 +583,7 @@ int libxl_set_vcpuaffinity_all(libxl_ctx unsigned int max_vcpus, libxl_cpumap *cpumap); int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_cpumap *cpumap); -int libxl_get_sched_id(libxl_ctx *ctx); +libxl_scheduler libxl_get_scheduler(libxl_ctx *ctx); int libxl_sched_credit_domain_get(libxl_ctx *ctx, uint32_t domid, @@ -627,7 +626,8 @@ int libxl_tmem_shared_auth(libxl_ctx *ct int libxl_tmem_freeable(libxl_ctx *ctx); int libxl_get_freecpus(libxl_ctx *ctx, libxl_cpumap *cpumap); -int libxl_cpupool_create(libxl_ctx *ctx, const char *name, int schedid, +int libxl_cpupool_create(libxl_ctx *ctx, const char *name, + libxl_scheduler sched, libxl_cpumap cpumap, libxl_uuid *uuid, uint32_t *poolid); int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid); diff -r 5eebc98a4a7f -r 81854ea73a13 tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 16:30:34 2012 +0000 +++ b/tools/libxl/libxl_types.idl Wed Feb 29 16:30:35 2012 +0000 @@ -105,6 +105,14 @@ libxl_bios_type = Enumeration("bios_type (3, "ovmf"), ]) +# Consistent with values defined in domctl.h +libxl_scheduler = Enumeration("scheduler", [ + (4, "sedf"), + (5, "credit"), + (6, "credit2"), + (7, "arinc653"), + ]) + # # Complex libxl types # @@ -164,7 +172,7 @@ libxl_dominfo = Struct("dominfo",[ libxl_cpupoolinfo = Struct("cpupoolinfo", [ ("poolid", uint32), - ("sched_id", uint32), + ("sched", libxl_scheduler), ("n_dom", uint32), ("cpumap", libxl_cpumap) ]) @@ -388,7 +396,9 @@ libxl_physinfo = Struct("physinfo", [ ("nr_nodes", uint32), ("hw_cap", libxl_hwcap), - ("phys_cap", uint32), + + ("cap_hvm", bool), + ("cap_hvm_directio", bool), ], dispose_fn=None, dir=DIR_OUT) libxl_cputopology = Struct("cputopology", [ diff -r 5eebc98a4a7f -r 81854ea73a13 tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Wed Feb 29 16:30:34 2012 +0000 +++ b/tools/libxl/libxl_utils.c Wed Feb 29 16:30:35 2012 +0000 @@ -19,18 +19,6 @@ #include "libxl_internal.h" -struct schedid_name { - char *name; - int id; -}; - -static struct schedid_name schedid_name[] = { - { "credit", XEN_SCHEDULER_CREDIT }, - { "sedf", XEN_SCHEDULER_SEDF }, - { "credit2", XEN_SCHEDULER_CREDIT2 }, - { NULL, -1 } -}; - const char *libxl_basename(const char *name) { const char *filename; @@ -151,28 +139,6 @@ int libxl_name_to_cpupoolid(libxl_ctx *c return ret; } -int libxl_name_to_schedid(libxl_ctx *ctx, const char *name) -{ - int i; - - for (i = 0; schedid_name[i].name != NULL; i++) - if (strcmp(name, schedid_name[i].name) == 0) - return schedid_name[i].id; - - return ERROR_INVAL; -} - -char *libxl_schedid_to_name(libxl_ctx *ctx, int schedid) -{ - int i; - - for (i = 0; schedid_name[i].name != NULL; i++) - if (schedid_name[i].id == schedid) - return schedid_name[i].name; - - return "unknown"; -} - int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid) { GC_INIT(ctx); diff -r 5eebc98a4a7f -r 81854ea73a13 tools/libxl/libxl_utils.h --- a/tools/libxl/libxl_utils.h Wed Feb 29 16:30:34 2012 +0000 +++ b/tools/libxl/libxl_utils.h Wed Feb 29 16:30:35 2012 +0000 @@ -24,8 +24,6 @@ int libxl_name_to_domid(libxl_ctx *ctx, char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid); int libxl_name_to_cpupoolid(libxl_ctx *ctx, const char *name, uint32_t *poolid); char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid); -int libxl_name_to_schedid(libxl_ctx *ctx, const char *name); -char *libxl_schedid_to_name(libxl_ctx *ctx, int schedid); int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid); int libxl_is_stubdom(libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid); int libxl_create_logfile(libxl_ctx *ctx, char *name, char **full_name); diff -r 5eebc98a4a7f -r 81854ea73a13 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:34 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:35 2012 +0000 @@ -3693,15 +3693,15 @@ int main_vcpuset(int argc, char **argv) static void output_xeninfo(void) { const libxl_version_info *info; - int sched_id; + libxl_scheduler sched; if (!(info = libxl_get_version_info(ctx))) { fprintf(stderr, "libxl_get_version_info failed.\n"); return; } - if ((sched_id = libxl_get_sched_id(ctx)) < 0) { - fprintf(stderr, "get_sched_id sysctl failed.\n"); + if ((sched = libxl_get_scheduler(ctx)) < 0) { + fprintf(stderr, "get_scheduler sysctl failed.\n"); return; } @@ -3709,7 +3709,7 @@ static void output_xeninfo(void) printf("xen_minor : %d\n", info->xen_version_minor); printf("xen_extra : %s\n", info->xen_version_extra); printf("xen_caps : %s\n", info->capabilities); - printf("xen_scheduler : %s\n", libxl_schedid_to_name(ctx, sched_id)); + printf("xen_scheduler : %s\n", libxl_scheduler_to_string(sched)); printf("xen_pagesize : %u\n", info->pagesize); printf("platform_params : virt_start=0x%"PRIx64"\n", info->virt_start); printf("xen_changeset : %s\n", info->changeset); @@ -3757,9 +3757,9 @@ static void output_physinfo(void) for (i = 0; i < 8; i++) printf("%08x%c", info.hw_cap[i], i < 7 ? '':'' : ''\n''); printf("virt_caps :"); - if (info.phys_cap & XEN_SYSCTL_PHYSCAP_hvm) + if (info.cap_hvm) printf(" hvm"); - if (info.phys_cap & XEN_SYSCTL_PHYSCAP_hvm_directio) + if (info.cap_hvm_directio) printf(" hvm_directio"); printf("\n"); vinfo = libxl_get_version_info(ctx); @@ -4065,7 +4065,7 @@ static int sched_sedf_domain_output( } static int sched_domain_output( - uint32_t sched, int (*output)(int), const char *cpupool) + libxl_scheduler sched, int (*output)(int), const char *cpupool) { libxl_dominfo *info; libxl_cpupoolinfo *poolinfo = NULL; @@ -4094,7 +4094,7 @@ static int sched_domain_output( } for (p = 0; !rc && (p < n_pools); p++) { - if ((poolinfo[p].sched_id != sched) || + if ((poolinfo[p].sched != sched) || (cpupool && (poolid != poolinfo[p].poolid))) continue; @@ -4175,7 +4175,7 @@ int main_sched_credit(int argc, char **a } if (!dom) { /* list all domain''s credit scheduler info */ - return -sched_domain_output(XEN_SCHEDULER_CREDIT, + return -sched_domain_output(LIBXL_SCHEDULER_CREDIT, sched_credit_domain_output, cpupool); } else { find_domain(dom); @@ -4251,7 +4251,7 @@ int main_sched_credit2(int argc, char ** } if (!dom) { /* list all domain''s credit scheduler info */ - return -sched_domain_output(XEN_SCHEDULER_CREDIT2, + return -sched_domain_output(LIBXL_SCHEDULER_CREDIT2, sched_credit2_domain_output, cpupool); } else { find_domain(dom); @@ -4353,7 +4353,7 @@ int main_sched_sedf(int argc, char **arg } if (!dom) { /* list all domain''s credit scheduler info */ - return -sched_domain_output(XEN_SCHEDULER_SEDF, + return -sched_domain_output(LIBXL_SCHEDULER_SEDF, sched_sedf_domain_output, cpupool); } else { find_domain(dom); @@ -5292,9 +5292,8 @@ int main_cpupoolcreate(int argc, char ** XLU_Config *config; const char *buf; const char *name; - const char *sched; uint32_t poolid; - int schedid = -1; + libxl_scheduler sched = 0; XLU_ConfigList *cpus; XLU_ConfigList *nodes; int n_cpus, n_nodes, i, n; @@ -5389,17 +5388,16 @@ int main_cpupoolcreate(int argc, char ** } if (!xlu_cfg_get_string (config, "sched", &buf, 0)) { - if ((schedid = libxl_name_to_schedid(ctx, buf)) < 0) { + if ((libxl_scheduler_from_string(buf, &sched)) < 0) { fprintf(stderr, "Unknown scheduler\n"); return -ERROR_FAIL; } } else { - if ((schedid = libxl_get_sched_id(ctx)) < 0) { - fprintf(stderr, "get_sched_id sysctl failed.\n"); + if ((sched = libxl_get_scheduler(ctx)) < 0) { + fprintf(stderr, "get_scheduler sysctl failed.\n"); return -ERROR_FAIL; } } - sched = libxl_schedid_to_name(ctx, schedid); if (libxl_get_freecpus(ctx, &freemap)) { fprintf(stderr, "libxl_get_freecpus failed\n"); @@ -5467,14 +5465,14 @@ int main_cpupoolcreate(int argc, char ** printf("Using config file \"%s\"\n", filename); printf("cpupool name: %s\n", name); - printf("scheduler: %s\n", sched); + printf("scheduler: %s\n", libxl_scheduler_to_string(sched)); printf("number of cpus: %d\n", n_cpus); if (dryrun_only) return 0; poolid = 0; - if (libxl_cpupool_create(ctx, name, schedid, cpumap, &uuid, &poolid)) { + if (libxl_cpupool_create(ctx, name, sched, cpumap, &uuid, &poolid)) { fprintf(stderr, "error on creating cpupool\n"); return -ERROR_FAIL; } @@ -5559,7 +5557,7 @@ int main_cpupoollist(int argc, char **ar } if (!opt_cpus) { printf("%3d %9s y %4d", n, - libxl_schedid_to_name(ctx, poolinfo[p].sched_id), + libxl_scheduler_to_string(poolinfo[p].sched), poolinfo[p].n_dom); } printf("\n"); @@ -5744,7 +5742,7 @@ int main_cpupoolnumasplit(int argc, char int c; int n; uint32_t poolid; - int schedid; + libxl_scheduler sched; int n_pools; int node; int n_cpus; @@ -5765,7 +5763,7 @@ int main_cpupoolnumasplit(int argc, char return -ERROR_NOMEM; } poolid = poolinfo[0].poolid; - schedid = poolinfo[0].sched_id; + sched = poolinfo[0].sched; for (p = 0; p < n_pools; p++) { libxl_cpupoolinfo_dispose(poolinfo + p); } @@ -5845,7 +5843,7 @@ int main_cpupoolnumasplit(int argc, char snprintf(name, 15, "Pool-node%d", node); libxl_uuid_generate(&uuid); poolid = 0; - ret = -libxl_cpupool_create(ctx, name, schedid, cpumap, &uuid, &poolid); + ret = -libxl_cpupool_create(ctx, name, sched, cpumap, &uuid, &poolid); if (ret) { fprintf(stderr, "error on creating cpupool\n"); goto out;
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 02 of 27 V4] libxl: Remove xen/sched.h from public interface
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533035 0 # Node ID 84a2d39f711e439952cdc3fd0b0a9a065dae2c5c # Parent 81854ea73a132154021df881c58aff6f870a4384 libxl: Remove xen/sched.h from public interface Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 81854ea73a13 -r 84a2d39f711e tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 @@ -137,8 +137,6 @@ #include <xentoollog.h> -#include <xen/sched.h> - #include <libxl_uuid.h> #include <_libxl_list.h> @@ -638,12 +636,7 @@ int libxl_cpupool_cpuremove(libxl_ctx *c int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus); int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid); -static inline int libxl_domid_valid_guest(uint32_t domid) -{ - /* returns 1 if the value _could_ be a valid guest domid, 0 otherwise - * does not check whether the domain actually exists */ - return domid > 0 && domid < DOMID_FIRST_RESERVED; -} +int libxl_domid_valid_guest(uint32_t domid); int libxl_flask_context_to_sid(libxl_ctx *ctx, char *buf, size_t len, uint32_t *ssidref); diff -r 81854ea73a13 -r 84a2d39f711e tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_types.idl Wed Feb 29 16:30:35 2012 +0000 @@ -113,6 +113,15 @@ libxl_scheduler = Enumeration("scheduler (7, "arinc653"), ]) +# Consistent with SHUTDOWN_* in sched.h +libxl_shutdown_reason = Enumeration("shutdown_reason", [ + (0, "poweroff"), + (1, "reboot"), + (2, "suspend"), + (3, "crash"), + (4, "watchdog"), + ]) + # # Complex libxl types # @@ -156,11 +165,11 @@ libxl_dominfo = Struct("dominfo",[ ("shutdown", bool), ("dying", bool), - # Valid SHUTDOWN_* value from xen/sched.h iff (shutdown||dying). + # Valid iff (shutdown||dying). # # Otherwise set to a value guaranteed not to clash with any valid - # SHUTDOWN_* constant. - ("shutdown_reason", uint8), + # LIBXL_SHUTDOWN_REASON_* constant. + ("shutdown_reason", libxl_shutdown_reason), ("current_memkb", uint64), ("shared_memkb", uint64), ("max_memkb", uint64), diff -r 81854ea73a13 -r 84a2d39f711e tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_utils.c Wed Feb 29 16:30:35 2012 +0000 @@ -507,6 +507,13 @@ void libxl_cputopology_list_free(libxl_c free(list); } +int libxl_domid_valid_guest(uint32_t domid) +{ + /* returns 1 if the value _could_ be a valid guest domid, 0 otherwise + * does not check whether the domain actually exists */ + return domid > 0 && domid < DOMID_FIRST_RESERVED; +} + /* * Local variables: * mode: C diff -r 81854ea73a13 -r 84a2d39f711e tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:35 2012 +0000 @@ -1235,19 +1235,19 @@ static int handle_domain_death(libxl_ctx libxl_action_on_shutdown action; switch (event->u.domain_shutdown.shutdown_reason) { - case SHUTDOWN_poweroff: + case LIBXL_SHUTDOWN_REASON_POWEROFF: action = d_config->on_poweroff; break; - case SHUTDOWN_reboot: + case LIBXL_SHUTDOWN_REASON_REBOOT: action = d_config->on_reboot; break; - case SHUTDOWN_suspend: + case LIBXL_SHUTDOWN_REASON_SUSPEND: LOG("Domain has suspended."); return 0; - case SHUTDOWN_crash: + case LIBXL_SHUTDOWN_REASON_CRASH: action = d_config->on_crash; break; - case SHUTDOWN_watchdog: + case LIBXL_SHUTDOWN_REASON_WATCHDOG: action = d_config->on_watchdog; break; default: diff -r 81854ea73a13 -r 84a2d39f711e tools/python/xen/lowlevel/xl/xl.c --- a/tools/python/xen/lowlevel/xl/xl.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/python/xen/lowlevel/xl/xl.c Wed Feb 29 16:30:35 2012 +0000 @@ -762,11 +762,11 @@ PyMODINIT_FUNC initxl(void) Py_INCREF(xl_error_obj); PyModule_AddObject(m, "Error", xl_error_obj); - _INT_CONST(m, SHUTDOWN_poweroff); - _INT_CONST(m, SHUTDOWN_reboot); - _INT_CONST(m, SHUTDOWN_suspend); - _INT_CONST(m, SHUTDOWN_crash); - _INT_CONST(m, SHUTDOWN_watchdog); + _INT_CONST_LIBXL(m, SHUTDOWN_REASON_POWEROFF); + _INT_CONST_LIBXL(m, SHUTDOWN_REASON_REBOOT); + _INT_CONST_LIBXL(m, SHUTDOWN_REASON_SUSPEND); + _INT_CONST_LIBXL(m, SHUTDOWN_REASON_CRASH); + _INT_CONST_LIBXL(m, SHUTDOWN_REASON_WATCHDOG); genwrap__init(m); }
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 03 of 27 V4] libxl: allow specification of testidl random seed
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533035 0 # Node ID b2aa980ba1ec2195a44ca193e7e558cb54c85762 # Parent 84a2d39f711e439952cdc3fd0b0a9a065dae2c5c libxl: allow specification of testidl random seed. Useful if you are interested in before/after results of changing the IDL or generator. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r 84a2d39f711e -r b2aa980ba1ec tools/libxl/gentest.py --- a/tools/libxl/gentest.py Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/gentest.py Wed Feb 29 16:30:35 2012 +0000 @@ -1,5 +1,6 @@ #!/usr/bin/python +import os import sys import re import random @@ -72,7 +73,7 @@ if __name__ == ''__main__'': print >>sys.stderr, "Usage: gentest.py <idl> <implementation>" sys.exit(1) - random.seed() + random.seed(os.getenv(''LIBXL_TESTIDL_SEED'')) (builtins,types) = idl.parse(sys.argv[1])
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 04 of 27 V4] libxl: generate a _dispose function for all Aggregate types
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533035 0 # Node ID 5c77ed035a404c9874bc530ee1de271b923951a8 # Parent b2aa980ba1ec2195a44ca193e7e558cb54c85762 libxl: generate a _dispose function for all Aggregate types Don''t special case types which we happen to know do not contain allocated data such that in the future if this changes we do not need to add an API. Although there is likely to be latent bugs in callers due to this having the API in old libraries mean that when callers are fixed they will not need to make special arrangements to handle old and new versions of the library. Adds dispose functions for: - libxl_dominfo - libxl_cpupoolinfo - libxl_physinfo - libxl_sched_credit - libxl_sched_credit2 I have attempted to fix any latent bugs in xl by inspection but have not bothered with libxl (on the basis that internally the library is allowed to make these sorts of assumptions and because it was looking like a very invasive job and that more would only creep in anyway). Several callsites use libxl_domain_info to check for the presence of a domain and throw away the actual info. As a convenience accept a NULL info pointer and just return the status. Also fix a memory leak in libxl_domain_list. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r b2aa980ba1ec -r 5c77ed035a40 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.c Wed Feb 29 16:30:35 2012 +0000 @@ -442,6 +442,7 @@ libxl_dominfo * libxl_list_domain(libxl_ ret = xc_domain_getinfolist(ctx->xch, 0, 1024, info); if (ret<0) { LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "geting domain info list"); + free(ptr); return NULL; } @@ -464,7 +465,8 @@ int libxl_domain_info(libxl_ctx *ctx, li } if (ret==0 || xcinfo.domain != domid) return ERROR_INVAL; - xcinfo2xlinfo(&xcinfo, info_r); + if (info_r) + xcinfo2xlinfo(&xcinfo, info_r); return 0; } @@ -986,13 +988,12 @@ void libxl_evdisable_disk_eject(libxl_ct int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid) { GC_INIT(ctx); - libxl_dominfo dominfo; char *dom_path; char *vm_path; char *pid; int rc, dm_present; - rc = libxl_domain_info(ctx, &dominfo, domid); + rc = libxl_domain_info(ctx, NULL, domid); switch(rc) { case 0: break; diff -r b2aa980ba1ec -r 5c77ed035a40 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 @@ -387,11 +387,14 @@ int libxl_console_exec(libxl_ctx *ctx, u * guests using pygrub. */ int libxl_primary_console_exec(libxl_ctx *ctx, uint32_t domid_vm); +/* May be called with info_r == NULL to check for domain''s existance */ int libxl_domain_info(libxl_ctx*, libxl_dominfo *info_r, uint32_t domid); libxl_dominfo * libxl_list_domain(libxl_ctx*, int *nb_domain); +void libxl_dominfo_list_free(libxl_dominfo *list, int nr); libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool); libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm); +void libxl_vminfo_list_free(libxl_vminfo *list, int nr); /* * Devices diff -r b2aa980ba1ec -r 5c77ed035a40 tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_types.idl Wed Feb 29 16:30:35 2012 +0000 @@ -177,7 +177,7 @@ libxl_dominfo = Struct("dominfo",[ ("vcpu_max_id", uint32), ("vcpu_online", uint32), ("cpupool", uint32), - ], dispose_fn=None) + ]) libxl_cpupoolinfo = Struct("cpupoolinfo", [ ("poolid", uint32), @@ -189,7 +189,7 @@ libxl_cpupoolinfo = Struct("cpupoolinfo" libxl_vminfo = Struct("vminfo", [ ("uuid", libxl_uuid), ("domid", libxl_domid), - ], dispose_fn=None) + ]) libxl_version_info = Struct("version_info", [ ("xen_version_major", integer), @@ -408,7 +408,7 @@ libxl_physinfo = Struct("physinfo", [ ("cap_hvm", bool), ("cap_hvm_directio", bool), - ], dispose_fn=None, dir=DIR_OUT) + ], dir=DIR_OUT) libxl_cputopology = Struct("cputopology", [ ("core", uint32), @@ -419,11 +419,11 @@ libxl_cputopology = Struct("cputopology" libxl_sched_credit_domain = Struct("sched_credit_domain", [ ("weight", integer), ("cap", integer), - ], dispose_fn=None) + ]) libxl_sched_credit2_domain = Struct("sched_credit2_domain", [ ("weight", integer), - ], dispose_fn=None) + ]) libxl_sched_sedf_domain = Struct("sched_sedf_domain", [ ("period", integer), @@ -431,7 +431,7 @@ libxl_sched_sedf_domain = Struct("sched_ ("latency", integer), ("extratime", integer), ("weight", integer), - ], dispose_fn=None) + ]) libxl_event_type = Enumeration("event_type", [ (1, "DOMAIN_SHUTDOWN"), diff -r b2aa980ba1ec -r 5c77ed035a40 tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_utils.c Wed Feb 29 16:30:35 2012 +0000 @@ -507,6 +507,22 @@ void libxl_cputopology_list_free(libxl_c free(list); } +void libxl_dominfo_list_free(libxl_dominfo *list, int nr) +{ + int i; + for (i = 0; i < nr; i++) + libxl_dominfo_dispose(&list[i]); + free(list); +} + +void libxl_vminfo_list_free(libxl_vminfo *list, int nr) +{ + int i; + for (i = 0; i < nr; i++) + libxl_vminfo_dispose(&list[i]); + free(list); +} + int libxl_domid_valid_guest(uint32_t domid) { /* returns 1 if the value _could_ be a valid guest domid, 0 otherwise diff -r b2aa980ba1ec -r 5c77ed035a40 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:35 2012 +0000 @@ -144,7 +144,6 @@ static int qualifier_to_id(const char *p static int domain_qualifier_to_domid(const char *p, uint32_t *domid_r, int *was_name_r) { - libxl_dominfo dominfo; int was_name, rc; was_name = qualifier_to_id(p, domid_r); @@ -156,7 +155,7 @@ static int domain_qualifier_to_domid(con if (rc) return rc; } else { - rc = libxl_domain_info(ctx, &dominfo, *domid_r); + rc = libxl_domain_info(ctx, NULL, *domid_r); /* error only if domain does not exist */ if (rc == ERROR_INVAL) return rc; @@ -2505,7 +2504,7 @@ static void list_vm(void) info[i].domid, domname); free(domname); } - free(info); + libxl_vminfo_list_free(info, nb_vm); } static void save_domain_core_begin(const char *domain_spec, @@ -3302,7 +3301,10 @@ int main_list(int argc, char **argv) else list_domains(verbose, context, info, nb_domain); - free(info_free); + if (info_free) + libxl_dominfo_list_free(info, nb_domain); + else + libxl_dominfo_dispose(info); return 0; } @@ -3565,8 +3567,7 @@ static void vcpulist(int argc, char **ar for (i = 0; i<nb_domain; i++) print_domain_vcpuinfo(dominfo[i].domid, physinfo.nr_cpus); - free(dominfo); - + libxl_dominfo_list_free(dominfo, nb_domain); } else { for (; argc > 0; ++argv, --argc) { if (domain_qualifier_to_domid(*argv, &domid, 0) < 0) { @@ -3578,7 +3579,7 @@ static void vcpulist(int argc, char **ar } } vcpulist_out: - ; + libxl_physinfo_dispose(&physinfo); } int main_vcpulist(int argc, char **argv) @@ -3778,6 +3779,7 @@ static void output_physinfo(void) free(cpumap.map); } + libxl_physinfo_dispose(&info); return; } @@ -3912,7 +3914,9 @@ int main_sharing(int argc, char **argv) sharing(info, nb_domain); if (info_free) - free(info_free); + libxl_dominfo_list_free(info_free, nb_domain); + else + libxl_dominfo_dispose(info); return 0; } @@ -4968,6 +4972,7 @@ static void print_uptime(int short_mode, info = libxl_list_vm(ctx, &nb_vm); for (i = 0; i < nb_vm; i++) print_domU_uptime(info[i].domid, short_mode, now); + libxl_vminfo_list_free(info, nb_vm); } else { for (i = 0; i < nb_doms; i++) { if (doms[i] == 0)
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 05 of 27 V4] libxl: Document _init/_dispose/_setdefault functions
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533035 0 # Node ID 8cfc778d4547fc37f16895771312d858c5eca5b9 # Parent 5c77ed035a404c9874bc530ee1de271b923951a8 libxl: Document _init/_dispose/_setdefault functions. Subsequent patches will transition to them. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 5c77ed035a40 -r 8cfc778d4547 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 @@ -124,6 +124,50 @@ * Therefore public functions which initialize a libxl__gc MUST call * libxl__free_all() before returning. */ +/* + * libxl types + * + * Most libxl types are defined by the libxl IDL (see + * libxl_types.idl). The library provides a common set of methods for + * initialising and freeing these types. + * + * void libxl_<type>_init(<type> *p): + * + * Initialises the members of "p" to all defaults. These may either + * be special value which indicates to the library that it should + * select an appropriate default when using this field or actual + * default values. + * + * Some fields within a data type (e.g. unions) cannot be sensibly + * initialised without further information. In these cases a + * separate subfield initialisation function is provided (see + * below). + * + * An instance which has been initialised using this method can + * always be safely passed to the dispose function (see + * below). This is true even if the data type contains fields which + * require a separate call to a subfield initialisation function. + * + * This method is provided for any aggregate type which is used as + * an input parameter. + * + * void libxl_<type>_init_<subfield>(<type> *p, subfield): + * + * Initialise those parts of "p" which are not initialised by the + * main init function due to the unknown value of "subfield". Sets + * p->subfield as well as initialising any fields to their default + * values. + * + * p->subfield must not have been previously initialised. + * + * This method is provided for any aggregate type. + * + * void libxl_<type>_dispose(instance *p): + * + * Frees any dynamically allocated memory used by the members of + * "p" but not the storage used by "p" itself (this allows for the + * allocation of arrays of types and for the composition of types). + */ #ifndef LIBXL_H #define LIBXL_H @@ -405,8 +449,9 @@ void libxl_vminfo_list_free(libxl_vminfo * additional data type libxl_device_<TYPE>_getinfo which contains * further runtime information about the device. * - * A common set of methods are available for each device type. These - * are described below. + * In addition to the general methods available for libxl types (see + * "libxl types" above) a common set of methods are available for each + * device type. These are described below. * * Querying * -------- @@ -424,10 +469,6 @@ void libxl_vminfo_list_free(libxl_vminfo * Creation / Control * ------------------ * - * libxl_device_<type>_init(ctx, device): - * - * Initalises device to a default configuration. - * * libxl_device_<type>_add(ctx, domid, device): * * Adds the given device to the specified domain. This can be called diff -r 5c77ed035a40 -r 8cfc778d4547 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_internal.h Wed Feb 29 16:30:35 2012 +0000 @@ -665,6 +665,19 @@ _hidden int libxl__device_destroy(libxl_ _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid); _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state); +/* + * For each aggregate type which can be used as an input we provide: + * + * int libxl__<type>_setdefault(gc, <type> *p): + * + * Idempotently sets any members of "p" which is currently set to + * a special value indicating that the defaults should be used + * (per libxl_<type>_init) to a specific value. + * + * All libxl API functions are expected to have arranged for this + * to be called before using any values within these structures. + */ + /* Arranges that dev will be removed from its guest. When * this is done, the ao will be completed. An error * return from libxl__initiate_device_remove means that the ao
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 06 of 27 V4] libxl: provide _init and _setdefault for libxl_domain_create_info
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533035 0 # Node ID 1284834d9b10a613573e0889822736e6e8941e0f # Parent 8cfc778d4547fc37f16895771312d858c5eca5b9 libxl: provide _init and _setdefault for libxl_domain_create_info. Some fields require further scaffolding before they can use the _init/_setdefault scheme and are handled in later patches. It doesn''t seem reasonable for the library to pick a default for the domain type so reject as invalid. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 8cfc778d4547 -r 1284834d9b10 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 @@ -356,7 +356,7 @@ int libxl_ctx_free(libxl_ctx *ctx /* 0 i int libxl_ctx_postfork(libxl_ctx *ctx); /* domain related functions */ -int libxl_init_create_info(libxl_ctx *ctx, libxl_domain_create_info *c_info); +void libxl_domain_create_info_init(libxl_domain_create_info *c_info); int libxl_init_build_info(libxl_ctx *ctx, libxl_domain_build_info *b_info, libxl_domain_create_info *c_info); diff -r 8cfc778d4547 -r 1284834d9b10 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 @@ -50,16 +50,19 @@ void libxl_domain_config_dispose(libxl_d libxl_domain_build_info_dispose(&d_config->b_info); } -int libxl_init_create_info(libxl_ctx *ctx, libxl_domain_create_info *c_info) +void libxl_domain_create_info_init(libxl_domain_create_info *c_info) { memset(c_info, ''\0'', sizeof(*c_info)); - c_info->xsdata = NULL; - c_info->platformdata = NULL; c_info->hap = 1; - c_info->type = LIBXL_DOMAIN_TYPE_HVM; c_info->oos = 1; - c_info->ssidref = 0; - c_info->poolid = 0; +} + +int libxl__domain_create_info_setdefault(libxl__gc *gc, + libxl_domain_create_info *c_info) +{ + if (!c_info->type) + return ERROR_INVAL; + return 0; } @@ -470,6 +473,9 @@ static int do_domain_create(libxl__gc *g domid = 0; + ret = libxl__domain_create_info_setdefault(gc, &d_config->c_info); + if (ret) goto error_out; + ret = libxl__domain_make(gc, &d_config->c_info, &domid); if (ret) { LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot make domain: %d", ret); diff -r 8cfc778d4547 -r 1284834d9b10 tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_dm.c Wed Feb 29 16:30:35 2012 +0000 @@ -705,7 +705,7 @@ static int libxl__create_stubdom(libxl__ goto out; } - memset(&dm_config.c_info, 0x00, sizeof(libxl_domain_create_info)); + libxl_domain_create_info_init(&dm_config.c_info); dm_config.c_info.type = LIBXL_DOMAIN_TYPE_PV; dm_config.c_info.name = libxl__sprintf(gc, "%s-dm", libxl__domid_to_name(gc, guest_domid)); @@ -740,6 +740,9 @@ static int libxl__create_stubdom(libxl__ dm_config.vifs = guest_config->vifs; dm_config.num_vifs = guest_config->num_vifs; + ret = libxl__domain_create_info_setdefault(gc, &dm_config.c_info); + if (ret) goto out; + libxl__vfb_and_vkb_from_hvm_guest_config(gc, guest_config, &vfb, &vkb); dm_config.vfbs = &vfb; dm_config.num_vfbs = 1; diff -r 8cfc778d4547 -r 1284834d9b10 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_internal.h Wed Feb 29 16:30:35 2012 +0000 @@ -187,6 +187,8 @@ libxl__ev_xswatch *libxl__watch_slot_con * version of the _evdisable_FOO function; the internal one is * used during cleanup. */ +_hidden int libxl__domain_create_info_setdefault(libxl__gc *gc, + libxl_domain_create_info *c_info); struct libxl__evgen_domain_death { uint32_t domid; diff -r 8cfc778d4547 -r 1284834d9b10 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:35 2012 +0000 @@ -535,8 +535,7 @@ static void parse_config_data(const char exit(1); } - if (libxl_init_create_info(ctx, c_info)) - exit(1); + libxl_domain_create_info_init(c_info); if (!xlu_cfg_get_string (config, "seclabel", &buf, 0)) { e = libxl_flask_context_to_sid(ctx, (char *)buf, strlen(buf),
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 07 of 27 V4] libxl: provide _init and _setdefault for libxl_domain_build_info
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533035 0 # Node ID 80dd9bfaaf0be68117bc01833b892663c87b98e3 # Parent 1284834d9b10a613573e0889822736e6e8941e0f libxl: provide _init and _setdefault for libxl_domain_build_info. Some fields require further scaffolding before they can use the _init/_setdefault scheme and are handled in later patches. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 1284834d9b10 -r 80dd9bfaaf0b tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.c Wed Feb 29 16:30:35 2012 +0000 @@ -2625,7 +2625,11 @@ int libxl_domain_need_memory(libxl_ctx * uint32_t *need_memkb) { GC_INIT(ctx); - int rc = ERROR_INVAL; + int rc; + + rc = libxl__domain_build_info_setdefault(gc, b_info); + if (rc) goto out; + *need_memkb = b_info->target_memkb; switch (b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: @@ -2637,6 +2641,7 @@ int libxl_domain_need_memory(libxl_ctx * *need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY; break; default: + rc = ERROR_INVAL; goto out; } if (*need_memkb % (2 * 1024)) diff -r 1284834d9b10 -r 80dd9bfaaf0b tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 @@ -357,9 +357,8 @@ int libxl_ctx_postfork(libxl_ctx *ctx); /* domain related functions */ void libxl_domain_create_info_init(libxl_domain_create_info *c_info); -int libxl_init_build_info(libxl_ctx *ctx, - libxl_domain_build_info *b_info, - libxl_domain_create_info *c_info); +void libxl_domain_build_info_init(libxl_domain_build_info *b_info, + const libxl_domain_create_info *c_info); typedef int (*libxl_console_ready)(libxl_ctx *ctx, uint32_t domid, void *priv); int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid); int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid, int restore_fd); diff -r 1284834d9b10 -r 80dd9bfaaf0b tools/libxl/libxl_bootloader.c --- a/tools/libxl/libxl_bootloader.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_bootloader.c Wed Feb 29 16:30:35 2012 +0000 @@ -346,6 +346,9 @@ int libxl_run_bootloader(libxl_ctx *ctx, struct stat st_buf; + rc = libxl__domain_build_info_setdefault(gc, info); + if (rc) goto out; + if (info->type != LIBXL_DOMAIN_TYPE_PV || !info->u.pv.bootloader) goto out; diff -r 1284834d9b10 -r 80dd9bfaaf0b tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 @@ -66,16 +66,10 @@ int libxl__domain_create_info_setdefault return 0; } -int libxl_init_build_info(libxl_ctx *ctx, - libxl_domain_build_info *b_info, - libxl_domain_create_info *c_info) +void libxl_domain_build_info_init(libxl_domain_build_info *b_info, + const libxl_domain_create_info *c_info) { memset(b_info, ''\0'', sizeof(*b_info)); - b_info->max_vcpus = 1; - b_info->cur_vcpus = 1; - if (libxl_cpumap_alloc(ctx, &b_info->cpumap)) - return ERROR_NOMEM; - libxl_cpumap_set_any(&b_info->cpumap); b_info->max_memkb = 32 * 1024; b_info->target_memkb = b_info->max_memkb; b_info->disable_migrate = 0; @@ -83,8 +77,6 @@ int libxl_init_build_info(libxl_ctx *ctx b_info->shadow_memkb = 0; b_info->type = c_info->type; - b_info->device_model_version - LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; b_info->device_model_stubdomain = false; b_info->device_model = NULL; @@ -108,15 +100,9 @@ int libxl_init_build_info(libxl_ctx *ctx b_info->u.hvm.stdvga = 0; b_info->u.hvm.vnc.enable = 1; - b_info->u.hvm.vnc.listen = strdup("127.0.0.1"); b_info->u.hvm.vnc.display = 0; b_info->u.hvm.vnc.findunused = 1; - b_info->u.hvm.keymap = NULL; - b_info->u.hvm.sdl.enable = 0; - b_info->u.hvm.sdl.opengl = 0; - b_info->u.hvm.nographic = 0; b_info->u.hvm.serial = NULL; - b_info->u.hvm.boot = strdup("cda"); b_info->u.hvm.usb = 0; b_info->u.hvm.usbdevice = NULL; b_info->u.hvm.xen_platform_pci = 1; @@ -125,7 +111,47 @@ int libxl_init_build_info(libxl_ctx *ctx b_info->u.pv.slack_memkb = 8 * 1024; break; default: - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, + abort(); + } +} + +int libxl__domain_build_info_setdefault(libxl__gc *gc, + libxl_domain_build_info *b_info) +{ + if (!b_info->device_model_version) + b_info->device_model_version + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; + + if (!b_info->max_vcpus) + b_info->max_vcpus = 1; + if (!b_info->cur_vcpus) + b_info->cur_vcpus = 1; + + if (!b_info->cpumap.size) { + if (libxl_cpumap_alloc(CTX, &b_info->cpumap)) + return ERROR_NOMEM; + libxl_cpumap_set_any(&b_info->cpumap); + } + + switch (b_info->type) { + case LIBXL_DOMAIN_TYPE_HVM: + if (!b_info->u.hvm.boot) { + b_info->u.hvm.boot = strdup("cda"); + if (!b_info->u.hvm.boot) return ERROR_NOMEM; + } + + if (b_info->u.hvm.vnc.enable) { + if (!b_info->u.hvm.vnc.listen) { + b_info->u.hvm.vnc.listen = strdup("127.0.0.1"); + if (!b_info->u.hvm.vnc.listen) return ERROR_NOMEM; + } + } + + break; + case LIBXL_DOMAIN_TYPE_PV: + break; + default: + LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "invalid domain type %s in create info", libxl_domain_type_to_string(b_info->type)); return ERROR_INVAL; @@ -488,6 +514,8 @@ static int do_domain_create(libxl__gc *g goto error_out; } + ret = libxl__domain_build_info_setdefault(gc, &d_config->b_info); + if (ret) goto error_out; for (i = 0; i < d_config->num_disks; i++) { ret = libxl__device_disk_set_backend(gc, &d_config->disks[i]); diff -r 1284834d9b10 -r 80dd9bfaaf0b tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_dm.c Wed Feb 29 16:30:35 2012 +0000 @@ -713,13 +713,12 @@ static int libxl__create_stubdom(libxl__ libxl_uuid_generate(&dm_config.c_info.uuid); - memset(&dm_config.b_info, 0x00, sizeof(libxl_domain_build_info)); - dm_config.b_info.type = dm_config.c_info.type; + libxl_domain_build_info_init(&dm_config.b_info, &dm_config.c_info); + dm_config.b_info.max_vcpus = 1; dm_config.b_info.max_memkb = 32 * 1024; dm_config.b_info.target_memkb = dm_config.b_info.max_memkb; - dm_config.b_info.type = LIBXL_DOMAIN_TYPE_PV; dm_config.b_info.u.pv.kernel.path = libxl__abs_path(gc, "ioemu-stubdom.gz", libxl_xenfirmwaredir_path()); dm_config.b_info.u.pv.cmdline = libxl__sprintf(gc, " -d %d", guest_domid); @@ -742,6 +741,8 @@ static int libxl__create_stubdom(libxl__ ret = libxl__domain_create_info_setdefault(gc, &dm_config.c_info); if (ret) goto out; + ret = libxl__domain_build_info_setdefault(gc, &dm_config.b_info); + if (ret) goto out; libxl__vfb_and_vkb_from_hvm_guest_config(gc, guest_config, &vfb, &vkb); dm_config.vfbs = &vfb; diff -r 1284834d9b10 -r 80dd9bfaaf0b tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_internal.h Wed Feb 29 16:30:35 2012 +0000 @@ -189,6 +189,8 @@ libxl__ev_xswatch *libxl__watch_slot_con */ _hidden int libxl__domain_create_info_setdefault(libxl__gc *gc, libxl_domain_create_info *c_info); +_hidden int libxl__domain_build_info_setdefault(libxl__gc *gc, + libxl_domain_build_info *b_info); struct libxl__evgen_domain_death { uint32_t domid; diff -r 1284834d9b10 -r 80dd9bfaaf0b tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:35 2012 +0000 @@ -584,8 +584,7 @@ static void parse_config_data(const char exit(1); } - if (libxl_init_build_info(ctx, b_info, c_info)) - exit(1); + libxl_domain_build_info_init(b_info, c_info); /* the following is the actual config parsing with overriding values in the structures */ if (!xlu_cfg_get_long (config, "vcpus", &l, 0)) { @@ -599,6 +598,11 @@ static void parse_config_data(const char if (!xlu_cfg_get_list (config, "cpus", &cpus, 0, 1)) { int i, n_cpus = 0; + if (libxl_cpumap_alloc(ctx, &b_info->cpumap)) { + fprintf(stderr, "Unable to allocate cpumap\n"); + exit(1); + } + libxl_cpumap_set_none(&b_info->cpumap); while ((buf = xlu_cfg_get_listitem(cpus, n_cpus)) != NULL) { i = atoi(buf); @@ -613,6 +617,11 @@ static void parse_config_data(const char else if (!xlu_cfg_get_string (config, "cpus", &buf, 0)) { char *buf2 = strdup(buf); + if (libxl_cpumap_alloc(ctx, &b_info->cpumap)) { + fprintf(stderr, "Unable to allocate cpumap\n"); + exit(1); + } + libxl_cpumap_set_none(&b_info->cpumap); if (vcpupin_parse(buf2, &b_info->cpumap)) exit(1);
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 08 of 27 V4] libxl: use an explicit LIBXL_TIMER_MODE_DEFAULT value
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533035 0 # Node ID 94609c13694b3db49f4da73cdfb3cacb16d597cc # Parent 80dd9bfaaf0be68117bc01833b892663c87b98e3 libxl: use an explicit LIBXL_TIMER_MODE_DEFAULT value Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r 80dd9bfaaf0b -r 94609c13694b tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 @@ -245,7 +245,7 @@ typedef LIBXL_TAILQ_ENTRY(struct libxl_e typedef struct libxl__ctx libxl_ctx; -#define LIBXL_TIMER_MODE_DEFAULT LIBXL_TIMER_MODE_NO_DELAY_FOR_MISSED_TICKS +#define LIBXL_TIMER_MODE_DEFAULT -1 #include "_libxl_types.h" diff -r 80dd9bfaaf0b -r 94609c13694b tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 @@ -94,7 +94,7 @@ void libxl_domain_build_info_init(libxl_ b_info->u.hvm.viridian = 0; b_info->u.hvm.hpet = 1; b_info->u.hvm.vpt_align = 1; - b_info->u.hvm.timer_mode = 1; + b_info->u.hvm.timer_mode = LIBXL_TIMER_MODE_DEFAULT; b_info->u.hvm.nested_hvm = 0; b_info->u.hvm.no_incr_generationid = 0; @@ -135,6 +135,10 @@ int libxl__domain_build_info_setdefault( switch (b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: + if (b_info->u.hvm.timer_mode == LIBXL_TIMER_MODE_DEFAULT) + b_info->u.hvm.timer_mode + LIBXL_TIMER_MODE_NO_DELAY_FOR_MISSED_TICKS; + if (!b_info->u.hvm.boot) { b_info->u.hvm.boot = strdup("cda"); if (!b_info->u.hvm.boot) return ERROR_NOMEM;
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533035 0 # Node ID 096829acb3693eb30787ad859775adb9064fe42c # Parent 94609c13694b3db49f4da73cdfb3cacb16d597cc libxl: drop 8M slack for PV guests. This serves no purpose. It relates to the old 8M to "account for backend allocations" which we used to add. This leaves a bit of unpopulated space in the Pseudo-physical address space which can be used by backends when mapping foreign memory. However 8M is not representative of that any more and modern kernels do not operate in this way anyway. I suspect an argument could be made for removing this from the libxl API altogether but instead lets just set the overhead to 0. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 94609c13694b -r 096829acb369 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 @@ -108,7 +108,7 @@ void libxl_domain_build_info_init(libxl_ b_info->u.hvm.xen_platform_pci = 1; break; case LIBXL_DOMAIN_TYPE_PV: - b_info->u.pv.slack_memkb = 8 * 1024; + b_info->u.pv.slack_memkb = 0; break; default: abort();
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 10 of 27 V4] libxl: introduce a descriminating default value for memkb fields
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533035 0 # Node ID 95e87306617eb179741b03f31bb16c2245789322 # Parent 096829acb3693eb30787ad859775adb9064fe42c libxl: introduce a descriminating default value for memkb fields. Consitently make such fields 64 bit values as used by dominfo. It is not clear if ->video_memkb and/or shadow_memkb shouldn''t be part of ->u.hvm but I have not changed that here. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r 096829acb369 -r 95e87306617e tools/libxl/gentest.py --- a/tools/libxl/gentest.py Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/gentest.py Wed Feb 29 16:30:35 2012 +0000 @@ -197,6 +197,7 @@ static void libxl_string_list_rand_init( } """) for ty in builtins + types: + if isinstance(ty, idl.Number): continue if ty.typename not in handcoded: f.write("static void %s_rand_init(%s);\n" % \ (ty.typename, diff -r 096829acb369 -r 95e87306617e tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 @@ -246,6 +246,7 @@ typedef LIBXL_TAILQ_ENTRY(struct libxl_e typedef struct libxl__ctx libxl_ctx; #define LIBXL_TIMER_MODE_DEFAULT -1 +#define LIBXL_MEMKB_DEFAULT ~0ULL #include "_libxl_types.h" diff -r 096829acb369 -r 95e87306617e tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 @@ -70,19 +70,20 @@ void libxl_domain_build_info_init(libxl_ const libxl_domain_create_info *c_info) { memset(b_info, ''\0'', sizeof(*b_info)); - b_info->max_memkb = 32 * 1024; - b_info->target_memkb = b_info->max_memkb; b_info->disable_migrate = 0; b_info->cpuid = NULL; - b_info->shadow_memkb = 0; b_info->type = c_info->type; + b_info->max_memkb = LIBXL_MEMKB_DEFAULT; + b_info->target_memkb = LIBXL_MEMKB_DEFAULT; + b_info->shadow_memkb = LIBXL_MEMKB_DEFAULT; + b_info->video_memkb = LIBXL_MEMKB_DEFAULT; + b_info->device_model_stubdomain = false; b_info->device_model = NULL; switch (b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: - b_info->video_memkb = 8 * 1024; b_info->u.hvm.firmware = NULL; b_info->u.hvm.bios = 0; b_info->u.hvm.pae = 1; @@ -133,8 +134,17 @@ int libxl__domain_build_info_setdefault( libxl_cpumap_set_any(&b_info->cpumap); } + if (b_info->max_memkb == LIBXL_MEMKB_DEFAULT) + b_info->max_memkb = 32 * 1024; + if (b_info->target_memkb == LIBXL_MEMKB_DEFAULT) + b_info->target_memkb = b_info->max_memkb; + switch (b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: + if (b_info->shadow_memkb == LIBXL_MEMKB_DEFAULT) + b_info->shadow_memkb = 0; + if (b_info->video_memkb == LIBXL_MEMKB_DEFAULT) + b_info->video_memkb = 8 * 1024; if (b_info->u.hvm.timer_mode == LIBXL_TIMER_MODE_DEFAULT) b_info->u.hvm.timer_mode LIBXL_TIMER_MODE_NO_DELAY_FOR_MISSED_TICKS; @@ -153,6 +163,10 @@ int libxl__domain_build_info_setdefault( break; case LIBXL_DOMAIN_TYPE_PV: + if (b_info->shadow_memkb == LIBXL_MEMKB_DEFAULT) + b_info->shadow_memkb = 0; + if (b_info->u.pv.slack_memkb == LIBXL_MEMKB_DEFAULT) + b_info->u.pv.slack_memkb = 0; break; default: LIBXL__LOG(CTX, LIBXL__LOG_ERROR, diff -r 096829acb369 -r 95e87306617e tools/libxl/libxl_dom.c --- a/tools/libxl/libxl_dom.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_dom.c Wed Feb 29 16:30:35 2012 +0000 @@ -129,11 +129,12 @@ int libxl__build_post(libxl__gc *gc, uin ents = libxl__calloc(gc, 12 + (info->max_vcpus * 2) + 2, sizeof(char *)); ents[0] = "memory/static-max"; - ents[1] = libxl__sprintf(gc, "%d", info->max_memkb); + ents[1] = libxl__sprintf(gc, "%"PRId64, info->max_memkb); ents[2] = "memory/target"; - ents[3] = libxl__sprintf(gc, "%d", info->target_memkb - info->video_memkb); + ents[3] = libxl__sprintf(gc, "%"PRId64, + info->target_memkb - info->video_memkb); ents[4] = "memory/videoram"; - ents[5] = libxl__sprintf(gc, "%d", info->video_memkb); + ents[5] = libxl__sprintf(gc, "%"PRId64, info->video_memkb); ents[6] = "domid"; ents[7] = libxl__sprintf(gc, "%d", domid); ents[8] = "store/port"; diff -r 096829acb369 -r 95e87306617e tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_types.idl Wed Feb 29 16:30:35 2012 +0000 @@ -18,6 +18,12 @@ libxl_file_reference = Builtin("file_ref libxl_hwcap = Builtin("hwcap", passby=PASS_BY_REFERENCE) # +# Specific integer types +# + +MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT") + +# # Constants / Enumerations # @@ -170,9 +176,9 @@ libxl_dominfo = Struct("dominfo",[ # Otherwise set to a value guaranteed not to clash with any valid # LIBXL_SHUTDOWN_REASON_* constant. ("shutdown_reason", libxl_shutdown_reason), - ("current_memkb", uint64), - ("shared_memkb", uint64), - ("max_memkb", uint64), + ("current_memkb", MemKB), + ("shared_memkb", MemKB), + ("max_memkb", MemKB), ("cpu_time", uint64), ("vcpu_max_id", uint32), ("vcpu_online", uint32), @@ -228,10 +234,10 @@ libxl_domain_build_info = Struct("domain ("cur_vcpus", integer), ("cpumap", libxl_cpumap), ("tsc_mode", libxl_tsc_mode), - ("max_memkb", uint32), - ("target_memkb", uint32), - ("video_memkb", uint32), - ("shadow_memkb", uint32), + ("max_memkb", MemKB), + ("target_memkb", MemKB), + ("video_memkb", MemKB), + ("shadow_memkb", MemKB), ("disable_migrate", bool), ("cpuid", libxl_cpuid_policy_list), ("type", libxl_domain_type), @@ -286,7 +292,7 @@ libxl_domain_build_info = Struct("domain ("xen_platform_pci", bool), ])), ("pv", Struct(None, [("kernel", libxl_file_reference), - ("slack_memkb", uint32), + ("slack_memkb", MemKB), ("bootloader", string), ("bootloader_args", libxl_string_list), ("cmdline", string), diff -r 096829acb369 -r 95e87306617e tools/libxl/xl_sxp.c --- a/tools/libxl/xl_sxp.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/xl_sxp.c Wed Feb 29 16:30:35 2012 +0000 @@ -21,6 +21,7 @@ #include "libxl_osdeps.h" #include <stdlib.h> +#include <inttypes.h> #include "libxl.h" #include "libxl_utils.h" @@ -68,8 +69,8 @@ void printf_info_sexp(int domid, libxl_d printf("\t(build_info)\n"); printf("\t(max_vcpus %d)\n", b_info->max_vcpus); printf("\t(tsc_mode %s)\n", libxl_tsc_mode_to_string(b_info->tsc_mode)); - printf("\t(max_memkb %d)\n", b_info->max_memkb); - printf("\t(target_memkb %d)\n", b_info->target_memkb); + printf("\t(max_memkb %"PRId64")\n", b_info->max_memkb); + printf("\t(target_memkb %"PRId64")\n", b_info->target_memkb); printf("\t(nomigrate %d)\n", b_info->disable_migrate); if (c_info->type == LIBXL_DOMAIN_TYPE_PV && b_info->u.pv.bootloader) { @@ -88,8 +89,8 @@ void printf_info_sexp(int domid, libxl_d case LIBXL_DOMAIN_TYPE_HVM: printf("\t\t(hvm\n"); printf("\t\t\t(firmware %s)\n", b_info->u.hvm.firmware); - printf("\t\t\t(video_memkb %d)\n", b_info->video_memkb); - printf("\t\t\t(shadow_memkb %d)\n", b_info->shadow_memkb); + printf("\t\t\t(video_memkb %"PRId64")\n", b_info->video_memkb); + printf("\t\t\t(shadow_memkb %"PRId64")\n", b_info->shadow_memkb); printf("\t\t\t(pae %d)\n", b_info->u.hvm.pae); printf("\t\t\t(apic %d)\n", b_info->u.hvm.apic); printf("\t\t\t(acpi %d)\n", b_info->u.hvm.acpi);
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533036 0 # Node ID 56f3abb2a946c1487bc48771fd50eb0e4da224c0 # Parent 95e87306617eb179741b03f31bb16c2245789322 libxl: disk: use _init/_setdefault Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 95e87306617e -r 56f3abb2a946 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.c Wed Feb 29 16:30:36 2012 +0000 @@ -1186,10 +1186,19 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, /******************************************************************************/ -int libxl_device_disk_init(libxl_ctx *ctx, libxl_device_disk *disk) +void libxl_device_disk_init(libxl_device_disk *disk) { memset(disk, 0x00, sizeof(libxl_device_disk)); - return 0; +} + +int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk) +{ + int rc; + + rc = libxl__device_disk_set_backend(gc, disk); + if (rc) return rc; + + return rc; } static int libxl__device_from_disk(libxl__gc *gc, uint32_t domid, @@ -1241,10 +1250,7 @@ int libxl_device_disk_add(libxl_ctx *ctx libxl__device device; int major, minor, rc; - rc = libxl__device_disk_set_backend(gc, disk); - if (rc) goto out; - - rc = libxl__device_disk_set_backend(gc, disk); + rc = libxl__device_disk_setdefault(gc, disk); if (rc) goto out; front = flexarray_make(16, 1); @@ -1396,7 +1402,7 @@ static void libxl__device_disk_from_xs_b unsigned int len; char *tmp; - libxl_device_disk_init(ctx, disk); + libxl_device_disk_init(disk); tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, "%s/params", be_path), &len); @@ -1440,7 +1446,7 @@ int libxl_devid_to_device_disk(libxl_ctx char *dompath, *path; int rc = ERROR_FAIL; - libxl_device_disk_init(ctx, disk); + libxl_device_disk_init(disk); dompath = libxl__xs_get_dompath(gc, domid); if (!dompath) { @@ -1604,7 +1610,7 @@ char * libxl_device_disk_local_attach(li char *ret = NULL; int rc; - rc = libxl__device_disk_set_backend(gc, disk); + rc = libxl__device_disk_setdefault(gc, disk); if (rc) goto out; switch (disk->backend) { diff -r 95e87306617e -r 56f3abb2a946 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:36 2012 +0000 @@ -498,7 +498,7 @@ void libxl_vminfo_list_free(libxl_vminfo */ /* Disks */ -int libxl_device_disk_init(libxl_ctx *ctx, libxl_device_disk *disk); +void libxl_device_disk_init(libxl_device_disk *disk); int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk); int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, diff -r 95e87306617e -r 56f3abb2a946 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:30:36 2012 +0000 @@ -536,7 +536,7 @@ static int do_domain_create(libxl__gc *g if (ret) goto error_out; for (i = 0; i < d_config->num_disks; i++) { - ret = libxl__device_disk_set_backend(gc, &d_config->disks[i]); + ret = libxl__device_disk_setdefault(gc, &d_config->disks[i]); if (ret) goto error_out; } diff -r 95e87306617e -r 56f3abb2a946 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/libxl_internal.h Wed Feb 29 16:30:36 2012 +0000 @@ -191,6 +191,8 @@ _hidden int libxl__domain_create_info_se libxl_domain_create_info *c_info); _hidden int libxl__domain_build_info_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info); +_hidden int libxl__device_disk_setdefault(libxl__gc *gc, + libxl_device_disk *disk); struct libxl__evgen_domain_death { uint32_t domid; diff -r 95e87306617e -r 56f3abb2a946 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:35 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:36 2012 +0000 @@ -382,7 +382,7 @@ static void parse_disk_config_multistrin { int e; - libxl_device_disk_init(ctx, disk); + libxl_device_disk_init(disk); if (!*config) { *config = xlu_cfg_init(stderr, "command line");
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533036 0 # Node ID 2d934f81d79832a490b889b063ceb26becde60ee # Parent 56f3abb2a946c1487bc48771fd50eb0e4da224c0 libxl: nic: use _init/_setdefault Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 56f3abb2a946 -r 2d934f81d798 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl.c Wed Feb 29 16:30:36 2012 +0000 @@ -1677,32 +1677,43 @@ int libxl_device_disk_local_detach(libxl } /******************************************************************************/ -int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic) +void libxl_device_nic_init(libxl_device_nic *nic) { - const uint8_t *r; - libxl_uuid uuid; - - libxl_uuid_generate(&uuid); - r = libxl_uuid_bytearray(&uuid); memset(nic, ''\0'', sizeof(*nic)); - - nic->backend_domid = 0; - nic->devid = -1; - nic->mtu = 1492; - nic->model = strdup("rtl8139"); - nic->mac[0] = 0x00; - nic->mac[1] = 0x16; - nic->mac[2] = 0x3e; - nic->mac[3] = r[0] & 0x7f; - nic->mac[4] = r[1]; - nic->mac[5] = r[2]; - nic->ifname = NULL; - nic->bridge = strdup("xenbr0"); - nic->ip = NULL; - if ( asprintf(&nic->script, "%s/vif-bridge", - libxl_xen_script_dir_path()) < 0 ) +} + +int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic) +{ + if (!nic->mtu) + nic->mtu = 1492; + if (!nic->model) { + nic->model = strdup("rtl8139"); + if (!nic->model) return ERROR_NOMEM; + } + if (!nic->mac[0] && !nic->mac[1] && !nic->mac[2] && + !nic->mac[3] && !nic->mac[4] && !nic->mac[5]) { + const uint8_t *r; + libxl_uuid uuid; + + libxl_uuid_generate(&uuid); + r = libxl_uuid_bytearray(&uuid); + + nic->mac[0] = 0x00; + nic->mac[1] = 0x16; + nic->mac[2] = 0x3e; + nic->mac[3] = r[0] & 0x7f; + nic->mac[4] = r[1]; + nic->mac[5] = r[2]; + } + if (!nic->bridge) { + nic->bridge = strdup("xenbr0"); + if (!nic->bridge) return ERROR_NOMEM; + } + if ( !nic->script && asprintf(&nic->script, "%s/vif-bridge", + libxl_xen_script_dir_path()) < 0 ) return ERROR_FAIL; - nic->nictype = LIBXL_NIC_TYPE_IOEMU; + if (!nic->nictype) + nic->nictype = LIBXL_NIC_TYPE_IOEMU; return 0; } @@ -1729,6 +1740,9 @@ int libxl_device_nic_add(libxl_ctx *ctx, char *dompath, **l; unsigned int nb, rc; + rc = libxl__device_nic_setdefault(gc, nic); + if (rc) goto out; + front = flexarray_make(16, 1); if (!front) { rc = ERROR_NOMEM; diff -r 56f3abb2a946 -r 2d934f81d798 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:36 2012 +0000 @@ -524,7 +524,7 @@ char * libxl_device_disk_local_attach(li int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk); /* Network Interfaces */ -int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic); +void libxl_device_nic_init(libxl_device_nic *nic); int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic); int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic, diff -r 56f3abb2a946 -r 2d934f81d798 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_internal.h Wed Feb 29 16:30:36 2012 +0000 @@ -193,6 +193,7 @@ _hidden int libxl__domain_build_info_set libxl_domain_build_info *b_info); _hidden int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk); +_hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic); struct libxl__evgen_domain_death { uint32_t domid; diff -r 56f3abb2a946 -r 2d934f81d798 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:36 2012 +0000 @@ -844,7 +844,7 @@ static void parse_config_data(const char d_config->vifs = (libxl_device_nic *) realloc(d_config->vifs, sizeof (libxl_device_nic) * (d_config->num_vifs+1)); nic = d_config->vifs + d_config->num_vifs; - CHK_ERRNO( libxl_device_nic_init(ctx, nic) ); + libxl_device_nic_init(nic); nic->devid = d_config->num_vifs; if (default_vifscript) { @@ -4614,7 +4614,7 @@ int main_networkattach(int argc, char ** fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]); return 1; } - libxl_device_nic_init(ctx, &nic); + libxl_device_nic_init(&nic); for (argv += optind+1, argc -= optind+1; argc > 0; ++argv, --argc) { if (MATCH_OPTION("type", *argv, oparg)) { if (!strcmp("vif", oparg)) {
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 13 of 27 V4] libxl: vfb/vkb: use _init/_setdefault
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533036 0 # Node ID 4ff5c9212400df0c271873ce30adabb4c26a80fa # Parent 2d934f81d79832a490b889b063ceb26becde60ee libxl: vfb/vkb: use _init/_setdefault Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 2d934f81d798 -r 4ff5c9212400 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl.c Wed Feb 29 16:30:36 2012 +0000 @@ -2101,9 +2101,13 @@ out: } /******************************************************************************/ -int libxl_device_vkb_init(libxl_ctx *ctx, libxl_device_vkb *vkb) +void libxl_device_vkb_init(libxl_device_vkb *vkb) { memset(vkb, 0x00, sizeof(libxl_device_vkb)); +} + +int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb) +{ return 0; } @@ -2129,6 +2133,9 @@ int libxl_device_vkb_add(libxl_ctx *ctx, libxl__device device; int rc; + rc = libxl__device_vkb_setdefault(gc, vkb); + if (rc) goto out; + front = flexarray_make(16, 1); if (!front) { rc = ERROR_NOMEM; @@ -2206,12 +2213,11 @@ out: } /******************************************************************************/ -int libxl_device_vfb_init(libxl_ctx *ctx, libxl_device_vfb *vfb) +void libxl_device_vfb_init(libxl_device_vfb *vfb) { memset(vfb, 0x00, sizeof(libxl_device_vfb)); vfb->vnc.enable = 1; vfb->vnc.passwd = NULL; - vfb->vnc.listen = strdup("127.0.0.1"); vfb->vnc.display = 0; vfb->vnc.findunused = 1; vfb->keymap = NULL; @@ -2219,6 +2225,15 @@ int libxl_device_vfb_init(libxl_ctx *ctx vfb->sdl.opengl = 0; vfb->sdl.display = NULL; vfb->sdl.xauthority = NULL; +} + +int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb) +{ + if (!vfb->vnc.listen) { + vfb->vnc.listen = strdup("127.0.0.1"); + if (!vfb->vnc.listen) return ERROR_NOMEM; + } + return 0; } @@ -2243,6 +2258,9 @@ int libxl_device_vfb_add(libxl_ctx *ctx, libxl__device device; int rc; + rc = libxl__device_vfb_setdefault(gc, vfb); + if (rc) goto out; + front = flexarray_make(16, 1); if (!front) { rc = ERROR_NOMEM; diff -r 2d934f81d798 -r 4ff5c9212400 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:36 2012 +0000 @@ -536,7 +536,7 @@ int libxl_device_nic_getinfo(libxl_ctx * libxl_device_nic *nic, libxl_nicinfo *nicinfo); /* Keyboard */ -int libxl_device_vkb_init(libxl_ctx *ctx, libxl_device_vkb *vkb); +void libxl_device_vkb_init(libxl_device_vkb *vkb); int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb); int libxl_device_vkb_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb, @@ -544,7 +544,7 @@ int libxl_device_vkb_remove(libxl_ctx *c int libxl_device_vkb_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb); /* Framebuffer */ -int libxl_device_vfb_init(libxl_ctx *ctx, libxl_device_vfb *vfb); +void libxl_device_vfb_init(libxl_device_vfb *vfb); int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb); int libxl_device_vfb_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb, diff -r 2d934f81d798 -r 4ff5c9212400 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:30:36 2012 +0000 @@ -595,9 +595,7 @@ static int do_domain_create(libxl__gc *g libxl__device_console_add(gc, domid, &console, &state); libxl_device_console_dispose(&console); - ret = libxl_device_vkb_init(ctx, &vkb); - if ( ret ) - goto error_out; + libxl_device_vkb_init(&vkb); libxl_device_vkb_add(ctx, domid, &vkb); libxl_device_vkb_dispose(&vkb); diff -r 2d934f81d798 -r 4ff5c9212400 tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_dm.c Wed Feb 29 16:30:36 2012 +0000 @@ -616,8 +616,8 @@ static int libxl__vfb_and_vkb_from_hvm_g if (b_info->type != LIBXL_DOMAIN_TYPE_HVM) return ERROR_INVAL; - memset(vfb, 0x00, sizeof(libxl_device_vfb)); - memset(vkb, 0x00, sizeof(libxl_device_vkb)); + libxl_device_vfb_init(vfb); + libxl_device_vkb_init(vkb); vfb->backend_domid = 0; vfb->devid = 0; diff -r 2d934f81d798 -r 4ff5c9212400 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_internal.h Wed Feb 29 16:30:36 2012 +0000 @@ -194,6 +194,8 @@ _hidden int libxl__domain_build_info_set _hidden int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk); _hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic); +_hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb); +_hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb); struct libxl__evgen_domain_death { uint32_t domid; diff -r 2d934f81d798 -r 4ff5c9212400 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:36 2012 +0000 @@ -940,12 +940,12 @@ skip: d_config->vfbs = (libxl_device_vfb *) realloc(d_config->vfbs, sizeof(libxl_device_vfb) * (d_config->num_vfbs + 1)); vfb = d_config->vfbs + d_config->num_vfbs; - libxl_device_vfb_init(ctx, vfb); + libxl_device_vfb_init(vfb); vfb->devid = d_config->num_vfbs; d_config->vkbs = (libxl_device_vkb *) realloc(d_config->vkbs, sizeof(libxl_device_vkb) * (d_config->num_vkbs + 1)); vkb = d_config->vkbs + d_config->num_vkbs; - libxl_device_vkb_init(ctx, vkb); + libxl_device_vkb_init(vkb); vkb->devid = d_config->num_vkbs; p = strtok(buf2, ",");
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 14 of 27 V4] libxl: make libxl_device_console internal
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533036 0 # Node ID 5a3e6c301be716a994f54195857a7dd9cff56296 # Parent 4ff5c9212400df0c271873ce30adabb4c26a80fa libxl: make libxl_device_console internal consoles are not directly exposed to users of the library and there are no API functions for manipluating them (only the console_exec function). Rather than commit to a particular API now make the type internal. When a user does come along it is much easier to add a completely new API rather than to fix an existing broken one. It''s easier to do this in a manner which users of the library can cope with in a compatible way e.g. adding a new API is easier to check for with ./configure. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r 4ff5c9212400 -r 5a3e6c301be7 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl.c Wed Feb 29 16:30:36 2012 +0000 @@ -2023,7 +2023,7 @@ int libxl_device_nic_getinfo(libxl_ctx * /******************************************************************************/ int libxl__device_console_add(libxl__gc *gc, uint32_t domid, - libxl_device_console *console, + libxl__device_console *console, libxl__domain_build_state *state) { flexarray_t *front; @@ -2070,7 +2070,7 @@ int libxl__device_console_add(libxl__gc flexarray_append(front, "limit"); flexarray_append(front, libxl__sprintf(gc, "%d", LIBXL_XENCONSOLE_LIMIT)); flexarray_append(front, "type"); - if (console->consback == LIBXL_CONSOLE_BACKEND_XENCONSOLED) + if (console->consback == LIBXL__CONSOLE_BACKEND_XENCONSOLED) flexarray_append(front, "xenconsoled"); else flexarray_append(front, "ioemu"); diff -r 4ff5c9212400 -r 5a3e6c301be7 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:30:36 2012 +0000 @@ -177,17 +177,16 @@ int libxl__domain_build_info_setdefault( return 0; } -static int init_console_info(libxl_device_console *console, int dev_num) +static int init_console_info(libxl__device_console *console, int dev_num) { - memset(console, 0x00, sizeof(libxl_device_console)); + memset(console, 0x00, sizeof(libxl__device_console)); console->devid = dev_num; - console->consback = LIBXL_CONSOLE_BACKEND_XENCONSOLED; + console->consback = LIBXL__CONSOLE_BACKEND_XENCONSOLED; console->output = strdup("pty"); - if ( NULL == console->output ) + if (!console->output) return ERROR_NOMEM; return 0; } - int libxl__domain_build(libxl__gc *gc, libxl_domain_build_info *info, uint32_t domid, @@ -586,14 +585,14 @@ static int do_domain_create(libxl__gc *g switch (d_config->c_info.type) { case LIBXL_DOMAIN_TYPE_HVM: { - libxl_device_console console; + libxl__device_console console; libxl_device_vkb vkb; ret = init_console_info(&console, 0); if ( ret ) goto error_out; libxl__device_console_add(gc, domid, &console, &state); - libxl_device_console_dispose(&console); + libxl__device_console_dispose(&console); libxl_device_vkb_init(&vkb); libxl_device_vkb_add(ctx, domid, &vkb); @@ -611,7 +610,7 @@ static int do_domain_create(libxl__gc *g case LIBXL_DOMAIN_TYPE_PV: { int need_qemu = 0; - libxl_device_console console; + libxl__device_console console; for (i = 0; i < d_config->num_vfbs; i++) { libxl_device_vfb_add(ctx, domid, &d_config->vfbs[i]); @@ -627,10 +626,10 @@ static int do_domain_create(libxl__gc *g d_config->num_disks, &d_config->disks[0]); if (need_qemu) - console.consback = LIBXL_CONSOLE_BACKEND_IOEMU; + console.consback = LIBXL__CONSOLE_BACKEND_IOEMU; libxl__device_console_add(gc, domid, &console, &state); - libxl_device_console_dispose(&console); + libxl__device_console_dispose(&console); if (need_qemu) { libxl__create_xenpv_qemu(gc, domid, d_config, &state, &dm_starting); diff -r 4ff5c9212400 -r 5a3e6c301be7 tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_dm.c Wed Feb 29 16:30:36 2012 +0000 @@ -688,7 +688,7 @@ static int libxl__create_stubdom(libxl__ { libxl_ctx *ctx = libxl__gc_owner(gc); int i, num_console = STUBDOM_SPECIAL_CONSOLES, ret; - libxl_device_console *console; + libxl__device_console *console; libxl_domain_config dm_config; libxl_device_vfb vfb; libxl_device_vkb vkb; @@ -820,7 +820,7 @@ retry_transaction: if (guest_config->b_info.u.hvm.serial) num_console++; - console = libxl__calloc(gc, num_console, sizeof(libxl_device_console)); + console = libxl__calloc(gc, num_console, sizeof(libxl__device_console)); if (!console) { ret = ERROR_NOMEM; goto out_free; @@ -828,7 +828,7 @@ retry_transaction: for (i = 0; i < num_console; i++) { console[i].devid = i; - console[i].consback = LIBXL_CONSOLE_BACKEND_IOEMU; + console[i].consback = LIBXL__CONSOLE_BACKEND_IOEMU; /* STUBDOM_CONSOLE_LOGGING (console 0) is for minios logging * STUBDOM_CONSOLE_SAVE (console 1) is for writing the save file * STUBDOM_CONSOLE_RESTORE (console 2) is for reading the save file @@ -1092,7 +1092,7 @@ out: } int libxl__need_xenpv_qemu(libxl__gc *gc, - int nr_consoles, libxl_device_console *consoles, + int nr_consoles, libxl__device_console *consoles, int nr_vfbs, libxl_device_vfb *vfbs, int nr_disks, libxl_device_disk *disks) { @@ -1104,7 +1104,7 @@ int libxl__need_xenpv_qemu(libxl__gc *gc } for (i = 0; i < nr_consoles; i++) { - if (consoles[i].consback == LIBXL_CONSOLE_BACKEND_IOEMU) { + if (consoles[i].consback == LIBXL__CONSOLE_BACKEND_IOEMU) { ret = 1; goto out; } diff -r 4ff5c9212400 -r 5a3e6c301be7 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_internal.h Wed Feb 29 16:30:36 2012 +0000 @@ -661,7 +661,7 @@ _hidden int libxl__device_disk_dev_numbe int *pdisk, int *ppartition); _hidden int libxl__device_console_add(libxl__gc *gc, uint32_t domid, - libxl_device_console *console, + libxl__device_console *console, libxl__domain_build_state *state); _hidden int libxl__device_generic_add(libxl__gc *gc, libxl__device *device, @@ -904,7 +904,7 @@ _hidden int libxl__create_xenpv_qemu(lib libxl__domain_build_state *state, libxl__spawner_starting **starting_r); _hidden int libxl__need_xenpv_qemu(libxl__gc *gc, - int nr_consoles, libxl_device_console *consoles, + int nr_consoles, libxl__device_console *consoles, int nr_vfbs, libxl_device_vfb *vfbs, int nr_disks, libxl_device_disk *disks); /* Caller must either: pass starting_r==0, or on successful diff -r 4ff5c9212400 -r 5a3e6c301be7 tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_types.idl Wed Feb 29 16:30:36 2012 +0000 @@ -42,11 +42,6 @@ libxl_console_type = Enumeration("consol (2, "PV"), ]) -libxl_console_backend = Enumeration("console_backend", [ - (1, "XENCONSOLED"), - (2, "IOEMU"), - ]) - libxl_disk_format = Enumeration("disk_format", [ (0, "UNKNOWN"), (1, "QCOW"), @@ -319,13 +314,6 @@ libxl_device_vkb = Struct("device_vkb", ("devid", integer), ]) -libxl_device_console = Struct("device_console", [ - ("backend_domid", libxl_domid), - ("devid", integer), - ("consback", libxl_console_backend), - ("output", string), - ]) - libxl_device_disk = Struct("device_disk", [ ("backend_domid", libxl_domid), ("pdev_path", string), diff -r 4ff5c9212400 -r 5a3e6c301be7 tools/libxl/libxl_types_internal.idl --- a/tools/libxl/libxl_types_internal.idl Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_types_internal.idl Wed Feb 29 16:30:36 2012 +0000 @@ -1,5 +1,7 @@ namespace("libxl__") +libxl_domid = Builtin("domid", namespace="libxl_", json_fn = "yajl_gen_integer") + libxl__qmp_message_type = Enumeration("qmp_message_type", [ (1, "QMP"), (2, "return"), @@ -17,3 +19,15 @@ libxl__device_kind = Enumeration("device (6, "VKBD"), (7, "CONSOLE"), ]) + +libxl__console_backend = Enumeration("console_backend", [ + (1, "XENCONSOLED"), + (2, "IOEMU"), + ]) + +libxl__device_console = Struct("device_console", [ + ("backend_domid", libxl_domid), + ("devid", integer), + ("consback", libxl__console_backend), + ("output", string), + ])
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533036 0 # Node ID 0b79a94f4cab781fea6692414a8d7f8734309bfc # Parent 5a3e6c301be716a994f54195857a7dd9cff56296 libxl: pci: use _init/_setdefault Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 5a3e6c301be7 -r 0b79a94f4cab tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:36 2012 +0000 @@ -552,7 +552,7 @@ int libxl_device_vfb_remove(libxl_ctx *c int libxl_device_vfb_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb); /* PCI Passthrough */ -int libxl_device_pci_init(libxl_ctx *ctx, libxl_device_pci *pci); +void libxl_device_pci_init(libxl_device_pci *pci); int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev); int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev); int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev); diff -r 5a3e6c301be7 -r 0b79a94f4cab tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_internal.h Wed Feb 29 16:30:36 2012 +0000 @@ -196,6 +196,7 @@ _hidden int libxl__device_disk_setdefaul _hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic); _hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb); _hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb); +_hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci); struct libxl__evgen_domain_death { uint32_t domid; diff -r 5a3e6c301be7 -r 0b79a94f4cab tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_pci.c Wed Feb 29 16:30:36 2012 +0000 @@ -765,6 +765,16 @@ static int libxl__device_pci_reset(libxl return -1; } +void libxl_device_pci_init(libxl_device_pci *pci) +{ + memset(pci, ''\0'', sizeof(*pci)); +} + +int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci) +{ + return 0; +} + int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev) { GC_INIT(ctx); @@ -782,6 +792,9 @@ int libxl__device_pci_add(libxl__gc *gc, int num_assigned, i, rc; int stubdomid = 0; + rc = libxl__device_pci_setdefault(gc, pcidev); + if (rc) goto out; + rc = get_all_assigned_devices(gc, &assigned, &num_assigned); if ( rc ) { LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot determine if device is assigned, refusing to continue"); diff -r 5a3e6c301be7 -r 0b79a94f4cab tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:36 2012 +0000 @@ -1021,7 +1021,7 @@ skip_vfb: d_config->pcidevs = (libxl_device_pci *) realloc(d_config->pcidevs, sizeof (libxl_device_pci) * (d_config->num_pcidevs + 1)); pcidev = d_config->pcidevs + d_config->num_pcidevs; - memset(pcidev, 0x00, sizeof(libxl_device_pci)); + libxl_device_pci_init(pcidev); pcidev->msitranslate = pci_msitranslate; pcidev->power_mgmt = pci_power_mgmt;
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 16 of 27 V4] libxl: add new "defbool" built in type
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533036 0 # Node ID 023e6c3f206511f46ef9582aa245b92bf27ed390 # Parent 0b79a94f4cab781fea6692414a8d7f8734309bfc libxl: add new "defbool" built in type. This type is a but like a "boolean" but with a third state "default" (so really I suppose it''s a tristate). Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r 0b79a94f4cab -r 023e6c3f2065 tools/libxl/gentest.py --- a/tools/libxl/gentest.py Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/gentest.py Wed Feb 29 16:30:36 2012 +0000 @@ -20,7 +20,8 @@ def randomize_case(s): def randomize_enum(e): return random.choice([v.name for v in e.values]) -handcoded = ["libxl_cpumap", "libxl_key_value_list", +handcoded = ["libxl_defbool", # Temp until a user appears in the next patch + "libxl_cpumap", "libxl_key_value_list", "libxl_cpuid_policy_list", "libxl_file_reference", "libxl_string_list"] @@ -55,6 +56,8 @@ def gen_rand_init(ty, v, indent = " " ty.pass_arg(v, parent is None)) elif ty.typename in ["bool"]: s += "%s = rand() %% 2;\n" % v + elif ty.typename in ["libxl_defbool"]: + s += "libxl_defbool_set(%s, !!rand() %% 1);\n" % v elif ty.typename in ["char *"]: s += "%s = rand_str();\n" % v elif ty.private: diff -r 0b79a94f4cab -r 023e6c3f2065 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl.c Wed Feb 29 16:30:36 2012 +0000 @@ -184,6 +184,47 @@ void libxl_key_value_list_dispose(libxl_ free(kvl); } +#define LIBXL__DEFBOOL_DEFAULT (0) +#define LIBXL__DEFBOOL_FALSE (-1) +#define LIBXL__DEFBOOL_TRUE (1) + +void libxl_defbool_set(libxl_defbool *db, bool b) +{ + db->val = b ? LIBXL__DEFBOOL_TRUE : LIBXL__DEFBOOL_FALSE; +} + +void libxl_defbool_unset(libxl_defbool *db) +{ + db->val = LIBXL__DEFBOOL_DEFAULT; +} + +bool libxl_defbool_is_default(libxl_defbool db) +{ + return !db.val; +} + +void libxl_defbool_setdefault(libxl_defbool *db, bool b) +{ + if (libxl_defbool_is_default(*db)) + libxl_defbool_set(db, b); +} + +bool libxl_defbool_val(libxl_defbool db) +{ + assert(!libxl_defbool_is_default(db)); + return db.val > 0; +} + +const char *libxl_defbool_to_string(libxl_defbool b) +{ + if (b.val < 0) + return "False"; + else if (b.val > 0) + return "True"; + else + return "<default>"; +} + /******************************************************************************/ diff -r 0b79a94f4cab -r 023e6c3f2065 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl.h Wed Feb 29 16:30:36 2012 +0000 @@ -243,6 +243,30 @@ typedef struct { struct libxl_event; typedef LIBXL_TAILQ_ENTRY(struct libxl_event) libxl_ev_link; +/* + * A boolean variable with an explicit default state. + * + * Users should treat this struct as opaque and use the following + * defined macros and accessor functions. + * + * To allow users of the library to naively select all defaults this + * state is represented as 0. False is < 0 and True is > 0. + */ +typedef struct { + int val; +} libxl_defbool; + +void libxl_defbool_set(libxl_defbool *db, bool b); +/* Resets to default */ +void libxl_defbool_unset(libxl_defbool *db); +/* Sets db only if it is currently == default */ +void libxl_defbool_setdefault(libxl_defbool *db, bool b); +bool libxl_defbool_is_default(libxl_defbool db); +/* db must not be == default */ +bool libxl_defbool_val(libxl_defbool db); + +const char *libxl_defbool_to_string(libxl_defbool b); + typedef struct libxl__ctx libxl_ctx; #define LIBXL_TIMER_MODE_DEFAULT -1 diff -r 0b79a94f4cab -r 023e6c3f2065 tools/libxl/libxl_json.c --- a/tools/libxl/libxl_json.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_json.c Wed Feb 29 16:30:36 2012 +0000 @@ -85,6 +85,12 @@ yajl_gen_status libxl__yajl_gen_enum(yaj /* * YAJL generators for builtin libxl types. */ +yajl_gen_status libxl_defbool_gen_json(yajl_gen hand, + libxl_defbool *db) +{ + return libxl__yajl_gen_asciiz(hand, libxl_defbool_to_string(*db)); +} + yajl_gen_status libxl_uuid_gen_json(yajl_gen hand, libxl_uuid *uuid) { diff -r 0b79a94f4cab -r 023e6c3f2065 tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_types.idl Wed Feb 29 16:30:36 2012 +0000 @@ -5,6 +5,8 @@ namespace("libxl_") +libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE) + libxl_domid = Builtin("domid", json_fn = "yajl_gen_integer", autogenerate_json = False) libxl_uuid = Builtin("uuid", passby=PASS_BY_REFERENCE) libxl_mac = Builtin("mac", passby=PASS_BY_REFERENCE) diff -r 0b79a94f4cab -r 023e6c3f2065 tools/libxl/libxlu_cfg.c --- a/tools/libxl/libxlu_cfg.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxlu_cfg.c Wed Feb 29 16:30:36 2012 +0000 @@ -237,6 +237,17 @@ int xlu_cfg_get_long(const XLU_Config *c return 0; } +int xlu_cfg_get_defbool(const XLU_Config *cfg, const char *n, libxl_defbool *b, + int dont_warn) +{ + int ret; + long l; + + ret = xlu_cfg_get_long(cfg, n, &l, dont_warn); + if (ret) return ret; + libxl_defbool_set(b, !!l); + return 0; +} int xlu_cfg_get_list(const XLU_Config *cfg, const char *n, XLU_ConfigList **list_r, int *entries_r, int dont_warn) { diff -r 0b79a94f4cab -r 023e6c3f2065 tools/libxl/libxlutil.h --- a/tools/libxl/libxlutil.h Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxlutil.h Wed Feb 29 16:30:36 2012 +0000 @@ -52,6 +52,8 @@ int xlu_cfg_replace_string(const XLU_Con char **value_r, int dont_warn); int xlu_cfg_get_long(const XLU_Config*, const char *n, long *value_r, int dont_warn); +int xlu_cfg_get_defbool(const XLU_Config*, const char *n, libxl_defbool *b, + int dont_warn); int xlu_cfg_get_list(const XLU_Config*, const char *n, XLU_ConfigList **list_r /* may be 0 */, diff -r 0b79a94f4cab -r 023e6c3f2065 tools/ocaml/libs/xl/genwrap.py --- a/tools/ocaml/libs/xl/genwrap.py Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/ocaml/libs/xl/genwrap.py Wed Feb 29 16:30:36 2012 +0000 @@ -10,6 +10,7 @@ builtins = { "int": ("int", "%(c)s = Int_val(%(o)s)", "Val_int(%(c)s)" ), "char *": ("string", "%(c)s = dup_String_val(gc, %(o)s)", "caml_copy_string(%(c)s)"), "libxl_domid": ("domid", "%(c)s = Int_val(%(o)s)", "Val_int(%(c)s)" ), + "libxl_defbool": ("bool option", "%(c)s = Defbool_val(%(o)s)", "Val_defbool(%(c)s)" ), "libxl_uuid": ("int array", "Uuid_val(gc, lg, &%(c)s, %(o)s)", "Val_uuid(&%(c)s)"), "libxl_key_value_list": ("(string * string) list", None, None), "libxl_mac": ("int array", "Mac_val(gc, lg, &%(c)s, %(o)s)", "Val_mac(&%(c)s)"), diff -r 0b79a94f4cab -r 023e6c3f2065 tools/ocaml/libs/xl/xenlight_stubs.c --- a/tools/ocaml/libs/xl/xenlight_stubs.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/ocaml/libs/xl/xenlight_stubs.c Wed Feb 29 16:30:36 2012 +0000 @@ -195,6 +195,33 @@ static int Uuid_val(caml_gc *gc, struct CAMLreturn(0); } +static value Val_defbool(libxl_defbool c_val) +{ + CAMLparam0(); + CAMLlocal1(v); + + if (libxl_defbool_is_default(c_val)) + v = Val_none; + else { + bool b = libxl_defbool_val(c_val); + v = Val_some(b ? Val_bool(true) : Val_bool(false)); + } + CAMLreturn(v); +} + +static libxl_defbool Defbool_val(value v) +{ + CAMLparam1(v); + libxl_defbool db; + if (v == Val_none) + libxl_defbool_unset(&db); + else { + bool b = Bool_val(Some_val(v)); + libxl_defbool_set(&db, b); + } + return db; +} + static value Val_hwcap(libxl_hwcap *c_val) { CAMLparam0(); diff -r 0b79a94f4cab -r 023e6c3f2065 tools/python/genwrap.py --- a/tools/python/genwrap.py Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/python/genwrap.py Wed Feb 29 16:30:36 2012 +0000 @@ -4,11 +4,13 @@ import sys,os import idl -(TYPE_BOOL, TYPE_INT, TYPE_UINT, TYPE_STRING, TYPE_AGGREGATE) = range(5) +(TYPE_DEFBOOL, TYPE_BOOL, TYPE_INT, TYPE_UINT, TYPE_STRING, TYPE_AGGREGATE) = range(6) def py_type(ty): if ty == idl.bool: return TYPE_BOOL + if ty.typename == "libxl_defbool": + return TYPE_DEFBOOL if isinstance(ty, idl.Enumeration): return TYPE_UINT if isinstance(ty, idl.Number): @@ -44,6 +46,8 @@ def py_decls(ty): for f in ty.fields: if py_type(f.type) is not None: continue + if py_type(f.type) == TYPE_DEFBOOL: + continue if ty.marshal_out(): l.append(''_hidden PyObject *attrib__%s_get(%s *%s);''%(\ fsanitize(f.type.typename), f.type.typename, f.name)) @@ -62,6 +66,8 @@ def py_attrib_get(ty, f): l.append('' ret = (self->obj.%s) ? Py_True : Py_False;''%f.name) l.append('' Py_INCREF(ret);'') l.append('' return ret;'') + elif t == TYPE_DEFBOOL: + l.append('' return genwrap__defbool_get(&self->obj.%s);''%f.name) elif t == TYPE_INT: l.append('' return genwrap__ll_get(self->obj.%s);''%f.name) elif t == TYPE_UINT: @@ -85,6 +91,8 @@ def py_attrib_set(ty, f): if t == TYPE_BOOL: l.append('' self->obj.%s = (NULL == v || Py_None == v || Py_False == v) ? 0 : 1;''%f.name) l.append('' return 0;'') + elif t == TYPE_DEFBOOL: + l.append('' return genwrap__defbool_set(v, &self->obj.%s);''%f.name) elif t == TYPE_UINT or t == TYPE_INT: l.append('' %slong long tmp;''%(t == TYPE_UINT and ''unsigned '' or '''')) l.append('' int ret;'') @@ -275,6 +283,8 @@ _hidden PyObject *genwrap__ull_get(unsig _hidden int genwrap__ull_set(PyObject *v, unsigned long long *val, unsigned long long mask); _hidden PyObject *genwrap__ll_get(long long val); _hidden int genwrap__ll_set(PyObject *v, long long *val, long long mask); +_hidden PyObject *genwrap__defbool_get(libxl_defbool *db); +_hidden int genwrap__defbool_set(PyObject *v, libxl_defbool *db); """ % " ".join(sys.argv)) for ty in [ty for ty in types if isinstance(ty, idl.Aggregate)]: diff -r 0b79a94f4cab -r 023e6c3f2065 tools/python/xen/lowlevel/xl/xl.c --- a/tools/python/xen/lowlevel/xl/xl.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/python/xen/lowlevel/xl/xl.c Wed Feb 29 16:30:36 2012 +0000 @@ -156,6 +156,21 @@ int genwrap__ll_set(PyObject *v, long lo return 0; } +PyObject *genwrap__defbool_get(libxl_defbool *db) +{ + PyObject *ret; + ret = libxl_defbool_val(*db) ? Py_True : Py_False; + Py_INCREF(ret); + return ret; +} + +int genwrap__defbool_set(PyObject *v, libxl_defbool *db) +{ + bool val = !(NULL == v || Py_None == v || Py_False == v); + libxl_defbool_set(db, val); + return 0; +} + static int fixed_bytearray_set(PyObject *v, uint8_t *ptr, size_t len) { char *tmp;
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 17 of 27 V4] libxl: make boolean members of libxl_domain_create_info into libxl_defbool
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533036 0 # Node ID 865634b37f7020ad943fb63e1c57ea3f666a7d52 # Parent 023e6c3f206511f46ef9582aa245b92bf27ed390 libxl: make boolean members of libxl_domain_create_info into libxl_defbool This allows them to be set via the _init/_setdefault methods. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r 023e6c3f2065 -r 865634b37f70 tools/libxl/gentest.py --- a/tools/libxl/gentest.py Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/gentest.py Wed Feb 29 16:30:36 2012 +0000 @@ -20,8 +20,7 @@ def randomize_case(s): def randomize_enum(e): return random.choice([v.name for v in e.values]) -handcoded = ["libxl_defbool", # Temp until a user appears in the next patch - "libxl_cpumap", "libxl_key_value_list", +handcoded = ["libxl_cpumap", "libxl_key_value_list", "libxl_cpuid_policy_list", "libxl_file_reference", "libxl_string_list"] diff -r 023e6c3f2065 -r 865634b37f70 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:30:36 2012 +0000 @@ -53,8 +53,6 @@ void libxl_domain_config_dispose(libxl_d void libxl_domain_create_info_init(libxl_domain_create_info *c_info) { memset(c_info, ''\0'', sizeof(*c_info)); - c_info->hap = 1; - c_info->oos = 1; } int libxl__domain_create_info_setdefault(libxl__gc *gc, @@ -63,6 +61,11 @@ int libxl__domain_create_info_setdefault if (!c_info->type) return ERROR_INVAL; + if (c_info->type == LIBXL_DOMAIN_TYPE_HVM) { + libxl_defbool_setdefault(&c_info->hap, true); + libxl_defbool_setdefault(&c_info->oos, true); + } + return 0; } @@ -366,8 +369,8 @@ int libxl__domain_make(libxl__gc *gc, li flags = 0; if (info->type == LIBXL_DOMAIN_TYPE_HVM) { flags |= XEN_DOMCTL_CDF_hvm_guest; - flags |= info->hap ? XEN_DOMCTL_CDF_hap : 0; - flags |= info->oos ? 0 : XEN_DOMCTL_CDF_oos_off; + flags |= libxl_defbool_val(info->hap) ? XEN_DOMCTL_CDF_hap : 0; + flags |= libxl_defbool_val(info->oos) ? 0 : XEN_DOMCTL_CDF_oos_off; } *domid = -1; @@ -519,6 +522,9 @@ static int do_domain_create(libxl__gc *g ret = libxl__domain_create_info_setdefault(gc, &d_config->c_info); if (ret) goto error_out; + ret = libxl__domain_create_info_setdefault(gc, &d_config->c_info); + if (ret) goto error_out; + ret = libxl__domain_make(gc, &d_config->c_info, &domid); if (ret) { LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot make domain: %d", ret); diff -r 023e6c3f2065 -r 865634b37f70 tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_types.idl Wed Feb 29 16:30:36 2012 +0000 @@ -211,8 +211,8 @@ libxl_version_info = Struct("version_inf libxl_domain_create_info = Struct("domain_create_info",[ ("type", libxl_domain_type), - ("hap", bool), - ("oos", bool), + ("hap", libxl_defbool), + ("oos", libxl_defbool), ("ssidref", uint32), ("name", string), ("uuid", libxl_uuid), diff -r 023e6c3f2065 -r 865634b37f70 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:36 2012 +0000 @@ -555,8 +555,7 @@ static void parse_config_data(const char !strncmp(buf, "hvm", strlen(buf))) c_info->type = LIBXL_DOMAIN_TYPE_HVM; - if (!xlu_cfg_get_long (config, "hap", &l, 0)) - c_info->hap = l; + xlu_cfg_get_defbool(config, "hap", &c_info->hap, 0); if (xlu_cfg_replace_string (config, "name", &c_info->name, 0)) { fprintf(stderr, "Domain name must be specified.\n"); @@ -572,8 +571,7 @@ static void parse_config_data(const char libxl_uuid_generate(&c_info->uuid); } - if (!xlu_cfg_get_long(config, "oos", &l, 0)) - c_info->oos = l; + xlu_cfg_get_defbool(config, "oos", &c_info->oos, 0); if (!xlu_cfg_get_string (config, "pool", &buf, 0)) { c_info->poolid = -1; diff -r 023e6c3f2065 -r 865634b37f70 tools/libxl/xl_sxp.c --- a/tools/libxl/xl_sxp.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/xl_sxp.c Wed Feb 29 16:30:36 2012 +0000 @@ -41,8 +41,8 @@ void printf_info_sexp(int domid, libxl_d printf("(domain\n\t(domid %d)\n", domid); printf("\t(create_info)\n"); printf("\t(hvm %d)\n", c_info->type == LIBXL_DOMAIN_TYPE_HVM); - printf("\t(hap %d)\n", c_info->hap); - printf("\t(oos %d)\n", c_info->oos); + printf("\t(hap %s)\n", libxl_defbool_to_string(c_info->hap)); + printf("\t(oos %s)\n", libxl_defbool_to_string(c_info->oos)); printf("\t(ssidref %d)\n", c_info->ssidref); printf("\t(name %s)\n", c_info->name);
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 18 of 27 V4] libxl: make boolean members of libxl_domain_build_info into libxl_defbool
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533582 0 # Node ID 6a475fa5019c3fc68f38fafbd36014d62c950c96 # Parent 865634b37f7020ad943fb63e1c57ea3f666a7d52 libxl: make boolean members of libxl_domain_build_info into libxl_defbool This allows them to be set via the _init/_setdefault methods. This just covers the obvious ones. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r 865634b37f70 -r 6a475fa5019c tools/libxl/libxl_bootloader.c --- a/tools/libxl/libxl_bootloader.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_bootloader.c Wed Feb 29 16:39:42 2012 +0000 @@ -352,6 +352,9 @@ int libxl_run_bootloader(libxl_ctx *ctx, if (info->type != LIBXL_DOMAIN_TYPE_PV || !info->u.pv.bootloader) goto out; + rc = libxl__domain_build_info_setdefault(gc, info); + if (rc) goto out; + rc = ERROR_INVAL; if (!disk) goto out; diff -r 865634b37f70 -r 6a475fa5019c tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:39:42 2012 +0000 @@ -73,7 +73,6 @@ void libxl_domain_build_info_init(libxl_ const libxl_domain_create_info *c_info) { memset(b_info, ''\0'', sizeof(*b_info)); - b_info->disable_migrate = 0; b_info->cpuid = NULL; b_info->type = c_info->type; @@ -89,17 +88,7 @@ void libxl_domain_build_info_init(libxl_ case LIBXL_DOMAIN_TYPE_HVM: b_info->u.hvm.firmware = NULL; b_info->u.hvm.bios = 0; - b_info->u.hvm.pae = 1; - b_info->u.hvm.apic = 1; - b_info->u.hvm.acpi = 1; - b_info->u.hvm.acpi_s3 = 1; - b_info->u.hvm.acpi_s4 = 1; - b_info->u.hvm.nx = 1; - b_info->u.hvm.viridian = 0; - b_info->u.hvm.hpet = 1; - b_info->u.hvm.vpt_align = 1; b_info->u.hvm.timer_mode = LIBXL_TIMER_MODE_DEFAULT; - b_info->u.hvm.nested_hvm = 0; b_info->u.hvm.no_incr_generationid = 0; b_info->u.hvm.stdvga = 0; @@ -107,9 +96,7 @@ void libxl_domain_build_info_init(libxl_ b_info->u.hvm.vnc.display = 0; b_info->u.hvm.vnc.findunused = 1; b_info->u.hvm.serial = NULL; - b_info->u.hvm.usb = 0; b_info->u.hvm.usbdevice = NULL; - b_info->u.hvm.xen_platform_pci = 1; break; case LIBXL_DOMAIN_TYPE_PV: b_info->u.pv.slack_memkb = 0; @@ -142,6 +129,8 @@ int libxl__domain_build_info_setdefault( if (b_info->target_memkb == LIBXL_MEMKB_DEFAULT) b_info->target_memkb = b_info->max_memkb; + libxl_defbool_setdefault(&b_info->disable_migrate, false); + switch (b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: if (b_info->shadow_memkb == LIBXL_MEMKB_DEFAULT) @@ -152,6 +141,19 @@ int libxl__domain_build_info_setdefault( b_info->u.hvm.timer_mode LIBXL_TIMER_MODE_NO_DELAY_FOR_MISSED_TICKS; + libxl_defbool_setdefault(&b_info->u.hvm.pae, true); + libxl_defbool_setdefault(&b_info->u.hvm.apic, true); + libxl_defbool_setdefault(&b_info->u.hvm.acpi, true); + libxl_defbool_setdefault(&b_info->u.hvm.acpi_s3, true); + libxl_defbool_setdefault(&b_info->u.hvm.acpi_s4, true); + libxl_defbool_setdefault(&b_info->u.hvm.nx, true); + libxl_defbool_setdefault(&b_info->u.hvm.viridian, false); + libxl_defbool_setdefault(&b_info->u.hvm.hpet, true); + libxl_defbool_setdefault(&b_info->u.hvm.vpt_align, true); + libxl_defbool_setdefault(&b_info->u.hvm.nested_hvm, false); + libxl_defbool_setdefault(&b_info->u.hvm.usb, false); + libxl_defbool_setdefault(&b_info->u.hvm.xen_platform_pci, true); + if (!b_info->u.hvm.boot) { b_info->u.hvm.boot = strdup("cda"); if (!b_info->u.hvm.boot) return ERROR_NOMEM; @@ -166,6 +168,7 @@ int libxl__domain_build_info_setdefault( break; case LIBXL_DOMAIN_TYPE_PV: + libxl_defbool_setdefault(&b_info->u.pv.e820_host, false); if (b_info->shadow_memkb == LIBXL_MEMKB_DEFAULT) b_info->shadow_memkb = 0; if (b_info->u.pv.slack_memkb == LIBXL_MEMKB_DEFAULT) @@ -221,11 +224,11 @@ int libxl__domain_build(libxl__gc *gc, localents = libxl__calloc(gc, 7, sizeof(char *)); localents[0] = "platform/acpi"; - localents[1] = (info->u.hvm.acpi) ? "1" : "0"; + localents[1] = libxl_defbool_val(info->u.hvm.acpi) ? "1" : "0"; localents[2] = "platform/acpi_s3"; - localents[3] = (info->u.hvm.acpi_s3) ? "1" : "0"; + localents[3] = libxl_defbool_val(info->u.hvm.acpi_s3) ? "1" : "0"; localents[4] = "platform/acpi_s4"; - localents[5] = (info->u.hvm.acpi_s4) ? "1" : "0"; + localents[5] = libxl_defbool_val(info->u.hvm.acpi_s4) ? "1" : "0"; break; case LIBXL_DOMAIN_TYPE_PV: @@ -427,7 +430,6 @@ retry_transaction: xs_rm(ctx->xsh, t, dom_path); libxl__xs_mkdir(gc, t, dom_path, roperm, ARRAY_SIZE(roperm)); - xs_rm(ctx->xsh, t, vm_path); libxl__xs_mkdir(gc, t, vm_path, roperm, ARRAY_SIZE(roperm)); @@ -674,7 +676,7 @@ static int do_domain_create(libxl__gc *g } if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV && - d_config->b_info.u.pv.e820_host) { + libxl_defbool_val(d_config->b_info.u.pv.e820_host)) { int rc; rc = libxl__e820_alloc(gc, domid, d_config); if (rc) diff -r 865634b37f70 -r 6a475fa5019c tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_dm.c Wed Feb 29 16:39:42 2012 +0000 @@ -194,7 +194,7 @@ static char ** libxl__build_device_model if (b_info->u.hvm.boot) { flexarray_vappend(dm_args, "-boot", b_info->u.hvm.boot, NULL); } - if (b_info->u.hvm.usb || b_info->u.hvm.usbdevice) { + if (libxl_defbool_val(b_info->u.hvm.usb) || b_info->u.hvm.usbdevice) { flexarray_append(dm_args, "-usb"); if (b_info->u.hvm.usbdevice) { flexarray_vappend(dm_args, @@ -204,7 +204,7 @@ static char ** libxl__build_device_model if (b_info->u.hvm.soundhw) { flexarray_vappend(dm_args, "-soundhw", b_info->u.hvm.soundhw, NULL); } - if (b_info->u.hvm.acpi) { + if (libxl_defbool_val(b_info->u.hvm.acpi)) { flexarray_append(dm_args, "-acpi"); } if (b_info->max_vcpus > 1) { @@ -433,7 +433,7 @@ static char ** libxl__build_device_model flexarray_vappend(dm_args, "-boot", libxl__sprintf(gc, "order=%s", b_info->u.hvm.boot), NULL); } - if (b_info->u.hvm.usb || b_info->u.hvm.usbdevice) { + if (libxl_defbool_val(b_info->u.hvm.usb) || b_info->u.hvm.usbdevice) { flexarray_append(dm_args, "-usb"); if (b_info->u.hvm.usbdevice) { flexarray_vappend(dm_args, @@ -443,7 +443,7 @@ static char ** libxl__build_device_model if (b_info->u.hvm.soundhw) { flexarray_vappend(dm_args, "-soundhw", b_info->u.hvm.soundhw, NULL); } - if (!b_info->u.hvm.acpi) { + if (!libxl_defbool_val(b_info->u.hvm.acpi)) { flexarray_append(dm_args, "-no-acpi"); } if (b_info->max_vcpus > 1) { @@ -945,7 +945,7 @@ int libxl__create_device_model(libxl__gc b_info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL) libxl__xs_write(gc, XBT_NULL, libxl__sprintf(gc, "%s/disable_pf", path), - "%d", !b_info->u.hvm.xen_platform_pci); + "%d", !libxl_defbool_val(b_info->u.hvm.xen_platform_pci)); libxl_create_logfile(ctx, libxl__sprintf(gc, "qemu-dm-%s", c_info->name), diff -r 865634b37f70 -r 6a475fa5019c tools/libxl/libxl_dom.c --- a/tools/libxl/libxl_dom.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_dom.c Wed Feb 29 16:39:42 2012 +0000 @@ -88,7 +88,7 @@ int libxl__build_pre(libxl__gc *gc, uint abort(); } xc_domain_set_tsc_info(ctx->xch, domid, tsc_mode, 0, 0, 0); - if ( info->disable_migrate ) + if (libxl_defbool_val(info->disable_migrate)) xc_domain_disable_migrate(ctx->xch, domid); if (info->type == LIBXL_DOMAIN_TYPE_HVM) { @@ -292,7 +292,7 @@ static int hvm_build_set_params(xc_inter return -1; va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET); - va_hvm->apic_mode = info->u.hvm.apic; + va_hvm->apic_mode = libxl_defbool_val(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++) @@ -302,14 +302,19 @@ static int hvm_build_set_params(xc_inter xc_get_hvm_param(handle, domid, HVM_PARAM_STORE_PFN, store_mfn); xc_get_hvm_param(handle, domid, HVM_PARAM_CONSOLE_PFN, console_mfn); - xc_set_hvm_param(handle, domid, HVM_PARAM_PAE_ENABLED, info->u.hvm.pae); + xc_set_hvm_param(handle, domid, HVM_PARAM_PAE_ENABLED, + libxl_defbool_val(info->u.hvm.pae)); #if defined(__i386__) || defined(__x86_64__) - xc_set_hvm_param(handle, domid, HVM_PARAM_VIRIDIAN, info->u.hvm.viridian); - xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, (unsigned long) info->u.hvm.hpet); + xc_set_hvm_param(handle, domid, HVM_PARAM_VIRIDIAN, + libxl_defbool_val(info->u.hvm.viridian)); + xc_set_hvm_param(handle, domid, HVM_PARAM_HPET_ENABLED, + libxl_defbool_val(info->u.hvm.hpet)); #endif xc_set_hvm_param(handle, domid, HVM_PARAM_TIMER_MODE, timer_mode(info)); - xc_set_hvm_param(handle, domid, HVM_PARAM_VPT_ALIGN, (unsigned long) info->u.hvm.vpt_align); - xc_set_hvm_param(handle, domid, HVM_PARAM_NESTEDHVM, info->u.hvm.nested_hvm); + xc_set_hvm_param(handle, domid, HVM_PARAM_VPT_ALIGN, + libxl_defbool_val(info->u.hvm.vpt_align)); + xc_set_hvm_param(handle, domid, HVM_PARAM_NESTEDHVM, + libxl_defbool_val(info->u.hvm.nested_hvm)); xc_set_hvm_param(handle, domid, HVM_PARAM_STORE_EVTCHN, store_evtchn); xc_set_hvm_param(handle, domid, HVM_PARAM_CONSOLE_EVTCHN, console_evtchn); @@ -400,7 +405,7 @@ int libxl__domain_restore_common(libxl__ case LIBXL_DOMAIN_TYPE_HVM: hvm = 1; superpages = 1; - pae = info->u.hvm.pae; + pae = libxl_defbool_val(info->u.hvm.pae); no_incr_generationid = info->u.hvm.no_incr_generationid; break; case LIBXL_DOMAIN_TYPE_PV: diff -r 865634b37f70 -r 6a475fa5019c tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_pci.c Wed Feb 29 16:39:42 2012 +0000 @@ -1378,7 +1378,7 @@ int libxl__e820_alloc(libxl__gc *gc, uin return ERROR_INVAL; b_info = &d_config->b_info; - if (!b_info->u.pv.e820_host) + if (!libxl_defbool_val(b_info->u.pv.e820_host)) return ERROR_INVAL; rc = xc_get_machine_memory_map(ctx->xch, map, E820MAX); diff -r 865634b37f70 -r 6a475fa5019c tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/libxl_types.idl Wed Feb 29 16:39:42 2012 +0000 @@ -235,7 +235,7 @@ libxl_domain_build_info = Struct("domain ("target_memkb", MemKB), ("video_memkb", MemKB), ("shadow_memkb", MemKB), - ("disable_migrate", bool), + ("disable_migrate", libxl_defbool), ("cpuid", libxl_cpuid_policy_list), ("type", libxl_domain_type), @@ -253,20 +253,20 @@ libxl_domain_build_info = Struct("domain ("extra_hvm", libxl_string_list), ("u", KeyedUnion(None, libxl_domain_type, "type", - [("hvm", Struct(None, [("firmware", string), - ("bios", libxl_bios_type), - ("pae", bool), - ("apic", bool), - ("acpi", bool), - ("acpi_s3", bool), - ("acpi_s4", bool), - ("nx", bool), - ("viridian", bool), - ("timeoffset", string), - ("hpet", bool), - ("vpt_align", bool), - ("timer_mode", libxl_timer_mode), - ("nested_hvm", bool), + [("hvm", Struct(None, [("firmware", string), + ("bios", libxl_bios_type), + ("pae", libxl_defbool), + ("apic", libxl_defbool), + ("acpi", libxl_defbool), + ("acpi_s3", libxl_defbool), + ("acpi_s4", libxl_defbool), + ("nx", libxl_defbool), + ("viridian", libxl_defbool), + ("timeoffset", string), + ("hpet", libxl_defbool), + ("vpt_align", libxl_defbool), + ("timer_mode", libxl_timer_mode), + ("nested_hvm", libxl_defbool), ("no_incr_generationid", bool), ("nographic", bool), ("stdvga", bool), @@ -280,13 +280,13 @@ libxl_domain_build_info = Struct("domain ("serial", string), ("boot", string), - ("usb", bool), + ("usb", libxl_defbool), # usbdevice: # - "tablet" for absolute mouse, # - "mouse" for PS/2 protocol relative mouse ("usbdevice", string), ("soundhw", string), - ("xen_platform_pci", bool), + ("xen_platform_pci", libxl_defbool), ])), ("pv", Struct(None, [("kernel", libxl_file_reference), ("slack_memkb", MemKB), @@ -296,7 +296,7 @@ libxl_domain_build_info = Struct("domain ("ramdisk", libxl_file_reference), ("features", string, {''const'': True}), # Use host''s E820 for PCI passthrough. - ("e820_host", bool), + ("e820_host", libxl_defbool), ])), ])), ], diff -r 865634b37f70 -r 6a475fa5019c tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:39:42 2012 +0000 @@ -671,8 +671,7 @@ static void parse_config_data(const char : libxl_get_required_shadow_memory(b_info->max_memkb, b_info->max_vcpus); - if (!xlu_cfg_get_long (config, "nomigrate", &l, 0)) - b_info->disable_migrate = l; + xlu_cfg_get_defbool(config, "nomigrate", &b_info->disable_migrate, 0); if (!xlu_cfg_get_long(config, "tsc_mode", &l, 1)) { const char *s = libxl_tsc_mode_to_string(l); @@ -714,24 +713,16 @@ static void parse_config_data(const char buf); exit (1); } - if (!xlu_cfg_get_long (config, "pae", &l, 0)) - b_info->u.hvm.pae = l; - if (!xlu_cfg_get_long (config, "apic", &l, 0)) - b_info->u.hvm.apic = l; - if (!xlu_cfg_get_long (config, "acpi", &l, 0)) - b_info->u.hvm.acpi = l; - if (!xlu_cfg_get_long (config, "acpi_s3", &l, 0)) - b_info->u.hvm.acpi_s3 = l; - if (!xlu_cfg_get_long (config, "acpi_s4", &l, 0)) - b_info->u.hvm.acpi_s4 = l; - if (!xlu_cfg_get_long (config, "nx", &l, 0)) - b_info->u.hvm.nx = l; - if (!xlu_cfg_get_long (config, "viridian", &l, 0)) - b_info->u.hvm.viridian = l; - if (!xlu_cfg_get_long (config, "hpet", &l, 0)) - b_info->u.hvm.hpet = l; - if (!xlu_cfg_get_long (config, "vpt_align", &l, 0)) - b_info->u.hvm.vpt_align = l; + + xlu_cfg_get_defbool(config, "pae", &b_info->u.hvm.pae, 0); + xlu_cfg_get_defbool(config, "apic", &b_info->u.hvm.apic, 0); + xlu_cfg_get_defbool(config, "acpi", &b_info->u.hvm.acpi, 0); + xlu_cfg_get_defbool(config, "acpi_s3", &b_info->u.hvm.acpi_s3, 0); + xlu_cfg_get_defbool(config, "acpi_s4", &b_info->u.hvm.acpi_s4, 0); + xlu_cfg_get_defbool(config, "nx", &b_info->u.hvm.nx, 0); + xlu_cfg_get_defbool(config, "viridian", &b_info->u.hvm.viridian, 0); + xlu_cfg_get_defbool(config, "hpet", &b_info->u.hvm.hpet, 0); + xlu_cfg_get_defbool(config, "vpt_align", &b_info->u.hvm.vpt_align, 0); if (!xlu_cfg_get_long(config, "timer_mode", &l, 1)) { const char *s = libxl_timer_mode_to_string(l); @@ -756,8 +747,7 @@ static void parse_config_data(const char } } - if (!xlu_cfg_get_long (config, "nestedhvm", &l, 0)) - b_info->u.hvm.nested_hvm = l; + xlu_cfg_get_defbool(config, "nestedhvm", &b_info->u.hvm.nested_hvm, 0); break; case LIBXL_DOMAIN_TYPE_PV: { @@ -997,19 +987,10 @@ skip_vfb: /* To be reworked (automatically enabled) once the auto ballooning * after guest starts is done (with PCI devices passed in). */ - if (!xlu_cfg_get_long (config, "e820_host", &l, 0)) { - switch (c_info->type) { - case LIBXL_DOMAIN_TYPE_HVM: - fprintf(stderr, "Can''t do e820_host in HVM mode!"); - break; - case LIBXL_DOMAIN_TYPE_PV: - if (l) - b_info->u.pv.e820_host = true; - break; - default: - abort(); - } - } + if (c_info->type == LIBXL_DOMAIN_TYPE_PV) { + xlu_cfg_get_defbool(config, "e820_host", &b_info->u.pv.e820_host, 0); + } + if (!xlu_cfg_get_list (config, "pci", &pcis, 0, 0)) { int i; d_config->num_pcidevs = 0; @@ -1027,7 +1008,7 @@ skip_vfb: d_config->num_pcidevs++; } if (d_config->num_pcidevs && c_info->type == LIBXL_DOMAIN_TYPE_PV) - b_info->u.pv.e820_host = true; + libxl_defbool_set(&b_info->u.pv.e820_host, true); } switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) { @@ -1219,12 +1200,12 @@ skip_vfb: b_info->u.hvm.gfx_passthru = l; xlu_cfg_replace_string (config, "serial", &b_info->u.hvm.serial, 0); xlu_cfg_replace_string (config, "boot", &b_info->u.hvm.boot, 0); - if (!xlu_cfg_get_long (config, "usb", &l, 0)) - b_info->u.hvm.usb = l; - xlu_cfg_replace_string (config, "usbdevice", &b_info->u.hvm.usbdevice, 0); + xlu_cfg_get_defbool(config, "usb", &b_info->u.hvm.usb, 0); + xlu_cfg_replace_string (config, "usbdevice", + &b_info->u.hvm.usbdevice, 0); xlu_cfg_replace_string (config, "soundhw", &b_info->u.hvm.soundhw, 0); - if (!xlu_cfg_get_long (config, "xen_platform_pci", &l, 0)) - b_info->u.hvm.xen_platform_pci = l; + xlu_cfg_get_defbool(config, "xen_platform_pci", + &b_info->u.hvm.xen_platform_pci, 0); } xlu_cfg_destroy(config); diff -r 865634b37f70 -r 6a475fa5019c tools/libxl/xl_sxp.c --- a/tools/libxl/xl_sxp.c Wed Feb 29 16:30:36 2012 +0000 +++ b/tools/libxl/xl_sxp.c Wed Feb 29 16:39:42 2012 +0000 @@ -71,7 +71,8 @@ void printf_info_sexp(int domid, libxl_d printf("\t(tsc_mode %s)\n", libxl_tsc_mode_to_string(b_info->tsc_mode)); printf("\t(max_memkb %"PRId64")\n", b_info->max_memkb); printf("\t(target_memkb %"PRId64")\n", b_info->target_memkb); - printf("\t(nomigrate %d)\n", b_info->disable_migrate); + printf("\t(nomigrate %s)\n", + libxl_defbool_to_string(b_info->disable_migrate)); if (c_info->type == LIBXL_DOMAIN_TYPE_PV && b_info->u.pv.bootloader) { int i; @@ -91,16 +92,22 @@ void printf_info_sexp(int domid, libxl_d printf("\t\t\t(firmware %s)\n", b_info->u.hvm.firmware); printf("\t\t\t(video_memkb %"PRId64")\n", b_info->video_memkb); printf("\t\t\t(shadow_memkb %"PRId64")\n", b_info->shadow_memkb); - printf("\t\t\t(pae %d)\n", b_info->u.hvm.pae); - printf("\t\t\t(apic %d)\n", b_info->u.hvm.apic); - printf("\t\t\t(acpi %d)\n", b_info->u.hvm.acpi); - printf("\t\t\t(nx %d)\n", b_info->u.hvm.nx); - printf("\t\t\t(viridian %d)\n", b_info->u.hvm.viridian); - printf("\t\t\t(hpet %d)\n", b_info->u.hvm.hpet); - printf("\t\t\t(vpt_align %d)\n", b_info->u.hvm.vpt_align); + printf("\t\t\t(pae %s)\n", libxl_defbool_to_string(b_info->u.hvm.pae)); + printf("\t\t\t(apic %s)\n", + libxl_defbool_to_string(b_info->u.hvm.apic)); + printf("\t\t\t(acpi %s)\n", + libxl_defbool_to_string(b_info->u.hvm.acpi)); + printf("\t\t\t(nx %s)\n", libxl_defbool_to_string(b_info->u.hvm.nx)); + printf("\t\t\t(viridian %s)\n", + libxl_defbool_to_string(b_info->u.hvm.viridian)); + printf("\t\t\t(hpet %s)\n", + libxl_defbool_to_string(b_info->u.hvm.hpet)); + printf("\t\t\t(vpt_align %s)\n", + libxl_defbool_to_string(b_info->u.hvm.vpt_align)); printf("\t\t\t(timer_mode %s)\n", libxl_timer_mode_to_string(b_info->u.hvm.timer_mode)); - printf("\t\t\t(nestedhvm %d)\n", b_info->u.hvm.nested_hvm); + printf("\t\t\t(nestedhvm %s)\n", + libxl_defbool_to_string(b_info->u.hvm.nested_hvm)); printf("\t\t\t(no_incr_generationid %d)\n", b_info->u.hvm.no_incr_generationid); @@ -125,7 +132,7 @@ void printf_info_sexp(int domid, libxl_d printf("\t\t\t(gfx_passthru %d)\n", b_info->u.hvm.gfx_passthru); printf("\t\t\t(serial %s)\n", b_info->u.hvm.serial); printf("\t\t\t(boot %s)\n", b_info->u.hvm.boot); - printf("\t\t\t(usb %d)\n", b_info->u.hvm.usb); + printf("\t\t\t(usb %s)\n", libxl_defbool_to_string(b_info->u.hvm.usb)); printf("\t\t\t(usbdevice %s)\n", b_info->u.hvm.usbdevice); printf("\t\t)\n"); break; @@ -134,7 +141,8 @@ void printf_info_sexp(int domid, libxl_d printf("\t\t\t(kernel %s)\n", b_info->u.pv.kernel.path); printf("\t\t\t(cmdline %s)\n", b_info->u.pv.cmdline); printf("\t\t\t(ramdisk %s)\n", b_info->u.pv.ramdisk.path); - printf("\t\t\t(e820_host %d)\n", b_info->u.pv.e820_host); + printf("\t\t\t(e820_host %s)\n", + libxl_defbool_to_string(b_info->u.pv.e820_host)); printf("\t\t)\n"); break; default:
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 19 of 27 V4] libxl: switch generation id control to libxl_defbool
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533598 0 # Node ID d9a7ad6b033d0a7838ff46a0e17a4e179c34a450 # Parent 6a475fa5019c3fc68f38fafbd36014d62c950c96 libxl: switch generation id control to libxl_defbool. This allows it to be set via the _init/_setdefault methods. Also switch the sense of the variable in the libxl API, since once you add defbool to the mix the double negatives become even more confusing. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Cc: Paul Durrant <Paul.Durrant@citrix.com> diff -r 6a475fa5019c -r d9a7ad6b033d tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:39:42 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:39:58 2012 +0000 @@ -89,7 +89,6 @@ void libxl_domain_build_info_init(libxl_ b_info->u.hvm.firmware = NULL; b_info->u.hvm.bios = 0; b_info->u.hvm.timer_mode = LIBXL_TIMER_MODE_DEFAULT; - b_info->u.hvm.no_incr_generationid = 0; b_info->u.hvm.stdvga = 0; b_info->u.hvm.vnc.enable = 1; @@ -151,6 +150,7 @@ int libxl__domain_build_info_setdefault( libxl_defbool_setdefault(&b_info->u.hvm.hpet, true); libxl_defbool_setdefault(&b_info->u.hvm.vpt_align, true); libxl_defbool_setdefault(&b_info->u.hvm.nested_hvm, false); + libxl_defbool_setdefault(&b_info->u.hvm.incr_generationid, false); libxl_defbool_setdefault(&b_info->u.hvm.usb, false); libxl_defbool_setdefault(&b_info->u.hvm.xen_platform_pci, true); diff -r 6a475fa5019c -r d9a7ad6b033d tools/libxl/libxl_dom.c --- a/tools/libxl/libxl_dom.c Wed Feb 29 16:39:42 2012 +0000 +++ b/tools/libxl/libxl_dom.c Wed Feb 29 16:39:58 2012 +0000 @@ -406,7 +406,7 @@ int libxl__domain_restore_common(libxl__ hvm = 1; superpages = 1; pae = libxl_defbool_val(info->u.hvm.pae); - no_incr_generationid = info->u.hvm.no_incr_generationid; + no_incr_generationid = !libxl_defbool_val(info->u.hvm.incr_generationid); break; case LIBXL_DOMAIN_TYPE_PV: hvm = 0; diff -r 6a475fa5019c -r d9a7ad6b033d tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 16:39:42 2012 +0000 +++ b/tools/libxl/libxl_types.idl Wed Feb 29 16:39:58 2012 +0000 @@ -267,7 +267,7 @@ libxl_domain_build_info = Struct("domain ("vpt_align", libxl_defbool), ("timer_mode", libxl_timer_mode), ("nested_hvm", libxl_defbool), - ("no_incr_generationid", bool), + ("incr_generationid",libxl_defbool), ("nographic", bool), ("stdvga", bool), ("vnc", libxl_vnc_info), diff -r 6a475fa5019c -r d9a7ad6b033d tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:39:42 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:39:58 2012 +0000 @@ -1357,7 +1357,7 @@ struct domain_create { const char *restore_file; int migrate_fd; /* -1 means none */ char **migration_domname_r; /* from malloc */ - int no_incr_generationid; + int incr_generationid; }; static int freemem(libxl_domain_build_info *b_info) @@ -1608,8 +1608,8 @@ static int create_domain(struct domain_c } if (d_config.c_info.type == LIBXL_DOMAIN_TYPE_HVM) - d_config.b_info.u.hvm.no_incr_generationid - dom_info->no_incr_generationid; + libxl_defbool_set(&d_config.b_info.u.hvm.incr_generationid, + dom_info->incr_generationid); if (debug || dom_info->dryrun) printf_info(default_output_format, -1, &d_config); @@ -2884,7 +2884,7 @@ static void migrate_receive(int debug, i dom_info.restore_file = "incoming migration stream"; dom_info.migrate_fd = 0; /* stdin */ dom_info.migration_domname_r = &migration_domname; - dom_info.no_incr_generationid = 1; + dom_info.incr_generationid = 0; rc = create_domain(&dom_info); if (rc < 0) { @@ -3009,6 +3009,7 @@ int main_restore(int argc, char **argv) dom_info.restore_file = checkpoint_file; dom_info.migrate_fd = -1; dom_info.console_autoconnect = console_autoconnect; + dom_info.incr_generationid = 1; rc = create_domain(&dom_info); if (rc < 0) @@ -3394,6 +3395,7 @@ int main_create(int argc, char **argv) dom_info.extra_config = extra_config; dom_info.migrate_fd = -1; dom_info.console_autoconnect = console_autoconnect; + dom_info.incr_generationid = 0; rc = create_domain(&dom_info); if (rc < 0) diff -r 6a475fa5019c -r d9a7ad6b033d tools/libxl/xl_sxp.c --- a/tools/libxl/xl_sxp.c Wed Feb 29 16:39:42 2012 +0000 +++ b/tools/libxl/xl_sxp.c Wed Feb 29 16:39:58 2012 +0000 @@ -108,8 +108,8 @@ void printf_info_sexp(int domid, libxl_d libxl_timer_mode_to_string(b_info->u.hvm.timer_mode)); printf("\t\t\t(nestedhvm %s)\n", libxl_defbool_to_string(b_info->u.hvm.nested_hvm)); - printf("\t\t\t(no_incr_generationid %d)\n", - b_info->u.hvm.no_incr_generationid); + printf("\t\t\t(no_incr_generationid %s)\n", + libxl_defbool_to_string(b_info->u.hvm.incr_generationid)); printf("\t\t\t(stdvga %d)\n", b_info->u.hvm.stdvga); printf("\t\t\t(vnc %d)\n", b_info->u.hvm.vnc.enable);
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 20 of 27 V4] libxl: use defbool for graphics related options
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330533600 0 # Node ID f2fc55636c0153df5bca389156b984eb1f10b59c # Parent d9a7ad6b033d0a7838ff46a0e17a4e179c34a450 libxl: use defbool for graphics related options This allows them to be set via the _init/_setdefault methods. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r d9a7ad6b033d -r f2fc55636c01 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Feb 29 16:39:58 2012 +0000 +++ b/tools/libxl/libxl.c Wed Feb 29 16:40:00 2012 +0000 @@ -2257,22 +2257,23 @@ out: void libxl_device_vfb_init(libxl_device_vfb *vfb) { memset(vfb, 0x00, sizeof(libxl_device_vfb)); - vfb->vnc.enable = 1; - vfb->vnc.passwd = NULL; - vfb->vnc.display = 0; - vfb->vnc.findunused = 1; - vfb->keymap = NULL; - vfb->sdl.enable = 0; - vfb->sdl.opengl = 0; - vfb->sdl.display = NULL; - vfb->sdl.xauthority = NULL; } int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb) { - if (!vfb->vnc.listen) { - vfb->vnc.listen = strdup("127.0.0.1"); - if (!vfb->vnc.listen) return ERROR_NOMEM; + libxl_defbool_setdefault(&vfb->vnc.enable, true); + if (libxl_defbool_val(vfb->vnc.enable)) { + if (!vfb->vnc.listen) { + vfb->vnc.listen = strdup("127.0.0.1"); + if (!vfb->vnc.listen) return ERROR_NOMEM; + } + + libxl_defbool_setdefault(&vfb->vnc.findunused, true); + } + + libxl_defbool_setdefault(&vfb->sdl.enable, false); + if (libxl_defbool_val(vfb->sdl.enable)) { + libxl_defbool_setdefault(&vfb->sdl.opengl, false); } return 0; @@ -2321,17 +2322,17 @@ int libxl_device_vfb_add(libxl_ctx *ctx, flexarray_append_pair(back, "state", libxl__sprintf(gc, "%d", 1)); flexarray_append_pair(back, "domain", libxl__domid_to_name(gc, domid)); flexarray_append_pair(back, "vnc", - libxl__sprintf(gc, "%d", vfb->vnc.enable)); + libxl_defbool_val(vfb->vnc.enable) ? "1" : "0"); flexarray_append_pair(back, "vnclisten", vfb->vnc.listen); flexarray_append_pair(back, "vncpasswd", vfb->vnc.passwd); flexarray_append_pair(back, "vncdisplay", libxl__sprintf(gc, "%d", vfb->vnc.display)); flexarray_append_pair(back, "vncunused", - libxl__sprintf(gc, "%d", vfb->vnc.findunused)); + libxl_defbool_val(vfb->vnc.findunused) ? "1" : "0"); flexarray_append_pair(back, "sdl", - libxl__sprintf(gc, "%d", vfb->sdl.enable)); + libxl_defbool_val(vfb->sdl.enable) ? "1" : "0"); flexarray_append_pair(back, "opengl", - libxl__sprintf(gc, "%d", vfb->sdl.opengl)); + libxl_defbool_val(vfb->sdl.opengl) ? "1" : "0"); if (vfb->sdl.xauthority) { flexarray_append_pair(back, "xauthority", vfb->sdl.xauthority); } diff -r d9a7ad6b033d -r f2fc55636c01 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:39:58 2012 +0000 +++ b/tools/libxl/libxl_create.c Wed Feb 29 16:40:00 2012 +0000 @@ -90,10 +90,7 @@ void libxl_domain_build_info_init(libxl_ b_info->u.hvm.bios = 0; b_info->u.hvm.timer_mode = LIBXL_TIMER_MODE_DEFAULT; - b_info->u.hvm.stdvga = 0; - b_info->u.hvm.vnc.enable = 1; b_info->u.hvm.vnc.display = 0; - b_info->u.hvm.vnc.findunused = 1; b_info->u.hvm.serial = NULL; b_info->u.hvm.usbdevice = NULL; break; @@ -159,13 +156,32 @@ int libxl__domain_build_info_setdefault( if (!b_info->u.hvm.boot) return ERROR_NOMEM; } - if (b_info->u.hvm.vnc.enable) { + libxl_defbool_setdefault(&b_info->u.hvm.stdvga, false); + libxl_defbool_setdefault(&b_info->u.hvm.vnc.enable, true); + if (libxl_defbool_val(b_info->u.hvm.vnc.enable)) { + libxl_defbool_setdefault(&b_info->u.hvm.vnc.findunused, true); if (!b_info->u.hvm.vnc.listen) { b_info->u.hvm.vnc.listen = strdup("127.0.0.1"); if (!b_info->u.hvm.vnc.listen) return ERROR_NOMEM; } } + libxl_defbool_setdefault(&b_info->u.hvm.sdl.enable, false); + if (libxl_defbool_val(b_info->u.hvm.sdl.enable)) { + libxl_defbool_setdefault(&b_info->u.hvm.sdl.opengl, false); + } + + libxl_defbool_setdefault(&b_info->u.hvm.spice.enable, false); + if (libxl_defbool_val(b_info->u.hvm.spice.enable)) { + libxl_defbool_setdefault(&b_info->u.hvm.spice.disable_ticketing, + false); + libxl_defbool_setdefault(&b_info->u.hvm.spice.agent_mouse, true); + } + + libxl_defbool_setdefault(&b_info->u.hvm.nographic, false); + + libxl_defbool_setdefault(&b_info->u.hvm.gfx_passthru, false); + break; case LIBXL_DOMAIN_TYPE_PV: libxl_defbool_setdefault(&b_info->u.pv.e820_host, false); diff -r d9a7ad6b033d -r f2fc55636c01 tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Wed Feb 29 16:39:58 2012 +0000 +++ b/tools/libxl/libxl_dm.c Wed Feb 29 16:40:00 2012 +0000 @@ -83,7 +83,7 @@ const libxl_vnc_info *libxl__dm_vnc(cons } else if (guest_config->num_vfbs > 0) { vnc = &guest_config->vfbs[0].vnc; } - return vnc && vnc->enable ? vnc : NULL; + return vnc && libxl_defbool_val(vnc->enable) ? vnc : NULL; } static const libxl_sdl_info *dm_sdl(const libxl_domain_config *guest_config) @@ -94,7 +94,7 @@ static const libxl_sdl_info *dm_sdl(cons } else if (guest_config->num_vfbs > 0) { sdl = &guest_config->vfbs[0].sdl; } - return sdl && sdl->enable ? sdl : NULL; + return sdl && libxl_defbool_val(sdl->enable) ? sdl : NULL; } static const char *dm_keymap(const libxl_domain_config *guest_config) @@ -156,13 +156,13 @@ static char ** libxl__build_device_model flexarray_append(dm_args, "-vnc"); flexarray_append(dm_args, vncarg); - if (vnc->findunused) { + if (libxl_defbool_val(vnc->findunused)) { flexarray_append(dm_args, "-vncunused"); } } if (sdl) { flexarray_append(dm_args, "-sdl"); - if (!sdl->opengl) { + if (!libxl_defbool_val(sdl->opengl)) { flexarray_append(dm_args, "-disable-opengl"); } /* XXX sdl->{display,xauthority} into $DISPLAY/$XAUTHORITY */ @@ -177,7 +177,7 @@ static char ** libxl__build_device_model flexarray_vappend(dm_args, "-serial", b_info->u.hvm.serial, NULL); } - if (b_info->u.hvm.nographic && (!sdl && !vnc)) { + if (libxl_defbool_val(b_info->u.hvm.nographic) && (!sdl && !vnc)) { flexarray_append(dm_args, "-nographic"); } @@ -187,7 +187,7 @@ static char ** libxl__build_device_model libxl__sizekb_to_mb(b_info->video_memkb)), NULL); } - if (b_info->u.hvm.stdvga) { + if (libxl_defbool_val(b_info->u.hvm.stdvga)) { flexarray_append(dm_args, "-std-vga"); } @@ -240,7 +240,7 @@ static char ** libxl__build_device_model if ( ioemu_vifs == 0 ) { flexarray_vappend(dm_args, "-net", "none", NULL); } - if (b_info->u.hvm.gfx_passthru) { + if (libxl_defbool_val(b_info->u.hvm.gfx_passthru)) { flexarray_append(dm_args, "-gfx_passthru"); } } else { @@ -293,7 +293,7 @@ static char *dm_spice_options(libxl__gc return NULL; } - if (!spice->disable_ticketing) { + if (!libxl_defbool_val(spice->disable_ticketing)) { if (!spice->passwd) { LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "spice ticketing is enabled but missing password"); @@ -309,12 +309,12 @@ static char *dm_spice_options(libxl__gc spice->port, spice->tls_port); if (spice->host) opt = libxl__sprintf(gc, "%s,addr=%s", opt, spice->host); - if (spice->disable_ticketing) + if (libxl_defbool_val(spice->disable_ticketing)) opt = libxl__sprintf(gc, "%s,disable-ticketing", opt); else opt = libxl__sprintf(gc, "%s,password=%s", opt, spice->passwd); opt = libxl__sprintf(gc, "%s,agent-mouse=%s", opt, - spice->agent_mouse ? "on" : "off"); + libxl_defbool_val(spice->agent_mouse) ? "on" : "off"); return opt; } @@ -383,7 +383,7 @@ static char ** libxl__build_device_model if (vnc->passwd && vnc->passwd[0]) { vncarg = libxl__sprintf(gc, "%s,password", vncarg); } - if (vnc->findunused) { + if (libxl_defbool_val(vnc->findunused)) { /* This option asks to QEMU to try this number of port before to * give up. So QEMU will try ports between $display and $display + * 99. This option needs to be the last one of the vnc options. */ @@ -411,11 +411,11 @@ static char ** libxl__build_device_model flexarray_vappend(dm_args, "-serial", b_info->u.hvm.serial, NULL); } - if (b_info->u.hvm.nographic && (!sdl && !vnc)) { + if (libxl_defbool_val(b_info->u.hvm.nographic) && (!sdl && !vnc)) { flexarray_append(dm_args, "-nographic"); } - if (b_info->u.hvm.spice.enable) { + if (libxl_defbool_val(b_info->u.hvm.spice.enable)) { const libxl_spice_info *spice = &b_info->u.hvm.spice; char *spiceoptions = dm_spice_options(gc, spice); if (!spiceoptions) @@ -425,7 +425,7 @@ static char ** libxl__build_device_model flexarray_append(dm_args, spiceoptions); } - if (b_info->u.hvm.stdvga) { + if (libxl_defbool_val(b_info->u.hvm.stdvga)) { flexarray_vappend(dm_args, "-vga", "std", NULL); } @@ -485,7 +485,7 @@ static char ** libxl__build_device_model flexarray_append(dm_args, "-net"); flexarray_append(dm_args, "none"); } - if (b_info->u.hvm.gfx_passthru) { + if (libxl_defbool_val(b_info->u.hvm.gfx_passthru)) { flexarray_append(dm_args, "-gfx_passthru"); } } else { diff -r d9a7ad6b033d -r f2fc55636c01 tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 16:39:58 2012 +0000 +++ b/tools/libxl/libxl_types.idl Wed Feb 29 16:40:00 2012 +0000 @@ -129,31 +129,31 @@ libxl_shutdown_reason = Enumeration("shu # Complex libxl types # libxl_vnc_info = Struct("vnc_info", [ - ("enable", bool), + ("enable", libxl_defbool), # "address:port" that should be listened on ("listen", string), ("passwd", string), ("display", integer), # If set then try to find an unused port - ("findunused", bool), + ("findunused", libxl_defbool), ]) libxl_spice_info = Struct("spice_info", [ - ("enable", bool), + ("enable", libxl_defbool), # At least one of spice port or spicetls_post must be given ("port", integer), ("tls_port", integer), # Interface to bind to ("host", string), # enable client connection with no password - ("disable_ticketing", bool), + ("disable_ticketing", libxl_defbool), ("passwd", string), - ("agent_mouse", bool), + ("agent_mouse", libxl_defbool), ]) libxl_sdl_info = Struct("sdl_info", [ - ("enable", bool), - ("opengl", bool), + ("enable", libxl_defbool), + ("opengl", libxl_defbool), ("display", string), ("xauthority", string), ]) @@ -268,15 +268,15 @@ libxl_domain_build_info = Struct("domain ("timer_mode", libxl_timer_mode), ("nested_hvm", libxl_defbool), ("incr_generationid",libxl_defbool), - ("nographic", bool), - ("stdvga", bool), + ("nographic", libxl_defbool), + ("stdvga", libxl_defbool), ("vnc", libxl_vnc_info), # keyboard layout, default is en-us keyboard ("keymap", string), ("sdl", libxl_sdl_info), ("spice", libxl_spice_info), - ("gfx_passthru", bool), + ("gfx_passthru", libxl_defbool), ("serial", string), ("boot", string), diff -r d9a7ad6b033d -r f2fc55636c01 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:39:58 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Wed Feb 29 16:40:00 2012 +0000 @@ -946,7 +946,7 @@ skip: break; *p2 = ''\0''; if (!strcmp(p, "vnc")) { - vfb->vnc.enable = atoi(p2 + 1); + libxl_defbool_set(&vfb->vnc.enable, atoi(p2 + 1)); } else if (!strcmp(p, "vnclisten")) { free(vfb->vnc.listen); vfb->vnc.listen = strdup(p2 + 1); @@ -956,14 +956,14 @@ skip: } else if (!strcmp(p, "vncdisplay")) { vfb->vnc.display = atoi(p2 + 1); } else if (!strcmp(p, "vncunused")) { - vfb->vnc.findunused = atoi(p2 + 1); + libxl_defbool_set(&vfb->vnc.findunused, atoi(p2 + 1)); } else if (!strcmp(p, "keymap")) { free(vfb->keymap); vfb->keymap = strdup(p2 + 1); } else if (!strcmp(p, "sdl")) { - vfb->sdl.enable = atoi(p2 + 1); + libxl_defbool_set(&vfb->sdl.enable, atoi(p2 + 1)); } else if (!strcmp(p, "opengl")) { - vfb->sdl.opengl = atoi(p2 + 1); + libxl_defbool_set(&vfb->sdl.opengl, atoi(p2 + 1)); } else if (!strcmp(p, "display")) { free(vfb->sdl.display); vfb->sdl.display = strdup(p2 + 1); @@ -1163,41 +1163,35 @@ skip_vfb: #undef parse_extra_args if (c_info->type == LIBXL_DOMAIN_TYPE_HVM) { - if (!xlu_cfg_get_long (config, "stdvga", &l, 0)) - b_info->u.hvm.stdvga = l; - if (!xlu_cfg_get_long (config, "vnc", &l, 0)) - b_info->u.hvm.vnc.enable = l; - xlu_cfg_replace_string (config, "vnclisten", &b_info->u.hvm.vnc.listen, 0); - xlu_cfg_replace_string (config, "vncpasswd", &b_info->u.hvm.vnc.passwd, 0); + xlu_cfg_get_defbool(config, "stdvga", &b_info->u.hvm.stdvga, 0); + xlu_cfg_get_defbool(config, "vnc", &b_info->u.hvm.vnc.enable, 0); + xlu_cfg_replace_string (config, "vnclisten", + &b_info->u.hvm.vnc.listen, 0); + xlu_cfg_replace_string (config, "vncpasswd", + &b_info->u.hvm.vnc.passwd, 0); if (!xlu_cfg_get_long (config, "vncdisplay", &l, 0)) b_info->u.hvm.vnc.display = l; - if (!xlu_cfg_get_long (config, "vncunused", &l, 0)) - b_info->u.hvm.vnc.findunused = l; + xlu_cfg_get_defbool(config, "vncunused", + &b_info->u.hvm.vnc.findunused, 0); xlu_cfg_replace_string (config, "keymap", &b_info->u.hvm.keymap, 0); - if (!xlu_cfg_get_long (config, "sdl", &l, 0)) - b_info->u.hvm.sdl.enable = l; - if (!xlu_cfg_get_long (config, "opengl", &l, 0)) - b_info->u.hvm.sdl.opengl = l; - if (!xlu_cfg_get_long (config, "spice", &l, 0)) - b_info->u.hvm.spice.enable = l; + xlu_cfg_get_defbool(config, "sdl", &b_info->u.hvm.sdl.enable, 0); + xlu_cfg_get_defbool(config, "opengl", &b_info->u.hvm.sdl.opengl, 0); + xlu_cfg_get_defbool (config, "spice", &b_info->u.hvm.spice.enable, 0); if (!xlu_cfg_get_long (config, "spiceport", &l, 0)) b_info->u.hvm.spice.port = l; if (!xlu_cfg_get_long (config, "spicetls_port", &l, 0)) b_info->u.hvm.spice.tls_port = l; xlu_cfg_replace_string (config, "spicehost", &b_info->u.hvm.spice.host, 0); - if (!xlu_cfg_get_long (config, "spicedisable_ticketing", &l, 0)) - b_info->u.hvm.spice.disable_ticketing = l; + xlu_cfg_get_defbool(config, "spicedisable_ticketing", + &b_info->u.hvm.spice.disable_ticketing, 0); xlu_cfg_replace_string (config, "spicepasswd", &b_info->u.hvm.spice.passwd, 0); - if (!xlu_cfg_get_long (config, "spiceagent_mouse", &l, 0)) - b_info->u.hvm.spice.agent_mouse = l; - else - b_info->u.hvm.spice.agent_mouse = 1; - if (!xlu_cfg_get_long (config, "nographic", &l, 0)) - b_info->u.hvm.nographic = l; - if (!xlu_cfg_get_long (config, "gfx_passthru", &l, 0)) - b_info->u.hvm.gfx_passthru = l; + xlu_cfg_get_defbool(config, "spiceagent_mouse", + &b_info->u.hvm.spice.agent_mouse, 0); + xlu_cfg_get_defbool(config, "nographic", &b_info->u.hvm.nographic, 0); + xlu_cfg_get_defbool(config, "gfx_passthru", + &b_info->u.hvm.gfx_passthru, 0); xlu_cfg_replace_string (config, "serial", &b_info->u.hvm.serial, 0); xlu_cfg_replace_string (config, "boot", &b_info->u.hvm.boot, 0); xlu_cfg_get_defbool(config, "usb", &b_info->u.hvm.usb, 0); diff -r d9a7ad6b033d -r f2fc55636c01 tools/libxl/xl_sxp.c --- a/tools/libxl/xl_sxp.c Wed Feb 29 16:39:58 2012 +0000 +++ b/tools/libxl/xl_sxp.c Wed Feb 29 16:40:00 2012 +0000 @@ -110,26 +110,34 @@ void printf_info_sexp(int domid, libxl_d libxl_defbool_to_string(b_info->u.hvm.nested_hvm)); printf("\t\t\t(no_incr_generationid %s)\n", libxl_defbool_to_string(b_info->u.hvm.incr_generationid)); - - printf("\t\t\t(stdvga %d)\n", b_info->u.hvm.stdvga); - printf("\t\t\t(vnc %d)\n", b_info->u.hvm.vnc.enable); + printf("\t\t\t(stdvga %s)\n", + libxl_defbool_to_string(b_info->u.hvm.stdvga)); + printf("\t\t\t(vnc %s)\n", + libxl_defbool_to_string(b_info->u.hvm.vnc.enable)); printf("\t\t\t(vnclisten %s)\n", b_info->u.hvm.vnc.listen); printf("\t\t\t(vncdisplay %d)\n", b_info->u.hvm.vnc.display); - printf("\t\t\t(vncunused %d)\n", b_info->u.hvm.vnc.findunused); + printf("\t\t\t(vncunused %s)\n", + libxl_defbool_to_string(b_info->u.hvm.vnc.findunused)); printf("\t\t\t(keymap %s)\n", b_info->u.hvm.keymap); - printf("\t\t\t(sdl %d)\n", b_info->u.hvm.sdl.enable); - printf("\t\t\t(opengl %d)\n", b_info->u.hvm.sdl.opengl); - printf("\t\t\t(nographic %d)\n", b_info->u.hvm.nographic); - printf("\t\t\t(spice %d)\n", b_info->u.hvm.spice.enable); + printf("\t\t\t(sdl %s)\n", + libxl_defbool_to_string(b_info->u.hvm.sdl.enable)); + printf("\t\t\t(opengl %s)\n", + libxl_defbool_to_string(b_info->u.hvm.sdl.opengl)); + printf("\t\t\t(nographic %s)\n", + libxl_defbool_to_string(b_info->u.hvm.nographic)); + printf("\t\t\t(spice %s)\n", + libxl_defbool_to_string(b_info->u.hvm.spice.enable)); printf("\t\t\t(spiceport %d)\n", b_info->u.hvm.spice.port); printf("\t\t\t(spicetls_port %d)\n", b_info->u.hvm.spice.tls_port); printf("\t\t\t(spicehost %s)\n", b_info->u.hvm.spice.host); - printf("\t\t\t(spicedisable_ticketing %d)\n", - b_info->u.hvm.spice.disable_ticketing); - printf("\t\t\t(spiceagent_mouse %d)\n", b_info->u.hvm.spice.agent_mouse); + printf("\t\t\t(spicedisable_ticketing %s)\n", + libxl_defbool_to_string(b_info->u.hvm.spice.disable_ticketing)); + printf("\t\t\t(spiceagent_mouse %s)\n", + libxl_defbool_to_string(b_info->u.hvm.spice.agent_mouse)); printf("\t\t\t(device_model %s)\n", b_info->device_model ? : "default"); - printf("\t\t\t(gfx_passthru %d)\n", b_info->u.hvm.gfx_passthru); + printf("\t\t\t(gfx_passthru %s)\n", + libxl_defbool_to_string(b_info->u.hvm.gfx_passthru)); printf("\t\t\t(serial %s)\n", b_info->u.hvm.serial); printf("\t\t\t(boot %s)\n", b_info->u.hvm.boot); printf("\t\t\t(usb %s)\n", libxl_defbool_to_string(b_info->u.hvm.usb)); @@ -204,13 +212,17 @@ void printf_info_sexp(int domid, libxl_d printf("\t\t\t(backend_domid %d)\n", d_config->vfbs[i].backend_domid); printf("\t\t\t(frontend_domid %d)\n", domid); printf("\t\t\t(devid %d)\n", d_config->vfbs[i].devid); - printf("\t\t\t(vnc %d)\n", d_config->vfbs[i].vnc.enable); + printf("\t\t\t(vnc %s)\n", + libxl_defbool_to_string(d_config->vfbs[i].vnc.enable)); printf("\t\t\t(vnclisten %s)\n", d_config->vfbs[i].vnc.listen); printf("\t\t\t(vncdisplay %d)\n", d_config->vfbs[i].vnc.display); - printf("\t\t\t(vncunused %d)\n", d_config->vfbs[i].vnc.findunused); + printf("\t\t\t(vncunused %s)\n", + libxl_defbool_to_string(d_config->vfbs[i].vnc.findunused)); printf("\t\t\t(keymap %s)\n", d_config->vfbs[i].keymap); - printf("\t\t\t(sdl %d)\n", d_config->vfbs[i].sdl.enable); - printf("\t\t\t(opengl %d)\n", d_config->vfbs[i].sdl.opengl); + printf("\t\t\t(sdl %s)\n", + libxl_defbool_to_string(d_config->vfbs[i].sdl.enable)); + printf("\t\t\t(opengl %s)\n", + libxl_defbool_to_string(d_config->vfbs[i].sdl.opengl)); printf("\t\t\t(display %s)\n", d_config->vfbs[i].sdl.display); printf("\t\t\t(xauthority %s)\n", d_config->vfbs[i].sdl.xauthority); printf("\t\t)\n");
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 21 of 27 V4] libxl: Select BIOS using libxl_domain_build_info_setdefaults
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330598783 0 # Node ID a884dc50100119da3e767ebe243f3e978981670f # Parent f2fc55636c0153df5bca389156b984eb1f10b59c libxl: Select BIOS using libxl_domain_build_info_setdefaults Remove libxl__domain_bios -- it is no longer necessary. Also we appear to have been setting the xenstore key even for device models for PV guests -- stop doing that. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r f2fc55636c01 -r a884dc501001 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 16:40:00 2012 +0000 +++ b/tools/libxl/libxl_create.c Thu Mar 01 10:46:23 2012 +0000 @@ -109,6 +109,26 @@ int libxl__domain_build_info_setdefault( b_info->device_model_version LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; + if (!b_info->u.hvm.bios) + switch (b_info->device_model_version) { + case 1: b_info->u.hvm.bios = LIBXL_BIOS_TYPE_ROMBIOS; break; + case 2: b_info->u.hvm.bios = LIBXL_BIOS_TYPE_SEABIOS; break; + default:return ERROR_INVAL; + } + + /* Enforce BIOS<->Device Model version relationship */ + switch (b_info->device_model_version) { + case 1: + if (b_info->u.hvm.bios != LIBXL_BIOS_TYPE_ROMBIOS) + return ERROR_INVAL; + break; + case 2: + if (b_info->u.hvm.bios == LIBXL_BIOS_TYPE_ROMBIOS) + return ERROR_INVAL; + break; + default:abort(); + } + if (!b_info->max_vcpus) b_info->max_vcpus = 1; if (!b_info->cur_vcpus) diff -r f2fc55636c01 -r a884dc501001 tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Wed Feb 29 16:40:00 2012 +0000 +++ b/tools/libxl/libxl_dm.c Thu Mar 01 10:46:23 2012 +0000 @@ -63,18 +63,6 @@ const char *libxl__domain_device_model(l return dm; } -static const char *libxl__domain_bios(libxl__gc *gc, - const libxl_domain_build_info *info) -{ - if (info->u.hvm.bios) - return libxl_bios_type_to_string(info->u.hvm.bios); - switch (info->device_model_version) { - case 1: return "rombios"; - case 2: return "seabios"; - default:return NULL; - } -} - const libxl_vnc_info *libxl__dm_vnc(const libxl_domain_config *guest_config) { const libxl_vnc_info *vnc = NULL; @@ -933,10 +921,13 @@ int libxl__create_device_model(libxl__gc goto out; } - path = xs_get_domain_path(ctx->xsh, domid); - libxl__xs_write(gc, XBT_NULL, libxl__sprintf(gc, "%s/hvmloader/bios", path), - "%s", libxl__domain_bios(gc, b_info)); - free(path); + if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) { + path = xs_get_domain_path(ctx->xsh, domid); + libxl__xs_write(gc, XBT_NULL, + libxl__sprintf(gc, "%s/hvmloader/bios", path), + "%s", libxl_bios_type_to_string(b_info->u.hvm.bios)); + free(path); + } path = libxl__sprintf(gc, "/local/domain/0/device-model/%d", domid); xs_mkdir(ctx->xsh, XBT_NULL, path);
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 22 of 27 V4] libxl: do not explicitly initialise members of build info to zero
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330598785 0 # Node ID 4918e8436684df642284f3b43be1dd75d1703421 # Parent a884dc50100119da3e767ebe243f3e978981670f libxl: do not explicitly initialise members of build info to zero Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r a884dc501001 -r 4918e8436684 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Thu Mar 01 10:46:23 2012 +0000 +++ b/tools/libxl/libxl_create.c Thu Mar 01 10:46:25 2012 +0000 @@ -73,7 +73,6 @@ void libxl_domain_build_info_init(libxl_ const libxl_domain_create_info *c_info) { memset(b_info, ''\0'', sizeof(*b_info)); - b_info->cpuid = NULL; b_info->type = c_info->type; b_info->max_memkb = LIBXL_MEMKB_DEFAULT; @@ -86,13 +85,7 @@ void libxl_domain_build_info_init(libxl_ switch (b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: - b_info->u.hvm.firmware = NULL; - b_info->u.hvm.bios = 0; b_info->u.hvm.timer_mode = LIBXL_TIMER_MODE_DEFAULT; - - b_info->u.hvm.vnc.display = 0; - b_info->u.hvm.serial = NULL; - b_info->u.hvm.usbdevice = NULL; break; case LIBXL_DOMAIN_TYPE_PV: b_info->u.pv.slack_memkb = 0;
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 23 of 27 V4] libxl: switch device model selection over to libxl_defbool
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330598786 0 # Node ID 708e5be5a38cf88a6dd5da81c41a632a6281269f # Parent 4918e8436684df642284f3b43be1dd75d1703421 libxl: switch device model selection over to libxl_defbool This allows it to be set via the _init/_setdefault methods. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> [since last v -- ERROR_INVAL on stubdomains + !traditional qemu] diff -r 4918e8436684 -r 708e5be5a38c tools/libxl/libxl.c --- a/tools/libxl/libxl.c Thu Mar 01 10:46:25 2012 +0000 +++ b/tools/libxl/libxl.c Thu Mar 01 10:46:26 2012 +0000 @@ -2714,7 +2714,7 @@ int libxl_domain_need_memory(libxl_ctx * switch (b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: *need_memkb += b_info->shadow_memkb + LIBXL_HVM_EXTRA_MEMORY; - if (b_info->device_model_stubdomain) + if (libxl_defbool_val(b_info->device_model_stubdomain)) *need_memkb += 32 * 1024; break; case LIBXL_DOMAIN_TYPE_PV: diff -r 4918e8436684 -r 708e5be5a38c tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Thu Mar 01 10:46:25 2012 +0000 +++ b/tools/libxl/libxl_create.c Thu Mar 01 10:46:26 2012 +0000 @@ -80,9 +80,6 @@ void libxl_domain_build_info_init(libxl_ b_info->shadow_memkb = LIBXL_MEMKB_DEFAULT; b_info->video_memkb = LIBXL_MEMKB_DEFAULT; - b_info->device_model_stubdomain = false; - b_info->device_model = NULL; - switch (b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: b_info->u.hvm.timer_mode = LIBXL_TIMER_MODE_DEFAULT; @@ -122,6 +119,17 @@ int libxl__domain_build_info_setdefault( default:abort(); } + libxl_defbool_setdefault(&b_info->device_model_stubdomain, false); + + if (b_info->type == LIBXL_DOMAIN_TYPE_HVM && + b_info->device_model_version !+ LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL && + libxl_defbool_val(b_info->device_model_stubdomain)) { + LIBXL__LOG(CTX, XTL_ERROR, + "device model stubdomains require \"qemu-xen-traditional\""); + return ERROR_INVAL; + } + if (!b_info->max_vcpus) b_info->max_vcpus = 1; if (!b_info->cur_vcpus) diff -r 4918e8436684 -r 708e5be5a38c tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Thu Mar 01 10:46:25 2012 +0000 +++ b/tools/libxl/libxl_dm.c Thu Mar 01 10:46:26 2012 +0000 @@ -39,7 +39,7 @@ const char *libxl__domain_device_model(l libxl_ctx *ctx = libxl__gc_owner(gc); const char *dm; - if (info->device_model_stubdomain) + if (libxl_defbool_val(info->device_model_stubdomain)) return NULL; if (info->device_model) { @@ -899,7 +899,7 @@ int libxl__create_device_model(libxl__gc char **pass_stuff; const char *dm; - if (b_info->device_model_stubdomain) { + if (libxl_defbool_val(b_info->device_model_stubdomain)) { rc = libxl__create_stubdom(gc, domid, guest_config, state, starting_r); goto out; } diff -r 4918e8436684 -r 708e5be5a38c tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Thu Mar 01 10:46:25 2012 +0000 +++ b/tools/libxl/libxl_types.idl Thu Mar 01 10:46:26 2012 +0000 @@ -240,8 +240,8 @@ libxl_domain_build_info = Struct("domain ("type", libxl_domain_type), ("device_model_version", libxl_device_model_version), - ("device_model_stubdomain", bool), - # you set device_model you must set device_model_version too + ("device_model_stubdomain", libxl_defbool), + # if you set device_model you must set device_model_version too ("device_model", string), ("device_model_ssidref", uint32), diff -r 4918e8436684 -r 708e5be5a38c tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Mar 01 10:46:25 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Thu Mar 01 10:46:26 2012 +0000 @@ -1125,8 +1125,8 @@ skip_vfb: } } else if (b_info->device_model) fprintf(stderr, "WARNING: device model override given without specific DM version\n"); - if (!xlu_cfg_get_long (config, "device_model_stubdomain_override", &l, 0)) - b_info->device_model_stubdomain = l; + xlu_cfg_get_defbool (config, "device_model_stubdomain_override", + &b_info->device_model_stubdomain, 0); if (!xlu_cfg_get_string (config, "device_model_stubdomain_seclabel", &buf, 0)) {
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 24 of 27 V4] libxl: add libxl_domain_build_info_init_type
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330598786 0 # Node ID 6be99cd73e1e242d516b1e4ac2d59dd940904a54 # Parent 708e5be5a38cf88a6dd5da81c41a632a6281269f libxl: add libxl_domain_build_info_init_type Use instead of parameterising libxl_domain_build_info_init. This allows callers to initialise a libxl_domain_build_info but not to commit to a particular type later on (e.g. after they''ve parsed the domain config) Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r 708e5be5a38c -r 6be99cd73e1e tools/libxl/libxl.h --- a/tools/libxl/libxl.h Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/libxl.h Thu Mar 01 10:46:26 2012 +0000 @@ -382,8 +382,9 @@ int libxl_ctx_postfork(libxl_ctx *ctx); /* domain related functions */ void libxl_domain_create_info_init(libxl_domain_create_info *c_info); -void libxl_domain_build_info_init(libxl_domain_build_info *b_info, - const libxl_domain_create_info *c_info); +void libxl_domain_build_info_init(libxl_domain_build_info *b_info); +void libxl_domain_build_info_init_type(libxl_domain_build_info *b_info, + libxl_domain_type type); typedef int (*libxl_console_ready)(libxl_ctx *ctx, uint32_t domid, void *priv); int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid); int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid, int restore_fd); diff -r 708e5be5a38c -r 6be99cd73e1e tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/libxl_create.c Thu Mar 01 10:46:26 2012 +0000 @@ -69,23 +69,29 @@ int libxl__domain_create_info_setdefault return 0; } -void libxl_domain_build_info_init(libxl_domain_build_info *b_info, - const libxl_domain_create_info *c_info) +void libxl_domain_build_info_init(libxl_domain_build_info *b_info) { memset(b_info, ''\0'', sizeof(*b_info)); - b_info->type = c_info->type; + b_info->type = -1; b_info->max_memkb = LIBXL_MEMKB_DEFAULT; b_info->target_memkb = LIBXL_MEMKB_DEFAULT; b_info->shadow_memkb = LIBXL_MEMKB_DEFAULT; b_info->video_memkb = LIBXL_MEMKB_DEFAULT; +} + +void libxl_domain_build_info_init_type(libxl_domain_build_info *b_info, + libxl_domain_type type) +{ + assert(b_info->type == -1); + b_info->type = type; switch (b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: b_info->u.hvm.timer_mode = LIBXL_TIMER_MODE_DEFAULT; break; case LIBXL_DOMAIN_TYPE_PV: - b_info->u.pv.slack_memkb = 0; + b_info->u.pv.slack_memkb = LIBXL_MEMKB_DEFAULT; break; default: abort(); diff -r 708e5be5a38c -r 6be99cd73e1e tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/libxl_dm.c Thu Mar 01 10:46:26 2012 +0000 @@ -701,7 +701,8 @@ static int libxl__create_stubdom(libxl__ libxl_uuid_generate(&dm_config.c_info.uuid); - libxl_domain_build_info_init(&dm_config.b_info, &dm_config.c_info); + libxl_domain_build_info_init(&dm_config.b_info); + libxl_domain_build_info_init_type(&dm_config.b_info, LIBXL_DOMAIN_TYPE_PV); dm_config.b_info.max_vcpus = 1; dm_config.b_info.max_memkb = 32 * 1024; diff -r 708e5be5a38c -r 6be99cd73e1e tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Thu Mar 01 10:46:26 2012 +0000 @@ -582,7 +582,8 @@ static void parse_config_data(const char exit(1); } - libxl_domain_build_info_init(b_info, c_info); + libxl_domain_build_info_init(b_info); + libxl_domain_build_info_init_type(b_info, c_info->type); /* the following is the actual config parsing with overriding values in the structures */ if (!xlu_cfg_get_long (config, "vcpus", &l, 0)) { @@ -699,7 +700,7 @@ static void parse_config_data(const char if (!xlu_cfg_get_long (config, "videoram", &l, 0)) b_info->video_memkb = l * 1024; - switch(c_info->type) { + switch(b_info->type) { case LIBXL_DOMAIN_TYPE_HVM: if (!xlu_cfg_get_string (config, "kernel", &buf, 0)) fprintf(stderr, "WARNING: ignoring \"kernel\" directive for HVM guest. "
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 25 of 27 V4] libxl: Make IDL KeyedUnion keyvar an idl.Field
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330598786 0 # Node ID 22edfaf269f0331025c7dd725fbf1e1fdbe64c4d # Parent 6be99cd73e1e242d516b1e4ac2d59dd940904a54 libxl: Make IDL KeyedUnion keyvar an idl.Field This is more logical than having keyvar_name and keyvar_type members. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> diff -r 6be99cd73e1e -r 22edfaf269f0 tools/libxl/gentest.py --- a/tools/libxl/gentest.py Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/gentest.py Thu Mar 01 10:46:26 2012 +0000 @@ -31,7 +31,7 @@ def gen_rand_init(ty, v, indent = " " elif isinstance(ty, idl.KeyedUnion): if parent is None: raise Exception("KeyedUnion type must have a parent") - s += "switch (%s) {\n" % (parent + ty.keyvar_name) + s += "switch (%s) {\n" % (parent + ty.keyvar.name) for f in ty.fields: (nparent,fexpr) = ty.member(v, f, parent is None) s += "case %s:\n" % f.enumname diff -r 6be99cd73e1e -r 22edfaf269f0 tools/libxl/gentypes.py --- a/tools/libxl/gentypes.py Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/gentypes.py Thu Mar 01 10:46:26 2012 +0000 @@ -56,7 +56,7 @@ def libxl_C_type_dispose(ty, v, indent if isinstance(ty, idl.KeyedUnion): if parent is None: raise Exception("KeyedUnion type must have a parent") - s += "switch (%s) {\n" % (parent + ty.keyvar_name) + s += "switch (%s) {\n" % (parent + ty.keyvar.name) for f in ty.fields: (nparent,fexpr) = ty.member(v, f, parent is None) s += "case %s:\n" % f.enumname @@ -86,7 +86,7 @@ def libxl_C_type_gen_json(ty, v, indent elif isinstance(ty, idl.KeyedUnion): if parent is None: raise Exception("KeyedUnion type must have a parent") - s += "switch (%s) {\n" % (parent + ty.keyvar_name) + s += "switch (%s) {\n" % (parent + ty.keyvar.name) for f in ty.fields: (nparent,fexpr) = ty.member(v, f, parent is None) s += "case %s:\n" % f.enumname diff -r 6be99cd73e1e -r 22edfaf269f0 tools/libxl/idl.py --- a/tools/libxl/idl.py Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/idl.py Thu Mar 01 10:46:26 2012 +0000 @@ -206,8 +206,9 @@ class KeyedUnion(Aggregate): if not isinstance(keyvar_type, Enumeration): raise ValueError - self.keyvar_name = keyvar_name - self.keyvar_type = keyvar_type + kv_kwargs = dict([(x.lstrip(''keyvar_''),y) for (x,y) in kwargs.items() if x.startswith(''keyvar_'')]) + + self.keyvar = Field(keyvar_type, keyvar_name, **kv_kwargs) for f in fields: # (name, enum, type) diff -r 6be99cd73e1e -r 22edfaf269f0 tools/libxl/idl.txt --- a/tools/libxl/idl.txt Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/idl.txt Thu Mar 01 10:46:26 2012 +0000 @@ -128,10 +128,9 @@ idl.KeyedUnion where the currently valid member of the union can be determined based upon another member in the containing type. - The KeyedUnion.keyvar_name must contain the name of the member of the + The KeyedUnion.keyvar contains an idl.type the member of the containing type which determines the valid member of the union. The - member referenced by KeyedUnion.keyvar_name has type - KeyedUnion.keyvar_type which must be an instance of the Enumeration type. + must be an instance of the Enumeration type. Standard Types --------------
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 26 of 27 V4] libxl: idl: generate KeyedUnion key member as part of the KeyedUnion
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330598786 0 # Node ID cc921425fcf20b93292bf9faf22fc1d3e4f49bbd # Parent 22edfaf269f0331025c7dd725fbf1e1fdbe64c4d libxl: idl: generate KeyedUnion key member as part of the KeyedUnion Rather than specifying it twice in the IDL. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 22edfaf269f0 -r cc921425fcf2 tools/libxl/gentypes.py --- a/tools/libxl/gentypes.py Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/gentypes.py Thu Mar 01 10:46:26 2012 +0000 @@ -32,6 +32,9 @@ def libxl_C_type_define(ty, indent = "") s += "} %s" % ty.typename elif isinstance(ty, idl.Aggregate): + if isinstance(ty, idl.KeyedUnion): + s += libxl_C_instance_of(ty.keyvar.type, ty.keyvar.name) + ";\n" + if ty.typename is None: s += "%s {\n" % ty.kind else: diff -r 22edfaf269f0 -r cc921425fcf2 tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/libxl_types.idl Thu Mar 01 10:46:26 2012 +0000 @@ -237,7 +237,6 @@ libxl_domain_build_info = Struct("domain ("shadow_memkb", MemKB), ("disable_migrate", libxl_defbool), ("cpuid", libxl_cpuid_policy_list), - ("type", libxl_domain_type), ("device_model_version", libxl_device_model_version), ("device_model_stubdomain", libxl_defbool), @@ -447,7 +446,6 @@ libxl_event = Struct("event",[ ("domid", libxl_domid), ("domuuid", libxl_uuid), ("for_user", libxl_ev_user), - ("type", libxl_event_type), ("u", KeyedUnion(None, libxl_event_type, "type", [("domain_shutdown", Struct(None, [ ("shutdown_reason", uint8),
Ian Campbell
2012-Mar-01 10:50 UTC
[PATCH 27 of 27 V4] libxl: autogenerate libxl_FOO_init and libxl_FOO_init_FIELD
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1330598786 0 # Node ID 1e555d6f24352f4558689a4ae1cd41bb5b90b64a # Parent cc921425fcf20b93292bf9faf22fc1d3e4f49bbd libxl: autogenerate libxl_FOO_init and libxl_FOO_init_FIELD Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r cc921425fcf2 -r 1e555d6f2435 tools/libxl/gentypes.py --- a/tools/libxl/gentypes.py Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/gentypes.py Thu Mar 01 10:46:26 2012 +0000 @@ -78,6 +78,88 @@ def libxl_C_type_dispose(ty, v, indent s = indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) +def libxl_init_members(ty, nesting = 0): + """Returns a list of members of ty which require a separate init""" + + if isinstance(ty, idl.Aggregate): + return [f for f in ty.fields if not f.const and isinstance(f.type,idl.KeyedUnion)] + else: + return [] + +def _libxl_C_type_init(ty, v, indent = " ", parent = None, subinit=False): + s = "" + if isinstance(ty, idl.KeyedUnion): + if parent is None: + raise Exception("KeyedUnion type must have a parent") + if subinit: + s += "switch (%s) {\n" % (parent + ty.keyvar.name) + for f in ty.fields: + (nparent,fexpr) = ty.member(v, f, parent is None) + s += "case %s:\n" % f.enumname + s += _libxl_C_type_init(f.type, fexpr, " ", nparent) + s += " break;\n" + s += "}\n" + else: + if ty.keyvar.init_val: + s += "%s = %s;\n" % (parent + ty.keyvar.name, ty.keyvar.init_val) + elif ty.keyvar.type.init_val: + s += "%s = %s;\n" % (parent + ty.keyvar.name, ty.keyvar.type.init_val) + elif isinstance(ty, idl.Struct) and (parent is None or ty.init_fn is None): + for f in [f for f in ty.fields if not f.const]: + (nparent,fexpr) = ty.member(v, f, parent is None) + if f.init_val is not None: + s += "%s = %s;\n" % (fexpr, f.init_val) + else: + s += _libxl_C_type_init(f.type, fexpr, "", nparent) + else: + if ty.init_val is not None: + s += "%s = %s;\n" % (ty.pass_arg(v, parent is None), ty.init_val) + elif ty.init_fn is not None: + s += "%s(%s);\n" % (ty.init_fn, ty.pass_arg(v, parent is None)) + + if s != "": + s = indent + s + return s.replace("\n", "\n%s" % indent).rstrip(indent) + +def libxl_C_type_init(ty): + s = "" + s += "void %s(%s)\n" % (ty.init_fn, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE)) + s += "{\n" + s += " memset(p, ''\\0'', sizeof(*p));\n" + s += _libxl_C_type_init(ty, "p") + s += "}\n" + s += "\n" + return s + +def libxl_C_type_member_init(ty, field): + if not isinstance(field.type, idl.KeyedUnion): + raise Exception("Only KeyedUnion is supported for member init") + + ku = field.type + + s = "" + s += "void %s(%s, %s)\n" % (ty.init_fn + "_" + ku.keyvar.name, + ty.make_arg("p", passby=idl.PASS_BY_REFERENCE), + ku.keyvar.type.make_arg(ku.keyvar.name)) + s += "{\n" + + if ku.keyvar.init_val: + init_val = ku.keyvar.init_val + elif ku.keyvar.type.init_val: + init_val = ku.keyvar.type.init_val + else: + init_val = None + + if init_val is not None: + (nparent,fexpr) = ty.member(ty.pass_arg("p"), ku.keyvar, isref=True) + s += " assert(%s == %s);\n" % (fexpr, init_val) + s += " %s = %s;\n" % (fexpr, ku.keyvar.name) + (nparent,fexpr) = ty.member(ty.pass_arg("p"), field, isref=True) + s += _libxl_C_type_init(ku, fexpr, parent=nparent, subinit=True) + s += "}\n" + s += "\n" + return s + def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s = "" if parent is None: @@ -199,6 +281,15 @@ if __name__ == ''__main__'': f.write(libxl_C_type_define(ty) + ";\n") if ty.dispose_fn is not None: f.write("void %s(%s);\n" % (ty.dispose_fn, ty.make_arg("p"))) + if ty.init_fn is not None: + f.write("void %s(%s);\n" % (ty.init_fn, ty.make_arg("p"))) + for field in libxl_init_members(ty): + if not isinstance(field.type, idl.KeyedUnion): + raise Exception("Only KeyedUnion is supported for member init") + ku = field.type + f.write("void %s(%s, %s);\n" % (ty.init_fn + "_" + ku.keyvar.name, + ty.make_arg("p"), + ku.keyvar.type.make_arg(ku.keyvar.name))) if ty.json_fn is not None: f.write("char *%s_to_json(libxl_ctx *ctx, %s);\n" % (ty.typename, ty.make_arg("p"))) if isinstance(ty, idl.Enumeration): @@ -227,7 +318,7 @@ if __name__ == ''__main__'': """ % (header_json_define, header_json_define, " ".join(sys.argv))) - for ty in [ty for ty in types+builtins if ty.json_fn is not None]: + for ty in [ty for ty in types if ty.json_fn is not None]: f.write("yajl_gen_status %s_gen_json(yajl_gen hand, %s);\n" % (ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) f.write("\n") @@ -264,6 +355,11 @@ if __name__ == ''__main__'': f.write(" memset(p, LIBXL_DTOR_POISON, sizeof(*p));\n") f.write("}\n") f.write("\n") + + for ty in [t for t in types if t.init_fn is not None and t.autogenerate_init_fn]: + f.write(libxl_C_type_init(ty)) + for field in libxl_init_members(ty): + f.write(libxl_C_type_member_init(ty, field)) for ty in [t for t in types if isinstance(t,idl.Enumeration)]: f.write("const char *%s_to_string(%s e)\n" % (ty.typename, ty.typename)) diff -r cc921425fcf2 -r 1e555d6f2435 tools/libxl/idl.py --- a/tools/libxl/idl.py Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/idl.py Thu Mar 01 10:46:26 2012 +0000 @@ -51,6 +51,10 @@ class Type(object): self.autogenerate_dispose_fn = kwargs.setdefault(''autogenerate_dispose_fn'', True) + self.init_fn = kwargs.setdefault(''init_fn'', None) + self.init_val = kwargs.setdefault(''init_val'', None) + self.autogenerate_init_fn = kwargs.setdefault(''autogenerate_init_fn'', False) + if self.typename is not None and not self.private: self.json_fn = kwargs.setdefault(''json_fn'', self.typename + "_gen_json") else: @@ -144,12 +148,20 @@ class Field(object): self.name = name self.const = kwargs.setdefault(''const'', False) self.enumname = kwargs.setdefault(''enumname'', None) + self.init_val = kwargs.setdefault(''init_val'', None) class Aggregate(Type): """A type containing a collection of other types""" def __init__(self, kind, typename, fields, **kwargs): Type.__init__(self, typename, **kwargs) + if self.typename is not None: + self.init_fn = kwargs.setdefault(''init_fn'', self.typename + "_init") + else: + self.init_fn = kwargs.setdefault(''init_fn'', None) + + self.autogenerate_init_fn = kwargs.setdefault(''autogenerate_init_fn'', True) + self.kind = kind self.fields = [] diff -r cc921425fcf2 -r 1e555d6f2435 tools/libxl/idl.txt --- a/tools/libxl/idl.txt Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/idl.txt Thu Mar 01 10:46:26 2012 +0000 @@ -44,6 +44,22 @@ Type.autogenerate_dispose_fn: (default: Indicates if the above named Type.dispose_fn should be autogenerated. +Type.init_val: (default: None) + + C expression for the value to initialise instances of this type to. + + If present takes precendence over init_fn (see below). + +Type.init_fn: (default: typename + "_init" if dir in [IN, BOTH] and + type != None) + + The name of the C function which will initialist Type. + +Type.autogenerate_init_fn: (default: True if dir in [IN, BOTH]) + + Indicates if the above named Type.init_fn should be + autogenerated. + Type.json_fn: (default: typename + "_gen_json" or None if type == None) The name of the C function which will generate a YAJL data structure @@ -105,10 +121,13 @@ idl.Aggregate Each field has the following properties: - Field.type The type of the member (a idl.Type). - Field.name The name of the member (can be None for anonymous - fields). - Field.const Boolean, true if the member is const. + Field.type The type of the member (a idl.Type). + Field.name The name of the member (can be None for anonymous + fields). + Field.const Boolean, true if the member is const. + Field.init_val The initialisation value for this field. Takes + precendence over both Field.type.init_val and + Field.type.init_fn. idl.Struct diff -r cc921425fcf2 -r 1e555d6f2435 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/libxl.c Thu Mar 01 10:46:26 2012 +0000 @@ -1227,11 +1227,6 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, /******************************************************************************/ -void libxl_device_disk_init(libxl_device_disk *disk) -{ - memset(disk, 0x00, sizeof(libxl_device_disk)); -} - int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk) { int rc; @@ -1718,10 +1713,6 @@ int libxl_device_disk_local_detach(libxl } /******************************************************************************/ -void libxl_device_nic_init(libxl_device_nic *nic) -{ - memset(nic, ''\0'', sizeof(*nic)); -} int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic) { @@ -2142,10 +2133,6 @@ out: } /******************************************************************************/ -void libxl_device_vkb_init(libxl_device_vkb *vkb) -{ - memset(vkb, 0x00, sizeof(libxl_device_vkb)); -} int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb) { @@ -2254,10 +2241,6 @@ out: } /******************************************************************************/ -void libxl_device_vfb_init(libxl_device_vfb *vfb) -{ - memset(vfb, 0x00, sizeof(libxl_device_vfb)); -} int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb) { @@ -3067,6 +3050,8 @@ int libxl_sched_credit_domain_get(libxl_ struct xen_domctl_sched_credit sdom; int rc; + libxl_sched_credit_domain_init(scinfo); + rc = xc_sched_credit_domain_get(ctx->xch, domid, &sdom); if (rc != 0) { LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting domain sched credit"); @@ -3126,6 +3111,8 @@ int libxl_sched_credit2_domain_get(libxl struct xen_domctl_sched_credit2 sdom; int rc; + libxl_sched_credit2_domain_init(scinfo); + rc = xc_sched_credit2_domain_get(ctx->xch, domid, &sdom); if (rc != 0) { LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, @@ -3183,6 +3170,8 @@ int libxl_sched_sedf_domain_get(libxl_ct uint16_t weight; int rc; + libxl_sched_sedf_domain_init(scinfo); + rc = xc_sedf_domain_get(ctx->xch, domid, &period, &slice, &latency, &extratime, &weight); if (rc != 0) { diff -r cc921425fcf2 -r 1e555d6f2435 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/libxl.h Thu Mar 01 10:46:26 2012 +0000 @@ -381,10 +381,6 @@ int libxl_ctx_free(libxl_ctx *ctx /* 0 i int libxl_ctx_postfork(libxl_ctx *ctx); /* domain related functions */ -void libxl_domain_create_info_init(libxl_domain_create_info *c_info); -void libxl_domain_build_info_init(libxl_domain_build_info *b_info); -void libxl_domain_build_info_init_type(libxl_domain_build_info *b_info, - libxl_domain_type type); typedef int (*libxl_console_ready)(libxl_ctx *ctx, uint32_t domid, void *priv); int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid); int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, libxl_console_ready cb, void *priv, uint32_t *domid, int restore_fd); @@ -523,7 +519,6 @@ void libxl_vminfo_list_free(libxl_vminfo */ /* Disks */ -void libxl_device_disk_init(libxl_device_disk *disk); int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk); int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, @@ -549,7 +544,6 @@ char * libxl_device_disk_local_attach(li int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk); /* Network Interfaces */ -void libxl_device_nic_init(libxl_device_nic *nic); int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic); int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic, @@ -561,7 +555,6 @@ int libxl_device_nic_getinfo(libxl_ctx * libxl_device_nic *nic, libxl_nicinfo *nicinfo); /* Keyboard */ -void libxl_device_vkb_init(libxl_device_vkb *vkb); int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb); int libxl_device_vkb_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb, @@ -569,7 +562,6 @@ int libxl_device_vkb_remove(libxl_ctx *c int libxl_device_vkb_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb); /* Framebuffer */ -void libxl_device_vfb_init(libxl_device_vfb *vfb); int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb); int libxl_device_vfb_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb, @@ -577,7 +569,6 @@ int libxl_device_vfb_remove(libxl_ctx *c int libxl_device_vfb_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb); /* PCI Passthrough */ -void libxl_device_pci_init(libxl_device_pci *pci); int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev); int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev); int libxl_device_pci_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev); diff -r cc921425fcf2 -r 1e555d6f2435 tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/libxl_create.c Thu Mar 01 10:46:26 2012 +0000 @@ -50,11 +50,6 @@ void libxl_domain_config_dispose(libxl_d libxl_domain_build_info_dispose(&d_config->b_info); } -void libxl_domain_create_info_init(libxl_domain_create_info *c_info) -{ - memset(c_info, ''\0'', sizeof(*c_info)); -} - int libxl__domain_create_info_setdefault(libxl__gc *gc, libxl_domain_create_info *c_info) { @@ -69,35 +64,6 @@ int libxl__domain_create_info_setdefault return 0; } -void libxl_domain_build_info_init(libxl_domain_build_info *b_info) -{ - memset(b_info, ''\0'', sizeof(*b_info)); - b_info->type = -1; - - b_info->max_memkb = LIBXL_MEMKB_DEFAULT; - b_info->target_memkb = LIBXL_MEMKB_DEFAULT; - b_info->shadow_memkb = LIBXL_MEMKB_DEFAULT; - b_info->video_memkb = LIBXL_MEMKB_DEFAULT; - -} - -void libxl_domain_build_info_init_type(libxl_domain_build_info *b_info, - libxl_domain_type type) -{ - assert(b_info->type == -1); - b_info->type = type; - switch (b_info->type) { - case LIBXL_DOMAIN_TYPE_HVM: - b_info->u.hvm.timer_mode = LIBXL_TIMER_MODE_DEFAULT; - break; - case LIBXL_DOMAIN_TYPE_PV: - b_info->u.pv.slack_memkb = LIBXL_MEMKB_DEFAULT; - break; - default: - abort(); - } -} - int libxl__domain_build_info_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info) { diff -r cc921425fcf2 -r 1e555d6f2435 tools/libxl/libxl_json.h --- a/tools/libxl/libxl_json.h Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/libxl_json.h Thu Mar 01 10:46:26 2012 +0000 @@ -22,6 +22,20 @@ # include <yajl/yajl_version.h> #endif +yajl_gen_status libxl_defbool_gen_json(yajl_gen hand, libxl_defbool *p); +yajl_gen_status libxl_domid_gen_json(yajl_gen hand, libxl_domid *p); +yajl_gen_status libxl_uuid_gen_json(yajl_gen hand, libxl_uuid *p); +yajl_gen_status libxl_mac_gen_json(yajl_gen hand, libxl_mac *p); +yajl_gen_status libxl_cpumap_gen_json(yajl_gen hand, libxl_cpumap *p); +yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_gen hand, + libxl_cpuid_policy_list *p); +yajl_gen_status libxl_string_list_gen_json(yajl_gen hand, libxl_string_list *p); +yajl_gen_status libxl_key_value_list_gen_json(yajl_gen hand, + libxl_key_value_list *p); +yajl_gen_status libxl_file_reference_gen_json(yajl_gen hand, + libxl_file_reference *p); +yajl_gen_status libxl_hwcap_gen_json(yajl_gen hand, libxl_hwcap *p); + #include <_libxl_types_json.h> /* YAJL version check */ diff -r cc921425fcf2 -r 1e555d6f2435 tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/libxl_pci.c Thu Mar 01 10:46:26 2012 +0000 @@ -765,11 +765,6 @@ static int libxl__device_pci_reset(libxl return -1; } -void libxl_device_pci_init(libxl_device_pci *pci) -{ - memset(pci, ''\0'', sizeof(*pci)); -} - int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci) { return 0; diff -r cc921425fcf2 -r 1e555d6f2435 tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/libxl_types.idl Thu Mar 01 10:46:26 2012 +0000 @@ -100,7 +100,7 @@ libxl_timer_mode = Enumeration("timer_mo (1, "no_delay_for_missed_ticks"), (2, "no_missed_ticks_pending"), (3, "one_missed_tick_pending"), - ]) + ], init_val = "LIBXL_TIMER_MODE_DEFAULT") libxl_bios_type = Enumeration("bios_type", [ (1, "rombios"), @@ -180,19 +180,19 @@ libxl_dominfo = Struct("dominfo",[ ("vcpu_max_id", uint32), ("vcpu_online", uint32), ("cpupool", uint32), - ]) + ], dir=DIR_OUT) libxl_cpupoolinfo = Struct("cpupoolinfo", [ ("poolid", uint32), ("sched", libxl_scheduler), ("n_dom", uint32), ("cpumap", libxl_cpumap) - ]) + ], dir=DIR_OUT) libxl_vminfo = Struct("vminfo", [ ("uuid", libxl_uuid), ("domid", libxl_domid), - ]) + ], dir=DIR_OUT) libxl_version_info = Struct("version_info", [ ("xen_version_major", integer), @@ -207,7 +207,7 @@ libxl_version_info = Struct("version_inf ("virt_start", uint64), ("pagesize", integer), ("commandline", string), - ]) + ], dir=DIR_OUT) libxl_domain_create_info = Struct("domain_create_info",[ ("type", libxl_domain_type), @@ -219,7 +219,9 @@ libxl_domain_create_info = Struct("domai ("xsdata", libxl_key_value_list), ("platformdata", libxl_key_value_list), ("poolid", uint32), - ]) + ], dir=DIR_IN) + +MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT") # Instances of libxl_file_reference contained in this struct which # have been mapped (with libxl_file_reference_map) will be unmapped @@ -297,8 +299,8 @@ libxl_domain_build_info = Struct("domain # Use host''s E820 for PCI passthrough. ("e820_host", libxl_defbool), ])), - ])), - ], + ], keyvar_init_val = "-1")), + ], dir=DIR_IN ) libxl_device_vfb = Struct("device_vfb", [ @@ -360,7 +362,7 @@ libxl_diskinfo = Struct("diskinfo", [ ("state", integer), ("evtch", integer), ("rref", integer), - ]) + ], dir=DIR_OUT) libxl_nicinfo = Struct("nicinfo", [ ("backend", string), @@ -372,7 +374,7 @@ libxl_nicinfo = Struct("nicinfo", [ ("evtch", integer), ("rref_tx", integer), ("rref_rx", integer), - ]) + ], dir=DIR_OUT) libxl_vcpuinfo = Struct("vcpuinfo", [ ("vcpuid", uint32), @@ -382,7 +384,7 @@ libxl_vcpuinfo = Struct("vcpuinfo", [ ("running", bool), ("vcpu_time", uint64), # total vcpu time ran (ns) ("cpumap", libxl_cpumap), # current cpu''s affinities - ]) + ], dir=DIR_OUT) libxl_physinfo = Struct("physinfo", [ ("threads_per_core", uint32), @@ -409,7 +411,7 @@ libxl_cputopology = Struct("cputopology" ("core", uint32), ("socket", uint32), ("node", uint32), - ]) + ], dir=DIR_OUT) libxl_sched_credit_domain = Struct("sched_credit_domain", [ ("weight", integer), diff -r cc921425fcf2 -r 1e555d6f2435 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Mar 01 10:46:26 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Thu Mar 01 10:46:26 2012 +0000 @@ -3922,6 +3922,7 @@ static int sched_credit_domain_set( { int rc; + rc = libxl_sched_credit_domain_set(ctx, domid, scinfo); if (rc) fprintf(stderr, "libxl_sched_credit_domain_set failed.\n"); @@ -3950,6 +3951,7 @@ static int sched_credit_domain_output( scinfo.weight, scinfo.cap); free(domname); + libxl_sched_credit_domain_dispose(&scinfo); return 0; } @@ -3997,6 +3999,7 @@ static int sched_credit2_domain_output( domid, scinfo.weight); free(domname); + libxl_sched_credit2_domain_dispose(&scinfo); return 0; } @@ -4020,7 +4023,6 @@ static int sched_sedf_domain_set( rc = libxl_sched_sedf_domain_set(ctx, domid, scinfo); if (rc) fprintf(stderr, "libxl_sched_sedf_domain_set failed.\n"); - return rc; } @@ -4049,6 +4051,7 @@ static int sched_sedf_domain_output( scinfo.extratime, scinfo.weight); free(domname); + libxl_sched_sedf_domain_dispose(&scinfo); return 0; } @@ -4181,6 +4184,7 @@ int main_sched_credit(int argc, char **a if (opt_c) scinfo.cap = cap; rc = sched_credit_domain_set(domid, &scinfo); + libxl_sched_credit_domain_dispose(&scinfo); if (rc) return -rc; } @@ -4255,6 +4259,7 @@ int main_sched_credit2(int argc, char ** if (opt_w) scinfo.weight = weight; rc = sched_credit2_domain_set(domid, &scinfo); + libxl_sched_credit2_domain_dispose(&scinfo); if (rc) return -rc; } @@ -4373,6 +4378,7 @@ int main_sched_sedf(int argc, char **arg scinfo.slice = 0; } rc = sched_sedf_domain_set(domid, &scinfo); + libxl_sched_sedf_domain_dispose(&scinfo); if (rc) return -rc; }
Attilio Rao
2012-Mar-01 11:45 UTC
Re: [PATCH 21 of 27 V4] libxl: Select BIOS using libxl_domain_build_info_setdefaults
On 01/03/12 10:50, Ian Campbell wrote:> # HG changeset patch > # User Ian Campbell<ian.campbell@citrix.com> > # Date 1330598783 0 > # Node ID a884dc50100119da3e767ebe243f3e978981670f > # Parent f2fc55636c0153df5bca389156b984eb1f10b59c > libxl: Select BIOS using libxl_domain_build_info_setdefaults > > Remove libxl__domain_bios -- it is no longer necessary. > > Also we appear to have been setting the xenstore key even for device models for > PV guests -- stop doing that. > > Signed-off-by: Ian Campbell<ian.campbell@citrix.com> > >This patch looks good to me. Attilio
Ian Jackson
2012-Mar-01 12:53 UTC
Re: [PATCH 00 of 27 V4] libxl: improved handling for default values in API
Ian Campbell writes ("[Xen-devel] [PATCH 00 of 27 V4] libxl: improved handling for default values in API"):> Introduce a mechanism for users of libxl to explicitly say "pick the > default for me".Thanks, I have applied all of these. Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Ian.