Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/mptutil/mpt_drive.c
Show First 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | mpt_pd_list(int fd) | ||||
CONFIG_PAGE_RAID_VOL_0 **volumes; | CONFIG_PAGE_RAID_VOL_0 **volumes; | ||||
RAID_VOL0_PHYS_DISK *rdisk; | RAID_VOL0_PHYS_DISK *rdisk; | ||||
CONFIG_PAGE_IOC_3 *ioc3; | CONFIG_PAGE_IOC_3 *ioc3; | ||||
IOC_3_PHYS_DISK *disk; | IOC_3_PHYS_DISK *disk; | ||||
CONFIG_PAGE_IOC_5 *ioc5; | CONFIG_PAGE_IOC_5 *ioc5; | ||||
IOC_5_HOT_SPARE *spare; | IOC_5_HOT_SPARE *spare; | ||||
struct mpt_drive_list *list; | struct mpt_drive_list *list; | ||||
int count, error, i, j; | int count, error, i, j; | ||||
size_t listsize; | |||||
ioc2 = mpt_read_ioc_page(fd, 2, NULL); | ioc2 = mpt_read_ioc_page(fd, 2, NULL); | ||||
if (ioc2 == NULL) { | if (ioc2 == NULL) { | ||||
error = errno; | error = errno; | ||||
warn("Failed to fetch volume list"); | warn("Failed to fetch volume list"); | ||||
errno = error; | errno = error; | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
Show All 26 Lines | mpt_pd_list(int fd) | ||||
vol = ioc2->RaidVolume; | vol = ioc2->RaidVolume; | ||||
for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) { | for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) { | ||||
volumes[i] = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, | volumes[i] = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, | ||||
NULL); | NULL); | ||||
if (volumes[i] == NULL) { | if (volumes[i] == NULL) { | ||||
error = errno; | error = errno; | ||||
warn("Failed to read volume info"); | warn("Failed to read volume info"); | ||||
errno = error; | errno = error; | ||||
free(volumes); | |||||
free(ioc5); | |||||
free(ioc3); | |||||
free(ioc2); | |||||
return (NULL); | return (NULL); | ||||
} | } | ||||
count += volumes[i]->NumPhysDisks; | count += volumes[i]->NumPhysDisks; | ||||
} | } | ||||
count += ioc3->NumPhysDisks; | count += ioc3->NumPhysDisks; | ||||
count += ioc5->NumHotSpares; | count += ioc5->NumHotSpares; | ||||
/* Walk the various lists enumerating drives. */ | /* Walk the various lists enumerating drives. */ | ||||
list = malloc(sizeof(*list) + sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0) * | listsize = sizeof(*list) + sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0) * count; | ||||
count); | list = calloc(1, listsize); | ||||
list->ndrives = 0; | |||||
for (i = 0; i < ioc2->NumActiveVolumes; i++) { | for (i = 0; i < ioc2->NumActiveVolumes; i++) { | ||||
rdisk = volumes[i]->PhysDisk; | rdisk = volumes[i]->PhysDisk; | ||||
for (j = 0; j < volumes[i]->NumPhysDisks; rdisk++, j++) | for (j = 0; j < volumes[i]->NumPhysDisks; rdisk++, j++) | ||||
if (mpt_pd_insert(fd, list, rdisk->PhysDiskNum) < 0) | if (mpt_pd_insert(fd, list, rdisk->PhysDiskNum) < 0) { | ||||
mpt_free_pd_list(list); | |||||
free(volumes); | |||||
free(ioc5); | |||||
free(ioc3); | |||||
free(ioc2); | |||||
return (NULL); | return (NULL); | ||||
} | |||||
free(volumes[i]); | free(volumes[i]); | ||||
} | } | ||||
free(ioc2); | free(ioc2); | ||||
free(volumes); | free(volumes); | ||||
spare = ioc5->HotSpare; | spare = ioc5->HotSpare; | ||||
for (i = 0; i < ioc5->NumHotSpares; spare++, i++) | for (i = 0; i < ioc5->NumHotSpares; spare++, i++) | ||||
if (mpt_pd_insert(fd, list, spare->PhysDiskNum) < 0) | if (mpt_pd_insert(fd, list, spare->PhysDiskNum) < 0) { | ||||
mpt_free_pd_list(list); | |||||
free(ioc5); | |||||
free(ioc3); | |||||
return (NULL); | return (NULL); | ||||
} | |||||
free(ioc5); | free(ioc5); | ||||
disk = ioc3->PhysDisk; | disk = ioc3->PhysDisk; | ||||
for (i = 0; i < ioc3->NumPhysDisks; disk++, i++) | for (i = 0; i < ioc3->NumPhysDisks; disk++, i++) | ||||
if (mpt_pd_insert(fd, list, disk->PhysDiskNum) < 0) | if (mpt_pd_insert(fd, list, disk->PhysDiskNum) < 0) { | ||||
mpt_free_pd_list(list); | |||||
free(ioc3); | |||||
return (NULL); | return (NULL); | ||||
} | |||||
free(ioc3); | free(ioc3); | ||||
return (list); | return (list); | ||||
} | } | ||||
void | void | ||||
mpt_free_pd_list(struct mpt_drive_list *list) | mpt_free_pd_list(struct mpt_drive_list *list) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | drive_set_state(char *drive, U8 Action, U8 State, const char *name) | ||||
fd = mpt_open(mpt_unit); | fd = mpt_open(mpt_unit); | ||||
if (fd < 0) { | if (fd < 0) { | ||||
error = errno; | error = errno; | ||||
warn("mpt_open"); | warn("mpt_open"); | ||||
return (error); | return (error); | ||||
} | } | ||||
list = mpt_pd_list(fd); | list = mpt_pd_list(fd); | ||||
if (list == NULL) | if (list == NULL) { | ||||
close(fd); | |||||
return (errno); | return (errno); | ||||
} | |||||
if (mpt_lookup_drive(list, drive, &PhysDiskNum) < 0) { | if (mpt_lookup_drive(list, drive, &PhysDiskNum) < 0) { | ||||
error = errno; | error = errno; | ||||
warn("Failed to find drive %s", drive); | warn("Failed to find drive %s", drive); | ||||
close(fd); | |||||
return (error); | return (error); | ||||
} | } | ||||
mpt_free_pd_list(list); | mpt_free_pd_list(list); | ||||
/* Get the info for this drive. */ | /* Get the info for this drive. */ | ||||
info = mpt_pd_info(fd, PhysDiskNum, NULL); | info = mpt_pd_info(fd, PhysDiskNum, NULL); | ||||
if (info == NULL) { | if (info == NULL) { | ||||
error = errno; | error = errno; | ||||
warn("Failed to fetch info for drive %u", PhysDiskNum); | warn("Failed to fetch info for drive %u", PhysDiskNum); | ||||
close(fd); | |||||
return (error); | return (error); | ||||
} | } | ||||
/* Try to change the state. */ | /* Try to change the state. */ | ||||
if (info->PhysDiskStatus.State == State) { | if (info->PhysDiskStatus.State == State) { | ||||
warnx("Drive %u is already in the desired state", PhysDiskNum); | warnx("Drive %u is already in the desired state", PhysDiskNum); | ||||
free(info); | |||||
close(fd); | |||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
error = mpt_raid_action(fd, Action, 0, 0, PhysDiskNum, 0, NULL, 0, NULL, | error = mpt_raid_action(fd, Action, 0, 0, PhysDiskNum, 0, NULL, 0, NULL, | ||||
NULL, 0, NULL, NULL, 0); | NULL, 0, NULL, NULL, 0); | ||||
if (error) { | if (error) { | ||||
warnc(error, "Failed to set drive %u to %s", PhysDiskNum, name); | warnc(error, "Failed to set drive %u to %s", PhysDiskNum, name); | ||||
free(info); | |||||
close(fd); | |||||
return (error); | return (error); | ||||
} | } | ||||
free(info); | free(info); | ||||
close(fd); | close(fd); | ||||
return (0); | return (0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |