Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/mptutil/mpt_volume.c
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | if (error) { | ||||
warnc(error, "Invalid volume: %s", av[1]); | warnc(error, "Invalid volume: %s", av[1]); | ||||
return (error); | return (error); | ||||
} | } | ||||
vnames = mpt_vol_names(fd, VolumeBus, VolumeID, NULL); | vnames = mpt_vol_names(fd, VolumeBus, VolumeID, NULL); | ||||
if (vnames == NULL) { | if (vnames == NULL) { | ||||
error = errno; | error = errno; | ||||
warn("Failed to fetch volume names"); | warn("Failed to fetch volume names"); | ||||
close(fd); | |||||
return (error); | return (error); | ||||
} | } | ||||
if (vnames->Header.PageType != MPI_CONFIG_PAGEATTR_CHANGEABLE) { | if (vnames->Header.PageType != MPI_CONFIG_PAGEATTR_CHANGEABLE) { | ||||
warnx("Volume name is read only"); | warnx("Volume name is read only"); | ||||
free(vnames); | |||||
close(fd); | |||||
return (EOPNOTSUPP); | return (EOPNOTSUPP); | ||||
} | } | ||||
printf("mpt%u changing volume %s name from \"%s\" to \"%s\"\n", | printf("mpt%u changing volume %s name from \"%s\" to \"%s\"\n", | ||||
mpt_unit, mpt_volume_name(VolumeBus, VolumeID), vnames->Name, | mpt_unit, mpt_volume_name(VolumeBus, VolumeID), vnames->Name, | ||||
av[2]); | av[2]); | ||||
bzero(vnames->Name, sizeof(vnames->Name)); | bzero(vnames->Name, sizeof(vnames->Name)); | ||||
strcpy(vnames->Name, av[2]); | strcpy(vnames->Name, av[2]); | ||||
if (mpt_write_config_page(fd, vnames, NULL) < 0) { | if (mpt_write_config_page(fd, vnames, NULL) < 0) { | ||||
error = errno; | error = errno; | ||||
warn("Failed to set volume name"); | warn("Failed to set volume name"); | ||||
free(vnames); | |||||
close(fd); | |||||
return (error); | return (error); | ||||
} | } | ||||
free(vnames); | free(vnames); | ||||
close(fd); | close(fd); | ||||
return (0); | return (0); | ||||
} | } | ||||
Show All 20 Lines | if (fd < 0) { | ||||
error = errno; | error = errno; | ||||
warn("mpt_open"); | warn("mpt_open"); | ||||
return (error); | return (error); | ||||
} | } | ||||
error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID); | error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID); | ||||
if (error) { | if (error) { | ||||
warnc(error, "Invalid volume: %s", av[1]); | warnc(error, "Invalid volume: %s", av[1]); | ||||
close(fd); | |||||
return (error); | return (error); | ||||
} | } | ||||
error = mpt_raid_action(fd, MPI_RAID_ACTION_INDICATOR_STRUCT, VolumeBus, | error = mpt_raid_action(fd, MPI_RAID_ACTION_INDICATOR_STRUCT, VolumeBus, | ||||
VolumeID, 0, 0, NULL, 0, &VolumeStatus, (U32 *)&prog, sizeof(prog), | VolumeID, 0, 0, NULL, 0, &VolumeStatus, (U32 *)&prog, sizeof(prog), | ||||
NULL, NULL, 0); | NULL, NULL, 0); | ||||
if (error) { | if (error) { | ||||
warnc(error, "Fetching volume status failed"); | warnc(error, "Fetching volume status failed"); | ||||
close(fd); | |||||
return (error); | return (error); | ||||
} | } | ||||
printf("Volume %s status:\n", mpt_volume_name(VolumeBus, VolumeID)); | printf("Volume %s status:\n", mpt_volume_name(VolumeBus, VolumeID)); | ||||
printf(" state: %s\n", mpt_volstate(VolumeStatus.State)); | printf(" state: %s\n", mpt_volstate(VolumeStatus.State)); | ||||
printf(" flags:"); | printf(" flags:"); | ||||
if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED) | if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED) | ||||
printf(" ENABLED"); | printf(" ENABLED"); | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | if (fd < 0) { | ||||
error = errno; | error = errno; | ||||
warn("mpt_open"); | warn("mpt_open"); | ||||
return (error); | return (error); | ||||
} | } | ||||
error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID); | error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID); | ||||
if (error) { | if (error) { | ||||
warnc(error, "Invalid volume: %s", av[1]); | warnc(error, "Invalid volume: %s", av[1]); | ||||
close(fd); | |||||
return (error); | return (error); | ||||
} | } | ||||
volume = mpt_vol_info(fd, VolumeBus, VolumeID, NULL); | volume = mpt_vol_info(fd, VolumeBus, VolumeID, NULL); | ||||
if (volume == NULL) | if (volume == NULL) { | ||||
close(fd); | |||||
return (errno); | return (errno); | ||||
} | |||||
Settings = volume->VolumeSettings.Settings; | Settings = volume->VolumeSettings.Settings; | ||||
NewSettings = Settings; | NewSettings = Settings; | ||||
if (strncmp(av[2], "enable", sizeof("enable")) == 0) | if (strncmp(av[2], "enable", sizeof("enable")) == 0) | ||||
NewSettings |= 0x01; | NewSettings |= 0x01; | ||||
if (strncmp(av[2], "disable", sizeof("disable")) == 0) | if (strncmp(av[2], "disable", sizeof("disable")) == 0) | ||||
NewSettings &= ~0x01; | NewSettings &= ~0x01; | ||||
if (NewSettings == Settings) { | if (NewSettings == Settings) { | ||||
warnx("volume cache unchanged"); | warnx("volume cache unchanged"); | ||||
free(volume); | |||||
close(fd); | close(fd); | ||||
return (0); | return (0); | ||||
} | } | ||||
volume->VolumeSettings.Settings = NewSettings; | volume->VolumeSettings.Settings = NewSettings; | ||||
error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS, | error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS, | ||||
VolumeBus, VolumeID, 0, *(U32 *)&volume->VolumeSettings, NULL, 0, | VolumeBus, VolumeID, 0, *(U32 *)&volume->VolumeSettings, NULL, 0, | ||||
NULL, NULL, 0, NULL, NULL, 0); | NULL, NULL, 0, NULL, NULL, 0); | ||||
if (error) | if (error) | ||||
warnc(error, "volume cache change failed"); | warnc(error, "volume cache change failed"); | ||||
close(fd); | close(fd); | ||||
return (error); | return (error); | ||||
} | } | ||||
MPT_COMMAND(volume, cache, volume_cache); | MPT_COMMAND(volume, cache, volume_cache); |