[libvirt PATCH 2/4] conf: new function virDomainNetRemoveByObj()

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

 



virDomainNetRemove() requires the index of the net device you want to
remove from the list, but in some cases you may not have the index
handy, only the object itself (or the object may not have been added
to the domain's list). virDomainNetRemoveByObj() first tries to find
the given object in the nets list, and deletes that if it is found.

As with virDomainNetRemove() it always unconditionally tries to remove
the device from the hostdevs list (in case it is the ridiculous
combined net+hostdev device created for <interface type='hostdev'>).

Signed-off-by: Laine Stump <laine@xxxxxxxxxx>
---
 src/conf/domain_conf.c   | 16 ++++++++++++++++
 src/conf/domain_conf.h   |  1 +
 src/libvirt_private.syms |  1 +
 3 files changed, 18 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0c52efa816..22e4ab5661 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15742,6 +15742,22 @@ virDomainNetRemove(virDomainDef *def, size_t i)
 }
 
 
+virDomainNetDef *
+virDomainNetRemoveByObj(virDomainDef *def, virDomainNetDef *net)
+{
+    size_t i;
+
+    /* the device might have been added to hostdevs but not nets */
+    virDomainNetRemoveHostdev(def, net);
+
+    for (i = 0; i < def->nnets; i++) {
+        if (def->nets[i] == net)
+            VIR_DELETE_ELEMENT(def->nets, i, def->nnets);
+    }
+    return net;
+}
+
+
 int
 virDomainNetUpdate(virDomainDef *def,
                    size_t netidx,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 8d64d4a1e2..8b4ed6d7d2 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3581,6 +3581,7 @@ int virDomainNetUpdate(virDomainDef *def, size_t netidx, virDomainNetDef *newnet
 int virDomainNetDHCPInterfaces(virDomainDef *def, virDomainInterfacePtr **ifaces);
 int virDomainNetARPInterfaces(virDomainDef *def, virDomainInterfacePtr **ifaces);
 virDomainNetDef *virDomainNetRemove(virDomainDef *def, size_t i);
+virDomainNetDef *virDomainNetRemoveByObj(virDomainDef *def, virDomainNetDef *net);
 void virDomainNetRemoveHostdev(virDomainDef *def, virDomainNetDef *net);
 
 int virDomainHostdevInsert(virDomainDef *def, virDomainHostdevDef *hostdev);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7c7627052b..c327098f68 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -544,6 +544,7 @@ virDomainNetModelTypeToString;
 virDomainNetNotifyActualDevice;
 virDomainNetReleaseActualDevice;
 virDomainNetRemove;
+virDomainNetRemoveByObj;
 virDomainNetRemoveHostdev;
 virDomainNetResolveActualType;
 virDomainNetSetModelString;
-- 
2.31.1




[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