[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH V5 02/32] xl / libxl: push parsing of SSID and CPU pool ID down to libxl
This patch pushes parsing of "init_seclabel", "seclabel", "device_model_stubdomain_seclabel" and "pool" down to libxl level. Originally the parsing is done in xl level, which is not ideal because libxl won't have the truely relevant information. With this patch libxl holds important information by itself. This is useful when we do serialization and deserialization of domain configurations on libxl level. The libxl IDL is extended to hold the string of labels and pool name. And if there those strings are present they take precedence over the numeric representations. As all relevant structures have a field called X_name / X_label now, a string is also copied there so that we can use it directly. In order to be compatible with users of older versions of libxl, this patch also defines LIBXL_HAVE_SSID_LABEL and LIBXL_HAVE_CPUPOOL_NAME. If they are defined, the respective strings are available. And if those strings are not NULL, libxl will do the parsing and ignore the numeric values. Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> Cc: Dario Faggioli <dario.faggioli@xxxxxxxxxx> Cc: Juergen Gross <juergen.gross@xxxxxxxxxxxxxx> Cc: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx> --- tools/libxl/libxl.c | 19 ++++++-- tools/libxl/libxl.h | 24 ++++++++++ tools/libxl/libxl_create.c | 57 +++++++++++++++++++++++ tools/libxl/libxl_dm.c | 4 ++ tools/libxl/libxl_types.idl | 6 +++ tools/libxl/xl_cmdimpl.c | 107 ++++++++++++------------------------------- tools/libxl/xl_sxp.c | 7 +-- 7 files changed, 138 insertions(+), 86 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index d59ce0c..a89f5fa 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -520,12 +520,18 @@ int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, return 0; } -static void xcinfo2xlinfo(const xc_domaininfo_t *xcinfo, +static void xcinfo2xlinfo(libxl_ctx *ctx, + const xc_domaininfo_t *xcinfo, libxl_dominfo *xlinfo) { + size_t size; + memcpy(&(xlinfo->uuid), xcinfo->handle, sizeof(xen_domain_handle_t)); xlinfo->domid = xcinfo->domain; xlinfo->ssidref = xcinfo->ssidref; + if (libxl_flask_sid_to_context(ctx, xlinfo->ssidref, + &xlinfo->ssid_label, &size) < 0) + xlinfo->ssid_label = NULL; xlinfo->dying = !!(xcinfo->flags&XEN_DOMINF_dying); xlinfo->shutdown = !!(xcinfo->flags&XEN_DOMINF_shutdown); @@ -572,7 +578,7 @@ libxl_dominfo * libxl_list_domain(libxl_ctx *ctx, int *nb_domain_out) } for (i = 0; i < ret; i++) { - xcinfo2xlinfo(&info[i], &ptr[i]); + xcinfo2xlinfo(ctx, &info[i], &ptr[i]); } *nb_domain_out = ret; return ptr; @@ -591,7 +597,7 @@ int libxl_domain_info(libxl_ctx *ctx, libxl_dominfo *info_r, if (ret==0 || xcinfo.domain != domid) return ERROR_INVAL; if (info_r) - xcinfo2xlinfo(&xcinfo, info_r); + xcinfo2xlinfo(ctx, &xcinfo, info_r); return 0; } @@ -619,6 +625,11 @@ static int cpupool_info(libxl__gc *gc, } info->poolid = xcinfo->cpupool_id; + info->pool_name = libxl_cpupoolid_to_name(CTX, info->poolid); + if (!info->pool_name) { + rc = ERROR_NOMEM; + goto out; + } info->sched = xcinfo->sched_id; info->n_dom = xcinfo->n_dom; rc = libxl_cpu_bitmap_alloc(CTX, &info->cpumap, 0); @@ -4160,7 +4171,7 @@ retry_transaction: abort_transaction = 1; goto out; } - xcinfo2xlinfo(&info, &ptr); + xcinfo2xlinfo(ctx, &info, &ptr); uuid = libxl__uuid2string(gc, ptr.uuid); libxl__xs_write(gc, t, libxl__sprintf(gc, "/vm/%s/memory", uuid), "%"PRIu32, new_target_memkb / 1024); diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 84f9c0e..2b06094 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -469,6 +469,30 @@ #define LIBXL_EXTERNAL_CALLERS_ONLY /* disappears for callers outside libxl */ #endif +/* + * LIBXL_HAVE_SSID_LABEL + * + * If this is defined, then libxl IDL contains string of XSM security + * label in all XSM related structures. + * + * If this string is not NULL, libxl will overwrite the numeric + * representation of this configuration regardless if it has been + * set by the caller, because libxl will do the parsing by itself. + */ +#define LIBXL_HAVE_SSID_LABEL 1 + +/* + * LIBXL_HAVE_CPUPOOL_NAME + * + * If this is defined, then libxl IDL contains string of CPU pool + * name in all CPU pool related structures. + * + * If this string is not NULL, libxl will overwrite the numeric + * representation of this configuration regardless if it has been + * set by the caller, because libxl will do the parsing by itself. + */ +#define LIBXL_HAVE_CPUPOOL_NAME 1 + typedef uint8_t libxl_mac[6]; #define LIBXL_MAC_FMT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx" #define LIBXL_MAC_FMTLEN ((2*6)+5) /* 6 hex bytes plus 5 colons */ diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index d015cf4..fe3bdd2 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -724,6 +724,63 @@ static void initiate_domain_create(libxl__egc *egc, domid = 0; + if (d_config->c_info.ssid_label) { + char *s = d_config->c_info.ssid_label; + ret = libxl_flask_context_to_sid(ctx, s, strlen(s), + &d_config->c_info.ssidref); + if (ret) { + if (errno == ENOSYS) { + LOG(WARN, "XSM Disabled: init_seclabel not supported"); + ret = 0; + } else { + LOG(ERROR, "Invalid init_seclabel: %s", s); + goto error_out; + } + } + } + + if (d_config->b_info.exec_ssid_label) { + char *s = d_config->b_info.exec_ssid_label; + ret = libxl_flask_context_to_sid(ctx, s, strlen(s), + &d_config->b_info.exec_ssidref); + if (ret) { + if (errno == ENOSYS) { + LOG(WARN, "XSM Disabled: seclabel not supported"); + ret = 0; + } else { + LOG(ERROR, "Invalid seclabel: %s", s); + goto error_out; + } + } + } + + if (d_config->b_info.device_model_ssid_label) { + char *s = d_config->b_info.device_model_ssid_label; + ret = libxl_flask_context_to_sid(ctx, s, strlen(s), + &d_config->b_info.device_model_ssidref); + if (ret) { + if (errno == ENOSYS) { + LOG(WARN,"XSM Disabled: device_model_stubdomain_seclabel not supported"); + ret = 0; + } else { + LOG(ERROR, "Invalid device_model_stubdomain_seclabel: %s", s); + goto error_out; + } + } + } + + if (d_config->c_info.pool_name) { + d_config->c_info.poolid = -1; + libxl_cpupool_qualifier_to_cpupoolid(ctx, d_config->c_info.pool_name, + &d_config->c_info.poolid, + NULL); + } + if (!libxl_cpupoolid_is_valid(ctx, d_config->c_info.poolid)) { + LOG(ERROR, "Illegal pool specified: %s", d_config->c_info.pool_name); + ret = ERROR_INVAL; + goto error_out; + } + /* If target_memkb is smaller than max_memkb, the subsequent call * to libxc when building HVM domain will enable PoD mode. */ diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 8abed7b..ea1ce38 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -909,7 +909,11 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) dm_config->c_info.type = LIBXL_DOMAIN_TYPE_PV; dm_config->c_info.name = libxl__stub_dm_name(gc, libxl__domid_to_name(gc, guest_domid)); + /* When we are here to launch stubdom, ssidref is a valid value + * already, no need to parse it again. + */ dm_config->c_info.ssidref = guest_config->b_info.device_model_ssidref; + dm_config->c_info.ssid_label = NULL; libxl_uuid_generate(&dm_config->c_info.uuid); diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 8944686..0dfafe7 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -215,6 +215,7 @@ libxl_dominfo = Struct("dominfo",[ ("uuid", libxl_uuid), ("domid", libxl_domid), ("ssidref", uint32), + ("ssid_label", string), ("running", bool), ("blocked", bool), ("paused", bool), @@ -240,6 +241,7 @@ libxl_dominfo = Struct("dominfo",[ libxl_cpupoolinfo = Struct("cpupoolinfo", [ ("poolid", uint32), + ("pool_name", string), ("sched", libxl_scheduler), ("n_dom", uint32), ("cpumap", libxl_bitmap) @@ -270,11 +272,13 @@ libxl_domain_create_info = Struct("domain_create_info",[ ("hap", libxl_defbool), ("oos", libxl_defbool), ("ssidref", uint32), + ("ssid_label", string), ("name", string), ("uuid", libxl_uuid), ("xsdata", libxl_key_value_list), ("platformdata", libxl_key_value_list), ("poolid", uint32), + ("pool_name", string), ("run_hotplug_scripts",libxl_defbool), ("pvh", libxl_defbool), ("driver_domain",libxl_defbool), @@ -309,6 +313,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("shadow_memkb", MemKB), ("rtc_timeoffset", uint32), ("exec_ssidref", uint32), + ("exec_ssid_label", string), ("localtime", libxl_defbool), ("disable_migrate", libxl_defbool), ("cpuid", libxl_cpuid_policy_list), @@ -319,6 +324,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ # if you set device_model you must set device_model_version too ("device_model", string), ("device_model_ssidref", uint32), + ("device_model_ssid_label", string), # extra parameters pass directly to qemu, NULL terminated ("extra", libxl_string_list), diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index ac3188e..a1cb5b8 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -727,35 +727,17 @@ static void parse_config_data(const char *config_source, exit(1); } - if (!xlu_cfg_get_string (config, "init_seclabel", &buf, 0)) { - e = libxl_flask_context_to_sid(ctx, (char *)buf, strlen(buf), - &c_info->ssidref); - if (e) { - if (errno == ENOSYS) { - fprintf(stderr, "XSM Disabled: init_seclabel not supported\n"); - } else { - fprintf(stderr, "Invalid init_seclabel: %s\n", buf); - exit(1); - } - } - } + if (!xlu_cfg_get_string (config, "init_seclabel", &buf, 0)) + xlu_cfg_replace_string(config, "init_seclabel", + &c_info->ssid_label, 0); if (!xlu_cfg_get_string (config, "seclabel", &buf, 0)) { - uint32_t ssidref; - e = libxl_flask_context_to_sid(ctx, (char *)buf, strlen(buf), - &ssidref); - if (e) { - if (errno == ENOSYS) { - fprintf(stderr, "XSM Disabled: seclabel not supported\n"); - } else { - fprintf(stderr, "Invalid seclabel: %s\n", buf); - exit(1); - } - } else if (c_info->ssidref) { - b_info->exec_ssidref = ssidref; - } else { - c_info->ssidref = ssidref; - } + if (c_info->ssid_label) + xlu_cfg_replace_string(config, "seclabel", + &b_info->exec_ssid_label, 0); + else + xlu_cfg_replace_string(config, "seclabel", + &c_info->ssid_label, 0); } libxl_defbool_set(&c_info->run_hotplug_scripts, run_hotplug_scripts); @@ -783,14 +765,8 @@ static void parse_config_data(const char *config_source, xlu_cfg_get_defbool(config, "oos", &c_info->oos, 0); - if (!xlu_cfg_get_string (config, "pool", &buf, 0)) { - c_info->poolid = -1; - libxl_cpupool_qualifier_to_cpupoolid(ctx, buf, &c_info->poolid, NULL); - } - if (!libxl_cpupoolid_is_valid(ctx, c_info->poolid)) { - fprintf(stderr, "Illegal pool specified\n"); - exit(1); - } + if (!xlu_cfg_get_string (config, "pool", &buf, 0)) + xlu_cfg_replace_string(config, "pool", &c_info->pool_name, 0); libxl_domain_build_info_init_type(b_info, c_info->type); if (blkdev_start) @@ -1582,20 +1558,10 @@ skip_vfb: &b_info->device_model_stubdomain, 0); if (!xlu_cfg_get_string (config, "device_model_stubdomain_seclabel", - &buf, 0)) { - e = libxl_flask_context_to_sid(ctx, (char *)buf, strlen(buf), - &b_info->device_model_ssidref); - if (e) { - if (errno == ENOSYS) { - fprintf(stderr, "XSM Disabled:" - " device_model_stubdomain_seclabel not supported\n"); - } else { - fprintf(stderr, "Invalid device_model_stubdomain_seclabel:" - " %s\n", buf); - exit(1); - } - } - } + &buf, 0)) + xlu_cfg_replace_string(config, "device_model_stubdomain_seclabel", + &b_info->device_model_ssid_label, 0); + #define parse_extra_args(type) \ e = xlu_cfg_get_list_as_string_list(config, "device_model_args"#type, \ &b_info->extra##type, 0); \ @@ -3307,15 +3273,8 @@ static void list_domains(int verbose, int context, int claim, int numa, } if (claim) printf(" %5lu", (unsigned long)info[i].outstanding_memkb / 1024); - if (verbose || context) { - int rc; - size_t size; - char *buf = NULL; - rc = libxl_flask_sid_to_context(ctx, info[i].ssidref, &buf, - &size); - printf(" %16s", rc < 0 ? "-" : buf); - free(buf); - } + if (verbose || context) + printf(" %16s", info[i].ssid_label ? : "-"); if (numa) { libxl_domain_get_nodeaffinity(ctx, info[i].domid, &nodemap); @@ -6780,27 +6739,21 @@ int main_cpupoollist(int argc, char **argv) for (p = 0; p < n_pools; p++) { if (!ret && (!pool || (poolinfo[p].poolid == poolid))) { - name = libxl_cpupoolid_to_name(ctx, poolinfo[p].poolid); - if (!name) { - fprintf(stderr, "error getting cpupool info\n"); - ret = -ERROR_NOMEM; - } else { - printf("%-19s", name); - free(name); - n = 0; - libxl_for_each_bit(c, poolinfo[p].cpumap) - if (libxl_bitmap_test(&poolinfo[p].cpumap, c)) { - if (n && opt_cpus) printf(","); - if (opt_cpus) printf("%d", c); - n++; - } - if (!opt_cpus) { - printf("%3d %9s y %4d", n, - libxl_scheduler_to_string(poolinfo[p].sched), - poolinfo[p].n_dom); + name = poolinfo[p].pool_name; + printf("%-19s", name); + n = 0; + libxl_for_each_bit(c, poolinfo[p].cpumap) + if (libxl_bitmap_test(&poolinfo[p].cpumap, c)) { + if (n && opt_cpus) printf(","); + if (opt_cpus) printf("%d", c); + n++; } - printf("\n"); + if (!opt_cpus) { + printf("%3d %9s y %4d", n, + libxl_scheduler_to_string(poolinfo[p].sched), + poolinfo[p].n_dom); } + printf("\n"); } } diff --git a/tools/libxl/xl_sxp.c b/tools/libxl/xl_sxp.c index a16a025..48eb608 100644 --- a/tools/libxl/xl_sxp.c +++ b/tools/libxl/xl_sxp.c @@ -37,7 +37,6 @@ void printf_info_sexp(int domid, libxl_domain_config *d_config) libxl_domain_create_info *c_info = &d_config->c_info; libxl_domain_build_info *b_info = &d_config->b_info; - char *pool; printf("(domain\n\t(domid %d)\n", domid); printf("\t(create_info)\n"); @@ -55,10 +54,8 @@ void printf_info_sexp(int domid, libxl_domain_config *d_config) } else { printf("\t(uuid <unknown>)\n"); } - pool = libxl_cpupoolid_to_name(ctx, c_info->poolid); - if (pool) - printf("\t(cpupool %s)\n", pool); - free(pool); + if (c_info->pool_name) + printf("\t(cpupool %s)\n", c_info->pool_name); if (c_info->xsdata) printf("\t(xsdata contains data)\n"); else -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |