From patchwork Mon Jul 30 06:46:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 950720 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.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 41f98w55psz9ryt for ; Mon, 30 Jul 2018 16:46:55 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 58CC37F6; Mon, 30 Jul 2018 06:46:51 +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 D0B353EE for ; Mon, 30 Jul 2018 06:46:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id A546F701 for ; Mon, 30 Jul 2018 06:46:48 +0000 (UTC) X-Originating-IP: 76.21.1.228 Received: from localhost.localdomain (unknown [76.21.1.228]) (Authenticated sender: jpettit@ovn.org) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 8A7DB1BF20B for ; Mon, 30 Jul 2018 06:46:45 +0000 (UTC) From: Justin Pettit To: dev@openvswitch.org Date: Sun, 29 Jul 2018 23:46:32 -0700 Message-Id: <20180730064638.121021-1-jpettit@ovn.org> X-Mailer: git-send-email 2.17.1 X-Spam-Level: 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 Subject: [ovs-dev] [ACL Meters 1/7] ovn: Use C strings instead of ds for extended tables. 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 Dynamic strings are not needed for the most part and are introduing additional conversions back and forth with C strings. Signed-off-by: Justin Pettit Acked-by: Ben Pfaff --- ovn/controller/ofctrl.c | 4 ++-- ovn/lib/actions.c | 20 ++++++++------------ ovn/lib/extend-table.c | 22 ++++++++++++---------- ovn/lib/extend-table.h | 5 ++--- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/ovn/controller/ofctrl.c b/ovn/controller/ofctrl.c index 349de3aaa284..c7f41612456d 100644 --- a/ovn/controller/ofctrl.c +++ b/ovn/controller/ofctrl.c @@ -874,7 +874,7 @@ ofctrl_put(struct hmap *flow_table, struct shash *pending_ct_zones, enum ofputil_protocol usable_protocols; char *group_string = xasprintf("group_id=%"PRIu32",%s", desired->table_id, - ds_cstr(&desired->info)); + desired->name); char *error = parse_ofp_group_mod_str(&gm, OFPGC11_ADD, group_string, NULL, NULL, &usable_protocols); if (!error) { @@ -897,7 +897,7 @@ ofctrl_put(struct hmap *flow_table, struct shash *pending_ct_zones, enum ofputil_protocol usable_protocols; char *meter_string = xasprintf("meter=%"PRIu32",%s", m_desired->table_id, - ds_cstr(&m_desired->info)); + m_desired->name); char *error = parse_ofp_meter_mod_str(&mm, meter_string, OFPMC13_ADD, &usable_protocols); if (!error) { diff --git a/ovn/lib/actions.c b/ovn/lib/actions.c index 5c559e37a479..430bb677bafb 100644 --- a/ovn/lib/actions.c +++ b/ovn/lib/actions.c @@ -1049,7 +1049,7 @@ encode_CT_LB(const struct ovnact_ct_lb *cl, recirc_table, zone_reg); } - table_id = ovn_extend_table_assign_id(ep->group_table, &ds); + table_id = ovn_extend_table_assign_id(ep->group_table, ds_cstr(&ds)); ds_destroy(&ds); if (table_id == EXT_TABLE_ID_INVALID) { return; @@ -2217,25 +2217,21 @@ encode_SET_METER(const struct ovnact_set_meter *cl, uint32_t table_id; struct ofpact_meter *om; - struct ds ds = DS_EMPTY_INITIALIZER; + char *name; if (cl->burst) { - ds_put_format(&ds, - "kbps burst stats bands=type=drop rate=%"PRId64" " - "burst_size=%"PRId64"", - cl->rate, cl->burst); + name = xasprintf("kbps burst stats bands=type=drop rate=%"PRId64" " + "burst_size=%"PRId64"", cl->rate, cl->burst); } else { - ds_put_format(&ds, "kbps stats bands=type=drop rate=%"PRId64"", - cl->rate); + name = xasprintf("kbps stats bands=type=drop rate=%"PRId64"", + cl->rate); } - table_id = ovn_extend_table_assign_id(ep->meter_table, &ds); + table_id = ovn_extend_table_assign_id(ep->meter_table, name); + free(name); if (table_id == EXT_TABLE_ID_INVALID) { - ds_destroy(&ds); return; } - ds_destroy(&ds); - /* Create an action to set the meter. */ om = ofpact_put_METER(ofpacts); om->meter_id = table_id; diff --git a/ovn/lib/extend-table.c b/ovn/lib/extend-table.c index e18713b9766c..511d1a84b0c0 100644 --- a/ovn/lib/extend-table.c +++ b/ovn/lib/extend-table.c @@ -15,6 +15,8 @@ */ #include +#include + #include "bitmap.h" #include "hash.h" #include "openvswitch/vlog.h" @@ -39,7 +41,7 @@ ovn_extend_table_destroy(struct ovn_extend_table *table) struct ovn_extend_table_info *desired, *d_next; HMAP_FOR_EACH_SAFE (desired, d_next, hmap_node, &table->existing) { hmap_remove(&table->existing, &desired->hmap_node); - ds_destroy(&desired->info); + free(desired->name); free(desired); } hmap_destroy(&table->desired); @@ -47,7 +49,7 @@ ovn_extend_table_destroy(struct ovn_extend_table *table) struct ovn_extend_table_info *existing, *e_next; HMAP_FOR_EACH_SAFE (existing, e_next, hmap_node, &table->existing) { hmap_remove(&table->existing, &existing->hmap_node); - ds_destroy(&existing->info); + free(existing->name); free(existing); } hmap_destroy(&table->existing); @@ -84,7 +86,7 @@ ovn_extend_table_clear(struct ovn_extend_table *table, bool existing) if (existing || g->new_table_id) { bitmap_set0(table->table_ids, g->table_id); } - ds_destroy(&g->info); + free(g->name); free(g); } } @@ -95,7 +97,7 @@ ovn_extend_table_remove(struct ovn_extend_table *table, { /* Remove 'existing' from 'groups->existing' */ hmap_remove(&table->existing, &existing->hmap_node); - ds_destroy(&existing->info); + free(existing->name); /* Dealloc group_id. */ bitmap_set0(table->table_ids, existing->table_id); @@ -115,7 +117,7 @@ ovn_extend_table_move(struct ovn_extend_table *table) hmap_insert(&table->existing, &desired->hmap_node, desired->hmap_node.hash); } else { - ds_destroy(&desired->info); + free(desired->name); free(desired); } } @@ -124,16 +126,16 @@ ovn_extend_table_move(struct ovn_extend_table *table) /* Assign a new table ID for the table information from the bitmap. * If it already exists, return the old ID. */ uint32_t -ovn_extend_table_assign_id(struct ovn_extend_table *table, struct ds *ds) +ovn_extend_table_assign_id(struct ovn_extend_table *table, const char *name) { uint32_t table_id = 0, hash; struct ovn_extend_table_info *table_info; - hash = hash_string(ds_cstr(ds), 0); + hash = hash_string(name, 0); /* Check whether we have non installed but allocated group_id. */ HMAP_FOR_EACH_WITH_HASH (table_info, hmap_node, hash, &table->desired) { - if (!strcmp(ds_cstr(&table_info->info), ds_cstr(ds))) { + if (!strcmp(table_info->name, name)) { return table_info->table_id; } } @@ -141,7 +143,7 @@ ovn_extend_table_assign_id(struct ovn_extend_table *table, struct ds *ds) /* Check whether we already have an installed entry for this * combination. */ HMAP_FOR_EACH_WITH_HASH (table_info, hmap_node, hash, &table->existing) { - if (!strcmp(ds_cstr(&table_info->info), ds_cstr(ds))) { + if (!strcmp(table_info->name, name)) { table_id = table_info->table_id; } } @@ -161,7 +163,7 @@ ovn_extend_table_assign_id(struct ovn_extend_table *table, struct ds *ds) bitmap_set1(table->table_ids, table_id); table_info = xmalloc(sizeof *table_info); - ds_clone(&table_info->info, ds); + table_info->name = xstrdup(name); table_info->table_id = table_id; table_info->hmap_node.hash = hash; table_info->new_table_id = new_table_id; diff --git a/ovn/lib/extend-table.h b/ovn/lib/extend-table.h index d9ae549beaf5..e4501f254fb7 100644 --- a/ovn/lib/extend-table.h +++ b/ovn/lib/extend-table.h @@ -20,7 +20,6 @@ #define MAX_EXT_TABLE_ID 65535 #define EXT_TABLE_ID_INVALID 0 -#include "openvswitch/dynamic-string.h" #include "openvswitch/hmap.h" #include "openvswitch/list.h" @@ -36,7 +35,7 @@ struct ovn_extend_table { struct ovn_extend_table_info { struct hmap_node hmap_node; - struct ds info; /* Details string for the table entity. */ + char *name; /* Name for the table entity. */ uint32_t table_id; bool new_table_id; /* 'True' if 'table_id' was reserved from * ovn_extend_table's 'table_ids' bitmap. */ @@ -58,7 +57,7 @@ void ovn_extend_table_remove(struct ovn_extend_table *, void ovn_extend_table_move(struct ovn_extend_table *); uint32_t ovn_extend_table_assign_id(struct ovn_extend_table *, - struct ds *); + const char *name); /* Iterates 'DESIRED' through all of the 'ovn_extend_table_info's in * 'TABLE'->desired that are not in 'TABLE'->existing. (The loop body