Skip to contentSkip to conversation

libxl: Specify the target ram size to Qemu (new) when calling it

PATCH Applied [email protected] 3 participants 11 messages Dec 16, 2010 – Jan 6, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: Specify the target ram size to Qemu (new) when calling it

From: Anthony PERARD <[email protected]>

This patch adds target_ram in device_model_info structure, to be used in libxl_build_device_model_args_new. Qemu upstream needs to know about it.

It introduces also libxl__sizekb_to_mb to convert size from KB to MB by rounding up the result.

---
 tools/libxl/libxl.c       |    4 ++++
 tools/libxl/libxl.idl     |    1 +
 tools/libxl/libxl_utils.h |    4 ++++
 tools/libxl/xl_cmdimpl.c  |    3 ++-
 4 files changed, 11 insertions(+), 1 deletions(-)
tools/libxl/libxl.c +4 -0
index aa28c72..9dfd211 100644
@@ -1384,6 +1384,10 @@ static char ** libxl_build_device_model_args_new(libxl__gc *gc,
     else
         flexarray_set(dm_args, num++, "xenfv");
 
+    /* RAM Size */
+    flexarray_set(dm_args, num++, "-m");
+    flexarray_set(dm_args, num++, libxl__sprintf(gc, "%d", info->target_ram));
+
     if (info->type == XENFV) {
         disks = libxl_device_disk_list(libxl__gc_owner(gc), info->domid, &nb);
         for (i; i < nb; i++) {
tools/libxl/libxl.idl +1 -0
index 8dd7749..89694b1 100644
@@ -139,6 +139,7 @@ libxl_device_model_info = Struct("device_model_info",[
     ("device_model",     string),
     ("saved_state",      string),
     ("type",             libxl_qemu_machine_type),
+    ("target_ram",       uint32),
     ("videoram",         integer,           False, "size of the videoram in MB"),
     ("stdvga",           bool,              False, "stdvga enabled or disabled"),
     ("vnc",              bool,              False, "vnc enabled or disabled"),
tools/libxl/libxl_utils.h +4 -0
index 7846c42..940fecd 100644
@@ -82,5 +82,9 @@ void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
 void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
 #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++)
 
+static inline uint32_t libxl__sizekb_to_mb(uint32_t s) {
+    return (s + 1023) / 1024;
+}
+
 #endif
 
tools/libxl/xl_cmdimpl.c +2 -1
index 5555319..3718a5a 100644
@@ -359,7 +359,8 @@ static void init_dm_info(libxl_device_model_info *dm_info,
 
     dm_info->dom_name = strdup(c_info->name);
     dm_info->device_model = strdup("qemu-dm");
-    dm_info->videoram = b_info->video_memkb / 1024;
+    dm_info->target_ram = libxl__sizekb_to_mb(b_info->target_memkb);
+    dm_info->videoram = libxl__sizekb_to_mb(b_info->video_memkb);
     dm_info->apic = b_info->u.hvm.apic;
     dm_info->vcpus = b_info->max_vcpus;
     dm_info->vcpu_avail = b_info->cur_vcpus;
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 libxl: Lists qdisk device in libxl_device_disk_list

From: Anthony PERARD <[email protected]>

As libxl switch to qdisk when blktap isn't available, this patch makes libxl_device_disk_list also list qdisk device. So libxl_build_device_model_args_new will be able to add qdisk device to the command line options of Qemu.

---
 tools/libxl/libxl.c |   30 +++++++++++++++++++++++++++++-
 1 files changed, 29 insertions(+), 1 deletions(-)
tools/libxl/libxl.c +29 -1
index 9dfd211..78dcf62 100644
@@ -2492,7 +2492,7 @@ int libxl_device_vkb_hard_shutdown(libxl_ctx *ctx, uint32_t domid)
 libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *be_path_tap, *be_path_vbd;
+    char *be_path_tap, *be_path_vbd, *be_path_qdisk;
     libxl_device_disk *dend, *disks, *ret = NULL;
     char **b, **l = NULL;
     unsigned int numl, len;
@@ -2500,6 +2500,7 @@ libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *n
 
     be_path_vbd = libxl__sprintf(&gc, "%s/backend/vbd/%d", libxl__xs_get_dompath(&gc, 0), domid);
     be_path_tap = libxl__sprintf(&gc, "%s/backend/tap/%d", libxl__xs_get_dompath(&gc, 0), domid);
+    be_path_qdisk = libxl__sprintf(&gc, "%s/backend/qdisk/%d", libxl__xs_get_dompath(&gc, 0), domid);
 
     b = l = libxl__xs_directory(&gc, XBT_NULL, be_path_vbd, &numl);
     if (l) {
@@ -2542,6 +2543,33 @@ libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *n
             disks->is_cdrom = !strcmp(type, "cdrom");
         }
     }
+    b = l = libxl__xs_directory(&gc, XBT_NULL, be_path_qdisk, &numl);
+    if (l) {
+        ret = realloc(ret, sizeof(libxl_device_disk) * (*num + numl));
+        disks = ret + *num;
+        *num += numl;
+        for (dend = ret + *num; disks < dend; ++disks, ++l) {
+            char *physpath_tmp;
+            disks->backend_domid = 0;
+            disks->domid = domid;
+            physpath_tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/params", be_path_qdisk, *l), &len);
+            if (strchr(physpath_tmp, ':')) {
+                disks->physpath = strdup(strchr(physpath_tmp, ':') + 1);
+                free(physpath_tmp);
+            } else {
+                disks->physpath = physpath_tmp;
+            }
+            libxl_string_to_phystype(ctx, libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/type", be_path_qdisk, *l)), &(disks->phystype));
+            disks->virtpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/dev", be_path_qdisk, *l), &len);
+            disks->unpluggable = atoi(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/removable", be_path_qdisk, *l)));
+            if (!strcmp(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/mode", be_path_qdisk, *l)), "w"))
+                disks->readwrite = 1;
+            else
+                disks->readwrite = 0;
+            type = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/device-type", libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/frontend", be_path_qdisk, *l))));
+            disks->is_cdrom = !strcmp(type, "cdrom");
+        }
+    }
     libxl__free_all(&gc);
     return ret;
 }
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH] libxl: Lists qdisk device in libxl_device_disk_list

[email protected] writes ("[Xen-devel] [PATCH] libxl: Lists qdisk device in libxl_device_disk_list"):

Quoted 4 lines

As libxl switch to qdisk when blktap isn't available, this patch makes libxl_device_disk_list also list qdisk device. So libxl_build_device_model_args_new will be able to add qdisk device to the command line options of Qemu.

Thanks for this contribution. But what you have done is introduced yet a third copy of a section of code which has been cloned-and-hacked one already.

Can you please make a patch which breaks the common code out into a separate function, or macro, or uses a loop, or something ? I don't much mind how it's done but to my mind a function is probably going to be easiest.

Ian.

#3 lore raw

PATCH v2 1/2 libxl: Factorize function libxl_device_disk_list

From: Anthony PERARD <[email protected]>

This patch adds function libxl_append_disk_list_of_type to get disks parameter of one backend type.

---
 tools/libxl/libxl.c |   99 ++++++++++++++++++++++++++-------------------------
 1 files changed, 50 insertions(+), 49 deletions(-)
tools/libxl/libxl.c +50 -49
index 10d4527..79ad06c 100644
@@ -2518,61 +2518,62 @@ int libxl_device_vkb_hard_shutdown(libxl_ctx *ctx, uint32_t domid)
     return ERROR_NI;
 }
 
-libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num)
+static unsigned int libxl_append_disk_list_of_type(libxl_ctx *ctx,
+                                                   uint32_t domid,
+                                                   const char *type,
+                                                   libxl_device_disk **disks,
+                                                   unsigned int *ndisks)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *be_path_tap, *be_path_vbd;
-    libxl_device_disk *dend, *disks, *ret = NULL;
-    char **b, **l = NULL;
-    unsigned int numl, len;
-    char *type;
-
-    be_path_vbd = libxl__sprintf(&gc, "%s/backend/vbd/%d", libxl__xs_get_dompath(&gc, 0), domid);
-    be_path_tap = libxl__sprintf(&gc, "%s/backend/tap/%d", libxl__xs_get_dompath(&gc, 0), domid);
-
-    b = l = libxl__xs_directory(&gc, XBT_NULL, be_path_vbd, &numl);
-    if (l) {
-        ret = realloc(ret, sizeof(libxl_device_disk) * numl);
-        disks = ret;
-        *num = numl;
-        dend = ret + *num;
-        for (; disks < dend; ++disks, ++l) {
-            disks->backend_domid = 0;
-            disks->domid = domid;
-            disks->physpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/params", be_path_vbd, *l), &len);
-            libxl_string_to_phystype(ctx, libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/type", be_path_vbd, *l)), &(disks->phystype));
-            disks->virtpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/dev", be_path_vbd, *l), &len);
-            disks->unpluggable = atoi(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/removable", be_path_vbd, *l)));
-            if (!strcmp(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/mode", be_path_vbd, *l)), "w"))
-                disks->readwrite = 1;
-            else
-                disks->readwrite = 0;
-            type = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/device-type", libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/frontend", be_path_vbd, *l))));
-            disks->is_cdrom = !strcmp(type, "cdrom");
-        }
-    }
-    b = l = libxl__xs_directory(&gc, XBT_NULL, be_path_tap, &numl);
-    if (l) {
-        ret = realloc(ret, sizeof(libxl_device_disk) * (*num + numl));
-        disks = ret + *num;
-        *num += numl;
-        for (dend = ret + *num; disks < dend; ++disks, ++l) {
-            disks->backend_domid = 0;
-            disks->domid = domid;
-            disks->physpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/params", be_path_tap, *l), &len);
-            libxl_string_to_phystype(ctx, libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/type", be_path_tap, *l)), &(disks->phystype));
-            disks->virtpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/dev", be_path_tap, *l), &len);
-            disks->unpluggable = atoi(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/removable", be_path_tap, *l)));
-            if (!strcmp(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/mode", be_path_tap, *l)), "w"))
-                disks->readwrite = 1;
+    char *be_path = NULL;
+    char **dir = NULL;
+    unsigned int n = 0, len = 0;
+    libxl_device_disk *pdisk = NULL, *pdisk_end = NULL;
+    char *physpath_tmp = NULL;
+
+    be_path = libxl__sprintf(&gc, "%s/backend/%s/%d",
+                             libxl__xs_get_dompath(&gc, 0), type, domid);
+    dir = libxl__xs_directory(&gc, XBT_NULL, be_path, &n);
+    if (dir) {
+        *disks = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
+        pdisk = *disks + *ndisks;
+        *ndisks += n;
+        pdisk_end = *disks + *ndisks;
+        for (; pdisk < pdisk_end; pdisk++, dir++) {
+            pdisk->backend_domid = 0;
+            pdisk->domid = domid;
+            physpath_tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/params", be_path, *dir), &len);
+            if (strchr(physpath_tmp, ':')) {
+                pdisk->physpath = strdup(strchr(physpath_tmp, ':') + 1);
+                free(physpath_tmp);
+            } else {
+                pdisk->physpath = physpath_tmp;
+            }
+            libxl_string_to_phystype(ctx, libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/type", be_path, *dir)), &(pdisk->phystype));
+            pdisk->virtpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/dev", be_path, *dir), &len);
+            pdisk->unpluggable = atoi(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/removable", be_path, *dir)));
+            if (!strcmp(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/mode", be_path, *dir)), "w"))
+                pdisk->readwrite = 1;
             else
-                disks->readwrite = 0;
-            type = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/device-type", libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/frontend", be_path_tap, *l))));
-            disks->is_cdrom = !strcmp(type, "cdrom");
+                pdisk->readwrite = 0;
+            type = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/device-type", libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/frontend", be_path, *dir))));
+            pdisk->is_cdrom = !strcmp(type, "cdrom");
         }
     }
+
     libxl__free_all(&gc);
-    return ret;
+    return n;
+}
+
+libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num)
+{
+    libxl_device_disk *disks = NULL;
+    unsigned int ndisks = 0;
+
+    *num = libxl_append_disk_list_of_type(ctx, domid, "vbd", &disks, &ndisks);
+    *num += libxl_append_disk_list_of_type(ctx, domid, "tap", &disks, &ndisks);
+
+    return disks;
 }
 
 int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
Signature · 1 line
1.7.1
Applied
#4 lore raw

Re: [PATCH V2 1/2] libxl: Factorize function libxl_device_disk_list

[email protected] writes ("[Xen-devel] [PATCH V2 1/2] libxl: Factorize function libxl_device_disk_list"):

Quoted 4 lines

From: Anthony PERARD <[email protected]>

This patch adds function libxl_append_disk_list_of_type to get disks parameter of one backend type.

Great, thanks.

The creation and destruction of a private gc in the internal function is perhaps unusual but in this case it doesn't lead to a bug, and yes the outer function doesn't need a gc.

Applied.

Ian.

#5 lore raw

PATCH v2 2/2 libxl: Lists qdisk device in libxl_device_disk_list

In reply to Ian Jackson

From: Anthony PERARD <[email protected]>

As libxl switch to qdisk when blktap isn't available, this patch makes libxl_device_disk_list also list qdisk device. So libxl_build_device_model_args_new will be able to add qdisk device to the command line options of Qemu.

---
 tools/libxl/libxl.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
tools/libxl/libxl.c +1 -0
index 79ad06c..fa42d98 100644
@@ -2572,6 +2572,7 @@ libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *n
 
     *num = libxl_append_disk_list_of_type(ctx, domid, "vbd", &disks, &ndisks);
     *num += libxl_append_disk_list_of_type(ctx, domid, "tap", &disks, &ndisks);
+    *num += libxl_append_disk_list_of_type(ctx, domid, "qdisk", &disks, &ndisks);
 
     return disks;
 }
