summaryrefslogtreecommitdiffstats
path: root/src/launch-libvirt.c
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-10-08 17:26:53 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-10-09 09:45:42 +0100
commit0a85fbc946d7838366c35c0425efddb1a91f593c (patch)
treebfc621b7075d563a37fdaafda05b594c0522c9c6 /src/launch-libvirt.c
parent18b7f09f366d518050f467d0944c81c82fd5e39e (diff)
downloadlibguestfs-0a85fbc946d7838366c35c0425efddb1a91f593c.tar.gz
libguestfs-0a85fbc946d7838366c35c0425efddb1a91f593c.tar.xz
libguestfs-0a85fbc946d7838366c35c0425efddb1a91f593c.zip
Add support for hotplugging (removing disks).
New API: remove-drive. Note because of a bug in fuser, this only works with psmisc >= 22.20. This also updates the hotplugging tests.
Diffstat (limited to 'src/launch-libvirt.c')
-rw-r--r--src/launch-libvirt.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index 3eab5676..5b7897d7 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -1410,6 +1410,40 @@ hot_add_drive_libvirt (guestfs_h *g, struct drive *drv, size_t drv_index)
return -1;
}
+/* Hot-remove a drive. Note the appliance is up when this is called. */
+static int
+hot_remove_drive_libvirt (guestfs_h *g, struct drive *drv, size_t drv_index)
+{
+ virConnectPtr conn = g->virt.connv;
+ virDomainPtr dom = g->virt.domv;
+ xmlChar *xml = NULL;
+
+ if (!conn || !dom) {
+ /* This is essentially an internal error if it happens. */
+ error (g, "%s: conn == NULL or dom == NULL", __func__);
+ return -1;
+ }
+
+ /* Re-create the XML for the disk. */
+ xml = construct_libvirt_xml_hot_add_disk (g, drv, drv_index);
+ if (xml == NULL)
+ return -1;
+
+ /* Detach it. */
+ if (virDomainDetachDeviceFlags (dom, (char *) xml,
+ VIR_DOMAIN_DEVICE_MODIFY_LIVE) == -1) {
+ libvirt_error (g, _("could not detach disk from libvirt domain"));
+ goto error;
+ }
+
+ free (xml);
+ return 0;
+
+ error:
+ free (xml);
+ return -1;
+}
+
static xmlChar *
construct_libvirt_xml_hot_add_disk (guestfs_h *g, struct drive *drv,
size_t drv_index)
@@ -1449,6 +1483,7 @@ struct attach_ops attach_ops_libvirt = {
.shutdown = shutdown_libvirt,
.max_disks = max_disks_libvirt,
.hot_add_drive = hot_add_drive_libvirt,
+ .hot_remove_drive = hot_remove_drive_libvirt,
};
#else /* no libvirt or libxml2 at compile time */