summaryrefslogtreecommitdiff
path: root/net-fs/openafs/files/0014-upstream-struct-init.patch
blob: e25e4898f57088c076de43db936d137fe397c2f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
From 9e612ba7bf1ccea8158ae38b5d687d8d78e1630e Mon Sep 17 00:00:00 2001
From: Cheyenne Wills <cwills@sinenomine.net>
Date: Wed, 26 Feb 2025 08:03:18 -0700
Subject: [PATCH 1/2] Convert HAVE_STRUCT_LABEL_SUPPORT to AFS_STRUCT_INIT

The OpenAFS coding style allows the use of designated initializers for
structs, however not all supported platforms have compilers that support
it.

The preprocessor define HAVE_STRUCT_LABEL_SUPPORT has been available for
use so structure initialization can be set up to support compilers that
do have designated initializers support.

The typical use is:

    struct foo x = {
    #ifndef HAVE_STRUCT_LABEL_SUPPORT
        val1,
        val2,
        ...
    #else
        .mem1 = val1,
        .mem2 = val2,
        ...
    #endif
    };

This results in extra lines of code where errors can easily be
introduced.

Create a macro, AFS_STRUCT_INIT, that uses designated initializers when
available, so the above example would be:

    struct foo x = {
        AFS_STRUCT_INIT(.mem1, val1),
        AFS_STRUCT_INIT(.mem2, val2),
        ...
    };

Convert the initialization of structures that are using the
HAVE_STRUCT_LABEL_SUPPORT define to use AFS_STRUCT_INIT.

Note, there is still a requirement that the order of initializers match
the order of the elements within the structure, but it should be easier
to verify that the initializers are in the proper order.

Use a consistent alignment, and add trailing comma on the last
element.

There are no functional changes made by this commit.

Reviewed-on: https://gerrit.openafs.org/16289
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
(cherry picked from commit 7c28b99490b75475ed9130526c536ae0e354e064)

Change-Id: I8faa4b497f2962bdd0a4ecb559e8b9288fd5c796
---
 src/afs/afs_dcache.c     | 66 ++++++++++++----------------------------
 src/afs/afs_fetchstore.c | 54 ++++++++++----------------------
 src/config/stds.h        |  6 ++++
 src/rx/xdr_len.c         | 28 +++++------------
 src/rx/xdr_mem.c         | 28 +++++------------
 src/rx/xdr_rx.c          | 28 +++++------------
 6 files changed, 66 insertions(+), 144 deletions(-)

diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c
index 35fd5947325d..e41ba8ff3a8e 100644
--- a/src/afs/afs_dcache.c
+++ b/src/afs/afs_dcache.c
@@ -104,55 +104,29 @@ afs_int32 afs_dcentries;	/*!< In-memory dcache entries */
 int dcacheDisabled = 0;
 
 struct afs_cacheOps afs_UfsCacheOps = {
-#ifndef HAVE_STRUCT_LABEL_SUPPORT
-    osi_UFSOpen,
-    osi_UFSTruncate,
-    afs_osi_Read,
-    afs_osi_Write,
-    osi_UFSClose,
-    afs_UFSReadUIO,
-    afs_UFSWriteUIO,
-    afs_UFSGetDSlot,
-    afs_UFSGetVolSlot,
-    afs_UFSHandleLink,
-#else
-    .open 	= osi_UFSOpen,
-    .truncate	= osi_UFSTruncate,
-    .fread	= afs_osi_Read,
-    .fwrite	= afs_osi_Write,
-    .close	= osi_UFSClose,
-    .vreadUIO	= afs_UFSReadUIO,
-    .vwriteUIO	= afs_UFSWriteUIO,
-    .GetDSlot	= afs_UFSGetDSlot,
-    .GetVolSlot = afs_UFSGetVolSlot,
-    .HandleLink	= afs_UFSHandleLink,
-#endif
+    AFS_STRUCT_INIT(.open,	osi_UFSOpen),
+    AFS_STRUCT_INIT(.truncate,	osi_UFSTruncate),
+    AFS_STRUCT_INIT(.fread,	afs_osi_Read),
+    AFS_STRUCT_INIT(.fwrite,	afs_osi_Write),
+    AFS_STRUCT_INIT(.close,	osi_UFSClose),
+    AFS_STRUCT_INIT(.vreadUIO,	afs_UFSReadUIO),
+    AFS_STRUCT_INIT(.vwriteUIO,	afs_UFSWriteUIO),
+    AFS_STRUCT_INIT(.GetDSlot,	afs_UFSGetDSlot),
+    AFS_STRUCT_INIT(.GetVolSlot, afs_UFSGetVolSlot),
+    AFS_STRUCT_INIT(.HandleLink, afs_UFSHandleLink),
 };
 
 struct afs_cacheOps afs_MemCacheOps = {
-#ifndef HAVE_STRUCT_LABEL_SUPPORT
-    afs_MemCacheOpen,
-    afs_MemCacheTruncate,
-    afs_MemReadBlk,
-    afs_MemWriteBlk,
-    afs_MemCacheClose,
-    afs_MemReadUIO,
-    afs_MemWriteUIO,
-    afs_MemGetDSlot,
-    afs_MemGetVolSlot,
-    afs_MemHandleLink,
-#else
-    .open	= afs_MemCacheOpen,
-    .truncate	= afs_MemCacheTruncate,
-    .fread	= afs_MemReadBlk,
-    .fwrite	= afs_MemWriteBlk,
-    .close	= afs_MemCacheClose,
-    .vreadUIO	= afs_MemReadUIO,
-    .vwriteUIO	= afs_MemWriteUIO,
-    .GetDSlot	= afs_MemGetDSlot,
-    .GetVolSlot	= afs_MemGetVolSlot,
-    .HandleLink	= afs_MemHandleLink,
-#endif
+    AFS_STRUCT_INIT(.open,	afs_MemCacheOpen),
+    AFS_STRUCT_INIT(.truncate,	afs_MemCacheTruncate),
+    AFS_STRUCT_INIT(.fread,	afs_MemReadBlk),
+    AFS_STRUCT_INIT(.fwrite,	afs_MemWriteBlk),
+    AFS_STRUCT_INIT(.close,	afs_MemCacheClose),
+    AFS_STRUCT_INIT(.vreadUIO,	afs_MemReadUIO),
+    AFS_STRUCT_INIT(.vwriteUIO,	afs_MemWriteUIO),
+    AFS_STRUCT_INIT(.GetDSlot,	afs_MemGetDSlot),
+    AFS_STRUCT_INIT(.GetVolSlot, afs_MemGetVolSlot),
+    AFS_STRUCT_INIT(.HandleLink, afs_MemHandleLink),
 };
 
 int cacheDiskType;		/*Type of backing disk for cache */
