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
|
/* $NetBSD: rf_compat32.c,v 1.9 2021/12/11 19:24:21 mrg 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_kintf.h"
#include "rf_compat32.h"
#include <compat/netbsd32/netbsd32.h>
typedef netbsd32_int64 RF_SectorNum_t32;
typedef netbsd32_int64 RF_StripeNum_t32;
/* from <dev/raidframe/raidframevar.h> */
typedef struct RF_Config_s32 {
RF_RowCol_t 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_t32 sectPerSU; /* sectors per stripe unit */
RF_StripeNum_t32 SUsPerPU;/* stripe units per parity unit */
RF_StripeNum_t32 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 */
netbsd32_pointer_t 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_t32;
static int
rf_config_netbsd32(struct raid_softc *rs, void *data)
{
RF_Config_t32 *u_cfg32 = NETBSD32PTR64(*(netbsd32_pointer_t *)data);
RF_Config_t *k_cfg;
RF_Config_t32 *k_cfg32;
int rv;
k_cfg32 = RF_Malloc(sizeof(*k_cfg32));
if (k_cfg32 == NULL)
return ENOMEM;
rv = copyin(u_cfg32, k_cfg32, sizeof(RF_Config_t32));
if (rv) {
RF_Free(k_cfg32, sizeof(RF_Config_t32));
return ENOMEM;
}
k_cfg = RF_Malloc(sizeof(*k_cfg));
if (k_cfg == NULL) {
RF_Free(k_cfg32, sizeof(RF_Config_t32));
return ENOMEM;
}
k_cfg->numCol = k_cfg32->numCol;
k_cfg->numSpare = k_cfg32->numSpare;
memcpy(k_cfg->devs, k_cfg32->devs, sizeof(k_cfg->devs));
memcpy(k_cfg->devnames, k_cfg32->devnames, sizeof(k_cfg->devnames));
memcpy(k_cfg->spare_devs, k_cfg32->spare_devs,
sizeof(k_cfg->spare_devs));
memcpy(k_cfg->spare_names, k_cfg32->spare_names,
sizeof(k_cfg->spare_names));
k_cfg->sectPerSU = k_cfg32->sectPerSU;
k_cfg->SUsPerPU = k_cfg32->SUsPerPU;
k_cfg->SUsPerRU = k_cfg32->SUsPerRU;
k_cfg->parityConfig = k_cfg32->parityConfig;
memcpy(k_cfg->diskQueueType, k_cfg32->diskQueueType,
sizeof(k_cfg->diskQueueType));
k_cfg->maxOutstandingDiskReqs = k_cfg32->maxOutstandingDiskReqs;
memcpy(k_cfg->debugVars, k_cfg32->debugVars, sizeof(k_cfg->debugVars));
k_cfg->layoutSpecificSize = k_cfg32->layoutSpecificSize;
k_cfg->layoutSpecific = NETBSD32PTR64(k_cfg32->layoutSpecific);
k_cfg->force = k_cfg32->force;
return rf_construct(rs, k_cfg);
}
static int
rf_get_info_netbsd32(RF_Raid_t *raidPtr, void *data)
{
int retcode;
void *ucfgp = NETBSD32PTR64(*(netbsd32_pointer_t *)data);
RF_DeviceConfig_t *d_cfg = RF_Malloc(sizeof(*d_cfg));
if (d_cfg == NULL)
return ENOMEM;
retcode = rf_get_info(raidPtr, d_cfg);
if (retcode == 0) {
retcode = copyout(d_cfg, ucfgp, sizeof(*d_cfg));
}
RF_Free(d_cfg, sizeof(RF_DeviceConfig_t));
return retcode;
}
static int
raidframe_netbsd32_ioctl(struct raid_softc *rs, u_long cmd, void *data)
{
RF_Raid_t *raidPtr = rf_get_raid(rs);
switch (cmd) {
case RAIDFRAME_GET_INFO32:
if (!rf_inited(rs))
return ENXIO;
return rf_get_info_netbsd32(raidPtr, data);
case RAIDFRAME_CONFIGURE32:
return rf_config_netbsd32(rs, data);
default:
return EPASSTHROUGH;
}
}
static void
raidframe_netbsd32_init(void)
{
MODULE_HOOK_SET(raidframe_netbsd32_ioctl_hook,
raidframe_netbsd32_ioctl);
}
static void
raidframe_netbsd32_fini(void)
{
MODULE_HOOK_UNSET(raidframe_netbsd32_ioctl_hook);
}
MODULE(MODULE_CLASS_EXEC, compat_netbsd32_raid, "raid,compat_netbsd32");
static int
compat_netbsd32_raid_modcmd(modcmd_t cmd, void *arg)
{
switch (cmd) {
case MODULE_CMD_INIT:
raidframe_netbsd32_init();
return 0;
case MODULE_CMD_FINI:
raidframe_netbsd32_fini();
return 0;
default:
return ENOTTY;
}
}
|