From patchwork Thu May 18 09:48:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1783105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.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=O651bRbo; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QMQDW0RHyz20dn for ; Thu, 18 May 2023 19:49:31 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 97281428EC; Thu, 18 May 2023 09:49:28 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 97281428EC Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=O651bRbo 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 QGmQ_FZU4U0c; Thu, 18 May 2023 09:49:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 2D1FF42883; Thu, 18 May 2023 09:49:20 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 2D1FF42883 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DDE9EC0035; Thu, 18 May 2023 09:49:19 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2A92FC0037 for ; Thu, 18 May 2023 09:49:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 6C8CB843D8 for ; Thu, 18 May 2023 09:49:10 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 6C8CB843D8 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=O651bRbo X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BbgxL44Hod4A for ; Thu, 18 May 2023 09:49:08 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 913E3843E3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 913E3843E3 for ; Thu, 18 May 2023 09:49:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684403347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FWXqHuoUtDmJysPpBVtOwUU601rZtbu86+ARI9EaUR4=; b=O651bRbo6SI3sSiwG5KuNHU0I3++WPv6MNEnO8v4hU3rsj3E7qa6/IJzzGNuT20McyJa6e NFwLLF9CFtA4GenC6h6Jv8/9LUMWQCxja/VZUQrUbEN6jHfjhEZveCpocrOGRYBkvYXHkX QKUa6kQbwH9WqTuGoX1hYtV04qv7B9I= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-237--VRLtk4_N-aCgyzVh7eHjA-1; Thu, 18 May 2023 05:49:06 -0400 X-MC-Unique: -VRLtk4_N-aCgyzVh7eHjA-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-30629b36d9bso772865f8f.0 for ; Thu, 18 May 2023 02:49:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684403345; x=1686995345; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xXCJRBX2cvoDALTeeHKthJYssSIsZQZ/+5QGlWUaraQ=; b=j6fh6hq3eeyNB/4/uzSKM5pEkHp8g54WTumJPbvJrakibAHEnSqY7HzlvKJr6eCGQ0 mwTDjkaBDLx9DHxRxQ4UIOtPlPbDnFXxCPVVhfxFIlFZ68VB7flWJyHJvOIlZCvW1JMY CXm1kVrxhfSSoCysrHmnqrsDS8Dud3bLsPZiKDoiJtRH5ev5vdIDGoF71HajbAxCNrBR x64y2sGAzhk/k3dcxyZhjwkqAc3Em4/FgRGaxo1P8dhvAO0aIzjc7lzQOYPvkFuldXvo dulzeVO3nJQxbf1mEzMl1HFNWtLVmK9VG6SGeC6GdoBcP3rHZkq8GWK+aGxQbOZZebe3 xl3g== X-Gm-Message-State: AC+VfDwQbokMYFOt5DgWsH7f6Hr4DKeqRIWwNgB7OvMAE3ve9xJ8one4 Mo/aNLx7vsz3f7Tik1G/oE0zDu2yU+wft1+ECHbigYDKWnVECAfQkWFh4DELwb8bAobIMKyqq2q Eq/9/ldG19qAiwYlI8iytAYxNmCNyVxpU5qP7tS+v3kXY4e6wenKcOfqjVc/kjRln4lwuRAsgww rHyArtJOdlfnGG X-Received: by 2002:adf:cd88:0:b0:309:382e:be27 with SMTP id q8-20020adfcd88000000b00309382ebe27mr1118184wrj.33.1684403345186; Thu, 18 May 2023 02:49:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6nOERmq5fcVCC70qWovp3ftg41vhVhx2K772RTQCUg4pf011etyb9o6862ByeVJEBhOo8fQw== X-Received: by 2002:adf:cd88:0:b0:309:382e:be27 with SMTP id q8-20020adfcd88000000b00309382ebe27mr1118165wrj.33.1684403344810; Thu, 18 May 2023 02:49:04 -0700 (PDT) Received: from localhost (net-130-25-106-149.cust.vodafonedsl.it. [130.25.106.149]) by smtp.gmail.com with ESMTPSA id o15-20020a5d62cf000000b0030789698eebsm1576976wrv.89.2023.05.18.02.49.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 02:49:04 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Thu, 18 May 2023 11:48:37 +0200 Message-Id: <5ea843f0e5734b1abbe23d5d91950ae2360a242e.1684403044.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: dceara@redhat.com, simon.horman@corigine.com, i.maximets@ovn.org, ralonsoh@redhat.com Subject: [ovs-dev] [PATCH v9 ovn 07/10] northd: make queue_id allocation global for the ovn cluster 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" In order to avoid possible queue_id clash when we have a localnet and a LSP ports on the same hv, make QoS queue_id allocation global for the ovn cluster. Acked-by: Numan Siddique Signed-off-by: Lorenzo Bianconi --- northd/northd.c | 127 ++++++++---------------------------------------- 1 file changed, 20 insertions(+), 107 deletions(-) diff --git a/northd/northd.c b/northd/northd.c index 470f76809..c107fe33a 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -469,94 +469,20 @@ build_chassis_features(const struct sbrec_chassis_table *sbrec_chassis_table, } } } - -struct ovn_chassis_qdisc_queues { - struct hmap_node key_node; - uint32_t queue_id; - struct uuid chassis_uuid; -}; static uint32_t -hash_chassis_queue(const struct uuid *chassis_uuid, uint32_t queue_id) -{ - return hash_2words(uuid_hash(chassis_uuid), queue_id); -} - -static void -destroy_chassis_queues(struct hmap *set) -{ - struct ovn_chassis_qdisc_queues *node; - HMAP_FOR_EACH_POP (node, key_node, set) { - free(node); - } - hmap_destroy(set); -} - -static void -add_chassis_queue(struct hmap *set, const struct uuid *chassis_uuid, - uint32_t queue_id) +allocate_queueid(unsigned long *queue_id_bitmap) { - struct ovn_chassis_qdisc_queues *node = xmalloc(sizeof *node); - node->queue_id = queue_id; - node->chassis_uuid = *chassis_uuid; - hmap_insert(set, &node->key_node, - hash_chassis_queue(chassis_uuid, queue_id)); -} - -static bool -chassis_queueid_in_use(const struct hmap *set, const struct uuid *chassis_uuid, - uint32_t queue_id) -{ - const struct ovn_chassis_qdisc_queues *node; - HMAP_FOR_EACH_WITH_HASH (node, key_node, - hash_chassis_queue(chassis_uuid, queue_id), set) { - if (uuid_equals(chassis_uuid, &node->chassis_uuid) - && node->queue_id == queue_id) { - return true; - } - } - return false; -} - -static uint32_t -allocate_chassis_queueid(struct hmap *set, const struct uuid *uuid, char *name) -{ - if (!uuid) { + uint32_t queue_id = bitmap_scan(queue_id_bitmap, 0, 1, + QDISC_MAX_QUEUE_ID + 1); + if (queue_id == QDISC_MAX_QUEUE_ID + 1) { + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); + VLOG_WARN_RL(&rl, "all queue ids exhausted"); return 0; } + bitmap_set1(queue_id_bitmap, queue_id); - for (uint32_t queue_id = QDISC_MIN_QUEUE_ID + 1; - queue_id <= QDISC_MAX_QUEUE_ID; - queue_id++) { - if (!chassis_queueid_in_use(set, uuid, queue_id)) { - add_chassis_queue(set, uuid, queue_id); - return queue_id; - } - } - - static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); - VLOG_WARN_RL(&rl, "all %s queue ids exhausted", name); - return 0; -} - -static void -free_chassis_queueid(struct hmap *set, const struct uuid *uuid, - uint32_t queue_id) -{ - if (!uuid) { - return; - } - - struct ovn_chassis_qdisc_queues *node; - HMAP_FOR_EACH_WITH_HASH (node, key_node, - hash_chassis_queue(uuid, queue_id), set) { - if (uuid_equals(uuid, &node->chassis_uuid) - && node->queue_id == queue_id) { - hmap_remove(set, &node->key_node); - free(node); - break; - } - } + return queue_id; } static inline bool @@ -2472,7 +2398,7 @@ tag_alloc_create_new_tag(struct hmap *tag_alloc_table, static void join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table, struct hmap *ls_datapaths, struct hmap *lr_datapaths, - struct hmap *ports, struct hmap *chassis_qdisc_queues, + struct hmap *ports, unsigned long *queue_id_bitmap, struct hmap *tag_alloc_table, struct ovs_list *sb_only, struct ovs_list *nb_only, struct ovs_list *both) { @@ -2537,11 +2463,8 @@ join_logical_ports(const struct sbrec_port_binding_table *sbrec_pb_table, uint32_t queue_id = smap_get_int(&op->sb->options, "qdisc_queue_id", 0); - if (queue_id && op->sb->chassis) { - add_chassis_queue( - chassis_qdisc_queues, - &op->sb->chassis->header_.uuid, - queue_id); + if (queue_id) { + bitmap_set1(queue_id_bitmap, queue_id); } ovs_list_push_back(both, &op->list); @@ -3359,7 +3282,7 @@ ovn_port_update_sbrec(struct ovsdb_idl_txn *ovnsb_txn, struct ovsdb_idl_index *sbrec_ha_chassis_grp_by_name, const struct sbrec_mirror_table *sbrec_mirror_table, const struct ovn_port *op, - struct hmap *chassis_qdisc_queues, + unsigned long *queue_id_bitmap, struct sset *active_ha_chassis_grps) { sbrec_port_binding_set_datapath(op->sb, op->od->sb); @@ -3484,23 +3407,12 @@ ovn_port_update_sbrec(struct ovsdb_idl_txn *ovnsb_txn, uint32_t queue_id = smap_get_int( &op->sb->options, "qdisc_queue_id", 0); bool has_qos = port_has_qos_params(&op->nbsp->options); - const struct uuid *uuid = NULL; struct smap options; - char *name = ""; - - if (lsp_is_localnet(op->nbsp)) { - uuid = &op->sb->header_.uuid; - name = "localnet"; - } else if (op->sb->chassis) { - uuid = &op->sb->chassis->header_.uuid; - name = op->sb->chassis->name; - } if (has_qos && !queue_id) { - queue_id = allocate_chassis_queueid(chassis_qdisc_queues, - uuid, name); + queue_id = allocate_queueid(queue_id_bitmap); } else if (!has_qos && queue_id) { - free_chassis_queueid(chassis_qdisc_queues, uuid, queue_id); + bitmap_set0(queue_id_bitmap, queue_id); queue_id = 0; } @@ -4678,7 +4590,8 @@ build_ports(struct ovsdb_idl_txn *ovnsb_txn, { struct ovs_list sb_only, nb_only, both; struct hmap tag_alloc_table = HMAP_INITIALIZER(&tag_alloc_table); - struct hmap chassis_qdisc_queues = HMAP_INITIALIZER(&chassis_qdisc_queues); + unsigned long *queue_id_bitmap = bitmap_allocate(QDISC_MAX_QUEUE_ID + 1); + bitmap_set1(queue_id_bitmap, 0); /* sset which stores the set of ha chassis group names used. */ struct sset active_ha_chassis_grps = @@ -4688,7 +4601,7 @@ build_ports(struct ovsdb_idl_txn *ovnsb_txn, * We will split them later. */ struct hmap *ports = ls_ports; join_logical_ports(sbrec_port_binding_table, ls_datapaths, lr_datapaths, - ports, &chassis_qdisc_queues, + ports, queue_id_bitmap, &tag_alloc_table, &sb_only, &nb_only, &both); /* Purge stale Mac_Bindings if ports are deleted. */ @@ -4736,7 +4649,7 @@ build_ports(struct ovsdb_idl_txn *ovnsb_txn, sbrec_chassis_by_hostname, sbrec_ha_chassis_grp_by_name, sbrec_mirror_table, - op, &chassis_qdisc_queues, + op, queue_id_bitmap, &active_ha_chassis_grps); } @@ -4747,7 +4660,7 @@ build_ports(struct ovsdb_idl_txn *ovnsb_txn, sbrec_chassis_by_hostname, sbrec_ha_chassis_grp_by_name, sbrec_mirror_table, - op, &chassis_qdisc_queues, + op, queue_id_bitmap, &active_ha_chassis_grps); sbrec_port_binding_set_logical_port(op->sb, op->key); } @@ -4776,7 +4689,7 @@ build_ports(struct ovsdb_idl_txn *ovnsb_txn, } tag_alloc_destroy(&tag_alloc_table); - destroy_chassis_queues(&chassis_qdisc_queues); + bitmap_free(queue_id_bitmap); cleanup_sb_ha_chassis_groups(sbrec_ha_chassis_group_table, &active_ha_chassis_grps); sset_destroy(&active_ha_chassis_grps);