From patchwork Fri Dec 16 22:25:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 706615 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tgQ571ygqz9t2p for ; Sat, 17 Dec 2016 09:31:07 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 19A74BF4; Fri, 16 Dec 2016 22:26:09 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id F22EEBEA for ; Fri, 16 Dec 2016 22:26:05 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 406B8153 for ; Fri, 16 Dec 2016 22:26:03 +0000 (UTC) Received: from mfilter37-d.gandi.net (mfilter37-d.gandi.net [217.70.178.168]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 09377A80CD; Fri, 16 Dec 2016 23:26:02 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter37-d.gandi.net Received: from relay3-d.mail.gandi.net ([IPv6:::ffff:217.70.183.195]) by mfilter37-d.gandi.net (mfilter37-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id dUOCxSyO-8JC; Fri, 16 Dec 2016 23:26:00 +0100 (CET) X-Originating-IP: 208.91.2.3 Received: from sigabrt.benpfaff.org (unknown [208.91.2.3]) (Authenticated sender: blp@ovn.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 53053A80C8; Fri, 16 Dec 2016 23:25:59 +0100 (CET) From: Ben Pfaff To: dev@openvswitch.org Date: Fri, 16 Dec 2016 14:25:36 -0800 Message-Id: <20161216222537.2221-11-blp@ovn.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161216222537.2221-1-blp@ovn.org> References: <20161216222537.2221-1-blp@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH v2 10/11] ovn-controller: Avoid code duplication getting chassis record. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Signed-off-by: Ben Pfaff --- 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 --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();