Signature · 1 line
1.7.1
Applied
#6 lore raw

Re: [PATCH V2 2/2] libxl: Lists qdisk device in libxl_device_disk_list

[email protected] writes ("[Xen-devel] [PATCH V2 2/2] libxl: Lists qdisk device in libxl_device_disk_list"):

Quoted 4 lines

As libxl switch to qdisk when blktap isn't available, this patch makes libxl_device_disk_list also list qdisk device. So libxl_build_device_model_args_new will be able to add qdisk device to the command line options of Qemu.

Applied, thanks.

Ian.

Applied
#7 lore raw
In reply to [email protected]

[email protected] writes ("[Xen-devel] [PATCH] libxl: Specify the target ram size to Qemu (new) when calling it"):

Quoted 2 lines

This patch adds target_ram in device_model_info structure, to be used in libxl_build_device_model_args_new. Qemu upstream needs to know about it.

I have applied this patch, thanks.

I'm just a little concerned, though: can you explain _why_ qemu upstream needs to know the target ram size ?

Ian.

#8 lore raw
Quoted 9 lines · Ian Jackson

[email protected] writes ("[Xen-devel] [PATCH] libxl: Specify the target ram size to Qemu (new) when calling it"):

Quoted 2 lines

This patch adds target_ram in device_model_info structure, to be used in libxl_build_device_model_args_new. Qemu upstream needs to know about it.

