[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] Merge
# HG changeset patch # User Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> # Date 1330605075 0 # Node ID d64aa013a82e591f628abd7a2cac7cc82da41a4f # Parent d7fe4cd831a0d8d7b3cd71ca302ca0280e3a5096 # Parent 17bfd4d2ffce56b65e7849a5779471ef4f5e4aea Merge --- diff -r d7fe4cd831a0 -r d64aa013a82e tools/libxl/gentest.py --- a/tools/libxl/gentest.py Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/gentest.py Thu Mar 01 12:31:15 2012 +0000 @@ -1,5 +1,6 @@ #!/usr/bin/python +import os import sys import re import random @@ -30,7 +31,7 @@ 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 @@ -54,6 +55,8 @@ 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: @@ -72,7 +75,7 @@ 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]) @@ -196,6 +199,7 @@ } """) 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/gentypes.py --- a/tools/libxl/gentypes.py Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/gentypes.py Thu Mar 01 12:31:15 2012 +0000 @@ -32,6 +32,9 @@ 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: @@ -56,7 +59,7 @@ 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 @@ -75,6 +78,88 @@ 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: @@ -86,7 +171,7 @@ 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 @@ -196,6 +281,15 @@ 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): @@ -224,7 +318,7 @@ """ % (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") @@ -261,6 +355,11 @@ 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/idl.py --- a/tools/libxl/idl.py Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/idl.py Thu Mar 01 12:31:15 2012 +0000 @@ -51,6 +51,10 @@ 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 @@ 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 = [] @@ -206,8 +218,9 @@ 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/idl.txt --- a/tools/libxl/idl.txt Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/idl.txt Thu Mar 01 12:31:15 2012 +0000 @@ -44,6 +44,22 @@ 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 @@ 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 @@ -128,10 +147,9 @@ 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 -------------- diff -r d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl.c Thu Mar 01 12:31:15 2012 +0000 @@ -184,6 +184,47 @@ 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>"; +} + /******************************************************************************/ @@ -442,6 +483,7 @@ 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 +506,8 @@ } if (ret==0 || xcinfo.domain != domid) return ERROR_INVAL; - xcinfo2xlinfo(&xcinfo, info_r); + if (info_r) + xcinfo2xlinfo(&xcinfo, info_r); return 0; } @@ -491,7 +534,7 @@ } 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); @@ -986,13 +1029,12 @@ 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; @@ -1185,10 +1227,14 @@ /******************************************************************************/ -int libxl_device_disk_init(libxl_ctx *ctx, libxl_device_disk *disk) +int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk) { - memset(disk, 0x00, sizeof(libxl_device_disk)); - return 0; + 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, @@ -1240,10 +1286,7 @@ 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); @@ -1395,7 +1438,7 @@ 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); @@ -1439,7 +1482,7 @@ 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) { @@ -1603,7 +1646,7 @@ 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) { @@ -1670,32 +1713,39 @@ } /******************************************************************************/ -int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic) + +int libxl__device_nic_setdefault(libxl__gc *gc, 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 ) + 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; } @@ -1722,6 +1772,9 @@ 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; @@ -2002,7 +2055,7 @@ /******************************************************************************/ 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; @@ -2049,7 +2102,7 @@ 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"); @@ -2080,9 +2133,9 @@ } /******************************************************************************/ -int libxl_device_vkb_init(libxl_ctx *ctx, libxl_device_vkb *vkb) + +int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb) { - memset(vkb, 0x00, sizeof(libxl_device_vkb)); return 0; } @@ -2108,6 +2161,9 @@ 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; @@ -2185,19 +2241,24 @@ } /******************************************************************************/ -int libxl_device_vfb_init(libxl_ctx *ctx, libxl_device_vfb *vfb) + +int libxl__device_vfb_setdefault(libxl__gc *gc, 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; - vfb->sdl.enable = 0; - vfb->sdl.opengl = 0; - vfb->sdl.display = NULL; - vfb->sdl.xauthority = NULL; + 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; } @@ -2222,6 +2283,9 @@ 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; @@ -2241,17 +2305,17 @@ 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); } @@ -2624,18 +2688,23 @@ 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: *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: *need_memkb += b_info->shadow_memkb + LIBXL_PV_EXTRA_MEMORY; break; default: + rc = ERROR_INVAL; goto out; } if (*need_memkb % (2 * 1024)) @@ -2750,7 +2819,10 @@ 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 +3033,11 @@ 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; } @@ -2981,6 +3050,8 @@ 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"); @@ -3040,6 +3111,8 @@ 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, @@ -3097,6 +3170,8 @@ 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) { @@ -3443,7 +3518,8 @@ 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 +3535,7 @@ 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl.h Thu Mar 01 12:31:15 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 @@ -137,9 +181,6 @@ #include <xentoollog.h> -#include <xen/sched.h> -#include <xen/sysctl.h> - #include <libxl_uuid.h> #include <_libxl_list.h> @@ -202,9 +243,34 @@ 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 LIBXL_TIMER_MODE_NO_DELAY_FOR_MISSED_TICKS +#define LIBXL_TIMER_MODE_DEFAULT -1 +#define LIBXL_MEMKB_DEFAULT ~0ULL #include "_libxl_types.h" @@ -315,10 +381,6 @@ int libxl_ctx_postfork(libxl_ctx *ctx); /* domain related functions */ -int libxl_init_create_info(libxl_ctx *ctx, 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); 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); @@ -390,11 +452,14 @@ * 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 @@ -405,8 +470,9 @@ * 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 +490,6 @@ * 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 @@ -457,7 +519,6 @@ */ /* Disks */ -int libxl_device_disk_init(libxl_ctx *ctx, 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, @@ -483,7 +544,6 @@ 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); 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, @@ -495,7 +555,6 @@ libxl_device_nic *nic, libxl_nicinfo *nicinfo); /* Keyboard */ -int libxl_device_vkb_init(libxl_ctx *ctx, 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, @@ -503,7 +562,6 @@ 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); 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, @@ -511,7 +569,6 @@ 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); 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); @@ -584,7 +641,7 @@ 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 +684,8 @@ 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); @@ -638,12 +696,7 @@ 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_bootloader.c --- a/tools/libxl/libxl_bootloader.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_bootloader.c Thu Mar 01 12:31:15 2012 +0000 @@ -346,9 +346,15 @@ 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; + rc = libxl__domain_build_info_setdefault(gc, info); + if (rc) goto out; + rc = ERROR_INVAL; if (!disk) goto out; diff -r d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_create.c --- a/tools/libxl/libxl_create.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_create.c Thu Mar 01 12:31:15 2012 +0000 @@ -50,79 +50,141 @@ libxl_domain_build_info_dispose(&d_config->b_info); } -int libxl_init_create_info(libxl_ctx *ctx, libxl_domain_create_info *c_info) +int libxl__domain_create_info_setdefault(libxl__gc *gc, + 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; + 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; } -int libxl_init_build_info(libxl_ctx *ctx, - libxl_domain_build_info *b_info, - libxl_domain_create_info *c_info) +int libxl__domain_build_info_setdefault(libxl__gc *gc, + libxl_domain_build_info *b_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; - b_info->cpuid = NULL; - b_info->shadow_memkb = 0; - b_info->type = c_info->type; + if (!b_info->device_model_version) + b_info->device_model_version = + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; - b_info->device_model_version = - LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; - b_info->device_model_stubdomain = false; - b_info->device_model = NULL; + 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(); + } + + 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) + 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); + } + + 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; + + libxl_defbool_setdefault(&b_info->disable_migrate, false); 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; - 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 = 1; - b_info->u.hvm.nested_hvm = 0; - b_info->u.hvm.no_incr_generationid = 0; + 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; - 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; + 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.incr_generationid, 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; + } + + 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: - b_info->u.pv.slack_memkb = 8 * 1024; + 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) + b_info->u.pv.slack_memkb = 0; break; default: - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, + LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "invalid domain type %s in create info", libxl_domain_type_to_string(b_info->type)); return ERROR_INVAL; @@ -130,17 +192,16 @@ 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, @@ -172,11 +233,11 @@ 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: @@ -320,8 +381,8 @@ 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; @@ -378,7 +439,6 @@ 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)); @@ -470,6 +530,12 @@ domid = 0; + 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); @@ -482,9 +548,11 @@ 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]); + ret = libxl__device_disk_setdefault(gc, &d_config->disks[i]); if (ret) goto error_out; } @@ -534,18 +602,16 @@ 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); - 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); @@ -561,7 +627,7 @@ 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]); @@ -577,10 +643,10 @@ 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); @@ -619,7 +685,7 @@ } 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_dm.c --- a/tools/libxl/libxl_dm.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_dm.c Thu Mar 01 12:31:15 2012 +0000 @@ -39,7 +39,7 @@ 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) { @@ -63,18 +63,6 @@ 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; @@ -83,7 +71,7 @@ } 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 +82,7 @@ } 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 +144,13 @@ 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 +165,7 @@ 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,14 +175,14 @@ 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"); } 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 +192,7 @@ 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) { @@ -240,7 +228,7 @@ 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 +281,7 @@ 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 +297,12 @@ 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 +371,7 @@ 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 +399,11 @@ 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 +413,7 @@ 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); } @@ -433,7 +421,7 @@ 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 +431,7 @@ 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) { @@ -485,7 +473,7 @@ 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 { @@ -616,8 +604,8 @@ 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; @@ -688,7 +676,7 @@ { 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; @@ -705,7 +693,7 @@ 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)); @@ -713,13 +701,13 @@ 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); + 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; 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); @@ -740,6 +728,11 @@ 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; + 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; dm_config.num_vfbs = 1; @@ -816,7 +809,7 @@ 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; @@ -824,7 +817,7 @@ 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 @@ -907,7 +900,7 @@ 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; } @@ -929,10 +922,13 @@ 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); @@ -941,7 +937,7 @@ 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), @@ -1088,7 +1084,7 @@ } 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) { @@ -1100,7 +1096,7 @@ } 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_dom.c --- a/tools/libxl/libxl_dom.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_dom.c Thu Mar 01 12:31:15 2012 +0000 @@ -88,7 +88,7 @@ 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) { @@ -129,11 +129,12 @@ 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"; @@ -291,7 +292,7 @@ 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++) @@ -301,14 +302,19 @@ 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); @@ -399,8 +405,8 @@ case LIBXL_DOMAIN_TYPE_HVM: hvm = 1; superpages = 1; - pae = info->u.hvm.pae; - no_incr_generationid = info->u.hvm.no_incr_generationid; + pae = libxl_defbool_val(info->u.hvm.pae); + no_incr_generationid = !libxl_defbool_val(info->u.hvm.incr_generationid); break; case LIBXL_DOMAIN_TYPE_PV: hvm = 0; diff -r d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_internal.h Thu Mar 01 12:31:15 2012 +0000 @@ -187,6 +187,16 @@ * 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); +_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); +_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; @@ -652,7 +662,7 @@ 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, @@ -665,6 +675,19 @@ _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 @@ -882,7 +905,7 @@ 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_json.c --- a/tools/libxl/libxl_json.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_json.c Thu Mar 01 12:31:15 2012 +0000 @@ -85,6 +85,12 @@ /* * 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_json.h --- a/tools/libxl/libxl_json.h Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_json.h Thu Mar 01 12:31:15 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_pci.c --- a/tools/libxl/libxl_pci.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_pci.c Thu Mar 01 12:31:15 2012 +0000 @@ -765,6 +765,11 @@ return -1; } +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 +787,9 @@ 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"); @@ -1365,7 +1373,7 @@ 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_types.idl Thu Mar 01 12:31:15 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) @@ -18,6 +20,12 @@ libxl_hwcap = Builtin("hwcap", passby=PASS_BY_REFERENCE) # +# Specific integer types +# + +MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT") + +# # Constants / Enumerations # @@ -36,11 +44,6 @@ (2, "PV"), ]) -libxl_console_backend = Enumeration("console_backend", [ - (1, "XENCONSOLED"), - (2, "IOEMU"), - ]) - libxl_disk_format = Enumeration("disk_format", [ (0, "UNKNOWN"), (1, "QCOW"), @@ -97,7 +100,7 @@ (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"), @@ -105,35 +108,52 @@ (3, "ovmf"), ]) +# Consistent with values defined in domctl.h +libxl_scheduler = Enumeration("scheduler", [ + (4, "sedf"), + (5, "credit"), + (6, "credit2"), + (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 # 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), ]) @@ -148,31 +168,31 @@ ("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), - ("current_memkb", uint64), - ("shared_memkb", uint64), - ("max_memkb", uint64), + # LIBXL_SHUTDOWN_REASON_* constant. + ("shutdown_reason", libxl_shutdown_reason), + ("current_memkb", MemKB), + ("shared_memkb", MemKB), + ("max_memkb", MemKB), ("cpu_time", uint64), ("vcpu_max_id", uint32), ("vcpu_online", uint32), ("cpupool", uint32), - ], dispose_fn=None) + ], dir=DIR_OUT) libxl_cpupoolinfo = Struct("cpupoolinfo", [ ("poolid", uint32), - ("sched_id", uint32), + ("sched", libxl_scheduler), ("n_dom", uint32), ("cpumap", libxl_cpumap) - ]) + ], dir=DIR_OUT) libxl_vminfo = Struct("vminfo", [ ("uuid", libxl_uuid), ("domid", libxl_domid), - ], dispose_fn=None) + ], dir=DIR_OUT) libxl_version_info = Struct("version_info", [ ("xen_version_major", integer), @@ -187,19 +207,21 @@ ("virt_start", uint64), ("pagesize", integer), ("commandline", string), - ]) + ], dir=DIR_OUT) 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), ("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 @@ -211,17 +233,16 @@ ("cur_vcpus", integer), ("cpumap", libxl_cpumap), ("tsc_mode", libxl_tsc_mode), - ("max_memkb", uint32), - ("target_memkb", uint32), - ("video_memkb", uint32), - ("shadow_memkb", uint32), - ("disable_migrate", bool), + ("max_memkb", MemKB), + ("target_memkb", MemKB), + ("video_memkb", MemKB), + ("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", 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), @@ -233,53 +254,53 @@ ("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), - ("no_incr_generationid", bool), - ("nographic", bool), - ("stdvga", 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), + ("incr_generationid",libxl_defbool), + ("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), - ("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", uint32), + ("slack_memkb", MemKB), ("bootloader", string), ("bootloader_args", libxl_string_list), ("cmdline", string), ("ramdisk", libxl_file_reference), ("features", string, {'const': True}), # Use host's E820 for PCI passthrough. - ("e820_host", bool), + ("e820_host", libxl_defbool), ])), - ])), - ], + ], keyvar_init_val = "-1")), + ], dir=DIR_IN ) libxl_device_vfb = Struct("device_vfb", [ @@ -296,13 +317,6 @@ ("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), @@ -348,7 +362,7 @@ ("state", integer), ("evtch", integer), ("rref", integer), - ]) + ], dir=DIR_OUT) libxl_nicinfo = Struct("nicinfo", [ ("backend", string), @@ -360,7 +374,7 @@ ("evtch", integer), ("rref_tx", integer), ("rref_rx", integer), - ]) + ], dir=DIR_OUT) libxl_vcpuinfo = Struct("vcpuinfo", [ ("vcpuid", uint32), @@ -370,7 +384,7 @@ ("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), @@ -388,23 +402,25 @@ ("nr_nodes", uint32), ("hw_cap", libxl_hwcap), - ("phys_cap", uint32), - ], dispose_fn=None, dir=DIR_OUT) + + ("cap_hvm", bool), + ("cap_hvm_directio", bool), + ], dir=DIR_OUT) libxl_cputopology = Struct("cputopology", [ ("core", uint32), ("socket", uint32), ("node", uint32), - ]) + ], dir=DIR_OUT) 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), @@ -412,7 +428,7 @@ ("latency", integer), ("extratime", integer), ("weight", integer), - ], dispose_fn=None) + ]) libxl_event_type = Enumeration("event_type", [ (1, "DOMAIN_SHUTDOWN"), @@ -432,7 +448,6 @@ ("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), diff -r d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_types_internal.idl --- a/tools/libxl/libxl_types_internal.idl Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_types_internal.idl Thu Mar 01 12:31:15 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 @@ (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), + ]) diff -r d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_utils.c Thu Mar 01 12:31:15 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 @@ 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); @@ -541,6 +507,29 @@ 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 + * does not check whether the domain actually exists */ + return domid > 0 && domid < DOMID_FIRST_RESERVED; +} + /* * Local variables: * mode: C diff -r d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxl_utils.h --- a/tools/libxl/libxl_utils.h Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxl_utils.h Thu Mar 01 12:31:15 2012 +0000 @@ -24,8 +24,6 @@ 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxlu_cfg.c --- a/tools/libxl/libxlu_cfg.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxlu_cfg.c Thu Mar 01 12:31:15 2012 +0000 @@ -237,6 +237,17 @@ 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/libxlutil.h --- a/tools/libxl/libxlutil.h Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/libxlutil.h Thu Mar 01 12:31:15 2012 +0000 @@ -52,6 +52,8 @@ 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 d7fe4cd831a0 -r d64aa013a82e tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Thu Mar 01 12:31:15 2012 +0000 @@ -144,7 +144,6 @@ 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 @@ 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; @@ -383,7 +382,7 @@ { int e; - libxl_device_disk_init(ctx, disk); + libxl_device_disk_init(disk); if (!*config) { *config = xlu_cfg_init(stderr, "command line"); @@ -536,8 +535,7 @@ 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), @@ -557,8 +555,7 @@ !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"); @@ -574,8 +571,7 @@ 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; @@ -586,8 +582,8 @@ exit(1); } - if (libxl_init_build_info(ctx, b_info, c_info)) - exit(1); + 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)) { @@ -601,6 +597,11 @@ 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); @@ -615,6 +616,11 @@ 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); @@ -666,8 +672,7 @@ : 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); @@ -695,7 +700,7 @@ 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. " @@ -709,24 +714,16 @@ 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); @@ -751,8 +748,7 @@ } } - 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: { @@ -837,7 +833,7 @@ 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) { @@ -933,12 +929,12 @@ 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, ","); @@ -951,7 +947,7 @@ 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); @@ -961,14 +957,14 @@ } 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); @@ -992,19 +988,10 @@ /* 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; @@ -1014,7 +1001,7 @@ 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; @@ -1022,7 +1009,7 @@ 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)) { @@ -1139,8 +1126,8 @@ } } 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)) { @@ -1177,49 +1164,43 @@ #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); - 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); @@ -1235,19 +1216,19 @@ 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: @@ -1371,7 +1352,7 @@ 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) @@ -1622,8 +1603,8 @@ } 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); @@ -2505,7 +2486,7 @@ 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, @@ -2898,7 +2879,7 @@ 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) { @@ -3023,6 +3004,7 @@ 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) @@ -3302,7 +3284,10 @@ 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; } @@ -3405,6 +3390,7 @@ 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) @@ -3565,8 +3551,7 @@ 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 +3563,7 @@ } } vcpulist_out: - ; + libxl_physinfo_dispose(&physinfo); } int main_vcpulist(int argc, char **argv) @@ -3693,15 +3678,15 @@ 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 +3694,7 @@ 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 +3742,9 @@ 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); @@ -3778,6 +3763,7 @@ free(cpumap.map); } + libxl_physinfo_dispose(&info); return; } @@ -3912,7 +3898,9 @@ 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; } @@ -3934,6 +3922,7 @@ { int rc; + rc = libxl_sched_credit_domain_set(ctx, domid, scinfo); if (rc) fprintf(stderr, "libxl_sched_credit_domain_set failed.\n"); @@ -3962,6 +3951,7 @@ scinfo.weight, scinfo.cap); free(domname); + libxl_sched_credit_domain_dispose(&scinfo); return 0; } @@ -4009,6 +3999,7 @@ domid, scinfo.weight); free(domname); + libxl_sched_credit2_domain_dispose(&scinfo); return 0; } @@ -4032,7 +4023,6 @@ rc = libxl_sched_sedf_domain_set(ctx, domid, scinfo); if (rc) fprintf(stderr, "libxl_sched_sedf_domain_set failed.\n"); - return rc; } @@ -4061,11 +4051,12 @@ scinfo.extratime, scinfo.weight); free(domname); + libxl_sched_sedf_domain_dispose(&scinfo); return 0; } 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 +4085,7 @@ } 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 +4166,7 @@ } 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); @@ -4193,6 +4184,7 @@ if (opt_c) scinfo.cap = cap; rc = sched_credit_domain_set(domid, &scinfo); + libxl_sched_credit_domain_dispose(&scinfo); if (rc) return -rc; } @@ -4251,7 +4243,7 @@ } 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); @@ -4267,6 +4259,7 @@ if (opt_w) scinfo.weight = weight; rc = sched_credit2_domain_set(domid, &scinfo); + libxl_sched_credit2_domain_dispose(&scinfo); if (rc) return -rc; } @@ -4353,7 +4346,7 @@ } 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); @@ -4385,6 +4378,7 @@ scinfo.slice = 0; } rc = sched_sedf_domain_set(domid, &scinfo); + libxl_sched_sedf_domain_dispose(&scinfo); if (rc) return -rc; } @@ -4602,7 +4596,7 @@ 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)) { @@ -4968,6 +4962,7 @@ 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) @@ -5292,9 +5287,8 @@ 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 +5383,16 @@ } 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 +5460,14 @@ 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 +5552,7 @@ } 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 +5737,7 @@ int c; int n; uint32_t poolid; - int schedid; + libxl_scheduler sched; int n_pools; int node; int n_cpus; @@ -5765,7 +5758,7 @@ 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 +5838,7 @@ 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; diff -r d7fe4cd831a0 -r d64aa013a82e tools/libxl/xl_sxp.c --- a/tools/libxl/xl_sxp.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/libxl/xl_sxp.c Thu Mar 01 12:31:15 2012 +0000 @@ -21,6 +21,7 @@ #include "libxl_osdeps.h" #include <stdlib.h> +#include <inttypes.h> #include "libxl.h" #include "libxl_utils.h" @@ -40,8 +41,8 @@ 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); @@ -68,9 +69,10 @@ 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(nomigrate %d)\n", b_info->disable_migrate); + printf("\t(max_memkb %"PRId64")\n", b_info->max_memkb); + printf("\t(target_memkb %"PRId64")\n", b_info->target_memkb); + 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; @@ -88,43 +90,57 @@ 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(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(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 %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(no_incr_generationid %d)\n", - b_info->u.hvm.no_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(nestedhvm %s)\n", + 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 %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 %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; @@ -133,7 +149,8 @@ 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: @@ -195,13 +212,17 @@ 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"); diff -r d7fe4cd831a0 -r d64aa013a82e tools/ocaml/libs/xl/genwrap.py --- a/tools/ocaml/libs/xl/genwrap.py Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/ocaml/libs/xl/genwrap.py Thu Mar 01 12:31:15 2012 +0000 @@ -10,6 +10,7 @@ "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 d7fe4cd831a0 -r d64aa013a82e tools/ocaml/libs/xl/xenlight_stubs.c --- a/tools/ocaml/libs/xl/xenlight_stubs.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/ocaml/libs/xl/xenlight_stubs.c Thu Mar 01 12:31:15 2012 +0000 @@ -195,6 +195,33 @@ 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 d7fe4cd831a0 -r d64aa013a82e tools/python/genwrap.py --- a/tools/python/genwrap.py Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/python/genwrap.py Thu Mar 01 12:31:15 2012 +0000 @@ -4,11 +4,13 @@ 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 @@ 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 @@ 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 @@ 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 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 d7fe4cd831a0 -r d64aa013a82e tools/python/xen/lowlevel/xl/xl.c --- a/tools/python/xen/lowlevel/xl/xl.c Wed Feb 29 17:01:41 2012 +0000 +++ b/tools/python/xen/lowlevel/xl/xl.c Thu Mar 01 12:31:15 2012 +0000 @@ -156,6 +156,21 @@ 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; @@ -762,11 +777,11 @@ 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); } _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |