Re: [libvirt] [PATCH 4/4 v3] qemu_hostdev: Add support to install port profile and mac address on hostdevs

2012-03-06 Thread Laine Stump
On 03/05/2012 08:12 PM, Roopa Prabhu wrote:
> From: Roopa Prabhu 
>
> These changes are applied only if the hostdev has a parent net device.
> If the parent netdevice has virtual port information, the original virtualport
> associate functions are called (these set and restore both mac and port 
> profile
> on an interface). Else, only mac address is set on the device
> using other methods depending on if its a sriov device or not.
>
> Changes also include hotplug pci devices
>
> Signed-off-by: Roopa Prabhu 
> ---
>  src/qemu/qemu_hostdev.c |  241 
> +--
>  src/qemu/qemu_hostdev.h |8 +-
>  src/qemu/qemu_hotplug.c |   10 ++
>  3 files changed, 246 insertions(+), 13 deletions(-)
>
>
> diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
> index b3cad8e..ebcdc52 100644
> --- a/src/qemu/qemu_hostdev.c
> +++ b/src/qemu/qemu_hostdev.c
> @@ -29,6 +29,13 @@
>  #include "memory.h"
>  #include "pci.h"
>  #include "hostusb.h"
> +#include "virnetdev.h"
> +
> +VIR_ENUM_IMPL(virNetDevVPort, VIR_NETDEV_VPORT_PROFILE_LAST,
> +  "none",
> +  "802.1Qbg",
> +  "802.1Qbh",
> +  "openvswitch")
>  

Oops. I didn't notice this until I got to the final build test before
pushing - VIR_ENUM_IMPL defines global functions, so you can't define it
twice for the same type. Instead, just export the xxxToString and
xxxFromString functions in libvirt_private.syms.

I'm squashing that change into the commit.

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


Re: [libvirt] [PATCH 4/4 v3] qemu_hostdev: Add support to install port profile and mac address on hostdevs

