Adds the APIs for virNodeDeviceDettach , ReAttach and Reset

* include/libvirt/libvirt.h include/libvirt/libvirt.h.in
  src/driver.h src/libvirt.c src/libvirt_public.syms
  src/lxc_driver.c src/openvz_driver.c src/qemu_driver.c
  src/test.c src/uml_driver.c: add the public APIs for
  virNodeDeviceDettach virNodeDeviceReAttach and virNodeDeviceReset
  and extends the driver structure accordingly.
Daniel
This commit is contained in:
Daniel Veillard 2009-03-02 16:25:13 +00:00
parent d217641314
commit 737af2ea04
11 changed files with 177 additions and 0 deletions

View File

@ -1,3 +1,12 @@
Mon Mar 2 17:19:23 CET 2009 Daniel Veillard <veillard@redhat.com>
* include/libvirt/libvirt.h include/libvirt/libvirt.h.in
src/driver.h src/libvirt.c src/libvirt_public.syms
src/lxc_driver.c src/openvz_driver.c src/qemu_driver.c
src/test.c src/uml_driver.c: add the public APIs for
virNodeDeviceDettach virNodeDeviceReAttach and virNodeDeviceReset
and extends the driver structure accordingly.
Mon Mar 2 17:07:44 CET 2009 Daniel Veillard <veillard@redhat.com>
* configure.in po/POTFILES.in src/Makefile.am src/libvirt_private.syms

View File

