Skip to content

Commit a19cf14

Browse files
Martin Belangerigaw
authored andcommitted
libnvme: replace accessor generator with Python and add in-source annotations
The generate-accessors tool has been rewritten in Python (generate-accessors.py) and the mechanism for controlling which structs and members get accessors has moved from separate list files to in-source annotations in the header files themselves. Struct inclusion is now opt-in via an annotation on the opening brace: struct nvme_ctrl { /*!generate-accessors*/ Members can be excluded or made read-only via per-member annotations: char *state; //!accessors:none char *firmware; //!accessors:readonly Both /* */ and // comment styles are accepted for all annotations. This replaces the generate-accessors-include.list and generate-accessors-exclude.list files, which are no longer needed. The annotations are co-located with the struct definitions, making it immediately visible from the header which structs and members are covered and why. The Python rewrite is significantly shorter (~350 lines vs ~2100) and handles the annotation-before-comment-stripping requirement naturally, whereas the C implementation would have required keeping a raw copy of each struct body in parallel with the comment-masked version. private.h is updated with the equivalent annotations that were previously expressed through the now-deleted list files. meson.build and update-accessors.sh are updated accordingly. The --incl and --excl CLI options are removed as they are superseded by annotations. Signed-off-by: Martin Belanger <[email protected]>
1 parent 1583464 commit a19cf14

8 files changed

Lines changed: 865 additions & 2378 deletions

File tree

libnvme/src/nvme/private.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct nvme_transport_handle {
128128
struct nvme_log *log;
129129
};
130130

131-
struct nvme_path {
131+
struct nvme_path { /*!generate-accessors*/
132132
struct list_node entry;
133133
struct list_node nentry;
134134

@@ -140,7 +140,7 @@ struct nvme_path {
140140
char *ana_state;
141141
char *numa_nodes;
142142
int grpid;
143-
int queue_depth;
143+
int queue_depth; //!accessors:none
144144
};
145145

146146
struct nvme_ns_head {
@@ -150,7 +150,7 @@ struct nvme_ns_head {
150150
char *sysfs_dir;
151151
};
152152

153-
struct nvme_ns {
153+
struct nvme_ns { /*!generate-accessors*/
154154
struct list_node entry;
155155

156156
struct nvme_subsystem *s;
@@ -161,7 +161,7 @@ struct nvme_ns {
161161
struct nvme_transport_handle *hdl;
162162
__u32 nsid;
163163
char *name;
164-
char *generic_name;
164+
char *generic_name; //!accessors:none
165165
char *sysfs_dir;
166166

167167
int lba_shift;
@@ -176,7 +176,7 @@ struct nvme_ns {
176176
enum nvme_csi csi;
177177
};
178178

179-
struct nvme_ctrl {
179+
struct nvme_ctrl { /*!generate-accessors*/
180180
struct list_node entry;
181181
struct list_head paths;
182182
struct list_head namespaces;
@@ -186,16 +186,16 @@ struct nvme_ctrl {
186186
struct nvme_transport_handle *hdl;
187187
char *name;
188188
char *sysfs_dir;
189-
char *address;
189+
char *address; //!accessors:none
190190
char *firmware;
191191
char *model;
192-
char *state;
192+
char *state; //!accessors:none
193193
char *numa_node;
194194
char *queue_count;
195195
char *serial;
196196
char *sqsize;
197197
char *transport;
198-
char *subsysnqn;
198+
char *subsysnqn; //!accessors:none
199199
char *traddr;
200200
char *trsvcid;
201201
char *dhchap_host_key;
@@ -206,7 +206,7 @@ struct nvme_ctrl {
206206
char *cntrltype;
207207
char *cntlid;
208208
char *dctype;
209-
char *phy_slot;
209+
char *phy_slot; //!accessors:none
210210
char *host_traddr;
211211
char *host_iface;
212212
bool discovery_ctrl;
@@ -216,7 +216,7 @@ struct nvme_ctrl {
216216
struct nvme_fabrics_config cfg;
217217
};
218218

219-
struct nvme_subsystem {
219+
struct nvme_subsystem { /*!generate-accessors*/
220220
struct list_node entry;
221221
struct list_head ctrls;
222222
struct list_head namespaces;
@@ -233,7 +233,7 @@ struct nvme_subsystem {
233233
char *iopolicy;
234234
};
235235

236-
struct nvme_host {
236+
struct nvme_host { /*!generate-accessors*/
237237
struct list_node entry;
238238
struct list_head subsystems;
239239
struct nvme_global_ctx *ctx;
@@ -242,12 +242,12 @@ struct nvme_host {
242242
char *hostid;
243243
char *dhchap_host_key;
244244
char *hostsymname;
245-
bool pdc_enabled;
245+
bool pdc_enabled; //!accessors:none
246246
bool pdc_enabled_valid; /* set if pdc_enabled doesn't have an undefined
247247
* value */
248248
};
249249

250-
struct nvme_fabric_options {
250+
struct nvme_fabric_options { /*!generate-accessors*/
251251
bool cntlid;
252252
bool concat;
253253
bool ctrl_loss_tmo;

libnvme/tools/generator/generate-accessors-exclude.list

Lines changed: 0 additions & 10 deletions
This file was deleted.

libnvme/tools/generator/generate-accessors-include.list

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)