I have applied this patch, thanks.

I'm just a little concerned, though: can you explain _why_ qemu upstream needs to know the target ram size ?

Qemu used to be responsible for initialising BIOS info tables, including memory size information such as e820, in lieu of the virtual BIOS doing it. I ripped all that out from our diverged tree, and put it in hvmloader/rombios, but maybe they still do it in upstream qemu. I think it would be harmless if so, since hvmloader/rombios will overwrite/ignore.

-- Keir

Quoted 6 lines

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#9 lore raw
Quoted 9 lines · Keir Fraser
Quoted 7 lines · Ian Jackson

[email protected] writes ("[Xen-devel] [PATCH] libxl: Specify the target ram size to Qemu (new) when calling it"):

Quoted 2 lines

This patch adds target_ram in device_model_info structure, to be used in libxl_build_device_model_args_new. Qemu upstream needs to know about it.

I have applied this patch, thanks.

Quoted 8 lines
Quoted 2 lines

I'm just a little concerned, though: can you explain _why_ qemu upstream needs to know the target ram size ?

Qemu used to be responsible for initialising BIOS info tables, including memory size information such as e820, in lieu of the virtual BIOS doing it. I ripped all that out from our diverged tree, and put it in hvmloader/rombios, but maybe they still do it in upstream qemu. I think it would be harmless if so, since hvmloader/rombios will overwrite/ignore.

There are another reason, qemu "allocate" the memory for the vga at a dynamic address. In qemu-xen, this address is static. So qemu need to know the size of the ram to put the memory of the vga after the ram. Qemu do the same for other memory like the rom of a nic.

Information about the ram is put in the struct RAMBlock of qemu.

Signature · 1 line
Anthony PERARD
#10 lore raw

Anthony Perard writes ("Re: [Xen-devel] [PATCH] libxl: Specify the target ram size to Qemu (new) when calling it"):

Quoted 7 lines · Keir Fraser
Quoted 5 lines

Qemu used to be responsible for initialising BIOS info tables, including memory size information such as e820, in lieu of the virtual BIOS doing it. I ripped all that out from our diverged tree, and put it in hvmloader/rombios, but maybe they still do it in upstream qemu. I think it would be harmless if so, since hvmloader/rombios will overwrite/ignore.

Quoted 6 lines

There are another reason, qemu "allocate" the memory for the vga at a dynamic address. In qemu-xen, this address is static. So qemu need to know the size of the ram to put the memory of the vga after the ram. Qemu do the same for other memory like the rom of a nic.

Information about the ram is put in the struct RAMBlock of qemu.

Right. OK, I'll stop worrying :-).

Ian.