@ -1053,6 +1053,10 @@ char * virNodeDeviceGetXMLDesc (virNodeDevicePtr dev,
int virNodeDeviceRef (virNodeDevicePtr dev);
int virNodeDeviceFree (virNodeDevicePtr dev);
int virNodeDeviceDettach (virNodeDevicePtr dev);
int virNodeDeviceReAttach (virNodeDevicePtr dev);
int virNodeDeviceReset (virNodeDevicePtr dev);
/*
* Domain Event Notification
*/

View File

@ -1053,6 +1053,10 @@ char * virNodeDeviceGetXMLDesc (virNodeDevicePtr dev,
int virNodeDeviceRef (virNodeDevicePtr dev);
int virNodeDeviceFree (virNodeDevicePtr dev);
int virNodeDeviceDettach (virNodeDevicePtr dev);
int virNodeDeviceReAttach (virNodeDevicePtr dev);
int virNodeDeviceReset (virNodeDevicePtr dev);
/*
* Domain Event Notification
*/

View File

@ -313,6 +313,16 @@ typedef virDomainPtr
unsigned long flags,
int retcode);
typedef int
(*virDrvNodeDeviceDettach)
(virNodeDevicePtr dev);
typedef int
(*virDrvNodeDeviceReAttach)
(virNodeDevicePtr dev);
typedef int
(*virDrvNodeDeviceReset)
(virNodeDevicePtr dev);
/**
* _virDriver:
*
@ -387,6 +397,9 @@ struct _virDriver {
virDrvDomainEventDeregister domainEventDeregister;
virDrvDomainMigratePrepare2 domainMigratePrepare2;
virDrvDomainMigrateFinish2 domainMigrateFinish2;
virDrvNodeDeviceDettach nodeDeviceDettach;
virDrvNodeDeviceReAttach nodeDeviceReAttach;
virDrvNodeDeviceReset nodeDeviceReset;
};
typedef int

View File

@ -7286,6 +7286,135 @@ virNodeDeviceRef(virNodeDevicePtr dev)
return 0;
}
/**
* virNodeDeviceAttach:
* @dev: pointer to the node device
*
* Dettach the node device from the node itself so that it may be
* assigned to a guest domain.
*
* Depending on the hypervisor, this may involve operations such
* as unbinding any device drivers from the device, binding the
* device to a dummy device driver and resetting the device.
*
* If the device is currently in use by the node, this method may
* fail.
*
* Once the device is not assigned to any guest, it may be re-attached
* to the node using the virNodeDeviceReattach() method.
*/
int
virNodeDeviceDettach(virNodeDevicePtr dev)
{
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
return (-1);
}
if (dev->conn->driver->nodeDeviceDettach) {
int ret;
ret = dev->conn->driver->nodeDeviceDettach (dev);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(dev->conn);
return (-1);
}
/**
* virNodeDeviceReAttach:
* @dev: pointer to the node device
*
* Re-attach a previously dettached node device to the node so that it
* may be used by the node again.
*
* Depending on the hypervisor, this may involve operations such
* as resetting the device, unbinding it from a dummy device driver
* and binding it to its appropriate driver.
*
* If the device is currently in use by a guest, this method may fail.
*/
int
virNodeDeviceReAttach(virNodeDevicePtr dev)
{
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
return (-1);
}
if (dev->conn->driver->nodeDeviceReAttach) {
int ret;
ret = dev->conn->driver->nodeDeviceReAttach (dev);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(dev->conn);
return (-1);
}
/**
* virNodeDeviceReset:
* @dev: pointer to the node device
*
* Reset a previously dettached node device to the node before or
* after assigning it to a guest.
*
* The exact reset semantics depends on the hypervisor and device
* type but, for example, KVM will attempt to reset PCI devices with
* a Function Level Reset, Secondary Bus Reset or a Power Management
* D-State reset.
*
* If the reset will affect other devices which are currently in use,
* this function may fail.
*/
int
virNodeDeviceReset(virNodeDevicePtr dev)
{
DEBUG("dev=%p, conn=%p", dev, dev ? dev->conn : NULL);
virResetLastError();
if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
return (-1);
}
if (dev->conn->driver->nodeDeviceReset) {
int ret;
ret = dev->conn->driver->nodeDeviceReset (dev);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
/* Copy to connection error object for back compatability */
virSetConnError(dev->conn);
return (-1);
}
/*
* Domain Event Notification

View File

@ -251,6 +251,9 @@ LIBVIRT_0.6.1 {
global:
virFreeError;
virSaveLastError;
virNodeDeviceDettach;
virNodeDeviceReAttach;
virNodeDeviceReset;
} LIBVIRT_0.6.0;
# .... define new API here using predicted next version number ....

View File

@ -1455,6 +1455,9 @@ static virDriver lxcDriver = {
NULL, /* domainEventDeregister */
NULL, /* domainMigratePrepare2 */
NULL, /* domainMigrateFinish2 */
NULL, /* nodeDeviceAttach */
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
};
static virStateDriver lxcStateDriver = {

View File

@ -1325,6 +1325,9 @@ static virDriver openvzDriver = {
NULL, /* domainEventDeregister */
NULL, /* domainMigratePrepare2 */
NULL, /* domainMigrateFinish2 */
NULL, /* nodeDeviceAttach */
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
};
int openvzRegister(void) {

View File

@ -4572,6 +4572,9 @@ static virDriver qemuDriver = {
qemudDomainEventDeregister, /* domainEventDeregister */
qemudDomainMigratePrepare2, /* domainMigratePrepare2 */
qemudDomainMigrateFinish2, /* domainMigrateFinish2 */
NULL, /* nodeDeviceDettach */
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
};

View File

@ -3527,6 +3527,9 @@ static virDriver testDriver = {
testDomainEventDeregister, /* domainEventDeregister */
NULL, /* domainMigratePrepare2 */
NULL, /* domainMigrateFinish2 */
NULL, /* nodeDeviceAttach */
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
};
static virNetworkDriver testNetworkDriver = {

View File

@ -1885,6 +1885,9 @@ static virDriver umlDriver = {
NULL, /* domainEventUnregister */
NULL, /* domainMigratePrepare2 */
NULL, /* domainMigrateFinish2 */
NULL, /* nodeDeviceAttach */
NULL, /* nodeDeviceReAttach */
NULL, /* nodeDeviceReset */
};