Home | History | Annotate | Line # | Download | only in raidframe
rf_compat80.c revision 1.5
      1 /*	$NetBSD: rf_compat80.c,v 1.5 2019/01/29 23:42:06 oster 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_compat80_mod.h"
     44 #include "rf_kintf.h"
     45 
     46 int
     47 rf_check_recon_status_ext80(RF_Raid_t *raidPtr, void *data)
     48 {
     49 	RF_ProgressInfo_t info, **infoPtr = data;
     50 
     51 	rf_check_recon_status_ext(raidPtr, &info);
     52 	return copyout(&info, *infoPtr, sizeof info);
     53 }
     54 
     55 int
     56 rf_check_parityrewrite_status_ext80(RF_Raid_t *raidPtr, void *data)
     57 {
     58 	RF_ProgressInfo_t info, **infoPtr = data;
     59 
     60 	rf_check_parityrewrite_status_ext(raidPtr, &info);
     61 	return copyout(&info, *infoPtr, sizeof info);
     62 }
     63 
     64 int
     65 rf_check_copyback_status_ext80(RF_Raid_t *raidPtr, void *data)
     66 {
     67 	RF_ProgressInfo_t info, **infoPtr = data;
     68 
     69 	rf_check_copyback_status_ext(raidPtr, &info);
     70 	return copyout(&info, *infoPtr, sizeof info);
     71 }
     72 
     73 static void
     74 rf_copy_raiddisk80(RF_RaidDisk_t *disk, RF_RaidDisk_t80 *disk80)
     75 {
     76 
     77 	/* Be sure the padding areas don't have kernel memory. */
     78 	memset(disk80, 0, sizeof *disk80);
     79 	memcpy(disk80->devname, disk->devname, sizeof(disk80->devname));
     80 	disk80->status = disk->status;
     81 	disk80->spareRow = 0;
     82 	disk80->spareCol = disk->spareCol;
     83 	disk80->numBlocks = disk->numBlocks;
     84 	disk80->blockSize = disk->blockSize;
     85 	disk80->partitionSize = disk->partitionSize;
     86 	disk80->auto_configured = disk->auto_configured;
     87 	disk80->dev = disk->dev;
     88 }
     89 
     90 int
     91 rf_get_info80(RF_Raid_t *raidPtr, void *data)
     92 {
     93 	RF_DeviceConfig_t *config;
     94 	RF_DeviceConfig_t80 *config80, **configPtr80 = data;
     95 	int rv;
     96 
     97 	RF_Malloc(config, sizeof *config, (RF_DeviceConfig_t *));
     98 	if (config == NULL)
     99 		return (ENOMEM);
    100 	RF_Malloc(config80, sizeof *config80, (RF_DeviceConfig_t80 *));
    101 	if (config80 == NULL) {
    102 		RF_Free(config, sizeof(RF_DeviceConfig_t))
    103 		return (ENOMEM);
    104 	}
    105 	rv = rf_get_info(raidPtr, config);
    106 	if (rv == 0) {
    107 		/* convert new to old */
    108 		config80->rows = 1;
    109 		config80->cols = config->cols;
    110 		config80->maxqdepth = config->maxqdepth;
    111 		config80->ndevs = config->ndevs;
    112 		config80->nspares = config->nspares;
    113 		for (size_t i = 0; i < RF_MAX_DISKS; i++) {
    114 			rf_copy_raiddisk80(&config->devs[i],
    115 					   &config80->devs[i]);
    116 			rf_copy_raiddisk80(&config->spares[i],
    117 					   &config80->spares[i]);
    118 		}
    119 		rv = copyout(config80, *configPtr80, sizeof *config80);
    120 	}
    121 	RF_Free(config, sizeof(RF_DeviceConfig_t));
    122 	RF_Free(config80, sizeof(RF_DeviceConfig_t80));
    123 
    124 	return rv;
    125 }
    126 
    127 int
    128 rf_get_component_label80(RF_Raid_t *raidPtr, void *data)
    129 {
    130 	RF_ComponentLabel_t **clabel_ptr = (RF_ComponentLabel_t **)data;
    131 	RF_ComponentLabel_t *clabel;
    132 	int retcode;
    133 
    134 	/*
    135 	 * Perhaps there should be an option to skip the in-core
    136 	 * copy and hit the disk, as with disklabel(8).
    137 	 */
    138 	RF_Malloc(clabel, sizeof(*clabel), (RF_ComponentLabel_t *));
    139 	if (clabel == NULL)
    140 		return ENOMEM;
    141 	retcode = copyin(*clabel_ptr, clabel, sizeof(*clabel));
    142 	if (retcode) {
    143 		RF_Free(clabel, sizeof(*clabel));
    144 		return retcode;
    145 	}
    146 
    147 	rf_get_component_label(raidPtr, clabel);
    148 	retcode = copyout(clabel, *clabel_ptr, sizeof(**clabel_ptr));
    149 	RF_Free(clabel, sizeof(*clabel));
    150 
    151 	return retcode;
    152 }
    153 
    154 int
    155 rf_config80(RF_Raid_t *raidPtr, int unit, void *data, RF_Config_t **k_cfgp)
    156 {
    157 	RF_Config_t80 *u80_cfg, *k80_cfg;
    158 	RF_Config_t *k_cfg;
    159 	size_t i, j;
    160 	int error;
    161 
    162 	if (raidPtr->valid) {
    163 		/* There is a valid RAID set running on this unit! */
    164 		printf("raid%d: Device already configured!\n", unit);
    165 		return EINVAL;
    166 	}
    167 
    168 	/* copy-in the configuration information */
    169 	/* data points to a pointer to the configuration structure */
    170 
    171 	u80_cfg = *((RF_Config_t80 **) data);
    172 	RF_Malloc(k80_cfg, sizeof(RF_Config_t80), (RF_Config_t80 *));
    173 	if (k80_cfg == NULL)
    174 		return ENOMEM;
    175 
    176 	error = copyin(u80_cfg, k80_cfg, sizeof(RF_Config_t80));
    177 	if (error) {
    178 		RF_Free(k80_cfg, sizeof(RF_Config_t80));
    179 		return error;
    180 	}
    181 	RF_Malloc(k_cfg, sizeof(RF_Config_t), (RF_Config_t *));
    182 	if (k_cfg == NULL) {
    183 		RF_Free(k80_cfg, sizeof(RF_Config_t80));
    184 		return ENOMEM;
    185 	}
    186 
    187 	k_cfg->numCol = k80_cfg->numCol;
    188 	k_cfg->numSpare = k80_cfg->numSpare;
    189 
    190 	for (i = 0; i < RF_MAXROW; i++)
    191 		for (j = 0; j < RF_MAXCOL; j++)
    192 			k_cfg->devs[i][j] = k80_cfg->devs[i][j];
    193 
    194 	memcpy(k_cfg->devnames, k80_cfg->devnames,
    195 	    sizeof(k_cfg->devnames));
    196 
    197 	for (i = 0; i < RF_MAXSPARE; i++)
    198 		k_cfg->spare_devs[i] = k80_cfg->spare_devs[i];
    199 
    200 	memcpy(k_cfg->spare_names, k80_cfg->spare_names,
    201 	    sizeof(k_cfg->spare_names));
    202 
    203 	k_cfg->sectPerSU = k80_cfg->sectPerSU;
    204 	k_cfg->SUsPerPU = k80_cfg->SUsPerPU;
    205 	k_cfg->SUsPerRU = k80_cfg->SUsPerRU;
    206 	k_cfg->parityConfig = k80_cfg->parityConfig;
    207 
    208 	memcpy(k_cfg->diskQueueType, k80_cfg->diskQueueType,
    209 	    sizeof(k_cfg->diskQueueType));
    210 
    211 	k_cfg->maxOutstandingDiskReqs = k80_cfg->maxOutstandingDiskReqs;
    212 
    213 	memcpy(k_cfg->debugVars, k80_cfg->debugVars,
    214 	    sizeof(k_cfg->debugVars));
    215 
    216 	k_cfg->layoutSpecificSize = k80_cfg->layoutSpecificSize;
    217 	k_cfg->layoutSpecific = k80_cfg->layoutSpecific;
    218 	k_cfg->force = k80_cfg->force;
    219 
    220 	RF_Free(k80_cfg, sizeof(RF_Config_t80));
    221 	*k_cfgp = k_cfg;
    222 	return 0;
    223 }
    224 
    225 int
    226 raidframe_ioctl_80(int cmd, int initted, RF_Raid_t *raidPtr, int unit,
    227     void *data, RF_Config_t **k_cfg)
    228 {
    229 int error;
    230 
    231 	switch (cmd) {
    232 	case RAIDFRAME_CHECK_RECON_STATUS_EXT80:
    233 	case RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT80:
    234 	case RAIDFRAME_CHECK_COPYBACK_STATUS_EXT80:
    235 	case RAIDFRAME_GET_INFO80:
    236 	case RAIDFRAME_GET_COMPONENT_LABEL80:
    237 		if (initted == 0)
    238 			return ENXIO;
    239 		break;
    240 	case RAIDFRAME_CONFIGURE80:
    241 		break;
    242 	case RAIDFRAME_FAIL_DISK80:
    243 		return EPASSTHROUGH;
    244 	default:
    245 		return EPASSTHROUGH;
    246 	}
    247 
    248 	switch (cmd) {
    249 	case RAIDFRAME_CHECK_RECON_STATUS_EXT80:
    250 		return rf_check_recon_status_ext80(raidPtr, data);
    251 	case RAIDFRAME_CHECK_PARITYREWRITE_STATUS_EXT80:
    252 		return rf_check_parityrewrite_status_ext80(raidPtr, data);
    253 	case RAIDFRAME_CHECK_COPYBACK_STATUS_EXT80:
    254 		return rf_check_copyback_status_ext80(raidPtr, data);
    255 	case RAIDFRAME_GET_INFO80:
    256 		return rf_get_info80(raidPtr, data);
    257 	case RAIDFRAME_GET_COMPONENT_LABEL80:
    258 		return rf_get_component_label80(raidPtr, data);
    259 	case RAIDFRAME_CONFIGURE80:
    260 		error = rf_config80(raidPtr, unit, data, k_cfg);
    261 		if (error != 0)
    262 			return error;
    263 		return EAGAIN;  /* flag mainline to call generic config */
    264 	}
    265 	return EPASSTHROUGH;
    266 }
    267 
    268 void
    269 raidframe_80_init(void)
    270 {
    271 
    272 	MODULE_SET_HOOK(raidframe_ioctl_80_hook, "raid80", raidframe_ioctl_80);
    273 }
    274 
    275 void
    276 raidframe_80_fini(void)
    277 {
    278 
    279 	MODULE_UNSET_HOOK(raidframe_ioctl_80_hook);
    280 }
    281 
    282 MODULE(MODULE_CLASS_EXEC, compat_raid_80, "raid,compat_80");
    283 
    284 static int
    285 compat_raid_80_modcmd(modcmd_t cmd, void *arg)
    286 {
    287 
    288 	switch (cmd) {
    289 	case MODULE_CMD_INIT:
    290 		raidframe_80_init();
    291 		return 0;
    292 	case MODULE_CMD_FINI:
    293 		raidframe_80_fini();
    294 		return 0;
    295 	default:
    296 		return ENOTTY;
    297 	}
    298 }
    299