[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] libxl: generate a _dispose function for all Aggregate types
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1330604773 0 # Node ID 4ed7554ad6e58c208c34d559b2ae499d5532d86d # Parent d66fe43c6cfdd7f7c39fa8fd0dd888a5a9b35000 libxl: generate a _dispose function for all Aggregate types Don't special case types which we happen to know do not contain allocated data such that in the future if this changes we do not need to add an API. Although there is likely to be latent bugs in callers due to this having the API in old libraries mean that when callers are fixed they will not need to make special arrangements to handle old and new versions of the library. Adds dispose functions for: - libxl_dominfo - libxl_cpupoolinfo - libxl_physinfo - libxl_sched_credit - libxl_sched_credit2 I have attempted to fix any latent bugs in xl by inspection but have not bothered with libxl (on the basis that internally the library is allowed to make these sorts of assumptions and because it was looking like a very invasive job and that more would only creep in anyway). Several callsites use libxl_domain_info to check for the presence of a domain and throw away the actual info. As a convenience accept a NULL info pointer and just return the status. Also fix a memory leak in libxl_domain_list. Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- diff -r d66fe43c6cfd -r 4ed7554ad6e5 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Thu Mar 01 12:26:13 2012 +0000 +++ b/tools/libxl/libxl.c Thu Mar 01 12:26:13 2012 +0000 @@ -442,6 +442,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 +465,8 @@ } if (ret==0 || xcinfo.domain != domid) return ERROR_INVAL; - xcinfo2xlinfo(&xcinfo, info_r); + if (info_r) + xcinfo2xlinfo(&xcinfo, info_r); return 0; } @@ -986,13 +988,12 @@ int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid) { GC_INIT(ctx); - libxl_dominfo dominfo; char *dom_path; char *vm_path; char *pid; int rc, dm_present; - rc = libxl_domain_info(ctx, &dominfo, domid); + rc = libxl_domain_info(ctx, NULL, domid); switch(rc) { case 0: break; diff -r d66fe43c6cfd -r 4ed7554ad6e5 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Thu Mar 01 12:26:13 2012 +0000 +++ b/tools/libxl/libxl.h Thu Mar 01 12:26:13 2012 +0000 @@ -387,11 +387,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 diff -r d66fe43c6cfd -r 4ed7554ad6e5 tools/libxl/libxl_types.idl --- a/tools/libxl/libxl_types.idl Thu Mar 01 12:26:13 2012 +0000 +++ b/tools/libxl/libxl_types.idl Thu Mar 01 12:26:13 2012 +0000 @@ -177,7 +177,7 @@ ("vcpu_max_id", uint32), ("vcpu_online", uint32), ("cpupool", uint32), - ], dispose_fn=None) + ]) libxl_cpupoolinfo = Struct("cpupoolinfo", [ ("poolid", uint32), @@ -189,7 +189,7 @@ libxl_vminfo = Struct("vminfo", [ ("uuid", libxl_uuid), ("domid", libxl_domid), - ], dispose_fn=None) + ]) libxl_version_info = Struct("version_info", [ ("xen_version_major", integer), @@ -408,7 +408,7 @@ ("cap_hvm", bool), ("cap_hvm_directio", bool), - ], dispose_fn=None, dir=DIR_OUT) + ], dir=DIR_OUT) libxl_cputopology = Struct("cputopology", [ ("core", uint32), @@ -419,11 +419,11 @@ libxl_sched_credit_domain = Struct("sched_credit_domain", [ ("weight", integer), ("cap", integer), - ], dispose_fn=None) + ]) libxl_sched_credit2_domain = Struct("sched_credit2_domain", [ ("weight", integer), - ], dispose_fn=None) + ]) libxl_sched_sedf_domain = Struct("sched_sedf_domain", [ ("period", integer), @@ -431,7 +431,7 @@ ("latency", integer), ("extratime", integer), ("weight", integer), - ], dispose_fn=None) + ]) libxl_event_type = Enumeration("event_type", [ (1, "DOMAIN_SHUTDOWN"), diff -r d66fe43c6cfd -r 4ed7554ad6e5 tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Thu Mar 01 12:26:13 2012 +0000 +++ b/tools/libxl/libxl_utils.c Thu Mar 01 12:26:13 2012 +0000 @@ -507,6 +507,22 @@ free(list); } +void libxl_dominfo_list_free(libxl_dominfo *list, int nr) +{ + int i; + for (i = 0; i < nr; i++) + libxl_dominfo_dispose(&list[i]); + free(list); +} + +void libxl_vminfo_list_free(libxl_vminfo *list, int nr) +{ + int i; + for (i = 0; i < nr; i++) + libxl_vminfo_dispose(&list[i]); + free(list); +} + int libxl_domid_valid_guest(uint32_t domid) { /* returns 1 if the value _could_ be a valid guest domid, 0 otherwise diff -r d66fe43c6cfd -r 4ed7554ad6e5 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Mar 01 12:26:13 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Thu Mar 01 12:26:13 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; @@ -2505,7 +2504,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, @@ -3302,7 +3301,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; } @@ -3565,8 +3567,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 +3579,7 @@ } } vcpulist_out: - ; + libxl_physinfo_dispose(&physinfo); } int main_vcpulist(int argc, char **argv) @@ -3778,6 +3779,7 @@ free(cpumap.map); } + libxl_physinfo_dispose(&info); return; } @@ -3912,7 +3914,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; } @@ -4968,6 +4972,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) _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |