2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2008 Yahoo!, Inc.
6 * Written by: John Baldwin <jhb@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
36 #include <sys/param.h>
37 #include <sys/errno.h>
47 MPT_TABLE(top, volume);
50 mpt_volstate(U8 State)
55 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL:
57 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED:
59 case MPI_RAIDVOL0_STATUS_STATE_FAILED:
61 case MPI_RAIDVOL0_STATUS_STATE_MISSING:
64 sprintf(buf, "VSTATE 0x%02x", State);
70 volume_name(int ac, char **av)
72 CONFIG_PAGE_RAID_VOL_1 *vnames;
73 U8 VolumeBus, VolumeID;
77 warnx("name: volume and name required");
81 if (strlen(av[2]) >= sizeof(vnames->Name)) {
82 warnx("name: new name is too long");
86 fd = mpt_open(mpt_unit);
93 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
95 warnc(error, "Invalid volume: %s", av[1]);
99 vnames = mpt_vol_names(fd, VolumeBus, VolumeID, NULL);
100 if (vnames == NULL) {
102 warn("Failed to fetch volume names");
107 if (vnames->Header.PageType != MPI_CONFIG_PAGEATTR_CHANGEABLE) {
108 warnx("Volume name is read only");
113 printf("mpt%u changing volume %s name from \"%s\" to \"%s\"\n",
114 mpt_unit, mpt_volume_name(VolumeBus, VolumeID), vnames->Name,
116 bzero(vnames->Name, sizeof(vnames->Name));
117 strcpy(vnames->Name, av[2]);
119 if (mpt_write_config_page(fd, vnames, NULL) < 0) {
121 warn("Failed to set volume name");
132 MPT_COMMAND(top, name, volume_name);
135 volume_status(int ac, char **av)
137 MPI_RAID_VOL_INDICATOR prog;
138 RAID_VOL0_STATUS VolumeStatus;
139 uint64_t total, remaining;
141 U8 VolumeBus, VolumeID;
145 warnx("volume status: %s", ac > 2 ? "extra arguments" :
150 fd = mpt_open(mpt_unit);
157 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
159 warnc(error, "Invalid volume: %s", av[1]);
164 error = mpt_raid_action(fd, MPI_RAID_ACTION_INDICATOR_STRUCT, VolumeBus,
165 VolumeID, 0, 0, NULL, 0, &VolumeStatus, (U32 *)&prog, sizeof(prog),
168 warnc(error, "Fetching volume status failed");
173 printf("Volume %s status:\n", mpt_volume_name(VolumeBus, VolumeID));
174 printf(" state: %s\n", mpt_volstate(VolumeStatus.State));
176 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED)
180 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_QUIESCED)
181 printf(", QUIESCED");
182 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
183 printf(", REBUILDING");
184 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE)
185 printf(", INACTIVE");
186 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_BAD_BLOCK_TABLE_FULL)
187 printf(", BAD BLOCK TABLE FULL");
189 if (VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
190 total = (uint64_t)prog.TotalBlocks.High << 32 |
191 prog.TotalBlocks.Low;
192 remaining = (uint64_t)prog.BlocksRemaining.High << 32 |
193 prog.BlocksRemaining.Low;
194 pct = (float)(total - remaining) * 100 / total;
195 printf(" resync: %.2f%% complete\n", pct);
201 MPT_COMMAND(volume, status, volume_status);
204 volume_cache(int ac, char **av)
206 CONFIG_PAGE_RAID_VOL_0 *volume;
207 U32 Settings, NewSettings;
208 U8 VolumeBus, VolumeID;
213 warnx("volume cache: %s", ac > 3 ? "extra arguments" :
214 "missing arguments");
218 for (s1 = av[2]; *s1 != '\0'; s1++)
220 if ((strcmp(av[2], "enable")) && (strcmp(av[2], "enabled")) &&
221 (strcmp(av[2], "disable")) && (strcmp(av[2], "disabled"))) {
222 warnx("volume cache: invalid flag, must be 'enable' or 'disable'\n");
226 fd = mpt_open(mpt_unit);
233 error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID);
235 warnc(error, "Invalid volume: %s", av[1]);
240 volume = mpt_vol_info(fd, VolumeBus, VolumeID, NULL);
241 if (volume == NULL) {
246 Settings = volume->VolumeSettings.Settings;
248 NewSettings = Settings;
249 if (strncmp(av[2], "enable", sizeof("enable")) == 0)
251 if (strncmp(av[2], "disable", sizeof("disable")) == 0)
252 NewSettings &= ~0x01;
254 if (NewSettings == Settings) {
255 warnx("volume cache unchanged");
261 volume->VolumeSettings.Settings = NewSettings;
262 error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS,
263 VolumeBus, VolumeID, 0, *(U32 *)&volume->VolumeSettings, NULL, 0,
264 NULL, NULL, 0, NULL, NULL, 0);
266 warnc(error, "volume cache change failed");
271 MPT_COMMAND(volume, cache, volume_cache);