summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorMarco Peereboom <marco@cvs.openbsd.org>2007-03-19 03:02:10 +0000
committerMarco Peereboom <marco@cvs.openbsd.org>2007-03-19 03:02:10 +0000
commit0583d77423003d709b189011b4fa7a6d3422a41a (patch)
tree2fc3b955836fb9cd6c0bb95f63972901c1870bf8 /sbin
parent16bd16fa930635ce3f536fd1bad24fa8d840a117 (diff)
Add a new device that provides a framework for IO manipulation. A very basic
implementation of a RAID 1 is included in this but it does not deal with failures yet. Disabled in GENERIC. Suggestions from and ok beck@ miod@ krw@ dlg@ deraadt@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/bioctl/bioctl.c76
1 files changed, 73 insertions, 3 deletions
diff --git a/sbin/bioctl/bioctl.c b/sbin/bioctl/bioctl.c
index 29a12b35c72..f6813a9e32a 100644
--- a/sbin/bioctl/bioctl.c
+++ b/sbin/bioctl/bioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bioctl.c,v 1.48 2006/08/28 12:36:08 mickey Exp $ */
+/* $OpenBSD: bioctl.c,v 1.49 2007/03/19 03:02:09 marco Exp $ */
/*
* Copyright (c) 2004, 2005 Marco Peereboom
@@ -60,6 +60,7 @@ void bio_alarm(char *);
void bio_setstate(char *);
void bio_setblink(char *, char *, int);
void bio_blink(char *, int, int);
+void bio_createraid(u_int16_t, char *);
int devh = -1;
int debug;
@@ -76,13 +77,14 @@ main(int argc, char *argv[])
/* u_int64_t subfunc = 0; */
char *bioc_dev = NULL, *sd_dev = NULL;
char *realname = NULL, *al_arg = NULL;
- char *bl_arg = NULL;
+ char *bl_arg = NULL, *dev_list = NULL;
int ch, rv, blink;
+ u_int16_t cr_level;
if (argc < 2)
usage();
- while ((ch = getopt(argc, argv, "b:u:H:ha:Div")) != -1) {
+ while ((ch = getopt(argc, argv, "b:c:l:u:H:ha:Div")) != -1) {
switch (ch) {
case 'a': /* alarm */
func |= BIOC_ALARM;
@@ -93,6 +95,10 @@ main(int argc, char *argv[])
blink = BIOC_SBBLINK;
bl_arg = optarg;
break;
+ case 'c': /* create */
+ func |= BIOC_CREATERAID;
+ cr_level = atoi(optarg);
+ break;
case 'u': /* unblink */
func |= BIOC_BLINK;
blink = BIOC_SBUNBLINK;
@@ -111,6 +117,10 @@ main(int argc, char *argv[])
case 'i': /* inquiry */
func |= BIOC_INQ;
break;
+ case 'l': /* device list */
+ func |= BIOC_DEVLIST;
+ dev_list = optarg;
+ break;
case 'v':
verbose = 1;
break;
@@ -163,6 +173,14 @@ main(int argc, char *argv[])
bio_setblink(sd_dev, bl_arg, blink);
} else if (func == BIOC_SETSTATE) {
bio_setstate(al_arg);
+ } else if (func & BIOC_CREATERAID || func & BIOC_DEVLIST) {
+ if (!(func & BIOC_CREATERAID))
+ errx(1, "need -c parameter");
+ if (!(func & BIOC_DEVLIST))
+ errx(1, "need -l parameter");
+ if (sd_dev)
+ errx(1, "can't use sd device");
+ bio_createraid(cr_level, dev_list);
}
return (0);
@@ -566,3 +584,55 @@ bio_blink(char *enclosure, int target, int blinktype)
close(bioh);
}
+
+void
+bio_createraid(u_int16_t level, char *dev_list)
+{
+ struct bio_locate bio;
+ struct bioc_createraid create;
+ int rv;
+ u_int16_t min_disks = 0;
+
+ if (debug)
+ printf("bio_createraid\n");
+
+ if (!dev_list)
+ errx(1, "no devices specified");
+
+ switch (level) {
+ case 0:
+ min_disks = 1;
+ break;
+ case 1:
+ min_disks = 2;
+ break;
+ default:
+ errx(1, "unsuported raid level");
+ }
+
+ /* XXX validate device list for real */
+#if 0
+ if (strncmp(dev_list, "sd", 2) == 0 && strlen(dev_list) > 2 &&
+ isdigit(dev_list[2])) {
+ if (strlen(dev_list) != 3)
+ errx(1, "only one device supported");
+
+ if (debug)
+ printf("bio_createraid: dev_list: %s\n", dev_list);
+ }
+ else
+ errx(1, "no sd device specified");
+#endif
+
+ memset(&create, 0, sizeof(create));
+ create.bc_cookie = bl.bl_cookie;
+ create.bc_level = level;
+ create.bc_dev_list_len = strlen(dev_list);
+ create.bc_dev_list = dev_list;
+
+ rv = ioctl(devh, BIOCCREATERAID, &create);
+ if (rv == -1) {
+ warn("BIOCCREATERAID");
+ return;
+ }
+}