提交 46a2ea36 编写于 作者: D Daniel P. Berrange

Introduce a new virDomainUpdateDeviceFlags public API

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
上级 987e31ed
......@@ -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
......
......@@ -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;
......
......@@ -3367,6 +3367,7 @@ static virDriver esxDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
NULL, /* domainGetAutostart */
NULL, /* domainSetAutostart */
esxDomainGetSchedulerType, /* domainGetSchedulerType */
......
......@@ -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
......
......@@ -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 ....
......@@ -2472,6 +2472,7 @@ static virDriver lxcDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
lxcDomainGetAutostart, /* domainGetAutostart */
lxcDomainSetAutostart, /* domainSetAutostart */
lxcGetSchedulerType, /* domainGetSchedulerType */
......
......@@ -757,6 +757,7 @@ static virDriver oneDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
oneGetAutostart, /* domainGetAutostart */
NULL, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */
......
......@@ -1509,6 +1509,7 @@ static virDriver openvzDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
openvzDomainGetAutostart, /* domainGetAutostart */
openvzDomainSetAutostart, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */
......
......@@ -1616,6 +1616,7 @@ virDriver phypDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
NULL, /* domainGetAutostart */
NULL, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */
......
......@@ -9914,6 +9914,7 @@ static virDriver qemuDriver = {
qemudDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
qemudDomainDetachDevice, /* domainDetachDevice */
qemudDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
qemudDomainGetAutostart, /* domainGetAutostart */
qemudDomainSetAutostart, /* domainSetAutostart */
qemuGetSchedulerType, /* domainGetSchedulerType */
......
......@@ -9460,6 +9460,7 @@ static virDriver remote_driver = {
remoteDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
remoteDomainDetachDevice, /* domainDetachDevice */
remoteDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
remoteDomainGetAutostart, /* domainGetAutostart */
remoteDomainSetAutostart, /* domainSetAutostart */
remoteDomainGetSchedulerType, /* domainGetSchedulerType */
......
......@@ -5255,6 +5255,7 @@ static virDriver testDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
testDomainGetAutostart, /* domainGetAutostart */
testDomainSetAutostart, /* domainSetAutostart */
testDomainGetSchedulerType, /* domainGetSchedulerType */
......
......@@ -1901,6 +1901,7 @@ static virDriver umlDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
umlDomainGetAutostart, /* domainGetAutostart */
umlDomainSetAutostart, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */
......
......@@ -7126,6 +7126,7 @@ virDriver NAME(Driver) = {
vboxDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
vboxDomainDetachDevice, /* domainDetachDevice */
vboxDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
NULL, /* domainGetAutostart */
NULL, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */
......
......@@ -1930,6 +1930,7 @@ static virDriver xenUnifiedDriver = {
xenUnifiedDomainAttachDeviceFlags, /* domainAttachDeviceFlags */
xenUnifiedDomainDetachDevice, /* domainDetachDevice */
xenUnifiedDomainDetachDeviceFlags, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
xenUnifiedDomainGetAutostart, /* domainGetAutostart */
xenUnifiedDomainSetAutostart, /* domainSetAutostart */
xenUnifiedDomainGetSchedulerType, /* domainGetSchedulerType */
......
......@@ -1716,6 +1716,7 @@ static virDriver xenapiDriver = {
NULL, /* domainAttachDeviceFlags */
NULL, /* domainDetachDevice */
NULL, /* domainDetachDeviceFlags */
NULL, /* domainUpdateDeviceFlags */
xenapiDomainGetAutostart, /* domainGetAutostart */
xenapiDomainSetAutostart, /* domainSetAutostart */
xenapiDomainGetSchedulerType, /* domainGetSchedulerType */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册