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
30 * $FreeBSD: src/usr.sbin/mptutil/mpt_volume.c,v 1.2 2010/11/09 19:28:06 jhb Exp $
33 #include <sys/param.h>
34 #include <sys/errno.h>
44 MPT_TABLE(top
, volume
);
47 mpt_volstate(U8 State
)
52 case MPI_RAIDVOL0_STATUS_STATE_OPTIMAL
:
54 case MPI_RAIDVOL0_STATUS_STATE_DEGRADED
:
56 case MPI_RAIDVOL0_STATUS_STATE_FAILED
:
58 case MPI_RAIDVOL0_STATUS_STATE_MISSING
:
61 sprintf(buf
, "VSTATE 0x%02x", State
);
67 volume_name(int ac
, char **av
)
69 CONFIG_PAGE_RAID_VOL_1
*vnames
;
70 U8 VolumeBus
, VolumeID
;
74 warnx("name: volume and name required");
78 if (strlen(av
[2]) >= sizeof(vnames
->Name
)) {
79 warnx("name: new name is too long");
83 fd
= mpt_open(mpt_unit
);
90 error
= mpt_lookup_volume(fd
, av
[1], &VolumeBus
, &VolumeID
);
92 warnc(error
, "Invalid volume: %s", av
[1]);
96 vnames
= mpt_vol_names(fd
, VolumeBus
, VolumeID
, NULL
);
99 warn("Failed to fetch volume names");
103 if (vnames
->Header
.PageType
!= MPI_CONFIG_PAGEATTR_CHANGEABLE
) {
104 warnx("Volume name is read only");
107 printf("mpt%u changing volume %s name from \"%s\" to \"%s\"\n",
108 mpt_unit
, mpt_volume_name(VolumeBus
, VolumeID
), vnames
->Name
,
110 bzero(vnames
->Name
, sizeof(vnames
->Name
));
111 strcpy(vnames
->Name
, av
[2]);
113 if (mpt_write_config_page(fd
, vnames
, NULL
) < 0) {
115 warn("Failed to set volume name");
124 MPT_COMMAND(top
, name
, volume_name
);
127 volume_status(int ac
, char **av
)
129 MPI_RAID_VOL_INDICATOR prog
;
130 RAID_VOL0_STATUS VolumeStatus
;
131 uint64_t total
, remaining
;
133 U8 VolumeBus
, VolumeID
;
137 warnx("volume status: %s", ac
> 2 ? "extra arguments" :
142 fd
= mpt_open(mpt_unit
);
149 error
= mpt_lookup_volume(fd
, av
[1], &VolumeBus
, &VolumeID
);
151 warnc(error
, "Invalid volume: %s", av
[1]);
155 error
= mpt_raid_action(fd
, MPI_RAID_ACTION_INDICATOR_STRUCT
, VolumeBus
,
156 VolumeID
, 0, 0, NULL
, 0, &VolumeStatus
, (U32
*)&prog
, sizeof(prog
),
159 warnc(error
, "Fetching volume status failed");
163 printf("Volume %s status:\n", mpt_volume_name(VolumeBus
, VolumeID
));
164 printf(" state: %s\n", mpt_volstate(VolumeStatus
.State
));
166 if (VolumeStatus
.Flags
& MPI_RAIDVOL0_STATUS_FLAG_ENABLED
)
170 if (VolumeStatus
.Flags
& MPI_RAIDVOL0_STATUS_FLAG_QUIESCED
)
171 printf(", QUIESCED");
172 if (VolumeStatus
.Flags
& MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
)
173 printf(", REBUILDING");
174 if (VolumeStatus
.Flags
& MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE
)
175 printf(", INACTIVE");
176 if (VolumeStatus
.Flags
& MPI_RAIDVOL0_STATUS_FLAG_BAD_BLOCK_TABLE_FULL
)
177 printf(", BAD BLOCK TABLE FULL");
179 if (VolumeStatus
.Flags
& MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
) {
180 total
= (uint64_t)prog
.TotalBlocks
.High
<< 32 |
181 prog
.TotalBlocks
.Low
;
182 remaining
= (uint64_t)prog
.BlocksRemaining
.High
<< 32 |
183 prog
.BlocksRemaining
.Low
;
184 pct
= (float)(total
- remaining
) * 100 / total
;
185 printf(" resync: %.2f%% complete\n", pct
);
191 MPT_COMMAND(volume
, status
, volume_status
);
194 volume_cache(int ac
, char **av
)
196 CONFIG_PAGE_RAID_VOL_0
*volume
;
197 U32 Settings
, NewSettings
;
198 U8 VolumeBus
, VolumeID
;
203 warnx("volume cache: %s", ac
> 3 ? "extra arguments" :
204 "missing arguments");
208 for (s1
= av
[2]; *s1
!= '\0'; s1
++)
210 if ((strcmp(av
[2], "enable")) && (strcmp(av
[2], "enabled")) &&
211 (strcmp(av
[2], "disable")) && (strcmp(av
[2], "disabled"))) {
212 warnx("volume cache: invalid flag, must be 'enable' or 'disable'\n");
216 fd
= mpt_open(mpt_unit
);
223 error
= mpt_lookup_volume(fd
, av
[1], &VolumeBus
, &VolumeID
);
225 warnc(error
, "Invalid volume: %s", av
[1]);
229 volume
= mpt_vol_info(fd
, VolumeBus
, VolumeID
, NULL
);
233 Settings
= volume
->VolumeSettings
.Settings
;
235 NewSettings
= Settings
;
236 if (strncmp(av
[2], "enable", sizeof("enable")) == 0)
238 if (strncmp(av
[2], "disable", sizeof("disable")) == 0)
239 NewSettings
&= ~0x01;
241 if (NewSettings
== Settings
) {
242 warnx("volume cache unchanged");
247 volume
->VolumeSettings
.Settings
= NewSettings
;
248 error
= mpt_raid_action(fd
, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS
,
249 VolumeBus
, VolumeID
, 0, *(U32
*)&volume
->VolumeSettings
, NULL
, 0,
250 NULL
, NULL
, 0, NULL
, NULL
, 0);
252 warnc(error
, "volume cache change failed");
257 MPT_COMMAND(volume
, cache
, volume_cache
);