summaryrefslogtreecommitdiff
path: root/sys/dev/raidframe/rf_compat80.c
blob: 24cb4e048d508eac582f2648dadf63ca82731a90 (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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*	$NetBSD: rf_compat80.c,v 1.17 2022/06/28 03:13:27 oster Exp $	*/

/*
 * Copyright (c) 2017 Matthew R. Green
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/module.h>

#include <sys/compat_stub.h>

#include <dev/raidframe/raidframeio.h>
#include <dev/raidframe/raidframevar.h>

#include "rf_raid.h"
#include "rf_compat80.h"
#include "rf_kintf.h"

/* NetBSD 8.99.x removed the row, raidPtr and next members */
struct rf_recon_req80 {
	RF_RowCol_t row, col;
	RF_ReconReqFlags_t flags;
	void   *raidPtr;	/* used internally; need not be set at ioctl
				 * time */
	struct rf_recon_req *next;	/* used internally; need not be set at
					 * ioctl time */
};

/* NetBSD 8.99.x made this structure alignment neutral */
typedef struct RF_RaidDisk_s80 {
        char    devname[56];    /* name of device file */
        RF_DiskStatus_t status; /* whether it is up or down */
        RF_RowCol_t spareRow;   /* if in status "spared", this identifies the
                                 * spare disk */
        RF_RowCol_t spareCol;   /* if in status "spared", this identifies the
                                 * spare disk */
        RF_SectorCount_t numBlocks;     /* number of blocks, obtained via READ
                                         * CAPACITY */
        int     blockSize;
        RF_SectorCount_t partitionSize; /* The *actual* and *full* size of
                                           the partition, from the disklabel */
        int     auto_configured;/* 1 if this component was autoconfigured.
                                   0 otherwise. */
        dev_t   dev;
} RF_RaidDisk_t80;

typedef struct RF_DeviceConfig_s80 {
	u_int   rows;
	u_int   cols;
	u_int   maxqdepth;
	int     ndevs;
	RF_RaidDisk_t80 devs[RF_MAX_DISKS];
	int     nspares;
	RF_RaidDisk_t80 spares[RF_MAX_DISKS];
} RF_DeviceConfig_t80;

typedef struct RF_Config_s80 {
	RF_RowCol_t numRow, numCol, numSpare;	/* number of rows, columns,
						 * and spare disks */
	dev_t   devs[RF_MAXROW][RF_MAXCOL];	/* device numbers for disks
						 * comprising array */
	char    devnames[RF_MAXROW][RF_MAXCOL][50];	/* device names */
	dev_t   spare_devs[RF_MAXSPARE];	/* device numbers for spare
						 * disks */
	char    spare_names[RF_MAXSPARE][50];	/* device names */
	RF_SectorNum_t sectPerSU;	/* sectors per stripe unit */
	RF_StripeNum_t SUsPerPU;/* stripe units per parity unit */
	RF_StripeNum_t SUsPerRU;/* stripe units per reconstruction unit */
	RF_ParityConfig_t parityConfig;	/* identifies the RAID architecture to
					 * be used */
	RF_DiskQueueType_t diskQueueType;	/* 'f' = fifo, 'c' = cvscan,
						 * not used in kernel */
	char    maxOutstandingDiskReqs;	/* # concurrent reqs to be sent to a
					 * disk.  not used in kernel. */
	char    debugVars[RF_MAXDBGV][50];	/* space for specifying debug
						 * variables & their values */
	unsigned int layoutSpecificSize;	/* size in bytes of
						 * layout-specific info */
	void   *layoutSpecific;	/* a pointer to a layout-specific structure to
				 * be copied in */
	int     force;                          /* if !0, ignore many fatal
						   configuration conditions */
	/*
	   "force" is used to override cases where the component labels would
	   indicate that configuration should not proceed without user
	   intervention
	 */
} RF_Config_t80;

static int
rf_check_recon_status_ext80(RF_Raid_t *raidPtr, void *data)
{
	RF_ProgressInfo_t info, **infoPtr = data;

	rf_check_recon_status_ext(raidPtr, &info);
	return copyout(&info, *infoPtr, sizeof(info));
}

static int
rf_check_parityrewrite_status_ext80(RF_Raid_t *raidPtr, void *data)
{
	RF_ProgressInfo_t info, **infoPtr = data;

	rf_check_parityrewrite_status_ext(raidPtr, &info);
	return copyout(&info, *infoPtr, sizeof(info));
}

static int
rf_check_copyback_status_ext80(RF_Raid_t *raidPtr, void *data)
{
	RF_ProgressInfo_t info, **infoPtr = data;

	rf_check_copyback_status_ext(raidPtr, &info);
	return copyout(&info, *infoPtr, sizeof(info));
}

static void
rf_copy_raiddisk80(RF_RaidDisk_t *disk, RF_RaidDisk_t80 *disk80)
{

	/* Be sure the padding areas don't have kernel memory. */
	memset(disk80, 0, sizeof(*disk80));
	memcpy(disk80->devname, disk->devname, sizeof(disk80->devname));
	disk80->status = disk->status;
	disk80->spareRow = 0;
	disk80->spareCol = disk->spareCol;
	disk80->numBlocks = disk->numBlocks;
	disk80->blockSize = disk->blockSize;
	disk80->partitionSize = disk->partitionSize;
	disk80->auto_configured = disk->auto_configured;
	disk80->dev = disk->dev;
}

static int
rf_get_info80(RF_Raid_t *raidPtr, void *data)
{
	RF_DeviceConfig_t *config;
	RF_DeviceConfig_t80 *config80, **configPtr80 = data;
	int rv;

	config = RF_Malloc(sizeof(*config));
	if (config == NULL)
		return ENOMEM;
	config80 = RF_Malloc(sizeof(*config80));
	if (config80 == NULL) {
		RF_Free(config, sizeof(*config));
		return ENOMEM;
	}
	rv = rf_get_info(raidPtr, config);
	if (rv == 0) {
		/* convert new to old */
		config80->rows = 1;
		config80->cols = config->cols;
		config80->maxqdepth = config->maxqdepth;
		config80->ndevs = config->ndevs;
		config80->nspares = config->nspares;
		for (size_t i = 0; i < RF_MAX_DISKS; i++) {
			rf_copy_raiddisk80(&config->devs[i],
					   &config80->devs[i]);
			rf_copy_raiddisk80(&config->spares[i],
					   &config80->spares[i]);
		}
		rv = copyout(config80, *configPtr80, sizeof(*config80));
	}
	RF_Free(config, sizeof(*config));
	RF_Free(config80, sizeof(*config80));

	return rv;
}

static int
rf_get_component_label80(RF_Raid_t *raidPtr, void *data)
{
	RF_ComponentLabel_t **clabel_ptr = (RF_ComponentLabel_t **)data;
	RF_ComponentLabel_t *clabel;
	int retcode;

	/*
	 * Perhaps there should be an option to skip the in-core
	 * copy and hit the disk, as with disklabel(8).
	 */
	clabel = RF_Malloc(sizeof(*clabel));
	if (clabel == NULL)
		return ENOMEM;
	retcode = copyin(*clabel_ptr, clabel, sizeof(*clabel));
	if (retcode) {
		RF_Free(clabel, sizeof(*clabel));
		return retcode;
	}

	rf_get_component_label(raidPtr, clabel);
	/* Fix-up for userland. */
	if (clabel->version == bswap32(RF_COMPONENT_LABEL_VERSION))
		clabel->version = RF_COMPONENT_LABEL_VERSION;

	retcode = copyout(clabel, *clabel_ptr, sizeof(**clabel_ptr));
	RF_Free(clabel, sizeof(*clabel));

	return retcode;
}

static int
rf_config80(struct raid_softc *rs, void *data)
{
	RF_Config_t80 *u80_cfg, *k80_cfg;
	RF_Config_t *k_cfg;
	RF_Raid_t *raidPtr = rf_get_raid(rs);
	size_t i, j;
	int error;

	if (raidPtr->valid) {
		/* There is a valid RAID set running on this unit! */
		printf("raid%d: Device already configured!\n", rf_get_unit(rs));
		return EINVAL;
	}

	/* copy-in the configuration information */
	/* data points to a pointer to the configuration structure */

	u80_cfg = *((RF_Config_t80 **) data);
	k80_cfg = RF_Malloc(sizeof(*k80_cfg));
	if (k80_cfg == NULL)
		return ENOMEM;

	error = copyin(u80_cfg, k80_cfg, sizeof(*k80_cfg));
	if (error) {
		RF_Free(k80_cfg, sizeof(*k80_cfg));
		return error;
	}
	k_cfg = RF_Malloc(sizeof(*k_cfg));
	if (k_cfg == NULL) {
		RF_Free(k80_cfg, sizeof(*k80_cfg));
		return ENOMEM;
	}

	k_cfg->numCol = k80_cfg->numCol;
	k_cfg->numSpare = k80_cfg->numSpare;

	for (i = 0; i < RF_MAXROW; i++)
		for (j = 0; j < RF_MAXCOL; j++)
			k_cfg->devs[i][j] = k80_cfg->devs[i][j];

	memcpy(k_cfg->devnames, k80_cfg->devnames,
	    sizeof(k_cfg->devnames));

	for (i = 0; i < RF_MAXSPARE; i++)
		k_cfg->spare_devs[i] = k80_cfg->spare_devs[i];

	memcpy(k_cfg->spare_names, k80_cfg->spare_names,
	    sizeof(k_cfg->spare_names));

	k_cfg->sectPerSU = k80_cfg->sectPerSU;
	k_cfg->SUsPerPU = k80_cfg->SUsPerPU;
	k_cfg->SUsPerRU = k80_cfg->SUsPerRU;
	k_cfg->parityConfig = k80_cfg->parityConfig;

	memcpy(k_cfg->diskQueueType, k80_cfg->diskQueueType,
	    sizeof(k_cfg->diskQueueType));

	k_cfg->maxOutstandingDiskReqs = k80_cfg->maxOutstandingDiskReqs;

	memcpy(k_cfg->debugVars, k80_cfg->debugVars,
	    sizeof(k_cfg->debugVars));

	k_cfg->layoutSpecificSize = k80_cfg->layoutSpecificSize;
	k_cfg->layoutSpecific = k80_cfg->layoutSpecific;
	k_cfg->force = k80_cfg->force;

	RF_Free(k80_cfg, sizeof(*k80_cfg));
	return rf_construct(rs, k_cfg);
}

static int
rf_fail_disk80(RF_Raid_t *raidPtr, struct rf_recon_req80 *req80)
{
	struct rf_recon_req req = {
		.col = req80->col,
		.flags = req80->flags,
	};
	return rf_fail_disk(raidPtr, &req);
}

static int
raidframe_ioctl_80(struct raid_softc *rs, u_long cmd, void *data)
{
	RF_Raid_t *raidPtr = rf_get_raid(rs);
 
	switch (cmd) {
	case RAIDFRAME_CHECK_RECON_STATUS_EXT80:
	case RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT80:
	case RAIDFRAME_CHECK_COPYBACK_STATUS_EXT80:
	case RAIDFRAME_GET_INFO80:
	case RAIDFRAME_GET_COMPONENT_LABEL80:
	case RAIDFRAME_FAIL_DISK80:
		if (!rf_inited(rs))
			return ENXIO;
		break;
	case RAIDFRAME_CONFIGURE80:
		break;
	default:
		return EPASSTHROUGH;
	}

	switch (cmd) {
	case RAIDFRAME_CHECK_RECON_STATUS_EXT80:
		return rf_check_recon_status_ext80(raidPtr, data);
	case RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT80:
		return rf_check_parityrewrite_status_ext80(raidPtr, data);
	case RAIDFRAME_CHECK_COPYBACK_STATUS_EXT80:
		return rf_check_copyback_status_ext80(raidPtr, data);
	case RAIDFRAME_GET_INFO80:
		return rf_get_info80(raidPtr, data);
	case RAIDFRAME_GET_COMPONENT_LABEL80:
		return rf_get_component_label80(raidPtr, data);
	case RAIDFRAME_CONFIGURE80:
		return rf_config80(rs, data);
	case RAIDFRAME_FAIL_DISK80:
		return rf_fail_disk80(raidPtr, data);
	default:
		/* abort really */
		return EPASSTHROUGH;
	}
}
 
static void
raidframe_80_init(void)
{
  
	MODULE_HOOK_SET(raidframe_ioctl_80_hook, raidframe_ioctl_80);
}
 
static void
raidframe_80_fini(void)
{
 
	MODULE_HOOK_UNSET(raidframe_ioctl_80_hook);
}

MODULE(MODULE_CLASS_EXEC, compat_raid_80, "raid,compat_80");

static int
compat_raid_80_modcmd(modcmd_t cmd, void *arg)
{

	switch (cmd) {
	case MODULE_CMD_INIT:
		raidframe_80_init();
		return 0;
	case MODULE_CMD_FINI:
		raidframe_80_fini();
		return 0;
	default:
		return ENOTTY;
	}
}