On 07/13/2012 04:04 PM, Peter Krempa wrote:
Hello, Peter,
Should I fix first 6 patches and resend them or wait until you finish
reviewing
last 2 ones ?
On 07/04/12 19:42, Dmitry Guryanov wrote:
> Add parallelsDomainDefineXML function, it works only for existing
> domains for the present.
>
> It's too hard to convert libvirt's XML domain configuration into
> PARALLELS's one, so I've decided to compare virDomainDef structures:
> current domain definition and the one created from XML, given to
> the function. And change only different parameters.
>
> Only description change implemetented, changing other parameters
> will be implemented later.
>
> Signed-off-by: Dmitry Guryanov <dguryanov(a)parallels.com>
> ---
> src/parallels/parallels_driver.c | 89
> ++++++++++++++++++++++++++++++++++++++
> 1 files changed, 89 insertions(+), 0 deletions(-)
>
> diff --git a/src/parallels/parallels_driver.c
> b/src/parallels/parallels_driver.c
> index b3d863f..54bdc9a 100644
> --- a/src/parallels/parallels_driver.c
> +++ b/src/parallels/parallels_driver.c
> @@ -1089,6 +1089,94 @@ parallelsShutdownDomain(virDomainPtr domain)
> VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
> }
>
> +static int
> +parallelsSetDescription(virDomainObjPtr dom, const char *description)
> +{
> + parallelsDomObjPtr parallelsdom;
> +
> + parallelsdom = dom->privateData;
> + if (parallelsCmdRun(PRLCTL, "set", parallelsdom->uuid,
> + "--description", description, NULL))
> + return -1;
> +
> + return 0;
> +}
> +
> +static int
> +parallelsApplyChanges(virDomainObjPtr dom, virDomainDefPtr newdef)
> +{
> + virDomainDefPtr olddef = dom->def;
> +
> + if (newdef->description && !STREQ(olddef->description,
> newdef->description)) {
> + if (parallelsSetDescription(dom, newdef->description))
> + return -1;
> + }
> +
> + /* TODO: compare all other parameters */
You should reject the change if something else is changed. Now the
change gets silently ignored but it's changed in libvirts data structs.
> +
> + return 0;
> +}
> +
> +static virDomainPtr
> +parallelsDomainDefineXML(virConnectPtr conn, const char *xml)
> +{
> + parallelsConnPtr privconn = conn->privateData;
> + virDomainPtr ret = NULL;
> + virDomainDefPtr def;
> + virDomainObjPtr dom = NULL, olddom = NULL;
> + virDomainEventPtr event = NULL;
> + int dupVM;
> +
> + parallelsDriverLock(privconn);
> + if ((def = virDomainDefParseString(privconn->caps, xml,
> + 1 << VIR_DOMAIN_VIRT_PARALLELS,
> + VIR_DOMAIN_XML_INACTIVE)) == NULL) {
> + parallelsError(VIR_ERR_INVALID_ARG, _("Can't parse XML
desc"));
> + goto cleanup;
> + }
> +
> + if ((dupVM = virDomainObjIsDuplicate(&privconn->domains, def,
> 0)) < 0) {
> + parallelsError(VIR_ERR_INVALID_ARG, _("Already exists"));
> + goto cleanup;
> + }
> +
> + if (dupVM == 1) {
> + olddom = virDomainFindByUUID(&privconn->domains, def->uuid);
> + parallelsApplyChanges(olddom, def);
> + virDomainObjUnlock(olddom);
> +
> + if (!(dom = virDomainAssignDef(privconn->caps,
> + &privconn->domains, def, false))) {
> + parallelsError(VIR_ERR_INTERNAL_ERROR, _("Can't allocate
> domobj"));
> + goto cleanup;
> + }
> +
> + def = NULL;
> + } else {
> + parallelsError(VIR_ERR_NO_SUPPORT, _("Not implemented yet"));
> + goto cleanup;
> + }
> +
> + event = virDomainEventNewFromObj(dom,
> + VIR_DOMAIN_EVENT_DEFINED,
> + !dupVM ?
> + VIR_DOMAIN_EVENT_DEFINED_ADDED :
> + VIR_DOMAIN_EVENT_DEFINED_UPDATED);
> +
> + ret = virGetDomain(conn, dom->def->name, dom->def->uuid);
> + if (ret)
> + ret->id = dom->def->id;
> +
> + cleanup:
> + virDomainDefFree(def);
> + if (dom)
> + virDomainObjUnlock(dom);
> + if (event)
> + parallelsDomainEventQueue(privconn, event);
> + parallelsDriverUnlock(privconn);
> + return ret;
> +}
> +
> static virDriver parallelsDriver = {
> .no = VIR_DRV_PARALLELS,
> .name = "PARALLELS",
> @@ -1116,6 +1204,7 @@ static virDriver parallelsDriver = {
> .domainDestroy = parallelsDestroyDomain, /* 0.10.0 */
> .domainShutdown = parallelsShutdownDomain, /* 0.10.0 */
> .domainCreate = parallelsDomainCreate, /* 0.10.0 */
> + .domainDefineXML = parallelsDomainDefineXML, /* 0.10.0 */
> };
>
> /**
>
--
Dmitry Guryanov