1
|
<?php
|
2
|
/*
|
3
|
diag_gmirror.php
|
4
|
Copyright (C) 2014 Jim Pingle
|
5
|
|
6
|
Redistribution and use in source and binary forms, with or without
|
7
|
modification, are permitted provided that the following conditions are met:
|
8
|
|
9
|
1. Redistributions of source code must retain the above copyright notice,
|
10
|
this list of conditions and the following disclaimer.
|
11
|
|
12
|
2. Redistributions in binary form must reproduce the above copyright
|
13
|
notice, this list of conditions and the following disclaimer in the
|
14
|
documentation and/or other materials provided with the distribution.
|
15
|
|
16
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
17
|
INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
18
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
19
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
20
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
21
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
22
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
23
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
24
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
25
|
POSSIBILITY OF SUCH DAMAGE.
|
26
|
*/
|
27
|
|
28
|
/*
|
29
|
pfSense_BUILDER_BINARIES: /sbin/gmirror /sbin/geom /usr/bin/grep /usr/bin/egrep /usr/bin/cut /usr/bin/head
|
30
|
pfSense_BUILDER_BINARIES: /sbin/mount /usr/bin/awk /usr/bin/sed
|
31
|
pfSense_MODULE: gmirror
|
32
|
*/
|
33
|
|
34
|
##|+PRIV
|
35
|
##|*IDENT=page-diagnostics-gmirror
|
36
|
##|*NAME=Diagnostics: GEOM Mirrors
|
37
|
##|*DESCR=Allow access to the 'Diagnostics: GEOM Mirrors' page.
|
38
|
##|*MATCH=diag_gmirror.php*
|
39
|
##|-PRIV
|
40
|
|
41
|
require_once("guiconfig.inc");
|
42
|
require_once("config.inc");
|
43
|
require_once("gmirror.inc");
|
44
|
|
45
|
$pgtitle = array(gettext("Diagnostics"), gettext("GEOM Mirrors"));
|
46
|
|
47
|
include("head.inc");
|
48
|
|
49
|
?>
|
50
|
|
51
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
|
52
|
|
53
|
<?php include("fbegin.inc"); ?>
|
54
|
|
55
|
<?PHP
|
56
|
$action_list = array(
|
57
|
"forget" => gettext("Forget all formerly connected consumers"),
|
58
|
"clear" => gettext("Remove metadata from disk"),
|
59
|
"insert" => gettext("Insert consumer into mirror"),
|
60
|
"remove" => gettext("Remove consumer from mirror"),
|
61
|
"activate" => gettext("Reactivate consumer on mirror"),
|
62
|
"deactivate" => gettext("Deactivate consumer from mirror"),
|
63
|
"rebuild" => gettext("Force rebuild of mirror consumer"),
|
64
|
);
|
65
|
|
66
|
/* User tried to pass a bogus action */
|
67
|
if (!empty($_REQUEST['action']) && !array_key_exists($_REQUEST['action'], $action_list)) {
|
68
|
header("Location: diag_gmirror.php");
|
69
|
return;
|
70
|
}
|
71
|
|
72
|
if ($_POST) {
|
73
|
if (!isset($_POST['confirm']) || ($_POST['confirm'] != gettext("Confirm"))) {
|
74
|
header("Location: diag_gmirror.php");
|
75
|
return;
|
76
|
}
|
77
|
$input_errors = "";
|
78
|
|
79
|
if (($_POST['action'] != "clear") && !is_valid_mirror($_POST['mirror']))
|
80
|
$input_errors[] = gettext("You must supply a valid mirror name.");
|
81
|
|
82
|
if (!empty($_POST['consumer']) && !is_valid_consumer($_POST['consumer']))
|
83
|
$input_errors[] = gettext("You must supply a valid consumer name");
|
84
|
|
85
|
/* Additional action-specific validation that hasn't already been tested */
|
86
|
switch ($_POST['action']) {
|
87
|
case "insert":
|
88
|
if (!is_consumer_unused($_POST['consumer']))
|
89
|
$input_errors[] = gettext("Consumer is already in use and cannot be inserted. Remove consumer from existing mirror first.");
|
90
|
if (gmirror_consumer_has_metadata($_POST['consumer']))
|
91
|
$input_errors[] = gettext("Consumer has metadata from an existing mirror. Clear metadata before inserting consumer.");
|
92
|
$mstat = gmirror_get_status_single($_POST['mirror']);
|
93
|
if (strtoupper($mstat) != "COMPLETE")
|
94
|
$input_errors[] = gettext("Mirror is not in a COMPLETE state, cannot insert consumer. Forget disconnected disks or wait for rebuild to finish.");
|
95
|
break;
|
96
|
case "clear":
|
97
|
if (!is_consumer_unused($_POST['consumer']))
|
98
|
$input_errors[] = gettext("Consumer is in use and cannot be cleared. Deactivate disk first.");
|
99
|
if (!gmirror_consumer_has_metadata($_POST['consumer']))
|
100
|
$input_errors[] = gettext("Consumer has no metadata to clear.");
|
101
|
break;
|
102
|
case "activate":
|
103
|
if (is_consumer_in_mirror($_POST['consumer'], $_POST['mirror']))
|
104
|
$input_errors[] = gettext("Consumer is already present on specified mirror.");
|
105
|
if (!gmirror_consumer_has_metadata($_POST['consumer']))
|
106
|
$input_errors[] = gettext("Consumer has no metadata and cannot be reactivated.");
|
107
|
|
108
|
break;
|
109
|
case "remove":
|
110
|
case "deactivate":
|
111
|
case "rebuild":
|
112
|
if (!is_consumer_in_mirror($_POST['consumer'], $_POST['mirror']))
|
113
|
$input_errors[] = gettext("Consumer must be present on the specified mirror.");
|
114
|
break;
|
115
|
}
|
116
|
|
117
|
$result = 0;
|
118
|
if (empty($input_errors)) {
|
119
|
switch ($_POST['action']) {
|
120
|
case "forget":
|
121
|
$result = gmirror_forget_disconnected($_POST['mirror']);
|
122
|
break;
|
123
|
case "clear":
|
124
|
$result = gmirror_clear_consumer($_POST['consumer']);
|
125
|
break;
|
126
|
case "insert":
|
127
|
$result = gmirror_insert_consumer($_POST['mirror'], $_POST['consumer']);
|
128
|
break;
|
129
|
case "remove":
|
130
|
$result = gmirror_remove_consumer($_POST['mirror'], $_POST['consumer']);
|
131
|
break;
|
132
|
case "activate":
|
133
|
$result = gmirror_activate_consumer($_POST['mirror'], $_POST['consumer']);
|
134
|
break;
|
135
|
case "deactivate":
|
136
|
$result = gmirror_deactivate_consumer($_POST['mirror'], $_POST['consumer']);
|
137
|
break;
|
138
|
case "rebuild":
|
139
|
$result = gmirror_force_rebuild($_POST['mirror'], $_POST['consumer']);
|
140
|
break;
|
141
|
}
|
142
|
$redir = "Location: diag_gmirror.php";
|
143
|
if ($result != 0) {
|
144
|
$redir .= "?error=" . urlencode($result);
|
145
|
}
|
146
|
/* If we reload the page too fast, the gmirror information may be missing or not up-to-date. */
|
147
|
sleep(3);
|
148
|
header($redir);
|
149
|
return;
|
150
|
}
|
151
|
}
|
152
|
|
153
|
$mirror_status = gmirror_get_status();
|
154
|
$mirror_list = gmirror_get_mirrors();
|
155
|
$unused_disks = gmirror_get_disks();
|
156
|
$unused_consumers = array();
|
157
|
foreach ($unused_disks as $disk) {
|
158
|
if (is_consumer_unused($disk))
|
159
|
$unused_consumers = array_merge($unused_consumers, gmirror_get_all_unused_consumer_sizes_on_disk($disk));
|
160
|
}
|
161
|
|
162
|
if ($input_errors)
|
163
|
print_input_errors($input_errors);
|
164
|
if ($_GET["error"] && ($_GET["error"] != 0))
|
165
|
print_info_box(gettext("There was an error performing the chosen mirror operation. Check the System Log for details."));
|
166
|
|
167
|
?>
|
168
|
<form action="diag_gmirror.php" method="POST" id="gmirror_form" name="gmirror_form">
|
169
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
170
|
<tr>
|
171
|
<td id="mainarea">
|
172
|
<div class="tabcont">
|
173
|
<span class="vexpl">
|
174
|
<span class="red">
|
175
|
<strong><?=gettext("NOTE:")?> </strong>
|
176
|
</span>
|
177
|
<?=gettext("The options on this page are intended for use by advanced users only. This page is for managing existing mirrors, not creating new mirrors.")?>
|
178
|
<br />
|
179
|
</span>
|
180
|
<p/>
|
181
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
182
|
|
183
|
<?PHP if ($_GET["action"]): ?>
|
184
|
<tr>
|
185
|
<td colspan="2" valign="top" class="listtopic"><?PHP echo gettext("Confirm Action"); ?></td>
|
186
|
</tr>
|
187
|
<tr>
|
188
|
<td width="22%" valign="top" class="vncell"> </td>
|
189
|
<td width="78%" class="vtable">
|
190
|
<strong><?PHP echo gettext("Please confirm the selected action"); ?></strong>:
|
191
|
<br />
|
192
|
<br /><strong><?PHP echo gettext("Action"); ?>:</strong> <?PHP echo $action_list[$_GET["action"]]; ?>
|
193
|
<input type="hidden" name="action" value="<?PHP echo htmlspecialchars($_GET["action"]); ?>" />
|
194
|
<?PHP if (!empty($_GET["mirror"])): ?>
|
195
|
<br /><strong><?PHP echo gettext("Mirror"); ?>:</strong> <?PHP echo htmlspecialchars($_GET["mirror"]); ?>
|
196
|
<input type="hidden" name="mirror" value="<?PHP echo htmlspecialchars($_GET["mirror"]); ?>" />
|
197
|
<?PHP endif; ?>
|
198
|
<?PHP if (!empty($_GET["consumer"])): ?>
|
199
|
<br /><strong><?PHP echo gettext("Consumer"); ?>:</strong> <?PHP echo htmlspecialchars($_GET["consumer"]); ?>
|
200
|
<input type="hidden" name="consumer" value="<?PHP echo htmlspecialchars($_GET["consumer"]); ?>" />
|
201
|
<?PHP endif; ?>
|
202
|
<br />
|
203
|
<br /><input type="submit" name="confirm" value="<?PHP echo gettext("Confirm"); ?>" />
|
204
|
</td>
|
205
|
</tr>
|
206
|
<?PHP else: ?>
|
207
|
<tr>
|
208
|
<td colspan="2" valign="top" class="listtopic"><?PHP echo gettext("GEOM Mirror information"); ?></td>
|
209
|
</tr>
|
210
|
|
211
|
<tr>
|
212
|
<td width="22%" valign="top" class="vncell"><?PHP echo gettext("Mirror Status"); ?></td>
|
213
|
<td width="78%" class="vtable">
|
214
|
|
215
|
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="gmirror status">
|
216
|
<tbody id="gmirror_status_table">
|
217
|
<?PHP if (count($mirror_status) > 0): ?>
|
218
|
<tr>
|
219
|
<td width="30%" class="vncellt"><?PHP echo gettext("Name"); ?></td>
|
220
|
<td width="30%" class="vncellt"><?PHP echo gettext("Status"); ?></td>
|
221
|
<td width="40%" class="vncellt"><?PHP echo gettext("Component"); ?></td>
|
222
|
</tr>
|
223
|
<?PHP foreach ($mirror_status as $mirror => $name):
|
224
|
$components = count($name["components"]); ?>
|
225
|
<tr>
|
226
|
<td width="30%" rowspan="<?PHP echo $components; ?>" class="listr">
|
227
|
<?PHP echo htmlspecialchars($name['name']); ?>
|
228
|
<br />Size: <?PHP echo gmirror_get_mirror_size($name['name']); ?>
|
229
|
</td>
|
230
|
<td width="30%" rowspan="<?PHP echo $components; ?>" class="listr">
|
231
|
<?PHP echo htmlspecialchars($name['status']); ?>
|
232
|
<?PHP if (strtoupper($name['status']) == "DEGRADED"): ?>
|
233
|
<br /><a href="diag_gmirror.php?action=forget&mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Forget Disconnected Disks"); ?>]</a>
|
234
|
<?PHP endif; ?>
|
235
|
</td>
|
236
|
<td width="40%" class="listr">
|
237
|
<?PHP echo $name['components'][0]; ?>
|
238
|
<?PHP list($cname, $cstatus) = explode(" ", $name['components'][0], 2); ?>
|
239
|
<br />
|
240
|
<?PHP if ((strtoupper($name['status']) == "COMPLETE") && (count($name["components"]) > 1)): ?>
|
241
|
<a href="diag_gmirror.php?action=rebuild&consumer=<?PHP echo htmlspecialchars($cname); ?>&mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Rebuild"); ?>]</a>
|
242
|
<a href="diag_gmirror.php?action=deactivate&consumer=<?PHP echo htmlspecialchars($cname); ?>&mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Deactivate"); ?>]</a>
|
243
|
<a href="diag_gmirror.php?action=remove&consumer=<?PHP echo htmlspecialchars($cname); ?>&mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Remove"); ?>]</a>
|
244
|
<?PHP endif; ?>
|
245
|
</td>
|
246
|
</tr>
|
247
|
<?PHP if (count($name["components"]) > 1):
|
248
|
$morecomponents = array_slice($name["components"], 1); ?>
|
249
|
<?PHP foreach ($morecomponents as $component): ?>
|
250
|
<tr>
|
251
|
<td width="40%" class="listr">
|
252
|
<?PHP echo $component; ?>
|
253
|
<?PHP list($cname, $cstatus) = explode(" ", $component, 2); ?>
|
254
|
<br />
|
255
|
<?PHP if ((strtoupper($name['status']) == "COMPLETE") && (count($name["components"]) > 1)): ?>
|
256
|
<a href="diag_gmirror.php?action=rebuild&consumer=<?PHP echo htmlspecialchars($cname); ?>&mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Rebuild"); ?>]</a>
|
257
|
<a href="diag_gmirror.php?action=deactivate&consumer=<?PHP echo htmlspecialchars($cname); ?>&mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Deactivate"); ?>]</a>
|
258
|
<a href="diag_gmirror.php?action=remove&consumer=<?PHP echo htmlspecialchars($cname); ?>&mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Remove"); ?>]</a>
|
259
|
<?PHP endif; ?>
|
260
|
</td>
|
261
|
</tr>
|
262
|
<?PHP endforeach; ?>
|
263
|
<?PHP endif; ?>
|
264
|
<?PHP endforeach; ?>
|
265
|
<?PHP else: ?>
|
266
|
<tr><td colspan="3" class="listr"><?PHP echo gettext("No Mirrors Found"); ?></td></tr>
|
267
|
<?PHP endif; ?>
|
268
|
</tbody>
|
269
|
</table>
|
270
|
<br /><?PHP echo gettext("Some disk operations may only be performed when there are multiple consumers present in a mirror."); ?>
|
271
|
</td>
|
272
|
</tr>
|
273
|
|
274
|
<tr>
|
275
|
<td colspan="2" valign="top" class="listtopic"><?PHP echo gettext("Consumer information"); ?></td>
|
276
|
</tr>
|
277
|
|
278
|
<tr>
|
279
|
<td width="22%" valign="top" class="vncell"><?PHP echo gettext("Available Consumers"); ?></td>
|
280
|
<td width="78%" class="vtable">
|
281
|
|
282
|
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="consumer list">
|
283
|
<tbody id="consumer_list">
|
284
|
<?PHP if (count($unused_consumers) > 0): ?>
|
285
|
<tr>
|
286
|
<td width="30%" class="vncellt"><?PHP echo gettext("Name"); ?></td>
|
287
|
<td width="30%" class="vncellt"><?PHP echo gettext("Size"); ?></td>
|
288
|
<td width="40%" class="vncellt"><?PHP echo gettext("Add to Mirror"); ?></td>
|
289
|
</tr>
|
290
|
<?PHP foreach ($unused_consumers as $consumer): ?>
|
291
|
<tr>
|
292
|
<td width="30%" class="listr">
|
293
|
<?PHP echo htmlspecialchars($consumer['name']); ?>
|
294
|
</td>
|
295
|
<td width="30%" class="listr"><?PHP echo htmlspecialchars($consumer['size']); ?> <?PHP echo htmlspecialchars($consumer['humansize']); ?></td>
|
296
|
<td width="40%" class="listr">
|
297
|
<?PHP $oldmirror = gmirror_get_consumer_metadata_mirror($consumer['name']);
|
298
|
if ($oldmirror): ?>
|
299
|
<a href="diag_gmirror.php?action=activate&consumer=<?PHP echo htmlspecialchars($consumer['name']); ?>&mirror=<?PHP echo htmlspecialchars($oldmirror); ?>">[<?PHP echo gettext("Reactivate on:"); ?> <?PHP echo htmlspecialchars($oldmirror); ?>]</a>
|
300
|
<br /><a href="diag_gmirror.php?action=clear&consumer=<?PHP echo htmlspecialchars($consumer['name']); ?>">[<?PHP echo gettext("Remove metadata from disk"); ?>]</a>
|
301
|
<?PHP else: ?>
|
302
|
<?PHP foreach ($mirror_list as $mirror):
|
303
|
$mirror_size = gmirror_get_mirror_size($mirror);
|
304
|
$consumer_size = gmirror_get_unused_consumer_size($consumer['name']);
|
305
|
?>
|
306
|
<?PHP if ($consumer_size > $mirror_size): ?>
|
307
|
<a href="diag_gmirror.php?action=insert&consumer=<?PHP echo htmlspecialchars($consumer['name']); ?>&mirror=<?PHP echo htmlspecialchars($mirror); ?>"><?PHP echo htmlspecialchars($mirror); ?></a>
|
308
|
<?PHP endif; ?>
|
309
|
<?PHP endforeach; ?>
|
310
|
<?PHP endif; ?>
|
311
|
</td>
|
312
|
</tr>
|
313
|
<?PHP endforeach; ?>
|
314
|
<?PHP else: ?>
|
315
|
<tr><td colspan="3" class="listr"><?PHP echo gettext("No unused consumers found"); ?></td></tr>
|
316
|
<?PHP endif; ?>
|
317
|
</tbody>
|
318
|
</table>
|
319
|
<br /><?PHP echo gettext("Consumers may only be added to a mirror if they are larger than the size of the mirror."); ?>
|
320
|
</td>
|
321
|
</tr>
|
322
|
<tr>
|
323
|
<td colspan="2" valign="top" class=""> </td>
|
324
|
</tr>
|
325
|
<tr>
|
326
|
<td colspan="2" valign="top" class=""><?PHP echo gettext("To repair a failed mirror, first perform a 'Forget' command on the mirror, followed by an 'insert' action on the new consumer."); ?></td>
|
327
|
</tr>
|
328
|
<?PHP endif;?>
|
329
|
</table>
|
330
|
</div>
|
331
|
</td>
|
332
|
</tr>
|
333
|
</table>
|
334
|
</form>
|
335
|
<?php require("fend.inc"); ?>
|
336
|
</body>
|
337
|
</html>
|
338
|
|
339
|
<?php
|
340
|
|
341
|
// Clear the loading indicator
|
342
|
echo "<script type=\"text/javascript\">";
|
343
|
echo "jQuery('#loading').html('');";
|
344
|
echo "</script>";
|
345
|
|
346
|
?>
|