Blob Blame History Raw
From 82e377ad94ff84f3b1fd82e9aa8ea8edbd5b9337 Mon Sep 17 00:00:00 2001
Message-Id: <82e377ad94ff84f3b1fd82e9aa8ea8edbd5b9337.1569932887.git.lorenzo.bianconi@redhat.com>
In-Reply-To: <9c04a4b62484895dc301875ad9da7c77c17a99c7.1569932887.git.lorenzo.bianconi@redhat.com>
References: <9c04a4b62484895dc301875ad9da7c77c17a99c7.1569932887.git.lorenzo.bianconi@redhat.com>
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Date: Tue, 24 Sep 2019 18:39:55 +0200
Subject: [PATCH ovn 2/3] northd: add the possibility to define localnet as qos
 capable port

Refactor allocate_chassis_queueid and free_chassis_queueid in order
to get an unused queue_id even for localnet ports and add the
the possibility to define localnet as qos capable port

Acked-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Mark Michelson <mmichels@redhat.com>
Acked-by: Mark Michelson <mmichels@redhat.com>
---
 ovn/northd/ovn-northd.c | 45 ++++++++++++++++++++++++++++++---------------
 1 file changed, 30 insertions(+), 15 deletions(-)

--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -357,7 +357,7 @@ destroy_chassis_queues(struct hmap *set)
 }
 
 static void
-add_chassis_queue(struct hmap *set, struct uuid *chassis_uuid,
+add_chassis_queue(struct hmap *set, const struct uuid *chassis_uuid,
                   uint32_t queue_id)
 {
     struct ovn_chassis_qdisc_queues *node = xmalloc(sizeof *node);
@@ -368,7 +368,7 @@ add_chassis_queue(struct hmap *set, stru
 }
 
 static bool
-chassis_queueid_in_use(const struct hmap *set, struct uuid *chassis_uuid,
+chassis_queueid_in_use(const struct hmap *set, const struct uuid *chassis_uuid,
                        uint32_t queue_id)
 {
     const struct ovn_chassis_qdisc_queues *node;
@@ -383,31 +383,38 @@ chassis_queueid_in_use(const struct hmap
 }
 
 static uint32_t
-allocate_chassis_queueid(struct hmap *set, struct sbrec_chassis *chassis)
+allocate_chassis_queueid(struct hmap *set, const struct uuid *uuid, char *name)
 {
+    if (!uuid) {
+        return 0;
+    }
+
     for (uint32_t queue_id = QDISC_MIN_QUEUE_ID + 1;
          queue_id <= QDISC_MAX_QUEUE_ID;
          queue_id++) {
-        if (!chassis_queueid_in_use(set, &chassis->header_.uuid, queue_id)) {
-            add_chassis_queue(set, &chassis->header_.uuid, 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", chassis->name);
+    VLOG_WARN_RL(&rl, "all %s queue ids exhausted", name);
     return 0;
 }
 
 static void
-free_chassis_queueid(struct hmap *set, struct sbrec_chassis *chassis,
+free_chassis_queueid(struct hmap *set, const struct uuid *uuid,
                      uint32_t queue_id)
 {
-    const struct uuid *chassis_uuid = &chassis->header_.uuid;
+    if (!uuid) {
+        return;
+    }
+
     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)
+                             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);
@@ -2568,15 +2575,23 @@ ovn_port_update_sbrec(struct northd_cont
             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 (!strcmp(op->nbsp->type, "localnet")) {
+                uuid = &op->sb->header_.uuid;
+                name = "localnet";
+            } else if (op->sb->chassis) {
+                uuid = &op->sb->chassis->header_.uuid;
+                name = op->sb->chassis->name;
+            }
 
-            if (op->sb->chassis && has_qos && !queue_id) {
+            if (has_qos && !queue_id) {
                 queue_id = allocate_chassis_queueid(chassis_qdisc_queues,
-                                                    op->sb->chassis);
+                                                    uuid, name);
             } else if (!has_qos && queue_id) {
-                free_chassis_queueid(chassis_qdisc_queues,
-                                     op->sb->chassis,
-                                     queue_id);
+                free_chassis_queueid(chassis_qdisc_queues, uuid, queue_id);
                 queue_id = 0;
             }