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.
105 warnc(error, "Unable to lookup volume device name");
108 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, qd.devname);
109 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);
128 warn("Unable to lock disk %s", disk->devname);
135 mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks,
136 int ndisks, int *index)
142 /* Check for a raw <bus>:<id> string. */
143 bus = strtol(name, &cp, 0);
145 id = strtol(cp + 1, &cp, 0);
147 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) {
161 if (name[0] == 'd' && name[1] == 'a') {
162 for (i = 0; i < ndisks; i++) {
163 if (strcmp(name, disks[i].devname) == 0) {
175 * Mark a standalone disk as being a physical disk.
178 mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum)
180 CONFIG_PAGE_HEADER header;
181 CONFIG_PAGE_RAID_PHYS_DISK_0 *config_page;
185 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK,
186 0, 0, &header, NULL);
189 if (header.PageVersion > MPI_RAIDPHYSDISKPAGE0_PAGEVERSION) {
190 warnx("Unsupported RAID physdisk page 0 version %d",
194 config_page = calloc(1, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0));
195 config_page->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
196 config_page->Header.PageNumber = 0;
197 config_page->Header.PageLength = sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0) /
199 config_page->PhysDiskIOC = 0; /* XXX */
200 config_page->PhysDiskBus = disk->bus;
201 config_page->PhysDiskID = disk->target;
203 /* XXX: Enclosure info for PhysDiskSettings? */
204 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0,
205 config_page, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0), NULL,
206 &ActionData, sizeof(ActionData), NULL, NULL, 1);
209 *PhysDiskNum = ActionData & 0xff;
214 mpt_delete_physdisk(int fd, U8 PhysDiskNum)
217 return (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_PHYSDISK, 0, 0,
218 PhysDiskNum, 0, NULL, 0, NULL, NULL, 0, NULL, NULL, 0));
222 * MPT's firmware does not have a clear command. Instead, we
223 * implement it by deleting each array and disk by hand.
226 clear_config(int ac, char **av)
228 CONFIG_PAGE_IOC_2 *ioc2;
229 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
230 CONFIG_PAGE_IOC_3 *ioc3;
231 IOC_3_PHYS_DISK *disk;
232 CONFIG_PAGE_IOC_5 *ioc5;
233 IOC_5_HOT_SPARE *spare;
234 int ch, error, fd, i;
236 fd = mpt_open(mpt_unit);
243 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
246 warn("Failed to fetch volume list");
250 /* Lock all the volumes first. */
251 vol = ioc2->RaidVolume;
252 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
253 if (mpt_lock_volume(vol->VolumeBus, vol->VolumeID) < 0) {
254 warnx("Volume %s is busy and cannot be deleted",
255 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
261 "Are you sure you wish to clear the configuration on mpt%u? [y/N] ",
264 if (ch != 'y' && ch != 'Y') {
265 printf("\nAborting\n");
269 /* Delete all the volumes. */
270 vol = ioc2->RaidVolume;
271 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
272 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME,
273 vol->VolumeBus, vol->VolumeID, 0,
274 MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
275 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0,
278 warnc(error, "Failed to delete volume %s",
279 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
283 /* Delete all the spares. */
284 ioc5 = mpt_read_ioc_page(fd, 5, NULL);
286 warn("Failed to fetch spare list");
288 spare = ioc5->HotSpare;
289 for (i = 0; i < ioc5->NumHotSpares; spare++, i++)
290 if (mpt_delete_physdisk(fd, spare->PhysDiskNum) < 0)
291 warn("Failed to delete physical disk %d",
296 /* Delete any RAID physdisks that may be left. */
297 ioc3 = mpt_read_ioc_page(fd, 3, NULL);
299 warn("Failed to fetch drive list");
301 disk = ioc3->PhysDisk;
302 for (i = 0; i < ioc3->NumPhysDisks; disk++, i++)
303 if (mpt_delete_physdisk(fd, disk->PhysDiskNum) < 0)
304 warn("Failed to delete physical disk %d",
309 printf("mpt%d: Configuration cleared\n", mpt_unit);
310 mpt_rescan_bus(-1, -1);
315 MPT_COMMAND(top, clear, clear_config);
321 static struct raid_type_entry {
324 } raid_type_table[] = {
325 { "raid0", RT_RAID0 },
326 { "raid-0", RT_RAID0 },
327 { "raid1", RT_RAID1 },
328 { "raid-1", RT_RAID1 },
329 { "mirror", RT_RAID1 },
330 { "raid1e", RT_RAID1E },
331 { "raid-1e", RT_RAID1E },
335 struct config_id_state {
336 struct mpt_standalone_disk *sdisks;
337 struct mpt_drive_list *list;
338 CONFIG_PAGE_IOC_2 *ioc2;
344 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
345 struct mpt_standalone_disk *sdisk;
350 struct drive_info *drives;
353 /* Parse a comma-separated list of drives for a volume. */
355 parse_volume(int fd, int raid_type, struct config_id_state *state,
356 char *volume_str, struct volume_info *info)
358 struct drive_info *dinfo;
364 for (count = 0; cp != NULL; count++) {
365 cp = strchr(cp, ',');
369 warnx("Invalid drive list '%s'", volume_str);
375 /* Validate the number of drives for this volume. */
379 warnx("RAID0 requires at least 2 drives in each "
386 warnx("RAID1 requires exactly 2 drives in each "
393 warnx("RAID1E requires at least 3 drives in each "
400 /* Validate each drive. */
401 info->drives = calloc(count, sizeof(struct drive_info));
402 info->drive_count = count;
403 for (dinfo = info->drives; (cp = strsep(&volume_str, ",")) != NULL;
405 /* If this drive is already a RAID phys just fetch the info. */
406 error = mpt_lookup_drive(state->list, cp, &PhysDiskNum);
408 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
409 if (dinfo->info == NULL)
414 /* See if it is a standalone disk. */
415 if (mpt_lookup_standalone_disk(cp, state->sdisks,
416 state->nsdisks, &i) < 0) {
418 warn("Unable to lookup drive %s", cp);
421 dinfo->sdisk = &state->sdisks[i];
423 /* Lock the disk, we will create phys disk pages later. */
424 if (mpt_lock_physdisk(dinfo->sdisk) < 0)
432 * Add RAID physdisk pages for any standalone disks that a volume is
436 add_drives(int fd, struct volume_info *info, int verbose)
438 struct drive_info *dinfo;
442 for (i = 0, dinfo = info->drives; i < info->drive_count;
444 if (dinfo->info == NULL) {
445 if (mpt_create_physdisk(fd, dinfo->sdisk,
449 "Failed to create physical disk page for %s",
450 dinfo->sdisk->devname);
454 printf("Added drive %s with PhysDiskNum %u\n",
455 dinfo->sdisk->devname, PhysDiskNum);
457 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
458 if (dinfo->info == NULL)
466 * Find the next free target ID assuming that 'target_id' is the last
467 * one used. 'target_id' should be 0xff for the initial test.
470 find_next_volume(struct config_id_state *state)
472 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
476 /* Assume the current one is used. */
479 /* Search drives first. */
480 for (i = 0; i < state->nsdisks; i++)
481 if (state->sdisks[i].target == state->target_id)
483 for (i = 0; i < state->list->ndrives; i++)
484 if (state->list->drives[i]->PhysDiskID == state->target_id)
487 /* Seach volumes second. */
488 vol = state->ioc2->RaidVolume;
489 for (i = 0; i < state->ioc2->NumActiveVolumes; vol++, i++)
490 if (vol->VolumeID == state->target_id)
493 return (state->target_id);
496 /* Create a volume and populate it with drives. */
497 static CONFIG_PAGE_RAID_VOL_0 *
498 build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size,
499 struct config_id_state *state, int verbose)
501 CONFIG_PAGE_HEADER header;
502 CONFIG_PAGE_RAID_VOL_0 *vol;
503 RAID_VOL0_PHYS_DISK *rdisk;
504 struct drive_info *dinfo;
510 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME,
511 0, 0, &header, NULL);
516 if (header.PageVersion > MPI_RAIDVOLPAGE0_PAGEVERSION) {
517 warnx("Unsupported RAID volume page 0 version %d",
522 page_size = sizeof(CONFIG_PAGE_RAID_VOL_0) +
523 sizeof(RAID_VOL0_PHYS_DISK) * (info->drive_count - 1);
524 vol = calloc(1, page_size);
529 vol->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
530 vol->Header.PageNumber = 0;
531 vol->Header.PageLength = page_size / 4;
534 vol->VolumeID = find_next_volume(state);
536 vol->VolumeIOC = 0; /* XXX */
537 vol->VolumeStatus.Flags = MPI_RAIDVOL0_STATUS_FLAG_ENABLED;
538 vol->VolumeStatus.State = MPI_RAIDVOL0_STATUS_STATE_OPTIMAL;
539 vol->VolumeSettings.Settings = MPI_RAIDVOL0_SETTING_USE_DEFAULTS;
540 vol->VolumeSettings.HotSparePool = MPI_RAID_HOT_SPARE_POOL_0;
541 vol->NumPhysDisks = info->drive_count;
543 /* Find the smallest drive. */
544 MinLBA = info->drives[0].info->MaxLBA;
545 for (i = 1; i < info->drive_count; i++)
546 if (info->drives[i].info->MaxLBA < MinLBA)
547 MinLBA = info->drives[i].info->MaxLBA;
550 * Now chop off 512MB at the end to leave room for the
551 * metadata. The controller might only use 64MB, but we just
552 * chop off the max to be simple.
554 MinLBA -= (512 * 1024 * 1024) / 512;
558 vol->VolumeType = MPI_RAID_VOL_TYPE_IS;
559 vol->StripeSize = stripe_size / 512;
560 MaxLBA = MinLBA * info->drive_count;
563 vol->VolumeType = MPI_RAID_VOL_TYPE_IM;
564 MaxLBA = MinLBA * (info->drive_count / 2);
567 vol->VolumeType = MPI_RAID_VOL_TYPE_IME;
568 vol->StripeSize = stripe_size / 512;
569 MaxLBA = MinLBA * info->drive_count / 2;
577 * If the controller doesn't support 64-bit addressing and the
578 * new volume is larger than 2^32 blocks, warn the user and
579 * truncate the volume.
581 if (MaxLBA >> 32 != 0 &&
582 !(state->ioc2->CapabilitiesFlags &
583 MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING)) {
585 "Controller does not support volumes > 2TB, truncating volume.");
588 vol->MaxLBA = MaxLBA;
589 vol->MaxLBAHigh = MaxLBA >> 32;
591 /* Populate drives. */
592 for (i = 0, dinfo = info->drives, rdisk = vol->PhysDisk;
593 i < info->drive_count; i++, dinfo++, rdisk++) {
595 printf("Adding drive %u (%u:%u) to volume %u:%u\n",
596 dinfo->info->PhysDiskNum, dinfo->info->PhysDiskBus,
597 dinfo->info->PhysDiskID, vol->VolumeBus,
599 if (raid_type == RT_RAID1) {
602 MPI_RAIDVOL0_PHYSDISK_PRIMARY;
605 MPI_RAIDVOL0_PHYSDISK_SECONDARY;
607 rdisk->PhysDiskMap = i;
608 rdisk->PhysDiskNum = dinfo->info->PhysDiskNum;
615 create_volume(int ac, char **av)
617 CONFIG_PAGE_RAID_VOL_0 *vol;
618 struct config_id_state state;
619 struct volume_info *info;
621 int ch, error, fd, i, quick, raid_type, verbose;
627 warnx("create: volume type required");
631 fd = mpt_open(mpt_unit);
638 /* Lookup the RAID type first. */
640 for (i = 0; raid_type_table[i].name != NULL; i++)
641 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
642 raid_type = raid_type_table[i].raid_type;
646 if (raid_type == -1) {
647 warnx("Unknown or unsupported volume type %s", av[1]);
651 /* Parse any options. */
658 stripe_size = 64 * 1024;
660 while ((ch = getopt(ac, av, "dqs:v")) != -1) {
671 stripe_size = dehumanize(optarg);
672 if ((stripe_size < 512) || (!powerof2(stripe_size))) {
673 warnx("Invalid stripe size %s", optarg);
688 /* Fetch existing config data. */
689 state.ioc2 = mpt_read_ioc_page(fd, 2, NULL);
690 if (state.ioc2 == NULL) {
692 warn("Failed to read volume list");
695 state.list = mpt_pd_list(fd);
696 if (state.list == NULL)
698 error = mpt_fetch_disks(fd, &state.nsdisks, &state.sdisks);
700 warn("Failed to fetch standalone disk list");
703 state.target_id = 0xff;
705 /* Parse the drive list. */
707 warnx("Exactly one drive list is required");
710 info = calloc(1, sizeof(*info));
713 error = parse_volume(fd, raid_type, &state, av[0], info);
717 /* Create RAID physdisk pages for standalone disks. */
718 error = add_drives(fd, info, verbose);
722 /* Build the volume. */
723 vol = build_volume(fd, info, raid_type, stripe_size, &state, verbose);
734 /* Send the new volume to the controller. */
735 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus,
736 vol->VolumeID, 0, quick ? MPI_RAID_ACTION_ADATA_DO_NOT_SYNC : 0,
737 vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1);
740 warn("Failed to add volume");
747 mpt_rescan_bus(vol->VolumeBus, vol->VolumeID);
753 mpt_free_pd_list(state.list);
759 MPT_COMMAND(top, create, create_volume);
762 delete_volume(int ac, char **av)
764 U8 VolumeBus, VolumeID;
768 warnx("delete: volume required");
772 fd = mpt_open(mpt_unit);
779 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
781 warnc(error, "Invalid volume %s", av[1]);
785 if (mpt_lock_volume(VolumeBus, VolumeID) < 0)
788 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus,
789 VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
790 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, NULL,
793 warnc(error, "Failed to delete volume");
797 mpt_rescan_bus(-1, -1);
802 MPT_COMMAND(top, delete, delete_volume);
805 find_volume_spare_pool(int fd, const char *name, int *pool)
807 CONFIG_PAGE_RAID_VOL_0 *info;
808 CONFIG_PAGE_IOC_2 *ioc2;
809 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
810 U8 VolumeBus, VolumeID;
811 int error, i, j, new_pool, pool_count[7];
813 error = mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID);
815 warnc(error, "Invalid volume %s", name);
819 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
824 * Check for an existing pool other than pool 0 (used for
827 if ((info->VolumeSettings.HotSparePool & ~MPI_RAID_HOT_SPARE_POOL_0) !=
829 *pool = 1 << (ffs(info->VolumeSettings.HotSparePool &
830 ~MPI_RAID_HOT_SPARE_POOL_0) - 1);
836 * Try to find a free pool. First, figure out which pools are
839 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
842 warn("Failed to fetch volume list");
845 bzero(pool_count, sizeof(pool_count));
846 vol = ioc2->RaidVolume;
847 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
848 info = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
851 for (j = 0; j < 7; j++)
852 if (info->VolumeSettings.HotSparePool & (1 << (j + 1)))
858 /* Find the pool with the lowest use count. */
860 for (i = 1; i < 7; i++)
861 if (pool_count[i] < pool_count[new_pool])
865 /* Add this pool to the volume. */
866 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
869 info->VolumeSettings.HotSparePool |= (1 << new_pool);
870 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
871 VolumeBus, VolumeID, 0, *(U32 *)&info->VolumeSettings, NULL, 0,
872 NULL, NULL, 0, NULL, NULL, 0);
874 warnx("Failed to add spare pool %d to %s", new_pool,
875 mpt_volume_name(VolumeBus, VolumeID));
880 *pool = (1 << new_pool);
885 add_spare(int ac, char **av)
887 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
888 struct mpt_standalone_disk *sdisks;
889 struct mpt_drive_list *list;
891 int error, fd, i, nsdisks, pool;
894 warnx("add spare: drive required");
898 warnx("add spare: extra arguments");
902 fd = mpt_open(mpt_unit);
910 error = find_volume_spare_pool(fd, av[2], &pool);
914 pool = MPI_RAID_HOT_SPARE_POOL_0;
916 list = mpt_pd_list(fd);
920 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
922 error = mpt_fetch_disks(fd, &nsdisks, &sdisks);
924 warn("Failed to fetch standalone disk list");
928 if (mpt_lookup_standalone_disk(av[1], sdisks, nsdisks, &i) <
931 warn("Unable to lookup drive %s", av[1]);
935 if (mpt_lock_physdisk(&sdisks[i]) < 0)
938 if (mpt_create_physdisk(fd, &sdisks[i], &PhysDiskNum) < 0) {
940 warn("Failed to create physical disk page");
945 mpt_free_pd_list(list);
947 info = mpt_pd_info(fd, PhysDiskNum, NULL);
950 warn("Failed to fetch drive info");
954 info->PhysDiskSettings.HotSparePool = pool;
955 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_PHYSDISK_SETTINGS, 0,
956 0, PhysDiskNum, *(U32 *)&info->PhysDiskSettings, NULL, 0, NULL,
957 NULL, 0, NULL, NULL, 0);
959 warnc(error, "Failed to assign spare");
968 MPT_COMMAND(top, add, add_spare);
971 remove_spare(int ac, char **av)
973 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
974 struct mpt_drive_list *list;
979 warnx("remove spare: drive required");
983 fd = mpt_open(mpt_unit);
990 list = mpt_pd_list(fd);
994 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
996 warn("Failed to find drive %s", av[1]);
999 mpt_free_pd_list(list);
1002 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1005 warn("Failed to fetch drive info");
1009 if (info->PhysDiskSettings.HotSparePool == 0) {
1010 warnx("Drive %u is not a hot spare", PhysDiskNum);
1014 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1016 warn("Failed to delete physical disk page");
1020 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1026 MPT_COMMAND(top, remove, remove_spare);
1032 pd_create(int ac, char **av)
1034 struct mpt_standalone_disk *disks;
1035 int error, fd, i, ndisks;
1039 warnx("pd create: drive required");
1043 fd = mpt_open(mpt_unit);
1050 error = mpt_fetch_disks(fd, &ndisks, &disks);
1052 warn("Failed to fetch standalone disk list");
1056 if (mpt_lookup_standalone_disk(av[1], disks, ndisks, &i) < 0) {
1058 warn("Unable to lookup drive");
1062 if (mpt_lock_physdisk(&disks[i]) < 0)
1065 if (mpt_create_physdisk(fd, &disks[i], &PhysDiskNum) < 0) {
1067 warn("Failed to create physical disk page");
1072 printf("Added drive %s with PhysDiskNum %u\n", av[1], PhysDiskNum);
1078 MPT_COMMAND(pd, create, pd_create);
1081 pd_delete(int ac, char **av)
1083 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
1084 struct mpt_drive_list *list;
1089 warnx("pd delete: drive required");
1093 fd = mpt_open(mpt_unit);
1100 list = mpt_pd_list(fd);
1104 if (mpt_lookup_drive(list, av[1], &PhysDiskNum) < 0) {
1106 warn("Failed to find drive %s", av[1]);
1109 mpt_free_pd_list(list);
1111 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1114 warn("Failed to fetch drive info");
1118 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1120 warn("Failed to delete physical disk page");
1124 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1130 MPT_COMMAND(pd, delete, pd_delete);
1132 /* Display raw data about a volume config. */
1134 dump_config(CONFIG_PAGE_RAID_VOL_0 *vol)
1138 printf("Volume Configuration (Debug):\n");
1140 " Page Header: Type 0x%02x Number 0x%02x Length 0x%02x(%u) Version 0x%02x\n",
1141 vol->Header.PageType, vol->Header.PageNumber,
1142 vol->Header.PageLength, vol->Header.PageLength * 4,
1143 vol->Header.PageVersion);
1144 printf(" Address: %d:%d IOC %d\n", vol->VolumeBus, vol->VolumeID,
1146 printf(" Type: %d (%s)\n", vol->VolumeType,
1147 mpt_raid_level(vol->VolumeType));
1148 printf(" Status: %s (Flags 0x%02x)\n",
1149 mpt_volstate(vol->VolumeStatus.State), vol->VolumeStatus.Flags);
1150 printf(" Settings: 0x%04x (Spare Pools 0x%02x)\n",
1151 vol->VolumeSettings.Settings, vol->VolumeSettings.HotSparePool);
1152 printf(" MaxLBA: %ju\n", (uintmax_t)vol->MaxLBAHigh << 32 |
1154 printf(" Stripe Size: %ld\n", (long)vol->StripeSize * 512);
1155 printf(" %d Disks:\n", vol->NumPhysDisks);
1157 for (i = 0; i < vol->NumPhysDisks; i++)
1158 printf(" Disk %d: Num 0x%02x Map 0x%02x\n", i,
1159 vol->PhysDisk[i].PhysDiskNum, vol->PhysDisk[i].PhysDiskMap);
1163 debug_config(int ac, char **av)
1165 CONFIG_PAGE_RAID_VOL_0 *vol;
1166 U8 VolumeBus, VolumeID;
1170 warnx("debug: volume required");
1174 fd = mpt_open(mpt_unit);
1181 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
1183 warnc(error, "Invalid volume: %s", av[1]);
1187 vol = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
1190 warn("Failed to get volume info");
1200 MPT_COMMAND(top, debug, debug_config);