From patchwork Fri Oct 18 10:09:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ales Musil X-Patchwork-Id: 1999043 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=K7W444Or; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XVL6c2Gtvz1xwD for ; Fri, 18 Oct 2024 21:10:00 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id CB0E140E16; Fri, 18 Oct 2024 10:09:57 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id QQdPrfe__0Mq; Fri, 18 Oct 2024 10:09:55 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 0260B40E82 Authentication-Results: smtp2.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=K7W444Or Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 0260B40E82; Fri, 18 Oct 2024 10:09:55 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C5DBBC08A6; Fri, 18 Oct 2024 10:09:54 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1F555C08A6 for ; Fri, 18 Oct 2024 10:09:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id A1D6A40871 for ; Fri, 18 Oct 2024 10:09:49 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id r5BeZ0H7Nh0s for ; Fri, 18 Oct 2024 10:09:48 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=amusil@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org B0EAF4080C Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org B0EAF4080C Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=K7W444Or Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id B0EAF4080C for ; Fri, 18 Oct 2024 10:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729246187; 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=P2dhbzJKjLyLDNYUL/2a1lnA6ii0UqOwuDTM8eLqvWE=; b=K7W444Ornq1FuV/yUhX0Wb9BTUx4/Y4i2SczCKoXu/j6L6l0Ts2ZzGYMLPAtPuIz7X6EgW EWsVmCUSbEUf7aOX9EQl74LZ+fYTmxZTBbsFm0bTNKEnVmJ45+ZVw1d7XbFrrZU86/8O5p hqOixRjeBf03EVAWDGAoFfdXhx5tEpg= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-342-dqMgosQqPBiK96bgJWFhsA-1; Fri, 18 Oct 2024 06:09:43 -0400 X-MC-Unique: dqMgosQqPBiK96bgJWFhsA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 47D351956096; Fri, 18 Oct 2024 10:09:42 +0000 (UTC) Received: from amusil.redhat.com (unknown [10.45.225.43]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 65A4519560A3; Fri, 18 Oct 2024 10:09:40 +0000 (UTC) From: Ales Musil To: dev@openvswitch.org Date: Fri, 18 Oct 2024 12:09:28 +0200 Message-ID: <20241018100930.826293-4-amusil@redhat.com> In-Reply-To: <20241018100930.826293-1-amusil@redhat.com> References: <20241018100930.826293-1-amusil@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH ovn 3/5] northd: Use the same UUID for SB representation of DNS. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dceara@redhat.com Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" The NB DNS has exactly one corresponding row in SB database. Use the NB UUID for the SB representation which makes the processing easier and the link between the rows is obvious at first glance. Signed-off-by: Ales Musil --- controller/pinctrl.c | 76 ++++++++++++++++++++++++-------------------- northd/northd.c | 21 +++--------- 2 files changed, 45 insertions(+), 52 deletions(-) diff --git a/controller/pinctrl.c b/controller/pinctrl.c index b891435c1..8a681ede7 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -3273,6 +3273,8 @@ put_be32(struct ofpbuf *buf, ovs_be32 x) } struct dns_data { + struct hmap_node hmap_node; + struct uuid uuid; uint64_t *dps; size_t n_dps; struct smap records; @@ -3280,7 +3282,20 @@ struct dns_data { bool delete; }; -static struct shash dns_cache = SHASH_INITIALIZER(&dns_cache); +static struct hmap dns_cache = HMAP_INITIALIZER(&dns_cache); + +static struct dns_data * +dns_cache_find_data(const struct uuid *uuid) +{ + struct dns_data *dns_data; + size_t hash = uuid_hash(uuid); + HMAP_FOR_EACH_WITH_HASH (dns_data, hmap_node, hash, &dns_cache) { + if (uuid_equals(&dns_data->uuid, uuid)) { + return dns_data; + } + } + return NULL; +} /* Called by pinctrl_run(). Runs within the main ovn-controller * thread context. */ @@ -3288,25 +3303,20 @@ static void sync_dns_cache(const struct sbrec_dns_table *dns_table) OVS_REQUIRES(pinctrl_mutex) { - struct shash_node *iter; - SHASH_FOR_EACH (iter, &dns_cache) { - struct dns_data *d = iter->data; - d->delete = true; + struct dns_data *dns_data; + HMAP_FOR_EACH (dns_data, hmap_node, &dns_cache) { + dns_data->delete = true; } const struct sbrec_dns *sbrec_dns; SBREC_DNS_TABLE_FOR_EACH (sbrec_dns, dns_table) { - const char *dns_id = smap_get(&sbrec_dns->external_ids, "dns_id"); - if (!dns_id) { - continue; - } - - struct dns_data *dns_data = shash_find_data(&dns_cache, dns_id); + const struct uuid *uuid = &sbrec_dns->header_.uuid; + dns_data = dns_cache_find_data(uuid); if (!dns_data) { dns_data = xmalloc(sizeof *dns_data); smap_init(&dns_data->records); smap_init(&dns_data->options); - shash_add(&dns_cache, dns_id, dns_data); + hmap_insert(&dns_cache, &dns_data->hmap_node, uuid_hash(uuid)); dns_data->n_dps = 0; dns_data->dps = NULL; } else { @@ -3333,14 +3343,13 @@ sync_dns_cache(const struct sbrec_dns_table *dns_table) } } - SHASH_FOR_EACH_SAFE (iter, &dns_cache) { - struct dns_data *d = iter->data; - if (d->delete) { - shash_delete(&dns_cache, iter); - smap_destroy(&d->records); - smap_destroy(&d->options); - free(d->dps); - free(d); + HMAP_FOR_EACH_SAFE (dns_data, hmap_node, &dns_cache) { + if (dns_data->delete) { + hmap_remove(&dns_cache, &dns_data->hmap_node); + smap_destroy(&dns_data->records); + smap_destroy(&dns_data->options); + free(dns_data->dps); + free(dns_data); } } } @@ -3348,14 +3357,12 @@ sync_dns_cache(const struct sbrec_dns_table *dns_table) static void destroy_dns_cache(void) { - struct shash_node *iter; - SHASH_FOR_EACH_SAFE (iter, &dns_cache) { - struct dns_data *d = iter->data; - shash_delete(&dns_cache, iter); - smap_destroy(&d->records); - smap_destroy(&d->options); - free(d->dps); - free(d); + struct dns_data *dns_data; + HMAP_FOR_EACH_POP (dns_data, hmap_node, &dns_cache) { + smap_destroy(&dns_data->records); + smap_destroy(&dns_data->options); + free(dns_data->dps); + free(dns_data); } } @@ -3543,17 +3550,16 @@ pinctrl_handle_dns_lookup( uint64_t dp_key = ntohll(pin->flow_metadata.flow.metadata); const char *answer_data = NULL; bool ovn_owned = false; - struct shash_node *iter; - SHASH_FOR_EACH (iter, &dns_cache) { - struct dns_data *d = iter->data; - ovn_owned = smap_get_bool(&d->options, "ovn-owned", false); - for (size_t i = 0; i < d->n_dps; i++) { - if (d->dps[i] == dp_key) { + struct dns_data *dns_data; + HMAP_FOR_EACH (dns_data, hmap_node, &dns_cache) { + ovn_owned = smap_get_bool(&dns_data->options, "ovn-owned", false); + for (size_t i = 0; i < dns_data->n_dps; i++) { + if (dns_data->dps[i] == dp_key) { /* DNS records in SBDB are stored in lowercase. Convert to * lowercase to perform case insensitive lookup */ char *query_name_lower = str_tolower(ds_cstr(&query_name)); - answer_data = smap_get(&d->records, query_name_lower); + answer_data = smap_get(&dns_data->records, query_name_lower); free(query_name_lower); if (answer_data) { break; diff --git a/northd/northd.c b/northd/northd.c index 0dac661b0..a81defe49 100644 --- a/northd/northd.c +++ b/northd/northd.c @@ -18162,7 +18162,7 @@ struct dns_info { }; static inline struct dns_info * -get_dns_info_from_hmap(struct hmap *dns_map, struct uuid *uuid) +get_dns_info_from_hmap(struct hmap *dns_map, const struct uuid *uuid) { struct dns_info *dns_info; size_t hash = uuid_hash(uuid); @@ -18208,15 +18208,8 @@ sync_dns_entries(struct ovsdb_idl_txn *ovnsb_txn, const struct sbrec_dns *sbrec_dns; SBREC_DNS_TABLE_FOR_EACH_SAFE (sbrec_dns, sbrec_dns_table) { - const char *nb_dns_uuid = smap_get(&sbrec_dns->external_ids, "dns_id"); - struct uuid dns_uuid; - if (!nb_dns_uuid || !uuid_from_string(&dns_uuid, nb_dns_uuid)) { - sbrec_dns_delete(sbrec_dns); - continue; - } - struct dns_info *dns_info = - get_dns_info_from_hmap(&dns_map, &dns_uuid); + get_dns_info_from_hmap(&dns_map, &sbrec_dns->header_.uuid); if (dns_info) { dns_info->sb_dns = sbrec_dns; } else { @@ -18227,14 +18220,8 @@ sync_dns_entries(struct ovsdb_idl_txn *ovnsb_txn, struct dns_info *dns_info; HMAP_FOR_EACH_POP (dns_info, hmap_node, &dns_map) { if (!dns_info->sb_dns) { - sbrec_dns = sbrec_dns_insert(ovnsb_txn); - dns_info->sb_dns = sbrec_dns; - char *dns_id = xasprintf( - UUID_FMT, UUID_ARGS(&dns_info->nb_dns->header_.uuid)); - const struct smap external_ids = - SMAP_CONST1(&external_ids, "dns_id", dns_id); - sbrec_dns_set_external_ids(sbrec_dns, &external_ids); - free(dns_id); + dns_info->sb_dns = sbrec_dns_insert_persist_uuid( + ovnsb_txn, &dns_info->nb_dns->header_.uuid); } /* Copy DNS options to SB*/