Blame SOURCES/0024-JSON-Improve-performance-of-json_events_cb.patch

8fd843
From 58d8baa70172bb9862276ac5f542248c88d3faf4 Mon Sep 17 00:00:00 2001
8fd843
From: Phil Sutter <psutter@redhat.com>
8fd843
Date: Wed, 24 Jun 2020 18:48:14 +0200
8fd843
Subject: [PATCH] JSON: Improve performance of json_events_cb()
8fd843
8fd843
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1835300
8fd843
Upstream Status: nftables commit c96c7da272e33
8fd843
8fd843
commit c96c7da272e33a34770c4de4e3e50f7ed264672e
8fd843
Author: Phil Sutter <phil@nwl.cc>
8fd843
Date:   Wed May 13 16:29:51 2020 +0200
8fd843
8fd843
    JSON: Improve performance of json_events_cb()
8fd843
8fd843
    The function tries to insert handles into JSON input for echo option.
8fd843
    Yet there may be nothing to do if the given netlink message doesn't
8fd843
    contain a handle, e.g. if it is an 'add element' command. Calling
8fd843
    seqnum_to_json() is pointless overhead in that case, and if input is
8fd843
    large this overhead is significant. Better wait with that call until
8fd843
    after checking if the message is relevant at all.
8fd843
8fd843
    Signed-off-by: Phil Sutter <phil@nwl.cc>
8fd843
    Acked-by: Eric Garver <eric@garver.life>
8fd843
---
8fd843
 src/parser_json.c | 9 ++++++---
8fd843
 1 file changed, 6 insertions(+), 3 deletions(-)
8fd843
8fd843
diff --git a/src/parser_json.c b/src/parser_json.c
8fd843
index c48faa8..ce8e566 100644
8fd843
--- a/src/parser_json.c
8fd843
+++ b/src/parser_json.c
8fd843
@@ -3845,12 +3845,15 @@ static uint64_t handle_from_nlmsg(const struct nlmsghdr *nlh)
8fd843
 }
8fd843
 int json_events_cb(const struct nlmsghdr *nlh, struct netlink_mon_handler *monh)
8fd843
 {
8fd843
-	json_t *tmp, *json = seqnum_to_json(nlh->nlmsg_seq);
8fd843
 	uint64_t handle = handle_from_nlmsg(nlh);
8fd843
+	json_t *tmp, *json;
8fd843
 	void *iter;
8fd843
 
8fd843
-	/* might be anonymous set, ignore message */
8fd843
-	if (!json || !handle)
8fd843
+	if (!handle)
8fd843
+		return MNL_CB_OK;
8fd843
+
8fd843
+	json = seqnum_to_json(nlh->nlmsg_seq);
8fd843
+	if (!json)
8fd843
 		return MNL_CB_OK;
8fd843
 
8fd843
 	tmp = json_object_get(json, "add");
8fd843
-- 
bfbb76
2.31.1
8fd843