[PATCH] dcache: Define DNAME_INLINE_LEN as a number directly

From: Tiezhu Yang
Date: Tue May 20 2025 - 02:48:28 EST


When executing the bcc script, there exists the following error
on LoongArch and x86_64:

Traceback (most recent call last):
File "/usr/share/bcc/tools/filetop", line 218, in <module>
counts = b.get_table("counts")
File "/usr/lib/python3.13/site-packages/bcc-0.34.0+a434ee50-py3.13.egg/bcc/__init__.py", line 658, in get_table
keytype = BPF._decode_table_type(json.loads(key_desc))
~~~~~~~~~~^^^^^^^^^^
File "/usr/lib64/python3.13/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
~~~~~~~~~~~~~~~~~~~~~~~^^^
File "/usr/lib64/python3.13/json/decoder.py", line 345, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.13/json/decoder.py", line 361, in raw_decode
obj, end = self.scan_once(s, idx)
~~~~~~~~~~~~~~^^^^^^^^
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 179 (char 178)

Here is the related definition in tools/filetop.py of bcc:

// the key for the output summary
struct info_t {
unsigned long inode;
dev_t dev;
dev_t rdev;
u32 pid;
u32 name_len;
char comm[TASK_COMM_LEN];
// de->d_name.name may point to de->d_iname so limit len accordingly
char name[DNAME_INLINE_LEN];
char type;
};

Here is the output of print(key_desc) in src/python/bcc/__init__.py
of bcc, there is a missing ',' between "char" and "unsigned long" at
column 179 for the "name" member.

["info_t", [["inode","unsigned long"], ["dev","unsigned int"], ["rdev","unsigned int"], ["pid","unsigned int"], ["name_len","unsigned int"], ["comm","char", [16]], ["name","char""unsigned long", [40]], ["type","char"], ["__pad_end","char",[7]] ], "struct_packed"]

In order to avoid such issues, define DNAME_INLINE_LEN as a number
directly, there is only "char" and no "unsigned long" at column 179
for the "name" member with this patch.

["info_t", [["inode","unsigned long"], ["dev","unsigned int"], ["rdev","unsigned int"], ["pid","unsigned int"], ["name_len","unsigned int"], ["comm","char", [16]], ["name","char", [40]], ["type","char"], ["__pad_end","char",[7]] ], "struct_packed"]

How to reproduce:

git clone https://github.com/iovisor/bcc.git
mkdir bcc/build; cd bcc/build
cmake ..
make
sudo make install
sudo /usr/share/bcc/tools/filetop

Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
---
include/linux/dcache.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index e9f07e37dd6f..08e91738e3de 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -70,15 +70,17 @@ extern const struct qstr dotdot_name;
*/
#ifdef CONFIG_64BIT
# define DNAME_INLINE_WORDS 5 /* 192 bytes */
+# define DNAME_INLINE_LEN 40
#else
# ifdef CONFIG_SMP
# define DNAME_INLINE_WORDS 9 /* 128 bytes */
+# define DNAME_INLINE_LEN 36
# else
# define DNAME_INLINE_WORDS 11 /* 128 bytes */
+# define DNAME_INLINE_LEN 44
# endif
#endif

-#define DNAME_INLINE_LEN (DNAME_INLINE_WORDS*sizeof(unsigned long))

union shortname_store {
unsigned char string[DNAME_INLINE_LEN];
--
2.42.0