Beispiel #1
0
int
mpt_lookup_volume(int fd, const char *name, U8 *VolumeBus, U8 *VolumeID)
{
	CONFIG_PAGE_IOC_2 *ioc2;
	CONFIG_PAGE_IOC_2_RAID_VOL *vol;
	struct mpt_query_disk info;
	char *cp;
	long bus, id;
	int i;

	/*
	 * Check for a raw [<bus>:]<id> string.  If the bus is not
	 * specified, assume bus 0.
	 */
	bus = strtol(name, &cp, 0);
	if (*cp == ':') {
		id = strtol(cp + 1, &cp, 0);
		if (*cp == '\0') {
			if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) {
				return (EINVAL);
			}
			*VolumeBus = bus;
			*VolumeID = id;
			return (0);
		}
	} else if (*cp == '\0') {
		if (bus < 0 || bus > 0xff)
			return (EINVAL);
		*VolumeBus = 0;
		*VolumeID = bus;
		return (0);
	}

	ioc2 = mpt_read_ioc_page(fd, 2, NULL);
	if (ioc2 == NULL)
		return (errno);

	vol = ioc2->RaidVolume;
	for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
		if (mpt_query_disk(vol->VolumeBus, vol->VolumeID, &info) != 0)
			continue;
		if (strcmp(name, info.devname) == 0) {
			*VolumeBus = vol->VolumeBus;
			*VolumeID = vol->VolumeID;
			free(ioc2);
			return (0);
		}
	}
	free(ioc2);
	return (EINVAL);
}
Beispiel #2
0
static int
show_adapter(int ac, char **av)
{
	CONFIG_PAGE_MANUFACTURING_0 *man0;
	CONFIG_PAGE_IOC_2 *ioc2;
	CONFIG_PAGE_IOC_6 *ioc6;
	U16 IOCStatus;
	int comma, error, fd;

	if (ac != 1) {
		warnx("show adapter: extra arguments");
		return (EINVAL);
	}

	fd = mpt_open(mpt_unit);
	if (fd < 0) {
		error = errno;
		warn("mpt_open");
		return (error);
	}

	man0 = mpt_read_man_page(fd, 0, NULL);
	if (man0 == NULL) {
		error = errno;
		warn("Failed to get controller info");
		return (error);
	}
	if (man0->Header.PageLength < sizeof(*man0) / 4) {
		warnx("Invalid controller info");
		return (EINVAL);
	}
	printf("mpt%d Adapter:\n", mpt_unit);
	printf("       Board Name: %.16s\n", man0->BoardName);
	printf("   Board Assembly: %.16s\n", man0->BoardAssembly);
	printf("        Chip Name: %.16s\n", man0->ChipName);
	printf("    Chip Revision: %.16s\n", man0->ChipRevision);

	free(man0);

	ioc2 = mpt_read_ioc_page(fd, 2, &IOCStatus);
	if (ioc2 != NULL) {
		printf("      RAID Levels:");
		comma = 0;
		if (ioc2->CapabilitiesFlags &
		    MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT) {
			printf(" RAID0");
			comma = 1;
		}
		if (ioc2->CapabilitiesFlags &
		    MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT) {
			printf("%s RAID1", comma ? "," : "");
			comma = 1;
		}
		if (ioc2->CapabilitiesFlags &
		    MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT) {
			printf("%s RAID1E", comma ? "," : "");
			comma = 1;
		}
		if (ioc2->CapabilitiesFlags &
		    MPI_IOCPAGE2_CAP_FLAGS_RAID_5_SUPPORT) {
			printf("%s RAID5", comma ? "," : "");
			comma = 1;
		}
		if (ioc2->CapabilitiesFlags &
		    MPI_IOCPAGE2_CAP_FLAGS_RAID_6_SUPPORT) {
			printf("%s RAID6", comma ? "," : "");
			comma = 1;
		}
		if (ioc2->CapabilitiesFlags &
		    MPI_IOCPAGE2_CAP_FLAGS_RAID_10_SUPPORT) {
			printf("%s RAID10", comma ? "," : "");
			comma = 1;
		}
		if (ioc2->CapabilitiesFlags &
		    MPI_IOCPAGE2_CAP_FLAGS_RAID_50_SUPPORT) {
			printf("%s RAID50", comma ? "," : "");
			comma = 1;
		}
		if (!comma)
			printf(" none");
		printf("\n");
		free(ioc2);
	} else if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
	    MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
		warnx("mpt_read_ioc_page(2): %s", mpt_ioc_status(IOCStatus));

	ioc6 = mpt_read_ioc_page(fd, 6, &IOCStatus);
	if (ioc6 != NULL) {
		display_stripe_map("    RAID0 Stripes",
		    ioc6->SupportedStripeSizeMapIS);
		display_stripe_map("   RAID1E Stripes",
		    ioc6->SupportedStripeSizeMapIME);
		printf(" RAID0 Drives/Vol: %u", ioc6->MinDrivesIS);
		if (ioc6->MinDrivesIS != ioc6->MaxDrivesIS)
			printf("-%u", ioc6->MaxDrivesIS);
		printf("\n");
		printf(" RAID1 Drives/Vol: %u", ioc6->MinDrivesIM);
		if (ioc6->MinDrivesIM != ioc6->MaxDrivesIM)
			printf("-%u", ioc6->MaxDrivesIM);
		printf("\n");
		printf("RAID1E Drives/Vol: %u", ioc6->MinDrivesIME);
		if (ioc6->MinDrivesIME != ioc6->MaxDrivesIME)
			printf("-%u", ioc6->MaxDrivesIME);
		printf("\n");
		free(ioc6);
	} else if ((IOCStatus & MPI_IOCSTATUS_MASK) !=
	    MPI_IOCSTATUS_CONFIG_INVALID_PAGE)
		warnx("mpt_read_ioc_page(6): %s", mpt_ioc_status(IOCStatus));

	/* TODO: Add an ioctl to fetch IOC_FACTS and print firmware version. */

	close(fd);

	return (0);
}
Beispiel #3
0
static int
show_volumes(int ac, char **av)
{
	CONFIG_PAGE_IOC_2 *ioc2;
	CONFIG_PAGE_IOC_2_RAID_VOL *vol;
	CONFIG_PAGE_RAID_VOL_0 **volumes;
	CONFIG_PAGE_RAID_VOL_1 *vnames;
	int error, fd, i, len, state_len;

	if (ac != 1) {
		warnx("show volumes: extra arguments");
		return (EINVAL);
	}

	fd = mpt_open(mpt_unit);
	if (fd < 0) {
		error = errno;
		warn("mpt_open");
		return (error);
	}

	/* Get the volume list from the controller. */
	ioc2 = mpt_read_ioc_page(fd, 2, NULL);
	if (ioc2 == NULL) {
		error = errno;
		warn("Failed to get volume list");
		return (error);
	}

	/*
	 * Go ahead and read the info for all the volumes and figure
	 * out the maximum width of the state field.
	 */
	volumes = malloc(sizeof(*volumes) * ioc2->NumActiveVolumes);
	state_len = strlen("State");
	vol = ioc2->RaidVolume;
	for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
		volumes[i] = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID,
		    NULL);
		if (volumes[i] == NULL)
			len = strlen("UNKNOWN");
		else
			len = strlen(mpt_volstate(
			    volumes[i]->VolumeStatus.State));
		if (len > state_len)
			state_len = len;
	}
	printf("mpt%d Volumes:\n", mpt_unit);
	printf("  Id     Size    Level   Stripe ");
	len = state_len - strlen("State");
	for (i = 0; i < (len + 1) / 2; i++)
		printf(" ");
	printf("State");
	for (i = 0; i < len / 2; i++)
		printf(" ");
	printf(" Write-Cache  Name\n");
	vol = ioc2->RaidVolume;
	for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
		printf("%6s ", mpt_volume_name(vol->VolumeBus, vol->VolumeID));
		if (volumes[i] != NULL)
			print_vol(volumes[i], state_len);
		else
			printf("         %-8s %-*s",
			    mpt_raid_level(vol->VolumeType), state_len,
			    "UNKNOWN");
		if (volumes[i] != NULL) {
			if (volumes[i]->VolumeSettings.Settings &
			    MPI_RAIDVOL0_SETTING_WRITE_CACHING_ENABLE)
				printf("   Enabled   ");
			else
				printf("   Disabled  ");
		} else
			printf("             ");
		free(volumes[i]);
		vnames = mpt_vol_names(fd, vol->VolumeBus, vol->VolumeID, NULL);
		if (vnames != NULL) {
			if (vnames->Name[0] != '\0')
				printf(" <%s>", vnames->Name);
			free(vnames);
		}
		printf("\n");
	}
	free(ioc2);
	close(fd);

	return (0);
}
Beispiel #4
0
static int
show_config(int ac, char **av)
{
	CONFIG_PAGE_IOC_2 *ioc2;
	CONFIG_PAGE_IOC_2_RAID_VOL *vol;
	CONFIG_PAGE_IOC_5 *ioc5;
	IOC_5_HOT_SPARE *spare;
	CONFIG_PAGE_RAID_VOL_0 *vinfo;
	RAID_VOL0_PHYS_DISK *disk;
	CONFIG_PAGE_RAID_VOL_1 *vnames;
	CONFIG_PAGE_RAID_PHYS_DISK_0 *pinfo;
	struct mpt_standalone_disk *sdisks;
	int error, fd, i, j, nsdisks;

	if (ac != 1) {
		warnx("show config: extra arguments");
		return (EINVAL);
	}

	fd = mpt_open(mpt_unit);
	if (fd < 0) {
		error = errno;
		warn("mpt_open");
		return (error);
	}

	/* Get the config from the controller. */
	ioc2 = mpt_read_ioc_page(fd, 2, NULL);
	ioc5 = mpt_read_ioc_page(fd, 5, NULL);
	if (ioc2 == NULL || ioc5 == NULL) {
		error = errno;
		warn("Failed to get config");
		return (error);
	}
	if (mpt_fetch_disks(fd, &nsdisks, &sdisks) < 0) {
		error = errno;
		warn("Failed to get standalone drive list");
		return (error);
	}

	/* Dump out the configuration. */
	printf("mpt%d Configuration: %d volumes, %d drives\n",
	    mpt_unit, ioc2->NumActiveVolumes, ioc2->NumActivePhysDisks +
	    nsdisks);
	vol = ioc2->RaidVolume;
	for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
		printf("    volume %s ", mpt_volume_name(vol->VolumeBus,
		    vol->VolumeID));
		vinfo = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL);
		if (vinfo == NULL) {
			printf("%s UNKNOWN", mpt_raid_level(vol->VolumeType));
		} else
			print_vol(vinfo, -1);
		vnames = mpt_vol_names(fd, vol->VolumeBus, vol->VolumeID, NULL);
		if (vnames != NULL) {
			if (vnames->Name[0] != '\0')
				printf(" <%s>", vnames->Name);
			free(vnames);
		}
		if (vinfo == NULL) {
			printf("\n");
			continue;
		}
		printf(" spans:\n");
		disk = vinfo->PhysDisk;
		for (j = 0; j < vinfo->NumPhysDisks; disk++, j++) {
			printf("        drive %u ", disk->PhysDiskNum);
			pinfo = mpt_pd_info(fd, disk->PhysDiskNum, NULL);
			if (pinfo != NULL) {
				print_pd(pinfo, -1, 0);
				free(pinfo);
			}
			printf("\n");
		}
		if (vinfo->VolumeSettings.HotSparePool != 0) {
			printf("        spare pools: ");
			print_spare_pools(vinfo->VolumeSettings.HotSparePool);
			printf("\n");
		}
		free(vinfo);
	}

	spare = ioc5->HotSpare;
	for (i = 0; i < ioc5->NumHotSpares; spare++, i++) {
		printf("    spare %u ", spare->PhysDiskNum);
		pinfo = mpt_pd_info(fd, spare->PhysDiskNum, NULL);
		if (pinfo != NULL) {
			print_pd(pinfo, -1, 0);
			free(pinfo);
		}
		printf(" backs pool %d\n", ffs(spare->HotSparePool) - 1);
	}
	for (i = 0; i < nsdisks; i++) {
		printf("    drive %s ", sdisks[i].devname);
		print_standalone(&sdisks[i], -1, 0);
		printf("\n");
	}
	free(ioc2);
	free(ioc5);
	free(sdisks);
	close(fd);

	return (0);
}
Beispiel #5
0
struct mpt_drive_list *
mpt_pd_list(int fd)
{
	CONFIG_PAGE_IOC_2 *ioc2;
	CONFIG_PAGE_IOC_2_RAID_VOL *vol;
	CONFIG_PAGE_RAID_VOL_0 **volumes;
	RAID_VOL0_PHYS_DISK *rdisk;
	CONFIG_PAGE_IOC_3 *ioc3;
	IOC_3_PHYS_DISK *disk;
	CONFIG_PAGE_IOC_5 *ioc5;
	IOC_5_HOT_SPARE *spare;
	struct mpt_drive_list *list;
	int count, error, i, j;

	ioc2 = mpt_read_ioc_page(fd, 2, NULL);
	if (ioc2 == NULL) {
		error = errno;
		warn("Failed to fetch volume list");
		errno = error;
		return (NULL);
	}

	ioc3 = mpt_read_ioc_page(fd, 3, NULL);
	if (ioc3 == NULL) {
		error = errno;
		warn("Failed to fetch drive list");
		free(ioc2);
		errno = error;
		return (NULL);
	}

	ioc5 = mpt_read_ioc_page(fd, 5, NULL);
	if (ioc5 == NULL) {
		error = errno;
		warn("Failed to fetch spare list");
		free(ioc3);
		free(ioc2);
		errno = error;
		return (NULL);
	}

	/*
	 * Go ahead and read the info for all the volumes.  For this
	 * pass we figure out how many physical drives there are.
	 */
	volumes = malloc(sizeof(*volumes) * ioc2->NumActiveVolumes);
	count = 0;
	vol = ioc2->RaidVolume;
	for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) {
		volumes[i] = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID,
		    NULL);
		if (volumes[i] == NULL) {
			error = errno;
			warn("Failed to read volume info");
			errno = error;
			return (NULL);
		}
		count += volumes[i]->NumPhysDisks;
	}
	count += ioc3->NumPhysDisks;
	count += ioc5->NumHotSpares;

	/* Walk the various lists enumerating drives. */
	list = malloc(sizeof(*list) + sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0) *
	    count);
	list->ndrives = 0;

	for (i = 0; i < ioc2->NumActiveVolumes; i++) {
		rdisk = volumes[i]->PhysDisk;
		for (j = 0; j < volumes[i]->NumPhysDisks; rdisk++, j++)
			if (mpt_pd_insert(fd, list, rdisk->PhysDiskNum) < 0)
				return (NULL);
		free(volumes[i]);
	}
	free(ioc2);
	free(volumes);

	spare = ioc5->HotSpare;
	for (i = 0; i < ioc5->NumHotSpares; spare++, i++)
		if (mpt_pd_insert(fd, list, spare->PhysDiskNum) < 0)
			return (NULL);
	free(ioc5);

	disk = ioc3->PhysDisk;
	for (i = 0; i < ioc3->NumPhysDisks; disk++, i++)
		if (mpt_pd_insert(fd, list, disk->PhysDiskNum) < 0)
			return (NULL);
	free(ioc3);

	return (list);
}