Skip to content

Commit 9c57724

Browse files
author
Martin Belanger
committed
generate-accessors: switch annotations to // comment style
Replace the /*!annotation*/ block-comment style with // line comments throughout. The canonical form is '// !token' (one space between // and !). The parser accepts any amount of whitespace between // and !, so '//!token', '// !token', and '//\t!token' are all equivalent. This makes the annotation resilient to contributor variation. Update all annotated structs in private.h and private-fabrics.h, and update the documentation and helper scripts accordingly. The generated accessors.{h,c} and accessors-fabrics.{h,c} are unchanged. Signed-off-by: Martin Belanger <[email protected]>
1 parent bea1cf0 commit 9c57724

6 files changed

Lines changed: 143 additions & 131 deletions

File tree

libnvme/src/nvme/private-fabrics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct libnvmf_context {
7878
* rest of the fabrics layer.
7979
*/
8080

81-
struct libnvmf_discovery_args { /*!generate-accessors*/
81+
struct libnvmf_discovery_args { // !generate-accessors
8282
int max_retries;
8383
__u8 lsp;
8484
};
@@ -95,7 +95,7 @@ struct libnvmf_discovery_args { /*!generate-accessors*/
9595
* @fragment: Optional fragment identifier component
9696
* (separated by '#')
9797
*/
98-
struct libnvmf_uri { //!generate-accessors
98+
struct libnvmf_uri { // !generate-accessors
9999
char *scheme;
100100
char *protocol;
101101
char *userinfo;

libnvme/src/nvme/private.h

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct linux_passthru_cmd64 {
102102
* @tls: Start TLS on the connection (TCP)
103103
* @concat: Enable secure concatenation (TCP)
104104
*/
105-
struct libnvme_fabrics_config { //!generate-accessors
105+
struct libnvme_fabrics_config { // !generate-accessors
106106
int queue_size;
107107
int nr_io_queues;
108108
int reconnect_delay;
@@ -167,7 +167,7 @@ struct libnvme_transport_handle {
167167
struct libnvme_log *log;
168168
};
169169

170-
struct libnvme_path { /*!generate-accessors*/
170+
struct libnvme_path { // !generate-accessors
171171
struct list_node entry;
172172
struct list_node nentry;
173173

@@ -179,7 +179,7 @@ struct libnvme_path { /*!generate-accessors*/
179179
char *ana_state;
180180
char *numa_nodes;
181181
int grpid;
182-
int queue_depth; //!accessors:none
182+
int queue_depth; // !accessors:none
183183
};
184184

185185
struct libnvme_ns_head {
@@ -189,7 +189,7 @@ struct libnvme_ns_head {
189189
char *sysfs_dir;
190190
};
191191

192-
struct libnvme_ns { /*!generate-accessors*/
192+
struct libnvme_ns { // !generate-accessors
193193
struct list_node entry;
194194

195195
struct libnvme_subsystem *s;
@@ -200,7 +200,7 @@ struct libnvme_ns { /*!generate-accessors*/
200200
struct libnvme_transport_handle *hdl;
201201
__u32 nsid;
202202
char *name;
203-
char *generic_name; //!accessors:none
203+
char *generic_name; // !accessors:none
204204
char *sysfs_dir;
205205

206206
int lba_shift;
@@ -215,78 +215,78 @@ struct libnvme_ns { /*!generate-accessors*/
215215
enum nvme_csi csi;
216216
};
217217

218-
struct libnvme_ctrl { /*!generate-accessors*/
218+
struct libnvme_ctrl { // !generate-accessors
219219
struct list_node entry;
220220
struct list_head paths;
221221
struct list_head namespaces;
222222
struct libnvme_subsystem *s;
223223

224224
struct libnvme_global_ctx *ctx;
225225
struct libnvme_transport_handle *hdl;
226-
char *name; //!accessors:readonly
227-
char *sysfs_dir; //!accessors:readonly
228-
char *address; //!accessors:none
229-
char *firmware; //!accessors:readonly
230-
char *model; //!accessors:readonly
231-
char *state; //!accessors:none
232-
char *numa_node; //!accessors:readonly
233-
char *queue_count; //!accessors:readonly
234-
char *serial; //!accessors:readonly
235-
char *sqsize; //!accessors:readonly
236-
char *transport; //!accessors:readonly
237-
char *subsysnqn; //!accessors:readonly
238-
char *traddr; //!accessors:readonly
239-
char *trsvcid; //!accessors:readonly
226+
char *name; // !accessors:readonly
227+
char *sysfs_dir; // !accessors:readonly
228+
char *address; // !accessors:none
229+
char *firmware; // !accessors:readonly
230+
char *model; // !accessors:readonly
231+
char *state; // !accessors:none
232+
char *numa_node; // !accessors:readonly
233+
char *queue_count; // !accessors:readonly
234+
char *serial; // !accessors:readonly
235+
char *sqsize; // !accessors:readonly
236+
char *transport; // !accessors:readonly
237+
char *subsysnqn; // !accessors:readonly
238+
char *traddr; // !accessors:readonly
239+
char *trsvcid; // !accessors:readonly
240240
char *dhchap_host_key;
241241
char *dhchap_ctrl_key;
242242
char *keyring;
243243
char *tls_key_identity;
244244
char *tls_key;
245-
char *cntrltype; //!accessors:readonly
246-
char *cntlid; //!accessors:readonly
247-
char *dctype; //!accessors:readonly
248-
char *phy_slot; //!accessors:readonly
249-
char *host_traddr; //!accessors:readonly
250-
char *host_iface; //!accessors:readonly
245+
char *cntrltype; // !accessors:readonly
246+
char *cntlid; // !accessors:readonly
247+
char *dctype; // !accessors:readonly
248+
char *phy_slot; // !accessors:readonly
249+
char *host_traddr; // !accessors:readonly
250+
char *host_iface; // !accessors:readonly
251251
bool discovery_ctrl;
252252
bool unique_discovery_ctrl;
253253
bool discovered;
254254
bool persistent;
255255
struct libnvme_fabrics_config cfg;
256256
};
257257

258-
struct libnvme_subsystem { /*!generate-accessors*/
258+
struct libnvme_subsystem { // !generate-accessors
259259
struct list_node entry;
260260
struct list_head ctrls;
261261
struct list_head namespaces;
262262
struct libnvme_host *h;
263263

264-
char *name; /*!accessors:readonly*/
265-
char *sysfs_dir; /*!accessors:readonly*/
266-
char *subsysnqn; /*!accessors:readonly*/
267-
char *model; /*!accessors:readonly*/
268-
char *serial; /*!accessors:readonly*/
269-
char *firmware; /*!accessors:readonly*/
270-
char *subsystype; /*!accessors:readonly*/
264+
char *name; // !accessors:readonly
265+
char *sysfs_dir; // !accessors:readonly
266+
char *subsysnqn; // !accessors:readonly
267+
char *model; // !accessors:readonly
268+
char *serial; // !accessors:readonly
269+
char *firmware; // !accessors:readonly
270+
char *subsystype; // !accessors:readonly
271271
char *application;
272272
char *iopolicy;
273273
};
274274

275-
struct libnvme_host { /*!generate-accessors*/
275+
struct libnvme_host { // !generate-accessors
276276
struct list_node entry;
277277
struct list_head subsystems;
278278
struct libnvme_global_ctx *ctx;
279279

280-
char *hostnqn; /*!accessors:readonly*/
281-
char *hostid; /*!accessors:readonly*/
280+
char *hostnqn; // !accessors:readonly
281+
char *hostid; // !accessors:readonly
282282
char *dhchap_host_key;
283283
char *hostsymname;
284-
bool pdc_enabled; //!accessors:none
284+
bool pdc_enabled; // !accessors:none
285285
bool pdc_enabled_valid; /* set if pdc_enabled doesn't have an undefined
286286
* value */
287287
};
288288

289-
struct libnvme_fabric_options { /*!generate-accessors*/
289+
struct libnvme_fabric_options { // !generate-accessors
290290
bool cntlid;
291291
bool concat;
292292
bool ctrl_loss_tmo;

libnvme/tools/generator/generate-accessors.md

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,29 @@ python3 generate-accessors.py [options] <header-files>
2525

2626
## Annotations
2727

28-
Struct inclusion and member behaviour are controlled by **annotations written as comments directly in the header file**. Both `/* */` (block) and `//` (line) comment styles are supported for every annotation.
28+
Struct inclusion and member behaviour are controlled by **annotations written as
29+
`//` comments directly in the header file**. The canonical form is `// !token`
30+
(one space between `//` and `!`). The parser also accepts `//!token` and
31+
`//\t!token` — any amount of whitespace between `//` and `!` is treated
32+
identically, making the annotation resilient to contributor variation.
2933

3034
### Struct inclusion — `generate-accessors`
3135

3236
Place the annotation on the same line as the struct's opening brace to opt that struct in to code generation. An optional mode qualifier sets the **default behaviour for all members** of that struct:
3337

34-
| Annotation | Default for all members |
35-
| --------------------------------------- | --------------------------------- |
36-
| `//!generate-accessors` | getter **and** setter (default) |
37-
| `//!generate-accessors:none` | no accessors |
38-
| `//!generate-accessors:readonly` | getter only |
39-
| `//!generate-accessors:writeonly` | setter only |
38+
| Annotation | Default for all members |
39+
| ---------------------------------------- | --------------------------------- |
40+
| `// !generate-accessors` | getter **and** setter (default) |
41+
| `// !generate-accessors:none` | no accessors |
42+
| `// !generate-accessors:readonly` | getter only |
43+
| `// !generate-accessors:writeonly` | setter only |
4044

4145
```c
42-
struct nvme_ctrl { /*!generate-accessors*/ /* both getter and setter */
46+
struct nvme_ctrl { // !generate-accessors /* both getter and setter */
4347
...
4448
};
4549

46-
struct nvme_ctrl { //!generate-accessors:readonly /* getter only by default */
50+
struct nvme_ctrl { // !generate-accessors:readonly /* getter only by default */
4751
...
4852
};
4953
```
@@ -57,10 +61,10 @@ Individual members can always override the struct-level default using a per-memb
5761
Place the annotation on a member's declaration line to suppress accessor generation for that member entirely (no setter, no getter):
5862

5963
```c
60-
struct nvme_ctrl { /*!generate-accessors*/
64+
struct nvme_ctrl { // !generate-accessors
6165
char *name;
62-
char *state; //!accessors:none
63-
char *subsysnqn; /*!accessors:none*/
66+
char *state; // !accessors:none
67+
char *subsysnqn; // !accessors:none
6468
};
6569
```
6670

@@ -69,10 +73,10 @@ struct nvme_ctrl { /*!generate-accessors*/
6973
Place the annotation on a member's declaration line to generate only a getter (no setter). This has the same effect as declaring the member `const`, but without changing the type in the struct. Also useful to override a `generate-accessors:writeonly` struct default for individual members:
7074

7175
```c
72-
struct nvme_ctrl { /*!generate-accessors*/
76+
struct nvme_ctrl { // !generate-accessors
7377
char *name;
74-
char *firmware; //!accessors:readonly
75-
char *model; /*!accessors:readonly*/
78+
char *firmware; // !accessors:readonly
79+
char *model; // !accessors:readonly
7680
};
7781
```
7882

@@ -83,9 +87,9 @@ Members declared with the `const` qualifier are also automatically read-only.
8387
Place the annotation on a member's declaration line to generate only a setter (no getter). Useful to override a `generate-accessors:readonly` struct default for individual members:
8488

8589
```c
86-
struct nvme_ctrl { /*!generate-accessors:readonly*/
90+
struct nvme_ctrl { // !generate-accessors:readonly
8791
char *name; /* getter only (struct default) */
88-
char *token; //!accessors:writeonly /* setter only override */
92+
char *token; // !accessors:writeonly /* setter only override */
8993
};
9094
```
9195

@@ -94,25 +98,25 @@ struct nvme_ctrl { /*!generate-accessors:readonly*/
9498
Place the annotation on a member's declaration line to generate both a getter and a setter, overriding a restrictive struct-level default (`none`, `readonly`, or `writeonly`):
9599

96100
```c
97-
struct nvme_ctrl { /*!generate-accessors:none*/
101+
struct nvme_ctrl { // !generate-accessors:none
98102
char *name; /* no accessors (struct default) */
99-
char *model; //!accessors:readwrite /* both getter and setter */
100-
char *firmware; //!accessors:readonly /* getter only */
103+
char *model; // !accessors:readwrite /* both getter and setter */
104+
char *firmware; // !accessors:readonly /* getter only */
101105
};
102106
```
103107

104108
### Annotation summary
105109

106-
| Annotation | Where | Effect |
107-
| --------------------------------------- | ------------ | ------------------------------------------- |
108-
| `//!generate-accessors` | struct brace | Include struct, default: getter + setter |
109-
| `//!generate-accessors:none` | struct brace | Include struct, default: no accessors |
110-
| `//!generate-accessors:readonly` | struct brace | Include struct, default: getter only |
111-
| `//!generate-accessors:writeonly` | struct brace | Include struct, default: setter only |
112-
| `//!accessors:none` | member line | Skip this member entirely |
113-
| `//!accessors:readonly` | member line | Generate getter only |
114-
| `//!accessors:writeonly` | member line | Generate setter only |
115-
| `//!accessors:readwrite` | member line | Generate getter and setter |
110+
| Annotation | Where | Effect |
111+
| ---------------------------------------- | ------------ | ------------------------------------------- |
112+
| `// !generate-accessors` | struct brace | Include struct, default: getter + setter |
113+
| `// !generate-accessors:none` | struct brace | Include struct, default: no accessors |
114+
| `// !generate-accessors:readonly` | struct brace | Include struct, default: getter only |
115+
| `// !generate-accessors:writeonly` | struct brace | Include struct, default: setter only |
116+
| `// !accessors:none` | member line | Skip this member entirely |
117+
| `// !accessors:readonly` | member line | Generate getter only |
118+
| `// !accessors:writeonly` | member line | Generate setter only |
119+
| `// !accessors:readwrite` | member line | Generate getter and setter |
116120
| `const` qualifier on member | member type | Suppress setter (built-in, always applies) |
117121

118122
------
@@ -122,15 +126,15 @@ struct nvme_ctrl { /*!generate-accessors:none*/
122126
### Header file (`person.h`)
123127

124128
```c
125-
struct person { /*!generate-accessors*/
129+
struct person { // !generate-accessors
126130
char *name;
127131
int age;
128132
const char *id; /* const → getter only, no annotation needed */
129-
char *secret; //!accessors:none
130-
char *role; //!accessors:readonly
133+
char *secret; // !accessors:none
134+
char *role; // !accessors:readonly
131135
};
132136

133-
struct car { /*!generate-accessors*/
137+
struct car { // !generate-accessors
134138
char *model;
135139
int year;
136140
const char *vin;
@@ -258,7 +262,7 @@ const char *car_get_vin(const struct car *p);
258262
#endif /* _ACCESSORS_H_ */
259263
```
260264

261-
> **Note:** The `secret` member is absent because of `//!accessors:none` — excluded members leave no trace in the output. The `role` member has only a getter because of `//!accessors:readonly`. The `id` and `vin` members have only getters because they are declared `const`.
265+
> **Note:** The `secret` member is absent because of `// !accessors:none` — excluded members leave no trace in the output. The `role` member has only a getter because of `// !accessors:readonly`. The `id` and `vin` members have only getters because they are declared `const`.
262266
263267
### Generated `accessors.c`
264268

@@ -361,7 +365,7 @@ LIBNVME_ACCESSORS_3 {
361365
};
362366
```
363367
364-
> **Note:** Only symbols for members that have accessors generated appear in the linker script. The `secret` member (excluded via `//!accessors:none`) and the write-only `token` example would have no getter entry. The version node name `LIBNVME_ACCESSORS_3` is hardcoded in the generator.
368+
> **Note:** Only symbols for members that have accessors generated appear in the linker script. The `secret` member (excluded via `// !accessors:none`) and the write-only `token` example would have no getter entry. The version node name `LIBNVME_ACCESSORS_3` is hardcoded in the generator.
365369
366370
------
367371
@@ -379,10 +383,10 @@ LIBNVME_ACCESSORS_3 {
379383
2. **String arrays** (`char **`) — setters deep-copy NULL-terminated arrays (each element and the container).
380384
3. **Fixed char arrays** (`char foo[N]`) — setters use `snprintf`, always NUL-terminated.
381385
4. **`const` members** — only a getter is generated, no setter (applies regardless of any annotation).
382-
5. **`//!accessors:readonly`** — same effect as `const`: getter only.
383-
6. **`//!accessors:writeonly`** — setter only; getter is suppressed.
384-
7. **`//!accessors:readwrite`** — both getter and setter; overrides a restrictive struct-level default.
385-
8. **`//!accessors:none`** — member is completely ignored by the generator.
386+
5. **`// !accessors:readonly`** — same effect as `const`: getter only.
387+
6. **`// !accessors:writeonly`** — setter only; getter is suppressed.
388+
7. **`// !accessors:readwrite`** — both getter and setter; overrides a restrictive struct-level default.
389+
8. **`// !accessors:none`** — member is completely ignored by the generator.
386390
9. **Struct-level mode** — the qualifier on `generate-accessors` sets the default for every member in the struct; per-member annotations override the struct default.
387391
10. **`--prefix`** — prepended to every function name (e.g. `--prefix nvme_` turns `ctrl_set_name` into `nvme_ctrl_set_name`).
388392
11. **Line length** — generated code is automatically wrapped to stay within the 80-column limit required by `checkpatch.pl`.

0 commit comments

Comments
 (0)