Project

General

Profile

Download (14.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_gmirror.php
4
	Copyright (C) 2014 Jim Pingle
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6

    
7
	Redistribution and use in source and binary forms, with or without
8
	modification, are permitted provided that the following conditions are met:
9

    
10
	1. Redistributions of source code must retain the above copyright notice,
11
	this list of conditions and the following disclaimer.
12

    
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

    
17
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
	INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
	POSSIBILITY OF SUCH DAMAGE.
27
*/
28

    
29
/*
30
	pfSense_BUILDER_BINARIES:	/sbin/gmirror	/sbin/geom	/usr/bin/grep	/usr/bin/egrep	/usr/bin/cut	/usr/bin/head
31
	pfSense_BUILDER_BINARIES:	/sbin/mount	/usr/bin/awk	/usr/bin/sed
32
	pfSense_MODULE:	gmirror
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-diagnostics-gmirror
37
##|*NAME=Diagnostics: GEOM Mirrors
38
##|*DESCR=Allow access to the 'Diagnostics: GEOM Mirrors' page.
39
##|*MATCH=diag_gmirror.php*
40
##|-PRIV
41

    
42
require_once("guiconfig.inc");
43
require_once("config.inc");
44
require_once("gmirror.inc");
45

    
46
$pgtitle = array(gettext("Diagnostics"), gettext("GEOM Mirrors"));
47

    
48
include("head.inc");
49

    
50
?>
51

    
52
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?=$jsevents["body"]["onload"];?>">
53

    
54
<?php include("fbegin.inc"); ?>
55

    
56
<?PHP
57
$action_list = array(
58
	"forget" => gettext("Forget all formerly connected consumers"),
59
	"clear" => gettext("Remove metadata from disk"),
60
	"insert" => gettext("Insert consumer into mirror"),
61
	"remove" => gettext("Remove consumer from mirror"),
62
	"activate" => gettext("Reactivate consumer on mirror"),
63
	"deactivate" => gettext("Deactivate consumer from mirror"),
64
	"rebuild" => gettext("Force rebuild of mirror consumer"),
65
);
66

    
67
/* User tried to pass a bogus action */
68
if (!empty($_REQUEST['action']) && !array_key_exists($_REQUEST['action'], $action_list)) {
69
	header("Location: diag_gmirror.php");
70
	return;
71
}
72

    
73
if ($_POST) {
74
	if (!isset($_POST['confirm']) || ($_POST['confirm'] != gettext("Confirm"))) {
75
		header("Location: diag_gmirror.php");
76
		return;
77
	}
78
	$input_errors = "";
79

    
80
	if (($_POST['action'] != "clear") && !is_valid_mirror($_POST['mirror']))
81
		$input_errors[] = gettext("You must supply a valid mirror name.");
82

    
83
	if (!empty($_POST['consumer']) && !is_valid_consumer($_POST['consumer']))
84
		$input_errors[] = gettext("You must supply a valid consumer name");
85

    
86
	/* Additional action-specific validation that hasn't already been tested */
87
	switch ($_POST['action']) {
88
		case "insert":
89
			if (!is_consumer_unused($_POST['consumer']))
90
				$input_errors[] = gettext("Consumer is already in use and cannot be inserted. Remove consumer from existing mirror first.");
91
			if (gmirror_consumer_has_metadata($_POST['consumer']))
92
				$input_errors[] = gettext("Consumer has metadata from an existing mirror. Clear metadata before inserting consumer.");
93
			$mstat = gmirror_get_status_single($_POST['mirror']);
94
			if (strtoupper($mstat) != "COMPLETE")
95
				$input_errors[] = gettext("Mirror is not in a COMPLETE state, cannot insert consumer. Forget disconnected disks or wait for rebuild to finish.");
96
			break;
97
		case "clear":
98
			if (!is_consumer_unused($_POST['consumer']))
99
				$input_errors[] = gettext("Consumer is in use and cannot be cleared. Deactivate disk first.");
100
			if (!gmirror_consumer_has_metadata($_POST['consumer']))
101
				$input_errors[] = gettext("Consumer has no metadata to clear.");
102
			break;
103
		case "activate":
104
			if (is_consumer_in_mirror($_POST['consumer'], $_POST['mirror']))
105
				$input_errors[] = gettext("Consumer is already present on specified mirror.");
106
			if (!gmirror_consumer_has_metadata($_POST['consumer']))
107
				$input_errors[] = gettext("Consumer has no metadata and cannot be reactivated.");
108
			
109
			break;
110
		case "remove":
111
		case "deactivate":
112
		case "rebuild":
113
			if (!is_consumer_in_mirror($_POST['consumer'], $_POST['mirror']))
114
				$input_errors[] = gettext("Consumer must be present on the specified mirror.");
115
			break;
116
	}
117

    
118
$result = 0;
119
	if (empty($input_errors)) {
120
		switch ($_POST['action']) {
121
			case "forget":
122
				$result = gmirror_forget_disconnected($_POST['mirror']);
123
				break;
124
			case "clear":
125
				$result = gmirror_clear_consumer($_POST['consumer']);
126
				break;
127
			case "insert":
128
				$result = gmirror_insert_consumer($_POST['mirror'], $_POST['consumer']);
129
				break;
130
			case "remove":
131
				$result = gmirror_remove_consumer($_POST['mirror'], $_POST['consumer']);
132
				break;
133
			case "activate":
134
				$result = gmirror_activate_consumer($_POST['mirror'], $_POST['consumer']);
135
				break;
136
			case "deactivate":
137
				$result = gmirror_deactivate_consumer($_POST['mirror'], $_POST['consumer']);
138
				break;
139
			case "rebuild":
140
				$result = gmirror_force_rebuild($_POST['mirror'], $_POST['consumer']);
141
				break;
142
		}
143
		$redir = "Location: diag_gmirror.php";
144
		if ($result != 0) {
145
			$redir .= "?error=" . urlencode($result);
146
		}
147
		/* If we reload the page too fast, the gmirror information may be missing or not up-to-date. */
148
		sleep(3);
149
		header($redir);
150
		return;
151
	}
152
}
153

    
154
$mirror_status = gmirror_get_status();
155
$mirror_list = gmirror_get_mirrors();
156
$unused_disks = gmirror_get_disks();
157
$unused_consumers = array();
158
foreach ($unused_disks as $disk) {
159
	if (is_consumer_unused($disk))
160
		$unused_consumers = array_merge($unused_consumers, gmirror_get_all_unused_consumer_sizes_on_disk($disk));
161
}
162

    
163
if ($input_errors)
164
	print_input_errors($input_errors);
165
if ($_GET["error"] && ($_GET["error"] != 0))
166
	print_info_box(gettext("There was an error performing the chosen mirror operation. Check the System Log for details."));
167

    
168
?>
169
<form action="diag_gmirror.php" method="POST" id="gmirror_form" name="gmirror_form">
170
<table width="100%" border="0" cellpadding="0" cellspacing="0">
171
	<tr>
172
		<td id="mainarea">
173
			<div class="tabcont">
174
				<span class="vexpl">
175
					<span class="red">
176
						<strong><?=gettext("NOTE:")?>&nbsp;</strong>
177
					</span>
178
					<?=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.")?>
179
					<br />&nbsp;
180
				</span>
181
				<p/>
182
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
183

    
184
<?PHP if ($_GET["action"]): ?>
185
					<tr>
186
						<td colspan="2" valign="top" class="listtopic"><?PHP echo gettext("Confirm Action"); ?></td>
187
					</tr>
188
					<tr>
189
						<td width="22%" valign="top" class="vncell">&nbsp;</td>
190
						<td width="78%" class="vtable">
191
							<strong><?PHP echo gettext("Please confirm the selected action"); ?></strong>:
192
							<br />
193
							<br /><strong><?PHP echo gettext("Action"); ?>:</strong> <?PHP echo $action_list[$_GET["action"]]; ?>
194
							<input type="hidden" name="action" value="<?PHP echo htmlspecialchars($_GET["action"]); ?>" />
195
						<?PHP if (!empty($_GET["mirror"])): ?>
196
							<br /><strong><?PHP echo gettext("Mirror"); ?>:</strong> <?PHP echo htmlspecialchars($_GET["mirror"]); ?>
197
							<input type="hidden" name="mirror" value="<?PHP echo htmlspecialchars($_GET["mirror"]); ?>" />
198
						<?PHP endif; ?>
199
						<?PHP if (!empty($_GET["consumer"])): ?>
200
							<br /><strong><?PHP echo gettext("Consumer"); ?>:</strong> <?PHP echo htmlspecialchars($_GET["consumer"]); ?>
201
							<input type="hidden" name="consumer" value="<?PHP echo htmlspecialchars($_GET["consumer"]); ?>" />
202
						<?PHP endif; ?>
203
							<br />
204
							<br /><input type="submit" name="confirm" value="<?PHP echo gettext("Confirm"); ?>" />
205
						</td>
206
					</tr>
207
<?PHP else: ?>
208
					<tr>
209
						<td colspan="2" valign="top" class="listtopic"><?PHP echo gettext("GEOM Mirror information"); ?></td>
210
					</tr>
211

    
212
					<tr>
213
						<td width="22%" valign="top" class="vncell"><?PHP echo gettext("Mirror Status"); ?></td>
214
						<td width="78%" class="vtable">
215

    
216
						<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="gmirror status">
217
							<tbody id="gmirror_status_table">
218
					<?PHP	if (count($mirror_status) > 0): ?>
219
							<tr>
220
							<td width="30%" class="vncellt"><?PHP echo gettext("Name"); ?></td>
221
							<td width="30%" class="vncellt"><?PHP echo gettext("Status"); ?></td>
222
							<td width="40%" class="vncellt"><?PHP echo gettext("Component"); ?></td>
223
							</tr>
224
						<?PHP	foreach ($mirror_status as $mirror => $name): 
225
								$components = count($name["components"]); ?>
226
								<tr>
227
								<td width="30%" rowspan="<?PHP echo $components; ?>" class="listr">
228
									<?PHP echo htmlspecialchars($name['name']); ?>
229
									<br />Size: <?PHP echo gmirror_get_mirror_size($name['name']); ?>
230
								</td>
231
								<td width="30%" rowspan="<?PHP echo $components; ?>" class="listr">
232
									<?PHP echo htmlspecialchars($name['status']); ?>
233
								<?PHP	if (strtoupper($name['status']) == "DEGRADED"): ?>
234
									<br /><a href="diag_gmirror.php?action=forget&amp;mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Forget Disconnected Disks"); ?>]</a>
