From: Sascha Wildner Date: Sat, 20 Nov 2010 14:58:34 +0000 (+0100) Subject: mlxcontrol(8): Sync with FreeBSD. X-Git-Tag: v2.11.0~578 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/c6aff4f7f0c74961380763de0bcb5dd49fb7faea mlxcontrol(8): Sync with FreeBSD. While here, raise WARNS to 6 and fix the warnings. --- diff --git a/usr.sbin/mlxcontrol/Makefile b/usr.sbin/mlxcontrol/Makefile index cd5cff7590..922026ecd7 100644 --- a/usr.sbin/mlxcontrol/Makefile +++ b/usr.sbin/mlxcontrol/Makefile @@ -1,11 +1,9 @@ -# $FreeBSD: src/usr.sbin/mlxcontrol/Makefile,v 1.2.2.2 2001/04/25 12:10:07 ru Exp $ -# $DragonFly: src/usr.sbin/mlxcontrol/Makefile,v 1.2 2003/06/17 04:29:57 dillon Exp $ +# $FreeBSD: src/usr.sbin/mlxcontrol/Makefile,v 1.6 2010/01/02 11:07:44 ed Exp $ -PROG= mlxcontrol -SRCS= command.c config.c interface.c util.c -MAN= mlxcontrol.8 -CFLAGS+= -I${.CURDIR}/../../sys -WARNS?= 2 +PROG= mlxcontrol +MAN= mlxcontrol.8 +SRCS= command.c interface.c util.c -.include +CFLAGS+= -I${.CURDIR}/../../sys +.include diff --git a/usr.sbin/mlxcontrol/command.c b/usr.sbin/mlxcontrol/command.c index 2c11bfdf80..538b6029aa 100644 --- a/usr.sbin/mlxcontrol/command.c +++ b/usr.sbin/mlxcontrol/command.c @@ -23,8 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mlxcontrol/command.c,v 1.2.2.1 2000/04/24 19:44:46 msmith Exp $ - * $DragonFly: src/usr.sbin/mlxcontrol/command.c,v 1.3 2003/08/08 04:18:46 dillon Exp $ + * $FreeBSD: src/usr.sbin/mlxcontrol/command.c,v 1.3 2008/09/12 17:40:17 sepotvin Exp $ */ #include @@ -49,16 +48,18 @@ static int cmd_rebuild(int argc, char *argv[]); static int cmd_pause(int argc, char *argv[]); #endif static int cmd_help(int argc, char *argv[]); +static int cmd_config(int argc, char *argv[]); -extern int cmd_config(int argc, char *argv[]); - +static void print_span(struct mlx_sys_drv_span *span, int arms); +static void print_sys_drive(struct conf_config *conf, int drvno); +static void print_phys_drive(struct conf_config *conf, int chn, int targ); struct { - char *cmd; + const char *cmd; int (*func)(int argc, char *argv[]); - char *desc; - char *text; + const char *desc; + const char *text; } commands[] = { {"status", cmd_status, "displays device status", @@ -268,10 +269,86 @@ status_print(int unit, void *arg) close(fd); } +/******************************************************************************** + * Print details for the system drive (drvno) in a format that we will be + * able to parse later. + * + * drive?? + * span? 0x????????-0x???????? ????MB on [...] + * ... + */ +static void +print_span(struct mlx_sys_drv_span *span, int arms) +{ + int i; + + printf("0x%08x-0x%08x %uMB on", span->sp_start_lba, span->sp_start_lba + span->sp_nblks, span->sp_nblks / 2048); + for (i = 0; i < arms; i++) + printf(" disk%02d%02d", span->sp_arm[i] >> 4, span->sp_arm[i] & 0x0f); + printf("\n"); +} + +static void +print_sys_drive(struct conf_config *conf, int drvno) +{ + struct mlx_sys_drv *drv = &conf->cc_cfg.cc_sys_drives[drvno]; + int i; + + printf("drive%02d ", drvno); + switch(drv->sd_raidlevel & 0xf) { + case MLX_SYS_DRV_RAID0: + printf("RAID0"); + break; + case MLX_SYS_DRV_RAID1: + printf("RAID1"); + break; + case MLX_SYS_DRV_RAID3: + printf("RAID3"); + break; + case MLX_SYS_DRV_RAID5: + printf("RAID5"); + break; + case MLX_SYS_DRV_RAID6: + printf("RAID6"); + break; + case MLX_SYS_DRV_JBOD: + printf("JBOD"); + break; + default: + printf("RAID?"); + } + printf(" write%s\n", drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through"); + + for (i = 0; i < drv->sd_valid_spans; i++) { + printf(" span%d ", i); + print_span(&drv->sd_span[i], drv->sd_valid_arms); + } +} + +/******************************************************************************** + * Print details for the physical drive at chn/targ in a format suitable for + * human consumption. + * + * CCTT () "/" + * ????MB + * + */ +static void +print_phys_drive(struct conf_config *conf, int chn, int targ) +{ + struct mlx_phys_drv *drv = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ]; + + /* if the drive isn't present, don't print it */ + if (!(drv->pd_flags1 & MLX_PHYS_DRV_PRESENT)) + return; + + mlx_print_phys_drv(drv, chn, targ, "# ", 1); +} + static struct { int hwid; - char *name; + const char *name; } mlx_controller_names[] = { {0x01, "960P/PD"}, {0x02, "960PL"}, @@ -293,7 +370,7 @@ controller_print(int unit, void *arg) struct mlx_phys_drv pd; int verbosity = *(int *)arg; static char buf[80]; - char *model; + const char *model; int i, channel, target; if (verbosity == 0) @@ -305,7 +382,7 @@ controller_print(int unit, void *arg) } else { for (i = 0, model = NULL; mlx_controller_names[i].name != NULL; i++) { - if ((enq.me_hardware_id & 0xff) == mlx_controller_names[i].hwid) { + if ((int)(enq.me_hardware_id & 0xff) == mlx_controller_names[i].hwid) { model = mlx_controller_names[i].name; break; } @@ -422,7 +499,7 @@ cmd_status(int argc, char *argv[]) * rescan -a */ static void -rescan_ctrlr(int unit, void *junk) +rescan_ctrlr(int unit, void *junk __unused) { int fd; @@ -480,7 +557,7 @@ cmd_rescan(int argc, char *argv[]) * */ static void -detach_drive(int unit, void *arg) +detach_drive(int unit, void *arg __unused) { int fd; @@ -629,12 +706,46 @@ cmd_rebuild(int argc, char *argv[]) warnx("drive rebuild or consistency check is already in progress on this controller"); break; default: - warn("ioctl MLXD_CHECKASYNC"); + warn("ioctl MLXD_REBUILDASYNC"); } } return(0); } +/******************************************************************************** + * Get the configuration from the selected controller. + * + * config + * Print the configuration for + * + * XXX update to support adding/deleting drives. + */ + +int +cmd_config(int argc __unused, char *argv[] __unused) +{ + struct conf_config conf; + int unit = 0; /* XXX */ + int i, j; + + bzero(&conf.cc_cfg, sizeof(conf.cc_cfg)); + if (mlx_read_configuration(unit, &conf.cc_cfg)) { + printf("mlx%d: error submitting READ CONFIGURATION\n", unit); + } else { + + printf("# Controller \n"); + printf("#\n# Physical devices connected:\n"); + for (i = 0; i < 5; i++) + for (j = 0; j < 16; j++) + print_phys_drive(&conf, i, j); + printf("#\n# System Drives defined:\n"); + + for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++) + print_sys_drive(&conf, i); + } + return(0); +} + #ifdef SUPPORT_PAUSE /******************************************************************************** * Pause one or more channels on a controller diff --git a/usr.sbin/mlxcontrol/config.c b/usr.sbin/mlxcontrol/config.c deleted file mode 100644 index c30843e850..0000000000 --- a/usr.sbin/mlxcontrol/config.c +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * Copyright (c) 1999 Michael Smith - * 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 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 AUTHOR 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: src/usr.sbin/mlxcontrol/config.c,v 1.2.2.1 2000/04/24 19:44:46 msmith Exp $ - * $DragonFly: src/usr.sbin/mlxcontrol/config.c,v 1.3 2003/08/08 04:18:46 dillon Exp $ - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "mlxcontrol.h" - -static void print_span(struct mlx_sys_drv_span *span, int arms); -static void print_sys_drive(struct conf_config *conf, int drvno); -static void print_phys_drive(struct conf_config *conf, int chn, int targ); - -/******************************************************************************** - * Get the configuration from the selected controller. - * - * config - * Print the configuration for - * - * XXX update to support adding/deleting drives. - */ - -int -cmd_config(int argc, char *argv[]) -{ - struct conf_config conf; - int unit = 0; /* XXX */ - int i, j; - - bzero(&conf.cc_cfg, sizeof(conf.cc_cfg)); - if (mlx_read_configuration(unit, &conf.cc_cfg)) { - printf("mlx%d: error submitting READ CONFIGURATION\n", unit); - } else { - - printf("# Controller \n"); - printf("#\n# Physical devices connected:\n"); - for (i = 0; i < 5; i++) - for (j = 0; j < 16; j++) - print_phys_drive(&conf, i, j); - printf("#\n# System Drives defined:\n"); - - for (i = 0; i < conf.cc_cfg.cc_num_sys_drives; i++) - print_sys_drive(&conf, i); - } - return(0); -} - - -/******************************************************************************** - * Print details for the system drive (drvno) in a format that we will be - * able to parse later. - * - * drive?? - * span? 0x????????-0x???????? ????MB on [...] - * ... - */ -static void -print_span(struct mlx_sys_drv_span *span, int arms) -{ - int i; - - printf("0x%08x-0x%08x %uMB on", span->sp_start_lba, span->sp_start_lba + span->sp_nblks, span->sp_nblks / 2048); - for (i = 0; i < arms; i++) - printf(" disk%02d%02d", span->sp_arm[i] >> 4, span->sp_arm[i] & 0x0f); - printf("\n"); -} - -static void -print_sys_drive(struct conf_config *conf, int drvno) -{ - struct mlx_sys_drv *drv = &conf->cc_cfg.cc_sys_drives[drvno]; - int i; - - printf("drive%02d ", drvno); - switch(drv->sd_raidlevel & 0xf) { - case MLX_SYS_DRV_RAID0: - printf("RAID0"); - break; - case MLX_SYS_DRV_RAID1: - printf("RAID1"); - break; - case MLX_SYS_DRV_RAID3: - printf("RAID3"); - break; - case MLX_SYS_DRV_RAID5: - printf("RAID5"); - break; - case MLX_SYS_DRV_RAID6: - printf("RAID6"); - break; - case MLX_SYS_DRV_JBOD: - printf("JBOD"); - break; - default: - printf("RAID?"); - } - printf(" write%s\n", drv->sd_raidlevel & MLX_SYS_DRV_WRITEBACK ? "back" : "through"); - - for (i = 0; i < drv->sd_valid_spans; i++) { - printf(" span%d ", i); - print_span(&drv->sd_span[i], drv->sd_valid_arms); - } -} - -/******************************************************************************** - * Print details for the physical drive at chn/targ in a format suitable for - * human consumption. - * - * CCTT () "/" - * ????MB - * - */ -static void -print_phys_drive(struct conf_config *conf, int chn, int targ) -{ - struct mlx_phys_drv *drv = &conf->cc_cfg.cc_phys_drives[chn * 16 + targ]; - - /* if the drive isn't present, don't print it */ - if (!(drv->pd_flags1 & MLX_PHYS_DRV_PRESENT)) - return; - - mlx_print_phys_drv(drv, chn, targ, "# ", 1); -} - - diff --git a/usr.sbin/mlxcontrol/interface.c b/usr.sbin/mlxcontrol/interface.c index 8fa1d7ad39..d88e1dc197 100644 --- a/usr.sbin/mlxcontrol/interface.c +++ b/usr.sbin/mlxcontrol/interface.c @@ -23,8 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mlxcontrol/interface.c,v 1.2.2.1 2000/04/24 19:44:46 msmith Exp $ - * $DragonFly: src/usr.sbin/mlxcontrol/interface.c,v 1.3 2003/08/08 04:18:46 dillon Exp $ + * $FreeBSD: src/usr.sbin/mlxcontrol/interface.c,v 1.3 2008/09/12 17:40:17 sepotvin Exp $ */ #include @@ -80,16 +79,18 @@ void mlxd_foreach_ctrlr(int unit, void *arg) { struct mlxd_foreach_action *ma = (struct mlxd_foreach_action *)arg; - int i, fd; + int i, fd, ctrlfd; /* Get the device */ - if ((fd = open(ctrlrpath(unit), 0)) < 0) + if ((ctrlfd = open(ctrlrpath(unit), 0)) < 0) return; for (i = -1; ;) { /* Get the unit number of the next child device */ - if (ioctl(fd, MLX_NEXT_CHILD, &i) < 0) + if (ioctl(ctrlfd, MLX_NEXT_CHILD, &i) < 0) { + close(ctrlfd); return; + } /* check that we can open this unit */ if ((fd = open(drivepath(i), 0)) >= 0) @@ -123,7 +124,7 @@ static struct } mlxd_find_ctrlr_param; static void -mlxd_find_ctrlr_search(int unit, void *arg) +mlxd_find_ctrlr_search(int unit, void *arg __unused) { int i, fd; diff --git a/usr.sbin/mlxcontrol/mlxcontrol.8 b/usr.sbin/mlxcontrol/mlxcontrol.8 index f9f8fa4a01..9b8b8b216b 100644 --- a/usr.sbin/mlxcontrol/mlxcontrol.8 +++ b/usr.sbin/mlxcontrol/mlxcontrol.8 @@ -21,10 +21,9 @@ .\" (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: src/usr.sbin/mlxcontrol/mlxcontrol.8,v 1.3.2.5 2001/08/16 15:56:07 ru Exp $ -.\" $DragonFly: src/usr.sbin/mlxcontrol/mlxcontrol.8,v 1.5 2008/05/02 02:05:08 swildner Exp $ +.\" $FreeBSD: src/usr.sbin/mlxcontrol/mlxcontrol.8,v 1.10 2010/10/08 12:40:16 uqs Exp $ .\" -.Dd April 10, 2000 +.Dd November 20, 2010 .Dt MLXCONTROL 8 .Os .Sh NAME @@ -72,7 +71,7 @@ where N is the unit number of the controller. Drive names are of the form "mlxdN" where N is the unit number of the drive. Do not specify the path to a device node. -.Bl -tag -width status +.Bl -tag -width rebuild .It status Print the status of controllers and system drives. If one or more drives are specified, @@ -91,7 +90,7 @@ This command returns 2 if one or more are offline. .It rescan Rescan one or more controllers for non-attached system drives -(eg. drives that have been +(e.g.\& drives that have been detached or created subsequent to driver initialisation). If the .Fl a @@ -105,12 +104,28 @@ If the flag is supplied, detach all system drives from the nominated controller. .It check Initiate a consistency check and repair pass on a redundant system drive -(eg. RAID1 or RAID5). +(e.g.\& RAID1 or RAID5). The controller will scan the system drive and repair any inconsistencies. This command returns immediately; use the .Ar status command to monitor the progress of the check. +.It rebuild +Requires two arguments, +.Ar controller +and +.Ar physdrive +as specified in the +output of the +.Ar status +command. +All system drives using space on the physical drive +.Ar physdrive +are rebuilt, reconstructing all data on the drive. +Note that each controller can only perform one rebuild at a time. +This command returns immediately; use the +.Ar status +command to monitor the progress of the rebuild. .It config Print the current configuration from the nominated controller. This command will be updated diff --git a/usr.sbin/mlxcontrol/mlxcontrol.h b/usr.sbin/mlxcontrol/mlxcontrol.h index 9224c534ab..fecfec3e28 100644 --- a/usr.sbin/mlxcontrol/mlxcontrol.h +++ b/usr.sbin/mlxcontrol/mlxcontrol.h @@ -23,8 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mlxcontrol/mlxcontrol.h,v 1.1.1.1.2.1 2000/04/24 19:44:47 msmith Exp $ - * $DragonFly: src/usr.sbin/mlxcontrol/mlxcontrol.h,v 1.3 2005/02/17 14:00:10 joerg Exp $ + * $FreeBSD: src/usr.sbin/mlxcontrol/mlxcontrol.h,v 1.4 2004/10/02 16:42:33 stefanf Exp $ */ #include @@ -55,7 +54,7 @@ extern char *drivename(int unit); extern int ctrlrunit(char *str); extern int driveunit(char *str); -extern void mlx_print_phys_drv(struct mlx_phys_drv *drv, int channel, int target, char *prefix, int verbose); +extern void mlx_print_phys_drv(struct mlx_phys_drv *drv, int channel, int target, const char *prefix, int verbose); struct conf_phys_drv { diff --git a/usr.sbin/mlxcontrol/util.c b/usr.sbin/mlxcontrol/util.c index b8e9f5f0d6..8751e93539 100644 --- a/usr.sbin/mlxcontrol/util.c +++ b/usr.sbin/mlxcontrol/util.c @@ -23,8 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mlxcontrol/util.c,v 1.2.2.1 2000/04/24 19:44:47 msmith Exp $ - * $DragonFly: src/usr.sbin/mlxcontrol/util.c,v 1.3 2003/08/08 04:18:46 dillon Exp $ + * $FreeBSD: src/usr.sbin/mlxcontrol/util.c,v 1.2 2000/04/11 23:04:17 msmith Exp $ */ #include @@ -108,9 +107,10 @@ driveunit(char *str) */ void -mlx_print_phys_drv(struct mlx_phys_drv *drv, int chn, int targ, char *prefix, int verbose) +mlx_print_phys_drv(struct mlx_phys_drv *drv, int chn, int targ, const char *prefix, int verbose) { - char *type, *device, *vendor, *revision; + const char *type; + char *device, *vendor, *revision; switch(drv->pd_flags2 & 0x03) { case MLX_PHYS_DRV_DISK: