diff mbox series

[ovs-dev,v7,4/6] northd: Don't create pb in ls_port_init too early.

Message ID 20240426175501.858655-5-ihrachys@redhat.com
State Accepted
Headers show
Series Correct tunnel ids exhaustion scenario. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success

Commit Message

Ihar Hrachyshka April 26, 2024, 5:54 p.m. UTC
This allows callers to avoid cleanup of the record in case the function
fails.

Signed-off-by: Ihar Hrachyshka <ihrachys@redhat.com>
---
 northd/northd.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/northd/northd.c b/northd/northd.c
index 4800a44bd..934c22dac 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -4313,12 +4313,19 @@  ls_port_init(struct ovn_port *op, struct ovsdb_idl_txn *ovnsb_txn,
     if (!ovn_port_assign_requested_tnl_id(sbrec_chassis_table, op)) {
         return false;
     }
+    /* Keep nonconflicting tunnel IDs that are already assigned. */
     if (sb) {
-        op->sb = sb;
-        /* Keep nonconflicting tunnel IDs that are already assigned. */
         if (!op->tunnel_key) {
-            ovn_port_add_tnlid(op, op->sb->tunnel_key);
+            ovn_port_add_tnlid(op, sb->tunnel_key);
         }
+    }
+    /* Assign new tunnel ids where needed. */
+    if (!ovn_port_allocate_key(sbrec_chassis_table, op)) {
+        return false;
+    }
+    /* Create new binding, if needed. */
+    if (sb) {
+        op->sb = sb;
     } else {
         /* XXX: the new SB port_binding will change in IDL, so need to handle
          * SB port_binding updates incrementally to achieve end-to-end
@@ -4326,10 +4333,6 @@  ls_port_init(struct ovn_port *op, struct ovsdb_idl_txn *ovnsb_txn,
         op->sb = sbrec_port_binding_insert(ovnsb_txn);
         sbrec_port_binding_set_logical_port(op->sb, op->key);
     }
-    /* Assign new tunnel ids where needed. */
-    if (!ovn_port_allocate_key(sbrec_chassis_table, op)) {
-        return false;
-    }
     ovn_port_update_sbrec(ovnsb_txn, sbrec_chassis_by_name,
                           sbrec_chassis_by_hostname, NULL, sbrec_mirror_table,
                           op, NULL, NULL);
@@ -4351,9 +4354,6 @@  ls_port_create(struct ovsdb_idl_txn *ovnsb_txn, struct hmap *ls_ports,
     if (!ls_port_init(op, ovnsb_txn, od, sb,
                       sbrec_mirror_table, sbrec_chassis_table,
                       sbrec_chassis_by_name, sbrec_chassis_by_hostname)) {
-        if (op->sb) {
-            sbrec_port_binding_delete(op->sb);
-        }
         ovn_port_destroy(ls_ports, op);
         return NULL;
     }
@@ -4557,8 +4557,8 @@  ls_handle_lsp_changes(struct ovsdb_idl_txn *ovnsb_idl_txn,
                                 ni->sbrec_chassis_table,
                                 ni->sbrec_chassis_by_name,
                                 ni->sbrec_chassis_by_hostname)) {
-                if (op->sb) {
-                    sbrec_port_binding_delete(op->sb);
+                if (sb) {
+                    sbrec_port_binding_delete(sb);
                 }
                 ovn_port_destroy(&nd->ls_ports, op);
                 goto fail;