235
								<?PHP	endif; ?>
236
								</td>
237
								<td width="40%" class="listr">
238
									<?PHP echo $name['components'][0]; ?>
239
									<?PHP list($cname, $cstatus) = explode(" ", $name['components'][0], 2); ?>
240
									<br />
241
								<?PHP	if ((strtoupper($name['status']) == "COMPLETE") && (count($name["components"]) > 1)): ?>
242
									<a href="diag_gmirror.php?action=rebuild&amp;consumer=<?PHP echo htmlspecialchars($cname); ?>&amp;mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Rebuild"); ?>]</a>
243
									<a href="diag_gmirror.php?action=deactivate&amp;consumer=<?PHP echo htmlspecialchars($cname); ?>&amp;mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Deactivate"); ?>]</a>
244
									<a href="diag_gmirror.php?action=remove&amp;consumer=<?PHP echo htmlspecialchars($cname); ?>&amp;mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Remove"); ?>]</a>
245
								<?PHP	endif; ?>
246
								</td>
247
								</tr>
248
							<?PHP	if (count($name["components"]) > 1):
249
									$morecomponents = array_slice($name["components"], 1); ?>
250
								<?PHP	foreach ($morecomponents as $component): ?>
251
										<tr>
252
										<td width="40%" class="listr">
