Re: [libvirt] [PATCH 1/8] Re-factor hostdev hotplug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 13, 2009 at 05:44:30PM +0100, Mark McLoughlin wrote:
> Re-factor the hostdev hotplug code so that we can easily add PCI
> hostdev hotplug to qemudDomainAttachHostDevice().
> 
> * src/qemu_driver.c: rename qemudDomainAttachHostDevice() to
>   qemudDomainAttachHostUsbDevice(); make qemudDomainAttachHostDevice()
>   handle all hostdev types
> 
> * src/libvirt_private.syms: export a couple of hostdev related
>   ToString() functions
> ---
>  src/libvirt_private.syms |    2 ++
>  src/qemu_driver.c        |   43 +++++++++++++++++++++++++++++++++----------
>  2 files changed, 35 insertions(+), 10 deletions(-)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index f20e5ce..642c2bc 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -88,6 +88,8 @@ virDomainGetRootFilesystem;
>  virDomainGraphicsTypeFromString;
>  virDomainGraphicsDefFree;
>  virDomainHostdevDefFree;
> +virDomainHostdevModeTypeToString;
> +virDomainHostdevSubsysTypeToString;
>  virDomainInputDefFree;
>  virDomainLifecycleTypeFromString;
>  virDomainLifecycleTypeToString;
> diff --git a/src/qemu_driver.c b/src/qemu_driver.c
> index 3ec8451..f181f27 100644
> --- a/src/qemu_driver.c
> +++ b/src/qemu_driver.c
> @@ -5148,9 +5148,9 @@ cleanup:
>      return -1;
>  }
>  
> -static int qemudDomainAttachHostDevice(virConnectPtr conn,
> -                                       virDomainObjPtr vm,
> -                                       virDomainDeviceDefPtr dev)
> +static int qemudDomainAttachHostUsbDevice(virConnectPtr conn,
> +                                          virDomainObjPtr vm,
> +                                          virDomainDeviceDefPtr dev)
>  {
>      int ret;
>      char *cmd, *reply;
> @@ -5200,6 +5200,34 @@ static int qemudDomainAttachHostDevice(virConnectPtr conn,
>      return 0;
>  }
>  
> +static int qemudDomainAttachHostDevice(virConnectPtr conn,
> +                                       struct qemud_driver *driver,
> +                                       virDomainObjPtr vm,
> +                                       virDomainDeviceDefPtr dev)
> +{
> +    virDomainHostdevDefPtr hostdev = dev->data.hostdev;
> +
> +    if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
> +        qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT,
> +                         _("hostdev mode '%s' not supported"),
> +                         virDomainHostdevModeTypeToString(hostdev->mode));
> +        return -1;
> +    }
> +
> +    if (qemuDomainSetDeviceOwnership(conn, driver, dev, 0) < 0)
> +        return -1;
> +
> +    switch (hostdev->source.subsys.type) {
> +    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
> +        return qemudDomainAttachHostUsbDevice(conn, vm, dev);
> +    default:
> +        qemudReportError(conn, dom, NULL, VIR_ERR_NO_SUPPORT,
> +                         _("hostdev subsys type '%s' not supported"),
> +                         virDomainHostdevSubsysTypeToString(hostdev->source.subsys.type));
> +        return -1;
> +    }
> +}
> +
>  static int qemudDomainAttachDevice(virDomainPtr dom,
>                                     const char *xml) {
>      struct qemud_driver *driver = dom->conn->privateData;
> @@ -5301,13 +5329,8 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
>          }
>      } else if (dev->type == VIR_DOMAIN_DEVICE_NET) {
>          ret = qemudDomainAttachNetDevice(dom->conn, driver, vm, dev, qemuCmdFlags);
> -    } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
> -               dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
> -               dev->data.hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
> -        if (qemuDomainSetDeviceOwnership(dom->conn, driver, dev, 0) < 0)
> -            goto cleanup;
> -
> -        ret = qemudDomainAttachHostDevice(dom->conn, vm, dev);
> +    } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
> +        ret = qemudDomainAttachHostDevice(dom->conn, driver, vm, dev);
>      } else {
>          qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
>                           _("device type '%s' cannot be attached"),


ACK


Danel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]