2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2008 Yahoo!, Inc.
6 * Written by: John Baldwin <jhb@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
36 #include <sys/param.h>
37 #include <sys/errno.h>
52 static void dump_config(CONFIG_PAGE_RAID_VOL_0 *vol);
56 dehumanize(const char *value)
63 iv = strtoq(value, &vtp, 0);
64 if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
89 * Lock the volume by opening its /dev device read/write. This will
90 * only work if nothing else has it opened (including mounts). We
91 * leak the fd on purpose since this application is not long-running.
94 mpt_lock_volume(U8 VolumeBus, U8 VolumeID)
96 char path[MAXPATHLEN];
97 struct mpt_query_disk qd;
100 error = mpt_query_disk(VolumeBus, VolumeID, &qd);
103 * This means there isn't a CAM device associated with
104 * the volume, and thus it is already implicitly
105 * locked, so just return.
109 warnc(error, "Unable to lookup volume device name");
112 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, qd.devname);
113 vfd = open(path, O_RDWR);
116 warn("Unable to lock volume %s", qd.devname);
123 mpt_lock_physdisk(struct mpt_standalone_disk *disk)
125 char path[MAXPATHLEN];
128 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk->devname);
129 dfd = open(path, O_RDWR);
132 warn("Unable to lock disk %s", disk->devname);
139 mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks,
140 int ndisks, int *index)
146 /* Check for a raw <bus>:<id> string. */
147 bus = strtol(name, &cp, 0);
149 id = strtol(cp + 1, &cp, 0);
151 if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) {
154 for (i = 0; i < ndisks; i++) {
155 if (disks[i].bus == (U8)bus &&
156 disks[i].target == (U8)id) {
165 if (name[0] == 'd' && name[1] == 'a') {
166 for (i = 0; i < ndisks; i++) {
167 if (strcmp(name, disks[i].devname) == 0) {
179 * Mark a standalone disk as being a physical disk.
182 mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum)
184 CONFIG_PAGE_HEADER header;
185 CONFIG_PAGE_RAID_PHYS_DISK_0 *config_page;
189 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK,
190 0, 0, &header, NULL);
193 if (header.PageVersion > MPI_RAIDPHYSDISKPAGE0_PAGEVERSION) {
194 warnx("Unsupported RAID physdisk page 0 version %d",
198 config_page = calloc(1, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0));
199 config_page->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
200 config_page->Header.PageNumber = 0;
201 config_page->Header.PageLength = sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0) /
203 config_page->PhysDiskIOC = 0; /* XXX */
204 config_page->PhysDiskBus = disk->bus;
205 config_page->PhysDiskID = disk->target;
207 /* XXX: Enclosure info for PhysDiskSettings? */
208 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0,
209 config_page, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0), NULL,
210 &ActionData, sizeof(ActionData), NULL, NULL, 1);
213 *PhysDiskNum = ActionData & 0xff;
218 mpt_delete_physdisk(int fd, U8 PhysDiskNum)
221 return (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_PHYSDISK, 0, 0,
222 PhysDiskNum, 0, NULL, 0, NULL, NULL, 0, NULL, NULL, 0));
226 * MPT's firmware does not have a clear command. Instead, we
227 * implement it by deleting each array and disk by hand.
230 clear_config(int ac, char **av)
232 CONFIG_PAGE_IOC_2 *ioc2;
233 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
234 CONFIG_PAGE_IOC_3 *ioc3;
235 IOC_3_PHYS_DISK *disk;
236 CONFIG_PAGE_IOC_5 *ioc5;
237 IOC_5_HOT_SPARE *spare;
238 int ch, error, fd, i;
240 fd = mpt_open(mpt_unit);
247 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
250 warn("Failed to fetch volume list");
255 /* Lock all the volumes first. */
256 vol = ioc2->RaidVolume;
257 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
258 if (mpt_lock_volume(vol->VolumeBus, vol->VolumeID) < 0) {
259 warnx("Volume %s is busy and cannot be deleted",
260 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
268 "Are you sure you wish to clear the configuration on mpt%u? [y/N] ",
271 if (ch != 'y' && ch != 'Y') {
272 printf("\nAborting\n");
278 /* Delete all the volumes. */
279 vol = ioc2->RaidVolume;
280 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
281 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME,
282 vol->VolumeBus, vol->VolumeID, 0,
283 MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
284 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0,
287 warnc(error, "Failed to delete volume %s",
288 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
292 /* Delete all the spares. */
293 ioc5 = mpt_read_ioc_page(fd, 5, NULL);
295 warn("Failed to fetch spare list");
297 spare = ioc5->HotSpare;
298 for (i = 0; i < ioc5->NumHotSpares; spare++, i++)
299 if (mpt_delete_physdisk(fd, spare->PhysDiskNum) < 0)
300 warn("Failed to delete physical disk %d",
305 /* Delete any RAID physdisks that may be left. */
306 ioc3 = mpt_read_ioc_page(fd, 3, NULL);
308 warn("Failed to fetch drive list");
310 disk = ioc3->PhysDisk;
311 for (i = 0; i < ioc3->NumPhysDisks; disk++, i++)
312 if (mpt_delete_physdisk(fd, disk->PhysDiskNum) < 0)
313 warn("Failed to delete physical disk %d",
318 printf("mpt%d: Configuration cleared\n", mpt_unit);
319 mpt_rescan_bus(-1, -1);
324 MPT_COMMAND(top, clear, clear_config);
330 static struct raid_type_entry {
333 } raid_type_table[] = {
334 { "raid0", RT_RAID0 },
335 { "raid-0", RT_RAID0 },
336 { "raid1", RT_RAID1 },
337 { "raid-1", RT_RAID1 },
338 { "mirror", RT_RAID1 },
339 { "raid1e", RT_RAID1E },
340 { "raid-1e", RT_RAID1E },
344 struct config_id_state {
345 struct mpt_standalone_disk *sdisks;
346 struct mpt_drive_list *list;
347 CONFIG_PAGE_IOC_2 *ioc2;
353 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
354 struct mpt_standalone_disk *sdisk;
359 struct drive_info *drives;
362 /* Parse a comma-separated list of drives for a volume. */
364 parse_volume(int fd, int raid_type, struct config_id_state *state,
365 char *volume_str, struct volume_info *info)
367 struct drive_info *dinfo;
373 for (count = 0; cp != NULL; count++) {
374 cp = strchr(cp, ',');
378 warnx("Invalid drive list '%s'", volume_str);
384 /* Validate the number of drives for this volume. */
388 warnx("RAID0 requires at least 2 drives in each "
395 warnx("RAID1 requires exactly 2 drives in each "
402 warnx("RAID1E requires at least 3 drives in each "
409 /* Validate each drive. */
410 info->drives = calloc(count, sizeof(struct drive_info));
411 info->drive_count = count;
412 for (dinfo = info->drives; (cp = strsep(&volume_str, ",")) != NULL;
414 /* If this drive is already a RAID phys just fetch the info. */
415 error = mpt_lookup_drive(state->list, cp, &PhysDiskNum);
417 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
418 if (dinfo->info == NULL)
423 /* See if it is a standalone disk. */
424 if (mpt_lookup_standalone_disk(cp, state->sdisks,
425 state->nsdisks, &i) < 0) {
427 warn("Unable to lookup drive %s", cp);
430 dinfo->sdisk = &state->sdisks[i];
432 /* Lock the disk, we will create phys disk pages later. */
433 if (mpt_lock_physdisk(dinfo->sdisk) < 0)
441 * Add RAID physdisk pages for any standalone disks that a volume is
445 add_drives(int fd, struct volume_info *info, int verbose)
447 struct drive_info *dinfo;
451 for (i = 0, dinfo = info->drives; i < info->drive_count;
453 if (dinfo->info == NULL) {
454 if (mpt_create_physdisk(fd, dinfo->sdisk,
458 "Failed to create physical disk page for %s",
459 dinfo->sdisk->devname);
463 printf("Added drive %s with PhysDiskNum %u\n",
464 dinfo->sdisk->devname, PhysDiskNum);
466 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
467 if (dinfo->info == NULL)
475 * Find the next free target ID assuming that 'target_id' is the last
476 * one used. 'target_id' should be 0xff for the initial test.
479 find_next_volume(struct config_id_state *state)
481 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
485 /* Assume the current one is used. */
488 /* Search drives first. */
489 for (i = 0; i < state->nsdisks; i++)
490 if (state->sdisks[i].target == state->target_id)
492 for (i = 0; i < state->list->ndrives; i++)
493 if (state->list->drives[i]->PhysDiskID == state->target_id)
496 /* Search volumes second. */
497 vol = state->ioc2->RaidVolume;
498 for (i = 0; i < state->ioc2->NumActiveVolumes; vol++, i++)
499 if (vol->VolumeID == state->target_id)
502 return (state->target_id);
505 /* Create a volume and populate it with drives. */
506 static CONFIG_PAGE_RAID_VOL_0 *
507 build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size,
508 struct config_id_state *state, int verbose)
510 CONFIG_PAGE_HEADER header;
511 CONFIG_PAGE_RAID_VOL_0 *vol;
512 RAID_VOL0_PHYS_DISK *rdisk;
513 struct drive_info *dinfo;
519 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME,
520 0, 0, &header, NULL);
525 if (header.PageVersion > MPI_RAIDVOLPAGE0_PAGEVERSION) {
526 warnx("Unsupported RAID volume page 0 version %d",
531 page_size = sizeof(CONFIG_PAGE_RAID_VOL_0) +
532 sizeof(RAID_VOL0_PHYS_DISK) * (info->drive_count - 1);
533 vol = calloc(1, page_size);
538 vol->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
539 vol->Header.PageNumber = 0;
540 vol->Header.PageLength = page_size / 4;
543 vol->VolumeID = find_next_volume(state);
545 vol->VolumeIOC = 0; /* XXX */
546 vol->VolumeStatus.Flags = MPI_RAIDVOL0_STATUS_FLAG_ENABLED;
547 vol->VolumeStatus.State = MPI_RAIDVOL0_STATUS_STATE_OPTIMAL;
548 vol->VolumeSettings.Settings = MPI_RAIDVOL0_SETTING_USE_DEFAULTS;
549 vol->VolumeSettings.HotSparePool = MPI_RAID_HOT_SPARE_POOL_0;
550 vol->NumPhysDisks = info->drive_count;
552 /* Find the smallest drive. */
553 MinLBA = info->drives[0].info->MaxLBA;
554 for (i = 1; i < info->drive_count; i++)
555 if (info->drives[i].info->MaxLBA < MinLBA)
556 MinLBA = info->drives[i].info->MaxLBA;
559 * Now chop off 512MB at the end to leave room for the
560 * metadata. The controller might only use 64MB, but we just
561 * chop off the max to be simple.
563 MinLBA -= (512 * 1024 * 1024) / 512;
567 vol->VolumeType = MPI_RAID_VOL_TYPE_IS;
568 vol->StripeSize = stripe_size / 512;
569 MaxLBA = (uint64_t)MinLBA * info->drive_count;
572 vol->VolumeType = MPI_RAID_VOL_TYPE_IM;
573 MaxLBA = (uint64_t)MinLBA * (info->drive_count / 2);
576 vol->VolumeType = MPI_RAID_VOL_TYPE_IME;
577 vol->StripeSize = stripe_size / 512;
578 MaxLBA = (uint64_t)MinLBA * info->drive_count / 2;
586 * If the controller doesn't support 64-bit addressing and the
587 * new volume is larger than 2^32 blocks, warn the user and
588 * truncate the volume.
590 if (MaxLBA >> 32 != 0 &&
591 !(state->ioc2->CapabilitiesFlags &
592 MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING)) {
594 "Controller does not support volumes > 2TB, truncating volume.");
597 vol->MaxLBA = MaxLBA;
598 vol->MaxLBAHigh = MaxLBA >> 32;
600 /* Populate drives. */
601 for (i = 0, dinfo = info->drives, rdisk = vol->PhysDisk;
602 i < info->drive_count; i++, dinfo++, rdisk++) {
604 printf("Adding drive %u (%u:%u) to volume %u:%u\n",
605 dinfo->info->PhysDiskNum, dinfo->info->PhysDiskBus,
606 dinfo->info->PhysDiskID, vol->VolumeBus,
608 if (raid_type == RT_RAID1) {
611 MPI_RAIDVOL0_PHYSDISK_PRIMARY;
614 MPI_RAIDVOL0_PHYSDISK_SECONDARY;
616 rdisk->PhysDiskMap = i;
617 rdisk->PhysDiskNum = dinfo->info->PhysDiskNum;
624 create_volume(int ac, char **av)
626 CONFIG_PAGE_RAID_VOL_0 *vol;
627 struct config_id_state state;
628 struct volume_info *info;
630 int ch, error, fd, i, quick, raid_type, verbose;
636 warnx("create: volume type required");
640 fd = mpt_open(mpt_unit);
647 /* Lookup the RAID type first. */
649 for (i = 0; raid_type_table[i].name != NULL; i++)
650 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
651 raid_type = raid_type_table[i].raid_type;
655 if (raid_type == -1) {
656 warnx("Unknown or unsupported volume type %s", av[1]);
661 /* Parse any options. */
668 stripe_size = 64 * 1024;
670 while ((ch = getopt(ac, av, "dqs:v")) != -1) {
681 stripe_size = dehumanize(optarg);
682 if ((stripe_size < 512) || (!powerof2(stripe_size))) {
683 warnx("Invalid stripe size %s", optarg);
700 /* Fetch existing config data. */
701 state.ioc2 = mpt_read_ioc_page(fd, 2, NULL);
702 if (state.ioc2 == NULL) {
704 warn("Failed to read volume list");
708 state.list = mpt_pd_list(fd);
709 if (state.list == NULL) {
713 error = mpt_fetch_disks(fd, &state.nsdisks, &state.sdisks);
715 warn("Failed to fetch standalone disk list");
719 state.target_id = 0xff;
721 /* Parse the drive list. */
723 warnx("Exactly one drive list is required");
727 info = calloc(1, sizeof(*info));
732 error = parse_volume(fd, raid_type, &state, av[0], info);
739 /* Create RAID physdisk pages for standalone disks. */
740 error = add_drives(fd, info, verbose);
747 /* Build the volume. */
748 vol = build_volume(fd, info, raid_type, stripe_size, &state, verbose);
762 /* Send the new volume to the controller. */
763 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus,
764 vol->VolumeID, 0, quick ? MPI_RAID_ACTION_ADATA_DO_NOT_SYNC : 0,
765 vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1);
768 warn("Failed to add volume");
777 mpt_rescan_bus(vol->VolumeBus, vol->VolumeID);
783 mpt_free_pd_list(state.list);
789 MPT_COMMAND(top, create, create_volume);
792 delete_volume(int ac, char **av)
794 U8 VolumeBus, VolumeID;
798 warnx("delete: volume required");
802 fd = mpt_open(mpt_unit);
809 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
811 warnc(error, "Invalid volume %s", av[1]);
816 if (mpt_lock_volume(VolumeBus, VolumeID) < 0) {
821 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus,
822 VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
823 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, NULL,
826 warnc(error, "Failed to delete volume");
831 mpt_rescan_bus(-1, -1);
836 MPT_COMMAND(top, delete, delete_volume);
839 find_volume_spare_pool(int fd, const char *name, int *pool)
841 CONFIG_PAGE_RAID_VOL_0 *info;
842 CONFIG_PAGE_IOC_2 *ioc2;
843 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
844 U8 VolumeBus, VolumeID;
845 int error, i, j, new_pool, pool_count[7];
847 error = mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID);
849 warnc(error, "Invalid volume %s", name);
853 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
858 * Check for an existing pool other than pool 0 (used for
861 if ((info->VolumeSettings.HotSparePool & ~MPI_RAID_HOT_SPARE_POOL_0) !=
863 *pool = 1 << (ffs(info->VolumeSettings.HotSparePool &
864 ~MPI_RAID_HOT_SPARE_POOL_0) - 1);
871 * Try to find a free pool. First, figure out which pools are
874 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
877 warn("Failed to fetch volume list");
880 bzero(pool_count, sizeof(pool_count));
881 vol = ioc2->RaidVolume;
882 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
883 info = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
886 for (j = 0; j < 7; j++)
887 if (info->VolumeSettings.HotSparePool & (1 << (j + 1)))
893 /* Find the pool with the lowest use count. */
895 for (i = 1; i < 7; i++)
896 if (pool_count[i] < pool_count[new_pool])
900 /* Add this pool to the volume. */
901 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
904 info->VolumeSettings.HotSparePool |= (1 << new_pool);
905 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
906 VolumeBus, VolumeID, 0, *(U32 *)&info->VolumeSettings, NULL, 0,
907 NULL, NULL, 0, NULL, NULL, 0);
909 warnx("Failed to add spare pool %d to %s", new_pool,
910 mpt_volume_name(VolumeBus, VolumeID));
916 *pool = (1 << new_pool);
921 add_spare(int ac, char **av)
923 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
924 struct mpt_standalone_disk *sdisks;
925 struct mpt_drive_list *list;
927 int error, fd, i, nsdisks, pool;
930 warnx("add spare: drive required");
934 warnx("add spare: extra arguments");
938 fd = mpt_open(mpt_unit);
946 error = find_volume_spare_pool(fd, av[2], &pool);
952 pool = MPI_RAID_HOT_SPARE_POOL_0;
954 list = mpt_pd_list(fd);
958 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
960 error = mpt_fetch_disks(fd, &nsdisks, &sdisks);
962 warn("Failed to fetch standalone disk list");
963 mpt_free_pd_list(list);
968 if (mpt_lookup_standalone_disk(av[1], sdisks, nsdisks, &i) <
971 warn("Unable to lookup drive %s", av[1]);
972 mpt_free_pd_list(list);
977 if (mpt_lock_physdisk(&sdisks[i]) < 0) {
978 mpt_free_pd_list(list);
983 if (mpt_create_physdisk(fd, &sdisks[i], &PhysDiskNum) < 0) {
985 warn("Failed to create physical disk page");
986 mpt_free_pd_list(list);
992 mpt_free_pd_list(list);
994 info = mpt_pd_info(fd, PhysDiskNum, NULL);
997 warn("Failed to fetch drive info");
1002 info->PhysDiskSettings.HotSparePool = pool;
1003 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_PHYSDISK_SETTINGS, 0,
1004 0, PhysDiskNum, *(U32 *)&info->PhysDiskSettings, NULL, 0, NULL,
1005 NULL, 0, NULL, NULL, 0);
1007 warnc(error, "Failed to assign spare");
1017 MPT_COMMAND(top, add, add_spare);
1020 remove_spare(int ac, char **av)
1022 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
1023 struct mpt_drive_list *list;
1028 warnx("remove spare: drive required");
1032 fd = mpt_open(mpt_unit);
1039 list = mpt_pd_list(fd);
1045 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
1047 warn("Failed to find drive %s", av[1]);
1051 mpt_free_pd_list(list);
1054 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1057 warn("Failed to fetch drive info");
1062 if (info->PhysDiskSettings.HotSparePool == 0) {
1063 warnx("Drive %u is not a hot spare", PhysDiskNum);
1069 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1071 warn("Failed to delete physical disk page");
1077 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1083 MPT_COMMAND(top, remove, remove_spare);
1089 pd_create(int ac, char **av)
1091 struct mpt_standalone_disk *disks;
1092 int error, fd, i, ndisks;
1096 warnx("pd create: drive required");
1100 fd = mpt_open(mpt_unit);
1107 error = mpt_fetch_disks(fd, &ndisks, &disks);
1109 warn("Failed to fetch standalone disk list");
1113 if (mpt_lookup_standalone_disk(av[1], disks, ndisks, &i) < 0) {
1115 warn("Unable to lookup drive");
1119 if (mpt_lock_physdisk(&disks[i]) < 0)
1122 if (mpt_create_physdisk(fd, &disks[i], &PhysDiskNum) < 0) {
1124 warn("Failed to create physical disk page");
1129 printf("Added drive %s with PhysDiskNum %u\n", av[1], PhysDiskNum);
1135 MPT_COMMAND(pd, create, pd_create);
1138 pd_delete(int ac, char **av)
1140 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
1141 struct mpt_drive_list *list;
1146 warnx("pd delete: drive required");
1150 fd = mpt_open(mpt_unit);
1157 list = mpt_pd_list(fd);
1161 if (mpt_lookup_drive(list, av[1], &PhysDiskNum) < 0) {
1163 warn("Failed to find drive %s", av[1]);
1166 mpt_free_pd_list(list);
1168 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1171 warn("Failed to fetch drive info");
1175 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1177 warn("Failed to delete physical disk page");
1181 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1187 MPT_COMMAND(pd, delete, pd_delete);
1189 /* Display raw data about a volume config. */
1191 dump_config(CONFIG_PAGE_RAID_VOL_0 *vol)
1195 printf("Volume Configuration (Debug):\n");
1197 " Page Header: Type 0x%02x Number 0x%02x Length 0x%02x(%u) Version 0x%02x\n",
1198 vol->Header.PageType, vol->Header.PageNumber,
1199 vol->Header.PageLength, vol->Header.PageLength * 4,
1200 vol->Header.PageVersion);
1201 printf(" Address: %d:%d IOC %d\n", vol->VolumeBus, vol->VolumeID,
1203 printf(" Type: %d (%s)\n", vol->VolumeType,
1204 mpt_raid_level(vol->VolumeType));
1205 printf(" Status: %s (Flags 0x%02x)\n",
1206 mpt_volstate(vol->VolumeStatus.State), vol->VolumeStatus.Flags);
1207 printf(" Settings: 0x%04x (Spare Pools 0x%02x)\n",
1208 vol->VolumeSettings.Settings, vol->VolumeSettings.HotSparePool);
1209 printf(" MaxLBA: %ju\n", (uintmax_t)vol->MaxLBAHigh << 32 |
1211 printf(" Stripe Size: %ld\n", (long)vol->StripeSize * 512);
1212 printf(" %d Disks:\n", vol->NumPhysDisks);
1214 for (i = 0; i < vol->NumPhysDisks; i++)
1215 printf(" Disk %d: Num 0x%02x Map 0x%02x\n", i,
1216 vol->PhysDisk[i].PhysDiskNum, vol->PhysDisk[i].PhysDiskMap);
1220 debug_config(int ac, char **av)
1222 CONFIG_PAGE_RAID_VOL_0 *vol;
1223 U8 VolumeBus, VolumeID;
1227 warnx("debug: volume required");
1231 fd = mpt_open(mpt_unit);
1238 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
1240 warnc(error, "Invalid volume: %s", av[1]);
1244 vol = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
1247 warn("Failed to get volume info");
1257 MPT_COMMAND(top, debug, debug_config);