From e5bdc50bc303c33a2ce936b3355823e24cbe1e5a Mon Sep 17 00:00:00 2001
From: Lwithwma Brahma <l.brahma@gxgroup.eu>
Date: Mon, 30 Aug 2021 09:18:30 +0530
Subject: [PATCH] qosmngr: do not read stats for disabled queues

-Fix qos ubus call in mixed mode
---
 src/qosmngr.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/qosmngr.c b/src/qosmngr.c
index a059cee..4c05a3f 100644
--- a/src/qosmngr.c
+++ b/src/qosmngr.c
@@ -79,11 +79,15 @@ static int get_no_queues(const char *ifname)
        uci_foreach_element(&uci_pkg->sections, uci_elmnt) {
                struct uci_section *uci_sec = uci_to_section(uci_elmnt);
                if (uci_sec && !strcmp(uci_sec->type, "queue")) {
-                       struct uci_element *e = NULL;
-                       uci_foreach_element(&uci_sec->options, e) {
-                               struct uci_option *uci_opn = uci_to_option(e);
-                               if (uci_opn && !strcmp(uci_opn->v.string, ifname))
-                                       queues++;
+                       const char *opt_enab;
+                       opt_enab = uci_lookup_option_string(uci_ctx, uci_sec, "enable");
+                       if (opt_enab && !strcmp(opt_enab, "1")) {
+                               struct uci_element *e = NULL;
+                               uci_foreach_element(&uci_sec->options, e) {
+                                       struct uci_option *uci_opn = uci_to_option(e);
+                                       if (uci_opn && !strcmp(uci_opn->v.string, ifname))
+                                               queues++;
+                               }
                        }
                }
        }
@@ -383,7 +387,7 @@ static int prepare_stats_blob(struct blob_buf *b, struct qos_stats *stats, void
 static int get_stats_by_ifname(struct blob_buf *b, struct qos_stats *stats, void *dd,
 				char *ifname, int qid)
 {
-	int ret = 0;
+	int ret = -1;
 
 	if (qid >= 0) {
 		ret = prepare_stats_blob(b, stats, dd, ifname, qid);
@@ -391,10 +395,15 @@ static int get_stats_by_ifname(struct blob_buf *b, struct qos_stats *stats, void
 		int i;
 		int queues = get_no_queues(ifname);
 
+		if (queues <= 0) {
+			ret = 0;
+			return ret;
+		}
+
 		for (i = 0; i < queues; i++) {
-			ret = prepare_stats_blob(b, stats, dd, ifname, i);
-			if (ret != 0)
-				return ret;
+			int pst = prepare_stats_blob(b, stats, dd, ifname, i);
+			if (pst == 0)
+				ret = 0;
 		}
 	}
 
-- 
GitLab