提交 2a58ed0b 编写于 作者: C Chunyan Liu 提交者: Jim Fehlig

libxl: support creating guest with USB hostdev

Support creating guest with USB host device in config file.
Currently libxl only supports xen PV guest, and only supports
specifying USB host device by 'bus number' and 'device number',
for example:

    <hostdev mode='subsystem' type='usb' managed='no'>
      <source>
        <address bus='1' device='3'/>
      </source>
    </hostdev>
Signed-off-by: NChunyan Liu <cyliu@suse.com>
Signed-off-by: NJim Fehlig <jfehlig@suse.com>
上级 55931292
...@@ -1514,6 +1514,75 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg, ...@@ -1514,6 +1514,75 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg,
} }
#ifdef LIBXL_HAVE_PVUSB
int
libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev)
{
virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
return -1;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
return -1;
if (usbsrc->bus <= 0 || usbsrc->device <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("libxenlight supports only USB device "
"specified by busnum:devnum"));
return -1;
}
usbdev->u.hostdev.hostbus = usbsrc->bus;
usbdev->u.hostdev.hostaddr = usbsrc->device;
return 0;
}
static int
libxlMakeUSBList(virDomainDefPtr def, libxl_domain_config *d_config)
{
virDomainHostdevDefPtr *l_hostdevs = def->hostdevs;
size_t nhostdevs = def->nhostdevs;
size_t nusbdevs = 0;
libxl_device_usbdev *x_usbdevs;
size_t i, j;
if (nhostdevs == 0)
return 0;
if (VIR_ALLOC_N(x_usbdevs, nhostdevs) < 0)
return -1;
for (i = 0, j = 0; i < nhostdevs; i++) {
if (l_hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
if (l_hostdevs[i]->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
continue;
libxl_device_usbdev_init(&x_usbdevs[j]);
if (libxlMakeUSB(l_hostdevs[i], &x_usbdevs[j]) < 0)
goto error;
nusbdevs++;
j++;
}
VIR_SHRINK_N(x_usbdevs, nhostdevs, nhostdevs - nusbdevs);
d_config->usbdevs = x_usbdevs;
d_config->num_usbdevs = nusbdevs;
return 0;
error:
for (i = 0; i < nusbdevs; i++)
libxl_device_usbdev_dispose(&x_usbdevs[i]);
VIR_FREE(x_usbdevs);
return -1;
}
#endif
int int
libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev) libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev)
{ {
...@@ -1717,6 +1786,11 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports, ...@@ -1717,6 +1786,11 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports,
if (libxlMakePCIList(def, d_config) < 0) if (libxlMakePCIList(def, d_config) < 0)
return -1; return -1;
#ifdef LIBXL_HAVE_PVUSB
if (libxlMakeUSBList(def, d_config) < 0)
return -1;
#endif
/* /*
* Now that any potential VFBs are defined, update the build info with * Now that any potential VFBs are defined, update the build info with
* the data of the primary display. Some day libxl might implicitely do * the data of the primary display. Some day libxl might implicitely do
......
...@@ -184,6 +184,11 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports, ...@@ -184,6 +184,11 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports,
int int
libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev); libxlMakePCI(virDomainHostdevDefPtr hostdev, libxl_device_pci *pcidev);
# ifdef LIBXL_HAVE_PVUSB
int
libxlMakeUSB(virDomainHostdevDefPtr hostdev, libxl_device_usbdev *usbdev);
# endif
virDomainXMLOptionPtr virDomainXMLOptionPtr
libxlCreateXMLConf(void); libxlCreateXMLConf(void);
......
...@@ -731,9 +731,14 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, ...@@ -731,9 +731,14 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
int vnc_port; int vnc_port;
char *file; char *file;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI;
#ifdef LIBXL_HAVE_PVUSB
hostdev_flags |= VIR_HOSTDEV_SP_USB;
#endif
virHostdevReAttachDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME, virHostdevReAttachDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
vm->def, VIR_HOSTDEV_SP_PCI, NULL); vm->def, hostdev_flags, NULL);
VIR_FREE(priv->lockState); VIR_FREE(priv->lockState);
if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0) if (virDomainLockProcessPause(driver->lockManager, vm, &priv->lockState) < 0)
...@@ -1043,6 +1048,11 @@ libxlDomainStart(libxlDriverPrivatePtr driver, ...@@ -1043,6 +1048,11 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
libxl_asyncprogress_how aop_console_how; libxl_asyncprogress_how aop_console_how;
libxl_domain_restore_params params; libxl_domain_restore_params params;
unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI;
#ifdef LIBXL_HAVE_PVUSB
hostdev_flags |= VIR_HOSTDEV_SP_USB;
#endif
libxl_domain_config_init(&d_config); libxl_domain_config_init(&d_config);
...@@ -1118,7 +1128,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, ...@@ -1118,7 +1128,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
goto cleanup_dom; goto cleanup_dom;
if (virHostdevPrepareDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME, if (virHostdevPrepareDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
vm->def, VIR_HOSTDEV_SP_PCI) < 0) vm->def, hostdev_flags) < 0)
goto cleanup_dom; goto cleanup_dom;
/* Unlock virDomainObj while creating the domain */ /* Unlock virDomainObj while creating the domain */
......
...@@ -351,6 +351,11 @@ libxlReconnectDomain(virDomainObjPtr vm, ...@@ -351,6 +351,11 @@ libxlReconnectDomain(virDomainObjPtr vm,
int len; int len;
uint8_t *data = NULL; uint8_t *data = NULL;
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI;
#ifdef LIBXL_HAVE_PVUSB
hostdev_flags |= VIR_HOSTDEV_SP_USB;
#endif
virObjectLock(vm); virObjectLock(vm);
...@@ -378,7 +383,7 @@ libxlReconnectDomain(virDomainObjPtr vm, ...@@ -378,7 +383,7 @@ libxlReconnectDomain(virDomainObjPtr vm,
/* Update hostdev state */ /* Update hostdev state */
if (virHostdevUpdateActiveDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME, if (virHostdevUpdateActiveDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
vm->def, VIR_HOSTDEV_SP_PCI) < 0) vm->def, hostdev_flags) < 0)
goto out; goto out;
if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback) if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册