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
30 * $FreeBSD: src/usr.sbin/mptutil/mpt_config.c,v 1.3 2010/11/22 14:36:04 jhb Exp $
33 #include <sys/param.h>
34 #include <sys/errno.h>
49 static void dump_config(CONFIG_PAGE_RAID_VOL_0 *vol);
53 dehumanize(const char *value)
60 iv = strtoq(value, &vtp, 0);
61 if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
82 * Lock the volume by opening its /dev device read/write. This will
83 * only work if nothing else has it opened (including mounts). We
84 * leak the fd on purpose since this application is not long-running.
87 mpt_lock_volume(U8 VolumeBus, U8 VolumeID)
89 char path[MAXPATHLEN];
90 struct mpt_query_disk qd;
93 error = mpt_query_disk(VolumeBus, VolumeID, &qd);
96 * This means there isn't a CAM device associated with
97 * the volume, and thus it is already implicitly
98 * locked, so just return.
102 warnc(error, "Unable to lookup volume device name");
105 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, qd.devname);
106 vfd = open(path, O_RDWR);
109 warn("Unable to lock volume %s", qd.devname);
116 mpt_lock_physdisk(struct mpt_standalone_disk *disk)
118 char path[MAXPATHLEN];
121 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk->devname);
122 dfd = open(path, O_RDWR);
125 warn("Unable to lock disk %s", disk->devname);
132 mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks,
133 int ndisks, int *idx)
139 /* Check for a raw <bus>:<id> string. */
140 bus = strtol(name, &cp, 0);
142 id = strtol(cp + 1, &cp, 0);
144 if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) {
147 for (i = 0; i < ndisks; i++) {
148 if (disks[i].bus == (U8)bus &&
149 disks[i].target == (U8)id) {
158 if (name[0] == 'd' && name[1] == 'a') {
159 for (i = 0; i < ndisks; i++) {
160 if (strcmp(name, disks[i].devname) == 0) {
172 * Mark a standalone disk as being a physical disk.
175 mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum)
177 CONFIG_PAGE_HEADER header;
178 CONFIG_PAGE_RAID_PHYS_DISK_0 *config_page;
182 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK,
183 0, 0, &header, NULL);
186 if (header.PageVersion > MPI_RAIDPHYSDISKPAGE0_PAGEVERSION) {
187 warnx("Unsupported RAID physdisk page 0 version %d",
191 config_page = calloc(1, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0));
192 config_page->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
193 config_page->Header.PageNumber = 0;
194 config_page->Header.PageLength = sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0) /
196 config_page->PhysDiskIOC = 0; /* XXX */
197 config_page->PhysDiskBus = disk->bus;
198 config_page->PhysDiskID = disk->target;
200 /* XXX: Enclosure info for PhysDiskSettings? */
201 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0,
202 config_page, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0), NULL,
203 &ActionData, sizeof(ActionData), NULL, NULL, 1);
206 *PhysDiskNum = ActionData & 0xff;
211 mpt_delete_physdisk(int fd, U8 PhysDiskNum)
214 return (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_PHYSDISK, 0, 0,
215 PhysDiskNum, 0, NULL, 0, NULL, NULL, 0, NULL, NULL, 0));
219 * MPT's firmware does not have a clear command. Instead, we
220 * implement it by deleting each array and disk by hand.
223 clear_config(int ac __unused, char **av __unused)
225 CONFIG_PAGE_IOC_2 *ioc2;
226 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
227 CONFIG_PAGE_IOC_3 *ioc3;
228 IOC_3_PHYS_DISK *disk;
229 CONFIG_PAGE_IOC_5 *ioc5;
230 IOC_5_HOT_SPARE *spare;
231 int ch, error, fd, i;
233 fd = mpt_open(mpt_unit);
240 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
243 warn("Failed to fetch volume list");
247 /* Lock all the volumes first. */
248 vol = ioc2->RaidVolume;
249 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
250 if (mpt_lock_volume(vol->VolumeBus, vol->VolumeID) < 0) {
251 warnx("Volume %s is busy and cannot be deleted",
252 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
258 "Are you sure you wish to clear the configuration on mpt%u? [y/N] ",
261 if (ch != 'y' && ch != 'Y') {
262 printf("\nAborting\n");
266 /* Delete all the volumes. */
267 vol = ioc2->RaidVolume;
268 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
269 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME,
270 vol->VolumeBus, vol->VolumeID, 0,
271 MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
272 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0,
275 warnc(error, "Failed to delete volume %s",
276 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) {
415 warn("Unable to lookup drive %s", cp);
418 dinfo->sdisk = &state->sdisks[i];
420 /* Lock the disk, we will create phys disk pages later. */
421 if (mpt_lock_physdisk(dinfo->sdisk) < 0)
429 * Add RAID physdisk pages for any standalone disks that a volume is
433 add_drives(int fd, struct volume_info *info, int verbose)
435 struct drive_info *dinfo;
439 for (i = 0, dinfo = info->drives; i < info->drive_count;
441 if (dinfo->info == NULL) {
442 if (mpt_create_physdisk(fd, dinfo->sdisk,
446 "Failed to create physical disk page for %s",
447 dinfo->sdisk->devname);
451 printf("Added drive %s with PhysDiskNum %u\n",
452 dinfo->sdisk->devname, PhysDiskNum);
454 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
455 if (dinfo->info == NULL)
463 * Find the next free target ID assuming that 'target_id' is the last
464 * one used. 'target_id' should be 0xff for the initial test.
467 find_next_volume(struct config_id_state *state)
469 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
473 /* Assume the current one is used. */
476 /* Search drives first. */
477 for (i = 0; i < state->nsdisks; i++)
478 if (state->sdisks[i].target == state->target_id)
480 for (i = 0; i < state->list->ndrives; i++)
481 if (state->list->drives[i]->PhysDiskID == state->target_id)
484 /* Seach volumes second. */
485 vol = state->ioc2->RaidVolume;
486 for (i = 0; i < state->ioc2->NumActiveVolumes; vol++, i++)
487 if (vol->VolumeID == state->target_id)
490 return (state->target_id);
493 /* Create a volume and populate it with drives. */
494 static CONFIG_PAGE_RAID_VOL_0 *
495 build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size,
496 struct config_id_state *state, int verbose)
498 CONFIG_PAGE_HEADER header;
499 CONFIG_PAGE_RAID_VOL_0 *vol;
500 RAID_VOL0_PHYS_DISK *rdisk;
501 struct drive_info *dinfo;
507 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME,
508 0, 0, &header, NULL);
513 if (header.PageVersion > MPI_RAIDVOLPAGE0_PAGEVERSION) {
514 warnx("Unsupported RAID volume page 0 version %d",
519 page_size = sizeof(CONFIG_PAGE_RAID_VOL_0) +
520 sizeof(RAID_VOL0_PHYS_DISK) * (info->drive_count - 1);
521 vol = calloc(1, page_size);
526 vol->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
527 vol->Header.PageNumber = 0;
528 vol->Header.PageLength = page_size / 4;
531 vol->VolumeID = find_next_volume(state);
533 vol->VolumeIOC = 0; /* XXX */
534 vol->VolumeStatus.Flags = MPI_RAIDVOL0_STATUS_FLAG_ENABLED;
535 vol->VolumeStatus.State = MPI_RAIDVOL0_STATUS_STATE_OPTIMAL;
536 vol->VolumeSettings.Settings = MPI_RAIDVOL0_SETTING_USE_DEFAULTS;
537 vol->VolumeSettings.HotSparePool = MPI_RAID_HOT_SPARE_POOL_0;
538 vol->NumPhysDisks = info->drive_count;
540 /* Find the smallest drive. */
541 MinLBA = info->drives[0].info->MaxLBA;
542 for (i = 1; i < info->drive_count; i++)
543 if (info->drives[i].info->MaxLBA < MinLBA)
544 MinLBA = info->drives[i].info->MaxLBA;
547 * Now chop off 512MB at the end to leave room for the
548 * metadata. The controller might only use 64MB, but we just
549 * chop off the max to be simple.
551 MinLBA -= (512 * 1024 * 1024) / 512;
555 vol->VolumeType = MPI_RAID_VOL_TYPE_IS;
556 vol->StripeSize = stripe_size / 512;
557 MaxLBA = MinLBA * info->drive_count;
560 vol->VolumeType = MPI_RAID_VOL_TYPE_IM;
561 MaxLBA = MinLBA * (info->drive_count / 2);
564 vol->VolumeType = MPI_RAID_VOL_TYPE_IME;
565 vol->StripeSize = stripe_size / 512;
566 MaxLBA = MinLBA * info->drive_count / 2;
574 * If the controller doesn't support 64-bit addressing and the
575 * new volume is larger than 2^32 blocks, warn the user and
576 * truncate the volume.
578 if (MaxLBA >> 32 != 0 &&
579 !(state->ioc2->CapabilitiesFlags &
580 MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING)) {
582 "Controller does not support volumes > 2TB, truncating volume.");
585 vol->MaxLBA = MaxLBA;
586 vol->MaxLBAHigh = MaxLBA >> 32;
588 /* Populate drives. */
589 for (i = 0, dinfo = info->drives, rdisk = vol->PhysDisk;
590 i < info->drive_count; i++, dinfo++, rdisk++) {
592 printf("Adding drive %u (%u:%u) to volume %u:%u\n",
593 dinfo->info->PhysDiskNum, dinfo->info->PhysDiskBus,
594 dinfo->info->PhysDiskID, vol->VolumeBus,
596 if (raid_type == RT_RAID1) {
599 MPI_RAIDVOL0_PHYSDISK_PRIMARY;
602 MPI_RAIDVOL0_PHYSDISK_SECONDARY;
604 rdisk->PhysDiskMap = i;
605 rdisk->PhysDiskNum = dinfo->info->PhysDiskNum;
612 create_volume(int ac, char **av)
614 CONFIG_PAGE_RAID_VOL_0 *vol;
615 struct config_id_state state;
616 struct volume_info *info;
618 int ch, error, fd, i, quick, raid_type, verbose;
624 warnx("create: volume type required");
628 fd = mpt_open(mpt_unit);
635 /* Lookup the RAID type first. */
637 for (i = 0; raid_type_table[i].name != NULL; i++)
638 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
639 raid_type = raid_type_table[i].raid_type;
643 if (raid_type == -1) {
644 warnx("Unknown or unsupported volume type %s", av[1]);
648 /* Parse any options. */
655 stripe_size = 64 * 1024;
657 while ((ch = getopt(ac, av, "dqs:v")) != -1) {
668 stripe_size = dehumanize(optarg);
669 if ((stripe_size < 512) || (!powerof2(stripe_size))) {
670 warnx("Invalid stripe size %s", optarg);
685 /* Fetch existing config data. */
686 state.ioc2 = mpt_read_ioc_page(fd, 2, NULL);
687 if (state.ioc2 == NULL) {
689 warn("Failed to read volume list");
692 state.list = mpt_pd_list(fd);
693 if (state.list == NULL)
695 error = mpt_fetch_disks(fd, &state.nsdisks, &state.sdisks);
697 warn("Failed to fetch standalone disk list");
700 state.target_id = 0xff;
702 /* Parse the drive list. */
704 warnx("Exactly one drive list is required");
707 info = calloc(1, sizeof(*info));
710 error = parse_volume(fd, raid_type, &state, av[0], info);
714 /* Create RAID physdisk pages for standalone disks. */
715 error = add_drives(fd, info, verbose);
719 /* Build the volume. */
720 vol = build_volume(fd, info, raid_type, stripe_size, &state, verbose);
731 /* Send the new volume to the controller. */
732 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus,
733 vol->VolumeID, 0, quick ? MPI_RAID_ACTION_ADATA_DO_NOT_SYNC : 0,
734 vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1);
737 warn("Failed to add volume");
744 mpt_rescan_bus(vol->VolumeBus, vol->VolumeID);
750 mpt_free_pd_list(state.list);
756 MPT_COMMAND(top, create, create_volume);
759 delete_volume(int ac, char **av)
761 U8 VolumeBus, VolumeID;
765 warnx("delete: volume required");
769 fd = mpt_open(mpt_unit);
776 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
778 warnc(error, "Invalid volume %s", av[1]);
782 if (mpt_lock_volume(VolumeBus, VolumeID) < 0)
785 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus,
786 VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
787 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, NULL,
790 warnc(error, "Failed to delete volume");
794 mpt_rescan_bus(-1, -1);
799 MPT_COMMAND(top, delete, delete_volume);
802 find_volume_spare_pool(int fd, const char *name, int *pool)
804 CONFIG_PAGE_RAID_VOL_0 *info;
805 CONFIG_PAGE_IOC_2 *ioc2;
806 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
807 U8 VolumeBus, VolumeID;
808 int error, i, j, new_pool, pool_count[7];
810 error = mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID);
812 warnc(error, "Invalid volume %s", name);
816 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
821 * Check for an existing pool other than pool 0 (used for
824 if ((info->VolumeSettings.HotSparePool & ~MPI_RAID_HOT_SPARE_POOL_0) !=
826 *pool = 1 << (ffs(info->VolumeSettings.HotSparePool &
827 ~MPI_RAID_HOT_SPARE_POOL_0) - 1);
833 * Try to find a free pool. First, figure out which pools are
836 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
839 warn("Failed to fetch volume list");
842 bzero(pool_count, sizeof(pool_count));
843 vol = ioc2->RaidVolume;
844 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
845 info = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
848 for (j = 0; j < 7; j++)
849 if (info->VolumeSettings.HotSparePool & (1 << (j + 1)))
855 /* Find the pool with the lowest use count. */
857 for (i = 1; i < 7; i++)
858 if (pool_count[i] < pool_count[new_pool])
862 /* Add this pool to the volume. */
863 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
866 info->VolumeSettings.HotSparePool |= (1 << new_pool);
867 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
868 VolumeBus, VolumeID, 0, *(U32 *)&info->VolumeSettings, NULL, 0,
869 NULL, NULL, 0, NULL, NULL, 0);
871 warnx("Failed to add spare pool %d to %s", new_pool,
872 mpt_volume_name(VolumeBus, VolumeID));
877 *pool = (1 << new_pool);
882 add_spare(int ac, char **av)
884 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
885 struct mpt_standalone_disk *sdisks;
886 struct mpt_drive_list *list;
888 int error, fd, i, nsdisks, pool = 0;
891 warnx("add spare: drive required");
895 warnx("add spare: extra arguments");
899 fd = mpt_open(mpt_unit);
907 error = find_volume_spare_pool(fd, av[2], &pool);
911 pool = MPI_RAID_HOT_SPARE_POOL_0;
913 list = mpt_pd_list(fd);
917 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
919 error = mpt_fetch_disks(fd, &nsdisks, &sdisks);
921 warn("Failed to fetch standalone disk list");
925 if (mpt_lookup_standalone_disk(av[1], sdisks, nsdisks, &i) <
928 warn("Unable to lookup drive %s", av[1]);
932 if (mpt_lock_physdisk(&sdisks[i]) < 0)
935 if (mpt_create_physdisk(fd, &sdisks[i], &PhysDiskNum) < 0) {
937 warn("Failed to create physical disk page");
942 mpt_free_pd_list(list);
944 info = mpt_pd_info(fd, PhysDiskNum, NULL);
947 warn("Failed to fetch drive info");
951 info->PhysDiskSettings.HotSparePool = pool;
952 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_PHYSDISK_SETTINGS, 0,
953 0, PhysDiskNum, *(U32 *)&info->PhysDiskSettings, NULL, 0, NULL,
954 NULL, 0, NULL, NULL, 0);
956 warnc(error, "Failed to assign spare");
965 MPT_COMMAND(top, add, add_spare);
968 remove_spare(int ac, char **av)
970 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
971 struct mpt_drive_list *list;
976 warnx("remove spare: drive required");
980 fd = mpt_open(mpt_unit);
987 list = mpt_pd_list(fd);
991 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
993 warn("Failed to find drive %s", av[1]);
996 mpt_free_pd_list(list);
999 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1002 warn("Failed to fetch drive info");
1006 if (info->PhysDiskSettings.HotSparePool == 0) {
1007 warnx("Drive %u is not a hot spare", PhysDiskNum);
1011 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1013 warn("Failed to delete physical disk page");
1017 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1023 MPT_COMMAND(top, remove, remove_spare);
1029 pd_create(int ac, char **av)
1031 struct mpt_standalone_disk *disks;
1032 int error, fd, i, ndisks;
1036 warnx("pd create: drive required");
1040 fd = mpt_open(mpt_unit);
1047 error = mpt_fetch_disks(fd, &ndisks, &disks);
1049 warn("Failed to fetch standalone disk list");
1053 if (mpt_lookup_standalone_disk(av[1], disks, ndisks, &i) < 0) {
1055 warn("Unable to lookup drive");
1059 if (mpt_lock_physdisk(&disks[i]) < 0)
1062 if (mpt_create_physdisk(fd, &disks[i], &PhysDiskNum) < 0) {
1064 warn("Failed to create physical disk page");
1069 printf("Added drive %s with PhysDiskNum %u\n", av[1], PhysDiskNum);
1075 MPT_COMMAND(pd, create, pd_create);
1078 pd_delete(int ac, char **av)
1080 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
1081 struct mpt_drive_list *list;
1086 warnx("pd delete: drive required");
1090 fd = mpt_open(mpt_unit);
1097 list = mpt_pd_list(fd);
1101 if (mpt_lookup_drive(list, av[1], &PhysDiskNum) < 0) {
1103 warn("Failed to find drive %s", av[1]);
1106 mpt_free_pd_list(list);
1108 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1111 warn("Failed to fetch drive info");
1115 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1117 warn("Failed to delete physical disk page");
1121 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1127 MPT_COMMAND(pd, delete, pd_delete);
1129 /* Display raw data about a volume config. */
1131 dump_config(CONFIG_PAGE_RAID_VOL_0 *vol)
1135 printf("Volume Configuration (Debug):\n");
1137 " Page Header: Type 0x%02x Number 0x%02x Length 0x%02x(%u) Version 0x%02x\n",
1138 vol->Header.PageType, vol->Header.PageNumber,
1139 vol->Header.PageLength, vol->Header.PageLength * 4,
1140 vol->Header.PageVersion);
1141 printf(" Address: %d:%d IOC %d\n", vol->VolumeBus, vol->VolumeID,
1143 printf(" Type: %d (%s)\n", vol->VolumeType,
1144 mpt_raid_level(vol->VolumeType));
1145 printf(" Status: %s (Flags 0x%02x)\n",
1146 mpt_volstate(vol->VolumeStatus.State), vol->VolumeStatus.Flags);
1147 printf(" Settings: 0x%04x (Spare Pools 0x%02x)\n",
1148 vol->VolumeSettings.Settings, vol->VolumeSettings.HotSparePool);
1149 printf(" MaxLBA: %ju\n", (uintmax_t)vol->MaxLBAHigh << 32 |
1151 printf(" Stripe Size: %ld\n", (long)vol->StripeSize * 512);
1152 printf(" %d Disks:\n", vol->NumPhysDisks);
1154 for (i = 0; i < vol->NumPhysDisks; i++)
1155 printf(" Disk %d: Num 0x%02x Map 0x%02x\n", i,
1156 vol->PhysDisk[i].PhysDiskNum, vol->PhysDisk[i].PhysDiskMap);
1160 debug_config(int ac, char **av)
1162 CONFIG_PAGE_RAID_VOL_0 *vol;
1163 U8 VolumeBus, VolumeID;
1167 warnx("debug: volume required");
1171 fd = mpt_open(mpt_unit);
1178 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
1180 warnc(error, "Invalid volume: %s", av[1]);
1184 vol = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
1187 warn("Failed to get volume info");
1197 MPT_COMMAND(top, debug, debug_config);