Home | History | Annotate | Line # | Download | only in raidframe
rf_compat80.c revision 1.1
      1 /*	$NetBSD: rf_compat80.c,v 1.1 2018/01/18 00:32:49 mrg 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 
     35 #include <dev/raidframe/raidframeio.h>
     36 #include <dev/raidframe/raidframevar.h>
     37 
     38 #include "rf_raid.h"
     39 #include "rf_compat80.h"
     40 #include "rf_kintf.h"
     41 
     42 int
     43 rf_check_recon_status_ext80(RF_Raid_t *raidPtr, void *data)
     44 {
     45 	RF_ProgressInfo_t info, **infoPtr = data;
     46 
     47 	rf_check_recon_status_ext(raidPtr, &info);
     48 	return copyout(&info, *infoPtr, sizeof info);
     49 }
     50 
     51 int
     52 rf_check_parityrewrite_status_ext80(RF_Raid_t *raidPtr, void *data)
     53 {
     54 	RF_ProgressInfo_t info, **infoPtr = data;
     55 
     56 	rf_check_parityrewrite_status_ext(raidPtr, &info);
     57 	return copyout(&info, *infoPtr, sizeof info);
     58 }
     59 
     60 int
     61 rf_check_copyback_status_ext80(RF_Raid_t *raidPtr, void *data)
     62 {
     63 	RF_ProgressInfo_t info, **infoPtr = data;
     64 
     65 	rf_check_copyback_status_ext(raidPtr, &info);
     66 	return copyout(&info, *infoPtr, sizeof info);
     67 }
     68 
     69 static void
     70 rf_copy_raiddisk80(RF_RaidDisk_t *disk, RF_RaidDisk_t80 *disk80)
     71 {
     72 
     73 	/* Be sure the padding areas don't have kernel memory. */
     74 	memset(disk80, 0, sizeof *disk80);
     75 	memcpy(disk80->devname, disk->devname, sizeof(disk80->devname));
     76 	disk80->status = disk->status;
     77 	disk80->spareRow = 0;
     78 	disk80->spareCol = disk->spareCol;
     79 	disk80->numBlocks = disk->numBlocks;
     80 	disk80->blockSize = disk->blockSize;
     81 	disk80->partitionSize = disk->partitionSize;
     82 	disk80->auto_configured = disk->auto_configured;
     83 	disk80->dev = disk->dev;
     84 }
     85 
     86 int
     87 rf_get_info80(RF_Raid_t *raidPtr, void *data)
     88 {
     89 	RF_DeviceConfig_t *config;
     90 	RF_DeviceConfig_t80 *config80, **configPtr80 = data;
     91 	int rv;
     92 
     93 	RF_Malloc(config, sizeof *config, (RF_DeviceConfig_t *));
     94 	if (config == NULL)
     95 		return (ENOMEM);
     96 	RF_Malloc(config80, sizeof *config80, (RF_DeviceConfig_t80 *));
     97 	if (config80 == NULL) {
     98 		RF_Free(config, sizeof(RF_DeviceConfig_t))
     99 		return (ENOMEM);
    100 	}
    101 	rv = rf_get_info(raidPtr, config);
    102 	if (rv == 0) {
    103 		/* convert new to old */
    104 		config80->rows = 1;
    105 		config80->cols = config->cols;
    106 		config80->maxqdepth = config->maxqdepth;
    107 		config80->ndevs = config->ndevs;
    108 		config80->nspares = config->nspares;
    109 		for (size_t i = 0; i < RF_MAX_DISKS; i++) {
    110 			rf_copy_raiddisk80(&config->devs[i],
    111 					   &config80->devs[i]);
    112 			rf_copy_raiddisk80(&config->spares[i],
    113 					   &config80->spares[i]);
    114 		}
    115 		rv = copyout(&config, *configPtr80, sizeof *config80);
    116 	}
    117 	RF_Free(config, sizeof(RF_DeviceConfig_t));
    118 	RF_Free(config80, sizeof(RF_DeviceConfig_t80));
    119 
    120 	return rv;
    121 }
    122 
    123 int
    124 rf_get_component_label80(RF_Raid_t *raidPtr, void *data)
    125 {
    126 	RF_ComponentLabel_t **clabel_ptr = (RF_ComponentLabel_t **)data;
    127 	RF_ComponentLabel_t *clabel;
    128 	int retcode;
    129 
    130 	/*
    131 	 * Perhaps there should be an option to skip the in-core
    132 	 * copy and hit the disk, as with disklabel(8).
    133 	 */
    134 	RF_Malloc(clabel, sizeof(*clabel), (RF_ComponentLabel_t *));
    135 	if (clabel == NULL)
    136 		return ENOMEM;
    137 	retcode = copyin(*clabel_ptr, clabel, sizeof(*clabel));
    138 	if (retcode) {
    139 		RF_Free(clabel, sizeof(*clabel));
    140 		return retcode;
    141 	}
    142 
    143 	rf_get_component_label(raidPtr, clabel);
    144 	retcode = copyout(clabel, *clabel_ptr, sizeof(**clabel_ptr));
    145 	RF_Free(clabel, sizeof(*clabel));
    146 
    147 	return retcode;
    148 }
    149