diff --git a/src/afs/afs_fetchstore.c b/src/afs/afs_fetchstore.c
index 97d0671811dc..5baf371a2c6a 100644
--- a/src/afs/afs_fetchstore.c
+++ b/src/afs/afs_fetchstore.c
@@ -309,48 +309,26 @@ afs_GenericStoreProc(struct storeOps *ops, void *rock,
 
 static
 struct storeOps rxfs_storeUfsOps = {
-#ifndef HAVE_STRUCT_LABEL_SUPPORT
-    rxfs_storeUfsPrepare,
-    rxfs_storeUfsRead,
-    rxfs_storeUfsWrite,
-    rxfs_storeStatus,
-    rxfs_storePadd,
-    rxfs_storeClose,
-    rxfs_storeDestroy,
-    afs_GenericStoreProc
-#else
-    .prepare = 	rxfs_storeUfsPrepare,
-    .read =	rxfs_storeUfsRead,
-    .write =	rxfs_storeUfsWrite,
-    .status =	rxfs_storeStatus,
-    .padd =	rxfs_storePadd,
-    .close =	rxfs_storeClose,
-    .destroy =	rxfs_storeDestroy,
-    .storeproc = afs_GenericStoreProc
-#endif
+    AFS_STRUCT_INIT(.prepare,	rxfs_storeUfsPrepare),
+    AFS_STRUCT_INIT(.read,	rxfs_storeUfsRead),
+    AFS_STRUCT_INIT(.write,	rxfs_storeUfsWrite),
+    AFS_STRUCT_INIT(.status,	rxfs_storeStatus),
+    AFS_STRUCT_INIT(.padd,	rxfs_storePadd),
+    AFS_STRUCT_INIT(.close,	rxfs_storeClose),
+    AFS_STRUCT_INIT(.destroy,	rxfs_storeDestroy),
+    AFS_STRUCT_INIT(.storeproc,	afs_GenericStoreProc),
 };
 
 static
 struct storeOps rxfs_storeMemOps = {
-#ifndef HAVE_STRUCT_LABEL_SUPPORT
-    rxfs_storeMemPrepare,
-    rxfs_storeMemRead,
-    rxfs_storeMemWrite,
-    rxfs_storeStatus,
-    rxfs_storePadd,
-    rxfs_storeClose,
-    rxfs_storeDestroy,
-    afs_GenericStoreProc
-#else
-    .prepare =	rxfs_storeMemPrepare,
-    .read = 	rxfs_storeMemRead,
-    .write = 	rxfs_storeMemWrite,
-    .status =	rxfs_storeStatus,
-    .padd =	rxfs_storePadd,
-    .close = 	rxfs_storeClose,
-    .destroy =	rxfs_storeDestroy,
-    .storeproc = afs_GenericStoreProc
-#endif
+    AFS_STRUCT_INIT(.prepare,	rxfs_storeMemPrepare),
+    AFS_STRUCT_INIT(.read,	rxfs_storeMemRead),
+    AFS_STRUCT_INIT(.write,	rxfs_storeMemWrite),
+    AFS_STRUCT_INIT(.status,	rxfs_storeStatus),
+    AFS_STRUCT_INIT(.padd,	rxfs_storePadd),
+    AFS_STRUCT_INIT(.close,	rxfs_storeClose),
+    AFS_STRUCT_INIT(.destroy,	rxfs_storeDestroy),
+    AFS_STRUCT_INIT(.storeproc,	afs_GenericStoreProc),
 };
 
 static afs_int32
diff --git a/src/config/stds.h b/src/config/stds.h
index 8ae68343458b..ae030149f6d2 100644
--- a/src/config/stds.h
+++ b/src/config/stds.h
@@ -305,6 +305,12 @@ hdr_static_inline(unsigned long long) afs_printable_uint64_lu(afs_uint64 d) { re
 # define AFS_FALLTHROUGH do {} while(0)
 #endif
 
+#if defined(HAVE_STRUCT_LABEL_SUPPORT)
+# define AFS_STRUCT_INIT(member, value) member = (value)
+#else
+# define AFS_STRUCT_INIT(member, value) (value)
+#endif
+
 /*
  * Conditionally remove unreached statements under Solaris Studio.
  */
diff --git a/src/rx/xdr_len.c b/src/rx/xdr_len.c
index 5de15d010d62..9f9fe1ca92ac 100644
--- a/src/rx/xdr_len.c
+++ b/src/rx/xdr_len.c
@@ -84,26 +84,14 @@ xdrlen_inline(XDR *xdrs, u_int len)
 }
 
 static struct xdr_ops xdrlen_ops = {
-#ifndef HAVE_STRUCT_LABEL_SUPPORT
-    /* Windows does not support labeled assigments */
-    xdrlen_getint32,    /* not supported */
-    xdrlen_putint32,    /* serialize an afs_int32 */
-    xdrlen_getbytes,    /* not supported */
-    xdrlen_putbytes,    /* serialize counted bytes */
-    xdrlen_getpos,      /* get offset in the stream */
-    xdrlen_setpos,      /* set offset in the stream */
-    xdrlen_inline,      /* not supported */
-    xdrlen_destroy,     /* destroy stream */
-#else
-    .x_getint32 = xdrlen_getint32,
-    .x_putint32 = xdrlen_putint32,
-    .x_getbytes = xdrlen_getbytes,
-    .x_putbytes = xdrlen_putbytes,
-    .x_getpostn = xdrlen_getpos,
-    .x_setpostn = xdrlen_setpos,
-    .x_inline = xdrlen_inline,
-    .x_destroy = xdrlen_destroy
-#endif
+    AFS_STRUCT_INIT(.x_getint32, xdrlen_getint32), /* not supported */
+    AFS_STRUCT_INIT(.x_putint32, xdrlen_putint32), /* serialize an afs_int32 */
+    AFS_STRUCT_INIT(.x_getbytes, xdrlen_getbytes), /* not supported */
+    AFS_STRUCT_INIT(.x_putbytes, xdrlen_putbytes), /* serialize counted bytes */
+    AFS_STRUCT_INIT(.x_getpostn, xdrlen_getpos),   /* get offset in the stream */
+    AFS_STRUCT_INIT(.x_setpostn, xdrlen_setpos),   /* set offset in the stream */
+    AFS_STRUCT_INIT(.x_inline,	 xdrlen_inline),   /* not supported */
+    AFS_STRUCT_INIT(.x_destroy,	 xdrlen_destroy),  /* destroy stream */
 };
 
 /**
diff --git a/src/rx/xdr_mem.c b/src/rx/xdr_mem.c
index ae849f521bf6..bd6720505edb 100644
--- a/src/rx/xdr_mem.c
+++ b/src/rx/xdr_mem.c
@@ -59,26 +59,14 @@ static afs_int32 *xdrmem_inline(XDR *, u_int);
 static void xdrmem_destroy(XDR *);
 
 static struct xdr_ops xdrmem_ops = {
-#ifndef HAVE_STRUCT_LABEL_SUPPORT
-    /* Windows does not support labeled assigments */
-    xdrmem_getint32,    /* deserialize an afs_int32 */
-    xdrmem_putint32,    /* serialize an afs_int32 */
-    xdrmem_getbytes,    /* deserialize counted bytes */
-    xdrmem_putbytes,    /* serialize counted bytes */
-    xdrmem_getpos,      /* get offset in the stream: not supported. */
-    xdrmem_setpos,      /* set offset in the stream: not supported. */
-    xdrmem_inline,      /* prime stream for inline macros */
-    xdrmem_destroy,     /* destroy stream */
-#else
-    .x_getint32 = xdrmem_getint32,
-    .x_putint32 = xdrmem_putint32,
-    .x_getbytes = xdrmem_getbytes,
-    .x_putbytes = xdrmem_putbytes,
-    .x_getpostn = xdrmem_getpos,
-    .x_setpostn = xdrmem_setpos,
-    .x_inline = xdrmem_inline,
-    .x_destroy = xdrmem_destroy
-#endif
+    AFS_STRUCT_INIT(.x_getint32, xdrmem_getint32), /* deserialize an afs_int32 */
+    AFS_STRUCT_INIT(.x_putint32, xdrmem_putint32), /* serialize an afs_int32 */
+    AFS_STRUCT_INIT(.x_getbytes, xdrmem_getbytes), /* deserialize counted bytes */
+    AFS_STRUCT_INIT(.x_putbytes, xdrmem_putbytes), /* serialize counted bytes */
+    AFS_STRUCT_INIT(.x_getpostn, xdrmem_getpos),   /* get offset in the stream: not supported. */
+    AFS_STRUCT_INIT(.x_setpostn, xdrmem_setpos),   /* set offset in the stream: not supported. */
+    AFS_STRUCT_INIT(.x_inline,	 xdrmem_inline),   /* prime stream for inline macros */
+    AFS_STRUCT_INIT(.x_destroy,	 xdrmem_destroy),  /* destroy stream */
 };
 
 /*
diff --git a/src/rx/xdr_rx.c b/src/rx/xdr_rx.c
index 62fbed331b02..34e2b4d75efe 100644
--- a/src/rx/xdr_rx.c
+++ b/src/rx/xdr_rx.c
@@ -49,26 +49,14 @@ static afs_int32 *xdrrx_inline(XDR *axdrs, u_int len);
  * Ops vector for stdio type XDR
  */
 static struct xdr_ops xdrrx_ops = {
-#ifndef HAVE_STRUCT_LABEL_SUPPORT
-    /* Windows does not support labeled assigments */
-    xdrrx_getint32,	/* deserialize an afs_int32 */
-    xdrrx_putint32,	/* serialize an afs_int32 */
-    xdrrx_getbytes,	/* deserialize counted bytes */
-    xdrrx_putbytes,	/* serialize counted bytes */
-    NULL,		/* get offset in the stream: not supported. */
-    NULL,		/* set offset in the stream: not supported. */
-    xdrrx_inline,	/* prime stream for inline macros */
-    NULL,		/* destroy stream */
-#else
-    .x_getint32 = xdrrx_getint32,	/* deserialize an afs_int32 */
-    .x_putint32 = xdrrx_putint32,	/* serialize an afs_int32 */
-    .x_getbytes = xdrrx_getbytes,	/* deserialize counted bytes */
-    .x_putbytes = xdrrx_putbytes,	/* serialize counted bytes */
-    .x_getpostn = NULL,		/* get offset in the stream: not supported. */
-    .x_setpostn = NULL,		/* set offset in the stream: not supported. */
-    .x_inline = xdrrx_inline,		/* prime stream for inline macros */
-    .x_destroy = NULL,			/* destroy stream */
-#endif
+    AFS_STRUCT_INIT(.x_getint32, xdrrx_getint32),	/* deserialize an afs_int32 */
+    AFS_STRUCT_INIT(.x_putint32, xdrrx_putint32),	/* serialize an afs_int32 */
+    AFS_STRUCT_INIT(.x_getbytes, xdrrx_getbytes),	/* deserialize counted bytes */
+    AFS_STRUCT_INIT(.x_putbytes, xdrrx_putbytes),	/* serialize counted bytes */
+    AFS_STRUCT_INIT(.x_getpostn, NULL),			/* get offset in the stream: not supported. */
+    AFS_STRUCT_INIT(.x_setpostn, NULL),			/* set offset in the stream: not supported. */
+    AFS_STRUCT_INIT(.x_inline,	 xdrrx_inline),		/* prime stream for inline macros */
+    AFS_STRUCT_INIT(.x_destroy,	 NULL),			/* destroy stream */
 };
 
 /*
-- 
2.45.3