Two more metadata parser fixes
v2 cover Two more metadata parser fixes
This series fixes a metadata parser for the ".filesystems" entry of the tst_test structure. First patch fixes the data storage to JSON serialization and second patch changes the parser to convert structure intialization with only designated initializers into a hash (object) rather than an arrray.
V2: Fixed corner case in structure parsing as reported by Andrea
Cyril Hrubis (2):
metadata: data_storage: Fix hash to json object serialization
metaparse: Map arrays with designated initializers to JSON objects
metadata/data_storage.h | 28 ++++++-- metadata/metaparse.c | 142 +++++++++++++++++++++++++++++++++------- 2 files changed, 143 insertions(+), 27 deletions(-)
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/2 metadata: data_storage: Fix hash to json object serialization
We have to move the curly braces into the switch() that prints the JSON values otherwise inner object will not have curly braces around them and the resulting JSON is not valid.
The changes between the old generated metadata and new metadata are only in the whitespaces:
--- metadata/data_storage.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
metadata/data_storage.h +4 -4
@@ -396,14 +396,16 @@ static inline void data_to_json_(struct data_node *self, FILE *f, unsigned int pdata_fprintf (f, padd,"null" );break ;case DATA_HASH : +data_fprintf (f, do_padd ? padd :0 ,"{\n" );for (i =0 ; i < self->hash.elems_used; i++) { -data_fprintf (f, padd,"\"%s\": " , self->hash.elems[i].id); +data_fprintf (f, padd+1 ,"\"%s\": " , self->hash.elems[i].id);data_to_json_ (self->hash.elems[i].node, f, padd+1 ,0 );if (i < self->hash.elems_used -1 )fprintf (f,",\n" );else fprintf (f,"\n" ); } +data_fprintf (f, padd,"}" );break ;case DATA_ARRAY :data_fprintf (f, do_padd ? padd :0 ,"[\n" );
@@ -421,9 +423,7 @@ static inline void data_to_json_(struct data_node *self, FILE *f, unsigned int pstatic inline void data_to_json (struct data_node *self,FILE *f,unsigned int padd) { -fprintf (f,"{\n" ); -data_to_json_ (self, f, padd +1 ,1 ); -data_fprintf (f, padd,"}" ); +data_to_json_ (self, f, padd,0 ); }#endif /* DATA_STORAGE_H__ */
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 metaparse: Map arrays with designated initializers to JSON objects
In reply to Cyril HrubisThe parser now scans array declarations and if it finds out that complete initialization is using designated initializers the result is mapped into a JSON object instead of an arrray.
A diff snippet looks like:
--------------------------
"filesystems": [
- [
- ".type=btrfs"
- ],
- [
- ".type=bcachefs"
- ],
- [
- ".type=xfs", - ".min_kver=4.16", - ".mkfs_ver=mkfs.xfs >= 1.5.0", - [
+ {
+ "type": "btrfs"
+ },
+ {
+ "type": "bcachefs"
+ },
+ {
+ "type": "xfs",
+ "min_kver": "4.16",
+ "mkfs_ver": "mkfs.xfs >= 1.5.0",
+ "mkfs_opts": [
"-m",
"reflink=1"- ],
- ".mkfs_opts=(constchar*const[])"
- ]
+ ]
+ }
],
--------------------------
--- metadata/data_storage.h | 20 ++++++ metadata/metaparse.c | 142 +++++++++++++++++++++++++++++++++------- 2 files changed, 139 insertions(+), 23 deletions(-)
metadata/data_storage.h +20 -0
@@ -10,6 +10,7 @@#include <stdio.h> #include <string.h> #include <stdlib.h> +#include <stdbool.h> enum data_type {DATA_ARRAY ,
@@ -228,6 +229,13 @@ static inline struct data_node *data_node_hash_get(struct data_node *self, constreturn hash->elems[i].node; } +static inline unsigned int data_node_hash_len (struct data_node *self) +{ +struct data_node_hash *hash = &self->hash; + +return hash->elems_used; +} +static inline int data_node_array_add (struct data_node *self,struct data_node *payload) {if (self->type !=DATA_ARRAY )
@@ -285,6 +293,18 @@ static inline void data_print_padd(unsigned int i)putchar (' ' ); } +static inline bool data_node_is_empty (struct data_node *self) +{ +switch (self->type) { +case DATA_ARRAY : +return data_node_array_len (self) ==0 ; +case DATA_HASH : +return data_node_hash_len (self) ==0 ; +default : +return false; + } +} +static inline void data_node_print_ (struct data_node *self,unsigned int padd) {unsigned int i;
metadata/metaparse.c +119 -23
196 lines not on this page · raw message
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] metaparse: Map arrays with designated initializers to JSON objects
Hi!
Now docs seem to be broken for tst_test.filesystems. This patch will solve the issue and it needs to be added to the patch-set:
doc/conf.py +0 -0
@@ -406,13 +406,12 @@ def _generate_setup_table(keys):
else:
values.append(f'{value[0]}, {value[1]}') elif key == 'filesystems':
- for v in value:
- for item in v:
- if isinstance(item, list):
- continue
-
- if item.startswith('.type'):
- values.append(item.replace('.type=', '')) + for params in value:
+ for pkey, pval in params.items():
+ if pkey == "type":
+ values.append(f"- {pval}")
+ else:
+ values.append(f" {pkey}: {pval}") elif key == "save_restore":
for item in value:
values.append(item[0])
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] metaparse: Map arrays with designated initializers to JSON objects
Hi!
Quoted 17 lines
Now docs seem to be broken for tst_test.filesystems. This patch will solve the issue and it needs to be added to the patch-set:
doc/conf.py +0
-6@@ -406,13 +406,12 @@ def _generate_setup_table(keys): else: values.append(f'{value[0]}, {value[1]}') elif key == 'filesystems': - for v in value: - for item in v: - if isinstance(item, list): - continue - - if item.startswith('.type'):
doc/conf.py def _generate_setup_table(keys): · line 417
Quoted 10 lines
doc/conf.py +6
-1- values.append(item.replace('.type=', '')) + for params in value: + for pkey, pval in params.items(): + if pkey == "type": + values.append(f"- {pval}") + else: + values.append(f" {pkey}: {pval}") elif key == "save_restore": for item in value: values.append(item[0])
Can you please send a proper patch so that I can apply all three patches together?
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] metaparse: Map arrays with designated initializers to JSON objects
Quoted 22 lines · Cyril Hrubis
Hi!
Quoted 21 lines
Now docs seem to be broken for tst_test.filesystems. This patch will solve the issue and it needs to be added to the patch-set:
doc/conf.py +3
-7@@ -406,13 +406,12 @@ def _generate_setup_table(keys): else: values.append(f'{value[0]}, {value[1]}') elif key == 'filesystems': - for v in value: - for item in v: - if isinstance(item, list): - continue - - if item.startswith('.type'): - values.append(item.replace('.type=', '')) + for params in value: + for pkey, pval in params.items(): + if pkey == "type":
Quoted 9 lines
doc/conf.py def _generate_setup_table(keys): · line 417
Quoted 6 lines
doc/conf.py +3
-0+ values.append(f"- {pval}") + else: + values.append(f" {pkey}: {pval}") elif key == "save_restore": for item in value: values.append(item[0])Can you please send a proper patch so that I can apply all three patches together?
From 072dacd2072d0cf3acce9d623091ab0e586e4799 Mon Sep 17 00:00:00 2001
From: Andrea Cervesato <[email protected]>
Date: Fri, 11 Jul 2025 15:17:12 +0200
Subject: [PATCH v1] doc: update filesystems info according to new metadata
To: [email protected]
New metadata is now using a dictionary definition for tst_test.filesystems. This patch will correctly show the filesystems setup information inside the html page.
---
doc/conf.py | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
doc/conf.py +0 -0
@@ -406,13 +406,12 @@ def _generate_setup_table(keys):
else:
values.append(f'{value[0]}, {value[1]}') elif key == 'filesystems':
- for v in value:
- for item in v:
- if isinstance(item, list):
- continue
-
- if item.startswith('.type'):
- values.append(item.replace('.type=', '')) + for params in value:
+ for pkey, pval in params.items():
+ if pkey == "type":
+ values.append(f"- {pval}")
+ else:
+ values.append(f" {pkey}: {pval}") elif key == "save_restore":
for item in value:
values.append(item[0])
Signature · 6 lines
2.50.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp