Re: [PATCHv2 4/4] qemu: interface: check and use ovs command to set qos of ovs managed port

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

 



On 7/1/21 10:42 AM, zhangjl02 wrote:
> From: zhangjl02 <zhangjl02@xxxxxxxxxx>
> 
> When qos is set or delete, we have to check if the port is an ovs managed
> port. If true, call the virNetDevOpenvswitchInterfaceSetQos function when qos
> is set, and call the virNetDevOpenvswitchInterfaceClearQos function when
> the interface is to be destroyed.
> ---
>  src/qemu/qemu_command.c | 10 ++++++++--
>  src/qemu/qemu_driver.c  | 22 +++++++++++++++++++++-
>  src/qemu/qemu_hotplug.c | 39 ++++++++++++++++++++++++++++-----------
>  src/qemu/qemu_process.c | 10 ++++++++--
>  4 files changed, 65 insertions(+), 16 deletions(-)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index ea513693f7..1e9ed592e1 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -8610,8 +8610,14 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
>      actualBandwidth = virDomainNetGetActualBandwidth(net);
>      if (actualBandwidth) {
>          if (virNetDevSupportsBandwidth(actualType)) {
> -            if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
> -                                      !virDomainNetTypeSharesHostView(net)) < 0)
> +            if (virDomainNetDefIsOvsport(net, actualType)) {
> +                if (virNetDevOpenvswitchInterfaceSetQos(net->ifname, actualBandwidth,
> +                                                        def->uuid,
> +                                                        !virDomainNetTypeSharesHostView(net)) < 0)
> +                    goto cleanup;
> +            }
> +            else if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
> +                                           !virDomainNetTypeSharesHostView(net)) < 0)
>                  goto cleanup;

