<div dir="ltr"><div>Sure, I will split it into two separate commits. I must have messed up sth in commits, since even in head-email I described 3 patches...<br><br>Regarding NULL, it is a little tricky. After running virDomainObjListRemove, the vm pointer has 0 references. Then, running virObjectUnlock causes libvirt segfault. To minimize changes, I used the solution from qemu: set vm to null and then check it inside cleanup. The "if (vm)" is just aesthetic - without it there was an awful warning on the console about null-pointer. I'd like to leave it as is, or remove "vm=NULL;" and insert virObjectRef/virObjectUnref pair instead.<br>
<br></div><div>What do you mean by ACL check? Do you think the check is unnecessary, or just should be placed earlier?<br><br><br></div><div>W.<br></div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
2014-04-08 9:01 GMT+02:00 Roman Bogorodskiy <span dir="ltr"><<a href="mailto:bogorodskiy@gmail.com" target="_blank">bogorodskiy@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  Wojciech Macek wrote:<br>
<br>
> Implement bhyveDomainCreteXML function.<br>
<br>
s/Crete/Create/<br>
<div class=""><br>
>  src/bhyve/bhyve_driver.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++-<br>
>  1 file changed, 80 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c<br>
> index f7a8912..2ea2d22 100644<br>
> --- a/src/bhyve/bhyve_driver.c<br>
> +++ b/src/bhyve/bhyve_driver.c<br>
> @@ -756,8 +756,14 @@ bhyveDomainDestroy(virDomainPtr dom)<br>
><br>
>      ret = virBhyveProcessStop(privconn, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);<br>
><br>
> +    if (!vm->persistent) {<br>
> +        virDomainObjListRemove(privconn->domains, vm);<br>
> +        vm = NULL;<br>
> +    }<br>
> +<br>
<br>
</div>This chunk doesn't seem to be directly related to domainCreateXML(),<br>
should there be a reasoning and probably it should be a separate commit<br>
even?<br>
<div class=""><br>
>   cleanup:<br>
> -    virObjectUnlock(vm);<br>
> +    if (vm)<br>
> +        virObjectUnlock(vm);<br>
<br>
</div>It's safe not to check for NULL here.<br>
<div><div class="h5"><br>
>      return ret;<br>
>  }<br>
><br>
> @@ -1074,6 +1080,78 @@ bhyveDomainResume(virDomainPtr dom)<br>
>      return ret;<br>
>  }<br>
><br>
> +static virDomainPtr<br>
> +bhyveDomainCreateXML(virConnectPtr conn,<br>
> +                     const char *xml,<br>
> +                     unsigned int flags)<br>
> +{<br>
> +    bhyveConnPtr privconn = conn->privateData;<br>
> +    virDomainPtr dom = NULL;<br>
> +    virDomainDefPtr def = NULL;<br>
> +    virDomainObjPtr vm = NULL;<br>
> +    virCapsPtr caps = NULL;<br>
> +    int ret;<br>
> +    unsigned int start_flags = 0;<br>
> +<br>
> +    virCheckFlags(VIR_DOMAIN_START_AUTODESTROY, NULL);<br>
> +<br>
> +    if (flags & VIR_DOMAIN_START_AUTODESTROY)<br>
> +        start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY;<br>
> +<br>
> +    caps = bhyveDriverGetCapabilities(privconn);<br>
> +    if (!caps)<br>
> +        return NULL;<br>
> +<br>
> +    if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt,<br>
> +                                       1 << VIR_DOMAIN_VIRT_BHYVE,<br>
> +                                       VIR_DOMAIN_XML_INACTIVE)) == NULL)<br>
> +        goto cleanup;<br>
> +<br>
> +    if (virDomainCreateXMLEnsureACL(conn, def) < 0)<br>
> +        goto cleanup;<br>
> +<br>
> +    if (!(vm = virDomainObjListAdd(privconn->domains, def,<br>
> +                                   privconn->xmlopt,<br>
> +                                   0, NULL)))<br>
> +        goto cleanup;<br>
> +    def = NULL;<br>
> +    vm->persistent = 0;<br>
> +<br>
> +    dom = virGetDomain(conn, vm->def->name, vm->def->uuid);<br>
> +    if (!dom)<br>
> +        goto cleanup;<br>
> +<br>
> +    dom->id = vm->def->id;<br>
> +<br>
> +    if (flags & VIR_DOMAIN_START_AUTODESTROY)<br>
> +        start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY;<br>
> +<br>
> +    if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0)<br>
> +            goto cleanup;<br>
<br>
</div></div>Do we really need this ACL check here?<br>
<div><div class="h5"><br>
> +    if (virDomainObjIsActive(vm)) {<br>
> +        virReportError(VIR_ERR_OPERATION_INVALID,<br>
> +                       "%s", _("Domain is already running"));<br>
> +        goto cleanup;<br>
> +    }<br>
> +<br>
> +    ret = virBhyveProcessStart(dom->conn, privconn, vm,<br>
> +                               VIR_DOMAIN_RUNNING_BOOTED,<br>
> +                               start_flags);<br>
> +    if (ret) {<br>
> +        virObjectUnref(dom);<br>
> +        dom = NULL;<br>
> +        goto cleanup;<br>
> +    }<br>
> +<br>
> + cleanup:<br>
> +    virObjectUnref(caps);<br>
> +    virDomainDefFree(def);<br>
> +    virObjectUnlock(vm);<br>
> +<br>
> +    return dom;<br>
> +}<br>
> +<br>
>  static virDriver bhyveDriver = {<br>
>      .no = VIR_DRV_BHYVE,<br>
>      .name = "bhyve",<br>
> @@ -1091,6 +1169,7 @@ static virDriver bhyveDriver = {<br>
>      .connectNumOfDefinedDomains = bhyveConnectNumOfDefinedDomains, /* 1.2.2 */<br>
>      .domainCreate = bhyveDomainCreate, /* 1.2.2 */<br>
>      .domainCreateWithFlags = bhyveDomainCreateWithFlags, /* 1.2.3 */<br>
> +    .domainCreateXML = bhyveDomainCreateXML, /* 1.2.4 */<br>
>      .domainDestroy = bhyveDomainDestroy, /* 1.2.2 */<br>
>      .domainLookupByUUID = bhyveDomainLookupByUUID, /* 1.2.2 */<br>
>      .domainLookupByName = bhyveDomainLookupByName, /* 1.2.2 */<br>
> --<br>
> 1.9.0<br>
><br>
</div></div>> --<br>
> libvir-list mailing list<br>
> <a href="mailto:libvir-list@redhat.com">libvir-list@redhat.com</a><br>
> <a href="https://www.redhat.com/mailman/listinfo/libvir-list" target="_blank">https://www.redhat.com/mailman/listinfo/libvir-list</a><br>
<span class="HOEnZb"><font color="#888888"><br>
Roman Bogorodskiy<br>
</font></span></blockquote></div><br></div>