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);
53 #define powerof2(x) ((((x)-1)&(x))==0)
56 dehumanize(const char *value)
63 iv = strtoq(value, &vtp, 0);
64 if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
85 * Lock the volume by opening its /dev device read/write. This will
86 * only work if nothing else has it opened (including mounts). We
87 * leak the fd on purpose since this application is not long-running.
90 mpt_lock_volume(U8 VolumeBus, U8 VolumeID)
92 char path[MAXPATHLEN];
93 struct mpt_query_disk qd;
96 error = mpt_query_disk(VolumeBus, VolumeID, &qd);
99 * This means there isn't a CAM device associated with
100 * the volume, and thus it is already implicitly
101 * locked, so just return.
106 warn("Unable to lookup volume device name");
109 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, qd.devname);
110 vfd = open(path, O_RDWR);
112 warn("Unable to lock volume %s", qd.devname);
119 mpt_lock_physdisk(struct mpt_standalone_disk *disk)
121 char path[MAXPATHLEN];
124 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk->devname);
125 dfd = open(path, O_RDWR);
127 warn("Unable to lock disk %s", disk->devname);
134 mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks,
135 int ndisks, int *index)
141 /* Check for a raw <bus>:<id> string. */
142 bus = strtol(name, &cp, 0);
144 id = strtol(cp + 1, &cp, 0);
146 if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) {
150 for (i = 0; i < ndisks; i++) {
151 if (disks[i].bus == (U8)bus &&
152 disks[i].target == (U8)id) {
162 if (name[0] == 'd' && name[1] == 'a') {
163 for (i = 0; i < ndisks; i++) {
164 if (strcmp(name, disks[i].devname) == 0) {
178 * Mark a standalone disk as being a physical disk.
181 mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum)
183 CONFIG_PAGE_HEADER header;
184 CONFIG_PAGE_RAID_PHYS_DISK_0 *config_page;
187 if (mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK,
188 0, 0, &header, NULL) < 0)
190 if (header.PageVersion > MPI_RAIDPHYSDISKPAGE0_PAGEVERSION) {
191 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 if (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) < 0)
210 *PhysDiskNum = ActionData & 0xff;
215 mpt_delete_physdisk(int fd, U8 PhysDiskNum)
218 return (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_PHYSDISK, 0, 0,
219 PhysDiskNum, 0, NULL, 0, NULL, NULL, 0, NULL, NULL, 0));
223 * MPT's firmware does not have a clear command. Instead, we
224 * implement it by deleting each array and disk by hand.
227 clear_config(int ac, char **av)
229 CONFIG_PAGE_IOC_2 *ioc2;
230 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
231 CONFIG_PAGE_IOC_3 *ioc3;
232 IOC_3_PHYS_DISK *disk;
233 CONFIG_PAGE_IOC_5 *ioc5;
234 IOC_5_HOT_SPARE *spare;
237 fd = mpt_open(mpt_unit);
243 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
245 warn("Failed to fetch volume list");
249 /* Lock all the volumes first. */
250 vol = ioc2->RaidVolume;
251 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
252 if (mpt_lock_volume(vol->VolumeBus, vol->VolumeID) < 0) {
253 warnx("Volume %s is busy and cannot be deleted",
254 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
260 "Are you sure you wish to clear the configuration on mpt%u? [y/N] ",
263 if (ch != 'y' && ch != 'Y') {
264 printf("\nAborting\n");
268 /* Delete all the volumes. */
269 vol = ioc2->RaidVolume;
270 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++)
271 if (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME,
272 vol->VolumeBus, vol->VolumeID, 0,
273 MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
274 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0,
276 warn("Failed to delete volume %s",
277 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
280 /* Delete all the spares. */
281 ioc5 = mpt_read_ioc_page(fd, 5, NULL);
283 warn("Failed to fetch spare list");
285 spare = ioc5->HotSpare;
286 for (i = 0; i < ioc5->NumHotSpares; spare++, i++)
287 if (mpt_delete_physdisk(fd, spare->PhysDiskNum) < 0)
288 warn("Failed to delete physical disk %d",
293 /* Delete any RAID physdisks that may be left. */
294 ioc3 = mpt_read_ioc_page(fd, 3, NULL);
296 warn("Failed to fetch drive list");
298 disk = ioc3->PhysDisk;
299 for (i = 0; i < ioc3->NumPhysDisks; disk++, i++)
300 if (mpt_delete_physdisk(fd, disk->PhysDiskNum) < 0)
301 warn("Failed to delete physical disk %d",
306 printf("mpt%d: Configuration cleared\n", mpt_unit);
307 mpt_rescan_bus(-1, -1);
312 MPT_COMMAND(top, clear, clear_config);
318 static struct raid_type_entry {
321 } raid_type_table[] = {
322 { "raid0", RT_RAID0 },
323 { "raid-0", RT_RAID0 },
324 { "raid1", RT_RAID1 },
325 { "raid-1", RT_RAID1 },
326 { "mirror", RT_RAID1 },
327 { "raid1e", RT_RAID1E },
328 { "raid-1e", RT_RAID1E },
332 struct config_id_state {
333 struct mpt_standalone_disk *sdisks;
334 struct mpt_drive_list *list;
335 CONFIG_PAGE_IOC_2 *ioc2;
341 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
342 struct mpt_standalone_disk *sdisk;
347 struct drive_info *drives;
350 /* Parse a comma-separated list of drives for a volume. */
352 parse_volume(int fd, int raid_type, struct config_id_state *state,
353 char *volume_str, struct volume_info *info)
355 struct drive_info *dinfo;
361 for (count = 0; cp != NULL; count++) {
362 cp = strchr(cp, ',');
366 warnx("Invalid drive list '%s'", volume_str);
372 /* Validate the number of drives for this volume. */
376 warnx("RAID0 requires at least 2 drives in each "
383 warnx("RAID1 requires exactly 2 drives in each "
390 warnx("RAID1E requires at least 3 drives in each "
397 /* Validate each drive. */
398 info->drives = calloc(count, sizeof(struct drive_info));
399 info->drive_count = count;
400 for (dinfo = info->drives; (cp = strsep(&volume_str, ",")) != NULL;
402 /* If this drive is already a RAID phys just fetch the info. */
403 error = mpt_lookup_drive(state->list, cp, &PhysDiskNum);
405 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
406 if (dinfo->info == NULL)
411 /* See if it is a standalone disk. */
412 if (mpt_lookup_standalone_disk(cp, state->sdisks,
413 state->nsdisks, &i) < 0) {
414 warn("Unable to lookup drive %s", cp);
417 dinfo->sdisk = &state->sdisks[i];
419 /* Lock the disk, we will create phys disk pages later. */
420 if (mpt_lock_physdisk(dinfo->sdisk) < 0)
428 * Add RAID physdisk pages for any standalone disks that a volume is
432 add_drives(int fd, struct volume_info *info, int verbose)
434 struct drive_info *dinfo;
438 for (i = 0, dinfo = info->drives; i < info->drive_count;
440 if (dinfo->info == NULL) {
441 if (mpt_create_physdisk(fd, dinfo->sdisk,
444 "Failed to create physical disk page for %s",
445 dinfo->sdisk->devname);
449 printf("Added drive %s with PhysDiskNum %u\n",
450 dinfo->sdisk->devname, PhysDiskNum);
452 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
453 if (dinfo->info == NULL)
461 * Find the next free target ID assuming that 'target_id' is the last
462 * one used. 'target_id' should be 0xff for the initial test.
465 find_next_volume(struct config_id_state *state)
467 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
471 /* Assume the current one is used. */
474 /* Search drives first. */
475 for (i = 0; i < state->nsdisks; i++)
476 if (state->sdisks[i].target == state->target_id)
478 for (i = 0; i < state->list->ndrives; i++)
479 if (state->list->drives[i]->PhysDiskID == state->target_id)
482 /* Seach volumes second. */
483 vol = state->ioc2->RaidVolume;
484 for (i = 0; i < state->ioc2->NumActiveVolumes; vol++, i++)
485 if (vol->VolumeID == state->target_id)
488 return (state->target_id);
491 /* Create a volume and populate it with drives. */
492 static CONFIG_PAGE_RAID_VOL_0 *
493 build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size,
494 struct config_id_state *state, int verbose)
496 CONFIG_PAGE_HEADER header;
497 CONFIG_PAGE_RAID_VOL_0 *vol;
498 RAID_VOL0_PHYS_DISK *rdisk;
499 struct drive_info *dinfo;
505 if (mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME,
506 0, 0, &header, NULL) < 0)
508 if (header.PageVersion > MPI_RAIDVOLPAGE0_PAGEVERSION) {
509 warnx("Unsupported RAID volume page 0 version %d",
514 page_size = sizeof(CONFIG_PAGE_RAID_VOL_0) +
515 sizeof(RAID_VOL0_PHYS_DISK) * (info->drive_count - 1);
516 vol = calloc(1, page_size);
519 vol->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
520 vol->Header.PageNumber = 0;
521 vol->Header.PageLength = page_size / 4;
524 vol->VolumeID = find_next_volume(state);
526 vol->VolumeIOC = 0; /* XXX */
527 vol->VolumeStatus.Flags = MPI_RAIDVOL0_STATUS_FLAG_ENABLED;
528 vol->VolumeStatus.State = MPI_RAIDVOL0_STATUS_STATE_OPTIMAL;
529 vol->VolumeSettings.Settings = MPI_RAIDVOL0_SETTING_USE_DEFAULTS;
530 vol->VolumeSettings.HotSparePool = MPI_RAID_HOT_SPARE_POOL_0;
531 vol->NumPhysDisks = info->drive_count;
533 /* Find the smallest drive. */
534 MinLBA = info->drives[0].info->MaxLBA;
535 for (i = 1; i < info->drive_count; i++)
536 if (info->drives[i].info->MaxLBA < MinLBA)
537 MinLBA = info->drives[i].info->MaxLBA;
540 * Now chop off 512MB at the end to leave room for the
541 * metadata. The controller might only use 64MB, but we just
542 * chop off the max to be simple.
544 MinLBA -= (512 * 1024 * 1024) / 512;
548 vol->VolumeType = MPI_RAID_VOL_TYPE_IS;
549 vol->StripeSize = stripe_size / 512;
550 MaxLBA = MinLBA * info->drive_count;
553 vol->VolumeType = MPI_RAID_VOL_TYPE_IM;
554 MaxLBA = MinLBA * (info->drive_count / 2);
557 vol->VolumeType = MPI_RAID_VOL_TYPE_IME;
558 vol->StripeSize = stripe_size / 512;
559 MaxLBA = MinLBA * info->drive_count / 2;
567 * If the controller doesn't support 64-bit addressing and the
568 * new volume is larger than 2^32 blocks, warn the user and
569 * truncate the volume.
571 if (MaxLBA >> 32 != 0 &&
572 !(state->ioc2->CapabilitiesFlags &
573 MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING)) {
575 "Controller does not support volumes > 2TB, truncating volume.");
578 vol->MaxLBA = MaxLBA;
579 vol->MaxLBAHigh = MaxLBA >> 32;
581 /* Populate drives. */
582 for (i = 0, dinfo = info->drives, rdisk = vol->PhysDisk;
583 i < info->drive_count; i++, dinfo++, rdisk++) {
585 printf("Adding drive %u (%u:%u) to volume %u:%u\n",
586 dinfo->info->PhysDiskNum, dinfo->info->PhysDiskBus,
587 dinfo->info->PhysDiskID, vol->VolumeBus,
589 if (raid_type == RT_RAID1) {
592 MPI_RAIDVOL0_PHYSDISK_PRIMARY;
595 MPI_RAIDVOL0_PHYSDISK_SECONDARY;
597 rdisk->PhysDiskMap = i;
598 rdisk->PhysDiskNum = dinfo->info->PhysDiskNum;
605 create_volume(int ac, char **av)
607 CONFIG_PAGE_RAID_VOL_0 *vol;
608 struct config_id_state state;
609 struct volume_info *info;
610 int ch, error, fd, i, raid_type, verbose, quick;
617 warnx("create: volume type required");
621 fd = mpt_open(mpt_unit);
627 /* Lookup the RAID type first. */
629 for (i = 0; raid_type_table[i].name != NULL; i++)
630 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
631 raid_type = raid_type_table[i].raid_type;
635 if (raid_type == -1) {
636 warnx("Unknown or unsupported volume type %s", av[1]);
640 /* Parse any options. */
647 stripe_size = 64 * 1024;
649 while ((ch = getopt(ac, av, "dqs:v")) != -1) {
660 stripe_size = dehumanize(optarg);
661 if ((stripe_size < 512) || (!powerof2(stripe_size))) {
662 warnx("Invalid stripe size %s", optarg);
677 /* Fetch existing config data. */
678 state.ioc2 = mpt_read_ioc_page(fd, 2, NULL);
679 if (state.ioc2 == NULL) {
680 warn("Failed to read volume list");
683 state.list = mpt_pd_list(fd);
684 if (state.list == NULL)
686 error = mpt_fetch_disks(fd, &state.nsdisks, &state.sdisks);
688 warn("Failed to fetch standalone disk list");
691 state.target_id = 0xff;
693 /* Parse the drive list. */
695 warnx("Exactly one drive list is required");
698 info = calloc(1, sizeof(*info));
699 error = parse_volume(fd, raid_type, &state, av[0], info);
703 /* Create RAID physdisk pages for standalone disks. */
704 error = add_drives(fd, info, verbose);
708 /* Build the volume. */
709 vol = build_volume(fd, info, raid_type, stripe_size, &state, verbose);
718 /* Send the new volume to the controller. */
719 if (mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus,
720 vol->VolumeID, 0, quick ? MPI_RAID_ACTION_ADATA_DO_NOT_SYNC : 0,
721 vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1) <
723 warn("Failed to add volume");
730 mpt_rescan_bus(vol->VolumeBus, vol->VolumeID);
736 mpt_free_pd_list(state.list);
742 MPT_COMMAND(top, create, create_volume);
745 delete_volume(int ac, char **av)
747 U8 VolumeBus, VolumeID;
751 warnx("delete: volume required");
755 fd = mpt_open(mpt_unit);
761 if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
762 warn("Invalid volume %s", av[1]);
766 if (mpt_lock_volume(VolumeBus, VolumeID) < 0)
769 if (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus,
770 VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
771 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, NULL,
773 warn("Failed to delete volume");
777 mpt_rescan_bus(-1, -1);
782 MPT_COMMAND(top, delete, delete_volume);
785 find_volume_spare_pool(int fd, const char *name, int *pool)
787 CONFIG_PAGE_RAID_VOL_0 *info;
788 CONFIG_PAGE_IOC_2 *ioc2;
789 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
790 U8 VolumeBus, VolumeID;
791 int i, j, new_pool, pool_count[7];
793 if (mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID) < 0) {
794 warn("Invalid volume %s", name);
798 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
803 * Check for an existing pool other than pool 0 (used for
806 if ((info->VolumeSettings.HotSparePool & ~MPI_RAID_HOT_SPARE_POOL_0) !=
808 *pool = 1 << (ffs(info->VolumeSettings.HotSparePool &
809 ~MPI_RAID_HOT_SPARE_POOL_0) - 1);
815 * Try to find a free pool. First, figure out which pools are
818 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
820 warn("Failed to fetch volume list");
823 bzero(pool_count, sizeof(pool_count));
824 vol = ioc2->RaidVolume;
825 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
826 info = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
829 for (j = 0; j < 7; j++)
830 if (info->VolumeSettings.HotSparePool & (1 << (j + 1)))
836 /* Find the pool with the lowest use count. */
838 for (i = 1; i < 7; i++)
839 if (pool_count[i] < pool_count[new_pool])
843 /* Add this pool to the volume. */
844 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
847 info->VolumeSettings.HotSparePool |= (1 << new_pool);
848 if (mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
849 VolumeBus, VolumeID, 0, *(U32 *)&info->VolumeSettings, NULL, 0,
850 NULL, NULL, 0, NULL, NULL, 0) < 0) {
851 warnx("Failed to add spare pool %d to %s", new_pool,
852 mpt_volume_name(VolumeBus, VolumeID));
857 *pool = (1 << new_pool);
862 add_spare(int ac, char **av)
864 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
865 struct mpt_standalone_disk *sdisks;
866 struct mpt_drive_list *list;
868 int error, fd, i, nsdisks, pool;
871 warnx("add spare: drive required");
875 warnx("add spare: extra arguments");
879 fd = mpt_open(mpt_unit);
886 if (find_volume_spare_pool(fd, av[2], &pool) < 0)
889 pool = MPI_RAID_HOT_SPARE_POOL_0;
891 list = mpt_pd_list(fd);
895 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
897 error = mpt_fetch_disks(fd, &nsdisks, &sdisks);
899 warn("Failed to fetch standalone disk list");
903 if (mpt_lookup_standalone_disk(av[1], sdisks, nsdisks, &i) <
905 warn("Unable to lookup drive %s", av[1]);
909 if (mpt_lock_physdisk(&sdisks[i]) < 0)
912 if (mpt_create_physdisk(fd, &sdisks[i], &PhysDiskNum) < 0) {
913 warn("Failed to create physical disk page");
918 mpt_free_pd_list(list);
920 info = mpt_pd_info(fd, PhysDiskNum, NULL);
922 warn("Failed to fetch drive info");
926 info->PhysDiskSettings.HotSparePool = pool;
927 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_PHYSDISK_SETTINGS, 0,
928 0, PhysDiskNum, *(U32 *)&info->PhysDiskSettings, NULL, 0, NULL,
929 NULL, 0, NULL, NULL, 0);
931 warn("Failed to assign spare");
940 MPT_COMMAND(top, add, add_spare);
943 remove_spare(int ac, char **av)
945 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
946 struct mpt_drive_list *list;
951 warnx("remove spare: drive required");
955 fd = mpt_open(mpt_unit);
961 list = mpt_pd_list(fd);
965 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
967 warn("Failed to find drive %s", av[1]);
970 mpt_free_pd_list(list);
973 info = mpt_pd_info(fd, PhysDiskNum, NULL);
975 warn("Failed to fetch drive info");
979 if (info->PhysDiskSettings.HotSparePool == 0) {
980 warnx("Drive %u is not a hot spare", PhysDiskNum);
984 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
985 warn("Failed to delete physical disk page");
989 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
995 MPT_COMMAND(top, remove, remove_spare);
1001 pd_create(int ac, char **av)
1003 struct mpt_standalone_disk *disks;
1004 int error, fd, i, ndisks;
1008 warnx("pd create: drive required");
1012 fd = mpt_open(mpt_unit);
1018 error = mpt_fetch_disks(fd, &ndisks, &disks);
1020 warn("Failed to fetch standalone disk list");
1024 if (mpt_lookup_standalone_disk(av[1], disks, ndisks, &i) < 0) {
1025 warn("Unable to lookup drive");
1029 if (mpt_lock_physdisk(&disks[i]) < 0)
1032 if (mpt_create_physdisk(fd, &disks[i], &PhysDiskNum) < 0) {
1033 warn("Failed to create physical disk page");
1038 printf("Added drive %s with PhysDiskNum %u\n", av[1], PhysDiskNum);
1044 MPT_COMMAND(pd, create, pd_create);
1047 pd_delete(int ac, char **av)
1049 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
1050 struct mpt_drive_list *list;
1055 warnx("pd delete: drive required");
1059 fd = mpt_open(mpt_unit);
1065 list = mpt_pd_list(fd);
1069 if (mpt_lookup_drive(list, av[1], &PhysDiskNum) < 0) {
1070 warn("Failed to find drive %s", av[1]);
1073 mpt_free_pd_list(list);
1075 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1077 warn("Failed to fetch drive info");
1081 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1082 warn("Failed to delete physical disk page");
1086 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1092 MPT_COMMAND(pd, delete, pd_delete);
1094 /* Display raw data about a volume config. */
1096 dump_config(CONFIG_PAGE_RAID_VOL_0 *vol)
1100 printf("Volume Configuration (Debug):\n");
1102 " Page Header: Type 0x%02x Number 0x%02x Length 0x%02x(%u) Version 0x%02x\n",
1103 vol->Header.PageType, vol->Header.PageNumber,
1104 vol->Header.PageLength, vol->Header.PageLength * 4,
1105 vol->Header.PageVersion);
1106 printf(" Address: %d:%d IOC %d\n", vol->VolumeBus, vol->VolumeID,
1108 printf(" Type: %d (%s)\n", vol->VolumeType,
1109 mpt_raid_level(vol->VolumeType));
1110 printf(" Status: %s (Flags 0x%02x)\n",
1111 mpt_volstate(vol->VolumeStatus.State), vol->VolumeStatus.Flags);
1112 printf(" Settings: 0x%04x (Spare Pools 0x%02x)\n",
1113 vol->VolumeSettings.Settings, vol->VolumeSettings.HotSparePool);
1114 printf(" MaxLBA: %ju\n", (uintmax_t)vol->MaxLBAHigh << 32 |
1116 printf(" Stripe Size: %ld\n", (long)vol->StripeSize * 512);
1117 printf(" %d Disks:\n", vol->NumPhysDisks);
1119 for (i = 0; i < vol->NumPhysDisks; i++)
1120 printf(" Disk %d: Num 0x%02x Map 0x%02x\n", i,
1121 vol->PhysDisk[i].PhysDiskNum, vol->PhysDisk[i].PhysDiskMap);
1125 debug_config(int ac, char **av)
1127 CONFIG_PAGE_RAID_VOL_0 *vol;
1128 U8 VolumeBus, VolumeID;
1132 warnx("debug: volume required");
1136 fd = mpt_open(mpt_unit);
1142 if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
1143 warn("Invalid volume: %s", av[1]);
1147 vol = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
1149 warn("Failed to get volume info");
1159 MPT_COMMAND(top, debug, debug_config);