2012-03-06 Thread Laine Stump
On 03/05/2012 08:12 PM, Roopa Prabhu wrote:
> From: Roopa Prabhu 
>
> These changes are applied only if the hostdev has a parent net device.
> If the parent netdevice has virtual port information, the original virtualport
> associate functions are called (these set and restore both mac and port 
> profile
> on an interface). Else, only mac address is set on the device
> using other methods depending on if its a sriov device or not.
>
> Changes also include hotplug pci devices
>
> Signed-off-by: Roopa Prabhu 
> ---
>  src/qemu/qemu_hostdev.c |  241 
> +--
>  src/qemu/qemu_hostdev.h |8 +-
>  src/qemu/qemu_hotplug.c |   10 ++
>  3 files changed, 246 insertions(+), 13 deletions(-)
>
>
> diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
> index b3cad8e..ebcdc52 100644
> --- a/src/qemu/qemu_hostdev.c
> +++ b/src/qemu/qemu_hostdev.c
> @@ -29,6 +29,13 @@
>  #include "memory.h"
>  #include "pci.h"
>  #include "hostusb.h"
> +#include "virnetdev.h"
> +
> +VIR_ENUM_IMPL(virNetDevVPort, VIR_NETDEV_VPORT_PROFILE_LAST,
> +  "none",
> +  "802.1Qbg",
> +  "802.1Qbh",
> +  "openvswitch")
>  
>  static pciDeviceList *
>  qemuGetPciHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
> @@ -156,19 +163,192 @@ int qemuUpdateActivePciHostdevs(struct qemud_driver 
> *driver,
>  return 0;
>  }
>  
> +static int
> +qemuDomainHostdevPciSysfsPath(virDomainHostdevDefPtr hostdev, char 
> **sysfs_path)
> +{
> +struct pci_config_address config_address;
> +
> +config_address.domain = hostdev->source.subsys.u.pci.domain;
> +config_address.bus = hostdev->source.subsys.u.pci.bus;
> +config_address.slot = hostdev->source.subsys.u.pci.slot;
> +config_address.function = hostdev->source.subsys.u.pci.function;
> +
> +return pciConfigAddressToSysfsFile(&config_address, sysfs_path);
> +}
> +
> +int
> +qemuDomainHostdevIsVirtualFunction(virDomainHostdevDefPtr hostdev)
> +{
> +char *sysfs_path = NULL;
> +int ret = -1;
> +
> +if (qemuDomainHostdevPciSysfsPath(hostdev, &sysfs_path) < 0)
> +return ret;
> +
> +ret = pciDeviceIsVirtualFunction(sysfs_path);
> +
> +VIR_FREE(sysfs_path);
> +
> +return ret;
> +}
> +
> +static int
> +qemuDomainHostdevNetDevice(virDomainHostdevDefPtr hostdev, char **linkdev,
> +   int *vf)
> +{
> +int ret = -1;
> +char *sysfs_path = NULL;
> +
> +if (qemuDomainHostdevPciSysfsPath(hostdev, &sysfs_path) < 0)
> +return ret;
> +
> +if (pciDeviceIsVirtualFunction(sysfs_path) == 1) {
> +if (pciDeviceGetVirtualFunctionInfo(sysfs_path, linkdev,
> +vf) < 0)
> +goto cleanup;
> +} else {
> +if (pciDeviceNetName(sysfs_path, linkdev) < 0)
> +goto cleanup;
> +*vf = -1;
> +}
> +
> +ret = 0;
> +
> +cleanup:
> +VIR_FREE(sysfs_path);
> +
> +return ret;
> +}
> +
> +static int
> +qemuDomainHostdevNetConfigVirtPortProfile(const char *linkdev, int vf,
> +  virNetDevVPortProfilePtr virtPort,
> +  const unsigned char *macaddr,
> +  const unsigned char *uuid,
> +  int associate)
> +{
> +int ret = -1;
> +
> +if (!virtPort)
> +return ret;
> +
> +switch(virtPort->virtPortType) {
> +case VIR_NETDEV_VPORT_PROFILE_NONE:
> +case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
> +case VIR_NETDEV_VPORT_PROFILE_8021QBG:
> +case VIR_NETDEV_VPORT_PROFILE_LAST:
> +qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("virtualport type %s 
> is "
> +"currently not supported on interfaces of type "
> +"hostdev"),
> +virNetDevVPortTypeToString(virtPort->virtPortType));
> +break;
> +
> +case VIR_NETDEV_VPORT_PROFILE_8021QBH:
> +if (associate)
> +ret = virNetDevVPortProfileAssociate(NULL, virtPort, macaddr,
> + linkdev, vf, uuid,
> + 
> VIR_NETDEV_VPORT_PROFILE_OP_CREATE, false);
> +else
> +ret = virNetDevVPortProfileDisassociate(NULL, virtPort,
> +macaddr, linkdev, vf,
> +
> VIR_NETDEV_VPORT_PROFILE_OP_DESTROY);
> +break;
> +}
> +
> +return ret;
> +}
> +
> +int
> +qemuDomainHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
> +  const unsigned char *uuid,
> +  char *stateDir)
> +{
> +char *linkdev = NULL;
> +virNetDevVPortProfilePtr virtPort;
> +int ret = -1;
> +int vf = -1;
> +int vlanid = -1;
> +int port_profile_associate = 1;

[libvirt] [PATCH 4/4 v3] qemu_hostdev: Add support to install port profile and mac address on hostdevs

2012-03-05 Thread Roopa Prabhu
From: Roopa Prabhu 

These changes are applied only if the hostdev has a parent net device.
If the parent netdevice has virtual port information, the original virtualport
associate functions are called (these set and restore both mac and port profile
on an interface). Else, only mac address is set on the device
using other methods depending on if its a sriov device or not.

Changes also include hotplug pci devices

Signed-off-by: Roopa Prabhu 
---
 src/qemu/qemu_hostdev.c |  241 +--
 src/qemu/qemu_hostdev.h |8 +-
 src/qemu/qemu_hotplug.c |   10 ++
 3 files changed, 246 insertions(+), 13 deletions(-)


diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index b3cad8e..ebcdc52 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -29,6 +29,13 @@
 #include "memory.h"
 #include "pci.h"
 #include "hostusb.h"
+#include "virnetdev.h"
+
+VIR_ENUM_IMPL(virNetDevVPort, VIR_NETDEV_VPORT_PROFILE_LAST,
+  "none",
+  "802.1Qbg",
+  "802.1Qbh",
+  "openvswitch")
 
 static pciDeviceList *
 qemuGetPciHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
@@ -156,19 +163,192 @@ int qemuUpdateActivePciHostdevs(struct qemud_driver 
*driver,
 return 0;
 }
 
+static int
+qemuDomainHostdevPciSysfsPath(virDomainHostdevDefPtr hostdev, char 
**sysfs_path)
+{
+struct pci_config_address config_address;
+
+config_address.domain = hostdev->source.subsys.u.pci.domain;
+config_address.bus = hostdev->source.subsys.u.pci.bus;
+config_address.slot = hostdev->source.subsys.u.pci.slot;
+config_address.function = hostdev->source.subsys.u.pci.function;
+
+return pciConfigAddressToSysfsFile(&config_address, sysfs_path);
+}
+
+int
+qemuDomainHostdevIsVirtualFunction(virDomainHostdevDefPtr hostdev)
+{
+char *sysfs_path = NULL;
+int ret = -1;
+
+if (qemuDomainHostdevPciSysfsPath(hostdev, &sysfs_path) < 0)
+return ret;
+
+ret = pciDeviceIsVirtualFunction(sysfs_path);
+
+VIR_FREE(sysfs_path);
+
+return ret;
+}
+
+static int
+qemuDomainHostdevNetDevice(virDomainHostdevDefPtr hostdev, char **linkdev,
+   int *vf)
+{
+int ret = -1;
+char *sysfs_path = NULL;
+
+if (qemuDomainHostdevPciSysfsPath(hostdev, &sysfs_path) < 0)
+return ret;
+
+if (pciDeviceIsVirtualFunction(sysfs_path) == 1) {
+if (pciDeviceGetVirtualFunctionInfo(sysfs_path, linkdev,
+vf) < 0)
+goto cleanup;
+} else {
+if (pciDeviceNetName(sysfs_path, linkdev) < 0)
+goto cleanup;
+*vf = -1;
+}
+
+ret = 0;
+
+cleanup:
+VIR_FREE(sysfs_path);
+
+return ret;
+}
+
+static int
+qemuDomainHostdevNetConfigVirtPortProfile(const char *linkdev, int vf,
+  virNetDevVPortProfilePtr virtPort,
+  const unsigned char *macaddr,
+  const unsigned char *uuid,
+  int associate)
+{
+int ret = -1;
+
+if (!virtPort)
+return ret;
+
+switch(virtPort->virtPortType) {
+case VIR_NETDEV_VPORT_PROFILE_NONE:
+case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
+case VIR_NETDEV_VPORT_PROFILE_8021QBG:
+case VIR_NETDEV_VPORT_PROFILE_LAST:
+qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("virtualport type %s is "
+"currently not supported on interfaces of type "
+"hostdev"),
+virNetDevVPortTypeToString(virtPort->virtPortType));
+break;
+
+case VIR_NETDEV_VPORT_PROFILE_8021QBH:
+if (associate)
+ret = virNetDevVPortProfileAssociate(NULL, virtPort, macaddr,
+ linkdev, vf, uuid,
+ 
VIR_NETDEV_VPORT_PROFILE_OP_CREATE, false);
+else
+ret = virNetDevVPortProfileDisassociate(NULL, virtPort,
+macaddr, linkdev, vf,
+
VIR_NETDEV_VPORT_PROFILE_OP_DESTROY);
+break;
+}
+
+return ret;
+}
+
+int
+qemuDomainHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
+  const unsigned char *uuid,
+  char *stateDir)
+{
+char *linkdev = NULL;
+virNetDevVPortProfilePtr virtPort;
+int ret = -1;
+int vf = -1;
+int vlanid = -1;
+int port_profile_associate = 1;
+int isvf;
+
+isvf = qemuDomainHostdevIsVirtualFunction(hostdev);
+if (isvf <= 0) {
+qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+_("Interface type hostdev is currently supported on"
+" sriov Virtual functions only"));
+return ret;
+}
+
+if (qemuDomainHostdevNetDe