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.1 2009/08/14 13:13:12 scottl Exp $
33 #include <sys/param.h>
34 #include <sys/errno.h>
49 static void dump_config(CONFIG_PAGE_RAID_VOL_0 *vol);
52 #define powerof2(x) ((((x)-1)&(x))==0)
55 dehumanize(const char *value)
62 iv = strtoq(value, &vtp, 0);
63 if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
84 * Lock the volume by opening its /dev device read/write. This will
85 * only work if nothing else has it opened (including mounts). We
86 * leak the fd on purpose since this application is not long-running.
89 mpt_lock_volume(U8 VolumeBus, U8 VolumeID)
91 char path[MAXPATHLEN];
92 struct mpt_query_disk qd;
95 error = mpt_query_disk(VolumeBus, VolumeID, &qd);
98 * This means there isn't a CAM device associated with
99 * the volume, and thus it is already implicitly
100 * locked, so just return.
105 warn("Unable to lookup volume device name");
108 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, qd.devname);
109 vfd = open(path, O_RDWR);
111 warn("Unable to lock volume %s", qd.devname);
118 mpt_lock_physdisk(struct mpt_standalone_disk *disk)
120 char path[MAXPATHLEN];
123 snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk->devname);
124 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 *idx)
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) {
149 for (i = 0; i < ndisks; i++) {
150 if (disks[i].bus == (U8)bus &&
151 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) {
177 * Mark a standalone disk as being a physical disk.
180 mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum)
182 CONFIG_PAGE_HEADER header;
183 CONFIG_PAGE_RAID_PHYS_DISK_0 *config_page;
186 if (mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK,
187 0, 0, &header, NULL) < 0)
189 if (header.PageVersion > MPI_RAIDPHYSDISKPAGE0_PAGEVERSION) {
190 warnx("Unsupported RAID physdisk page 0 version %d",
195 config_page = calloc(1, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0));
196 config_page->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
197 config_page->Header.PageNumber = 0;
198 config_page->Header.PageLength = sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0) /
200 config_page->PhysDiskIOC = 0; /* XXX */
201 config_page->PhysDiskBus = disk->bus;
202 config_page->PhysDiskID = disk->target;
204 /* XXX: Enclosure info for PhysDiskSettings? */
205 if (mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0,
206 config_page, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0), NULL,
207 &ActionData, sizeof(ActionData), NULL, NULL, 1) < 0)
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 __unused, char **av __unused)
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;
236 fd = mpt_open(mpt_unit);
242 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 if (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,
275 warn("Failed to delete volume %s",
276 mpt_volume_name(vol->VolumeBus, vol->VolumeID));
279 /* Delete all the spares. */
280 ioc5 = mpt_read_ioc_page(fd, 5, NULL);
282 warn("Failed to fetch spare list");
284 spare = ioc5->HotSpare;
285 for (i = 0; i < ioc5->NumHotSpares; spare++, i++)
286 if (mpt_delete_physdisk(fd, spare->PhysDiskNum) < 0)
287 warn("Failed to delete physical disk %d",
292 /* Delete any RAID physdisks that may be left. */
293 ioc3 = mpt_read_ioc_page(fd, 3, NULL);
295 warn("Failed to fetch drive list");
297 disk = ioc3->PhysDisk;
298 for (i = 0; i < ioc3->NumPhysDisks; disk++, i++)
299 if (mpt_delete_physdisk(fd, disk->PhysDiskNum) < 0)
300 warn("Failed to delete physical disk %d",
305 printf("mpt%d: Configuration cleared\n", mpt_unit);
306 mpt_rescan_bus(-1, -1);
311 MPT_COMMAND(top, clear, clear_config);
317 static struct raid_type_entry {
320 } raid_type_table[] = {
321 { "raid0", RT_RAID0 },
322 { "raid-0", RT_RAID0 },
323 { "raid1", RT_RAID1 },
324 { "raid-1", RT_RAID1 },
325 { "mirror", RT_RAID1 },
326 { "raid1e", RT_RAID1E },
327 { "raid-1e", RT_RAID1E },
331 struct config_id_state {
332 struct mpt_standalone_disk *sdisks;
333 struct mpt_drive_list *list;
334 CONFIG_PAGE_IOC_2 *ioc2;
340 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
341 struct mpt_standalone_disk *sdisk;
346 struct drive_info *drives;
349 /* Parse a comma-separated list of drives for a volume. */
351 parse_volume(int fd, int raid_type, struct config_id_state *state,
352 char *volume_str, struct volume_info *info)
354 struct drive_info *dinfo;
360 for (count = 0; cp != NULL; count++) {
361 cp = strchr(cp, ',');
365 warnx("Invalid drive list '%s'", volume_str);
371 /* Validate the number of drives for this volume. */
375 warnx("RAID0 requires at least 2 drives in each "
382 warnx("RAID1 requires exactly 2 drives in each "
389 warnx("RAID1E requires at least 3 drives in each "
396 /* Validate each drive. */
397 info->drives = calloc(count, sizeof(struct drive_info));
398 info->drive_count = count;
399 for (dinfo = info->drives; (cp = strsep(&volume_str, ",")) != NULL;
401 /* If this drive is already a RAID phys just fetch the info. */
402 error = mpt_lookup_drive(state->list, cp, &PhysDiskNum);
404 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
405 if (dinfo->info == NULL)
410 /* See if it is a standalone disk. */
411 if (mpt_lookup_standalone_disk(cp, state->sdisks,
412 state->nsdisks, &i) < 0) {
413 warn("Unable to lookup drive %s", cp);
416 dinfo->sdisk = &state->sdisks[i];
418 /* Lock the disk, we will create phys disk pages later. */
419 if (mpt_lock_physdisk(dinfo->sdisk) < 0)
427 * Add RAID physdisk pages for any standalone disks that a volume is
431 add_drives(int fd, struct volume_info *info, int verbose)
433 struct drive_info *dinfo;
437 for (i = 0, dinfo = info->drives; i < info->drive_count;
439 if (dinfo->info == NULL) {
440 if (mpt_create_physdisk(fd, dinfo->sdisk,
443 "Failed to create physical disk page for %s",
444 dinfo->sdisk->devname);
448 printf("Added drive %s with PhysDiskNum %u\n",
449 dinfo->sdisk->devname, PhysDiskNum);
451 dinfo->info = mpt_pd_info(fd, PhysDiskNum, NULL);
452 if (dinfo->info == NULL)
460 * Find the next free target ID assuming that 'target_id' is the last
461 * one used. 'target_id' should be 0xff for the initial test.
464 find_next_volume(struct config_id_state *state)
466 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
470 /* Assume the current one is used. */
473 /* Search drives first. */
474 for (i = 0; i < state->nsdisks; i++)
475 if (state->sdisks[i].target == state->target_id)
477 for (i = 0; i < state->list->ndrives; i++)
478 if (state->list->drives[i]->PhysDiskID == state->target_id)
481 /* Seach volumes second. */
482 vol = state->ioc2->RaidVolume;
483 for (i = 0; i < state->ioc2->NumActiveVolumes; vol++, i++)
484 if (vol->VolumeID == state->target_id)
487 return (state->target_id);
490 /* Create a volume and populate it with drives. */
491 static CONFIG_PAGE_RAID_VOL_0 *
492 build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size,
493 struct config_id_state *state, int verbose)
495 CONFIG_PAGE_HEADER header;
496 CONFIG_PAGE_RAID_VOL_0 *vol;
497 RAID_VOL0_PHYS_DISK *rdisk;
498 struct drive_info *dinfo;
504 if (mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME,
505 0, 0, &header, NULL) < 0)
507 if (header.PageVersion > MPI_RAIDVOLPAGE0_PAGEVERSION) {
508 warnx("Unsupported RAID volume page 0 version %d",
513 page_size = sizeof(CONFIG_PAGE_RAID_VOL_0) +
514 sizeof(RAID_VOL0_PHYS_DISK) * (info->drive_count - 1);
515 vol = calloc(1, page_size);
518 vol->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
519 vol->Header.PageNumber = 0;
520 vol->Header.PageLength = page_size / 4;
523 vol->VolumeID = find_next_volume(state);
525 vol->VolumeIOC = 0; /* XXX */
526 vol->VolumeStatus.Flags = MPI_RAIDVOL0_STATUS_FLAG_ENABLED;
527 vol->VolumeStatus.State = MPI_RAIDVOL0_STATUS_STATE_OPTIMAL;
528 vol->VolumeSettings.Settings = MPI_RAIDVOL0_SETTING_USE_DEFAULTS;
529 vol->VolumeSettings.HotSparePool = MPI_RAID_HOT_SPARE_POOL_0;
530 vol->NumPhysDisks = info->drive_count;
532 /* Find the smallest drive. */
533 MinLBA = info->drives[0].info->MaxLBA;
534 for (i = 1; i < info->drive_count; i++)
535 if (info->drives[i].info->MaxLBA < MinLBA)
536 MinLBA = info->drives[i].info->MaxLBA;
539 * Now chop off 512MB at the end to leave room for the
540 * metadata. The controller might only use 64MB, but we just
541 * chop off the max to be simple.
543 MinLBA -= (512 * 1024 * 1024) / 512;
547 vol->VolumeType = MPI_RAID_VOL_TYPE_IS;
548 vol->StripeSize = stripe_size / 512;
549 MaxLBA = MinLBA * info->drive_count;
552 vol->VolumeType = MPI_RAID_VOL_TYPE_IM;
553 MaxLBA = MinLBA * (info->drive_count / 2);
556 vol->VolumeType = MPI_RAID_VOL_TYPE_IME;
557 vol->StripeSize = stripe_size / 512;
558 MaxLBA = MinLBA * info->drive_count / 2;
566 * If the controller doesn't support 64-bit addressing and the
567 * new volume is larger than 2^32 blocks, warn the user and
568 * truncate the volume.
570 if (MaxLBA >> 32 != 0 &&
571 !(state->ioc2->CapabilitiesFlags &
572 MPI_IOCPAGE2_CAP_FLAGS_RAID_64_BIT_ADDRESSING)) {
574 "Controller does not support volumes > 2TB, truncating volume.");
577 vol->MaxLBA = MaxLBA;
578 vol->MaxLBAHigh = MaxLBA >> 32;
580 /* Populate drives. */
581 for (i = 0, dinfo = info->drives, rdisk = vol->PhysDisk;
582 i < info->drive_count; i++, dinfo++, rdisk++) {
584 printf("Adding drive %u (%u:%u) to volume %u:%u\n",
585 dinfo->info->PhysDiskNum, dinfo->info->PhysDiskBus,
586 dinfo->info->PhysDiskID, vol->VolumeBus,
588 if (raid_type == RT_RAID1) {
591 MPI_RAIDVOL0_PHYSDISK_PRIMARY;
594 MPI_RAIDVOL0_PHYSDISK_SECONDARY;
596 rdisk->PhysDiskMap = i;
597 rdisk->PhysDiskNum = dinfo->info->PhysDiskNum;
604 create_volume(int ac, char **av)
606 CONFIG_PAGE_RAID_VOL_0 *vol;
607 struct config_id_state state;
608 struct volume_info *info;
609 int ch, error, fd, i, raid_type, verbose, quick;
616 warnx("create: volume type required");
620 fd = mpt_open(mpt_unit);
626 /* Lookup the RAID type first. */
628 for (i = 0; raid_type_table[i].name != NULL; i++)
629 if (strcasecmp(raid_type_table[i].name, av[1]) == 0) {
630 raid_type = raid_type_table[i].raid_type;
634 if (raid_type == -1) {
635 warnx("Unknown or unsupported volume type %s", av[1]);
639 /* Parse any options. */
646 stripe_size = 64 * 1024;
648 while ((ch = getopt(ac, av, "dqs:v")) != -1) {
659 stripe_size = dehumanize(optarg);
660 if ((stripe_size < 512) || (!powerof2(stripe_size))) {
661 warnx("Invalid stripe size %s", optarg);
676 /* Fetch existing config data. */
677 state.ioc2 = mpt_read_ioc_page(fd, 2, NULL);
678 if (state.ioc2 == NULL) {
679 warn("Failed to read volume list");
682 state.list = mpt_pd_list(fd);
683 if (state.list == NULL)
685 error = mpt_fetch_disks(fd, &state.nsdisks, &state.sdisks);
687 warn("Failed to fetch standalone disk list");
690 state.target_id = 0xff;
692 /* Parse the drive list. */
694 warnx("Exactly one drive list is required");
697 info = calloc(1, sizeof(*info));
698 error = parse_volume(fd, raid_type, &state, av[0], info);
702 /* Create RAID physdisk pages for standalone disks. */
703 error = add_drives(fd, info, verbose);
707 /* Build the volume. */
708 vol = build_volume(fd, info, raid_type, stripe_size, &state, verbose);
717 /* Send the new volume to the controller. */
718 if (mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus,
719 vol->VolumeID, 0, quick ? MPI_RAID_ACTION_ADATA_DO_NOT_SYNC : 0,
720 vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1) <
722 warn("Failed to add volume");
729 mpt_rescan_bus(vol->VolumeBus, vol->VolumeID);
735 mpt_free_pd_list(state.list);
741 MPT_COMMAND(top, create, create_volume);
744 delete_volume(int ac, char **av)
746 U8 VolumeBus, VolumeID;
750 warnx("delete: volume required");
754 fd = mpt_open(mpt_unit);
760 if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
761 warn("Invalid volume %s", av[1]);
765 if (mpt_lock_volume(VolumeBus, VolumeID) < 0)
768 if (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus,
769 VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS |
770 MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, NULL,
772 warn("Failed to delete volume");
776 mpt_rescan_bus(-1, -1);
781 MPT_COMMAND(top, delete, delete_volume);
784 find_volume_spare_pool(int fd, const char *name, int *pool)
786 CONFIG_PAGE_RAID_VOL_0 *info;
787 CONFIG_PAGE_IOC_2 *ioc2;
788 CONFIG_PAGE_IOC_2_RAID_VOL *vol;
789 U8 VolumeBus, VolumeID;
790 int i, j, new_pool, pool_count[7];
792 if (mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID) < 0) {
793 warn("Invalid volume %s", name);
797 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
802 * Check for an existing pool other than pool 0 (used for
805 if ((info->VolumeSettings.HotSparePool & ~MPI_RAID_HOT_SPARE_POOL_0) !=
807 *pool = 1 << (ffs(info->VolumeSettings.HotSparePool &
808 ~MPI_RAID_HOT_SPARE_POOL_0) - 1);
814 * Try to find a free pool. First, figure out which pools are
817 ioc2 = mpt_read_ioc_page(fd, 2, NULL);
819 warn("Failed to fetch volume list");
822 bzero(pool_count, sizeof(pool_count));
823 vol = ioc2->RaidVolume;
824 for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
825 info = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
828 for (j = 0; j < 7; j++)
829 if (info->VolumeSettings.HotSparePool & (1 << (j + 1)))
835 /* Find the pool with the lowest use count. */
837 for (i = 1; i < 7; i++)
838 if (pool_count[i] < pool_count[new_pool])
842 /* Add this pool to the volume. */
843 info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
846 info->VolumeSettings.HotSparePool |= (1 << new_pool);
847 if (mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
848 VolumeBus, VolumeID, 0, *(U32 *)&info->VolumeSettings, NULL, 0,
849 NULL, NULL, 0, NULL, NULL, 0) < 0) {
850 warnx("Failed to add spare pool %d to %s", new_pool,
851 mpt_volume_name(VolumeBus, VolumeID));
856 *pool = (1 << new_pool);
861 add_spare(int ac, char **av)
863 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
864 struct mpt_standalone_disk *sdisks;
865 struct mpt_drive_list *list;
867 int error, fd, i, nsdisks, pool;
870 warnx("add spare: drive required");
874 warnx("add spare: extra arguments");
878 fd = mpt_open(mpt_unit);
885 if (find_volume_spare_pool(fd, av[2], &pool) < 0)
888 pool = MPI_RAID_HOT_SPARE_POOL_0;
890 list = mpt_pd_list(fd);
894 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
896 error = mpt_fetch_disks(fd, &nsdisks, &sdisks);
898 warn("Failed to fetch standalone disk list");
902 if (mpt_lookup_standalone_disk(av[1], sdisks, nsdisks, &i) <
904 warn("Unable to lookup drive %s", av[1]);
908 if (mpt_lock_physdisk(&sdisks[i]) < 0)
911 if (mpt_create_physdisk(fd, &sdisks[i], &PhysDiskNum) < 0) {
912 warn("Failed to create physical disk page");
917 mpt_free_pd_list(list);
919 info = mpt_pd_info(fd, PhysDiskNum, NULL);
921 warn("Failed to fetch drive info");
925 info->PhysDiskSettings.HotSparePool = pool;
926 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_PHYSDISK_SETTINGS, 0,
927 0, PhysDiskNum, *(U32 *)&info->PhysDiskSettings, NULL, 0, NULL,
928 NULL, 0, NULL, NULL, 0);
930 warn("Failed to assign spare");
939 MPT_COMMAND(top, add, add_spare);
942 remove_spare(int ac, char **av)
944 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
945 struct mpt_drive_list *list;
950 warnx("remove spare: drive required");
954 fd = mpt_open(mpt_unit);
960 list = mpt_pd_list(fd);
964 error = mpt_lookup_drive(list, av[1], &PhysDiskNum);
966 warn("Failed to find drive %s", av[1]);
969 mpt_free_pd_list(list);
972 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) {
984 warn("Failed to delete physical disk page");
988 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
994 MPT_COMMAND(top, remove, remove_spare);
1000 pd_create(int ac, char **av)
1002 struct mpt_standalone_disk *disks;
1003 int error, fd, i, ndisks;
1007 warnx("pd create: drive required");
1011 fd = mpt_open(mpt_unit);
1017 error = mpt_fetch_disks(fd, &ndisks, &disks);
1019 warn("Failed to fetch standalone disk list");
1023 if (mpt_lookup_standalone_disk(av[1], disks, ndisks, &i) < 0) {
1024 warn("Unable to lookup drive");
1028 if (mpt_lock_physdisk(&disks[i]) < 0)
1031 if (mpt_create_physdisk(fd, &disks[i], &PhysDiskNum) < 0) {
1032 warn("Failed to create physical disk page");
1037 printf("Added drive %s with PhysDiskNum %u\n", av[1], PhysDiskNum);
1043 MPT_COMMAND(pd, create, pd_create);
1046 pd_delete(int ac, char **av)
1048 CONFIG_PAGE_RAID_PHYS_DISK_0 *info;
1049 struct mpt_drive_list *list;
1054 warnx("pd delete: drive required");
1058 fd = mpt_open(mpt_unit);
1064 list = mpt_pd_list(fd);
1068 if (mpt_lookup_drive(list, av[1], &PhysDiskNum) < 0) {
1069 warn("Failed to find drive %s", av[1]);
1072 mpt_free_pd_list(list);
1074 info = mpt_pd_info(fd, PhysDiskNum, NULL);
1076 warn("Failed to fetch drive info");
1080 if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) {
1081 warn("Failed to delete physical disk page");
1085 mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID);
1091 MPT_COMMAND(pd, delete, pd_delete);
1093 /* Display raw data about a volume config. */
1095 dump_config(CONFIG_PAGE_RAID_VOL_0 *vol)
1099 printf("Volume Configuration (Debug):\n");
1101 " Page Header: Type 0x%02x Number 0x%02x Length 0x%02x(%u) Version 0x%02x\n",
1102 vol->Header.PageType, vol->Header.PageNumber,
1103 vol->Header.PageLength, vol->Header.PageLength * 4,
1104 vol->Header.PageVersion);
1105 printf(" Address: %d:%d IOC %d\n", vol->VolumeBus, vol->VolumeID,
1107 printf(" Type: %d (%s)\n", vol->VolumeType,
1108 mpt_raid_level(vol->VolumeType));
1109 printf(" Status: %s (Flags 0x%02x)\n",
1110 mpt_volstate(vol->VolumeStatus.State), vol->VolumeStatus.Flags);
1111 printf(" Settings: 0x%04x (Spare Pools 0x%02x)\n",
1112 vol->VolumeSettings.Settings, vol->VolumeSettings.HotSparePool);
1113 printf(" MaxLBA: %ju\n", (uintmax_t)vol->MaxLBAHigh << 32 |
1115 printf(" Stripe Size: %ld\n", (long)vol->StripeSize * 512);
1116 printf(" %d Disks:\n", vol->NumPhysDisks);
1118 for (i = 0; i < vol->NumPhysDisks; i++)
1119 printf(" Disk %d: Num 0x%02x Map 0x%02x\n", i,
1120 vol->PhysDisk[i].PhysDiskNum, vol->PhysDisk[i].PhysDiskMap);
1124 debug_config(int ac, char **av)
1126 CONFIG_PAGE_RAID_VOL_0 *vol;
1127 U8 VolumeBus, VolumeID;
1131 warnx("debug: volume required");
1135 fd = mpt_open(mpt_unit);
1141 if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
1142 warn("Invalid volume: %s", av[1]);
1146 vol = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
1148 warn("Failed to get volume info");
1158 MPT_COMMAND(top, debug, debug_config);