2 * Copyright (c) 2008, 2009 Yahoo!, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the authors may not be used to endorse or promote
14 * products derived from this software without specific prior written
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/param.h>
34 #include <sys/sysctl.h>
47 static int add_spare(int ac, char **av);
48 static int remove_spare(int ac, char **av);
51 dehumanize(const char *value)
58 iv = strtoq(value, &vtp, 0);
59 if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
80 mfi_config_read(int fd, struct mfi_config_data **configp)
82 return mfi_config_read_opcode(fd, MFI_DCMD_CFG_READ, configp, NULL, 0);
86 mfi_config_read_opcode(int fd, uint32_t opcode, struct mfi_config_data **configp,
87 uint8_t *mbox, size_t mboxlen)
89 struct mfi_config_data *config;
94 * Keep fetching the config in a loop until we have a large enough
95 * buffer to hold the entire configuration.
100 config = reallocf(config, config_size);
103 if (mfi_dcmd_command(fd, opcode, config,
104 config_size, mbox, mboxlen, NULL) < 0) {
111 if (config->size > config_size) {
112 config_size = config->size;
120 static struct mfi_array *
121 mfi_config_lookup_array(struct mfi_config_data *config, uint16_t array_ref)
123 struct mfi_array *ar;
127 p = (char *)config->array;
128 for (i = 0; i < config->array_count; i++) {
129 ar = (struct mfi_array *)p;
130 if (ar->array_ref == array_ref)
132 p += config->array_size;
138 static struct mfi_ld_config *
139 mfi_config_lookup_volume(struct mfi_config_data *config, uint8_t target_id)
141 struct mfi_ld_config *ld;
145 p = (char *)config->array + config->array_count * config->array_size;
146 for (i = 0; i < config->log_drv_count; i++) {
147 ld = (struct mfi_ld_config *)p;
148 if (ld->properties.ld.v.target_id == target_id)
150 p += config->log_drv_size;
157 clear_config(int ac __unused, char **av __unused)
159 struct mfi_ld_list list;
163 fd = mfi_open(mfi_unit, O_RDWR);
170 if (!mfi_reconfig_supported()) {
171 warnx("The current mfi(4) driver does not support "
172 "configuration changes.");
177 if (mfi_ld_get_list(fd, &list, NULL) < 0) {
179 warn("Failed to get volume list");
184 for (i = 0; i < list.ld_count; i++) {
185 if (mfi_volume_busy(fd, list.ld_list[i].ld.v.target_id)) {
186 warnx("Volume %s is busy and cannot be deleted",
187 mfi_volume_name(fd, list.ld_list[i].ld.v.target_id));
194 "Are you sure you wish to clear the configuration on mfi%u? [y/N] ",
197 if (ch != 'y' && ch != 'Y') {
198 printf("\nAborting\n");
203 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_CLEAR, NULL, 0, NULL, 0, NULL) < 0) {
205 warn("Failed to clear configuration");
210 printf("mfi%d: Configuration cleared\n", mfi_unit);
215 MFI_COMMAND(top, clear, clear_config);
217 #define MAX_DRIVES_PER_ARRAY MFI_MAX_ROW_SIZE
218 #define MFI_ARRAY_SIZE sizeof(struct mfi_array)
231 compare_int(const void *one, const void *two)
235 first = *(const int *)one;
236 second = *(const int *)two;
238 return (first - second);
241 static struct raid_type_entry {
244 } raid_type_table[] = {
245 { "raid0", RT_RAID0 },
246 { "raid-0", RT_RAID0 },
247 { "raid1", RT_RAID1 },
248 { "raid-1", RT_RAID1 },
249 { "mirror", RT_RAID1 },
250 { "raid5", RT_RAID5 },
251 { "raid-5", RT_RAID5 },
252 { "raid6", RT_RAID6 },
253 { "raid-6", RT_RAID6 },
255 { "concat", RT_CONCAT },
256 { "raid10", RT_RAID10 },
257 { "raid1+0", RT_RAID10 },
258 { "raid-10", RT_RAID10 },
259 { "raid-1+0", RT_RAID10 },
260 { "raid50", RT_RAID50 },
261 { "raid5+0", RT_RAID50 },
262 { "raid-50", RT_RAID50 },
263 { "raid-5+0", RT_RAID50 },
264 { "raid60", RT_RAID60 },
265 { "raid6+0", RT_RAID60 },
266 { "raid-60", RT_RAID60 },
267 { "raid-6+0", RT_RAID60 },
271 struct config_id_state {
282 struct mfi_pd_info *drives;
283 struct mfi_array *array;
286 /* Parse a comma-separated list of drives for an array. */
288 parse_array(int fd, int raid_type, char *array_str, struct array_info *info)
290 struct mfi_pd_info *pinfo;
297 for (count = 0; cp != NULL; count++) {
298 cp = strchr(cp, ',');
302 warnx("Invalid drive list '%s'", array_str);
308 /* Validate the number of drives for this array. */
309 if (count >= MAX_DRIVES_PER_ARRAY) {
310 warnx("Too many drives for a single array: max is %d",
311 MAX_DRIVES_PER_ARRAY);
317 if (count % 2 != 0) {
318 warnx("RAID1 and RAID10 require an even number of "
319 "drives in each array");
326 warnx("RAID5 and RAID50 require at least 3 drives in "
334 warnx("RAID6 and RAID60 require at least 4 drives in "
341 /* Validate each drive. */
342 info->drives = calloc(count, sizeof(struct mfi_pd_info));
343 if (info->drives == NULL) {
344 warnx("malloc failed");
347 info->drive_count = count;
348 for (pinfo = info->drives; (cp = strsep(&array_str, ",")) != NULL;
350 error = mfi_lookup_drive(fd, cp, &device_id);
357 if (mfi_pd_get_info(fd, device_id, pinfo, NULL) < 0) {
359 warn("Failed to fetch drive info for drive %s", cp);
365 if (pinfo->fw_state != MFI_PD_STATE_UNCONFIGURED_GOOD) {
366 warnx("Drive %u is not available", device_id);
372 if (pinfo->state.ddf.v.pd_type.is_foreign) {
373 warnx("Drive %u is foreign", device_id);
384 * Find the next free array ref assuming that 'array_ref' is the last
385 * one used. 'array_ref' should be 0xffff for the initial test.
388 find_next_array(struct config_id_state *state)
392 /* Assume the current one is used. */
395 /* Find the next free one. */
396 for (i = 0; i < state->array_count; i++)
397 if (state->arrays[i] == state->array_ref)
399 return (state->array_ref);
403 * Find the next free volume ID assuming that 'target_id' is the last
404 * one used. 'target_id' should be 0xff for the initial test.
407 find_next_volume(struct config_id_state *state)
411 /* Assume the current one is used. */
414 /* Find the next free one. */
415 for (i = 0; i < state->log_drv_count; i++)
416 if (state->volumes[i] == state->target_id)
418 return (state->target_id);
421 /* Populate an array with drives. */
423 build_array(int fd __unused, char *arrayp, struct array_info *array_info,
424 struct config_id_state *state, int verbose)
426 struct mfi_array *ar = (struct mfi_array *)arrayp;
429 ar->size = array_info->drives[0].coerced_size;
430 ar->num_drives = array_info->drive_count;
431 ar->array_ref = find_next_array(state);
432 for (i = 0; i < array_info->drive_count; i++) {
434 printf("Adding drive %s to array %u\n",
436 array_info->drives[i].ref.v.device_id,
437 MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS),
439 if (ar->size > array_info->drives[i].coerced_size)
440 ar->size = array_info->drives[i].coerced_size;
441 ar->pd[i].ref = array_info->drives[i].ref;
442 ar->pd[i].fw_state = MFI_PD_STATE_ONLINE;
444 array_info->array = ar;
448 * Create a volume that spans one or more arrays.
451 build_volume(char *volumep, int narrays, struct array_info *arrays,
452 int raid_type, long stripe_size, struct config_id_state *state, int verbose)
454 struct mfi_ld_config *ld = (struct mfi_ld_config *)volumep;
455 struct mfi_array *ar;
459 ld->properties.ld.v.target_id = find_next_volume(state);
460 ld->properties.ld.v.seq = 0;
461 ld->properties.default_cache_policy = MR_LD_CACHE_ALLOW_WRITE_CACHE |
462 MR_LD_CACHE_WRITE_BACK;
463 ld->properties.access_policy = MFI_LD_ACCESS_RW;
464 ld->properties.disk_cache_policy = MR_PD_CACHE_UNCHANGED;
465 ld->properties.current_cache_policy = MR_LD_CACHE_ALLOW_WRITE_CACHE |
466 MR_LD_CACHE_WRITE_BACK;
467 ld->properties.no_bgi = 0;
473 ld->params.primary_raid_level = DDF_RAID0;
474 ld->params.raid_level_qualifier = 0;
475 ld->params.secondary_raid_level = 0;
478 ld->params.primary_raid_level = DDF_RAID1;
479 ld->params.raid_level_qualifier = 0;
480 ld->params.secondary_raid_level = 0;
483 ld->params.primary_raid_level = DDF_RAID5;
484 ld->params.raid_level_qualifier = 3;
485 ld->params.secondary_raid_level = 0;
488 ld->params.primary_raid_level = DDF_RAID6;
489 ld->params.raid_level_qualifier = 3;
490 ld->params.secondary_raid_level = 0;
493 ld->params.primary_raid_level = DDF_CONCAT;
494 ld->params.raid_level_qualifier = 0;
495 ld->params.secondary_raid_level = 0;
498 ld->params.primary_raid_level = DDF_RAID1;
499 ld->params.raid_level_qualifier = 0;
500 ld->params.secondary_raid_level = 3; /* XXX? */
504 * XXX: This appears to work though the card's BIOS
505 * complains that the configuration is foreign. The
506 * BIOS setup does not allow for creation of RAID-50
507 * or RAID-60 arrays. The only nested array
508 * configuration it allows for is RAID-10.
510 ld->params.primary_raid_level = DDF_RAID5;
511 ld->params.raid_level_qualifier = 3;
512 ld->params.secondary_raid_level = 3; /* XXX? */
515 ld->params.primary_raid_level = DDF_RAID6;
516 ld->params.raid_level_qualifier = 3;
517 ld->params.secondary_raid_level = 3; /* XXX? */
522 * Stripe size is encoded as (2 ^ N) * 512 = stripe_size. Use
523 * ffs() to simulate log2(stripe_size).
525 ld->params.stripe_size = ffs(stripe_size) - 1 - 9;
526 ld->params.num_drives = arrays[0].array->num_drives;
527 ld->params.span_depth = narrays;
528 ld->params.state = MFI_LD_STATE_OPTIMAL;
529 ld->params.init_state = MFI_LD_PARAMS_INIT_NO;
530 ld->params.is_consistent = 0;
533 for (i = 0; i < narrays; i++) {
534 ar = arrays[i].array;
536 printf("Adding array %u to volume %u\n", ar->array_ref,
537 ld->properties.ld.v.target_id);
538 ld->span[i].start_block = 0;
539 ld->span[i].num_blocks = ar->size;
540 ld->span[i].array_ref = ar->array_ref;
545 create_volume(int ac, char **av)
547 struct mfi_config_data *config;
548 struct mfi_array *ar;
549 struct mfi_ld_config *ld;
550 struct config_id_state state;
552 char *p, *cfg_arrays, *cfg_volumes;
553 int error, fd, i, raid_type;
554 int narrays, nvolumes, arrays_per_volume;
555 struct array_info *arrays;
563 * Backwards compat. Map 'create volume' to 'create' and
564 * 'create spare' to 'add'.
567 if (strcmp(av[1], "volume") == 0) {
570 } else if (strcmp(av[1], "spare") == 0) {
573 return (add_spare(ac, av));
578 warnx("create volume: volume type required");
582 bzero(&state, sizeof(state));
588 fd = mfi_open(mfi_unit, O_RDWR);
595 if (!mfi_reconfig_supported()) {
596 warnx("The current mfi(4) driver does not support "
597 "configuration changes.");
602 /* Lookup the RAID type first. */
604 for (i = 0; raid_type_table[i].name != NULL; i++)
605 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
606 raid_type = raid_type_table[i].raid_type;
610 if (raid_type == -1) {
611 warnx("Unknown or unsupported volume type %s", av[1]);
616 /* Parse any options. */
622 stripe_size = 64 * 1024;
624 while ((ch = getopt(ac, av, "ds:v")) != -1) {
632 stripe_size = dehumanize(optarg);
633 if ((stripe_size < 512) || (!powerof2(stripe_size)))
634 stripe_size = 64 * 1024;
648 /* Parse all the arrays. */
651 warnx("At least one drive list is required");
662 warnx("Only one drive list can be specified");
671 warnx("RAID10, RAID50, and RAID60 require at least "
676 if (narrays > MFI_MAX_SPAN_DEPTH) {
677 warnx("Volume spans more than %d arrays",
684 arrays = calloc(narrays, sizeof(*arrays));
685 if (arrays == NULL) {
686 warnx("malloc failed");
690 for (i = 0; i < narrays; i++) {
691 error = parse_array(fd, raid_type, av[i], &arrays[i]);
700 for (i = 1; i < narrays; i++) {
701 if (arrays[i].drive_count != arrays[0].drive_count) {
702 warnx("All arrays must contain the same "
712 * Fetch the current config and build sorted lists of existing
713 * array and volume identifiers.
715 if (mfi_config_read(fd, &config) < 0) {
717 warn("Failed to read configuration");
720 p = (char *)config->array;
721 state.array_ref = 0xffff;
722 state.target_id = 0xff;
723 state.array_count = config->array_count;
724 if (config->array_count > 0) {
725 state.arrays = calloc(config->array_count, sizeof(int));
726 if (state.arrays == NULL) {
727 warnx("malloc failed");
731 for (i = 0; i < config->array_count; i++) {
732 ar = (struct mfi_array *)p;
733 state.arrays[i] = ar->array_ref;
734 p += config->array_size;
736 qsort(state.arrays, config->array_count, sizeof(int),
740 state.log_drv_count = config->log_drv_count;
741 if (config->log_drv_count) {
742 state.volumes = calloc(config->log_drv_count, sizeof(int));
743 if (state.volumes == NULL) {
744 warnx("malloc failed");
748 for (i = 0; i < config->log_drv_count; i++) {
749 ld = (struct mfi_ld_config *)p;
750 state.volumes[i] = ld->properties.ld.v.target_id;
751 p += config->log_drv_size;
753 qsort(state.volumes, config->log_drv_count, sizeof(int),
756 state.volumes = NULL;
759 /* Determine the size of the configuration we will build. */
767 /* Each volume spans a single array. */
773 /* A single volume spans multiple arrays. */
781 config_size = sizeof(struct mfi_config_data) +
782 sizeof(struct mfi_ld_config) * nvolumes + MFI_ARRAY_SIZE * narrays;
783 config = calloc(1, config_size);
784 if (config == NULL) {
785 warnx("malloc failed");
789 config->size = config_size;
790 config->array_count = narrays;
791 config->array_size = MFI_ARRAY_SIZE; /* XXX: Firmware hardcode */
792 config->log_drv_count = nvolumes;
793 config->log_drv_size = sizeof(struct mfi_ld_config);
794 config->spares_count = 0;
795 config->spares_size = 40; /* XXX: Firmware hardcode */
796 cfg_arrays = (char *)config->array;
797 cfg_volumes = cfg_arrays + config->array_size * narrays;
799 /* Build the arrays. */
800 for (i = 0; i < narrays; i++) {
801 build_array(fd, cfg_arrays, &arrays[i], &state, verbose);
802 cfg_arrays += config->array_size;
805 /* Now build the volume(s). */
806 arrays_per_volume = narrays / nvolumes;
807 for (i = 0; i < nvolumes; i++) {
808 build_volume(cfg_volumes, arrays_per_volume,
809 &arrays[i * arrays_per_volume], raid_type, stripe_size,
811 cfg_volumes += config->log_drv_size;
816 dump_config(fd, config, NULL);
819 /* Send the new config to the controller. */
820 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_ADD, config, config_size,
821 NULL, 0, NULL) < 0) {
823 warn("Failed to add volume");
832 if (arrays != NULL) {
833 for (i = 0; i < narrays; i++)
834 free(arrays[i].drives);
841 MFI_COMMAND(top, create, create_volume);
844 delete_volume(int ac, char **av)
846 struct mfi_ld_info info;
848 uint8_t target_id, mbox[4];
851 * Backwards compat. Map 'delete volume' to 'delete' and
852 * 'delete spare' to 'remove'.
855 if (strcmp(av[1], "volume") == 0) {
858 } else if (strcmp(av[1], "spare") == 0) {
861 return (remove_spare(ac, av));
866 warnx("delete volume: volume required");
870 fd = mfi_open(mfi_unit, O_RDWR);
877 if (!mfi_reconfig_supported()) {
878 warnx("The current mfi(4) driver does not support "
879 "configuration changes.");
884 if (mfi_lookup_volume(fd, av[1], &target_id) < 0) {
886 warn("Invalid volume %s", av[1]);
891 if (mfi_ld_get_info(fd, target_id, &info, NULL) < 0) {
893 warn("Failed to get info for volume %d", target_id);
898 if (mfi_volume_busy(fd, target_id)) {
899 warnx("Volume %s is busy and cannot be deleted",
900 mfi_volume_name(fd, target_id));
905 mbox_store_ldref(mbox, &info.ld_config.properties.ld);
906 if (mfi_dcmd_command(fd, MFI_DCMD_LD_DELETE, NULL, 0, mbox,
907 sizeof(mbox), NULL) < 0) {
909 warn("Failed to delete volume");
918 MFI_COMMAND(top, delete, delete_volume);
921 add_spare(int ac, char **av)
923 struct mfi_pd_info info;
924 struct mfi_config_data *config;
925 struct mfi_array *ar;
926 struct mfi_ld_config *ld;
927 struct mfi_spare *spare;
934 warnx("add spare: drive required");
938 fd = mfi_open(mfi_unit, O_RDWR);
947 error = mfi_lookup_drive(fd, av[1], &device_id);
951 if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) {
953 warn("Failed to fetch drive info");
957 if (info.fw_state != MFI_PD_STATE_UNCONFIGURED_GOOD) {
958 warnx("Drive %u is not available", device_id);
964 if (mfi_lookup_volume(fd, av[2], &target_id) < 0) {
966 warn("Invalid volume %s", av[2]);
971 if (mfi_config_read(fd, &config) < 0) {
973 warn("Failed to read configuration");
977 spare = malloc(sizeof(struct mfi_spare) + sizeof(uint16_t) *
978 config->array_count);
980 warnx("malloc failed");
984 bzero(spare, sizeof(struct mfi_spare));
985 spare->ref = info.ref;
988 /* Global spare backs all arrays. */
989 p = (char *)config->array;
990 for (i = 0; i < config->array_count; i++) {
991 ar = (struct mfi_array *)p;
992 if (ar->size > info.coerced_size) {
993 warnx("Spare isn't large enough for array %u",
998 p += config->array_size;
1000 spare->array_count = 0;
1003 * Dedicated spares only back the arrays for a
1006 ld = mfi_config_lookup_volume(config, target_id);
1008 warnx("Did not find volume %d", target_id);
1013 spare->spare_type |= MFI_SPARE_DEDICATED;
1014 spare->array_count = ld->params.span_depth;
1015 for (i = 0; i < ld->params.span_depth; i++) {
1016 ar = mfi_config_lookup_array(config,
1017 ld->span[i].array_ref);
1019 warnx("Missing array; inconsistent config?");
1023 if (ar->size > info.coerced_size) {
1024 warnx("Spare isn't large enough for array %u",
1029 spare->array_ref[i] = ar->array_ref;
1033 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_MAKE_SPARE, spare,
1034 sizeof(struct mfi_spare) + sizeof(uint16_t) * spare->array_count,
1035 NULL, 0, NULL) < 0) {
1037 warn("Failed to assign spare");
1048 MFI_COMMAND(top, add, add_spare);
1051 remove_spare(int ac, char **av)
1053 struct mfi_pd_info info;
1059 warnx("remove spare: drive required");
1063 fd = mfi_open(mfi_unit, O_RDWR);
1070 error = mfi_lookup_drive(fd, av[1], &device_id);
1076 /* Get the info for this drive. */
1077 if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) {
1079 warn("Failed to fetch info for drive %u", device_id);
1084 if (info.fw_state != MFI_PD_STATE_HOT_SPARE) {
1085 warnx("Drive %u is not a hot spare", device_id);
1090 mbox_store_pdref(mbox, &info.ref);
1091 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_REMOVE_SPARE, NULL, 0, mbox,
1092 sizeof(mbox), NULL) < 0) {
1094 warn("Failed to delete spare");
1103 MFI_COMMAND(top, remove, remove_spare);
1105 /* Display raw data about a config. */
1107 dump_config(int fd, struct mfi_config_data *config, const char *msg_prefix)
1109 struct mfi_array *ar;
1110 struct mfi_ld_config *ld;
1111 struct mfi_spare *sp;
1112 struct mfi_pd_info pinfo;
1117 if (NULL == msg_prefix)
1118 msg_prefix = "Configuration (Debug)";
1121 "mfi%d %s: %d arrays, %d volumes, %d spares\n", mfi_unit,
1122 msg_prefix, config->array_count, config->log_drv_count,
1123 config->spares_count);
1124 printf(" array size: %u\n", config->array_size);
1125 printf(" volume size: %u\n", config->log_drv_size);
1126 printf(" spare size: %u\n", config->spares_size);
1127 p = (char *)config->array;
1129 for (i = 0; i < config->array_count; i++) {
1130 ar = (struct mfi_array *)p;
1131 printf(" array %u of %u drives:\n", ar->array_ref,
1133 printf(" size = %ju\n", (uintmax_t)ar->size);
1134 for (j = 0; j < ar->num_drives; j++) {
1135 device_id = ar->pd[j].ref.v.device_id;
1136 if (device_id == 0xffff)
1137 printf(" drive MISSING\n");
1139 printf(" drive %u %s\n", device_id,
1140 mfi_pdstate(ar->pd[j].fw_state));
1141 if (mfi_pd_get_info(fd, device_id, &pinfo,
1143 printf(" raw size: %ju\n",
1144 (uintmax_t)pinfo.raw_size);
1145 printf(" non-coerced size: %ju\n",
1146 (uintmax_t)pinfo.non_coerced_size);
1147 printf(" coerced size: %ju\n",
1148 (uintmax_t)pinfo.coerced_size);
1152 p += config->array_size;
1155 for (i = 0; i < config->log_drv_count; i++) {
1156 ld = (struct mfi_ld_config *)p;
1157 printf(" volume %s ",
1158 mfi_volume_name(fd, ld->properties.ld.v.target_id));
1160 mfi_raid_level(ld->params.primary_raid_level,
1161 ld->params.secondary_raid_level),
1162 mfi_ldstate(ld->params.state));
1163 if (ld->properties.name[0] != '\0')
1164 printf(" <%s>", ld->properties.name);
1166 printf(" primary raid level: %u\n",
1167 ld->params.primary_raid_level);
1168 printf(" raid level qualifier: %u\n",
1169 ld->params.raid_level_qualifier);
1170 printf(" secondary raid level: %u\n",
1171 ld->params.secondary_raid_level);
1172 printf(" stripe size: %u\n", ld->params.stripe_size);
1173 printf(" num drives: %u\n", ld->params.num_drives);
1174 printf(" init state: %u\n", ld->params.init_state);
1175 printf(" consistent: %u\n", ld->params.is_consistent);
1176 printf(" no bgi: %u\n", ld->properties.no_bgi);
1177 printf(" spans:\n");
1178 for (j = 0; j < ld->params.span_depth; j++) {
1179 printf(" array %u @ ", ld->span[j].array_ref);
1180 printf("%ju : %ju\n",
1181 (uintmax_t)ld->span[j].start_block,
1182 (uintmax_t)ld->span[j].num_blocks);
1184 p += config->log_drv_size;
1187 for (i = 0; i < config->spares_count; i++) {
1188 sp = (struct mfi_spare *)p;
1189 printf(" %s spare %u ",
1190 sp->spare_type & MFI_SPARE_DEDICATED ? "dedicated" :
1191 "global", sp->ref.v.device_id);
1192 printf("%s", mfi_pdstate(MFI_PD_STATE_HOT_SPARE));
1193 printf(" backs:\n");
1194 for (j = 0; j < sp->array_count; j++)
1195 printf(" array %u\n", sp->array_ref[j]);
1196 p += config->spares_size;
1202 debug_config(int ac, char **av)
1204 struct mfi_config_data *config;
1208 warnx("debug: extra arguments");
1212 fd = mfi_open(mfi_unit, O_RDWR);
1219 /* Get the config from the controller. */
1220 if (mfi_config_read(fd, &config) < 0) {
1222 warn("Failed to get config");
1227 /* Dump out the configuration. */
1228 dump_config(fd, config, NULL);
1234 MFI_COMMAND(top, debug, debug_config);
1237 dump(int ac, char **av)
1239 struct mfi_config_data *config;
1245 warnx("dump: extra arguments");
1249 fd = mfi_open(mfi_unit, O_RDWR);
1256 /* Get the stashed copy of the last dcmd from the driver. */
1257 snprintf(buf, sizeof(buf), "dev.mfi.%d.debug_command", mfi_unit);
1258 if (sysctlbyname(buf, NULL, &len, NULL, 0) < 0) {
1260 warn("Failed to read debug command");
1261 if (error == ENOENT)
1267 config = malloc(len);
1268 if (config == NULL) {
1269 warnx("malloc failed");
1273 if (sysctlbyname(buf, config, &len, NULL, 0) < 0) {
1275 warn("Failed to read debug command");
1280 dump_config(fd, config, NULL);
1286 MFI_COMMAND(top, dump, dump);