2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2008, 2009 Yahoo!, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The names of the authors may not be used to endorse or promote
16 * products derived from this software without specific prior written
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/param.h>
34 #include <sys/sysctl.h>
48 static int add_spare(int ac, char **av);
49 static int remove_spare(int ac, char **av);
52 dehumanize(const char *value)
59 iv = strtoq(value, &vtp, 0);
60 if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
81 mfi_config_read(int fd, struct mfi_config_data **configp)
83 return mfi_config_read_opcode(fd, MFI_DCMD_CFG_READ, configp, NULL, 0);
87 mfi_config_read_opcode(int fd, uint32_t opcode, struct mfi_config_data **configp,
88 uint8_t *mbox, size_t mboxlen)
90 struct mfi_config_data *config;
95 * Keep fetching the config in a loop until we have a large enough
96 * buffer to hold the entire configuration.
101 config = reallocf(config, config_size);
104 if (mfi_dcmd_command(fd, opcode, config,
105 config_size, mbox, mboxlen, NULL) < 0) {
112 if (config->size > config_size) {
113 config_size = config->size;
121 static struct mfi_array *
122 mfi_config_lookup_array(struct mfi_config_data *config, uint16_t array_ref)
124 struct mfi_array *ar;
128 p = (char *)config->array;
129 for (i = 0; i < config->array_count; i++) {
130 ar = (struct mfi_array *)p;
131 if (ar->array_ref == array_ref)
133 p += config->array_size;
139 static struct mfi_ld_config *
140 mfi_config_lookup_volume(struct mfi_config_data *config, uint8_t target_id)
142 struct mfi_ld_config *ld;
146 p = (char *)config->array + config->array_count * config->array_size;
147 for (i = 0; i < config->log_drv_count; i++) {
148 ld = (struct mfi_ld_config *)p;
149 if (ld->properties.ld.v.target_id == target_id)
151 p += config->log_drv_size;
158 clear_config(int ac __unused, char **av __unused)
160 struct mfi_ld_list list;
164 fd = mfi_open(mfi_device, O_RDWR);
171 if (!mfi_reconfig_supported(mfi_device)) {
172 warnx("The current %s driver does not support "
173 "configuration changes.", mfi_device);
178 if (mfi_ld_get_list(fd, &list, NULL) < 0) {
180 warn("Failed to get volume list");
185 for (i = 0; i < list.ld_count; i++) {
186 if (mfi_volume_busy(fd, list.ld_list[i].ld.v.target_id)) {
187 warnx("Volume %s is busy and cannot be deleted",
188 mfi_volume_name(fd, list.ld_list[i].ld.v.target_id));
195 "Are you sure you wish to clear the configuration on %s? [y/N] ",
198 if (ch != 'y' && ch != 'Y') {
199 printf("\nAborting\n");
204 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_CLEAR, NULL, 0, NULL, 0, NULL) < 0) {
206 warn("Failed to clear configuration");
211 printf("%s: Configuration cleared\n", mfi_device);
216 MFI_COMMAND(top, clear, clear_config);
218 #define MAX_DRIVES_PER_ARRAY MFI_MAX_ROW_SIZE
219 #define MFI_ARRAY_SIZE sizeof(struct mfi_array)
232 compare_int(const void *one, const void *two)
236 first = *(const int *)one;
237 second = *(const int *)two;
239 return (first - second);
242 static struct raid_type_entry {
245 } raid_type_table[] = {
246 { "raid0", RT_RAID0 },
247 { "raid-0", RT_RAID0 },
248 { "raid1", RT_RAID1 },
249 { "raid-1", RT_RAID1 },
250 { "mirror", RT_RAID1 },
251 { "raid5", RT_RAID5 },
252 { "raid-5", RT_RAID5 },
253 { "raid6", RT_RAID6 },
254 { "raid-6", RT_RAID6 },
256 { "concat", RT_CONCAT },
257 { "raid10", RT_RAID10 },
258 { "raid1+0", RT_RAID10 },
259 { "raid-10", RT_RAID10 },
260 { "raid-1+0", RT_RAID10 },
261 { "raid50", RT_RAID50 },
262 { "raid5+0", RT_RAID50 },
263 { "raid-50", RT_RAID50 },
264 { "raid-5+0", RT_RAID50 },
265 { "raid60", RT_RAID60 },
266 { "raid6+0", RT_RAID60 },
267 { "raid-60", RT_RAID60 },
268 { "raid-6+0", RT_RAID60 },
272 struct config_id_state {
283 struct mfi_pd_info *drives;
284 struct mfi_array *array;
287 /* Parse a comma-separated list of drives for an array. */
289 parse_array(int fd, int raid_type, char *array_str, struct array_info *info)
291 struct mfi_pd_info *pinfo;
298 for (count = 0; cp != NULL; count++) {
299 cp = strchr(cp, ',');
303 warnx("Invalid drive list '%s'", array_str);
309 /* Validate the number of drives for this array. */
310 if (count >= MAX_DRIVES_PER_ARRAY) {
311 warnx("Too many drives for a single array: max is %d",
312 MAX_DRIVES_PER_ARRAY);
318 if (count % 2 != 0) {
319 warnx("RAID1 and RAID10 require an even number of "
320 "drives in each array");
327 warnx("RAID5 and RAID50 require at least 3 drives in "
335 warnx("RAID6 and RAID60 require at least 4 drives in "
342 /* Validate each drive. */
343 info->drives = calloc(count, sizeof(struct mfi_pd_info));
344 if (info->drives == NULL) {
345 warnx("malloc failed");
348 info->drive_count = count;
349 for (pinfo = info->drives; (cp = strsep(&array_str, ",")) != NULL;
351 error = mfi_lookup_drive(fd, cp, &device_id);
358 if (mfi_pd_get_info(fd, device_id, pinfo, NULL) < 0) {
360 warn("Failed to fetch drive info for drive %s", cp);
366 if (pinfo->fw_state != MFI_PD_STATE_UNCONFIGURED_GOOD) {
367 warnx("Drive %u is not available", device_id);
373 if (pinfo->state.ddf.v.pd_type.is_foreign) {
374 warnx("Drive %u is foreign", device_id);
385 * Find the next free array ref assuming that 'array_ref' is the last
386 * one used. 'array_ref' should be 0xffff for the initial test.
389 find_next_array(struct config_id_state *state)
393 /* Assume the current one is used. */
396 /* Find the next free one. */
397 for (i = 0; i < state->array_count; i++)
398 if (state->arrays[i] == state->array_ref)
400 return (state->array_ref);
404 * Find the next free volume ID assuming that 'target_id' is the last
405 * one used. 'target_id' should be 0xff for the initial test.
408 find_next_volume(struct config_id_state *state)
412 /* Assume the current one is used. */
415 /* Find the next free one. */
416 for (i = 0; i < state->log_drv_count; i++)
417 if (state->volumes[i] == state->target_id)
419 return (state->target_id);
422 /* Populate an array with drives. */
424 build_array(int fd __unused, char *arrayp, struct array_info *array_info,
425 struct config_id_state *state, int verbose)
427 struct mfi_array *ar = (struct mfi_array *)arrayp;
430 ar->size = array_info->drives[0].coerced_size;
431 ar->num_drives = array_info->drive_count;
432 ar->array_ref = find_next_array(state);
433 for (i = 0; i < array_info->drive_count; i++) {
435 printf("Adding drive %s to array %u\n",
437 array_info->drives[i].ref.v.device_id,
438 MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS),
440 if (ar->size > array_info->drives[i].coerced_size)
441 ar->size = array_info->drives[i].coerced_size;
442 ar->pd[i].ref = array_info->drives[i].ref;
443 ar->pd[i].fw_state = MFI_PD_STATE_ONLINE;
445 array_info->array = ar;
449 * Create a volume that spans one or more arrays.
452 build_volume(char *volumep, int narrays, struct array_info *arrays,
453 int raid_type, long stripe_size, struct config_id_state *state, int verbose)
455 struct mfi_ld_config *ld = (struct mfi_ld_config *)volumep;
456 struct mfi_array *ar;
460 ld->properties.ld.v.target_id = find_next_volume(state);
461 ld->properties.ld.v.seq = 0;
462 ld->properties.default_cache_policy = MR_LD_CACHE_ALLOW_WRITE_CACHE |
463 MR_LD_CACHE_WRITE_BACK;
464 ld->properties.access_policy = MFI_LD_ACCESS_RW;
465 ld->properties.disk_cache_policy = MR_PD_CACHE_UNCHANGED;
466 ld->properties.current_cache_policy = MR_LD_CACHE_ALLOW_WRITE_CACHE |
467 MR_LD_CACHE_WRITE_BACK;
468 ld->properties.no_bgi = 0;
474 ld->params.primary_raid_level = DDF_RAID0;
475 ld->params.raid_level_qualifier = 0;
476 ld->params.secondary_raid_level = 0;
479 ld->params.primary_raid_level = DDF_RAID1;
480 ld->params.raid_level_qualifier = 0;
481 ld->params.secondary_raid_level = 0;
484 ld->params.primary_raid_level = DDF_RAID5;
485 ld->params.raid_level_qualifier = 3;
486 ld->params.secondary_raid_level = 0;
489 ld->params.primary_raid_level = DDF_RAID6;
490 ld->params.raid_level_qualifier = 3;
491 ld->params.secondary_raid_level = 0;
494 ld->params.primary_raid_level = DDF_CONCAT;
495 ld->params.raid_level_qualifier = 0;
496 ld->params.secondary_raid_level = 0;
499 ld->params.primary_raid_level = DDF_RAID1;
500 ld->params.raid_level_qualifier = 0;
501 ld->params.secondary_raid_level = 3; /* XXX? */
505 * XXX: This appears to work though the card's BIOS
506 * complains that the configuration is foreign. The
507 * BIOS setup does not allow for creation of RAID-50
508 * or RAID-60 arrays. The only nested array
509 * configuration it allows for is RAID-10.
511 ld->params.primary_raid_level = DDF_RAID5;
512 ld->params.raid_level_qualifier = 3;
513 ld->params.secondary_raid_level = 3; /* XXX? */
516 ld->params.primary_raid_level = DDF_RAID6;
517 ld->params.raid_level_qualifier = 3;
518 ld->params.secondary_raid_level = 3; /* XXX? */
523 * Stripe size is encoded as (2 ^ N) * 512 = stripe_size. Use
524 * ffs() to simulate log2(stripe_size).
526 ld->params.stripe_size = ffs(stripe_size) - 1 - 9;
527 ld->params.num_drives = arrays[0].array->num_drives;
528 ld->params.span_depth = narrays;
529 ld->params.state = MFI_LD_STATE_OPTIMAL;
530 ld->params.init_state = MFI_LD_PARAMS_INIT_NO;
531 ld->params.is_consistent = 0;
534 for (i = 0; i < narrays; i++) {
535 ar = arrays[i].array;
537 printf("Adding array %u to volume %u\n", ar->array_ref,
538 ld->properties.ld.v.target_id);
539 ld->span[i].start_block = 0;
540 ld->span[i].num_blocks = ar->size;
541 ld->span[i].array_ref = ar->array_ref;
546 create_volume(int ac, char **av)
548 struct mfi_config_data *config;
549 struct mfi_array *ar;
550 struct mfi_ld_config *ld;
551 struct config_id_state state;
553 char *p, *cfg_arrays, *cfg_volumes;
554 int error, fd, i, raid_type;
555 int narrays, nvolumes, arrays_per_volume;
556 struct array_info *arrays;
564 * Backwards compat. Map 'create volume' to 'create' and
565 * 'create spare' to 'add'.
568 if (strcmp(av[1], "volume") == 0) {
571 } else if (strcmp(av[1], "spare") == 0) {
574 return (add_spare(ac, av));
579 warnx("create volume: volume type required");
583 bzero(&state, sizeof(state));
589 fd = mfi_open(mfi_device, O_RDWR);
596 if (!mfi_reconfig_supported(mfi_device)) {
597 warnx("The current %s(4) driver does not support "
598 "configuration changes.", mfi_device);
603 /* Lookup the RAID type first. */
605 for (i = 0; raid_type_table[i].name != NULL; i++)
606 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
607 raid_type = raid_type_table[i].raid_type;
611 if (raid_type == -1) {
612 warnx("Unknown or unsupported volume type %s", av[1]);
617 /* Parse any options. */
623 stripe_size = 64 * 1024;
625 while ((ch = getopt(ac, av, "ds:v")) != -1) {
633 stripe_size = dehumanize(optarg);
634 if ((stripe_size < 512) || (!powerof2(stripe_size)))
635 stripe_size = 64 * 1024;
649 /* Parse all the arrays. */
652 warnx("At least one drive list is required");
663 warnx("Only one drive list can be specified");
672 warnx("RAID10, RAID50, and RAID60 require at least "
677 if (narrays > MFI_MAX_SPAN_DEPTH) {
678 warnx("Volume spans more than %d arrays",
685 arrays = calloc(narrays, sizeof(*arrays));
686 if (arrays == NULL) {
687 warnx("malloc failed");
691 for (i = 0; i < narrays; i++) {
692 error = parse_array(fd, raid_type, av[i], &arrays[i]);
701 for (i = 1; i < narrays; i++) {
702 if (arrays[i].drive_count != arrays[0].drive_count) {
703 warnx("All arrays must contain the same "
713 * Fetch the current config and build sorted lists of existing
714 * array and volume identifiers.
716 if (mfi_config_read(fd, &config) < 0) {
718 warn("Failed to read configuration");
721 p = (char *)config->array;
722 state.array_ref = 0xffff;
723 state.target_id = 0xff;
724 state.array_count = config->array_count;
725 if (config->array_count > 0) {
726 state.arrays = calloc(config->array_count, sizeof(int));
727 if (state.arrays == NULL) {
728 warnx("malloc failed");
732 for (i = 0; i < config->array_count; i++) {
733 ar = (struct mfi_array *)p;
734 state.arrays[i] = ar->array_ref;
735 p += config->array_size;
737 qsort(state.arrays, config->array_count, sizeof(int),
741 state.log_drv_count = config->log_drv_count;
742 if (config->log_drv_count) {
743 state.volumes = calloc(config->log_drv_count, sizeof(int));
744 if (state.volumes == NULL) {
745 warnx("malloc failed");
749 for (i = 0; i < config->log_drv_count; i++) {
750 ld = (struct mfi_ld_config *)p;
751 state.volumes[i] = ld->properties.ld.v.target_id;
752 p += config->log_drv_size;
754 qsort(state.volumes, config->log_drv_count, sizeof(int),
757 state.volumes = NULL;
760 /* Determine the size of the configuration we will build. */
768 /* Each volume spans a single array. */
774 /* A single volume spans multiple arrays. */
782 config_size = sizeof(struct mfi_config_data) +
783 sizeof(struct mfi_ld_config) * nvolumes + MFI_ARRAY_SIZE * narrays;
784 config = calloc(1, config_size);
785 if (config == NULL) {
786 warnx("malloc failed");
790 config->size = config_size;
791 config->array_count = narrays;
792 config->array_size = MFI_ARRAY_SIZE; /* XXX: Firmware hardcode */
793 config->log_drv_count = nvolumes;
794 config->log_drv_size = sizeof(struct mfi_ld_config);
795 config->spares_count = 0;
796 config->spares_size = 40; /* XXX: Firmware hardcode */
797 cfg_arrays = (char *)config->array;
798 cfg_volumes = cfg_arrays + config->array_size * narrays;
800 /* Build the arrays. */
801 for (i = 0; i < narrays; i++) {
802 build_array(fd, cfg_arrays, &arrays[i], &state, verbose);
803 cfg_arrays += config->array_size;
806 /* Now build the volume(s). */
807 arrays_per_volume = narrays / nvolumes;
808 for (i = 0; i < nvolumes; i++) {
809 build_volume(cfg_volumes, arrays_per_volume,
810 &arrays[i * arrays_per_volume], raid_type, stripe_size,
812 cfg_volumes += config->log_drv_size;
817 dump_config(fd, config, NULL);
820 /* Send the new config to the controller. */
821 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_ADD, config, config_size,
822 NULL, 0, NULL) < 0) {
824 warn("Failed to add volume");
833 if (arrays != NULL) {
834 for (i = 0; i < narrays; i++)
835 free(arrays[i].drives);
842 MFI_COMMAND(top, create, create_volume);
845 delete_volume(int ac, char **av)
847 struct mfi_ld_info info;
849 uint8_t target_id, mbox[4];
852 * Backwards compat. Map 'delete volume' to 'delete' and
853 * 'delete spare' to 'remove'.
856 if (strcmp(av[1], "volume") == 0) {
859 } else if (strcmp(av[1], "spare") == 0) {
862 return (remove_spare(ac, av));
867 warnx("delete volume: volume required");
871 fd = mfi_open(mfi_device, O_RDWR);
878 if (!mfi_reconfig_supported(mfi_device)) {
879 warnx("The current %s(4) driver does not support "
880 "configuration changes.", mfi_device);
885 if (mfi_lookup_volume(fd, av[1], &target_id) < 0) {
887 warn("Invalid volume %s", av[1]);
892 if (mfi_ld_get_info(fd, target_id, &info, NULL) < 0) {
894 warn("Failed to get info for volume %d", target_id);
899 if (mfi_volume_busy(fd, target_id)) {
900 warnx("Volume %s is busy and cannot be deleted",
901 mfi_volume_name(fd, target_id));
906 mbox_store_ldref(mbox, &info.ld_config.properties.ld);
907 if (mfi_dcmd_command(fd, MFI_DCMD_LD_DELETE, NULL, 0, mbox,
908 sizeof(mbox), NULL) < 0) {
910 warn("Failed to delete volume");
919 MFI_COMMAND(top, delete, delete_volume);
922 add_spare(int ac, char **av)
924 struct mfi_pd_info info;
925 struct mfi_config_data *config;
926 struct mfi_array *ar;
927 struct mfi_ld_config *ld;
928 struct mfi_spare *spare;
935 warnx("add spare: drive required");
939 fd = mfi_open(mfi_device, O_RDWR);
948 error = mfi_lookup_drive(fd, av[1], &device_id);
952 if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) {
954 warn("Failed to fetch drive info");
958 if (info.fw_state != MFI_PD_STATE_UNCONFIGURED_GOOD) {
959 warnx("Drive %u is not available", device_id);
965 if (mfi_lookup_volume(fd, av[2], &target_id) < 0) {
967 warn("Invalid volume %s", av[2]);
972 if (mfi_config_read(fd, &config) < 0) {
974 warn("Failed to read configuration");
978 spare = malloc(sizeof(struct mfi_spare) + sizeof(uint16_t) *
979 config->array_count);
981 warnx("malloc failed");
985 bzero(spare, sizeof(struct mfi_spare));
986 spare->ref = info.ref;
989 /* Global spare backs all arrays. */
990 p = (char *)config->array;
991 for (i = 0; i < config->array_count; i++) {
992 ar = (struct mfi_array *)p;
993 if (ar->size > info.coerced_size) {
994 warnx("Spare isn't large enough for array %u",
999 p += config->array_size;
1001 spare->array_count = 0;
1004 * Dedicated spares only back the arrays for a
1007 ld = mfi_config_lookup_volume(config, target_id);
1009 warnx("Did not find volume %d", target_id);
1014 spare->spare_type |= MFI_SPARE_DEDICATED;
1015 spare->array_count = ld->params.span_depth;
1016 for (i = 0; i < ld->params.span_depth; i++) {
1017 ar = mfi_config_lookup_array(config,
1018 ld->span[i].array_ref);
1020 warnx("Missing array; inconsistent config?");
1024 if (ar->size > info.coerced_size) {
1025 warnx("Spare isn't large enough for array %u",
1030 spare->array_ref[i] = ar->array_ref;
1034 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_MAKE_SPARE, spare,
1035 sizeof(struct mfi_spare) + sizeof(uint16_t) * spare->array_count,
1036 NULL, 0, NULL) < 0) {
1038 warn("Failed to assign spare");
1049 MFI_COMMAND(top, add, add_spare);
1052 remove_spare(int ac, char **av)
1054 struct mfi_pd_info info;
1060 warnx("remove spare: drive required");
1064 fd = mfi_open(mfi_device, O_RDWR);
1071 error = mfi_lookup_drive(fd, av[1], &device_id);
1077 /* Get the info for this drive. */
1078 if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) {
1080 warn("Failed to fetch info for drive %u", device_id);
1085 if (info.fw_state != MFI_PD_STATE_HOT_SPARE) {
1086 warnx("Drive %u is not a hot spare", device_id);
1091 mbox_store_pdref(mbox, &info.ref);
1092 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_REMOVE_SPARE, NULL, 0, mbox,
1093 sizeof(mbox), NULL) < 0) {
1095 warn("Failed to delete spare");
1104 MFI_COMMAND(top, remove, remove_spare);
1106 /* Display raw data about a config. */
1108 dump_config(int fd, struct mfi_config_data *config, const char *msg_prefix)
1110 struct mfi_array *ar;
1111 struct mfi_ld_config *ld;
1112 struct mfi_spare *sp;
1113 struct mfi_pd_info pinfo;
1118 if (NULL == msg_prefix)
1119 msg_prefix = "Configuration (Debug)";
1122 "%s %s: %d arrays, %d volumes, %d spares\n", mfi_device,
1123 msg_prefix, config->array_count, config->log_drv_count,
1124 config->spares_count);
1125 printf(" array size: %u\n", config->array_size);
1126 printf(" volume size: %u\n", config->log_drv_size);
1127 printf(" spare size: %u\n", config->spares_size);
1128 p = (char *)config->array;
1130 for (i = 0; i < config->array_count; i++) {
1131 ar = (struct mfi_array *)p;
1132 printf(" array %u of %u drives:\n", ar->array_ref,
1134 printf(" size = %ju\n", (uintmax_t)ar->size);
1135 for (j = 0; j < ar->num_drives; j++) {
1136 device_id = ar->pd[j].ref.v.device_id;
1137 if (device_id == 0xffff)
1138 printf(" drive MISSING\n");
1140 printf(" drive %u %s\n", device_id,
1141 mfi_pdstate(ar->pd[j].fw_state));
1142 if (mfi_pd_get_info(fd, device_id, &pinfo,
1144 printf(" raw size: %ju\n",
1145 (uintmax_t)pinfo.raw_size);
1146 printf(" non-coerced size: %ju\n",
1147 (uintmax_t)pinfo.non_coerced_size);
1148 printf(" coerced size: %ju\n",
1149 (uintmax_t)pinfo.coerced_size);
1153 p += config->array_size;
1156 for (i = 0; i < config->log_drv_count; i++) {
1157 ld = (struct mfi_ld_config *)p;
1158 printf(" volume %s ",
1159 mfi_volume_name(fd, ld->properties.ld.v.target_id));
1161 mfi_raid_level(ld->params.primary_raid_level,
1162 ld->params.secondary_raid_level),
1163 mfi_ldstate(ld->params.state));
1164 if (ld->properties.name[0] != '\0')
1165 printf(" <%s>", ld->properties.name);
1167 printf(" primary raid level: %u\n",
1168 ld->params.primary_raid_level);
1169 printf(" raid level qualifier: %u\n",
1170 ld->params.raid_level_qualifier);
1171 printf(" secondary raid level: %u\n",
1172 ld->params.secondary_raid_level);
1173 printf(" stripe size: %u\n", ld->params.stripe_size);
1174 printf(" num drives: %u\n", ld->params.num_drives);
1175 printf(" init state: %u\n", ld->params.init_state);
1176 printf(" consistent: %u\n", ld->params.is_consistent);
1177 printf(" no bgi: %u\n", ld->properties.no_bgi);
1178 printf(" spans:\n");
1179 for (j = 0; j < ld->params.span_depth; j++) {
1180 printf(" array %u @ ", ld->span[j].array_ref);
1181 printf("%ju : %ju\n",
1182 (uintmax_t)ld->span[j].start_block,
1183 (uintmax_t)ld->span[j].num_blocks);
1185 p += config->log_drv_size;
1188 for (i = 0; i < config->spares_count; i++) {
1189 sp = (struct mfi_spare *)p;
1190 printf(" %s spare %u ",
1191 sp->spare_type & MFI_SPARE_DEDICATED ? "dedicated" :
1192 "global", sp->ref.v.device_id);
1193 printf("%s", mfi_pdstate(MFI_PD_STATE_HOT_SPARE));
1194 printf(" backs:\n");
1195 for (j = 0; j < sp->array_count; j++)
1196 printf(" array %u\n", sp->array_ref[j]);
1197 p += config->spares_size;
1203 debug_config(int ac, char **av)
1205 struct mfi_config_data *config;
1209 warnx("debug: extra arguments");
1213 fd = mfi_open(mfi_device, O_RDWR);
1220 /* Get the config from the controller. */
1221 if (mfi_config_read(fd, &config) < 0) {
1223 warn("Failed to get config");
1228 /* Dump out the configuration. */
1229 dump_config(fd, config, NULL);
1235 MFI_COMMAND(top, debug, debug_config);
1238 dump(int ac, char **av)
1240 struct mfi_config_data *config;
1246 warnx("dump: extra arguments");
1250 fd = mfi_open(mfi_device, O_RDWR);
1257 /* Get the stashed copy of the last dcmd from the driver. */
1258 snprintf(buf, sizeof(buf), "dev.mfi.%d.debug_command", mfi_unit);
1259 if (sysctlbyname(buf, NULL, &len, NULL, 0) < 0) {
1261 warn("Failed to read debug command");
1262 if (error == ENOENT)
1268 config = malloc(len);
1269 if (config == NULL) {
1270 warnx("malloc failed");
1274 if (sysctlbyname(buf, config, &len, NULL, 0) < 0) {
1276 warn("Failed to read debug command");
1281 dump_config(fd, config, NULL);
1287 MFI_COMMAND(top, dump, dump);