2 * Copyright (c) 2008 Yahoo!, Inc.
4 * Written by: John Baldwin <jhb@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the names of any co-contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
34 #include <sys/param.h>
35 #include <sys/errno.h>
50 static void dump_config(CONFIG_PAGE_RAID_VOL_0 *vol);
54 dehumanize(const char *value)
61 iv = strtoq(value, &vtp, 0);
62 if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
87 * Lock the volume by opening its /dev device read/write. This will
88 * only work if nothing else has it opened (including mounts). We
89 * leak the fd on purpose since this application is not long-running.
92 mpt_lock_volume(U8 VolumeBus, U8 VolumeID)
94 char path[MAXPATHLEN];
95 struct mpt_query_disk qd;
98 error = mpt_query_disk(VolumeBus, VolumeID, &qd);
101 * This means there isn't a CAM device associated with
102 * the volume, and thus it is already implicitly
103 * locked, so just return.
107 warnc(error, "Unable to lookup volume device name");
110 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, qd.devname);
111 vfd = open(path, O_RDWR);
114 warn("Unable to lock volume %s", qd.devname);
121 mpt_lock_physdisk(struct mpt_standalone_disk *disk)
123 char path[MAXPATHLEN];
126 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk->devname);
127 dfd = open(path, O_RDWR);
130 warn("Unable to lock disk %s", disk->devname);
137 mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks,
138 int ndisks, int *index)
144 /* Check for a raw <bus>:<id> string. */
145 bus = strtol(name, &cp, 0);
147 id = strtol(cp + 1, &cp, 0);
149 if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) {
152 for (i = 0; i < ndisks; i++) {
153 if (disks[i].bus == (U8)bus &&
154 disks[i].target == (U8)id) {
163 if (name[0] == 'd' && name[1] == 'a') {
164 for (i = 0; i < ndisks; i++) {
165 if (strcmp(name, disks[i].devname) == 0) {
177 * Mark a standalone disk as being a physical disk.
180 mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum)
182 CONFIG_PAGE_HEADER header;
183 CONFIG_PAGE_RAID_PHYS_DISK_0 *config_page;
187 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK,
188 0, 0, &header, NULL);
191 if (header.PageVersion > MPI_RAIDPHYSDISKPAGE0_PAGEVERSION) {
192 warnx("Unsupported RAID physdisk page 0 version %d",
196 config_page = calloc(1, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0));
197 config_page->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
198 config_page->Header.PageNumber = 0;
199 config_page->Header.PageLength = sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0) /
201 config_page->PhysDiskIOC = 0; /* XXX */
202 config_page->PhysDiskBus = disk->bus;
203 config_page->PhysDiskID = disk->target;
205 /* XXX: Enclosure info for PhysDiskSettings? */
206 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0,
207 config_page, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0), NULL,
208 &ActionData, sizeof(ActionData), NULL, NULL, 1);
211 *PhysDiskNum = ActionData & 0xff;
216 mpt_delete_physdisk(int fd, U8 PhysDiskNum)
219 return (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_PHYSDISK, 0, 0,
220 PhysDiskNum, 0, NULL, 0, NULL, NULL, 0, NULL, NULL, 0));
224 * MPT's firmware does not have a clear command. Instead, we
225 * implement it by deleting each array and disk by hand.
228 clear_config(int ac, char **av)
230 CONFIG_PAGE_IOC_2 *ioc2;
231 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
232 CONFIG_PAGE_IOC_3 *ioc3;
233 IOC_3_PHYS_DISK *disk;
234 CONFIG_PAGE_IOC_5 *ioc5;
235 IOC_5_HOT_SPARE *spare;
236 int ch, error, fd, i;
238 fd = mpt_open(mpt_unit);
245 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
248 warn("Failed to fetch volume list");
253 /* Lock all the volumes first. */
254 vol = ioc2->RaidVolume;
255 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
256 if (mpt_lock_volume(vol->VolumeBus, vol->VolumeID) < 0) {
257 warnx("Volume %s is busy and cannot be deleted",
258 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
266 "Are you sure you wish to clear the configuration on mpt%u? [y/N] ",
269 if (ch != 'y' && ch != 'Y') {
270 printf("\nAborting\n");
276 /* Delete all the volumes. */
277 vol = ioc2->RaidVolume;
278 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
279 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME,
280 vol->VolumeBus, vol->VolumeID, 0,
281 MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
282 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0,
285 warnc(error, "Failed to delete volume %s",
286 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
290 /* Delete all the spares. */
291 ioc5 = mpt_read_ioc_page(fd, 5, NULL);
293 warn("Failed to fetch spare list");
295 spare = ioc5->HotSpare;
296 for (i = 0; i < ioc5->NumHotSpares; spare++, i++)
297 if (mpt_delete_physdisk(fd, spare->PhysDiskNum) < 0)
298 warn("Failed to delete physical disk %d",
303 /* Delete any RAID physdisks that may be left. */
304 ioc3 = mpt_read_ioc_page(fd, 3, NULL);
306 warn("Failed to fetch drive list");
308 disk = ioc3->PhysDisk;
309 for (i = 0; i < ioc3->NumPhysDisks; disk++, i++)
310 if (mpt_delete_physdisk(fd, disk->PhysDiskNum) < 0)
311 warn("Failed to delete physical disk %d",
316 printf("mpt%d: Configuration cleared\n", mpt_unit);
317 mpt_rescan_bus(-1, -1);
322 MPT_COMMAND(top, clear, clear_config);
328 static struct raid_type_entry {
331 } raid_type_table[] = {
332 { "raid0", RT_RAID0 },
333 { "raid-0", RT_RAID0 },
334 { "raid1", RT_RAID1 },
335 { "raid-1", RT_RAID1 },
336 { "mirror", RT_RAID1 },
337 { "raid1e", RT_RAID1E },
338 { "raid-1e", RT_RAID1E },
342 struct config_id_state {
343 struct mpt_standalone_disk *sdisks;
344 struct mpt_drive_list *list;
345 CONFIG_PAGE_IOC_2 *ioc2;
351 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
352 struct mpt_standalone_disk *sdisk;
357 struct drive_info *drives;
360 /* Parse a comma-separated list of drives for a volume. */
362 parse_volume(int fd, int raid_type, struct config_id_state *state,
363 char *volume_str, struct volume_info *info)
365 struct drive_info *dinfo;
371 for (count = 0; cp != NULL; count++) {
372 cp = strchr(cp, ',');
376 warnx("Invalid drive list '%s'", volume_str);
382 /* Validate the number of drives for this volume. */
386 warnx("RAID0 requires at least 2 drives in each "
393 warnx("RAID1 requires exactly 2 drives in each "
400 warnx("RAID1E requires at least 3 drives in each "
407 /* Validate each drive. */
408 info->drives = calloc(count, sizeof(struct drive_info));
409 info->drive_count = count;
410 for (dinfo = info->drives; (cp = strsep(&volume_str, ",")) != NULL;
412 /* If this drive is already a RAID phys just fetch the info. */
413 error = mpt_lookup_drive(state->list, cp, &PhysDiskNum);
415 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
416 if (dinfo->info == NULL)
421 /* See if it is a standalone disk. */
422 if (mpt_lookup_standalone_disk(cp, state->sdisks,
423 state->nsdisks, &i) < 0) {
425 warn("Unable to lookup drive %s", cp);
428 dinfo->sdisk = &state->sdisks[i];
430 /* Lock the disk, we will create phys disk pages later. */
431 if (mpt_lock_physdisk(dinfo->sdisk) < 0)
439 * Add RAID physdisk pages for any standalone disks that a volume is
443 add_drives(int fd, struct volume_info *info, int verbose)
445 struct drive_info *dinfo;
449 for (i = 0, dinfo = info->drives; i < info->drive_count;
451 if (dinfo->info == NULL) {
452 if (mpt_create_physdisk(fd, dinfo->sdisk,
456 "Failed to create physical disk page for %s",
457 dinfo->sdisk->devname);
461 printf("Added drive %s with PhysDiskNum %u\n",
462 dinfo->sdisk->devname, PhysDiskNum);
464 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
465 if (dinfo->info == NULL)
473 * Find the next free target ID assuming that 'target_id' is the last
474 * one used. 'target_id' should be 0xff for the initial test.
477 find_next_volume(struct config_id_state *state)
479 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
483 /* Assume the current one is used. */
486 /* Search drives first. */
487 for (i = 0; i < state->nsdisks; i++)
488 if (state->sdisks[i].target == state->target_id)
490 for (i = 0; i < state->list->ndrives; i++)
491 if (state->list->drives[i]->PhysDiskID == state->target_id)
494 /* Search volumes second. */
495 vol = state->ioc2->RaidVolume;
496 for (i = 0; i < state->ioc2->NumActiveVolumes; vol++, i++)
497 if (vol->VolumeID == state->target_id)
500 return (state->target_id);
503 /* Create a volume and populate it with drives. */
504 static CONFIG_PAGE_RAID_VOL_0 *
505 build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size,
506 struct config_id_state *state, int verbose)
508 CONFIG_PAGE_HEADER header;
509 CONFIG_PAGE_RAID_VOL_0 *vol;
510 RAID_VOL0_PHYS_DISK *rdisk;
511 struct drive_info *dinfo;
517 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME,
518 0, 0, &header, NULL);
523 if (header.PageVersion > MPI_RAIDVOLPAGE0_PAGEVERSION) {
524 warnx("Unsupported RAID volume page 0 version %d",
529 page_size = sizeof(CONFIG_PAGE_RAID_VOL_0) +
530 sizeof(RAID_VOL0_PHYS_DISK) * (info->drive_count - 1);
531 vol = calloc(1, page_size);
536 vol->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
537 vol->Header.PageNumber = 0;
538 vol->Header.PageLength = page_size / 4;
541 vol->VolumeID = find_next_volume(state);
543 vol->VolumeIOC = 0; /* XXX */
544 vol->VolumeStatus.Flags = MPI_RAIDVOL0_STATUS_FLAG_ENABLED;
545 vol->VolumeStatus.State = MPI_RAIDVOL0_STATUS_STATE_OPTIMAL;
546 vol->VolumeSettings.Settings = MPI_RAIDVOL0_SETTING_USE_DEFAULTS;
547 vol->VolumeSettings.HotSparePool = MPI_RAID_HOT_SPARE_POOL_0;
548 vol->NumPhysDisks = info->drive_count;
550 /* Find the smallest drive. */
551 MinLBA = info->drives[0].info->MaxLBA;
552 for (i = 1; i < info->drive_count; i++)
553 if (info->drives[i].info->MaxLBA < MinLBA)
554 MinLBA = info->drives[i].info->MaxLBA;
557 * Now chop off 512MB at the end to leave room for the
558 * metadata. The controller might only use 64MB, but we just
559 * chop off the max to be simple.
561 MinLBA -= (512 * 1024 * 1024) / 512;
565 vol->VolumeType = MPI_RAID_VOL_TYPE_IS;
566 vol->StripeSize = stripe_size / 512;
567 MaxLBA = (uint64_t)MinLBA * info->drive_count;
570 vol->VolumeType = MPI_RAID_VOL_TYPE_IM;
571 MaxLBA = (uint64_t)MinLBA * (info->drive_count / 2);
574 vol->VolumeType = MPI_RAID_VOL_TYPE_IME;
575 vol->StripeSize = stripe_size / 512;
576 MaxLBA = (uint64_t)MinLBA * info->drive_count / 2;
584 * If the controller doesn't support 64-bit addressing and the
585 * new volume is larger than 2^32 blocks, warn the user and
586 * truncate the volume.
588 if (MaxLBA >> 32 != 0 &&
589 !(state->ioc2->CapabilitiesFlags &
590 MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING)) {
592 "Controller does not support volumes > 2TB, truncating volume.");
595 vol->MaxLBA = MaxLBA;
596 vol->MaxLBAHigh = MaxLBA >> 32;
598 /* Populate drives. */
599 for (i = 0, dinfo = info->drives, rdisk = vol->PhysDisk;
600 i < info->drive_count; i++, dinfo++, rdisk++) {
602 printf("Adding drive %u (%u:%u) to volume %u:%u\n",
603 dinfo->info->PhysDiskNum, dinfo->info->PhysDiskBus,
604 dinfo->info->PhysDiskID, vol->VolumeBus,
606 if (raid_type == RT_RAID1) {
609 MPI_RAIDVOL0_PHYSDISK_PRIMARY;
612 MPI_RAIDVOL0_PHYSDISK_SECONDARY;
614 rdisk->PhysDiskMap = i;
615 rdisk->PhysDiskNum = dinfo->info->PhysDiskNum;
622 create_volume(int ac, char **av)
624 CONFIG_PAGE_RAID_VOL_0 *vol;
625 struct config_id_state state;
626 struct volume_info *info;
628 int ch, error, fd, i, quick, raid_type, verbose;
634 warnx("create: volume type required");
638 fd = mpt_open(mpt_unit);
645 /* Lookup the RAID type first. */
647 for (i = 0; raid_type_table[i].name != NULL; i++)
648 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
649 raid_type = raid_type_table[i].raid_type;
653 if (raid_type == -1) {
654 warnx("Unknown or unsupported volume type %s", av[1]);
659 /* Parse any options. */
666 stripe_size = 64 * 1024;
668 while ((ch = getopt(ac, av, "dqs:v")) != -1) {
679 stripe_size = dehumanize(optarg);
680 if ((stripe_size < 512) || (!powerof2(stripe_size))) {
681 warnx("Invalid stripe size %s", optarg);
698 /* Fetch existing config data. */
699 state.ioc2 = mpt_read_ioc_page(fd, 2, NULL);
700 if (state.ioc2 == NULL) {
702 warn("Failed to read volume list");
706 state.list = mpt_pd_list(fd);
707 if (state.list == NULL) {
711 error = mpt_fetch_disks(fd, &state.nsdisks, &state.sdisks);
713 warn("Failed to fetch standalone disk list");
717 state.target_id = 0xff;
719 /* Parse the drive list. */
721 warnx("Exactly one drive list is required");
725 info = calloc(1, sizeof(*info));
730 error = parse_volume(fd, raid_type, &state, av[0], info);
737 /* Create RAID physdisk pages for standalone disks. */
738 error = add_drives(fd, info, verbose);
745 /* Build the volume. */
746 vol = build_volume(fd, info, raid_type, stripe_size, &state, verbose);
760 /* Send the new volume to the controller. */
761 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus,
762 vol->VolumeID, 0, quick ? MPI_RAID_ACTION_ADATA_DO_NOT_SYNC : 0,
763 vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1);
766 warn("Failed to add volume");
775 mpt_rescan_bus(vol->VolumeBus, vol->VolumeID);
781 mpt_free_pd_list(state.list);
787 MPT_COMMAND(top, create, create_volume);
790 delete_volume(int ac, char **av)
792 U8 VolumeBus, VolumeID;
796 warnx("delete: volume required");
800 fd = mpt_open(mpt_unit);
807 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
809 warnc(error, "Invalid volume %s", av[1]);
814 if (mpt_lock_volume(VolumeBus, VolumeID) < 0) {
819 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus,
820 VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
821 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, NULL,
824 warnc(error, "Failed to delete volume");
829 mpt_rescan_bus(-1, -1);
834 MPT_COMMAND(top, delete, delete_volume);
837 find_volume_spare_pool(int fd, const char *name, int *pool)
839 CONFIG_PAGE_RAID_VOL_0 *info;
840 CONFIG_PAGE_IOC_2 *ioc2;
841 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
842 U8 VolumeBus, VolumeID;
843 int error, i, j, new_pool, pool_count[7];
845 error = mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID);
847 warnc(error, "Invalid volume %s", name);
851 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
856 * Check for an existing pool other than pool 0 (used for
859 if ((info->VolumeSettings.HotSparePool & ~MPI_RAID_HOT_SPARE_POOL_0) !=
861 *pool = 1 << (ffs(info->VolumeSettings.HotSparePool &
862 ~MPI_RAID_HOT_SPARE_POOL_0) - 1);
869 * Try to find a free pool. First, figure out which pools are
872 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
875 warn("Failed to fetch volume list");
878 bzero(pool_count, sizeof(pool_count));
879 vol = ioc2->RaidVolume;
880 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
881 info = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
884 for (j = 0; j < 7; j++)
885 if (info->VolumeSettings.HotSparePool & (1 << (j + 1)))
891 /* Find the pool with the lowest use count. */
893 for (i = 1; i < 7; i++)
894 if (pool_count[i] < pool_count[new_pool])
898 /* Add this pool to the volume. */
899 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
902 info->VolumeSettings.HotSparePool |= (1 << new_pool);
903 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
904 VolumeBus, VolumeID, 0, *(U32 *)&info->VolumeSettings, NULL, 0,
905 NULL, NULL, 0, NULL, NULL, 0);
907 warnx("Failed to add spare pool %d to %s", new_pool,
908 mpt_volume_name(VolumeBus, VolumeID));
914 *pool = (1 << new_pool);
919 add_spare(int ac, char **av)
921 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
922 struct mpt_standalone_disk *sdisks;
923 struct mpt_drive_list *list;
925 int error, fd, i, nsdisks, pool;
928 warnx("add spare: drive required");
932 warnx("add spare: extra arguments");
936 fd = mpt_open(mpt_unit);
944 error = find_volume_spare_pool(fd, av[2], &pool);
950 pool = MPI_RAID_HOT_SPARE_POOL_0;
952 list = mpt_pd_list(fd);
956 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
958 error = mpt_fetch_disks(fd, &nsdisks, &sdisks);
960 warn("Failed to fetch standalone disk list");
961 mpt_free_pd_list(list);
966 if (mpt_lookup_standalone_disk(av[1], sdisks, nsdisks, &i) <
969 warn("Unable to lookup drive %s", av[1]);
970 mpt_free_pd_list(list);
975 if (mpt_lock_physdisk(&sdisks[i]) < 0) {
976 mpt_free_pd_list(list);
981 if (mpt_create_physdisk(fd, &sdisks[i], &PhysDiskNum) < 0) {
983 warn("Failed to create physical disk page");
984 mpt_free_pd_list(list);
990 mpt_free_pd_list(list);
992 info = mpt_pd_info(fd, PhysDiskNum, NULL);
995 warn("Failed to fetch drive info");
1000 info->PhysDiskSettings.HotSparePool = pool;
1001 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_PHYSDISK_SETTINGS, 0,
1002 0, PhysDiskNum, *(U32 *)&info->PhysDiskSettings, NULL, 0, NULL,
1003 NULL, 0, NULL, NULL, 0);
1005 warnc(error, "Failed to assign spare");
1015 MPT_COMMAND(top, add, add_spare);
1018 remove_spare(int ac, char **av)
1020 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
1021 struct mpt_drive_list *list;
1026 warnx("remove spare: drive required");
1030 fd = mpt_open(mpt_unit);
1037 list = mpt_pd_list(fd);
1043 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
1045 warn("Failed to find drive %s", av[1]);
1049 mpt_free_pd_list(list);
1052 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1055 warn("Failed to fetch drive info");
1060 if (info->PhysDiskSettings.HotSparePool == 0) {
1061 warnx("Drive %u is not a hot spare", PhysDiskNum);
1067 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1069 warn("Failed to delete physical disk page");
1075 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1081 MPT_COMMAND(top, remove, remove_spare);
1087 pd_create(int ac, char **av)
1089 struct mpt_standalone_disk *disks;
1090 int error, fd, i, ndisks;
1094 warnx("pd create: drive required");
1098 fd = mpt_open(mpt_unit);
1105 error = mpt_fetch_disks(fd, &ndisks, &disks);
1107 warn("Failed to fetch standalone disk list");
1111 if (mpt_lookup_standalone_disk(av[1], disks, ndisks, &i) < 0) {
1113 warn("Unable to lookup drive");
1117 if (mpt_lock_physdisk(&disks[i]) < 0)
1120 if (mpt_create_physdisk(fd, &disks[i], &PhysDiskNum) < 0) {
1122 warn("Failed to create physical disk page");
1127 printf("Added drive %s with PhysDiskNum %u\n", av[1], PhysDiskNum);
1133 MPT_COMMAND(pd, create, pd_create);
1136 pd_delete(int ac, char **av)
1138 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
1139 struct mpt_drive_list *list;
1144 warnx("pd delete: drive required");
1148 fd = mpt_open(mpt_unit);
1155 list = mpt_pd_list(fd);
1159 if (mpt_lookup_drive(list, av[1], &PhysDiskNum) < 0) {
1161 warn("Failed to find drive %s", av[1]);
1164 mpt_free_pd_list(list);
1166 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1169 warn("Failed to fetch drive info");
1173 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1175 warn("Failed to delete physical disk page");
1179 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1185 MPT_COMMAND(pd, delete, pd_delete);
1187 /* Display raw data about a volume config. */
1189 dump_config(CONFIG_PAGE_RAID_VOL_0 *vol)
1193 printf("Volume Configuration (Debug):\n");
1195 " Page Header: Type 0x%02x Number 0x%02x Length 0x%02x(%u) Version 0x%02x\n",
1196 vol->Header.PageType, vol->Header.PageNumber,
1197 vol->Header.PageLength, vol->Header.PageLength * 4,
1198 vol->Header.PageVersion);
1199 printf(" Address: %d:%d IOC %d\n", vol->VolumeBus, vol->VolumeID,
1201 printf(" Type: %d (%s)\n", vol->VolumeType,
1202 mpt_raid_level(vol->VolumeType));
1203 printf(" Status: %s (Flags 0x%02x)\n",
1204 mpt_volstate(vol->VolumeStatus.State), vol->VolumeStatus.Flags);
1205 printf(" Settings: 0x%04x (Spare Pools 0x%02x)\n",
1206 vol->VolumeSettings.Settings, vol->VolumeSettings.HotSparePool);
1207 printf(" MaxLBA: %ju\n", (uintmax_t)vol->MaxLBAHigh << 32 |
1209 printf(" Stripe Size: %ld\n", (long)vol->StripeSize * 512);
1210 printf(" %d Disks:\n", vol->NumPhysDisks);
1212 for (i = 0; i < vol->NumPhysDisks; i++)
1213 printf(" Disk %d: Num 0x%02x Map 0x%02x\n", i,
1214 vol->PhysDisk[i].PhysDiskNum, vol->PhysDisk[i].PhysDiskMap);
1218 debug_config(int ac, char **av)
1220 CONFIG_PAGE_RAID_VOL_0 *vol;
1221 U8 VolumeBus, VolumeID;
1225 warnx("debug: volume required");
1229 fd = mpt_open(mpt_unit);
1236 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
1238 warnc(error, "Invalid volume: %s", av[1]);
1242 vol = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
1245 warn("Failed to get volume info");
1255 MPT_COMMAND(top, debug, debug_config);