diff mbox

[ovs-dev,v2,10/11] ovn-controller: Avoid code duplication getting chassis record.

Message ID 20161216222537.2221-11-blp@ovn.org
State Superseded
Headers show

Commit Message

Ben Pfaff Dec. 16, 2016, 10:25 p.m. UTC
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 ovn/controller/binding.c        | 26 ++++++++++----------------
 ovn/controller/binding.h        |  6 +++---
 ovn/controller/chassis.c        | 12 +++---------
 ovn/controller/chassis.h        |  3 ++-
 ovn/controller/ovn-controller.c |  8 +++++---
 5 files changed, 23 insertions(+), 32 deletions(-)
diff mbox

Patch

diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c
index 2759e23..4ad01b0 100644
--- a/ovn/controller/binding.c
+++ b/ovn/controller/binding.c
@@ -413,21 +413,20 @@  consider_local_datapath(struct controller_ctx *ctx,
 
 void
 binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
-            const char *chassis_id, const struct ldatapath_index *ldatapaths,
+            const struct sbrec_chassis *chassis_rec,
+            const struct ldatapath_index *ldatapaths,
             const struct lport_index *lports, struct hmap *local_datapaths,
             struct sset *all_lports)
 {
-    const struct sbrec_chassis *chassis_rec;
+    if (!chassis_rec) {
+        return;
+    }
+
     const struct sbrec_port_binding *binding_rec;
     struct shash lport_to_iface = SHASH_INITIALIZER(&lport_to_iface);
     struct sset egress_ifaces = SSET_INITIALIZER(&egress_ifaces);
     struct hmap qos_map;
 
-    chassis_rec = get_chassis(ctx->ovnsb_idl, chassis_id);
-    if (!chassis_rec) {
-        return;
-    }
-
     hmap_init(&qos_map);
     if (br_int) {
         get_local_iface_ids(br_int, &lport_to_iface, all_lports,
@@ -462,25 +461,20 @@  binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
 /* Returns true if the database is all cleaned up, false if more work is
  * required. */
 bool
-binding_cleanup(struct controller_ctx *ctx, const char *chassis_id)
+binding_cleanup(struct controller_ctx *ctx,
+                const struct sbrec_chassis *chassis_rec)
 {
     if (!ctx->ovnsb_idl_txn) {
         return false;
     }
-
-    if (!chassis_id) {
-        return true;
-    }
-
-    const struct sbrec_chassis *chassis_rec
-        = get_chassis(ctx->ovnsb_idl, chassis_id);
     if (!chassis_rec) {
         return true;
     }
 
     ovsdb_idl_txn_add_comment(
         ctx->ovnsb_idl_txn,
-        "ovn-controller: removing all port bindings for '%s'", chassis_id);
+        "ovn-controller: removing all port bindings for '%s'",
+        chassis_rec->name);
 
     const struct sbrec_port_binding *binding_rec;
     bool any_changes = false;
diff --git a/ovn/controller/binding.h b/ovn/controller/binding.h
index 0bb293d..3bfa7d1 100644
--- a/ovn/controller/binding.h
+++ b/ovn/controller/binding.h
@@ -25,14 +25,14 @@  struct ldatapath_index;
 struct lport_index;
 struct ovsdb_idl;
 struct ovsrec_bridge;
-struct simap;
+struct sbrec_chassis;
 struct sset;
 
 void binding_register_ovs_idl(struct ovsdb_idl *);
 void binding_run(struct controller_ctx *, const struct ovsrec_bridge *br_int,
-                 const char *chassis_id, const struct ldatapath_index *,
+                 const struct sbrec_chassis *, const struct ldatapath_index *,
                  const struct lport_index *, struct hmap *local_datapaths,
                  struct sset *all_lports);
-bool binding_cleanup(struct controller_ctx *, const char *chassis_id);
+bool binding_cleanup(struct controller_ctx *, const struct sbrec_chassis *);
 
 #endif /* ovn/binding.h */
diff --git a/ovn/controller/chassis.c b/ovn/controller/chassis.c
index 70cd159..db8cc2e 100644
--- a/ovn/controller/chassis.c
+++ b/ovn/controller/chassis.c
@@ -233,22 +233,16 @@  chassis_run(struct controller_ctx *ctx, const char *chassis_id,
 /* Returns true if the database is all cleaned up, false if more work is
  * required. */
 bool
-chassis_cleanup(struct controller_ctx *ctx, const char *chassis_id)
+chassis_cleanup(struct controller_ctx *ctx,
+                const struct sbrec_chassis *chassis_rec)
 {
-    if (!chassis_id) {
-        return true;
-    }
-
-    /* Delete Chassis row. */
-    const struct sbrec_chassis *chassis_rec
-        = get_chassis(ctx->ovnsb_idl, chassis_id);
     if (!chassis_rec) {
         return true;
     }
     if (ctx->ovnsb_idl_txn) {
         ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn,
                                   "ovn-controller: unregistering chassis '%s'",
-                                  chassis_id);
+                                  chassis_rec->name);
         sbrec_chassis_delete(chassis_rec);
     }
     return false;
diff --git a/ovn/controller/chassis.h b/ovn/controller/chassis.h
index 016d71c..2cc47fc 100644
--- a/ovn/controller/chassis.h
+++ b/ovn/controller/chassis.h
@@ -21,11 +21,12 @@ 
 struct controller_ctx;
 struct ovsdb_idl;
 struct ovsrec_bridge;
+struct sbrec_chassis;
 
 void chassis_register_ovs_idl(struct ovsdb_idl *);
 const struct sbrec_chassis *chassis_run(struct controller_ctx *,
                                         const char *chassis_id,
                                         const struct ovsrec_bridge *br_int);
-bool chassis_cleanup(struct controller_ctx *, const char *chassis_id);
+bool chassis_cleanup(struct controller_ctx *, const struct sbrec_chassis *);
 
 #endif /* ovn/chassis.h */
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index c0a4ee3..763ce7d 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -507,7 +507,7 @@  main(int argc, char *argv[])
         if (chassis_id) {
             chassis = chassis_run(&ctx, chassis_id, br_int);
             encaps_run(&ctx, br_int, chassis_id);
-            binding_run(&ctx, br_int, chassis_id, &ldatapaths, &lports,
+            binding_run(&ctx, br_int, chassis, &ldatapaths, &lports,
                         &local_datapaths, &all_lports);
         }
 
@@ -600,11 +600,13 @@  main(int argc, char *argv[])
 
         const struct ovsrec_bridge *br_int = get_br_int(&ctx);
         const char *chassis_id = get_chassis_id(ctx.ovs_idl);
+        const struct sbrec_chassis *chassis
+            = chassis_id ? get_chassis(ctx.ovnsb_idl, chassis_id) : NULL;
 
         /* Run all of the cleanup functions, even if one of them returns false.
          * We're done if all of them return true. */
-        done = binding_cleanup(&ctx, chassis_id);
-        done = chassis_cleanup(&ctx, chassis_id) && done;
+        done = binding_cleanup(&ctx, chassis);
+        done = chassis_cleanup(&ctx, chassis) && done;
         done = encaps_cleanup(&ctx, br_int) && done;
         if (done) {
             poll_immediate_wake();