253
											<?PHP echo $component; ?>
254
											<?PHP list($cname, $cstatus) = explode(" ", $component, 2); ?>
255
											<br />
256
										<?PHP	if ((strtoupper($name['status']) == "COMPLETE") && (count($name["components"]) > 1)): ?>
257
											<a href="diag_gmirror.php?action=rebuild&amp;consumer=<?PHP echo htmlspecialchars($cname); ?>&amp;mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Rebuild"); ?>]</a>
258
											<a href="diag_gmirror.php?action=deactivate&amp;consumer=<?PHP echo htmlspecialchars($cname); ?>&amp;mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Deactivate"); ?>]</a>
259
											<a href="diag_gmirror.php?action=remove&amp;consumer=<?PHP echo htmlspecialchars($cname); ?>&amp;mirror=<?PHP echo htmlspecialchars($name['name']); ?>">[<?PHP echo gettext("Remove"); ?>]</a>
260
										<?PHP	endif; ?>
261
										</td>
262
										</tr>
263
								<?PHP	endforeach; ?>
264
							<?PHP	endif; ?>
265
						<?PHP	endforeach; ?>
266
					<?PHP	else: ?>
267
							<tr><td colspan="3" class="listr"><?PHP echo gettext("No Mirrors Found"); ?></td></tr>
