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')) {
83 * Lock the volume by opening its /dev device read/write. This will
84 * only work if nothing else has it opened (including mounts). We
85 * leak the fd on purpose since this application is not long-running.
88 mpt_lock_volume(U8 VolumeBus, U8 VolumeID)
90 char path[MAXPATHLEN];
91 struct mpt_query_disk qd;
94 error = mpt_query_disk(VolumeBus, VolumeID, &qd);
97 * This means there isn't a CAM device associated with
98 * the volume, and thus it is already implicitly
99 * locked, so just return.
103 warnc(error, "Unable to lookup volume device name");
106 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, qd.devname);
107 vfd = open(path, O_RDWR);
110 warn("Unable to lock volume %s", qd.devname);
117 mpt_lock_physdisk(struct mpt_standalone_disk *disk)
119 char path[MAXPATHLEN];
122 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk->devname);
123 dfd = open(path, O_RDWR);
126 warn("Unable to lock disk %s", disk->devname);
133 mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks,
134 int ndisks, int *index)
140 /* Check for a raw <bus>:<id> string. */
141 bus = strtol(name, &cp, 0);
143 id = strtol(cp + 1, &cp, 0);
145 if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) {
148 for (i = 0; i < ndisks; i++) {
149 if (disks[i].bus == (U8)bus &&
150 disks[i].target == (U8)id) {
159 if (name[0] == 'd' && name[1] == 'a') {
160 for (i = 0; i < ndisks; i++) {
161 if (strcmp(name, disks[i].devname) == 0) {
173 * Mark a standalone disk as being a physical disk.
176 mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum)
178 CONFIG_PAGE_HEADER header;
179 CONFIG_PAGE_RAID_PHYS_DISK_0 *config_page;
183 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK,
184 0, 0, &header, NULL);
187 if (header.PageVersion > MPI_RAIDPHYSDISKPAGE0_PAGEVERSION) {
188 warnx("Unsupported RAID physdisk page 0 version %d",
192 config_page = calloc(1, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0));
193 config_page->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
194 config_page->Header.PageNumber = 0;
195 config_page->Header.PageLength = sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0) /
197 config_page->PhysDiskIOC = 0; /* XXX */
198 config_page->PhysDiskBus = disk->bus;
199 config_page->PhysDiskID = disk->target;
201 /* XXX: Enclosure info for PhysDiskSettings? */
202 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0,
203 config_page, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0), NULL,
204 &ActionData, sizeof(ActionData), NULL, NULL, 1);
207 *PhysDiskNum = ActionData & 0xff;
212 mpt_delete_physdisk(int fd, U8 PhysDiskNum)
215 return (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_PHYSDISK, 0, 0,
216 PhysDiskNum, 0, NULL, 0, NULL, NULL, 0, NULL, NULL, 0));
220 * MPT's firmware does not have a clear command. Instead, we
221 * implement it by deleting each array and disk by hand.
224 clear_config(int ac, char **av)
226 CONFIG_PAGE_IOC_2 *ioc2;
227 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
228 CONFIG_PAGE_IOC_3 *ioc3;
229 IOC_3_PHYS_DISK *disk;
230 CONFIG_PAGE_IOC_5 *ioc5;
231 IOC_5_HOT_SPARE *spare;
232 int ch, error, fd, i;
234 fd = mpt_open(mpt_unit);
241 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
244 warn("Failed to fetch volume list");
248 /* Lock all the volumes first. */
249 vol = ioc2->RaidVolume;
250 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
251 if (mpt_lock_volume(vol->VolumeBus, vol->VolumeID) < 0) {
252 warnx("Volume %s is busy and cannot be deleted",
253 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
259 "Are you sure you wish to clear the configuration on mpt%u? [y/N] ",
262 if (ch != 'y' && ch != 'Y') {
263 printf("\nAborting\n");
267 /* Delete all the volumes. */
268 vol = ioc2->RaidVolume;
269 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
270 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME,
271 vol->VolumeBus, vol->VolumeID, 0,
272 MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
273 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0,
276 warnc(error, "Failed to delete volume %s",
277 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
281 /* Delete all the spares. */
282 ioc5 = mpt_read_ioc_page(fd, 5, NULL);
284 warn("Failed to fetch spare list");
286 spare = ioc5->HotSpare;
287 for (i = 0; i < ioc5->NumHotSpares; spare++, i++)
288 if (mpt_delete_physdisk(fd, spare->PhysDiskNum) < 0)
289 warn("Failed to delete physical disk %d",
294 /* Delete any RAID physdisks that may be left. */
295 ioc3 = mpt_read_ioc_page(fd, 3, NULL);
297 warn("Failed to fetch drive list");
299 disk = ioc3->PhysDisk;
300 for (i = 0; i < ioc3->NumPhysDisks; disk++, i++)
301 if (mpt_delete_physdisk(fd, disk->PhysDiskNum) < 0)
302 warn("Failed to delete physical disk %d",
307 printf("mpt%d: Configuration cleared\n", mpt_unit);
308 mpt_rescan_bus(-1, -1);
313 MPT_COMMAND(top, clear, clear_config);
319 static struct raid_type_entry {
322 } raid_type_table[] = {
323 { "raid0", RT_RAID0 },
324 { "raid-0", RT_RAID0 },
325 { "raid1", RT_RAID1 },
326 { "raid-1", RT_RAID1 },
327 { "mirror", RT_RAID1 },
328 { "raid1e", RT_RAID1E },
329 { "raid-1e", RT_RAID1E },
333 struct config_id_state {
334 struct mpt_standalone_disk *sdisks;
335 struct mpt_drive_list *list;
336 CONFIG_PAGE_IOC_2 *ioc2;
342 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
343 struct mpt_standalone_disk *sdisk;
348 struct drive_info *drives;
351 /* Parse a comma-separated list of drives for a volume. */
353 parse_volume(int fd, int raid_type, struct config_id_state *state,
354 char *volume_str, struct volume_info *info)
356 struct drive_info *dinfo;
362 for (count = 0; cp != NULL; count++) {
363 cp = strchr(cp, ',');
367 warnx("Invalid drive list '%s'", volume_str);
373 /* Validate the number of drives for this volume. */
377 warnx("RAID0 requires at least 2 drives in each "
384 warnx("RAID1 requires exactly 2 drives in each "
391 warnx("RAID1E requires at least 3 drives in each "
398 /* Validate each drive. */
399 info->drives = calloc(count, sizeof(struct drive_info));
400 info->drive_count = count;
401 for (dinfo = info->drives; (cp = strsep(&volume_str, ",")) != NULL;
403 /* If this drive is already a RAID phys just fetch the info. */
404 error = mpt_lookup_drive(state->list, cp, &PhysDiskNum);
406 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
407 if (dinfo->info == NULL)
412 /* See if it is a standalone disk. */
413 if (mpt_lookup_standalone_disk(cp, state->sdisks,
414 state->nsdisks, &i) < 0) {
416 warn("Unable to lookup drive %s", cp);
419 dinfo->sdisk = &state->sdisks[i];
421 /* Lock the disk, we will create phys disk pages later. */
422 if (mpt_lock_physdisk(dinfo->sdisk) < 0)
430 * Add RAID physdisk pages for any standalone disks that a volume is
434 add_drives(int fd, struct volume_info *info, int verbose)
436 struct drive_info *dinfo;
440 for (i = 0, dinfo = info->drives; i < info->drive_count;
442 if (dinfo->info == NULL) {
443 if (mpt_create_physdisk(fd, dinfo->sdisk,
447 "Failed to create physical disk page for %s",
448 dinfo->sdisk->devname);
452 printf("Added drive %s with PhysDiskNum %u\n",
453 dinfo->sdisk->devname, PhysDiskNum);
455 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
456 if (dinfo->info == NULL)
464 * Find the next free target ID assuming that 'target_id' is the last
465 * one used. 'target_id' should be 0xff for the initial test.
468 find_next_volume(struct config_id_state *state)
470 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
474 /* Assume the current one is used. */
477 /* Search drives first. */
478 for (i = 0; i < state->nsdisks; i++)
479 if (state->sdisks[i].target == state->target_id)
481 for (i = 0; i < state->list->ndrives; i++)
482 if (state->list->drives[i]->PhysDiskID == state->target_id)
485 /* Search volumes second. */
486 vol = state->ioc2->RaidVolume;
487 for (i = 0; i < state->ioc2->NumActiveVolumes; vol++, i++)
488 if (vol->VolumeID == state->target_id)
491 return (state->target_id);
494 /* Create a volume and populate it with drives. */
495 static CONFIG_PAGE_RAID_VOL_0 *
496 build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size,
497 struct config_id_state *state, int verbose)
499 CONFIG_PAGE_HEADER header;
500 CONFIG_PAGE_RAID_VOL_0 *vol;
501 RAID_VOL0_PHYS_DISK *rdisk;
502 struct drive_info *dinfo;
508 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME,
509 0, 0, &header, NULL);
514 if (header.PageVersion > MPI_RAIDVOLPAGE0_PAGEVERSION) {
515 warnx("Unsupported RAID volume page 0 version %d",
520 page_size = sizeof(CONFIG_PAGE_RAID_VOL_0) +
521 sizeof(RAID_VOL0_PHYS_DISK) * (info->drive_count - 1);
522 vol = calloc(1, page_size);
527 vol->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
528 vol->Header.PageNumber = 0;
529 vol->Header.PageLength = page_size / 4;
532 vol->VolumeID = find_next_volume(state);
534 vol->VolumeIOC = 0; /* XXX */
535 vol->VolumeStatus.Flags = MPI_RAIDVOL0_STATUS_FLAG_ENABLED;
536 vol->VolumeStatus.State = MPI_RAIDVOL0_STATUS_STATE_OPTIMAL;
537 vol->VolumeSettings.Settings = MPI_RAIDVOL0_SETTING_USE_DEFAULTS;
538 vol->VolumeSettings.HotSparePool = MPI_RAID_HOT_SPARE_POOL_0;
539 vol->NumPhysDisks = info->drive_count;
541 /* Find the smallest drive. */
542 MinLBA = info->drives[0].info->MaxLBA;
543 for (i = 1; i < info->drive_count; i++)
544 if (info->drives[i].info->MaxLBA < MinLBA)
545 MinLBA = info->drives[i].info->MaxLBA;
548 * Now chop off 512MB at the end to leave room for the
549 * metadata. The controller might only use 64MB, but we just
550 * chop off the max to be simple.
552 MinLBA -= (512 * 1024 * 1024) / 512;
556 vol->VolumeType = MPI_RAID_VOL_TYPE_IS;
557 vol->StripeSize = stripe_size / 512;
558 MaxLBA = MinLBA * info->drive_count;
561 vol->VolumeType = MPI_RAID_VOL_TYPE_IM;
562 MaxLBA = MinLBA * (info->drive_count / 2);
565 vol->VolumeType = MPI_RAID_VOL_TYPE_IME;
566 vol->StripeSize = stripe_size / 512;
567 MaxLBA = MinLBA * info->drive_count / 2;
575 * If the controller doesn't support 64-bit addressing and the
576 * new volume is larger than 2^32 blocks, warn the user and
577 * truncate the volume.
579 if (MaxLBA >> 32 != 0 &&
580 !(state->ioc2->CapabilitiesFlags &
581 MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING)) {
583 "Controller does not support volumes > 2TB, truncating volume.");
586 vol->MaxLBA = MaxLBA;
587 vol->MaxLBAHigh = MaxLBA >> 32;
589 /* Populate drives. */
590 for (i = 0, dinfo = info->drives, rdisk = vol->PhysDisk;
591 i < info->drive_count; i++, dinfo++, rdisk++) {
593 printf("Adding drive %u (%u:%u) to volume %u:%u\n",
594 dinfo->info->PhysDiskNum, dinfo->info->PhysDiskBus,
595 dinfo->info->PhysDiskID, vol->VolumeBus,
597 if (raid_type == RT_RAID1) {
600 MPI_RAIDVOL0_PHYSDISK_PRIMARY;
603 MPI_RAIDVOL0_PHYSDISK_SECONDARY;
605 rdisk->PhysDiskMap = i;
606 rdisk->PhysDiskNum = dinfo->info->PhysDiskNum;
613 create_volume(int ac, char **av)
615 CONFIG_PAGE_RAID_VOL_0 *vol;
616 struct config_id_state state;
617 struct volume_info *info;
619 int ch, error, fd, i, quick, raid_type, verbose;
625 warnx("create: volume type required");
629 fd = mpt_open(mpt_unit);
636 /* Lookup the RAID type first. */
638 for (i = 0; raid_type_table[i].name != NULL; i++)
639 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
640 raid_type = raid_type_table[i].raid_type;
644 if (raid_type == -1) {
645 warnx("Unknown or unsupported volume type %s", av[1]);
649 /* Parse any options. */
656 stripe_size = 64 * 1024;
658 while ((ch = getopt(ac, av, "dqs:v")) != -1) {
669 stripe_size = dehumanize(optarg);
670 if ((stripe_size < 512) || (!powerof2(stripe_size))) {
671 warnx("Invalid stripe size %s", optarg);
686 /* Fetch existing config data. */
687 state.ioc2 = mpt_read_ioc_page(fd, 2, NULL);
688 if (state.ioc2 == NULL) {
690 warn("Failed to read volume list");
693 state.list = mpt_pd_list(fd);
694 if (state.list == NULL)
696 error = mpt_fetch_disks(fd, &state.nsdisks, &state.sdisks);
698 warn("Failed to fetch standalone disk list");
701 state.target_id = 0xff;
703 /* Parse the drive list. */
705 warnx("Exactly one drive list is required");
708 info = calloc(1, sizeof(*info));
711 error = parse_volume(fd, raid_type, &state, av[0], info);
715 /* Create RAID physdisk pages for standalone disks. */
716 error = add_drives(fd, info, verbose);
720 /* Build the volume. */
721 vol = build_volume(fd, info, raid_type, stripe_size, &state, verbose);
732 /* Send the new volume to the controller. */
733 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus,
734 vol->VolumeID, 0, quick ? MPI_RAID_ACTION_ADATA_DO_NOT_SYNC : 0,
735 vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1);
738 warn("Failed to add volume");
745 mpt_rescan_bus(vol->VolumeBus, vol->VolumeID);
751 mpt_free_pd_list(state.list);
757 MPT_COMMAND(top, create, create_volume);
760 delete_volume(int ac, char **av)
762 U8 VolumeBus, VolumeID;
766 warnx("delete: volume required");
770 fd = mpt_open(mpt_unit);
777 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
779 warnc(error, "Invalid volume %s", av[1]);
783 if (mpt_lock_volume(VolumeBus, VolumeID) < 0)
786 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus,
787 VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
788 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, NULL,
791 warnc(error, "Failed to delete volume");
795 mpt_rescan_bus(-1, -1);
800 MPT_COMMAND(top, delete, delete_volume);
803 find_volume_spare_pool(int fd, const char *name, int *pool)
805 CONFIG_PAGE_RAID_VOL_0 *info;
806 CONFIG_PAGE_IOC_2 *ioc2;
807 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
808 U8 VolumeBus, VolumeID;
809 int error, i, j, new_pool, pool_count[7];
811 error = mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID);
813 warnc(error, "Invalid volume %s", name);
817 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
822 * Check for an existing pool other than pool 0 (used for
825 if ((info->VolumeSettings.HotSparePool & ~MPI_RAID_HOT_SPARE_POOL_0) !=
827 *pool = 1 << (ffs(info->VolumeSettings.HotSparePool &
828 ~MPI_RAID_HOT_SPARE_POOL_0) - 1);
834 * Try to find a free pool. First, figure out which pools are
837 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
840 warn("Failed to fetch volume list");
843 bzero(pool_count, sizeof(pool_count));
844 vol = ioc2->RaidVolume;
845 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
846 info = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
849 for (j = 0; j < 7; j++)
850 if (info->VolumeSettings.HotSparePool & (1 << (j + 1)))
856 /* Find the pool with the lowest use count. */
858 for (i = 1; i < 7; i++)
859 if (pool_count[i] < pool_count[new_pool])
863 /* Add this pool to the volume. */
864 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
867 info->VolumeSettings.HotSparePool |= (1 << new_pool);
868 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
869 VolumeBus, VolumeID, 0, *(U32 *)&info->VolumeSettings, NULL, 0,
870 NULL, NULL, 0, NULL, NULL, 0);
872 warnx("Failed to add spare pool %d to %s", new_pool,
873 mpt_volume_name(VolumeBus, VolumeID));
878 *pool = (1 << new_pool);
883 add_spare(int ac, char **av)
885 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
886 struct mpt_standalone_disk *sdisks;
887 struct mpt_drive_list *list;
889 int error, fd, i, nsdisks, pool;
892 warnx("add spare: drive required");
896 warnx("add spare: extra arguments");
900 fd = mpt_open(mpt_unit);
908 error = find_volume_spare_pool(fd, av[2], &pool);
912 pool = MPI_RAID_HOT_SPARE_POOL_0;
914 list = mpt_pd_list(fd);
918 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
920 error = mpt_fetch_disks(fd, &nsdisks, &sdisks);
922 warn("Failed to fetch standalone disk list");
926 if (mpt_lookup_standalone_disk(av[1], sdisks, nsdisks, &i) <
929 warn("Unable to lookup drive %s", av[1]);
933 if (mpt_lock_physdisk(&sdisks[i]) < 0)
936 if (mpt_create_physdisk(fd, &sdisks[i], &PhysDiskNum) < 0) {
938 warn("Failed to create physical disk page");
943 mpt_free_pd_list(list);
945 info = mpt_pd_info(fd, PhysDiskNum, NULL);
948 warn("Failed to fetch drive info");
952 info->PhysDiskSettings.HotSparePool = pool;
953 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_PHYSDISK_SETTINGS, 0,
954 0, PhysDiskNum, *(U32 *)&info->PhysDiskSettings, NULL, 0, NULL,
955 NULL, 0, NULL, NULL, 0);
957 warnc(error, "Failed to assign spare");
966 MPT_COMMAND(top, add, add_spare);
969 remove_spare(int ac, char **av)
971 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
972 struct mpt_drive_list *list;
977 warnx("remove spare: drive required");
981 fd = mpt_open(mpt_unit);
988 list = mpt_pd_list(fd);
992 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
994 warn("Failed to find drive %s", av[1]);
997 mpt_free_pd_list(list);
1000 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1003 warn("Failed to fetch drive info");
1007 if (info->PhysDiskSettings.HotSparePool == 0) {
1008 warnx("Drive %u is not a hot spare", PhysDiskNum);
1012 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1014 warn("Failed to delete physical disk page");
1018 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1024 MPT_COMMAND(top, remove, remove_spare);
1030 pd_create(int ac, char **av)
1032 struct mpt_standalone_disk *disks;
1033 int error, fd, i, ndisks;
1037 warnx("pd create: drive required");
1041 fd = mpt_open(mpt_unit);
1048 error = mpt_fetch_disks(fd, &ndisks, &disks);
1050 warn("Failed to fetch standalone disk list");
1054 if (mpt_lookup_standalone_disk(av[1], disks, ndisks, &i) < 0) {
1056 warn("Unable to lookup drive");
1060 if (mpt_lock_physdisk(&disks[i]) < 0)
1063 if (mpt_create_physdisk(fd, &disks[i], &PhysDiskNum) < 0) {
1065 warn("Failed to create physical disk page");
1070 printf("Added drive %s with PhysDiskNum %u\n", av[1], PhysDiskNum);
1076 MPT_COMMAND(pd, create, pd_create);
1079 pd_delete(int ac, char **av)
1081 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
1082 struct mpt_drive_list *list;
1087 warnx("pd delete: drive required");
1091 fd = mpt_open(mpt_unit);
1098 list = mpt_pd_list(fd);
1102 if (mpt_lookup_drive(list, av[1], &PhysDiskNum) < 0) {
1104 warn("Failed to find drive %s", av[1]);
1107 mpt_free_pd_list(list);
1109 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1112 warn("Failed to fetch drive info");
1116 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1118 warn("Failed to delete physical disk page");
1122 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1128 MPT_COMMAND(pd, delete, pd_delete);
1130 /* Display raw data about a volume config. */
1132 dump_config(CONFIG_PAGE_RAID_VOL_0 *vol)
1136 printf("Volume Configuration (Debug):\n");
1138 " Page Header: Type 0x%02x Number 0x%02x Length 0x%02x(%u) Version 0x%02x\n",
1139 vol->Header.PageType, vol->Header.PageNumber,
1140 vol->Header.PageLength, vol->Header.PageLength * 4,
1141 vol->Header.PageVersion);
1142 printf(" Address: %d:%d IOC %d\n", vol->VolumeBus, vol->VolumeID,
1144 printf(" Type: %d (%s)\n", vol->VolumeType,
1145 mpt_raid_level(vol->VolumeType));
1146 printf(" Status: %s (Flags 0x%02x)\n",
1147 mpt_volstate(vol->VolumeStatus.State), vol->VolumeStatus.Flags);
1148 printf(" Settings: 0x%04x (Spare Pools 0x%02x)\n",
1149 vol->VolumeSettings.Settings, vol->VolumeSettings.HotSparePool);
1150 printf(" MaxLBA: %ju\n", (uintmax_t)vol->MaxLBAHigh << 32 |
1152 printf(" Stripe Size: %ld\n", (long)vol->StripeSize * 512);
1153 printf(" %d Disks:\n", vol->NumPhysDisks);
1155 for (i = 0; i < vol->NumPhysDisks; i++)
1156 printf(" Disk %d: Num 0x%02x Map 0x%02x\n", i,
1157 vol->PhysDisk[i].PhysDiskNum, vol->PhysDisk[i].PhysDiskMap);
1161 debug_config(int ac, char **av)
1163 CONFIG_PAGE_RAID_VOL_0 *vol;
1164 U8 VolumeBus, VolumeID;
1168 warnx("debug: volume required");
1172 fd = mpt_open(mpt_unit);
1179 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
1181 warnc(error, "Invalid volume: %s", av[1]);
1185 vol = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
1188 warn("Failed to get volume info");
1198 MPT_COMMAND(top, debug, debug_config);