Blob Blame History Raw
From 5ac7b872d91e8cb14fffbadc732b2d214009dd3c Mon Sep 17 00:00:00 2001
Message-Id: <5ac7b872d91e8cb14fffbadc732b2d214009dd3c.1378475168.git.jdenemar@redhat.com>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 4 Sep 2013 10:30:15 +0200
Subject: [PATCH] conf: Remove the actual hostdev when removing a network

https://bugzilla.redhat.com/show_bug.cgi?id=1003537

Commit 50348e6edfa reused the code to remove the hostdev portion of a
network definition on multiple places but forgot to take into account
that sometimes the "actual" network is passed and in some cases the
parent of that.

This patch uses the virDomainNetGetActualHostdev() helper to acquire the
correct pointer all the time while removing the hostdev portion from the
list.

(cherry picked from commit 991270db9969026876c3f5911143dab13ab9050d)
---
 src/conf/domain_conf.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1a20232..7a80508 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9941,14 +9941,14 @@ void
 virDomainNetRemoveHostdev(virDomainDefPtr def,
                           virDomainNetDefPtr net)
 {
-    if (net->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
-        /* hostdev net devices are normally also be in the hostdevs
-         * array, but might have already been removed by the time we
-         * get here.
-         */
-        virDomainHostdevDefPtr hostdev = &net->data.hostdev.def;
-        size_t i;
+    /* hostdev net devices are normally also be in the hostdevs
+     * array, but might have already been removed by the time we
+     * get here.
+     */
+    virDomainHostdevDefPtr hostdev = virDomainNetGetActualHostdev(net);
+    size_t i;
 
+    if (hostdev) {
         for (i = 0; i < def->nhostdevs; i++) {
             if (def->hostdevs[i] == hostdev) {
                 virDomainHostdevRemove(def, i);
-- 
1.8.3.2