[ovs-dev] [PATCH v4 ovn 1/3] controller: do not allocate iface name twice in if_status_mgr module

Lorenzo Bianconi lorenzo.bianconi at redhat.com
Thu Oct 14 15:16:59 UTC 2021


Rely on shash_add_nocopy instead of shash_add in ovs_iface_create in
order to avoid allocating iface_id twice.

Acked-by: Dumitru Ceara <dceara at redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi at redhat.com>
---
 controller/if-status.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/controller/if-status.c b/controller/if-status.c
index b5a4025fc..00f826c50 100644
--- a/controller/if-status.c
+++ b/controller/if-status.c
@@ -344,7 +344,7 @@ ovs_iface_create(struct if_status_mgr *mgr, const char *iface_id,
 
     VLOG_DBG("Interface %s create.", iface_id);
     iface->id = xstrdup(iface_id);
-    shash_add(&mgr->ifaces, iface_id, iface);
+    shash_add_nocopy(&mgr->ifaces, iface->id, iface);
     ovs_iface_set_state(mgr, iface, state);
     return iface;
 }
@@ -355,7 +355,10 @@ ovs_iface_destroy(struct if_status_mgr *mgr, struct ovs_iface *iface)
     VLOG_DBG("Interface %s destroy: state %s", iface->id,
              if_state_names[iface->state]);
     hmapx_find_and_delete(&mgr->ifaces_per_state[iface->state], iface);
-    shash_find_and_delete(&mgr->ifaces, iface->id);
+    struct shash_node *node = shash_find(&mgr->ifaces, iface->id);
+    if (node) {
+        shash_steal(&mgr->ifaces, node);
+    }
     free(iface->id);
     free(iface);
 }
-- 
2.31.1



More information about the dev mailing list