Re: [RFC PATCH v2 REBASE 02/18] conf: Introduce new hostdev device type mdev

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

 



On Mon, Feb 20, 2017 at 03:28:15PM +0100, Erik Skultety wrote:
> A mediated device will be identified by a UUID of the user pre-created
> mediated device. The data necessary to identify a mediated device can
> be easily extended in the future, e.g. when auto-creation of mediated
> devices should be enabled.
> 
> Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
> ---
>  src/conf/domain_conf.c              | 36 +++++++++++++++++++++++++++++++++++-
>  src/conf/domain_conf.h              |  9 +++++++++
>  src/qemu/qemu_domain.c              |  1 +
>  src/qemu/qemu_hotplug.c             |  2 ++
>  src/security/security_apparmor.c    |  3 +++
>  src/security/security_dac.c         |  2 ++
>  src/security/security_selinux.c     |  2 ++
>  tests/domaincapsschemadata/full.xml |  1 +
>  8 files changed, 55 insertions(+), 1 deletion(-)

Patches 04/18 and 06/18 should be merged into this one, it adds the same
functionality.

> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index a56ea82..83aa15f 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -56,6 +56,7 @@
>  #include "virstring.h"
>  #include "virnetdev.h"
>  #include "virhostdev.h"
> +#include "virmdev.h"
>  
>  #define VIR_FROM_THIS VIR_FROM_DOMAIN
>  
> @@ -649,7 +650,8 @@ VIR_ENUM_IMPL(virDomainHostdevSubsys, VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST,
>                "usb",
>                "pci",
>                "scsi",
> -              "scsi_host")
> +              "scsi_host",
> +              "mdev")
>  
>  VIR_ENUM_IMPL(virDomainHostdevSubsysPCIBackend,
>                VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST,
> @@ -668,6 +670,11 @@ VIR_ENUM_IMPL(virDomainHostdevSubsysSCSIHostProtocol,
>                "none",
>                "vhost")
>  
> +VIR_ENUM_IMPL(virMediatedDeviceModel,
> +              VIR_MDEV_MODEL_TYPE_LAST,
> +              "default",
> +              "vfio-pci")
> +
>  VIR_ENUM_IMPL(virDomainHostdevCaps, VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST,
>                "storage",
>                "misc",
> @@ -6349,10 +6356,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
>      char *sgio = NULL;
>      char *rawio = NULL;
>      char *backendStr = NULL;
> +    char *model = NULL;
>      int backend;
>      int ret = -1;
>      virDomainHostdevSubsysPCIPtr pcisrc = &def->source.subsys.u.pci;
>      virDomainHostdevSubsysSCSIPtr scsisrc = &def->source.subsys.u.scsi;
> +    virDomainHostdevSubsysMediatedDevPtr mdevsrc = &def->source.subsys.u.mdev;
>  
>      /* @managed can be read from the xml document - it is always an
>       * attribute of the toplevel element, no matter what type of
> @@ -6432,6 +6441,21 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
>          }
>      }
>  
> +    if (model) {
> +        if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
> +            virReportError(VIR_ERR_XML_ERROR, "%s",
> +                           _("model is only supported with mediated devices"));
> +            goto error;
> +        }
> +
> +        if ((mdevsrc->model = virMediatedDeviceModelTypeFromString(model)) <= 0) {
> +            virReportError(VIR_ERR_XML_ERROR,
> +                           _("unknown hostdev model '%s'"),
> +                           model);
> +            goto error;
> +        }

This condition means that "VIR_MDEV_MODEL_TYPE_DEFAULT" is also unknown
which is not correct, however your code later on depends on this check because
in function virDomainHostdevSubsysMediatedDevDefParseXML you require that the
model must by > 0.  This should be handled by postParse code to check whether
the model has a correct value.

If you want to check whether model attribute was provided you shouldn't do
it by the parsed value but whether the attribute was present in the XML.

The rest of the patch looks good.

Pavel

> +    }
> +
>      switch (def->source.subsys.type) {
>      case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
>          if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, def, flags) < 0)
> @@ -6464,6 +6488,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
>          if (virDomainHostdevSubsysSCSIVHostDefParseXML(sourcenode, def) < 0)
>              goto error;
>          break;
> +    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
> +        break;
>  
>      default:
>          virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> @@ -13297,6 +13323,7 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr xmlopt,
>              }
>              break;
>          case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
> +        case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
>          case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
>              break;
>          }
> @@ -14188,6 +14215,7 @@ virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
>              return 1;
>          else
>              return 0;
> +    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
>      case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
>          return 0;
>      }
> @@ -23121,6 +23149,7 @@ virDomainHostdevDefFormat(virBufferPtr buf,
>  {
>      const char *mode = virDomainHostdevModeTypeToString(def->mode);
>      virDomainHostdevSubsysSCSIPtr scsisrc = &def->source.subsys.u.scsi;
> +    virDomainHostdevSubsysMediatedDevPtr mdevsrc = &def->source.subsys.u.mdev;
>      const char *type;
>  
>      if (!mode) {
> @@ -23170,6 +23199,11 @@ virDomainHostdevDefFormat(virBufferPtr buf,
>              virBufferAsprintf(buf, " rawio='%s'",
>                                virTristateBoolTypeToString(scsisrc->rawio));
>          }
> +
> +        if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
> +            mdevsrc->model)
> +            virBufferAsprintf(buf, " model='%s'",
> +                              virMediatedDeviceModelTypeToString(mdevsrc->model));
>      }
>      virBufferAddLit(buf, ">\n");
>      virBufferAdjustIndent(buf, 2);
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index 7e1afa4..e1a7a36 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -295,6 +295,7 @@ typedef enum {
>      VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI,
>      VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI,
>      VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST,
> +    VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV,
>  
>      VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST
>  } virDomainHostdevSubsysType;
> @@ -369,6 +370,13 @@ struct _virDomainHostdevSubsysSCSI {
>      } u;
>  };
>  
> +typedef struct _virDomainHostdevSubsysMediatedDev virDomainHostdevSubsysMediatedDev;
> +typedef virDomainHostdevSubsysMediatedDev *virDomainHostdevSubsysMediatedDevPtr;
> +struct _virDomainHostdevSubsysMediatedDev {
> +    int model;                          /* enum virMediatedDeviceModelType */
> +    char uuidstr[VIR_UUID_STRING_BUFLEN];   /* mediated device's uuid string */
> +};
> +
>  typedef enum {
>      VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_NONE,
>      VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST,
> @@ -394,6 +402,7 @@ struct _virDomainHostdevSubsys {
>          virDomainHostdevSubsysPCI pci;
>          virDomainHostdevSubsysSCSI scsi;
>          virDomainHostdevSubsysSCSIVHost scsi_host;
> +        virDomainHostdevSubsysMediatedDev mdev;
>      } u;
>  };
>  
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index ea4b282..b905f9a 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -6978,6 +6978,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
>              break;
>          }
>  
> +        case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
>          case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
>              break;
>          }
> diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> index 2f209f1..96c27ad 100644
> --- a/src/qemu/qemu_hotplug.c
> +++ b/src/qemu/qemu_hotplug.c
> @@ -3854,6 +3854,8 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
>      case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
>          qemuDomainRemoveSCSIVHostDevice(driver, vm, hostdev);
>          break;
> +    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
> +        break;
>      case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
>          break;
>      }
> diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
> index 0d3e891..f5b72e1 100644
> --- a/src/security/security_apparmor.c
> +++ b/src/security/security_apparmor.c
> @@ -901,6 +901,9 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
>          break;
>      }
>  
> +    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
> +        break;
> +
>      case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
>          ret = 0;
>          break;
> diff --git a/src/security/security_dac.c b/src/security/security_dac.c
> index 6721917..ecce1d3 100644
> --- a/src/security/security_dac.c
> +++ b/src/security/security_dac.c
> @@ -964,6 +964,7 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
>          break;
>      }
>  
> +    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
>      case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
>          ret = 0;
>          break;
> @@ -1119,6 +1120,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr,
>          break;
>      }
>  
> +    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
>      case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
>          ret = 0;
>          break;
> diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
> index e22de06..e152c72 100644
> --- a/src/security/security_selinux.c
> +++ b/src/security/security_selinux.c
> @@ -1782,6 +1782,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
>          break;
>      }
>  
> +    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
>      case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
>          ret = 0;
>          break;
> @@ -2009,6 +2010,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
>          break;
>      }
>  
> +    case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
>      case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
>          ret = 0;
>          break;
> diff --git a/tests/domaincapsschemadata/full.xml b/tests/domaincapsschemadata/full.xml
> index 6abd499..6b43069 100644
> --- a/tests/domaincapsschemadata/full.xml
> +++ b/tests/domaincapsschemadata/full.xml
> @@ -88,6 +88,7 @@
>          <value>pci</value>
>          <value>scsi</value>
>          <value>scsi_host</value>
> +        <value>mdev</value>
>        </enum>
>        <enum name='capsType'>
>          <value>storage</value>
> -- 
> 2.10.2
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: signature.asc
Description: Digital signature

--
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]
  Powered by Linux