/*
* 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.
*/
/* 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_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;
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 */
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;
}
}