]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Introduce a new virDomainUpdateDeviceFlags public API
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 22 Mar 2010 12:23:41 +0000 (12:23 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 26 Mar 2010 14:13:28 +0000 (14:13 +0000)
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

16 files changed:
include/libvirt/libvirt.h.in
src/driver.h
src/esx/esx_driver.c
src/libvirt.c
src/libvirt_public.syms
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

index 936382104e06cc44eebd5608ed4a50e55d05ecec..c70570e7edd6ea6a9acf8660edee6cb6be21340b 100644 (file)
@@ -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
index c6577ed7ef059458ecde92d398d9e4b5800498a6..16089eb46c420a2322b4b70b12cb4add9c8a7a8d 100644 (file)
@@ -203,6 +203,10 @@ typedef int
         (*virDrvDomainDetachDeviceFlags) (virDomainPtr domain,
                                           const char *xml,
                                           unsigned int flags);
+typedef int
+        (*virDrvDomainUpdateDeviceFlags) (virDomainPtr domain,
+                                          const char *xml,
+                                          unsigned int flags);
 typedef int
         (*virDrvDomainGetAutostart)    (virDomainPtr domain,
                                          int *autostart);
@@ -460,6 +464,7 @@ struct _virDriver {
     virDrvDomainAttachDeviceFlags      domainAttachDeviceFlags;
     virDrvDomainDetachDevice   domainDetachDevice;
     virDrvDomainDetachDeviceFlags      domainDetachDeviceFlags;
+    virDrvDomainUpdateDeviceFlags      domainUpdateDeviceFlags;
     virDrvDomainGetAutostart   domainGetAutostart;
     virDrvDomainSetAutostart   domainSetAutostart;
     virDrvDomainGetSchedulerType       domainGetSchedulerType;
index 90cedd5ecc35cb1ee4fe61ea00b09de2eda4570b..bbe8a519b93dc8b4f94e8d963f8d4a28650101c8 100644 (file)
@@ -3367,6 +3367,7 @@ static virDriver esxDriver = {
     NULL,                            /* domainAttachDeviceFlags */
     NULL,                            /* domainDetachDevice */
     NULL,                            /* domainDetachDeviceFlags */
+    NULL,                            /* domainUpdateDeviceFlags */
     NULL,                            /* domainGetAutostart */
     NULL,                            /* domainSetAutostart */
     esxDomainGetSchedulerType,       /* domainGetSchedulerType */
index 50239ff2f47df170f220f840428f5ee549a16abf..8424eaf381ad507486f58d2f2a535b60194cf88a 100644 (file)
@@ -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
@@ -5335,6 +5343,64 @@ error:
     return -1;
 }
 
+/**
+ * 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
index 6cb03a5a04e7cc38aabc42a66b6184fe934205d4..f1491e9afa5e46f9082e514a78acb9d4184d8d5a 100644 (file)
@@ -364,6 +364,7 @@ LIBVIRT_0.7.8 {
         virDomainMigrateSetMaxDowntime;
         virConnectDomainEventRegisterAny;
         virConnectDomainEventDeregisterAny;
+        virDomainUpdateDeviceFlags;
 } LIBVIRT_0.7.7;
 
 # .... define new API here using predicted next version number ....
index d619fd745ac9f9f9b85c4e2262b3078e300bac3a..e0e60c9a281c631f7145b96bb2df96e1a5d79cef 100644 (file)
@@ -2472,6 +2472,7 @@ static virDriver lxcDriver = {
     NULL, /* domainAttachDeviceFlags */
     NULL, /* domainDetachDevice */
     NULL, /* domainDetachDeviceFlags */
+    NULL, /* domainUpdateDeviceFlags */
     lxcDomainGetAutostart, /* domainGetAutostart */
     lxcDomainSetAutostart, /* domainSetAutostart */
     lxcGetSchedulerType, /* domainGetSchedulerType */
index 2957ac99e3d59338b348fb0a941910ab6c28d5b7..d8c5059a8cd2a0c6209c1386671fa931be2c6d93 100644 (file)
@@ -757,6 +757,7 @@ static virDriver oneDriver = {
     NULL, /* domainAttachDeviceFlags */
     NULL, /* domainDetachDevice */
     NULL, /* domainDetachDeviceFlags */
+    NULL, /* domainUpdateDeviceFlags */
     oneGetAutostart, /* domainGetAutostart */
     NULL, /* domainSetAutostart */
     NULL, /* domainGetSchedulerType */
index d9b15ca5c5a8a5f22e8fc81fd84deaa92a4b895f..da094ffec6799f22a51705e658f1982a41b318b0 100644 (file)
@@ -1509,6 +1509,7 @@ static virDriver openvzDriver = {
     NULL, /* domainAttachDeviceFlags */
     NULL, /* domainDetachDevice */
     NULL, /* domainDetachDeviceFlags */
+    NULL, /* domainUpdateDeviceFlags */
     openvzDomainGetAutostart, /* domainGetAutostart */
     openvzDomainSetAutostart, /* domainSetAutostart */
     NULL, /* domainGetSchedulerType */
index 6cea3d14282ebc42ddc50cb5fc133f5fdb667b56..4f7efdbb4867ab484375a4cccea30afda0848970 100644 (file)
@@ -1616,6 +1616,7 @@ virDriver phypDriver = {
     NULL,                       /* domainAttachDeviceFlags */
     NULL,                       /* domainDetachDevice */
     NULL,                       /* domainDetachDeviceFlags */
+    NULL,                       /* domainUpdateDeviceFlags */
     NULL,                       /* domainGetAutostart */
     NULL,                       /* domainSetAutostart */
     NULL,                       /* domainGetSchedulerType */
index 214324def01ff6c1ab434c9b2539a19e2a89dcfe..3c7c1d3dc60968930a693825b00037759cb50645 100644 (file)
@@ -9914,6 +9914,7 @@ static virDriver qemuDriver = {
     qemudDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
     qemudDomainDetachDevice, /* domainDetachDevice */
     qemudDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
+    NULL, /* domainUpdateDeviceFlags */
     qemudDomainGetAutostart, /* domainGetAutostart */
     qemudDomainSetAutostart, /* domainSetAutostart */
     qemuGetSchedulerType, /* domainGetSchedulerType */
index e28a364dec84f03adeeaf47ba80787712bf21c4f..c01cdadd76af03a365b6040643d52c2c50a47b9f 100644 (file)
@@ -9460,6 +9460,7 @@ static virDriver remote_driver = {
     remoteDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
     remoteDomainDetachDevice, /* domainDetachDevice */
     remoteDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
+    NULL, /* domainUpdateDeviceFlags */
     remoteDomainGetAutostart, /* domainGetAutostart */
     remoteDomainSetAutostart, /* domainSetAutostart */
     remoteDomainGetSchedulerType, /* domainGetSchedulerType */
index 204265f286ca12670e1b4c8819ce403af626859a..4af2d001d257414b5c56436e5535da265786af7e 100644 (file)
@@ -5255,6 +5255,7 @@ static virDriver testDriver = {
     NULL, /* domainAttachDeviceFlags */
     NULL, /* domainDetachDevice */
     NULL, /* domainDetachDeviceFlags */
+    NULL, /* domainUpdateDeviceFlags */
     testDomainGetAutostart, /* domainGetAutostart */
     testDomainSetAutostart, /* domainSetAutostart */
     testDomainGetSchedulerType, /* domainGetSchedulerType */
index 798df53e9e98a0777c8bda848a902fe203fa0265..008eb8d4d37da15e3017a13fee8a5cde21abbf88 100644 (file)
@@ -1901,6 +1901,7 @@ static virDriver umlDriver = {
     NULL, /* domainAttachDeviceFlags */
     NULL, /* domainDetachDevice */
     NULL, /* domainDetachDeviceFlags */
+    NULL, /* domainUpdateDeviceFlags */
     umlDomainGetAutostart, /* domainGetAutostart */
     umlDomainSetAutostart, /* domainSetAutostart */
     NULL, /* domainGetSchedulerType */
index 2e81f42d51961ea6fa1ee828effd785f0929278b..599ee90cd39d2c35d1554361ffddc2a5a2449948 100644 (file)
@@ -7126,6 +7126,7 @@ virDriver NAME(Driver) = {
     vboxDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
     vboxDomainDetachDevice, /* domainDetachDevice */
     vboxDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
+    NULL, /* domainUpdateDeviceFlags */
     NULL, /* domainGetAutostart */
     NULL, /* domainSetAutostart */
     NULL, /* domainGetSchedulerType */
index f4e65c44f8b696fb06e5b137e3f066bd322b4d14..0f0912cc6dbbe40d7ed822734ed617e64ff6aad1 100644 (file)
@@ -1930,6 +1930,7 @@ static virDriver xenUnifiedDriver = {
     xenUnifiedDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
     xenUnifiedDomainDetachDevice, /* domainDetachDevice */
     xenUnifiedDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
+    NULL, /* domainUpdateDeviceFlags */
     xenUnifiedDomainGetAutostart, /* domainGetAutostart */
     xenUnifiedDomainSetAutostart, /* domainSetAutostart */
     xenUnifiedDomainGetSchedulerType, /* domainGetSchedulerType */
index b4ee4cf84012c7ccfebe6412a1efb0d736cecbef..6e1183d356f7b38fa5a16351ffa80bd0f36522b5 100644 (file)
@@ -1716,6 +1716,7 @@ static virDriver xenapiDriver = {
     NULL, /* domainAttachDeviceFlags */
     NULL, /* domainDetachDevice */
     NULL, /* domainDetachDeviceFlags */
+    NULL, /* domainUpdateDeviceFlags */
     xenapiDomainGetAutostart, /* domainGetAutostart */
     xenapiDomainSetAutostart, /* domainSetAutostart */
     xenapiDomainGetSchedulerType, /* domainGetSchedulerType */