The current virDomainAttachDevice API can be (ab)used to change
the media of an existing CDROM/Floppy device. Going forward there
will be more devices that can be configured on the fly and overloading
virDomainAttachDevice for this is not too pleasant. This patch adds
a new virDomainUpdateDeviceFlags() explicitly just for modifying
existing devices.
* include/libvirt/libvirt.h.in: Add virDomainUpdateDeviceFlags
* src/driver.h: Internal API for virDomainUpdateDeviceFlags
* src/libvirt.c, src/libvirt_public.syms: Glue public API to
driver API
* src/esx/esx_driver.c, src/lxc/lxc_driver.c, src/opennebula/one_driver.c,
src/openvz/openvz_driver.c, src/phyp/phyp_driver.c, src/qemu/qemu_driver.c,
src/remote/remote_driver.c, src/test/test_driver.c, src/uml/uml_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xen_driver.c, src/xenapi/xenapi_driver.c: Add
stubs for new driver entry point
---
include/libvirt/libvirt.h.in | 2 +
src/driver.h | 5 +++
src/esx/esx_driver.c | 1 +
src/libvirt.c | 68 +++++++++++++++++++++++++++++++++++++++++-
src/libvirt_public.syms | 1 +
src/lxc/lxc_driver.c | 1 +
src/opennebula/one_driver.c | 1 +
src/openvz/openvz_driver.c | 1 +
src/phyp/phyp_driver.c | 1 +
src/qemu/qemu_driver.c | 1 +
src/remote/remote_driver.c | 1 +
src/test/test_driver.c | 1 +
src/uml/uml_driver.c | 1 +
src/vbox/vbox_tmpl.c | 1 +
src/xen/xen_driver.c | 1 +
src/xenapi/xenapi_driver.c | 1 +
16 files changed, 87 insertions(+), 1 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index aaefa09..e71a30c 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -878,6 +878,8 @@ int virDomainAttachDeviceFlags(virDomainPtr domain,
const char *xml, unsigned int flags);
int virDomainDetachDeviceFlags(virDomainPtr domain,
const char *xml, unsigned int flags);
+int virDomainUpdateDeviceFlags(virDomainPtr domain,
+ const char *xml, unsigned int flags);
/*
* NUMA support
diff --git a/src/driver.h b/src/driver.h
index 362533f..bec5545 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -204,6 +204,10 @@ typedef int
const char *xml,
unsigned int flags);
typedef int
+ (*virDrvDomainUpdateDeviceFlags) (virDomainPtr domain,
+ const char *xml,
+ unsigned int flags);
+typedef int
(*virDrvDomainGetAutostart) (virDomainPtr domain,
int *autostart);
typedef int
@@ -448,6 +452,7 @@ struct _virDriver {
virDrvDomainAttachDeviceFlags domainAttachDeviceFlags;
virDrvDomainDetachDevice domainDetachDevice;
virDrvDomainDetachDeviceFlags domainDetachDeviceFlags;
+ virDrvDomainUpdateDeviceFlags domainUpdateDeviceFlags;
virDrvDomainGetAutostart domainGetAutostart;
virDrvDomainSetAutostart domainSetAutostart;
virDrvDomainGetSchedulerType domainGetSchedulerType;
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 30a1adb..b566d77 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -3367,6 +3367,7 @@ static virDriver esxDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
NULL, /* domainGetAutostart */
NULL, /* domainSetAutostart */
esxDomainGetSchedulerType, /* domainGetSchedulerType */
diff --git a/src/libvirt.c b/src/libvirt.c
index 7b74fd9..66a4d6c 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -1868,7 +1868,7 @@ error:
*
* Deprecated after 0.4.6.
* Renamed to virDomainCreateXML() providing identical functionality.
- * This existing name will left indefinitely for API compatability.
+ * This existing name will left indefinitely for API compatibility.
*
* Returns a new domain object or NULL in case of failure
*/
@@ -5147,6 +5147,10 @@ error:
* Create a virtual device attachment to backend. This function,
* having hotplug semantics, is only allowed on an active domain.
*
+ * For compatibility, this method can also be used to change the media
+ * in an existing CDROM/Floppy device, however, applications are
+ * recommended to use the virDomainUpdateDeviceFlag method instead.
+ *
* Returns 0 in case of success, -1 in case of failure.
*/
int
@@ -5201,6 +5205,10 @@ error:
* return failure if LIVE is specified but it only supports modifying the
* persisted device allocation.
*
+ * For compatibility, this method can also be used to change the media
+ * in an existing CDROM/Floppy device, however, applications are
+ * recommended to use the virDomainUpdateDeviceFlag method instead.
+ *
* Returns 0 in case of success, -1 in case of failure.
*/
int
@@ -5336,6 +5344,64 @@ error:
}
/**
+ * virDomainUpdateDeviceFlags:
+ * @domain: pointer to domain object
+ * @xml: pointer to XML description of one device
+ * @flags: an OR'ed set of virDomainDeviceModifyFlags
+ *
+ * Change a virtual device on a domain, using the flags parameter
+ * to control how the device is changed. VIR_DOMAIN_DEVICE_MODIFY_CURRENT
+ * specifies that the device change is made based on current domain
+ * state. VIR_DOMAIN_DEVICE_MODIFY_LIVE specifies that the device shall be
+ * changed on the active domain instance only and is not added to the
+ * persisted domain configuration. VIR_DOMAIN_DEVICE_MODIFY_CONFIG
+ * specifies that the device shall be changed on the persisted domain
+ * configuration only. Note that the target hypervisor must return an
+ * error if unable to satisfy flags. E.g. the hypervisor driver will
+ * return failure if LIVE is specified but it only supports modifying the
+ * persisted device allocation.
+ *
+ * This method is used for actions such changing CDROM/Floppy device
+ * media, altering the graphics configuration such as password,
+ * reconfiguring the NIC device backend connectivity, etc.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+int
+virDomainUpdateDeviceFlags(virDomainPtr domain,
+ const char *xml, unsigned int flags)
+{
+ virConnectPtr conn;
+ DEBUG("domain=%p, xml=%s, flags=%d", domain, xml, flags);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+ virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+ return (-1);
+ }
+ if (domain->conn->flags & VIR_CONNECT_RO) {
+ virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ goto error;
+ }
+ conn = domain->conn;
+
+ if (conn->driver->domainUpdateDeviceFlags) {
+ int ret;
+ ret = conn->driver->domainUpdateDeviceFlags(domain, xml, flags);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ virDispatchError(domain->conn);
+ return -1;
+}
+
+/**
* virNodeGetCellsFreeMemory:
* @conn: pointer to the hypervisor connection
* @freeMems: pointer to the array of unsigned long long
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 623e53c..7247125 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -362,6 +362,7 @@ LIBVIRT_0.7.8 {
global:
virStorageVolWipe;
virDomainMigrateSetMaxDowntime;
+ virDomainUpdateDeviceFlags;
} LIBVIRT_0.7.7;
# .... define new API here using predicted next version number ....
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index ba13065..88c3c55 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2428,6 +2428,7 @@ static virDriver lxcDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
lxcDomainGetAutostart, /* domainGetAutostart */
lxcDomainSetAutostart, /* domainSetAutostart */
lxcGetSchedulerType, /* domainGetSchedulerType */
diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c
index e1d1efc..23f4c09 100644
--- a/src/opennebula/one_driver.c
+++ b/src/opennebula/one_driver.c
@@ -757,6 +757,7 @@ static virDriver oneDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
oneGetAutostart, /* domainGetAutostart */
NULL, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 50aadfc..ea71d3b 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1509,6 +1509,7 @@ static virDriver openvzDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
openvzDomainGetAutostart, /* domainGetAutostart */
openvzDomainSetAutostart, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index e4d67dc..909de77 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1616,6 +1616,7 @@ virDriver phypDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
NULL, /* domainGetAutostart */
NULL, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 257f914..caa6442 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9644,6 +9644,7 @@ static virDriver qemuDriver = {
qemudDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
qemudDomainDetachDevice, /* domainDetachDevice */
qemudDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
qemudDomainGetAutostart, /* domainGetAutostart */
qemudDomainSetAutostart, /* domainSetAutostart */
qemuGetSchedulerType, /* domainGetSchedulerType */
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 1476f19..2088bed 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -9157,6 +9157,7 @@ static virDriver remote_driver = {
remoteDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
remoteDomainDetachDevice, /* domainDetachDevice */
remoteDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
remoteDomainGetAutostart, /* domainGetAutostart */
remoteDomainSetAutostart, /* domainSetAutostart */
remoteDomainGetSchedulerType, /* domainGetSchedulerType */
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index f54ebae..5254851 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5214,6 +5214,7 @@ static virDriver testDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
testDomainGetAutostart, /* domainGetAutostart */
testDomainSetAutostart, /* domainSetAutostart */
testDomainGetSchedulerType, /* domainGetSchedulerType */
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index bf06787..5031d39 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1901,6 +1901,7 @@ static virDriver umlDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
umlDomainGetAutostart, /* domainGetAutostart */
umlDomainSetAutostart, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 1765d63..f398041 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -7030,6 +7030,7 @@ virDriver NAME(Driver) = {
vboxDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
vboxDomainDetachDevice, /* domainDetachDevice */
vboxDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
NULL, /* domainGetAutostart */
NULL, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 204ed91..1ff3e44 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1875,6 +1875,7 @@ static virDriver xenUnifiedDriver = {
xenUnifiedDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
xenUnifiedDomainDetachDevice, /* domainDetachDevice */
xenUnifiedDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
xenUnifiedDomainGetAutostart, /* domainGetAutostart */
xenUnifiedDomainSetAutostart, /* domainSetAutostart */
xenUnifiedDomainGetSchedulerType, /* domainGetSchedulerType */
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index ac00424..a06781a 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -1716,6 +1716,7 @@ static virDriver xenapiDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
+ NULL, /* domainUpdateDeviceFlags */
xenapiDomainGetAutostart, /* domainGetAutostart */
xenapiDomainSetAutostart, /* domainSetAutostart */
xenapiDomainGetSchedulerType, /* domainGetSchedulerType */
--
1.6.6.1