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 * Lock the volume by opening its /dev device read/write. This will
54 * only work if nothing else has it opened (including mounts). We
55 * leak the fd on purpose since this application is not long-running.
58 mpt_lock_volume(U8 VolumeBus, U8 VolumeID)
60 char path[MAXPATHLEN];
61 struct mpt_query_disk qd;
64 error = mpt_query_disk(VolumeBus, VolumeID, &qd);
67 * This means there isn't a CAM device associated with
68 * the volume, and thus it is already implicitly
69 * locked, so just return.
73 warnc(error, "Unable to lookup volume device name");
76 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, qd.devname);
77 vfd = open(path, O_RDWR);
80 warn("Unable to lock volume %s", qd.devname);
87 mpt_lock_physdisk(struct mpt_standalone_disk *disk)
89 char path[MAXPATHLEN];
92 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk->devname);
93 dfd = open(path, O_RDWR);
96 warn("Unable to lock disk %s", disk->devname);
103 mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks,
104 int ndisks, int *idx)
110 /* Check for a raw <bus>:<id> string. */
111 bus = strtol(name, &cp, 0);
113 id = strtol(cp + 1, &cp, 0);
115 if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) {
118 for (i = 0; i < ndisks; i++) {
119 if (disks[i].bus == (U8)bus &&
120 disks[i].target == (U8)id) {
129 if (name[0] == 'd' && name[1] == 'a') {
130 for (i = 0; i < ndisks; i++) {
131 if (strcmp(name, disks[i].devname) == 0) {
143 * Mark a standalone disk as being a physical disk.
146 mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum)
148 CONFIG_PAGE_HEADER header;
149 CONFIG_PAGE_RAID_PHYS_DISK_0 *config_page;
153 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK,
154 0, 0, &header, NULL);
157 if (header.PageVersion > MPI_RAIDPHYSDISKPAGE0_PAGEVERSION) {
158 warnx("Unsupported RAID physdisk page 0 version %d",
162 config_page = calloc(1, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0));
163 config_page->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
164 config_page->Header.PageNumber = 0;
165 config_page->Header.PageLength = sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0) /
167 config_page->PhysDiskIOC = 0; /* XXX */
168 config_page->PhysDiskBus = disk->bus;
169 config_page->PhysDiskID = disk->target;
171 /* XXX: Enclosure info for PhysDiskSettings? */
172 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0,
173 config_page, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0), NULL,
174 &ActionData, sizeof(ActionData), NULL, NULL, 1);
177 *PhysDiskNum = ActionData & 0xff;
182 mpt_delete_physdisk(int fd, U8 PhysDiskNum)
185 return (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_PHYSDISK, 0, 0,
186 PhysDiskNum, 0, NULL, 0, NULL, NULL, 0, NULL, NULL, 0));
190 * MPT's firmware does not have a clear command. Instead, we
191 * implement it by deleting each array and disk by hand.
194 clear_config(int ac __unused, char **av __unused)
196 CONFIG_PAGE_IOC_2 *ioc2;
197 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
198 CONFIG_PAGE_IOC_3 *ioc3;
199 IOC_3_PHYS_DISK *disk;
200 CONFIG_PAGE_IOC_5 *ioc5;
201 IOC_5_HOT_SPARE *spare;
202 int ch, error, fd, i;
204 fd = mpt_open(mpt_unit);
211 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
214 warn("Failed to fetch volume list");
218 /* Lock all the volumes first. */
219 vol = ioc2->RaidVolume;
220 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
221 if (mpt_lock_volume(vol->VolumeBus, vol->VolumeID) < 0) {
222 warnx("Volume %s is busy and cannot be deleted",
223 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
229 "Are you sure you wish to clear the configuration on mpt%u? [y/N] ",
232 if (ch != 'y' && ch != 'Y') {
233 printf("\nAborting\n");
237 /* Delete all the volumes. */
238 vol = ioc2->RaidVolume;
239 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
240 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME,
241 vol->VolumeBus, vol->VolumeID, 0,
242 MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
243 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0,
246 warnc(error, "Failed to delete volume %s",
247 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
251 /* Delete all the spares. */
252 ioc5 = mpt_read_ioc_page(fd, 5, NULL);
254 warn("Failed to fetch spare list");
256 spare = ioc5->HotSpare;
257 for (i = 0; i < ioc5->NumHotSpares; spare++, i++)
258 if (mpt_delete_physdisk(fd, spare->PhysDiskNum) < 0)
259 warn("Failed to delete physical disk %d",
264 /* Delete any RAID physdisks that may be left. */
265 ioc3 = mpt_read_ioc_page(fd, 3, NULL);
267 warn("Failed to fetch drive list");
269 disk = ioc3->PhysDisk;
270 for (i = 0; i < ioc3->NumPhysDisks; disk++, i++)
271 if (mpt_delete_physdisk(fd, disk->PhysDiskNum) < 0)
272 warn("Failed to delete physical disk %d",
277 printf("mpt%d: Configuration cleared\n", mpt_unit);
278 mpt_rescan_bus(-1, -1);
283 MPT_COMMAND(top, clear, clear_config);
289 static struct raid_type_entry {
292 } raid_type_table[] = {
293 { "raid0", RT_RAID0 },
294 { "raid-0", RT_RAID0 },
295 { "raid1", RT_RAID1 },
296 { "raid-1", RT_RAID1 },
297 { "mirror", RT_RAID1 },
298 { "raid1e", RT_RAID1E },
299 { "raid-1e", RT_RAID1E },
303 struct config_id_state {
304 struct mpt_standalone_disk *sdisks;
305 struct mpt_drive_list *list;
306 CONFIG_PAGE_IOC_2 *ioc2;
312 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
313 struct mpt_standalone_disk *sdisk;
318 struct drive_info *drives;
321 /* Parse a comma-separated list of drives for a volume. */
323 parse_volume(int fd, int raid_type, struct config_id_state *state,
324 char *volume_str, struct volume_info *info)
326 struct drive_info *dinfo;
332 for (count = 0; cp != NULL; count++) {
333 cp = strchr(cp, ',');
337 warnx("Invalid drive list '%s'", volume_str);
343 /* Validate the number of drives for this volume. */
347 warnx("RAID0 requires at least 2 drives in each "
354 warnx("RAID1 requires exactly 2 drives in each "
361 warnx("RAID1E requires at least 3 drives in each "
368 /* Validate each drive. */
369 info->drives = calloc(count, sizeof(struct drive_info));
370 info->drive_count = count;
371 for (dinfo = info->drives; (cp = strsep(&volume_str, ",")) != NULL;
373 /* If this drive is already a RAID phys just fetch the info. */
374 error = mpt_lookup_drive(state->list, cp, &PhysDiskNum);
376 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
377 if (dinfo->info == NULL)
382 /* See if it is a standalone disk. */
383 if (mpt_lookup_standalone_disk(cp, state->sdisks,
384 state->nsdisks, &i) < 0) {
386 warn("Unable to lookup drive %s", cp);
389 dinfo->sdisk = &state->sdisks[i];
391 /* Lock the disk, we will create phys disk pages later. */
392 if (mpt_lock_physdisk(dinfo->sdisk) < 0)
400 * Add RAID physdisk pages for any standalone disks that a volume is
404 add_drives(int fd, struct volume_info *info, int verbose)
406 struct drive_info *dinfo;
410 for (i = 0, dinfo = info->drives; i < info->drive_count;
412 if (dinfo->info == NULL) {
413 if (mpt_create_physdisk(fd, dinfo->sdisk,
417 "Failed to create physical disk page for %s",
418 dinfo->sdisk->devname);
422 printf("Added drive %s with PhysDiskNum %u\n",
423 dinfo->sdisk->devname, PhysDiskNum);
425 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
426 if (dinfo->info == NULL)
434 * Find the next free target ID assuming that 'target_id' is the last
435 * one used. 'target_id' should be 0xff for the initial test.
438 find_next_volume(struct config_id_state *state)
440 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
444 /* Assume the current one is used. */
447 /* Search drives first. */
448 for (i = 0; i < state->nsdisks; i++)
449 if (state->sdisks[i].target == state->target_id)
451 for (i = 0; i < state->list->ndrives; i++)
452 if (state->list->drives[i]->PhysDiskID == state->target_id)
455 /* Seach volumes second. */
456 vol = state->ioc2->RaidVolume;
457 for (i = 0; i < state->ioc2->NumActiveVolumes; vol++, i++)
458 if (vol->VolumeID == state->target_id)
461 return (state->target_id);
464 /* Create a volume and populate it with drives. */
465 static CONFIG_PAGE_RAID_VOL_0 *
466 build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size,
467 struct config_id_state *state, int verbose)
469 CONFIG_PAGE_HEADER header;
470 CONFIG_PAGE_RAID_VOL_0 *vol;
471 RAID_VOL0_PHYS_DISK *rdisk;
472 struct drive_info *dinfo;
478 error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME,
479 0, 0, &header, NULL);
484 if (header.PageVersion > MPI_RAIDVOLPAGE0_PAGEVERSION) {
485 warnx("Unsupported RAID volume page 0 version %d",
490 page_size = sizeof(CONFIG_PAGE_RAID_VOL_0) +
491 sizeof(RAID_VOL0_PHYS_DISK) * (info->drive_count - 1);
492 vol = calloc(1, page_size);
497 vol->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
498 vol->Header.PageNumber = 0;
499 vol->Header.PageLength = page_size / 4;
502 vol->VolumeID = find_next_volume(state);
504 vol->VolumeIOC = 0; /* XXX */
505 vol->VolumeStatus.Flags = MPI_RAIDVOL0_STATUS_FLAG_ENABLED;
506 vol->VolumeStatus.State = MPI_RAIDVOL0_STATUS_STATE_OPTIMAL;
507 vol->VolumeSettings.Settings = MPI_RAIDVOL0_SETTING_USE_DEFAULTS;
508 vol->VolumeSettings.HotSparePool = MPI_RAID_HOT_SPARE_POOL_0;
509 vol->NumPhysDisks = info->drive_count;
511 /* Find the smallest drive. */
512 MinLBA = info->drives[0].info->MaxLBA;
513 for (i = 1; i < info->drive_count; i++)
514 if (info->drives[i].info->MaxLBA < MinLBA)
515 MinLBA = info->drives[i].info->MaxLBA;
518 * Now chop off 512MB at the end to leave room for the
519 * metadata. The controller might only use 64MB, but we just
520 * chop off the max to be simple.
522 MinLBA -= (512 * 1024 * 1024) / 512;
526 vol->VolumeType = MPI_RAID_VOL_TYPE_IS;
527 vol->StripeSize = stripe_size / 512;
528 MaxLBA = MinLBA * info->drive_count;
531 vol->VolumeType = MPI_RAID_VOL_TYPE_IM;
532 MaxLBA = MinLBA * (info->drive_count / 2);
535 vol->VolumeType = MPI_RAID_VOL_TYPE_IME;
536 vol->StripeSize = stripe_size / 512;
537 MaxLBA = MinLBA * info->drive_count / 2;
545 * If the controller doesn't support 64-bit addressing and the
546 * new volume is larger than 2^32 blocks, warn the user and
547 * truncate the volume.
549 if (MaxLBA >> 32 != 0 &&
550 !(state->ioc2->CapabilitiesFlags &
551 MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING)) {
553 "Controller does not support volumes > 2TB, truncating volume.");
556 vol->MaxLBA = MaxLBA;
557 vol->MaxLBAHigh = MaxLBA >> 32;
559 /* Populate drives. */
560 for (i = 0, dinfo = info->drives, rdisk = vol->PhysDisk;
561 i < info->drive_count; i++, dinfo++, rdisk++) {
563 printf("Adding drive %u (%u:%u) to volume %u:%u\n",
564 dinfo->info->PhysDiskNum, dinfo->info->PhysDiskBus,
565 dinfo->info->PhysDiskID, vol->VolumeBus,
567 if (raid_type == RT_RAID1) {
570 MPI_RAIDVOL0_PHYSDISK_PRIMARY;
573 MPI_RAIDVOL0_PHYSDISK_SECONDARY;
575 rdisk->PhysDiskMap = i;
576 rdisk->PhysDiskNum = dinfo->info->PhysDiskNum;
583 create_volume(int ac, char **av)
585 CONFIG_PAGE_RAID_VOL_0 *vol;
586 struct config_id_state state;
587 struct volume_info *info;
589 int ch, error, fd, i, quick, raid_type, verbose;
595 warnx("create: volume type required");
599 fd = mpt_open(mpt_unit);
606 /* Lookup the RAID type first. */
608 for (i = 0; raid_type_table[i].name != NULL; i++)
609 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
610 raid_type = raid_type_table[i].raid_type;
614 if (raid_type == -1) {
615 warnx("Unknown or unsupported volume type %s", av[1]);
619 /* Parse any options. */
626 stripe_size = 64 * 1024;
628 while ((ch = getopt(ac, av, "dqs:v")) != -1) {
639 error = dehumanize_number(optarg, &stripe_size);
640 if ((error != 0) || (stripe_size < 512) ||
641 (!powerof2(stripe_size))) {
642 warnx("Invalid stripe size %s", optarg);
657 /* Fetch existing config data. */
658 state.ioc2 = mpt_read_ioc_page(fd, 2, NULL);
659 if (state.ioc2 == NULL) {
661 warn("Failed to read volume list");
664 state.list = mpt_pd_list(fd);
665 if (state.list == NULL)
667 error = mpt_fetch_disks(fd, &state.nsdisks, &state.sdisks);
669 warn("Failed to fetch standalone disk list");
672 state.target_id = 0xff;
674 /* Parse the drive list. */
676 warnx("Exactly one drive list is required");
679 info = calloc(1, sizeof(*info));
682 error = parse_volume(fd, raid_type, &state, av[0], info);
686 /* Create RAID physdisk pages for standalone disks. */
687 error = add_drives(fd, info, verbose);
691 /* Build the volume. */
692 vol = build_volume(fd, info, raid_type, stripe_size, &state, verbose);
703 /* Send the new volume to the controller. */
704 error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus,
705 vol->VolumeID, 0, quick ? MPI_RAID_ACTION_ADATA_DO_NOT_SYNC : 0,
706 vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1);
709 warn("Failed to add volume");
716 mpt_rescan_bus(vol->VolumeBus, vol->VolumeID);
722 mpt_free_pd_list(state.list);
728 MPT_COMMAND(top, create, create_volume);
731 delete_volume(int ac, char **av)
733 U8 VolumeBus, VolumeID;
737 warnx("delete: volume required");
741 fd = mpt_open(mpt_unit);
748 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
750 warnc(error, "Invalid volume %s", av[1]);
754 if (mpt_lock_volume(VolumeBus, VolumeID) < 0)
757 error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus,
758 VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
759 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, NULL,
762 warnc(error, "Failed to delete volume");
766 mpt_rescan_bus(-1, -1);
771 MPT_COMMAND(top, delete, delete_volume);
774 find_volume_spare_pool(int fd, const char *name, int *pool)
776 CONFIG_PAGE_RAID_VOL_0 *info;
777 CONFIG_PAGE_IOC_2 *ioc2;
778 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
779 U8 VolumeBus, VolumeID;
780 int error, i, j, new_pool, pool_count[7];
782 error = mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID);
784 warnc(error, "Invalid volume %s", name);
788 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
793 * Check for an existing pool other than pool 0 (used for
796 if ((info->VolumeSettings.HotSparePool & ~MPI_RAID_HOT_SPARE_POOL_0) !=
798 *pool = 1 << (ffs(info->VolumeSettings.HotSparePool &
799 ~MPI_RAID_HOT_SPARE_POOL_0) - 1);
805 * Try to find a free pool. First, figure out which pools are
808 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
811 warn("Failed to fetch volume list");
814 bzero(pool_count, sizeof(pool_count));
815 vol = ioc2->RaidVolume;
816 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
817 info = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
820 for (j = 0; j < 7; j++)
821 if (info->VolumeSettings.HotSparePool & (1 << (j + 1)))
827 /* Find the pool with the lowest use count. */
829 for (i = 1; i < 7; i++)
830 if (pool_count[i] < pool_count[new_pool])
834 /* Add this pool to the volume. */
835 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
838 info->VolumeSettings.HotSparePool |= (1 << new_pool);
839 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
840 VolumeBus, VolumeID, 0, *(U32 *)&info->VolumeSettings, NULL, 0,
841 NULL, NULL, 0, NULL, NULL, 0);
843 warnx("Failed to add spare pool %d to %s", new_pool,
844 mpt_volume_name(VolumeBus, VolumeID));
849 *pool = (1 << new_pool);
854 add_spare(int ac, char **av)
856 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
857 struct mpt_standalone_disk *sdisks;
858 struct mpt_drive_list *list;
860 int error, fd, i, nsdisks, pool = 0;
863 warnx("add spare: drive required");
867 warnx("add spare: extra arguments");
871 fd = mpt_open(mpt_unit);
879 error = find_volume_spare_pool(fd, av[2], &pool);
883 pool = MPI_RAID_HOT_SPARE_POOL_0;
885 list = mpt_pd_list(fd);
889 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
891 error = mpt_fetch_disks(fd, &nsdisks, &sdisks);
893 warn("Failed to fetch standalone disk list");
897 if (mpt_lookup_standalone_disk(av[1], sdisks, nsdisks, &i) <
900 warn("Unable to lookup drive %s", av[1]);
904 if (mpt_lock_physdisk(&sdisks[i]) < 0)
907 if (mpt_create_physdisk(fd, &sdisks[i], &PhysDiskNum) < 0) {
909 warn("Failed to create physical disk page");
914 mpt_free_pd_list(list);
916 info = mpt_pd_info(fd, PhysDiskNum, NULL);
919 warn("Failed to fetch drive info");
923 info->PhysDiskSettings.HotSparePool = pool;
924 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_PHYSDISK_SETTINGS, 0,
925 0, PhysDiskNum, *(U32 *)&info->PhysDiskSettings, NULL, 0, NULL,
926 NULL, 0, NULL, NULL, 0);
928 warnc(error, "Failed to assign spare");
937 MPT_COMMAND(top, add, add_spare);
940 remove_spare(int ac, char **av)
942 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
943 struct mpt_drive_list *list;
948 warnx("remove spare: drive required");
952 fd = mpt_open(mpt_unit);
959 list = mpt_pd_list(fd);
963 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
965 warn("Failed to find drive %s", av[1]);
968 mpt_free_pd_list(list);
971 info = mpt_pd_info(fd, PhysDiskNum, NULL);
974 warn("Failed to fetch drive info");
978 if (info->PhysDiskSettings.HotSparePool == 0) {
979 warnx("Drive %u is not a hot spare", PhysDiskNum);
983 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);
1019 error = mpt_fetch_disks(fd, &ndisks, &disks);
1021 warn("Failed to fetch standalone disk list");
1025 if (mpt_lookup_standalone_disk(av[1], disks, ndisks, &i) < 0) {
1027 warn("Unable to lookup drive");
1031 if (mpt_lock_physdisk(&disks[i]) < 0)
1034 if (mpt_create_physdisk(fd, &disks[i], &PhysDiskNum) < 0) {
1036 warn("Failed to create physical disk page");
1041 printf("Added drive %s with PhysDiskNum %u\n", av[1], PhysDiskNum);
1047 MPT_COMMAND(pd, create, pd_create);
1050 pd_delete(int ac, char **av)
1052 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
1053 struct mpt_drive_list *list;
1058 warnx("pd delete: drive required");
1062 fd = mpt_open(mpt_unit);
1069 list = mpt_pd_list(fd);
1073 if (mpt_lookup_drive(list, av[1], &PhysDiskNum) < 0) {
1075 warn("Failed to find drive %s", av[1]);
1078 mpt_free_pd_list(list);
1080 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1083 warn("Failed to fetch drive info");
1087 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1089 warn("Failed to delete physical disk page");
1093 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1099 MPT_COMMAND(pd, delete, pd_delete);
1101 /* Display raw data about a volume config. */
1103 dump_config(CONFIG_PAGE_RAID_VOL_0 *vol)
1107 printf("Volume Configuration (Debug):\n");
1109 " Page Header: Type 0x%02x Number 0x%02x Length 0x%02x(%u) Version 0x%02x\n",
1110 vol->Header.PageType, vol->Header.PageNumber,
1111 vol->Header.PageLength, vol->Header.PageLength * 4,
1112 vol->Header.PageVersion);
1113 printf(" Address: %d:%d IOC %d\n", vol->VolumeBus, vol->VolumeID,
1115 printf(" Type: %d (%s)\n", vol->VolumeType,
1116 mpt_raid_level(vol->VolumeType));
1117 printf(" Status: %s (Flags 0x%02x)\n",
1118 mpt_volstate(vol->VolumeStatus.State), vol->VolumeStatus.Flags);
1119 printf(" Settings: 0x%04x (Spare Pools 0x%02x)\n",
1120 vol->VolumeSettings.Settings, vol->VolumeSettings.HotSparePool);
1121 printf(" MaxLBA: %ju\n", (uintmax_t)vol->MaxLBAHigh << 32 |
1123 printf(" Stripe Size: %ld\n", (long)vol->StripeSize * 512);
1124 printf(" %d Disks:\n", vol->NumPhysDisks);
1126 for (i = 0; i < vol->NumPhysDisks; i++)
1127 printf(" Disk %d: Num 0x%02x Map 0x%02x\n", i,
1128 vol->PhysDisk[i].PhysDiskNum, vol->PhysDisk[i].PhysDiskMap);
1132 debug_config(int ac, char **av)
1134 CONFIG_PAGE_RAID_VOL_0 *vol;
1135 U8 VolumeBus, VolumeID;
1139 warnx("debug: volume required");
1143 fd = mpt_open(mpt_unit);
1150 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
1152 warnc(error, "Invalid volume: %s", av[1]);
1156 vol = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
1159 warn("Failed to get volume info");
1169 MPT_COMMAND(top, debug, debug_config);