WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] xl: Fix invalid return of libxl-internal

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] xl: Fix invalid return of libxl-internal pointers via libxl_domid_to_name()
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 13 Aug 2010 02:15:34 -0700
Delivery-date: Fri, 13 Aug 2010 02:20:03 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User "Gianni Tedesco (3P)" <gianni.tedesco@xxxxxxxxxx>
# Date 1281528494 -3600
# Node ID 8c60cc6aabd473e851c478e897184dc16e3f49c2
# Parent  6c3dc59c1efc6f02938e8e17e657fdf1a15f6295
xl: Fix invalid return of libxl-internal pointers via libxl_domid_to_name()
libxl_domid_to_name 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>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 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(-)

diff -r 6c3dc59c1efc -r 8c60cc6aabd4 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Aug 11 13:07:21 2010 +0100
+++ b/tools/libxl/libxl.c       Wed Aug 11 13:08:14 2010 +0100
@@ -1379,7 +1379,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];
 
@@ -2186,7 +2186,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);
 
@@ -2243,7 +2243,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));
@@ -2420,7 +2420,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);
@@ -2438,7 +2438,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;
@@ -2484,7 +2484,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 6c3dc59c1efc -r 8c60cc6aabd4 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Wed Aug 11 13:07:21 2010 +0100
+++ b/tools/libxl/libxl_internal.h      Wed Aug 11 13:08:14 2010 +0100
@@ -227,8 +227,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 6c3dc59c1efc -r 8c60cc6aabd4 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c   Wed Aug 11 13:07:21 2010 +0100
+++ b/tools/libxl/libxl_pci.c   Wed Aug 11 13:08:14 2010 +0100
@@ -228,7 +228,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 6c3dc59c1efc -r 8c60cc6aabd4 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Wed Aug 11 13:07:21 2010 +0100
+++ b/tools/libxl/libxl_utils.c Wed Aug 11 13:08:14 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 6c3dc59c1efc -r 8c60cc6aabd4 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Wed Aug 11 13:07:21 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Wed Aug 11 13:08:14 2010 +0100
@@ -2154,8 +2154,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,
@@ -2166,6 +2168,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);
@@ -2177,6 +2180,7 @@ void list_vm(void)
 void list_vm(void)
 {
     libxl_vminfo *info;
+    char *domname;
     int nb_vm, i;
 
     info = libxl_list_vm(&ctx, &nb_vm);
@@ -2187,12 +2191,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);
 }
@@ -3197,10 +3203,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 ", '-', '-', '-');
@@ -3608,11 +3617,14 @@ static void sched_credit_domain_output(
 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)
@@ -3758,6 +3770,7 @@ int main_domname(int argc, char **argv)
     }
 
     printf("%s\n", domname);
+    free(domname);
 
     return 0;
 }
@@ -4519,6 +4532,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)
@@ -4533,24 +4547,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");
@@ -4563,29 +4578,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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] xl: Fix invalid return of libxl-internal pointers via libxl_domid_to_name(), Xen patchbot-unstable <=