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>
49 static void dump_config(int fd, struct mfi_config_data *config);
52 static int add_spare(int ac, char **av);
53 static int remove_spare(int ac, char **av);
56 dehumanize(const char *value)
63 iv = strtoq(value, &vtp, 0);
64 if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
84 mfi_config_read(int fd, struct mfi_config_data **configp)
86 struct mfi_config_data *config;
90 * Keep fetching the config in a loop until we have a large enough
91 * buffer to hold the entire configuration.
96 config = reallocf(config, config_size);
99 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_READ, config,
100 config_size, NULL, 0, NULL) < 0)
103 if (config->size > config_size) {
104 config_size = config->size;
112 static struct mfi_array *
113 mfi_config_lookup_array(struct mfi_config_data *config, uint16_t array_ref)
115 struct mfi_array *ar;
119 p = (char *)config->array;
120 for (i = 0; i < config->array_count; i++) {
121 ar = (struct mfi_array *)p;
122 if (ar->array_ref == array_ref)
124 p += config->array_size;
130 static struct mfi_ld_config *
131 mfi_config_lookup_volume(struct mfi_config_data *config, uint8_t target_id)
133 struct mfi_ld_config *ld;
137 p = (char *)config->array + config->array_count * config->array_size;
138 for (i = 0; i < config->log_drv_count; i++) {
139 ld = (struct mfi_ld_config *)p;
140 if (ld->properties.ld.v.target_id == target_id)
142 p += config->log_drv_size;
149 clear_config(int ac, char **av)
151 struct mfi_ld_list list;
155 fd = mfi_open(mfi_unit);
162 if (!mfi_reconfig_supported()) {
163 warnx("The current mfi(4) driver does not support "
164 "configuration changes.");
168 if (mfi_ld_get_list(fd, &list, NULL) < 0) {
170 warn("Failed to get volume list");
174 for (i = 0; i < list.ld_count; i++) {
175 if (mfi_volume_busy(fd, list.ld_list[i].ld.v.target_id)) {
176 warnx("Volume %s is busy and cannot be deleted",
177 mfi_volume_name(fd, list.ld_list[i].ld.v.target_id));
183 "Are you sure you wish to clear the configuration on mfi%u? [y/N] ",
186 if (ch != 'y' && ch != 'Y') {
187 printf("\nAborting\n");
191 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_CLEAR, NULL, 0, NULL, 0, NULL) < 0) {
193 warn("Failed to clear configuration");
197 printf("mfi%d: Configuration cleared\n", mfi_unit);
202 MFI_COMMAND(top, clear, clear_config);
204 #define MFI_ARRAY_SIZE 288
205 #define MAX_DRIVES_PER_ARRAY \
206 ((MFI_ARRAY_SIZE - sizeof(struct mfi_array)) / 8)
219 compare_int(const void *one, const void *two)
223 first = *(const int *)one;
224 second = *(const int *)two;
226 return (first - second);
229 static struct raid_type_entry {
232 } raid_type_table[] = {
233 { "raid0", RT_RAID0 },
234 { "raid-0", RT_RAID0 },
235 { "raid1", RT_RAID1 },
236 { "raid-1", RT_RAID1 },
237 { "mirror", RT_RAID1 },
238 { "raid5", RT_RAID5 },
239 { "raid-5", RT_RAID5 },
240 { "raid6", RT_RAID6 },
241 { "raid-6", RT_RAID6 },
243 { "concat", RT_CONCAT },
244 { "raid10", RT_RAID10 },
245 { "raid1+0", RT_RAID10 },
246 { "raid-10", RT_RAID10 },
247 { "raid-1+0", RT_RAID10 },
248 { "raid50", RT_RAID50 },
249 { "raid5+0", RT_RAID50 },
250 { "raid-50", RT_RAID50 },
251 { "raid-5+0", RT_RAID50 },
252 { "raid60", RT_RAID60 },
253 { "raid6+0", RT_RAID60 },
254 { "raid-60", RT_RAID60 },
255 { "raid-6+0", RT_RAID60 },
259 struct config_id_state {
270 struct mfi_pd_info *drives;
271 struct mfi_array *array;
274 /* Parse a comma-separated list of drives for an array. */
276 parse_array(int fd, int raid_type, char *array_str, struct array_info *info)
278 struct mfi_pd_info *pinfo;
285 for (count = 0; cp != NULL; count++) {
286 cp = strchr(cp, ',');
290 warnx("Invalid drive list '%s'", array_str);
296 /* Validate the number of drives for this array. */
297 if (count >= MAX_DRIVES_PER_ARRAY) {
298 warnx("Too many drives for a single array: max is %zu",
299 MAX_DRIVES_PER_ARRAY);
305 if (count % 2 != 0) {
306 warnx("RAID1 and RAID10 require an even number of "
307 "drives in each array");
314 warnx("RAID5 and RAID50 require at least 3 drives in "
322 warnx("RAID6 and RAID60 require at least 4 drives in "
329 /* Validate each drive. */
330 info->drives = calloc(count, sizeof(struct mfi_pd_info));
331 info->drive_count = count;
332 for (pinfo = info->drives; (cp = strsep(&array_str, ",")) != NULL;
334 error = mfi_lookup_drive(fd, cp, &device_id);
338 if (mfi_pd_get_info(fd, device_id, pinfo, NULL) < 0) {
340 warn("Failed to fetch drive info for drive %s", cp);
344 if (pinfo->fw_state != MFI_PD_STATE_UNCONFIGURED_GOOD) {
345 warnx("Drive %u is not available", device_id);
354 * Find the next free array ref assuming that 'array_ref' is the last
355 * one used. 'array_ref' should be 0xffff for the initial test.
358 find_next_array(struct config_id_state *state)
362 /* Assume the current one is used. */
365 /* Find the next free one. */
366 for (i = 0; i < state->array_count; i++)
367 if (state->arrays[i] == state->array_ref)
369 return (state->array_ref);
373 * Find the next free volume ID assuming that 'target_id' is the last
374 * one used. 'target_id' should be 0xff for the initial test.
377 find_next_volume(struct config_id_state *state)
381 /* Assume the current one is used. */
384 /* Find the next free one. */
385 for (i = 0; i < state->log_drv_count; i++)
386 if (state->volumes[i] == state->target_id)
388 return (state->target_id);
391 /* Populate an array with drives. */
393 build_array(int fd, char *arrayp, struct array_info *array_info,
394 struct config_id_state *state, int verbose)
396 struct mfi_array *ar = (struct mfi_array *)arrayp;
399 ar->size = array_info->drives[0].coerced_size;
400 ar->num_drives = array_info->drive_count;
401 ar->array_ref = find_next_array(state);
402 for (i = 0; i < array_info->drive_count; i++) {
404 printf("Adding drive %u to array %u\n",
405 array_info->drives[i].ref.v.device_id,
407 if (ar->size > array_info->drives[i].coerced_size)
408 ar->size = array_info->drives[i].coerced_size;
409 ar->pd[i].ref = array_info->drives[i].ref;
410 ar->pd[i].fw_state = MFI_PD_STATE_ONLINE;
412 array_info->array = ar;
416 * Create a volume that spans one or more arrays.
419 build_volume(char *volumep, int narrays, struct array_info *arrays,
420 int raid_type, long stripe_size, struct config_id_state *state, int verbose)
422 struct mfi_ld_config *ld = (struct mfi_ld_config *)volumep;
423 struct mfi_array *ar;
427 ld->properties.ld.v.target_id = find_next_volume(state);
428 ld->properties.ld.v.seq = 0;
429 ld->properties.default_cache_policy = MR_LD_CACHE_ALLOW_WRITE_CACHE |
430 MR_LD_CACHE_WRITE_BACK;
431 ld->properties.access_policy = MFI_LD_ACCESS_RW;
432 ld->properties.disk_cache_policy = MR_PD_CACHE_UNCHANGED;
433 ld->properties.current_cache_policy = MR_LD_CACHE_ALLOW_WRITE_CACHE |
434 MR_LD_CACHE_WRITE_BACK;
435 ld->properties.no_bgi = 0;
441 ld->params.primary_raid_level = DDF_RAID0;
442 ld->params.raid_level_qualifier = 0;
443 ld->params.secondary_raid_level = 0;
446 ld->params.primary_raid_level = DDF_RAID1;
447 ld->params.raid_level_qualifier = 0;
448 ld->params.secondary_raid_level = 0;
451 ld->params.primary_raid_level = DDF_RAID5;
452 ld->params.raid_level_qualifier = 3;
453 ld->params.secondary_raid_level = 0;
456 ld->params.primary_raid_level = DDF_RAID6;
457 ld->params.raid_level_qualifier = 3;
458 ld->params.secondary_raid_level = 0;
461 ld->params.primary_raid_level = DDF_CONCAT;
462 ld->params.raid_level_qualifier = 0;
463 ld->params.secondary_raid_level = 0;
466 ld->params.primary_raid_level = DDF_RAID1;
467 ld->params.raid_level_qualifier = 0;
468 ld->params.secondary_raid_level = 3; /* XXX? */
472 * XXX: This appears to work though the card's BIOS
473 * complains that the configuration is foreign. The
474 * BIOS setup does not allow for creation of RAID-50
475 * or RAID-60 arrays. The only nested array
476 * configuration it allows for is RAID-10.
478 ld->params.primary_raid_level = DDF_RAID5;
479 ld->params.raid_level_qualifier = 3;
480 ld->params.secondary_raid_level = 3; /* XXX? */
483 ld->params.primary_raid_level = DDF_RAID6;
484 ld->params.raid_level_qualifier = 3;
485 ld->params.secondary_raid_level = 3; /* XXX? */
490 * Stripe size is encoded as (2 ^ N) * 512 = stripe_size. Use
491 * ffs() to simulate log2(stripe_size).
493 ld->params.stripe_size = ffs(stripe_size) - 1 - 9;
494 ld->params.num_drives = arrays[0].array->num_drives;
495 ld->params.span_depth = narrays;
496 ld->params.state = MFI_LD_STATE_OPTIMAL;
497 ld->params.init_state = MFI_LD_PARAMS_INIT_NO;
498 ld->params.is_consistent = 0;
501 for (i = 0; i < narrays; i++) {
502 ar = arrays[i].array;
504 printf("Adding array %u to volume %u\n", ar->array_ref,
505 ld->properties.ld.v.target_id);
506 ld->span[i].start_block = 0;
507 ld->span[i].num_blocks = ar->size;
508 ld->span[i].array_ref = ar->array_ref;
513 create_volume(int ac, char **av)
515 struct mfi_config_data *config;
516 struct mfi_array *ar;
517 struct mfi_ld_config *ld;
518 struct config_id_state state;
520 char *p, *cfg_arrays, *cfg_volumes;
521 int error, fd, i, raid_type;
522 int narrays, nvolumes, arrays_per_volume;
523 struct array_info *arrays;
531 * Backwards compat. Map 'create volume' to 'create' and
532 * 'create spare' to 'add'.
535 if (strcmp(av[1], "volume") == 0) {
538 } else if (strcmp(av[1], "spare") == 0) {
541 return (add_spare(ac, av));
546 warnx("create volume: volume type required");
551 fd = mfi_open(mfi_unit);
558 if (!mfi_reconfig_supported()) {
559 warnx("The current mfi(4) driver does not support "
560 "configuration changes.");
564 /* Lookup the RAID type first. */
566 for (i = 0; raid_type_table[i].name != NULL; i++)
567 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
568 raid_type = raid_type_table[i].raid_type;
572 if (raid_type == -1) {
573 warnx("Unknown or unsupported volume type %s", av[1]);
577 /* Parse any options. */
583 stripe_size = 64 * 1024;
585 while ((ch = getopt(ac, av, "ds:v")) != -1) {
593 stripe_size = dehumanize(optarg);
594 if ((stripe_size < 512) || (!powerof2(stripe_size)))
595 stripe_size = 64 * 1024;
608 /* Parse all the arrays. */
611 warnx("At least one drive list is required");
621 warnx("Only one drive list can be specified");
629 warnx("RAID10, RAID50, and RAID60 require at least "
633 if (narrays > MFI_MAX_SPAN_DEPTH) {
634 warnx("Volume spans more than %d arrays",
640 arrays = calloc(narrays, sizeof(*arrays));
641 for (i = 0; i < narrays; i++) {
642 error = parse_array(fd, raid_type, av[i], &arrays[i]);
651 for (i = 1; i < narrays; i++) {
652 if (arrays[i].drive_count != arrays[0].drive_count) {
653 warnx("All arrays must contain the same "
662 * Fetch the current config and build sorted lists of existing
663 * array and volume identifiers.
665 if (mfi_config_read(fd, &config) < 0) {
667 warn("Failed to read configuration");
670 p = (char *)config->array;
671 state.array_ref = 0xffff;
672 state.target_id = 0xff;
673 state.array_count = config->array_count;
674 if (config->array_count > 0) {
675 state.arrays = calloc(config->array_count, sizeof(int));
676 for (i = 0; i < config->array_count; i++) {
677 ar = (struct mfi_array *)p;
678 state.arrays[i] = ar->array_ref;
679 p += config->array_size;
681 qsort(state.arrays, config->array_count, sizeof(int),
685 state.log_drv_count = config->log_drv_count;
686 if (config->log_drv_count) {
687 state.volumes = calloc(config->log_drv_count, sizeof(int));
688 for (i = 0; i < config->log_drv_count; i++) {
689 ld = (struct mfi_ld_config *)p;
690 state.volumes[i] = ld->properties.ld.v.target_id;
691 p += config->log_drv_size;
693 qsort(state.volumes, config->log_drv_count, sizeof(int),
696 state.volumes = NULL;
699 /* Determine the size of the configuration we will build. */
707 /* Each volume spans a single array. */
713 /* A single volume spans multiple arrays. */
721 config_size = sizeof(struct mfi_config_data) +
722 sizeof(struct mfi_ld_config) * nvolumes + MFI_ARRAY_SIZE * narrays;
723 config = calloc(1, config_size);
724 config->size = config_size;
725 config->array_count = narrays;
726 config->array_size = MFI_ARRAY_SIZE; /* XXX: Firmware hardcode */
727 config->log_drv_count = nvolumes;
728 config->log_drv_size = sizeof(struct mfi_ld_config);
729 config->spares_count = 0;
730 config->spares_size = 40; /* XXX: Firmware hardcode */
731 cfg_arrays = (char *)config->array;
732 cfg_volumes = cfg_arrays + config->array_size * narrays;
734 /* Build the arrays. */
735 for (i = 0; i < narrays; i++) {
736 build_array(fd, cfg_arrays, &arrays[i], &state, verbose);
737 cfg_arrays += config->array_size;
740 /* Now build the volume(s). */
741 arrays_per_volume = narrays / nvolumes;
742 for (i = 0; i < nvolumes; i++) {
743 build_volume(cfg_volumes, arrays_per_volume,
744 &arrays[i * arrays_per_volume], raid_type, stripe_size,
746 cfg_volumes += config->log_drv_size;
751 dump_config(fd, config);
754 /* Send the new config to the controller. */
755 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_ADD, config, config_size,
756 NULL, 0, NULL) < 0) {
758 warn("Failed to add volume");
764 if (state.log_drv_count > 0)
766 if (state.array_count > 0)
768 for (i = 0; i < narrays; i++)
769 free(arrays[i].drives);
775 MFI_COMMAND(top, create, create_volume);
778 delete_volume(int ac, char **av)
780 struct mfi_ld_info info;
782 uint8_t target_id, mbox[4];
785 * Backwards compat. Map 'delete volume' to 'delete' and
786 * 'delete spare' to 'remove'.
789 if (strcmp(av[1], "volume") == 0) {
792 } else if (strcmp(av[1], "spare") == 0) {
795 return (remove_spare(ac, av));
800 warnx("delete volume: volume required");
804 fd = mfi_open(mfi_unit);
811 if (!mfi_reconfig_supported()) {
812 warnx("The current mfi(4) driver does not support "
813 "configuration changes.");
817 if (mfi_lookup_volume(fd, av[1], &target_id) < 0) {
819 warn("Invalid volume %s", av[1]);
823 if (mfi_ld_get_info(fd, target_id, &info, NULL) < 0) {
825 warn("Failed to get info for volume %d", target_id);
829 if (mfi_volume_busy(fd, target_id)) {
830 warnx("Volume %s is busy and cannot be deleted",
831 mfi_volume_name(fd, target_id));
835 mbox_store_ldref(mbox, &info.ld_config.properties.ld);
836 if (mfi_dcmd_command(fd, MFI_DCMD_LD_DELETE, NULL, 0, mbox,
837 sizeof(mbox), NULL) < 0) {
839 warn("Failed to delete volume");
847 MFI_COMMAND(top, delete, delete_volume);
850 add_spare(int ac, char **av)
852 struct mfi_pd_info info;
853 struct mfi_config_data *config;
854 struct mfi_array *ar;
855 struct mfi_ld_config *ld;
856 struct mfi_spare *spare;
863 warnx("add spare: drive required");
867 fd = mfi_open(mfi_unit);
874 error = mfi_lookup_drive(fd, av[1], &device_id);
878 if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) {
880 warn("Failed to fetch drive info");
884 if (info.fw_state != MFI_PD_STATE_UNCONFIGURED_GOOD) {
885 warnx("Drive %u is not available", device_id);
890 if (mfi_lookup_volume(fd, av[2], &target_id) < 0) {
892 warn("Invalid volume %s", av[2]);
897 if (mfi_config_read(fd, &config) < 0) {
899 warn("Failed to read configuration");
903 spare = malloc(sizeof(struct mfi_spare) + sizeof(uint16_t) *
904 config->array_count);
905 bzero(spare, sizeof(struct mfi_spare));
906 spare->ref = info.ref;
909 /* Global spare backs all arrays. */
910 p = (char *)config->array;
911 for (i = 0; i < config->array_count; i++) {
912 ar = (struct mfi_array *)p;
913 if (ar->size > info.coerced_size) {
914 warnx("Spare isn't large enough for array %u",
918 p += config->array_size;
920 spare->array_count = 0;
923 * Dedicated spares only back the arrays for a
926 ld = mfi_config_lookup_volume(config, target_id);
928 warnx("Did not find volume %d", target_id);
932 spare->spare_type |= MFI_SPARE_DEDICATED;
933 spare->array_count = ld->params.span_depth;
934 for (i = 0; i < ld->params.span_depth; i++) {
935 ar = mfi_config_lookup_array(config,
936 ld->span[i].array_ref);
938 warnx("Missing array; inconsistent config?");
941 if (ar->size > info.coerced_size) {
942 warnx("Spare isn't large enough for array %u",
946 spare->array_ref[i] = ar->array_ref;
951 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_MAKE_SPARE, spare,
952 sizeof(struct mfi_spare) + sizeof(uint16_t) * spare->array_count,
953 NULL, 0, NULL) < 0) {
955 warn("Failed to assign spare");
963 MFI_COMMAND(top, add, add_spare);
966 remove_spare(int ac, char **av)
968 struct mfi_pd_info info;
974 warnx("remove spare: drive required");
978 fd = mfi_open(mfi_unit);
985 error = mfi_lookup_drive(fd, av[1], &device_id);
989 /* Get the info for this drive. */
990 if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) {
992 warn("Failed to fetch info for drive %u", device_id);
996 if (info.fw_state != MFI_PD_STATE_HOT_SPARE) {
997 warnx("Drive %u is not a hot spare", device_id);
1001 mbox_store_pdref(mbox, &info.ref);
1002 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_REMOVE_SPARE, NULL, 0, mbox,
1003 sizeof(mbox), NULL) < 0) {
1005 warn("Failed to delete spare");
1013 MFI_COMMAND(top, remove, remove_spare);
1016 /* Display raw data about a config. */
1018 dump_config(int fd, struct mfi_config_data *config)
1020 struct mfi_array *ar;
1021 struct mfi_ld_config *ld;
1022 struct mfi_spare *sp;
1023 struct mfi_pd_info pinfo;
1029 "mfi%d Configuration (Debug): %d arrays, %d volumes, %d spares\n",
1030 mfi_unit, config->array_count, config->log_drv_count,
1031 config->spares_count);
1032 printf(" array size: %u\n", config->array_size);
1033 printf(" volume size: %u\n", config->log_drv_size);
1034 printf(" spare size: %u\n", config->spares_size);
1035 p = (char *)config->array;
1037 for (i = 0; i < config->array_count; i++) {
1038 ar = (struct mfi_array *)p;
1039 printf(" array %u of %u drives:\n", ar->array_ref,
1041 printf(" size = %ju\n", (uintmax_t)ar->size);
1042 for (j = 0; j < ar->num_drives; j++) {
1043 device_id = ar->pd[j].ref.v.device_id;
1044 if (device_id == 0xffff)
1045 printf(" drive MISSING\n");
1047 printf(" drive %u %s\n", device_id,
1048 mfi_pdstate(ar->pd[j].fw_state));
1049 if (mfi_pd_get_info(fd, device_id, &pinfo,
1051 printf(" raw size: %ju\n",
1052 (uintmax_t)pinfo.raw_size);
1053 printf(" non-coerced size: %ju\n",
1054 (uintmax_t)pinfo.non_coerced_size);
1055 printf(" coerced size: %ju\n",
1056 (uintmax_t)pinfo.coerced_size);
1060 p += config->array_size;
1063 for (i = 0; i < config->log_drv_count; i++) {
1064 ld = (struct mfi_ld_config *)p;
1065 printf(" volume %s ",
1066 mfi_volume_name(fd, ld->properties.ld.v.target_id));
1068 mfi_raid_level(ld->params.primary_raid_level,
1069 ld->params.secondary_raid_level),
1070 mfi_ldstate(ld->params.state));
1071 if (ld->properties.name[0] != '\0')
1072 printf(" <%s>", ld->properties.name);
1074 printf(" primary raid level: %u\n",
1075 ld->params.primary_raid_level);
1076 printf(" raid level qualifier: %u\n",
1077 ld->params.raid_level_qualifier);
1078 printf(" secondary raid level: %u\n",
1079 ld->params.secondary_raid_level);
1080 printf(" stripe size: %u\n", ld->params.stripe_size);
1081 printf(" num drives: %u\n", ld->params.num_drives);
1082 printf(" init state: %u\n", ld->params.init_state);
1083 printf(" consistent: %u\n", ld->params.is_consistent);
1084 printf(" no bgi: %u\n", ld->properties.no_bgi);
1085 printf(" spans:\n");
1086 for (j = 0; j < ld->params.span_depth; j++) {
1087 printf(" array %u @ ", ld->span[j].array_ref);
1088 printf("%ju : %ju\n",
1089 (uintmax_t)ld->span[j].start_block,
1090 (uintmax_t)ld->span[j].num_blocks);
1092 p += config->log_drv_size;
1095 for (i = 0; i < config->spares_count; i++) {
1096 sp = (struct mfi_spare *)p;
1097 printf(" %s spare %u ",
1098 sp->spare_type & MFI_SPARE_DEDICATED ? "dedicated" :
1099 "global", sp->ref.v.device_id);
1100 printf("%s", mfi_pdstate(MFI_PD_STATE_HOT_SPARE));
1101 printf(" backs:\n");
1102 for (j = 0; j < sp->array_count; j++)
1103 printf(" array %u\n", sp->array_ref[j]);
1104 p += config->spares_size;
1109 debug_config(int ac, char **av)
1111 struct mfi_config_data *config;
1115 warnx("debug: extra arguments");
1119 fd = mfi_open(mfi_unit);
1126 /* Get the config from the controller. */
1127 if (mfi_config_read(fd, &config) < 0) {
1129 warn("Failed to get config");
1133 /* Dump out the configuration. */
1134 dump_config(fd, config);
1140 MFI_COMMAND(top, debug, debug_config);
1143 dump(int ac, char **av)
1145 struct mfi_config_data *config;
1151 warnx("dump: extra arguments");
1155 fd = mfi_open(mfi_unit);
1162 /* Get the stashed copy of the last dcmd from the driver. */
1163 snprintf(buf, sizeof(buf), "dev.mfi.%d.debug_command", mfi_unit);
1164 if (sysctlbyname(buf, NULL, &len, NULL, 0) < 0) {
1166 warn("Failed to read debug command");
1167 if (error == ENOENT)
1172 config = malloc(len);
1173 if (sysctlbyname(buf, config, &len, NULL, 0) < 0) {
1175 warn("Failed to read debug command");
1178 dump_config(fd, config);
1184 MFI_COMMAND(top, dump, dump);