[libvirt] [PATCH v13 06/49] lxc: use general virhostdev lists instead of its own
Daniel P. Berrange
berrange at redhat.com
Tue Mar 4 12:37:23 UTC 2014
On Sat, Mar 01, 2014 at 02:29:01PM +0800, Chunyan Liu wrote:
>
> Signed-off-by: Chunyan Liu <cyliu at suse.com>
> ---
> src/lxc/lxc_conf.h | 4 ----
> src/lxc/lxc_driver.c | 17 +++++++++--------
> src/lxc/lxc_hostdev.c | 49 ++++++++++++++++++++++++++++++++-----------------
> 3 files changed, 41 insertions(+), 29 deletions(-)
>
> diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
> index e04dcdd..5be159b 100644
> --- a/src/lxc/lxc_conf.h
> +++ b/src/lxc/lxc_conf.h
> @@ -93,10 +93,6 @@ struct _virLXCDriver {
> /* Immutable pointer, self-locking APIs */
> virDomainObjListPtr domains;
>
> - /* Immutable pointer. Requires lock to be held before
> - * calling APIs. */
> - virUSBDeviceListPtr activeUsbHostdevs;
> -
> /* Immutable pointer, self-locking APIs */
> virObjectEventStatePtr domainEventState;
>
> diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
> index 10e0fbb..f67a236 100644
> --- a/src/lxc/lxc_driver.c
> +++ b/src/lxc/lxc_driver.c
> @@ -71,6 +71,7 @@
> #include "virstring.h"
> #include "viraccessapicheck.h"
> #include "viraccessapichecklxc.h"
> +#include "virhostdev.h"
>
> #define VIR_FROM_THIS VIR_FROM_LXC
>
> @@ -1557,9 +1558,6 @@ static int lxcStateInitialize(bool privileged,
> if (!(lxc_driver->securityManager = lxcSecurityInit(cfg)))
> goto cleanup;
>
> - if ((lxc_driver->activeUsbHostdevs = virUSBDeviceListNew()) == NULL)
> - goto cleanup;
I think it would be desirable to call virHostdevManagerGetDefault()
here and save the pointer to the mgr in lxc_driver->hostdevmgr.
That avoids the later functions having to worry about failure of
the virHostdevManagerGetDefault function
> -
> if ((virLXCDriverGetCapabilities(lxc_driver, true)) == NULL)
> goto cleanup;
>
> @@ -1674,7 +1672,6 @@ static int lxcStateCleanup(void)
>
> virSysinfoDefFree(lxc_driver->hostsysinfo);
>
> - virObjectUnref(lxc_driver->activeUsbHostdevs);
> virObjectUnref(lxc_driver->caps);
> virObjectUnref(lxc_driver->securityManager);
> virObjectUnref(lxc_driver->xmlopt);
> @@ -4688,7 +4685,7 @@ cleanup:
>
>
> static int
> -lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
> +lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver ATTRIBUTE_UNUSED,
> virDomainObjPtr vm,
> virDomainDeviceDefPtr dev)
> {
> @@ -4697,6 +4694,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
> int idx, ret = -1;
> char *dst = NULL;
> virUSBDevicePtr usb = NULL;
> + virHostdevManagerPtr hostdev_mgr;
>
> if ((idx = virDomainHostdevFind(vm->def,
> dev->data.hostdev,
> @@ -4733,9 +4731,12 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
> VIR_WARN("cannot deny device %s for domain %s",
> dst, vm->def->name);
>
> - virObjectLock(driver->activeUsbHostdevs);
> - virUSBDeviceListDel(driver->activeUsbHostdevs, usb);
> - virObjectUnlock(driver->activeUsbHostdevs);
> + hostdev_mgr = virHostdevManagerGetDefault();
> + if (hostdev_mgr == NULL)
> + goto cleanup;
> + virObjectLock(hostdev_mgr->activeUsbHostdevs);
> + virUSBDeviceListDel(hostdev_mgr->activeUsbHostdevs, usb);
> + virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
Hmm, on second look, this 'goto cleanup' here is a problem - we've already
done the detach at this point, so we can't tolerate failure.
Regards,
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 :|
More information about the libvir-list
mailing list