summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorMarco Peereboom <marco@cvs.openbsd.org>2008-08-22 02:00:13 +0000
committerMarco Peereboom <marco@cvs.openbsd.org>2008-08-22 02:00:13 +0000
commitc6721809ba7f5c92bc4e3467237036dede2bbf18 (patch)
treeae39840f615398dd418d8db40ba1c1813d0bcb54 /sbin
parentc503c93462caae532cda73784a279fd9b12491c4 (diff)
Add a hack to manually kick off rebuilds. This will need some love in the
near future. ok deraadt
Diffstat (limited to 'sbin')
-rw-r--r--sbin/bioctl/bioctl.811
-rw-r--r--sbin/bioctl/bioctl.c84
2 files changed, 78 insertions, 17 deletions
diff --git a/sbin/bioctl/bioctl.8 b/sbin/bioctl/bioctl.8
index 4137b47d1b3..ed777895634 100644
--- a/sbin/bioctl/bioctl.8
+++ b/sbin/bioctl/bioctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: bioctl.8,v 1.59 2008/08/11 17:28:24 marco Exp $
+.\" $OpenBSD: bioctl.8,v 1.60 2008/08/22 02:00:12 marco Exp $
.\"
.\" Copyright (c) 2004, 2005 Marco Peereboom
.\"
@@ -23,7 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: August 11 2008 $
+.Dd $Mdocdate: August 22 2008 $
.Dt BIOCTL 8
.Os
.Sh NAME
@@ -40,6 +40,7 @@
.Op Fl H Ar channel:target[.lun]
.Op Fl l Ar special[,special,...]
.Op Fl r Ar rounds
+.Op Fl R Ar device|channel:target[.lun]
.Op Fl u Ar channel:target[.lun]
.Ar device
.Ek
@@ -148,6 +149,12 @@ the algorithm used to convert a passphrase into a key.
Higher iteration counts take more time, but offer more resistance to key
guessing attacks.
The minimum is 1000 rounds and the default is 8192.
+.It Fl R Ar device|channel:target[.lun]
+Manually kick off a rebuild using device or
+.Ar channel:target[.lun]
+on the provided drive name.
+This command requires a drive by name (e.g. sd1) instead of a controller
+by name (e.g. softraid0).
.It Fl u Ar channel:target[.lun]
Instruct the device at
.Ar channel:target[.lun]
diff --git a/sbin/bioctl/bioctl.c b/sbin/bioctl/bioctl.c
index 6096c5c2d10..b9cee800411 100644
--- a/sbin/bioctl/bioctl.c
+++ b/sbin/bioctl/bioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bioctl.c,v 1.74 2008/08/11 17:28:24 marco Exp $ */
+/* $OpenBSD: bioctl.c,v 1.75 2008/08/22 02:00:12 marco Exp $ */
/*
* Copyright (c) 2004, 2005 Marco Peereboom
@@ -70,7 +70,8 @@ void derive_key_pkcs(int, u_int8_t *, size_t, u_int8_t *,
void bio_inq(char *);
void bio_alarm(char *);
-void bio_setstate(char *);
+int bio_getvolbyname(char *);
+void bio_setstate(char *, int, char *);
void bio_setblink(char *, char *, int);
void bio_blink(char *, int, int);
void bio_createraid(u_int16_t, char *);
@@ -97,13 +98,13 @@ main(int argc, char *argv[])
char *realname = NULL, *al_arg = NULL;
char *bl_arg = NULL, *dev_list = NULL;
const char *errstr;
- int ch, rv, blink = 0, diskinq = 0;
+ int ch, rv, blink = 0, diskinq = 0, ss_func = 0;
u_int16_t cr_level = 0;
if (argc < 2)
usage();
- while ((ch = getopt(argc, argv, "a:b:C:c:dH:hil:qr:vu:")) != -1) {
+ while ((ch = getopt(argc, argv, "a:b:C:c:dH:hil:qr:R:vu:")) != -1) {
switch (ch) {
case 'a': /* alarm */
func |= BIOC_ALARM;
@@ -135,6 +136,7 @@ main(int argc, char *argv[])
break;
case 'H': /* set hotspare */
func |= BIOC_SETSTATE;
+ ss_func = BIOC_SSHOTSPARE;
al_arg = optarg;
break;
case 'h':
@@ -153,6 +155,12 @@ main(int argc, char *argv[])
errx(1, "Number of rounds is %s: %s",
errstr, optarg);
break;
+ case 'R':
+ /* rebuild to provided chunk/CTL */
+ func |= BIOC_SETSTATE;
+ ss_func = BIOC_SSREBUILD;
+ al_arg = optarg;
+ break;
case 'v':
verbose = 1;
break;
@@ -206,7 +214,7 @@ main(int argc, char *argv[])
} else if (func == BIOC_BLINK) {
bio_setblink(sd_dev, bl_arg, blink);
} else if (func == BIOC_SETSTATE) {
- bio_setstate(al_arg);
+ bio_setstate(al_arg, ss_func, argv[0]);
} else if (func == BIOC_DELETERAID && sd_dev != NULL) {
bio_deleteraid(sd_dev);
} else if (func & BIOC_CREATERAID || func & BIOC_DEVLIST) {
@@ -233,8 +241,9 @@ usage(void)
"\t[-C flag[,flag,...]] [-c raidlevel] "
"[-H channel:target[.lun]]\n"
"\t[-l special[,special,...]] [-r rounds] "
- "[-u channel:target[.lun]]\n"
- "\tdevice\n", __progname);
+ "[-R device|channel:target[.lun]\n"
+ "\t[-u channel:target[.lun]] "
+ "device\n", __progname);
exit(1);
}
@@ -492,23 +501,67 @@ bio_alarm(char *arg)
}
}
+int
+bio_getvolbyname(char *name)
+{
+ int id = -1, i, rv;
+ struct bioc_inq bi;
+ struct bioc_vol bv;
+
+ memset(&bi, 0, sizeof(bi));
+ bi.bi_cookie = bl.bl_cookie;
+ rv = ioctl(devh, BIOCINQ, &bi);
+ if (rv == -1)
+ err(1, "BIOCINQ");
+
+ for (i = 0; i < bi.bi_novol; i++) {
+ memset(&bv, 0, sizeof(bv));
+ bv.bv_cookie = bl.bl_cookie;
+ bv.bv_volid = i;
+ rv = ioctl(devh, BIOCVOL, &bv);
+ if (rv == -1)
+ err(1, "BIOCVOL");
+
+ if (name && strcmp(name, bv.bv_dev) != 0)
+ continue;
+ id = i;
+ break;
+ }
+
+ return (id);
+}
+
void
-bio_setstate(char *arg)
+bio_setstate(char *arg, int status, char *devname)
{
struct bioc_setstate bs;
struct locator location;
+ struct stat sb;
const char *errstr;
int rv;
- errstr = str2locator(arg, &location);
- if (errstr)
- errx(1, "Target %s: %s", arg, errstr);
+ memset(&bs, 0, sizeof(bs));
+ if (stat(arg, &sb) == -1) {
+ /* use CTL */
+ errstr = str2locator(arg, &location);
+ if (errstr)
+ errx(1, "Target %s: %s", arg, errstr);
+ bs.bs_channel = location.channel;
+ bs.bs_target = location.target;
+ bs.bs_lun = location.lun;
+ } else {
+ /* use other id */
+ bs.bs_other_id = sb.st_rdev;
+ bs.bs_other_id_type = BIOC_SSOTHER_DEVT;
+ }
bs.bs_cookie = bl.bl_cookie;
- bs.bs_status = BIOC_SSHOTSPARE;
- bs.bs_channel = location.channel;
- bs.bs_target = location.target;
- bs.bs_lun = location.lun;
+ bs.bs_status = status;
+
+ /* make sure user supplied a sd device */
+ bs.bs_volid = bio_getvolbyname(devname);
+ if (bs.bs_volid == -1)
+ errx(1, "invalid device %s", devname);
rv = ioctl(devh, BIOCSETSTATE, &bs);
if (rv == -1)
@@ -831,6 +884,7 @@ bio_deleteraid(char *dev)
memset(&bd, 0, sizeof(bd));
bd.bd_cookie = bd.bd_cookie;
+ /* XXX make this a dev_t instead of a string */
strlcpy(bd.bd_dev, dev, sizeof bd.bd_dev);
if (ioctl(devh, BIOCDELETERAID, &bd))
errx(1, "delete volume %s failed", dev);