Thread (5 messages) 5 messages, 2 authors, 2020-05-05

Re: [PATCH iproute2-next 1/2] ss: introduce cgroup2 cache and helper functions

From: David Ahern <hidden>
Date: 2020-05-05 15:42:18
Also in: bpf, cgroups

global comment. iproute2 uses the net coding style of reverse xmas tree
for declarations. There are a number of places that need to be fixed up.

On 4/30/20 9:52 AM, Dmitry Yakunin wrote:
quoted hunk ↗ jump to hunk
diff --git a/lib/cg_map.c b/lib/cg_map.c
new file mode 100644
index 0000000..0a1d834
--- /dev/null
+++ b/lib/cg_map.c
@@ -0,0 +1,133 @@
+/*
+ * cg_map.c	cgroup v2 cache
+ *
+ *		This program is free software; you can redistribute it and/or
+ *		modify it under the terms of the GNU General Public License
+ *		as published by the Free Software Foundation; either version
+ *		2 of the License, or (at your option) any later version.
Drop the boilerplate in favor of SPDX line
+ *
+ * Authors:	Dmitry Yakunin [off-list ref]
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <linux/types.h>
+#include <linux/limits.h>
+#include <ftw.h>
+
+#include "cg_map.h"
+#include "list.h"
+#include "utils.h"
+
+struct cg_cache {
+	struct hlist_node id_hash;
+	__u64	id;
+	char	path[];
+};
+
+#define IDMAP_SIZE	1024
+static struct hlist_head id_head[IDMAP_SIZE];
+
+static struct cg_cache *cg_get_by_id(__u64 id)
+{
+	struct hlist_node *n;
+	unsigned int h = id & (IDMAP_SIZE - 1);
+
+	hlist_for_each(n, &id_head[h]) {
+		struct cg_cache *cg
+			= container_of(n, struct cg_cache, id_hash);
Don't split the line like that. Since you need 2 lines just do:
+		struct cg_cache *cg;
+
+		cg = container_of(n, struct cg_cache, id_hash);
+		if (cg->id == id)
+			return cg;
+	}
+
+	return NULL;
+}
+


Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help