tools/libxl/libxl.c | 12 +++++-----
tools/libxl/libxl_internal.h | 3 +-
tools/libxl/libxl_pci.c | 2 +-
tools/libxl/libxl_utils.c | 11 ++++++++-
tools/libxl/xl_cmdimpl.c | 49 +++++++++++++++++++++++++++++--------------
5 files changed, 50 insertions(+), 27 deletions(-)
This function has numerous in-and-out-of-library callers. In library callers
now use _libxl_domid_to_name() which participates in garbage collection and
out-of-library callers are fixed up to free() the domain name.
Signed-off-by: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
diff -r 0c8c78fea130 -r b4d2cf5a2a60 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Tue Aug 10 15:47:56 2010 +0100
+++ b/tools/libxl/libxl.c Tue Aug 10 15:50:03 2010 +0100
@@ -1221,7 +1221,7 @@ static int libxl_create_stubdom(libxl_ct
memset(&c_info, 0x00, sizeof(libxl_domain_create_info));
c_info.hvm = 0;
- c_info.name = libxl_sprintf(ctx, "%s-dm", libxl_domid_to_name(ctx,
info->domid));
+ c_info.name = libxl_sprintf(ctx, "%s-dm", _libxl_domid_to_name(ctx,
info->domid));
for (i = 0; i < 16; i++)
c_info.uuid[i] = info->uuid[i];
@@ -2028,7 +2028,7 @@ retry_transaction:
flexarray_set(back, boffset++, "state");
flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", 1));
flexarray_set(back, boffset++, "domain");
- flexarray_set(back, boffset++, libxl_domid_to_name(ctx, domid));
+ flexarray_set(back, boffset++, _libxl_domid_to_name(ctx, domid));
flexarray_set(back, boffset++, "protocol");
flexarray_set(back, boffset++, LIBXL_XENCONSOLE_PROTOCOL);
@@ -2085,7 +2085,7 @@ int libxl_device_vkb_add(libxl_ctx *ctx,
flexarray_set(back, boffset++, "state");
flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", 1));
flexarray_set(back, boffset++, "domain");
- flexarray_set(back, boffset++, libxl_domid_to_name(ctx, domid));
+ flexarray_set(back, boffset++, _libxl_domid_to_name(ctx, domid));
flexarray_set(front, foffset++, "backend-id");
flexarray_set(front, foffset++, libxl_sprintf(ctx, "%d",
vkb->backend_domid));
@@ -2262,7 +2262,7 @@ static int libxl_build_xenpv_qemu_args(l
uint32_t guest_domid;
if (libxl_is_stubdom(ctx, vfb->domid, &guest_domid)) {
char *filename;
- char *name = libxl_sprintf(ctx, "qemu-dm-%s",
libxl_domid_to_name(ctx, guest_domid));
+ char *name = libxl_sprintf(ctx, "qemu-dm-%s",
_libxl_domid_to_name(ctx, guest_domid));
libxl_create_logfile(ctx, name, &filename);
info->serial = libxl_sprintf(ctx, "file:%s", filename);
free(filename);
@@ -2280,7 +2280,7 @@ static int libxl_build_xenpv_qemu_args(l
info->extra[j] = NULL;
}
info->domid = vfb->domid;
- info->dom_name = libxl_domid_to_name(ctx, vfb->domid);
+ info->dom_name = _libxl_domid_to_name(ctx, vfb->domid);
info->device_model = libxl_abs_path(ctx, "qemu-dm", libxl_libexec_path());
info->type = XENPV;
return 0;
@@ -2326,7 +2326,7 @@ int libxl_device_vfb_add(libxl_ctx *ctx,
flexarray_set(back, boffset++, "state");
flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", 1));
flexarray_set(back, boffset++, "domain");
- flexarray_set(back, boffset++, libxl_domid_to_name(ctx, domid));
+ flexarray_set(back, boffset++, _libxl_domid_to_name(ctx, domid));
flexarray_set(back, boffset++, "vnc");
flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", vfb->vnc));
flexarray_set(back, boffset++, "vnclisten");
diff -r 0c8c78fea130 -r b4d2cf5a2a60 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h Tue Aug 10 15:47:56 2010 +0100
+++ b/tools/libxl/libxl_internal.h Tue Aug 10 15:50:03 2010 +0100
@@ -226,8 +226,7 @@ char *libxl_abs_path(libxl_ctx *ctx, cha
#define XL_LOG_WARNING XTL_WARN
#define XL_LOG_ERROR XTL_ERROR
-/* Error handling */
-int libxl_xc_error(int xc_err);
+char *_libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid);
#endif
diff -r 0c8c78fea130 -r b4d2cf5a2a60 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c Tue Aug 10 15:47:56 2010 +0100
+++ b/tools/libxl/libxl_pci.c Tue Aug 10 15:50:03 2010 +0100
@@ -224,7 +224,7 @@ static int libxl_create_pci_backend(libx
flexarray_set(back, boffset++, "state");
flexarray_set(back, boffset++, libxl_sprintf(ctx, "%d", 1));
flexarray_set(back, boffset++, "domain");
- flexarray_set(back, boffset++, libxl_domid_to_name(ctx, domid));
+ flexarray_set(back, boffset++, _libxl_domid_to_name(ctx, domid));
for (i = 0; i < num; i++) {
flexarray_set(back, boffset++, libxl_sprintf(ctx, "key-%d", i));
flexarray_set(back, boffset++, libxl_sprintf(ctx, PCI_BDF,
pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func));
diff -r 0c8c78fea130 -r b4d2cf5a2a60 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Tue Aug 10 15:47:56 2010 +0100
+++ b/tools/libxl/libxl_utils.c Tue Aug 10 15:50:03 2010 +0100
@@ -51,7 +51,14 @@ char *libxl_domid_to_name(libxl_ctx *ctx
snprintf(path, sizeof(path), "/local/domain/%d/name", domid);
s = xs_read(ctx->xsh, XBT_NULL, path, &len);
- libxl_ptr_add(ctx, s);
+ return s;
+}
+
+char *_libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid)
+{
+ char *s = libxl_domid_to_name(ctx, domid);
+ if ( s )
+ libxl_ptr_add(ctx, s);
return s;
}
@@ -68,7 +75,7 @@ int libxl_name_to_domid(libxl_ctx *ctx,
return ERROR_NOMEM;
for (i = 0; i < nb_domains; i++) {
- domname = libxl_domid_to_name(ctx, dominfo[i].domid);
+ domname = _libxl_domid_to_name(ctx, dominfo[i].domid);
if (!domname)
continue;
if (strcmp(domname, name) == 0) {
diff -r 0c8c78fea130 -r b4d2cf5a2a60 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Tue Aug 10 15:47:56 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Tue Aug 10 15:50:03 2010 +0100
@@ -2143,8 +2143,10 @@ void list_domains(int verbose, const lib
printf("Name ID Mem
VCPUs\tState\tTime(s)\n");
for (i = 0; i < nb_domain; i++) {
+ char *domname;
+ domname = libxl_domid_to_name(&ctx, info[i].domid);
printf("%-40s %5d %5lu %5d %c%c%c%c%c%c %8.1f",
- libxl_domid_to_name(&ctx, info[i].domid),
+ domname,
info[i].domid,
(unsigned long) (info[i].max_memkb / 1024),
info[i].vcpu_online,
@@ -2155,6 +2157,7 @@ void list_domains(int verbose, const lib
info[i].shutdown_reason == SHUTDOWN_crash ? 'c' : '-',
info[i].dying ? 'd' : '-',
((float)info[i].cpu_time / 1e9));
+ free(domname);
if (verbose) {
char *uuid = libxl_uuid2string(&ctx, info[i].uuid);
printf(" %s", uuid);
@@ -2166,6 +2169,7 @@ void list_domains(int verbose, const lib
void list_vm(void)
{
libxl_vminfo *info;
+ char *domname;
int nb_vm, i;
info = libxl_list_vm(&ctx, &nb_vm);
@@ -2176,12 +2180,14 @@ void list_vm(void)
}
printf("UUID ID name\n");
for (i = 0; i < nb_vm; i++) {
+ domname = libxl_domid_to_name(&ctx, info[i].domid);
printf(UUID_FMT " %d %-30s\n",
info[i].uuid[0], info[i].uuid[1], info[i].uuid[2], info[i].uuid[3],
info[i].uuid[4], info[i].uuid[5], info[i].uuid[6], info[i].uuid[7],
info[i].uuid[8], info[i].uuid[9], info[i].uuid[10],
info[i].uuid[11],
info[i].uuid[12], info[i].uuid[13], info[i].uuid[14],
info[i].uuid[15],
- info[i].domid, libxl_domid_to_name(&ctx, info[i].domid));
+ info[i].domid, domname);
+ free(domname);
}
free(info);
}
@@ -3181,10 +3187,13 @@ static void print_vcpuinfo(uint32_t tdom
int i, l;
uint64_t *cpumap;
uint64_t pcpumap;
+ char *domname;
/* NAME ID VCPU */
+ domname = libxl_domid_to_name(&ctx, tdomid);
printf("%-32s %5u %5u",
- libxl_domid_to_name(&ctx, tdomid), tdomid, vcpuinfo->vcpuid);
+ domname, tdomid, vcpuinfo->vcpuid);
+ free(domname);
if (!vcpuinfo->online) {
/* CPU STA */
printf("%5c %3c%cp ", '-', '-', '-');
@@ -3593,11 +3602,14 @@ static int sched_credit_domain_set(
static void sched_credit_domain_output(
int domid, libxl_sched_credit *scinfo)
{
+ char *domname;
+ domname = libxl_domid_to_name(&ctx, domid);
printf("%-33s %4d %6d %4d\n",
- libxl_domid_to_name(&ctx, domid),
+ domname,
domid,
scinfo->weight,
scinfo->cap);
+ free(domname);
}
int main_sched_credit(int argc, char **argv)
@@ -3743,6 +3755,7 @@ int main_domname(int argc, char **argv)
}
printf("%s\n", domname);
+ free(domname);
return 0;
}
@@ -4505,6 +4518,7 @@ static void print_dom0_uptime(int short_
uint32_t uptime = 0;
char *uptime_str = NULL;
char *now_str = NULL;
+ char *domname;
fd = open("/proc/uptime", O_RDONLY);
if (fd == -1)
@@ -4519,24 +4533,25 @@ static void print_dom0_uptime(int short_
strtok(buf, " ");
uptime = strtoul(buf, NULL, 10);
+ domname = libxl_domid_to_name(&ctx, 0);
if (short_mode)
{
now_str = current_time_to_string(now);
uptime_str = uptime_to_string(uptime, 1);
printf(" %s up %s, %s (%d)\n", now_str, uptime_str,
- libxl_domid_to_name(&ctx, 0), 0);
+ domname, 0);
}
else
{
+ now_str = NULL;
uptime_str = uptime_to_string(uptime, 0);
- printf("%-33s %4d %s\n", libxl_domid_to_name(&ctx, 0),
+ printf("%-33s %4d %s\n", domname,
0, uptime_str);
}
- if (now_str)
- free(now_str);
- if (uptime_str)
- free(uptime_str);
+ free(now_str);
+ free(uptime_str);
+ free(domname);
return;
err:
fprintf(stderr, "Can not get Dom0 uptime.\n");
@@ -4549,29 +4564,31 @@ static void print_domU_uptime(uint32_t d
uint32_t uptime = 0;
char *uptime_str = NULL;
char *now_str = NULL;
+ char *domname;
s_time = libxl_vm_get_start_time(&ctx, domuid);
if (s_time == -1)
return;
uptime = now - s_time;
+ domname = libxl_domid_to_name(&ctx, domuid);
if (short_mode)
{
now_str = current_time_to_string(now);
uptime_str = uptime_to_string(uptime, 1);
printf(" %s up %s, %s (%d)\n", now_str, uptime_str,
- libxl_domid_to_name(&ctx, domuid), domuid);
+ domname, domuid);
}
else
{
+ now_str = NULL;
uptime_str = uptime_to_string(uptime, 0);
- printf("%-33s %4d %s\n", libxl_domid_to_name(&ctx, domuid),
+ printf("%-33s %4d %s\n", domname,
domuid, uptime_str);
}
- if (now_str)
- free(now_str);
- if (uptime_str)
- free(uptime_str);
+ free(domname);
+ free(now_str);
+ free(uptime_str);
return;
}
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|