On Fri, Sep 13, 2013 at 11:34:35AM +0800, Chunyan Liu wrote:
Add pci passthrough to libxl driver, support attach-device,
detach-device and
start a vm with pci hostdev specified.
Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
po/POTFILES.in | 2 +-
src/libxl/libxl_conf.c | 63 +++++++
src/libxl/libxl_conf.h | 4 +
src/libxl/libxl_driver.c | 443 +++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 510 insertions(+), 2 deletions(-)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ec205c9..d01cb99 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -159,6 +159,7 @@ src/util/vireventpoll.c
src/util/virfile.c
src/util/virhash.c
src/util/virhook.c
+src/util/virhostdev.c
src/util/viridentity.c
src/util/virinitctl.c
src/util/viriptables.c
@@ -196,7 +197,6 @@ src/util/viruri.c
src/util/virusb.c
src/util/virutil.c
src/util/virxml.c
-src/util/virhostdev.c
src/vbox/vbox_MSCOMGlue.c
src/vbox/vbox_XPCOMCGlue.c
src/vbox/vbox_driver.c
This change is bogus - the sort order should be fixed in the previous
patch.
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index d4226b8..31d8f8a 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -335,6 +338,10 @@ libxlVmReap(libxlDriverPrivatePtr driver,
return -1;
}
+ hostdev_mgr = virHostdevManagerGetDefault();
You must check for NULL return.
+ virHostdevReAttachDomainHostdevs(hostdev_mgr,
LIBXL_DRIVER_NAME,
+ vm->def, VIR_SP_PCI_HOSTDEV);
+
libxlVmCleanup(driver, vm, reason);
return 0;
}
@@ -553,6 +560,7 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
int managed_save_fd = -1;
libxlDomainObjPrivatePtr priv = vm->privateData;
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+ virHostdevManagerPtr hostdev_mgr;
if (libxlDomainObjPrivateInitCtx(vm) < 0)
goto error;
@@ -611,6 +619,12 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
goto error;
}
+ VIR_DEBUG("Preparing host PCI devices");
+ hostdev_mgr = virHostdevManagerGetDefault();
Again check for NULL
+ if (virHostdevPrepareDomainHostdevs(hostdev_mgr,
LIBXL_DRIVER_NAME,
+ vm->def, VIR_SP_PCI_HOSTDEV) < 0)
+ goto error;
+
/* use as synchronous operations => ao_how = NULL and no intermediate reports
=> ao_progress = NULL */
if (restore_fd < 0)
@@ -706,6 +720,7 @@ libxlReconnectDomain(virDomainObjPtr vm,
libxl_dominfo d_info;
int len;
uint8_t *data = NULL;
+ virHostdevManagerPtr hostdev_mgr;
virObjectLock(vm);
@@ -729,6 +744,13 @@ libxlReconnectDomain(virDomainObjPtr vm,
/* Update domid in case it changed (e.g. reboot) while we were gone? */
vm->def->id = d_info.domid;
+
+ /* Update hostdev state */
+ hostdev_mgr = virHostdevManagerGetDefault();
Check for NULL.
Many more cases follow, so I won't repeat this point again.
static virDriver libxlDriver = {
.no = VIR_DRV_LIBXL,
- .name = "xenlight",
+ .name = LIBXL_DRIVER_NAME,
This change should be separate.
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|