Introduce GEOM RAID3 class, i.e. kernel module, which implements RAID3
transformation and graid3(8) userland utility, which can be used for configuration. No manual page yet, sorry. Hardware provided by: Daniel Seuffert
This commit is contained in:
parent
336d354baa
commit
8394d51046
11
sbin/geom/class/raid3/Makefile
Normal file
11
sbin/geom/class/raid3/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.PATH: ${.CURDIR}/../../misc
|
||||
|
||||
CLASS= raid3
|
||||
|
||||
NOMAN= notyet
|
||||
DPADD= ${LIBMD}
|
||||
LDADD= -lmd
|
||||
|
||||
.include <bsd.lib.mk>
|
340
sbin/geom/class/raid3/geom_raid3.c
Normal file
340
sbin/geom/class/raid3/geom_raid3.c
Normal file
@ -0,0 +1,340 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||
* 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 AUTHORS AND CONTRIBUTORS ``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 AUTHORS OR CONTRIBUTORS 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/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <errno.h>
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <assert.h>
|
||||
#include <libgeom.h>
|
||||
#include <geom/raid3/g_raid3.h>
|
||||
#include <core/geom.h>
|
||||
#include <misc/subr.h>
|
||||
|
||||
|
||||
uint32_t lib_version = G_LIB_VERSION;
|
||||
uint32_t version = G_RAID3_VERSION;
|
||||
|
||||
static void raid3_main(struct gctl_req *req, unsigned f);
|
||||
static void raid3_clear(struct gctl_req *req);
|
||||
static void raid3_dump(struct gctl_req *req);
|
||||
static void raid3_label(struct gctl_req *req);
|
||||
|
||||
struct g_command class_commands[] = {
|
||||
{ "clear", G_FLAG_VERBOSE, raid3_main, G_NULL_OPTS },
|
||||
{ "configure", G_FLAG_VERBOSE, NULL,
|
||||
{
|
||||
{ 'a', "autosync", NULL, G_TYPE_NONE },
|
||||
{ 'd', "dynamic", NULL, G_TYPE_NONE },
|
||||
{ 'h', "hardcode", NULL, G_TYPE_NONE },
|
||||
{ 'n', "noautosync", NULL, G_TYPE_NONE },
|
||||
G_OPT_SENTINEL
|
||||
}
|
||||
},
|
||||
{ "dump", 0, raid3_main, G_NULL_OPTS },
|
||||
{ "insert", G_FLAG_VERBOSE, NULL,
|
||||
{
|
||||
{ 'h', "hardcode", NULL, G_TYPE_NONE },
|
||||
{ 'n', "number", NULL, G_TYPE_NUMBER },
|
||||
G_OPT_SENTINEL
|
||||
}
|
||||
},
|
||||
{ "label", G_FLAG_VERBOSE, raid3_main,
|
||||
{
|
||||
{ 'h', "hardcode", NULL, G_TYPE_NONE },
|
||||
{ 'n', "noautosync", NULL, G_TYPE_NONE },
|
||||
G_OPT_SENTINEL
|
||||
}
|
||||
},
|
||||
{ "rebuild", G_FLAG_VERBOSE, NULL, G_NULL_OPTS },
|
||||
{ "remove", G_FLAG_VERBOSE, NULL,
|
||||
{
|
||||
{ 'n', "number", NULL, G_TYPE_NUMBER },
|
||||
G_OPT_SENTINEL
|
||||
}
|
||||
},
|
||||
{ "stop", G_FLAG_VERBOSE, NULL,
|
||||
{
|
||||
{ 'f', "force", NULL, G_TYPE_NONE },
|
||||
G_OPT_SENTINEL
|
||||
}
|
||||
},
|
||||
G_CMD_SENTINEL
|
||||
};
|
||||
|
||||
static int verbose = 0;
|
||||
|
||||
void usage(const char *);
|
||||
void
|
||||
usage(const char *comm)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s label [-hnv] name prov prov prov [prov [...]]\n"
|
||||
" %s clear [-v] prov [prov [...]]\n"
|
||||
" %s dump prov [prov [...]]\n"
|
||||
" %s configure [-adhnv] name\n"
|
||||
" %s rebuild [-v] name prov\n"
|
||||
" %s insert [-hv] <-n number> name prov\n"
|
||||
" %s remove [-v] <-n number> name\n"
|
||||
" %s stop [-fv] name\n",
|
||||
comm, comm, comm, comm, comm, comm, comm, comm);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
raid3_main(struct gctl_req *req, unsigned flags)
|
||||
{
|
||||
const char *name;
|
||||
|
||||
if ((flags & G_FLAG_VERBOSE) != 0)
|
||||
verbose = 1;
|
||||
|
||||
name = gctl_get_asciiparam(req, "verb");
|
||||
if (name == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "verb");
|
||||
return;
|
||||
}
|
||||
if (strcmp(name, "label") == 0)
|
||||
raid3_label(req);
|
||||
else if (strcmp(name, "clear") == 0)
|
||||
raid3_clear(req);
|
||||
else if (strcmp(name, "dump") == 0)
|
||||
raid3_dump(req);
|
||||
else
|
||||
gctl_error(req, "Unknown command: %s.", name);
|
||||
}
|
||||
|
||||
static void
|
||||
raid3_label(struct gctl_req *req)
|
||||
{
|
||||
struct g_raid3_metadata md;
|
||||
u_char sector[512];
|
||||
const char *str;
|
||||
char param[16];
|
||||
int *hardcode, *nargs, *noautosync, error, i;
|
||||
unsigned sectorsize;
|
||||
off_t mediasize;
|
||||
|
||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
|
||||
if (nargs == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "nargs");
|
||||
return;
|
||||
}
|
||||
if (*nargs < 4) {
|
||||
gctl_error(req, "Too few arguments.");
|
||||
return;
|
||||
}
|
||||
#ifndef BITCOUNT
|
||||
#define BITCOUNT(x) (((BX_(x) + (BX_(x) >> 4)) & 0x0F0F0F0F) % 255)
|
||||
#define BX_(x) ((x) - (((x) >> 1) & 0x77777777) - \
|
||||
(((x) >> 2) & 0x33333333) - (((x) >> 3) & 0x11111111))
|
||||
#endif
|
||||
if (BITCOUNT(*nargs - 2) != 1) {
|
||||
gctl_error(req, "Invalid number of components.");
|
||||
return;
|
||||
}
|
||||
|
||||
strlcpy(md.md_magic, G_RAID3_MAGIC, sizeof(md.md_magic));
|
||||
md.md_version = G_RAID3_VERSION;
|
||||
str = gctl_get_asciiparam(req, "arg0");
|
||||
if (str == NULL) {
|
||||
gctl_error(req, "No 'arg%u' argument.", 0);
|
||||
return;
|
||||
}
|
||||
strlcpy(md.md_name, str, sizeof(md.md_name));
|
||||
md.md_all = *nargs - 1;
|
||||
md.md_mflags = 0;
|
||||
md.md_dflags = 0;
|
||||
md.md_syncid = 1;
|
||||
md.md_sync_offset = 0;
|
||||
noautosync = gctl_get_paraml(req, "noautosync", sizeof(*noautosync));
|
||||
if (noautosync == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "noautosync");
|
||||
return;
|
||||
}
|
||||
if (*noautosync)
|
||||
md.md_mflags |= G_RAID3_DEVICE_FLAG_NOAUTOSYNC;
|
||||
hardcode = gctl_get_paraml(req, "hardcode", sizeof(*hardcode));
|
||||
if (hardcode == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "hardcode");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate sectorsize by finding least common multiple from
|
||||
* sectorsizes of every disk and find the smallest mediasize.
|
||||
*/
|
||||
mediasize = 0;
|
||||
sectorsize = 0;
|
||||
for (i = 1; i < *nargs; i++) {
|
||||
unsigned ssize;
|
||||
off_t msize;
|
||||
|
||||
snprintf(param, sizeof(param), "arg%u", i);
|
||||
str = gctl_get_asciiparam(req, param);
|
||||
|
||||
msize = g_get_mediasize(str);
|
||||
ssize = g_get_sectorsize(str);
|
||||
if (msize == 0 || ssize == 0) {
|
||||
gctl_error(req, "Can't get informations about %s: %s.",
|
||||
str, strerror(errno));
|
||||
return;
|
||||
}
|
||||
msize -= ssize;
|
||||
if (mediasize == 0 || (mediasize > 0 && msize < mediasize))
|
||||
mediasize = msize;
|
||||
if (sectorsize == 0)
|
||||
sectorsize = ssize;
|
||||
else
|
||||
sectorsize = g_lcm(sectorsize, ssize);
|
||||
}
|
||||
md.md_mediasize = mediasize * (*nargs - 2);
|
||||
md.md_sectorsize = sectorsize * (*nargs - 2);
|
||||
|
||||
/*
|
||||
* Clear last sector first, to spoil all components if device exists.
|
||||
*/
|
||||
for (i = 1; i < *nargs; i++) {
|
||||
snprintf(param, sizeof(param), "arg%u", i);
|
||||
str = gctl_get_asciiparam(req, param);
|
||||
|
||||
error = g_metadata_clear(str, NULL);
|
||||
if (error != 0) {
|
||||
gctl_error(req, "Can't store metadata on %s: %s.", str,
|
||||
strerror(error));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Ok, store metadata (use disk number as priority).
|
||||
*/
|
||||
for (i = 1; i < *nargs; i++) {
|
||||
snprintf(param, sizeof(param), "arg%u", i);
|
||||
str = gctl_get_asciiparam(req, param);
|
||||
|
||||
md.md_no = i - 1;
|
||||
if (!*hardcode)
|
||||
bzero(md.md_provider, sizeof(md.md_provider));
|
||||
else {
|
||||
if (strncmp(str, _PATH_DEV, strlen(_PATH_DEV)) == 0)
|
||||
str += strlen(_PATH_DEV);
|
||||
strlcpy(md.md_provider, str, sizeof(md.md_provider));
|
||||
}
|
||||
raid3_metadata_encode(&md, sector);
|
||||
error = g_metadata_store(str, sector, sizeof(sector));
|
||||
if (error != 0) {
|
||||
fprintf(stderr, "Can't store metadata on %s: %s.\n",
|
||||
str, strerror(error));
|
||||
gctl_error(req, "Not fully done.");
|
||||
continue;
|
||||
}
|
||||
if (verbose)
|
||||
printf("Metadata value stored on %s.\n", str);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
raid3_clear(struct gctl_req *req)
|
||||
{
|
||||
const char *name;
|
||||
char param[16];
|
||||
int *nargs, error, i;
|
||||
|
||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
|
||||
if (nargs == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "nargs");
|
||||
return;
|
||||
}
|
||||
if (*nargs < 1) {
|
||||
gctl_error(req, "Too few arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < *nargs; i++) {
|
||||
snprintf(param, sizeof(param), "arg%u", i);
|
||||
name = gctl_get_asciiparam(req, param);
|
||||
|
||||
error = g_metadata_clear(name, G_RAID3_MAGIC);
|
||||
if (error != 0) {
|
||||
fprintf(stderr, "Can't clear metadata on %s: %s.\n",
|
||||
name, strerror(error));
|
||||
gctl_error(req, "Not fully done.");
|
||||
continue;
|
||||
}
|
||||
if (verbose)
|
||||
printf("Metadata cleared on %s.\n", name);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
raid3_dump(struct gctl_req *req)
|
||||
{
|
||||
struct g_raid3_metadata md, tmpmd;
|
||||
const char *name;
|
||||
char param[16];
|
||||
int *nargs, error, i;
|
||||
|
||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
|
||||
if (nargs == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "nargs");
|
||||
return;
|
||||
}
|
||||
if (*nargs < 1) {
|
||||
gctl_error(req, "Too few arguments.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < *nargs; i++) {
|
||||
snprintf(param, sizeof(param), "arg%u", i);
|
||||
name = gctl_get_asciiparam(req, param);
|
||||
|
||||
error = g_metadata_read(name, (u_char *)&tmpmd, sizeof(tmpmd),
|
||||
G_RAID3_MAGIC);
|
||||
if (error != 0) {
|
||||
fprintf(stderr, "Can't read metadata from %s: %s.\n",
|
||||
name, strerror(error));
|
||||
gctl_error(req, "Not fully done.");
|
||||
continue;
|
||||
}
|
||||
if (raid3_metadata_decode((u_char *)&tmpmd, &md) != 0) {
|
||||
fprintf(stderr, "MD5 hash mismatch for %s, skipping.\n",
|
||||
name);
|
||||
gctl_error(req, "Not fully done.");
|
||||
continue;
|
||||
}
|
||||
printf("Metadata on %s:\n", name);
|
||||
raid3_metadata_dump(&md);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
2763
sys/geom/raid3/g_raid3.c
Normal file
2763
sys/geom/raid3/g_raid3.c
Normal file
File diff suppressed because it is too large
Load Diff
306
sys/geom/raid3/g_raid3.h
Normal file
306
sys/geom/raid3/g_raid3.h
Normal file
@ -0,0 +1,306 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||
* 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 AUTHORS AND CONTRIBUTORS ``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 AUTHORS OR CONTRIBUTORS 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.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _G_RAID3_H_
|
||||
#define _G_RAID3_H_
|
||||
|
||||
#include <sys/endian.h>
|
||||
#include <sys/md5.h>
|
||||
|
||||
#define G_RAID3_CLASS_NAME "RAID3"
|
||||
|
||||
#define G_RAID3_MAGIC "GEOM::RAID3"
|
||||
#define G_RAID3_VERSION 0
|
||||
|
||||
#define G_RAID3_DISK_FLAG_DIRTY 0x0000000000000001ULL
|
||||
#define G_RAID3_DISK_FLAG_SYNCHRONIZING 0x0000000000000002ULL
|
||||
#define G_RAID3_DISK_FLAG_FORCE_SYNC 0x0000000000000004ULL
|
||||
#define G_RAID3_DISK_FLAG_HARDCODED 0x0000000000000008ULL
|
||||
#define G_RAID3_DISK_FLAG_MASK (G_RAID3_DISK_FLAG_DIRTY | \
|
||||
G_RAID3_DISK_FLAG_SYNCHRONIZING | \
|
||||
G_RAID3_DISK_FLAG_FORCE_SYNC)
|
||||
|
||||
#define G_RAID3_DEVICE_FLAG_NOAUTOSYNC 0x0000000000000001ULL
|
||||
#define G_RAID3_DEVICE_FLAG_MASK (G_RAID3_DEVICE_FLAG_NOAUTOSYNC)
|
||||
|
||||
#ifdef _KERNEL
|
||||
extern u_int g_raid3_debug;
|
||||
|
||||
#define G_RAID3_DEBUG(lvl, ...) do { \
|
||||
if (g_raid3_debug >= (lvl)) { \
|
||||
printf("GEOM_RAID3"); \
|
||||
if (g_raid3_debug > 0) \
|
||||
printf("[%u]", lvl); \
|
||||
printf(": "); \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} \
|
||||
} while (0)
|
||||
#define G_RAID3_LOGREQ(lvl, bp, ...) do { \
|
||||
if (g_raid3_debug >= (lvl)) { \
|
||||
printf("GEOM_RAID3"); \
|
||||
if (g_raid3_debug > 0) \
|
||||
printf("[%u]", lvl); \
|
||||
printf(": "); \
|
||||
printf(__VA_ARGS__); \
|
||||
printf(" "); \
|
||||
g_print_bio(bp); \
|
||||
printf("\n"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define G_RAID3_MAX_IO_SIZE (DFLTPHYS * 2)
|
||||
|
||||
#define G_RAID3_BIO_CFLAG_REGULAR 0x01
|
||||
#define G_RAID3_BIO_CFLAG_SYNC 0x02
|
||||
#define G_RAID3_BIO_CFLAG_PARITY 0x04
|
||||
#define G_RAID3_BIO_CFLAG_NODISK 0x08
|
||||
#define G_RAID3_BIO_CFLAG_REGSYNC 0x10
|
||||
|
||||
#define G_RAID3_BIO_PFLAG_DEGRADED 0x01
|
||||
#define G_RAID3_BIO_PFLAG_NOPARITY 0x02
|
||||
|
||||
/*
|
||||
* Informations needed for synchronization.
|
||||
*/
|
||||
struct g_raid3_disk_sync {
|
||||
struct g_consumer *ds_consumer; /* Consumer connected to our device. */
|
||||
off_t ds_offset; /* Offset of next request to send. */
|
||||
off_t ds_offset_done; /* Offset of already synchronized
|
||||
region. */
|
||||
u_int ds_syncid; /* Disk's synchronization ID. */
|
||||
u_char *ds_data;
|
||||
};
|
||||
|
||||
/*
|
||||
* Informations needed for synchronization.
|
||||
*/
|
||||
struct g_raid3_device_sync {
|
||||
struct g_geom *ds_geom; /* Synchronization geom. */
|
||||
};
|
||||
|
||||
#define G_RAID3_DISK_STATE_NODISK 0
|
||||
#define G_RAID3_DISK_STATE_NONE 1
|
||||
#define G_RAID3_DISK_STATE_NEW 2
|
||||
#define G_RAID3_DISK_STATE_ACTIVE 3
|
||||
#define G_RAID3_DISK_STATE_STALE 4
|
||||
#define G_RAID3_DISK_STATE_SYNCHRONIZING 5
|
||||
#define G_RAID3_DISK_STATE_DISCONNECTED 6
|
||||
#define G_RAID3_DISK_STATE_DESTROY 7
|
||||
struct g_raid3_disk {
|
||||
u_int d_no; /* Disk number. */
|
||||
struct g_consumer *d_consumer; /* Consumer. */
|
||||
struct g_raid3_softc *d_softc; /* Back-pointer to softc. */
|
||||
int d_state; /* Disk state. */
|
||||
uint64_t d_flags; /* Additional flags. */
|
||||
struct g_raid3_disk_sync d_sync; /* Sync information. */
|
||||
LIST_ENTRY(g_raid3_disk) d_next;
|
||||
};
|
||||
#define d_name d_consumer->provider->name
|
||||
|
||||
#define G_RAID3_EVENT_DONTWAIT 0x1
|
||||
#define G_RAID3_EVENT_WAIT 0x2
|
||||
#define G_RAID3_EVENT_DEVICE 0x4
|
||||
#define G_RAID3_EVENT_DONE 0x8
|
||||
struct g_raid3_event {
|
||||
struct g_raid3_disk *e_disk;
|
||||
int e_state;
|
||||
int e_flags;
|
||||
int e_error;
|
||||
TAILQ_ENTRY(g_raid3_event) e_next;
|
||||
};
|
||||
|
||||
#define G_RAID3_DEVICE_FLAG_DESTROY 0x0100000000000000ULL
|
||||
#define G_RAID3_DEVICE_FLAG_WAIT 0x0200000000000000ULL
|
||||
|
||||
#define G_RAID3_DEVICE_STATE_STARTING 0
|
||||
#define G_RAID3_DEVICE_STATE_DEGRADED 1
|
||||
#define G_RAID3_DEVICE_STATE_COMPLETE 2
|
||||
|
||||
#define G_RAID3_BUMP_ON_FIRST_WRITE 1
|
||||
#define G_RAID3_BUMP_IMMEDIATELY 2
|
||||
|
||||
struct g_raid3_softc {
|
||||
u_int sc_state; /* Device state. */
|
||||
uint64_t sc_mediasize; /* Device size. */
|
||||
uint32_t sc_sectorsize; /* Sector size. */
|
||||
uint64_t sc_flags; /* Additional flags. */
|
||||
|
||||
struct g_geom *sc_geom;
|
||||
struct g_provider *sc_provider;
|
||||
|
||||
uint32_t sc_id; /* Device unique ID. */
|
||||
|
||||
struct bio_queue_head sc_queue;
|
||||
struct mtx sc_queue_mtx;
|
||||
struct proc *sc_worker;
|
||||
|
||||
struct g_raid3_disk *sc_disks;
|
||||
u_int sc_ndisks; /* Number of disks. */
|
||||
struct g_raid3_disk *sc_syncdisk;
|
||||
|
||||
uma_zone_t sc_zone_64k;
|
||||
uma_zone_t sc_zone_16k;
|
||||
uma_zone_t sc_zone_4k;
|
||||
|
||||
u_int sc_syncid; /* Synchronization ID. */
|
||||
int sc_bump_syncid;
|
||||
struct g_raid3_device_sync sc_sync;
|
||||
|
||||
TAILQ_HEAD(, g_raid3_event) sc_events;
|
||||
struct mtx sc_events_mtx;
|
||||
|
||||
struct callout sc_callout;
|
||||
};
|
||||
#define sc_name sc_geom->name
|
||||
|
||||
const char *g_raid3_get_diskname(struct g_raid3_disk *disk);
|
||||
u_int g_raid3_ndisks(struct g_raid3_softc *sc, int state);
|
||||
int g_raid3_destroy(struct g_raid3_softc *sc, boolean_t force);
|
||||
int g_raid3_event_send(void *arg, int state, int flags);
|
||||
struct g_raid3_metadata;
|
||||
void g_raid3_fill_metadata(struct g_raid3_disk *disk,
|
||||
struct g_raid3_metadata *md);
|
||||
int g_raid3_clear_metadata(struct g_raid3_disk *disk);
|
||||
void g_raid3_update_metadata(struct g_raid3_disk *disk);
|
||||
|
||||
g_ctl_req_t g_raid3_config;
|
||||
#endif /* _KERNEL */
|
||||
|
||||
struct g_raid3_metadata {
|
||||
char md_magic[16]; /* Magic value. */
|
||||
uint32_t md_version; /* Version number. */
|
||||
char md_name[16]; /* Device name. */
|
||||
uint32_t md_id; /* Device unique ID. */
|
||||
uint16_t md_no; /* Component number. */
|
||||
uint16_t md_all; /* Number of disks in device. */
|
||||
uint32_t md_syncid; /* Synchronization ID. */
|
||||
uint64_t md_mediasize; /* Size of whole device. */
|
||||
uint32_t md_sectorsize; /* Sector size. */
|
||||
uint64_t md_sync_offset; /* Synchronized offset. */
|
||||
uint64_t md_mflags; /* Additional device flags. */
|
||||
uint64_t md_dflags; /* Additional disk flags. */
|
||||
char md_provider[16]; /* Hardcoded provider. */
|
||||
u_char md_hash[16]; /* MD5 hash. */
|
||||
};
|
||||
static __inline void
|
||||
raid3_metadata_encode(struct g_raid3_metadata *md, u_char *data)
|
||||
{
|
||||
MD5_CTX ctx;
|
||||
|
||||
bcopy(md->md_magic, data, 16);
|
||||
le32enc(data + 16, md->md_version);
|
||||
bcopy(md->md_name, data + 20, 16);
|
||||
le32enc(data + 36, md->md_id);
|
||||
le16enc(data + 40, md->md_no);
|
||||
le16enc(data + 42, md->md_all);
|
||||
le32enc(data + 44, md->md_syncid);
|
||||
le64enc(data + 48, md->md_mediasize);
|
||||
le32enc(data + 56, md->md_sectorsize);
|
||||
le64enc(data + 60, md->md_sync_offset);
|
||||
le64enc(data + 68, md->md_mflags);
|
||||
le64enc(data + 76, md->md_dflags);
|
||||
bcopy(md->md_provider, data + 84, 16);
|
||||
MD5Init(&ctx);
|
||||
MD5Update(&ctx, data, 100);
|
||||
MD5Final(md->md_hash, &ctx);
|
||||
bcopy(md->md_hash, data + 100, 16);
|
||||
}
|
||||
static __inline int
|
||||
raid3_metadata_decode(const u_char *data, struct g_raid3_metadata *md)
|
||||
{
|
||||
MD5_CTX ctx;
|
||||
|
||||
bcopy(data, md->md_magic, 16);
|
||||
md->md_version = le32dec(data + 16);
|
||||
bcopy(data + 20, md->md_name, 16);
|
||||
md->md_id = le32dec(data + 36);
|
||||
md->md_no = le16dec(data + 40);
|
||||
md->md_all = le16dec(data + 42);
|
||||
md->md_syncid = le32dec(data + 44);
|
||||
md->md_mediasize = le64dec(data + 48);
|
||||
md->md_sectorsize = le32dec(data + 56);
|
||||
md->md_sync_offset = le64dec(data + 60);
|
||||
md->md_mflags = le64dec(data + 68);
|
||||
md->md_dflags = le64dec(data + 76);
|
||||
bcopy(data + 84, md->md_provider, 16);
|
||||
bcopy(data + 100, md->md_hash, 16);
|
||||
MD5Init(&ctx);
|
||||
MD5Update(&ctx, data, 100);
|
||||
MD5Final(md->md_hash, &ctx);
|
||||
if (bcmp(md->md_hash, data + 100, 16) != 0)
|
||||
return (EINVAL);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static __inline void
|
||||
raid3_metadata_dump(const struct g_raid3_metadata *md)
|
||||
{
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
char hash[16 * 2 + 1];
|
||||
u_int i;
|
||||
|
||||
printf(" magic: %s\n", md->md_magic);
|
||||
printf(" version: %u\n", (u_int)md->md_version);
|
||||
printf(" name: %s\n", md->md_name);
|
||||
printf(" id: %u\n", (u_int)md->md_id);
|
||||
printf(" no: %u\n", (u_int)md->md_no);
|
||||
printf(" all: %u\n", (u_int)md->md_all);
|
||||
printf(" syncid: %u\n", (u_int)md->md_syncid);
|
||||
printf(" mediasize: %jd\n", (intmax_t)md->md_mediasize);
|
||||
printf("sectorsize: %u\n", (u_int)md->md_sectorsize);
|
||||
printf("syncoffset: %jd\n", (intmax_t)md->md_sync_offset);
|
||||
printf(" mflags:");
|
||||
if (md->md_mflags == 0)
|
||||
printf(" NONE");
|
||||
else {
|
||||
if ((md->md_mflags & G_RAID3_DEVICE_FLAG_NOAUTOSYNC) != 0)
|
||||
printf(" NOAUTOSYNC");
|
||||
}
|
||||
printf("\n");
|
||||
printf(" dflags:");
|
||||
if (md->md_dflags == 0)
|
||||
printf(" NONE");
|
||||
else {
|
||||
if ((md->md_dflags & G_RAID3_DISK_FLAG_DIRTY) != 0)
|
||||
printf(" DIRTY");
|
||||
if ((md->md_dflags & G_RAID3_DISK_FLAG_SYNCHRONIZING) != 0)
|
||||
printf(" SYNCHRONIZING");
|
||||
if ((md->md_dflags & G_RAID3_DISK_FLAG_FORCE_SYNC) != 0)
|
||||
printf(" FORCE_SYNC");
|
||||
}
|
||||
printf("\n");
|
||||
printf("hcprovider: %s\n", md->md_provider);
|
||||
bzero(hash, sizeof(hash));
|
||||
for (i = 0; i < 16; i++) {
|
||||
hash[i * 2] = hex[md->md_hash[i] >> 4];
|
||||
hash[i * 2 + 1] = hex[md->md_hash[i] & 0x0f];
|
||||
}
|
||||
printf(" MD5 hash: %s\n", hash);
|
||||
}
|
||||
#endif /* !_G_RAID3_H_ */
|
484
sys/geom/raid3/g_raid3_ctl.c
Normal file
484
sys/geom/raid3/g_raid3_ctl.c
Normal file
@ -0,0 +1,484 @@
|
||||
/*-
|
||||
* Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
||||
* 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 AUTHORS AND CONTRIBUTORS ``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 AUTHORS OR CONTRIBUTORS 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/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/bio.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/bitstring.h>
|
||||
#include <vm/uma.h>
|
||||
#include <machine/atomic.h>
|
||||
#include <geom/geom.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/kthread.h>
|
||||
#include <geom/raid3/g_raid3.h>
|
||||
|
||||
|
||||
static struct g_raid3_softc *
|
||||
g_raid3_find_device(struct g_class *mp, const char *name)
|
||||
{
|
||||
struct g_raid3_softc *sc;
|
||||
struct g_geom *gp;
|
||||
|
||||
g_topology_assert();
|
||||
LIST_FOREACH(gp, &mp->geom, geom) {
|
||||
sc = gp->softc;
|
||||
if (sc == NULL)
|
||||
continue;
|
||||
if ((sc->sc_flags & G_RAID3_DEVICE_FLAG_DESTROY) != 0)
|
||||
continue;
|
||||
if (strcmp(gp->name, name) == 0 ||
|
||||
strcmp(sc->sc_name, name) == 0) {
|
||||
return (sc);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static struct g_raid3_disk *
|
||||
g_raid3_find_disk(struct g_raid3_softc *sc, const char *name)
|
||||
{
|
||||
struct g_raid3_disk *disk;
|
||||
u_int n;
|
||||
|
||||
g_topology_assert();
|
||||
for (n = 0; n < sc->sc_ndisks; n++) {
|
||||
disk = &sc->sc_disks[n];
|
||||
if (disk->d_state == G_RAID3_DISK_STATE_NODISK)
|
||||
continue;
|
||||
if (disk->d_consumer == NULL)
|
||||
continue;
|
||||
if (disk->d_consumer->provider == NULL)
|
||||
continue;
|
||||
if (strcmp(disk->d_consumer->provider->name, name) == 0)
|
||||
return (disk);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
g_raid3_ctl_configure(struct gctl_req *req, struct g_class *mp)
|
||||
{
|
||||
struct g_raid3_softc *sc;
|
||||
struct g_raid3_disk *disk;
|
||||
const char *name;
|
||||
int *nargs, *autosync, *noautosync, do_sync = 0;
|
||||
u_int n;
|
||||
|
||||
g_topology_assert();
|
||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
|
||||
if (*nargs != 1) {
|
||||
gctl_error(req, "Invalid number of arguments.");
|
||||
return;
|
||||
}
|
||||
name = gctl_get_asciiparam(req, "arg0");
|
||||
sc = g_raid3_find_device(mp, name);
|
||||
if (sc == NULL) {
|
||||
gctl_error(req, "No such device: %s.", name);
|
||||
return;
|
||||
}
|
||||
if (g_raid3_ndisks(sc, -1) < sc->sc_ndisks) {
|
||||
gctl_error(req, "Not all disks connected.");
|
||||
return;
|
||||
}
|
||||
autosync = gctl_get_paraml(req, "autosync", sizeof(*autosync));
|
||||
if (autosync == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "autosync");
|
||||
return;
|
||||
}
|
||||
noautosync = gctl_get_paraml(req, "noautosync", sizeof(*noautosync));
|
||||
if (noautosync == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "noautosync");
|
||||
return;
|
||||
}
|
||||
if (!*autosync && !*noautosync) {
|
||||
gctl_error(req, "Nothing has changed.");
|
||||
return;
|
||||
}
|
||||
if (*autosync && *noautosync) {
|
||||
gctl_error(req, "'%s' and '%s' specified.", "autosync",
|
||||
"noautosync");
|
||||
return;
|
||||
}
|
||||
if ((sc->sc_flags & G_RAID3_DEVICE_FLAG_NOAUTOSYNC) != 0) {
|
||||
if (*autosync) {
|
||||
sc->sc_flags &= ~G_RAID3_DEVICE_FLAG_NOAUTOSYNC;
|
||||
do_sync = 1;
|
||||
}
|
||||
} else {
|
||||
if (*noautosync)
|
||||
sc->sc_flags |= G_RAID3_DEVICE_FLAG_NOAUTOSYNC;
|
||||
}
|
||||
for (n = 0; n < sc->sc_ndisks; n++) {
|
||||
disk = &sc->sc_disks[n];
|
||||
if (do_sync) {
|
||||
if (disk->d_state == G_RAID3_DISK_STATE_SYNCHRONIZING)
|
||||
disk->d_flags &= ~G_RAID3_DISK_FLAG_FORCE_SYNC;
|
||||
}
|
||||
g_raid3_update_metadata(disk);
|
||||
if (do_sync) {
|
||||
if (disk->d_state == G_RAID3_DISK_STATE_STALE) {
|
||||
/*
|
||||
* XXX: This is probably possible that this
|
||||
* component will not be retasted.
|
||||
*/
|
||||
g_raid3_event_send(disk,
|
||||
G_RAID3_DISK_STATE_DISCONNECTED,
|
||||
G_RAID3_EVENT_DONTWAIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
g_raid3_ctl_rebuild(struct gctl_req *req, struct g_class *mp)
|
||||
{
|
||||
struct g_raid3_softc *sc;
|
||||
struct g_raid3_disk *disk;
|
||||
const char *name;
|
||||
int *nargs;
|
||||
|
||||
g_topology_assert();
|
||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
|
||||
if (nargs == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "nargs");
|
||||
return;
|
||||
}
|
||||
if (*nargs != 2) {
|
||||
gctl_error(req, "Invalid number of arguments.");
|
||||
return;
|
||||
}
|
||||
name = gctl_get_asciiparam(req, "arg0");
|
||||
if (name == NULL) {
|
||||
gctl_error(req, "No 'arg%u' argument.", 0);
|
||||
return;
|
||||
}
|
||||
sc = g_raid3_find_device(mp, name);
|
||||
if (sc == NULL) {
|
||||
gctl_error(req, "No such device: %s.", name);
|
||||
return;
|
||||
}
|
||||
name = gctl_get_asciiparam(req, "arg1");
|
||||
if (name == NULL) {
|
||||
gctl_error(req, "No 'arg%u' argument.", 1);
|
||||
return;
|
||||
}
|
||||
disk = g_raid3_find_disk(sc, name);
|
||||
if (disk == NULL) {
|
||||
gctl_error(req, "No such provider: %s.", name);
|
||||
return;
|
||||
}
|
||||
if (disk->d_state == G_RAID3_DISK_STATE_ACTIVE &&
|
||||
g_raid3_ndisks(sc, G_RAID3_DISK_STATE_ACTIVE) < sc->sc_ndisks) {
|
||||
gctl_error(req, "There is one stale disk already.", name);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Do rebuild by resetting syncid and disconnecting disk.
|
||||
* It'll be retasted, connected to the device and synchronized.
|
||||
*/
|
||||
disk->d_sync.ds_syncid = 0;
|
||||
if ((sc->sc_flags & G_RAID3_DEVICE_FLAG_NOAUTOSYNC) != 0)
|
||||
disk->d_flags |= G_RAID3_DISK_FLAG_FORCE_SYNC;
|
||||
g_raid3_update_metadata(disk);
|
||||
g_raid3_event_send(disk, G_RAID3_DISK_STATE_DISCONNECTED,
|
||||
G_RAID3_EVENT_WAIT);
|
||||
}
|
||||
|
||||
static void
|
||||
g_raid3_ctl_stop(struct gctl_req *req, struct g_class *mp)
|
||||
{
|
||||
struct g_raid3_softc *sc;
|
||||
int *force, *nargs, error;
|
||||
const char *name;
|
||||
char param[16];
|
||||
u_int i;
|
||||
|
||||
g_topology_assert();
|
||||
|
||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
|
||||
if (nargs == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "nargs");
|
||||
return;
|
||||
}
|
||||
if (*nargs < 1) {
|
||||
gctl_error(req, "Missing device(s).");
|
||||
return;
|
||||
}
|
||||
force = gctl_get_paraml(req, "force", sizeof(*force));
|
||||
if (force == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "force");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < (u_int)*nargs; i++) {
|
||||
snprintf(param, sizeof(param), "arg%u", i);
|
||||
name = gctl_get_asciiparam(req, param);
|
||||
if (name == NULL) {
|
||||
gctl_error(req, "No 'arg%u' argument.", i);
|
||||
return;
|
||||
}
|
||||
sc = g_raid3_find_device(mp, name);
|
||||
if (sc == NULL) {
|
||||
gctl_error(req, "No such device: %s.", name);
|
||||
return;
|
||||
}
|
||||
error = g_raid3_destroy(sc, *force);
|
||||
if (error != 0) {
|
||||
gctl_error(req, "Cannot destroy device %s (error=%d).",
|
||||
sc->sc_geom->name, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
g_raid3_ctl_insert_orphan(struct g_consumer *cp)
|
||||
{
|
||||
|
||||
KASSERT(1 == 0, ("%s called while inserting %s.", __func__,
|
||||
cp->provider->name));
|
||||
}
|
||||
|
||||
static void
|
||||
g_raid3_ctl_insert(struct gctl_req *req, struct g_class *mp)
|
||||
{
|
||||
struct g_raid3_metadata md;
|
||||
struct g_raid3_softc *sc;
|
||||
struct g_raid3_disk *disk;
|
||||
struct g_geom *gp;
|
||||
struct g_provider *pp;
|
||||
struct g_consumer *cp;
|
||||
const char *name;
|
||||
u_char *sector;
|
||||
intmax_t *no;
|
||||
int *hardcode, *nargs, error;
|
||||
|
||||
g_topology_assert();
|
||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
|
||||
if (nargs == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "nargs");
|
||||
return;
|
||||
}
|
||||
if (*nargs != 2) {
|
||||
gctl_error(req, "Invalid number of arguments.");
|
||||
return;
|
||||
}
|
||||
name = gctl_get_asciiparam(req, "arg0");
|
||||
if (name == NULL) {
|
||||
gctl_error(req, "No 'arg%u' argument.", 0);
|
||||
return;
|
||||
}
|
||||
sc = g_raid3_find_device(mp, name);
|
||||
if (sc == NULL) {
|
||||
gctl_error(req, "No such device: %s.", name);
|
||||
return;
|
||||
}
|
||||
no = gctl_get_paraml(req, "number", sizeof(*no));
|
||||
if (no == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "no");
|
||||
return;
|
||||
}
|
||||
if (*no >= sc->sc_ndisks) {
|
||||
gctl_error(req, "Invalid component number.");
|
||||
return;
|
||||
}
|
||||
hardcode = gctl_get_paraml(req, "hardcode", sizeof(*hardcode));
|
||||
if (hardcode == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "hardcode");
|
||||
return;
|
||||
}
|
||||
disk = &sc->sc_disks[*no];
|
||||
if (disk->d_state != G_RAID3_DISK_STATE_NODISK) {
|
||||
gctl_error(req, "Component %u is already connected.", *no);
|
||||
return;
|
||||
}
|
||||
name = gctl_get_asciiparam(req, "arg1");
|
||||
if (name == NULL) {
|
||||
gctl_error(req, "No 'arg%u' argument.", 1);
|
||||
return;
|
||||
}
|
||||
pp = g_provider_by_name(name);
|
||||
if (pp == NULL) {
|
||||
gctl_error(req, "Invalid provider.");
|
||||
return;
|
||||
}
|
||||
if (((sc->sc_sectorsize / (sc->sc_ndisks - 1)) % pp->sectorsize) != 0) {
|
||||
gctl_error(req,
|
||||
"Cannot insert provider %s, because of its sector size.",
|
||||
pp->name);
|
||||
return;
|
||||
}
|
||||
gp = g_new_geomf(mp, "raid3:insert");
|
||||
gp->orphan = g_raid3_ctl_insert_orphan;
|
||||
cp = g_new_consumer(gp);
|
||||
error = g_attach(cp, pp);
|
||||
if (error != 0) {
|
||||
gctl_error(req, "Cannot attach to %s.", pp->name);
|
||||
goto end;
|
||||
}
|
||||
error = g_access(cp, 0, 1, 1);
|
||||
if (error != 0) {
|
||||
gctl_error(req, "Cannot access %s.", pp->name);
|
||||
goto end;
|
||||
}
|
||||
g_raid3_fill_metadata(disk, &md);
|
||||
md.md_syncid = 0;
|
||||
md.md_dflags = 0;
|
||||
if (*hardcode)
|
||||
strlcpy(md.md_provider, pp->name, sizeof(md.md_provider));
|
||||
else
|
||||
bzero(md.md_provider, sizeof(md.md_provider));
|
||||
sector = g_malloc(pp->sectorsize, M_WAITOK);
|
||||
raid3_metadata_encode(&md, sector);
|
||||
g_topology_unlock();
|
||||
error = g_write_data(cp, pp->mediasize - pp->sectorsize, sector,
|
||||
pp->sectorsize);
|
||||
g_topology_lock();
|
||||
g_free(sector);
|
||||
if (error != 0)
|
||||
gctl_error(req, "Cannot store metadata on %s.", pp->name);
|
||||
end:
|
||||
if (gp != NULL) {
|
||||
if (cp != NULL) {
|
||||
if (cp->acw > 0)
|
||||
g_access(cp, 0, -1, -1);
|
||||
if (cp->provider != NULL)
|
||||
g_detach(cp);
|
||||
g_destroy_consumer(cp);
|
||||
}
|
||||
g_destroy_geom(gp);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
g_raid3_ctl_remove(struct gctl_req *req, struct g_class *mp)
|
||||
{
|
||||
struct g_raid3_softc *sc;
|
||||
struct g_raid3_disk *disk;
|
||||
const char *name;
|
||||
intmax_t *no;
|
||||
int *nargs;
|
||||
|
||||
g_topology_assert();
|
||||
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
|
||||
if (nargs == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "nargs");
|
||||
return;
|
||||
}
|
||||
if (*nargs != 1) {
|
||||
gctl_error(req, "Invalid number of arguments.");
|
||||
return;
|
||||
}
|
||||
name = gctl_get_asciiparam(req, "arg0");
|
||||
if (name == NULL) {
|
||||
gctl_error(req, "No 'arg%u' argument.", 0);
|
||||
return;
|
||||
}
|
||||
sc = g_raid3_find_device(mp, name);
|
||||
if (sc == NULL) {
|
||||
gctl_error(req, "No such device: %s.", name);
|
||||
return;
|
||||
}
|
||||
no = gctl_get_paraml(req, "number", sizeof(*no));
|
||||
if (no == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "no");
|
||||
return;
|
||||
}
|
||||
if (*no >= sc->sc_ndisks) {
|
||||
gctl_error(req, "Invalid component number.");
|
||||
return;
|
||||
}
|
||||
disk = &sc->sc_disks[*no];
|
||||
switch (disk->d_state) {
|
||||
case G_RAID3_DISK_STATE_ACTIVE:
|
||||
/*
|
||||
* When replacing ACTIVE component, all the rest has to be also
|
||||
* ACTIVE.
|
||||
*/
|
||||
if (g_raid3_ndisks(sc, G_RAID3_DISK_STATE_ACTIVE) <
|
||||
sc->sc_ndisks) {
|
||||
gctl_error(req, "Cannot replace component number %u.",
|
||||
*no);
|
||||
return;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case G_RAID3_DISK_STATE_STALE:
|
||||
case G_RAID3_DISK_STATE_SYNCHRONIZING:
|
||||
if (g_raid3_clear_metadata(disk) != 0) {
|
||||
gctl_error(req, "Cannot clear metadata on %s.",
|
||||
g_raid3_get_diskname(disk));
|
||||
sc->sc_bump_syncid = G_RAID3_BUMP_IMMEDIATELY;
|
||||
}
|
||||
g_raid3_event_send(disk, G_RAID3_DISK_STATE_DISCONNECTED,
|
||||
G_RAID3_EVENT_WAIT);
|
||||
break;
|
||||
case G_RAID3_DISK_STATE_NODISK:
|
||||
break;
|
||||
default:
|
||||
gctl_error(req, "Cannot replace component number %u.", *no);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g_raid3_config(struct gctl_req *req, struct g_class *mp, const char *verb)
|
||||
{
|
||||
uint32_t *version;
|
||||
|
||||
g_topology_assert();
|
||||
|
||||
version = gctl_get_paraml(req, "version", sizeof(*version));
|
||||
if (version == NULL) {
|
||||
gctl_error(req, "No '%s' argument.", "version");
|
||||
return;
|
||||
}
|
||||
if (*version != G_RAID3_VERSION) {
|
||||
gctl_error(req, "Userland and kernel parts are out of sync.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(verb, "configure") == 0)
|
||||
g_raid3_ctl_configure(req, mp);
|
||||
else if (strcmp(verb, "insert") == 0)
|
||||
g_raid3_ctl_insert(req, mp);
|
||||
else if (strcmp(verb, "rebuild") == 0)
|
||||
g_raid3_ctl_rebuild(req, mp);
|
||||
else if (strcmp(verb, "remove") == 0)
|
||||
g_raid3_ctl_remove(req, mp);
|
||||
else if (strcmp(verb, "stop") == 0)
|
||||
g_raid3_ctl_stop(req, mp);
|
||||
else
|
||||
gctl_error(req, "Unknown verb.");
|
||||
}
|
9
sys/modules/geom/geom_raid3/Makefile
Normal file
9
sys/modules/geom/geom_raid3/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.PATH: ${.CURDIR}/../../../geom/raid3
|
||||
|
||||
KMOD= geom_raid3
|
||||
SRCS= g_raid3.c
|
||||
SRCS+= g_raid3_ctl.c
|
||||
|
||||
.include <bsd.kmod.mk>
|
Loading…
x
Reference in New Issue
Block a user