Again, we use slightly different style for if-else and curly braces. I'll just paste what I think should be squashed in:

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1e9ed592e1..522394bb74 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8610,15 +8610,15 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver,
     actualBandwidth = virDomainNetGetActualBandwidth(net);
     if (actualBandwidth) {
         if (virNetDevSupportsBandwidth(actualType)) {
-            if (virDomainNetDefIsOvsport(net, actualType)) {
+            if (virDomainNetDefIsOvsport(net)) {
                 if (virNetDevOpenvswitchInterfaceSetQos(net->ifname, actualBandwidth,
                                                         def->uuid,
                                                         !virDomainNetTypeSharesHostView(net)) < 0)
                     goto cleanup;
-            }
-            else if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
-                                           !virDomainNetTypeSharesHostView(net)) < 0)
+            } else if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
+                                             !virDomainNetTypeSharesHostView(net)) < 0) {
                 goto cleanup;
+            }
         } else {
             VIR_WARN("setting bandwidth on interfaces of "
                      "type '%s' is not implemented yet",
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a6212fed6a..72f550bf8d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10278,7 +10278,7 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
     if (net) {
         actualType = virDomainNetGetActualType(net);
         qosSupported = virNetDevSupportsBandwidth(actualType);
-        ovsType = virDomainNetDefIsOvsport(net, actualType);
+        ovsType = virDomainNetDefIsOvsport(net);
     }
 
     if (qosSupported && persistentNet) {
@@ -10368,10 +10368,10 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
             }
         }
 
-        if (ovsType){
+        if (ovsType) {
             if (virNetDevOpenvswitchInterfaceSetQos(net->ifname, newBandwidth,
                                                     vm->def->uuid,
-                                                    !virDomainNetTypeSharesHostView(net)) < 0){
+                                                    !virDomainNetTypeSharesHostView(net)) < 0) {
                 virErrorPtr orig_err;
 
                 virErrorPreserveLast(&orig_err);
@@ -10385,9 +10385,8 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
                 virErrorRestore(&orig_err);
                 goto endjob;
             }
-        }
-        else if (virNetDevBandwidthSet(net->ifname, newBandwidth, false,
-                                  !virDomainNetTypeSharesHostView(net)) < 0) {
+        } else if (virNetDevBandwidthSet(net->ifname, newBandwidth, false,
+                                         !virDomainNetTypeSharesHostView(net)) < 0) {
             virErrorPtr orig_err;
 
             virErrorPreserveLast(&orig_err);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e900834e3e..cb6a4e4ea5 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1409,15 +1409,15 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver,
     actualBandwidth = virDomainNetGetActualBandwidth(net);
     if (actualBandwidth) {
         if (virNetDevSupportsBandwidth(actualType)) {
-            if (virDomainNetDefIsOvsport(net, actualType)) {
+            if (virDomainNetDefIsOvsport(net)) {
                 if (virNetDevOpenvswitchInterfaceSetQos(net->ifname, actualBandwidth,
                                                         vm->def->uuid,
                                                         !virDomainNetTypeSharesHostView(net)) < 0)
                     goto cleanup;
+            } else if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
+                                             !virDomainNetTypeSharesHostView(net)) < 0) {
+                goto cleanup;
             }
-            else if (virNetDevBandwidthSet(net->ifname, actualBandwidth, false,
-                                  !virDomainNetTypeSharesHostView(net)) < 0)
-            goto cleanup;
         } else {
             VIR_WARN("setting bandwidth on interfaces of "
                      "type '%s' is not implemented yet",
@@ -3920,15 +3920,15 @@ qemuDomainChangeNet(virQEMUDriver *driver,
         const virNetDevBandwidth *newb = virDomainNetGetActualBandwidth(newdev);
 
         if (newb) {
-            if (virDomainNetDefIsOvsport(newdev, newType)) {
+            if (virDomainNetDefIsOvsport(newdev)) {
                 if (virNetDevOpenvswitchInterfaceSetQos(newdev->ifname, newb,
                                                         vm->def->uuid,
                                                         !virDomainNetTypeSharesHostView(newdev)) < 0)
                     goto cleanup;
+            } else if (virNetDevBandwidthSet(newdev->ifname, newb, false,
+                                             !virDomainNetTypeSharesHostView(newdev)) < 0) {
+                goto cleanup;
             }
-            else if (virNetDevBandwidthSet(newdev->ifname, newb, false,
-                                  !virDomainNetTypeSharesHostView(newdev)) < 0)
-            goto cleanup;
         } else {
             /*
              * virNetDevBandwidthSet() doesn't clear any existing
@@ -4677,15 +4677,15 @@ qemuDomainRemoveNetDevice(virQEMUDriver *driver,
     if (!(charDevAlias = qemuAliasChardevFromDevAlias(net->info.alias)))
         return -1;
 
-    if (virNetDevSupportsBandwidth(virDomainNetGetActualType(net))){
-        if (virDomainNetDefIsOvsport(net, actualType)) {
+    if (virNetDevSupportsBandwidth(virDomainNetGetActualType(net))) {
+        if (virDomainNetDefIsOvsport(net)) {
             if (virNetDevOpenvswitchInterfaceClearQos(net->ifname, vm->def->uuid) < 0)
                 VIR_WARN("cannot clear bandwidth setting for ovs device : %s",
                          net->ifname);
-        }
-        else if (virNetDevBandwidthClear(net->ifname) < 0)
+        } else if (virNetDevBandwidthClear(net->ifname) < 0) {
             VIR_WARN("cannot clear bandwidth setting for device : %s",
                      net->ifname);
+        }
     }
 
     /* deactivate the tap/macvtap device on the host, which could also
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 95cdf232ef..3693796b06 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7818,7 +7818,6 @@ void qemuProcessStop(virQEMUDriver *driver,
     g_autofree char *timestamp = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     g_autoptr(virConnect) conn = NULL;
-    int actualType;
 
     VIR_DEBUG("Shutting down vm=%p name=%s id=%d pid=%lld, "
               "reason=%s, asyncJob=%s, flags=0x%x",
@@ -7967,8 +7966,7 @@ void qemuProcessStop(virQEMUDriver *driver,
     for (i = 0; i < def->nnets; i++) {
         virDomainNetDef *net = def->nets[i];
         vport = virDomainNetGetActualVirtPortProfile(net);
-        actualType = virDomainNetGetActualType(net);
-        switch (actualType) {
+        switch (virDomainNetGetActualType(net)) {
         case VIR_DOMAIN_NET_TYPE_DIRECT:
             ignore_value(virNetDevMacVLanDeleteWithVPortProfile(
                              net->ifname, &net->mac,
@@ -8024,10 +8022,11 @@ void qemuProcessStop(virQEMUDriver *driver,
             else
                 VIR_WARN("Unable to release network device '%s'", NULLSTR(net->ifname));
         }
-        if (virDomainNetDefIsOvsport(net, actualType)) {
-            if (virNetDevOpenvswitchInterfaceClearQos(net->ifname, vm->def->uuid) < 0)
-                VIR_WARN("cannot clear bandwidth setting for ovs device : %s",
-                         net->ifname);
+
+        if (virDomainNetDefIsOvsport(net) &&
+            virNetDevOpenvswitchInterfaceClearQos(net->ifname, vm->def->uuid) < 0) {
+            VIR_WARN("cannot clear bandwidth setting for ovs device : %s",
+                     net->ifname);
         }
     }
 
Michal




[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