[libvirt] [PATCH v2 02/15] vbox: Close media when undefining domains

Dawid Zamirski posted 15 patches 8 years, 3 months ago
There is a newer version of this series
[libvirt] [PATCH v2 02/15] vbox: Close media when undefining domains
Posted by Dawid Zamirski 8 years, 3 months ago
When registering a VM we call OpenMedium on each disk image which adds it
to vbox's global media registry. Therefore, we should make sure to call
Close when unregistering VM so we cleanup the media registry entries
after ourselves - this does not remove disk image files. This follows
the behaviour of the VBoxManage unregistervm command.
---
 src/vbox/vbox_tmpl.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4aa5e9a63..2679b60f7 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -378,6 +378,8 @@ _unregisterMachine(vboxDriverPtr data, vboxIID *iid, IMachine **machine)
 {
     nsresult rc;
     vboxArray media = VBOX_ARRAY_INITIALIZER;
+    size_t i;
+
     rc = data->vboxObj->vtbl->FindMachine(data->vboxObj, iid->value, machine);
     if (NS_FAILED(rc)) {
         virReportError(VIR_ERR_NO_DOMAIN, "%s",
@@ -385,12 +387,24 @@ _unregisterMachine(vboxDriverPtr data, vboxIID *iid, IMachine **machine)
         return rc;
     }
 
-    /* We're not interested in the array returned by the Unregister method,
-     * but in the side effect of unregistering the virtual machine. In order
-     * to call the Unregister method correctly we need to use the vboxArray
-     * wrapper here. */
     rc = vboxArrayGetWithUintArg(&media, *machine, (*machine)->vtbl->Unregister,
-                                 CleanupMode_DetachAllReturnNone);
+                                 CleanupMode_DetachAllReturnHardDisksOnly);
+
+    if (NS_FAILED(rc))
+        goto cleanup;
+
+    /* close each medium attached to VM to remove from media registry */
+    for (i = 0; i < media.count; i++) {
+        IMedium *medium = media.items[i];
+
+        if (!medium)
+            continue;
+
+        /* it's ok to ignore failure here - e.g. it may be used by another VM */
+        ignore_value(medium->vtbl->Close(medium));
+    }
+
+ cleanup:
     vboxArrayUnalloc(&media);
     return rc;
 }
-- 
2.14.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 02/15] vbox: Close media when undefining domains
Posted by John Ferlan 8 years, 3 months ago

On 10/24/2017 03:35 PM, Dawid Zamirski wrote:
> When registering a VM we call OpenMedium on each disk image which adds it
> to vbox's global media registry. Therefore, we should make sure to call
> Close when unregistering VM so we cleanup the media registry entries
> after ourselves - this does not remove disk image files. This follows
> the behaviour of the VBoxManage unregistervm command.
> ---
>  src/vbox/vbox_tmpl.c | 24 +++++++++++++++++++-----
>  1 file changed, 19 insertions(+), 5 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

[I can push this before a v3 would be necessary - more later]

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list