From 0a85fbc946d7838366c35c0425efddb1a91f593c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 8 Oct 2012 17:26:53 +0100 Subject: 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. --- src/launch-libvirt.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/launch-libvirt.c') 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 */ -- cgit