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
31 #include <sys/cdefs.h>
34 #include <sys/param.h>
35 #include <sys/errno.h>
45 MPT_TABLE(top, volume);
48 mpt_volstate(U8 State)
53 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
55 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
57 case MPI_RAIDVOL0_STATUS_STATE_FAILED:
59 case MPI_RAIDVOL0_STATUS_STATE_MISSING:
62 sprintf(buf, "VSTATE 0x%02x", State);
68 volume_name(int ac, char **av)
70 CONFIG_PAGE_RAID_VOL_1 *vnames;
71 U8 VolumeBus, VolumeID;
75 warnx("name: volume and name required");
79 if (strlen(av[2]) >= sizeof(vnames->Name)) {
80 warnx("name: new name is too long");
84 fd = mpt_open(mpt_unit);
90 if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
91 warn("Invalid volume: %s", av[1]);
95 vnames = mpt_vol_names(fd, VolumeBus, VolumeID, NULL);
97 warn("Failed to fetch volume names");
101 if (vnames->Header.PageType != MPI_CONFIG_PAGEATTR_CHANGEABLE) {
102 warnx("Volume name is read only");
105 printf("mpt%u changing volume %s name from \"%s\" to \"%s\"\n",
106 mpt_unit, mpt_volume_name(VolumeBus, VolumeID), vnames->Name,
108 bzero(vnames->Name, sizeof(vnames->Name));
109 strcpy(vnames->Name, av[2]);
111 if (mpt_write_config_page(fd, vnames, NULL) < 0) {
112 warn("Failed to set volume name");
121 MPT_COMMAND(top, name, volume_name);
124 volume_status(int ac, char **av)
126 MPI_RAID_VOL_INDICATOR prog;
127 RAID_VOL0_STATUS VolumeStatus;
128 uint64_t total, remaining;
130 U8 VolumeBus, VolumeID;
134 warnx("volume status: %s", ac > 2 ? "extra arguments" :
139 fd = mpt_open(mpt_unit);
145 if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
146 warn("Invalid volume: %s", av[1]);
150 if (mpt_raid_action(fd, MPI_RAID_ACTION_INDICATOR_STRUCT, VolumeBus,
151 VolumeID, 0, 0, NULL, 0, &VolumeStatus, (U32 *)&prog, sizeof(prog),
152 NULL, NULL, 0) < 0) {
153 warn("Fetching volume status failed");
157 printf("Volume %s status:\n", mpt_volume_name(VolumeBus, VolumeID));
158 printf(" state: %s\n", mpt_volstate(VolumeStatus.State));
160 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)
164 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_QUIESCED)
165 printf(", QUIESCED");
166 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
167 printf(", REBUILDING");
168 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE)
169 printf(", INACTIVE");
170 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_BAD_BLOCK_TABLE_FULL)
171 printf(", BAD BLOCK TABLE FULL");
173 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
174 total = (uint64_t)prog.TotalBlocks.High << 32 |
175 prog.TotalBlocks.Low;
176 remaining = (uint64_t)prog.BlocksRemaining.High << 32 |
177 prog.BlocksRemaining.Low;
178 pct = (float)(total - remaining) * 100 / total;
179 printf(" resync: %.2f%% complete\n", pct);
185 MPT_COMMAND(volume, status, volume_status);
188 volume_cache(int ac, char **av)
190 CONFIG_PAGE_RAID_VOL_0 *volume;
191 U32 Settings, NewSettings;
192 U8 VolumeBus, VolumeID;
197 warnx("volume cache: %s", ac > 3 ? "extra arguments" :
202 for (s1 = av[2]; *s1 != '\0'; s1++)
204 if ((strcmp(av[2], "enable")) && (strcmp(av[2], "enabled")) &&
205 (strcmp(av[2], "disable")) && (strcmp(av[2], "disabled"))) {
206 warnx("volume cache: invalid flag, must be 'enable' or 'disable'\n");
210 fd = mpt_open(mpt_unit);
216 if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) {
217 warn("Invalid volume: %s", av[1]);
221 volume = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
225 Settings = volume->VolumeSettings.Settings;
227 NewSettings = Settings;
228 if (strncmp(av[2], "enable", sizeof("enable")) == 0)
230 if (strncmp(av[2], "disable", sizeof("disable")) == 0)
231 NewSettings &= ~0x01;
233 if (NewSettings == Settings) {
234 warnx("volume cache unchanged\n");
239 volume->VolumeSettings.Settings = NewSettings;
240 if (mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
241 VolumeBus, VolumeID, 0, *(U32 *)&volume->VolumeSettings, NULL, 0,
242 NULL, NULL, 0, NULL, NULL, 0) < 0)
243 warnx("volume cache change failed, errno= %d\n", errno);
248 MPT_COMMAND(volume, cache, volume_cache);