268
					<?PHP	endif; ?>
269
							</tbody>
270
						</table>
271
						<br /><?PHP echo gettext("Some disk operations may only be performed when there are multiple consumers present in a mirror."); ?>
272
						</td>
273
					</tr>
274

    
275
					<tr>
276
						<td colspan="2" valign="top" class="listtopic"><?PHP echo gettext("Consumer information"); ?></td>
277
					</tr>
278

    
279
					<tr>
280
						<td width="22%" valign="top" class="vncell"><?PHP echo gettext("Available Consumers"); ?></td>
281
						<td width="78%" class="vtable">
282

    
283
						<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="consumer list">
284
							<tbody id="consumer_list">
285
					<?PHP	if (count($unused_consumers) > 0): ?>
286
							<tr>
287
							<td width="30%" class="vncellt"><?PHP echo gettext("Name"); ?></td>
288
							<td width="30%" class="vncellt"><?PHP echo gettext("Size"); ?></td>
289
							<td width="40%" class="vncellt"><?PHP echo gettext("Add to Mirror"); ?></td>
290
							</tr>
291
						<?PHP	foreach ($unused_consumers as $consumer): ?>
292
								<tr>
293
								<td width="30%" class="listr">
294
									<?PHP echo htmlspecialchars($consumer['name']); ?>
295
								</td>
296
								<td width="30%" class="listr"><?PHP echo htmlspecialchars($consumer['size']); ?> <?PHP echo htmlspecialchars($consumer['humansize']); ?></td>
297
								<td width="40%" class="listr">
298
							<?PHP	$oldmirror = gmirror_get_consumer_metadata_mirror($consumer['name']);
299
								if ($oldmirror): ?>
300
									<a href="diag_gmirror.php?action=activate&amp;consumer=<?PHP echo htmlspecialchars($consumer['name']); ?>&amp;mirror=<?PHP echo htmlspecialchars($oldmirror); ?>">[<?PHP echo gettext("Reactivate on:") . ' ' . htmlspecialchars($oldmirror); ?>]</a>
301
									<br /><a href="diag_gmirror.php?action=clear&amp;consumer=<?PHP echo htmlspecialchars($consumer['name']); ?>">[<?PHP echo gettext("Remove metadata from disk"); ?>]</a>
302
							<?PHP	else: ?>
303
							<?PHP	foreach ($mirror_list as $mirror):
304
									$mirror_size = gmirror_get_mirror_size($mirror);
305
									$consumer_size = gmirror_get_unused_consumer_size($consumer['name']);
306
								?>
307
								<?PHP	if ($consumer_size > $mirror_size): ?>
308
									<a href="diag_gmirror.php?action=insert&amp;consumer=<?PHP echo htmlspecialchars($consumer['name']); ?>&amp;mirror=<?PHP echo htmlspecialchars($mirror); ?>"><?PHP echo htmlspecialchars($mirror); ?></a>
309
								<?PHP	endif; ?>
310
							<?PHP	endforeach; ?>
311
							<?PHP	endif; ?>
312
								</td>
313
								</tr>
314
						<?PHP	endforeach; ?>
315
					<?PHP	else: ?>
316
							<tr><td colspan="3" class="listr"><?PHP echo gettext("No unused consumers found"); ?></td></tr>
317
					<?PHP	endif; ?>
318
							</tbody>
319
						</table>
320
						<br /><?PHP echo gettext("Consumers may only be added to a mirror if they are larger than the size of the mirror."); ?>
321
						</td>
322
					</tr>
323
					<tr>
324
						<td colspan="2" valign="top" class="">&nbsp;</td>
325
					</tr>
326
					<tr>
327
						<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>
328
					</tr>
329
<?PHP endif;?>
330
				</table>
331
			</div>
332
		</td>
333
	</tr>
334
</table>
335
</form>
336
<?php require("fend.inc"); ?>
337
</body>
338
</html>
339

    
340
<?php
341

    
342
// Clear the loading indicator
343
echo "<script type=\"text/javascript\">";
344
echo "jQuery('#loading').html('');";
345
echo "</script>";
346

    
347
?>
(13-13/241)