Daniel Veillard wrote:
On Wed, May 04, 2011 at 12:17:06PM +0200, Markus Groß wrote:
> Creating a domU on a freshly booted dom0 does not work,
> because the libxl driver does not allocate memory for the domU.
> After creating a domain with xl libvirt is able to create domains too.
> This patch reserves enough memory for the domU first.
> ---
> src/libxl/libxl_driver.c | 48 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 files changed, 46 insertions(+), 2 deletions(-)
>
> diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
> index 247d78e..d4ca025 100644
> --- a/src/libxl/libxl_driver.c
> +++ b/src/libxl/libxl_driver.c
> @@ -498,6 +498,46 @@ cleanup:
> return ret;
> }
>
> +static int
> +libxlFreeMem(libxlDomainObjPrivatePtr priv, libxl_domain_config *d_config)
> +{
> + uint32_t needed_mem;
> + uint32_t free_mem;
> + int i;
> + int ret = -1;
> + int tries = 3;
> + int wait_secs = 10;
> +
> + if ((ret = libxl_domain_need_memory(&priv->ctx,
&d_config->b_info,
> + &d_config->dm_info,
> + &needed_mem)) >= 0) {
> + for (i = 0; i < tries; ++i) {
> + if ((ret = libxl_get_free_memory(&priv->ctx, &free_mem)) <
0)
> + break;
> +
> + if (free_mem >= needed_mem) {
> + ret = 0;
> + break;
> + }
> +
> + if ((ret = libxl_set_memory_target(&priv->ctx, 0,
> + free_mem - needed_mem,
> + /* relative */ 1, 0)) < 0)
> + break;
> +
> + ret = libxl_wait_for_free_memory(&priv->ctx, 0, needed_mem,
> + wait_secs);
> + if (ret == 0 || ret != ERROR_NOMEM)
> + break;
> +
> + if ((ret = libxl_wait_for_memory_target(&priv->ctx, 0, 1)) <
0)
> + break;
> + }
> + }
> +
> + return ret;
> +}
> +
> /*
> * Start a domain through libxenlight.
> *
> @@ -521,8 +561,12 @@ libxlVmStart(libxlDriverPrivatePtr driver,
> if (libxlBuildDomainConfig(driver, def, &d_config) < 0 )
> return -1;
>
> - //TODO: Balloon dom0 ??
> - //ret = freemem(&d_config->b_info, &d_config->dm_info);
> + if (libxlFreeMem(priv, &d_config) < 0) {
> + libxlError(VIR_ERR_INTERNAL_ERROR,
> + _("libxenlight failed to get free memory for domain
'%s'"),
> + d_config.c_info.name);
> + goto error;
> + }
>
> ret = libxl_domain_create_new(&priv->ctx, &d_config,
> NULL, &child_console_pid, &domid);
>
That looks okay to me. My main question is if it's critical enough
that we should push this in 0.9.1,
ACK, but I don't know if it should be commited immediately
Sorry I didn't get to this before the release, but I haven't had much
time to work on libvirt recently.
ACK as well and I've pushed the patch now. Thanks Markus.
Regards,
Jim