rf_compat80.c revision 1.14.14.1 1 /* $NetBSD: rf_compat80.c,v 1.14.14.1 2021/05/31 22:15:19 cjep Exp $ */
2
3 /*
4 * Copyright (c) 2017 Matthew R. Green
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/module.h>
35
36 #include <sys/compat_stub.h>
37
38 #include <dev/raidframe/raidframeio.h>
39 #include <dev/raidframe/raidframevar.h>
40
41 #include "rf_raid.h"
42 #include "rf_compat80.h"
43 #include "rf_kintf.h"
44
45 /* NetBSD 8.99.x removed the row, raidPtr and next members */
46 struct rf_recon_req80 {
47 RF_RowCol_t row, col;
48 RF_ReconReqFlags_t flags;
49 void *raidPtr; /* used internally; need not be set at ioctl
50 * time */
51 struct rf_recon_req *next; /* used internally; need not be set at
52 * ioctl time */
53 };
54
55 /* NetBSD 8.99.x made this structure alignment neutral */
56 typedef struct RF_RaidDisk_s80 {
57 char devname[56]; /* name of device file */
58 RF_DiskStatus_t status; /* whether it is up or down */
59 RF_RowCol_t spareRow; /* if in status "spared", this identifies the
60 * spare disk */
61 RF_RowCol_t spareCol; /* if in status "spared", this identifies the
62 * spare disk */
63 RF_SectorCount_t numBlocks; /* number of blocks, obtained via READ
64 * CAPACITY */
65 int blockSize;
66 RF_SectorCount_t partitionSize; /* The *actual* and *full* size of
67 the partition, from the disklabel */
68 int auto_configured;/* 1 if this component was autoconfigured.
69 0 otherwise. */
70 dev_t dev;
71 } RF_RaidDisk_t80;
72
73 typedef struct RF_DeviceConfig_s80 {
74 u_int rows;
75 u_int cols;
76 u_int maxqdepth;
77 int ndevs;
78 RF_RaidDisk_t80 devs[RF_MAX_DISKS];
79 int nspares;
80 RF_RaidDisk_t80 spares[RF_MAX_DISKS];
81 } RF_DeviceConfig_t80;
82
83 typedef struct RF_Config_s80 {
84 RF_RowCol_t numRow, numCol, numSpare; /* number of rows, columns,
85 * and spare disks */
86 dev_t devs[RF_MAXROW][RF_MAXCOL]; /* device numbers for disks
87 * comprising array */
88 char devnames[RF_MAXROW][RF_MAXCOL][50]; /* device names */
89 dev_t spare_devs[RF_MAXSPARE]; /* device numbers for spare
90 * disks */
91 char spare_names[RF_MAXSPARE][50]; /* device names */
92 RF_SectorNum_t sectPerSU; /* sectors per stripe unit */
93 RF_StripeNum_t SUsPerPU;/* stripe units per parity unit */
94 RF_StripeNum_t SUsPerRU;/* stripe units per reconstruction unit */
95 RF_ParityConfig_t parityConfig; /* identifies the RAID architecture to
96 * be used */
97 RF_DiskQueueType_t diskQueueType; /* 'f' = fifo, 'c' = cvscan,
98 * not used in kernel */
99 char maxOutstandingDiskReqs; /* # concurrent reqs to be sent to a
100 * disk. not used in kernel. */
101 char debugVars[RF_MAXDBGV][50]; /* space for specifying debug
102 * variables & their values */
103 unsigned int layoutSpecificSize; /* size in bytes of
104 * layout-specific info */
105 void *layoutSpecific; /* a pointer to a layout-specific structure to
106 * be copied in */
107 int force; /* if !0, ignore many fatal
108 configuration conditions */
109 /*
110 "force" is used to override cases where the component labels would
111 indicate that configuration should not proceed without user
112 intervention
113 */
114 } RF_Config_t80;
115
116 static int
117 rf_check_recon_status_ext80(RF_Raid_t *raidPtr, void *data)
118 {
119 RF_ProgressInfo_t info, **infoPtr = data;
120
121 rf_check_recon_status_ext(raidPtr, &info);
122 return copyout(&info, *infoPtr, sizeof(info));
123 }
124
125 static int
126 rf_check_parityrewrite_status_ext80(RF_Raid_t *raidPtr, void *data)
127 {
128 RF_ProgressInfo_t info, **infoPtr = data;
129
130 rf_check_parityrewrite_status_ext(raidPtr, &info);
131 return copyout(&info, *infoPtr, sizeof(info));
132 }
133
134 static int
135 rf_check_copyback_status_ext80(RF_Raid_t *raidPtr, void *data)
136 {
137 RF_ProgressInfo_t info, **infoPtr = data;
138
139 rf_check_copyback_status_ext(raidPtr, &info);
140 return copyout(&info, *infoPtr, sizeof(info));
141 }
142
143 static void
144 rf_copy_raiddisk80(RF_RaidDisk_t *disk, RF_RaidDisk_t80 *disk80)
145 {
146
147 /* Be sure the padding areas don't have kernel memory. */
148 memset(disk80, 0, sizeof(*disk80));
149 memcpy(disk80->devname, disk->devname, sizeof(disk80->devname));
150 disk80->status = disk->status;
151 disk80->spareRow = 0;
152 disk80->spareCol = disk->spareCol;
153 disk80->numBlocks = disk->numBlocks;
154 disk80->blockSize = disk->blockSize;
155 disk80->partitionSize = disk->partitionSize;
156 disk80->auto_configured = disk->auto_configured;
157 disk80->dev = disk->dev;
158 }
159
160 static int
161 rf_get_info80(RF_Raid_t *raidPtr, void *data)
162 {
163 RF_DeviceConfig_t *config;
164 RF_DeviceConfig_t80 *config80, **configPtr80 = data;
165 int rv;
166
167 config = RF_Malloc(sizeof(*config));
168 if (config == NULL)
169 return ENOMEM;
170 config80 = RF_Malloc(sizeof(*config80));
171 if (config80 == NULL) {
172 RF_Free(config, sizeof(*config));
173 return ENOMEM;
174 }
175 rv = rf_get_info(raidPtr, config);
176 if (rv == 0) {
177 /* convert new to old */
178 config80->rows = 1;
179 config80->cols = config->cols;
180 config80->maxqdepth = config->maxqdepth;
181 config80->ndevs = config->ndevs;
182 config80->nspares = config->nspares;
183 for (size_t i = 0; i < RF_MAX_DISKS; i++) {
184 rf_copy_raiddisk80(&config->devs[i],
185 &config80->devs[i]);
186 rf_copy_raiddisk80(&config->spares[i],
187 &config80->spares[i]);
188 }
189 rv = copyout(config80, *configPtr80, sizeof(*config80));
190 }
191 RF_Free(config, sizeof(*config));
192 RF_Free(config80, sizeof(*config80));
193
194 return rv;
195 }
196
197 static int
198 rf_get_component_label80(RF_Raid_t *raidPtr, void *data)
199 {
200 RF_ComponentLabel_t **clabel_ptr = (RF_ComponentLabel_t **)data;
201 RF_ComponentLabel_t *clabel;
202 int retcode;
203
204 /*
205 * Perhaps there should be an option to skip the in-core
206 * copy and hit the disk, as with disklabel(8).
207 */
208 clabel = RF_Malloc(sizeof(*clabel));
209 if (clabel == NULL)
210 return ENOMEM;
211 retcode = copyin(*clabel_ptr, clabel, sizeof(*clabel));
212 if (retcode) {
213 RF_Free(clabel, sizeof(*clabel));
214 return retcode;
215 }
216
217 rf_get_component_label(raidPtr, clabel);
218 /* Fix-up for userland. */
219 if (clabel->version == bswap32(RF_COMPONENT_LABEL_VERSION))
220 clabel->version = RF_COMPONENT_LABEL_VERSION;
221
222 retcode = copyout(clabel, *clabel_ptr, sizeof(**clabel_ptr));
223 RF_Free(clabel, sizeof(*clabel));
224
225 return retcode;
226 }
227
228 static int
229 rf_config80(struct raid_softc *rs, void *data)
230 {
231 RF_Config_t80 *u80_cfg, *k80_cfg;
232 RF_Config_t *k_cfg;
233 RF_Raid_t *raidPtr = rf_get_raid(rs);
234 size_t i, j;
235 int error;
236
237 if (raidPtr->valid) {
238 /* There is a valid RAID set running on this unit! */
239 printf("raid%d: Device already configured!\n", rf_get_unit(rs));
240 return EINVAL;
241 }
242
243 /* copy-in the configuration information */
244 /* data points to a pointer to the configuration structure */
245
246 u80_cfg = *((RF_Config_t80 **) data);
247 k80_cfg = RF_Malloc(sizeof(*k80_cfg));
248 if (k80_cfg == NULL)
249 return ENOMEM;
250
251 error = copyin(u80_cfg, k80_cfg, sizeof(*k80_cfg));
252 if (error) {
253 RF_Free(k80_cfg, sizeof(*k80_cfg));
254 return error;
255 }
256 k_cfg = RF_Malloc(sizeof(*k_cfg));
257 if (k_cfg == NULL) {
258 RF_Free(k80_cfg, sizeof(*k80_cfg));
259 return ENOMEM;
260 }
261
262 k_cfg->numCol = k80_cfg->numCol;
263 k_cfg->numSpare = k80_cfg->numSpare;
264
265 for (i = 0; i < RF_MAXROW; i++)
266 for (j = 0; j < RF_MAXCOL; j++)
267 k_cfg->devs[i][j] = k80_cfg->devs[i][j];
268
269 memcpy(k_cfg->devnames, k80_cfg->devnames,
270 sizeof(k_cfg->devnames));
271
272 for (i = 0; i < RF_MAXSPARE; i++)
273 k_cfg->spare_devs[i] = k80_cfg->spare_devs[i];
274
275 memcpy(k_cfg->spare_names, k80_cfg->spare_names,
276 sizeof(k_cfg->spare_names));
277
278 k_cfg->sectPerSU = k80_cfg->sectPerSU;
279 k_cfg->SUsPerPU = k80_cfg->SUsPerPU;
280 k_cfg->SUsPerRU = k80_cfg->SUsPerRU;
281 k_cfg->parityConfig = k80_cfg->parityConfig;
282
283 memcpy(k_cfg->diskQueueType, k80_cfg->diskQueueType,
284 sizeof(k_cfg->diskQueueType));
285
286 k_cfg->maxOutstandingDiskReqs = k80_cfg->maxOutstandingDiskReqs;
287
288 memcpy(k_cfg->debugVars, k80_cfg->debugVars,
289 sizeof(k_cfg->debugVars));
290
291 k_cfg->layoutSpecificSize = k80_cfg->layoutSpecificSize;
292 k_cfg->layoutSpecific = k80_cfg->layoutSpecific;
293 k_cfg->force = k80_cfg->force;
294
295 RF_Free(k80_cfg, sizeof(*k80_cfg));
296 return rf_construct(rs, k_cfg);
297 }
298
299 static int
300 rf_fail_disk80(RF_Raid_t *raidPtr, struct rf_recon_req80 *req80)
301 {
302 struct rf_recon_req req = {
303 .col = req80->col,
304 .flags = req80->flags,
305 };
306 return rf_fail_disk(raidPtr, &req);
307 }
308
309 static int
310 raidframe_ioctl_80(struct raid_softc *rs, u_long cmd, void *data)
311 {
312 RF_Raid_t *raidPtr = rf_get_raid(rs);
313
314 switch (cmd) {
315 case RAIDFRAME_CHECK_RECON_STATUS_EXT80:
316 case RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT80:
317 case RAIDFRAME_CHECK_COPYBACK_STATUS_EXT80:
318 case RAIDFRAME_GET_INFO80:
319 case RAIDFRAME_GET_COMPONENT_LABEL80:
320 if (!rf_inited(rs))
321 return ENXIO;
322 break;
323 case RAIDFRAME_CONFIGURE80:
324 case RAIDFRAME_FAIL_DISK80:
325 break;
326 default:
327 return EPASSTHROUGH;
328 }
329
330 switch (cmd) {
331 case RAIDFRAME_CHECK_RECON_STATUS_EXT80:
332 return rf_check_recon_status_ext80(raidPtr, data);
333 case RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT80:
334 return rf_check_parityrewrite_status_ext80(raidPtr, data);
335 case RAIDFRAME_CHECK_COPYBACK_STATUS_EXT80:
336 return rf_check_copyback_status_ext80(raidPtr, data);
337 case RAIDFRAME_GET_INFO80:
338 return rf_get_info80(raidPtr, data);
339 case RAIDFRAME_GET_COMPONENT_LABEL80:
340 return rf_get_component_label80(raidPtr, data);
341 case RAIDFRAME_CONFIGURE80:
342 return rf_config80(rs, data);
343 case RAIDFRAME_FAIL_DISK80:
344 return rf_fail_disk80(raidPtr, data);
345 default:
346 /* abort really */
347 return EPASSTHROUGH;
348 }
349 }
350
351 static void
352 raidframe_80_init(void)
353 {
354
355 MODULE_HOOK_SET(raidframe_ioctl_80_hook, raidframe_ioctl_80);
356 }
357
358 static void
359 raidframe_80_fini(void)
360 {
361
362 MODULE_HOOK_UNSET(raidframe_ioctl_80_hook);
363 }
364
365 MODULE(MODULE_CLASS_EXEC, compat_raid_80, "raid,compat_80");
366
367 static int
368 compat_raid_80_modcmd(modcmd_t cmd, void *arg)
369 {
370
371 switch (cmd) {
372 case MODULE_CMD_INIT:
373 raidframe_80_init();
374 return 0;
375 case MODULE_CMD_FINI:
376 raidframe_80_fini();
377 return 0;
378 default:
379 return ENOTTY;
380 }
381 }
382