From patchwork Fri Jan 14 18:01:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1580225 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RC5hTZTr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jb8J21mnBz9ssD for ; Sat, 15 Jan 2022 05:01:38 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 5C7C441627; Fri, 14 Jan 2022 18:01:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VzqURg1HrLFC; Fri, 14 Jan 2022 18:01:34 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 63BA641572; Fri, 14 Jan 2022 18:01:33 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 60598C0072; Fri, 14 Jan 2022 18:01:32 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6F293C0031 for ; Fri, 14 Jan 2022 18:01:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 1EF8B60AC3 for ; Fri, 14 Jan 2022 18:01:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HN3iHqNCg98s for ; Fri, 14 Jan 2022 18:01:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4540060ABE for ; Fri, 14 Jan 2022 18:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642183288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bx3k9gUbiQc24CQDZzIi6cVd8ocqftBDYDTbkLXCv5A=; b=RC5hTZTrcv09kwgpV6+UvNo3e9flfIwYdUFIyb91fYQBs7+QxxWtzBbVbjCZypUMWEhtCj Ox3qpbnRAHG2qRcZO3F2ibMVua1moDk7uDHsweDFh2UYkGFsBwNaUcMpW2kiev1Xt1Upef 9B21vMpfjv2dBpGKniJgOX3RpiwkgXA= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-377-TTkMS6ezO5Kmn7rko6eq8A-1; Fri, 14 Jan 2022 13:01:27 -0500 X-MC-Unique: TTkMS6ezO5Kmn7rko6eq8A-1 Received: by mail-qk1-f200.google.com with SMTP id p68-20020a37a647000000b0047876d0c485so7914463qke.22 for ; Fri, 14 Jan 2022 10:01:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bx3k9gUbiQc24CQDZzIi6cVd8ocqftBDYDTbkLXCv5A=; b=gYkkL/gBEc/1z5KYs+cLOssztihRvsLwP5Oc+h4beb0EuGjLI6EL1tnNikxLkrB4nI jshcvnQSPVY5220cyj8ckaaMAEIGFGBEecbX3NeQdCNhbHxwU6lp6r6MModC+cWh2zKK kcXK/OnNJWGt0oQqSFvxMWJ/gbLFBSNHYoeyepP/PLnDKIpJQCnUV62KZ/MTa+Qfu54+ /WBU72tOlYRYB55ylXYBucjVI5aQ8px7uUS7BMPdRmhX/obaEHAtNk/6XWY+3qMHPjHa v08zeGrhZKJ4C6OBby8o5gfZm0RRAxZ0W19Nb/RLNCAxLWxiekj7gN5vZMWlWNdmnh+W CgGg== X-Gm-Message-State: AOAM5333Qjew1aaVUU5HCk6uWggR7zhfTIs5g9+ygo9hDyL0aFowfZpA j92XoFuLlrrJXT/7lE4sI8mP/h5DC4Md90HXbio+Bm18sbYbjrCZCUS8HOB/h+03hb3375soVJT Vi/7vsJvjMSubst8UD1KOUvZdGNqDPQ3c9+SBksSu5tfmdlEDPSI6pjhnrV2uN5qyTN1Y/sjSxv 7llMM9 X-Received: by 2002:a37:6354:: with SMTP id x81mr7357818qkb.499.1642183286112; Fri, 14 Jan 2022 10:01:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhfBC3bCgu9g3Emifu58Ahy4fFxrXt43y4UAUdj/YBPdZqLKU6lKAtTrhLoAmB4IgZRcBQXQ== X-Received: by 2002:a37:6354:: with SMTP id x81mr7357773qkb.499.1642183285644; Fri, 14 Jan 2022 10:01:25 -0800 (PST) Received: from lore-desk.redhat.com (net-93-146-37-237.cust.vodafonedsl.it. [93.146.37.237]) by smtp.gmail.com with ESMTPSA id b6sm4165824qtk.91.2022.01.14.10.01.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jan 2022 10:01:25 -0800 (PST) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Fri, 14 Jan 2022 19:01:18 +0100 Message-Id: <1212633d1a3d342e087416bd9f93b0cef572e011.1642182763.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lorenzo.bianconi@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v2 ovn 2/3] lib: extend-table: add pending_id map X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Introduce pending_id map used to store meter_id allocated but not yet inserted in the desired_table. This is a preliminary patch to add metering IP engine. Signed-off-by: Lorenzo Bianconi --- controller/ofctrl.c | 9 +++++ controller/ofctrl.h | 1 + lib/extend-table.c | 82 +++++++++++++++++++++++++++++++++------------ lib/extend-table.h | 7 ++++ 4 files changed, 78 insertions(+), 21 deletions(-) diff --git a/controller/ofctrl.c b/controller/ofctrl.c index 08fcfed8b..bf715787e 100644 --- a/controller/ofctrl.c +++ b/controller/ofctrl.c @@ -1801,6 +1801,15 @@ add_meter_string(struct ovn_extend_table_info *m_desired, free(meter_string); } +uint32_t ofctrl_get_meter_id(const char *name, bool new_id) +{ + uint32_t id; + bool val; + + ovn_extend_table_get_id(meters, name, &id, NULL, &val, new_id); + return id; +} + static void add_meter(struct ovn_extend_table_info *m_desired, const struct sbrec_meter_table *meter_table, diff --git a/controller/ofctrl.h b/controller/ofctrl.h index 014de210d..0efcb2ef5 100644 --- a/controller/ofctrl.h +++ b/controller/ofctrl.h @@ -129,5 +129,6 @@ void ofctrl_check_and_add_flow_metered(struct ovn_desired_flow_table *, bool ofctrl_is_connected(void); void ofctrl_set_probe_interval(int probe_interval); void ofctrl_get_memory_usage(struct simap *usage); +uint32_t ofctrl_get_meter_id(const char *name, bool new_id); #endif /* controller/ofctrl.h */ diff --git a/lib/extend-table.c b/lib/extend-table.c index c708e24b9..52c8cd62e 100644 --- a/lib/extend-table.c +++ b/lib/extend-table.c @@ -37,6 +37,7 @@ ovn_extend_table_init(struct ovn_extend_table *table) hmap_init(&table->desired); hmap_init(&table->lflow_to_desired); hmap_init(&table->existing); + shash_init(&table->pending_ids); } static struct ovn_extend_table_info * @@ -191,6 +192,14 @@ ovn_extend_table_clear(struct ovn_extend_table *table, bool existing) } ovn_extend_table_info_destroy(g); } + + struct shash_node *node, *tmp; + SHASH_FOR_EACH_SAFE (node, tmp, &table->pending_ids) { + uint32_t *id = node->data; + shash_delete(&table->pending_ids, node); + free(id); + } + shash_destroy(&table->pending_ids); } void @@ -282,54 +291,85 @@ ovn_extend_table_sync(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, const char *name, - struct uuid lflow_uuid) +bool +ovn_extend_table_get_id(struct ovn_extend_table *table, const char *name, + uint32_t *meter_id, struct uuid *lflow_uuid, + bool *new_id, bool pending) { - uint32_t table_id = 0, hash; struct ovn_extend_table_info *table_info; - - hash = hash_string(name, 0); + uint32_t 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(table_info->name, name)) { VLOG_DBG("ovn_externd_table_assign_id: reuse old id %"PRIu32 - " for %s, used by lflow "UUID_FMT, - table_info->table_id, table_info->name, - UUID_ARGS(&lflow_uuid)); - ovn_extend_info_add_lflow_ref(table, table_info, &lflow_uuid); - return table_info->table_id; + " for %s", table_info->table_id, table_info->name); + if (lflow_uuid) { + ovn_extend_info_add_lflow_ref(table, table_info, lflow_uuid); + } + *meter_id = table_info->table_id; + return false; } } + *new_id = false; /* 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(table_info->name, name)) { - table_id = table_info->table_id; + *meter_id = table_info->table_id; + return true; } } - bool new_table_id = false; - if (!table_id) { - /* Reserve a new group_id. */ - table_id = bitmap_scan(table->table_ids, 0, 1, MAX_EXT_TABLE_ID + 1); - new_table_id = true; + /* Check if a ids has been already allocated for this flow. */ + uint32_t *id = shash_find_and_delete(&table->pending_ids, name); + if (id) { + *meter_id = *id; + free(id); + return true; } + /* Reserve a new group_id. */ + uint32_t table_id = bitmap_scan(table->table_ids, 0, 1, + MAX_EXT_TABLE_ID + 1); if (table_id == MAX_EXT_TABLE_ID + 1) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); VLOG_ERR_RL(&rl, "%"PRIu32" out of table ids.", table_id); - return EXT_TABLE_ID_INVALID; + *meter_id = EXT_TABLE_ID_INVALID; + return false; } bitmap_set1(table->table_ids, table_id); + *meter_id = table_id; + + *new_id = true; + if (pending) { + /* Add the id to pedning map. */ + id = xmalloc(sizeof *id); + *id = table_id; + shash_add(&table->pending_ids, name, id); + } + + return true; +} + +/* 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, const char *name, + struct uuid lflow_uuid) +{ + uint32_t table_id, hash = hash_string(name, 0); + struct ovn_extend_table_info *table_info; + bool new_table_id; + + if (!ovn_extend_table_get_id(table, name, &table_id, + &lflow_uuid, &new_table_id, false)) { + return table_id; + } table_info = ovn_extend_table_info_alloc(name, table_id, new_table_id, hash); - hmap_insert(&table->desired, &table_info->hmap_node, table_info->hmap_node.hash); diff --git a/lib/extend-table.h b/lib/extend-table.h index 4d80cfd80..5c5f65695 100644 --- a/lib/extend-table.h +++ b/lib/extend-table.h @@ -21,6 +21,7 @@ #define EXT_TABLE_ID_INVALID 0 #include "openvswitch/hmap.h" +#include "openvswitch/shash.h" #include "openvswitch/list.h" #include "openvswitch/uuid.h" @@ -30,6 +31,8 @@ struct ovn_extend_table { unsigned long *table_ids; /* Used as a bitmap with value set * for allocated group ids in either * desired or existing. */ + struct shash pending_ids; + struct hmap desired; struct hmap lflow_to_desired; /* Index for looking up desired table * items from given lflow uuid, with @@ -93,6 +96,10 @@ void ovn_extend_table_sync(struct ovn_extend_table *); uint32_t ovn_extend_table_assign_id(struct ovn_extend_table *, const char *name, struct uuid lflow_uuid); +bool +ovn_extend_table_get_id(struct ovn_extend_table *table, const char *name, + uint32_t *meter_id, struct uuid *lflow_uuid, + bool *new_id, bool pending); /* Iterates 'DESIRED' through all of the 'ovn_extend_table_info's in * 'TABLE'->desired that are not in 'TABLE'->existing. (The loop body