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

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

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

    
118
			break;
119
		case "remove":
120
		case "deactivate":
121
		case "rebuild":
122
			if (!is_consumer_in_mirror($_POST['consumer'], $_POST['mirror'])) {
123
				$input_errors[] = gettext("Consumer must be present on the specified mirror.");
124
			}
125
			break;
126
	}
127

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

    
164
$mirror_status = gmirror_get_status();
165
$mirror_list = gmirror_get_mirrors();
166
$unused_disks = gmirror_get_disks();
167
$unused_consumers = array();
168
foreach ($unused_disks as $disk) {
169
	if (is_consumer_unused($disk)) {
170
		$unused_consumers = array_merge($unused_consumers, gmirror_get_all_unused_consumer_sizes_on_disk($disk));
171
	}
172
}
173

    
174
if ($input_errors) {
175
	print_input_errors($input_errors);
176
}
177
if ($_GET["error"] && ($_GET["error"] != 0)) {
178
	print_info_box(gettext("There was an error performing the chosen mirror operation. Check the System Log for details."));
179
}
180

    
181
?>
182
<form action="diag_gmirror.php" method="POST" id="gmirror_form" name="gmirror_form">
183
<table width="100%" border="0" cellpadding="0" cellspacing="0">
184
	<tr>
185
		<td id="mainarea">
186
			<div class="tabcont">
187
				<span class="vexpl">
188
					<span class="red">
189
						<strong><?=gettext("NOTE:")?>&nbsp;</strong>
190
					</span>
191
					<?=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.")?>
192
					<br />&nbsp;
193
				</span>
194
				<p/>
195
				<table width="100%" border="0" cellpadding="6" cellspacing="0">
196

    
197
<?php if ($_GET["action"]): ?>
198
					<tr>
199
						<td colspan="2" valign="top" class="listtopic"><?php echo gettext("Confirm Action"); ?></td>
200
					</tr>
201
					<tr>
202
						<td width="22%" valign="top" class="vncell">&nbsp;</td>
203
						<td width="78%" class="vtable">
204
							<strong><?php echo gettext("Please confirm the selected action"); ?></strong>:
205
							<br />
206
							<br /><strong><?php echo gettext("Action"); ?>:</strong> <?php echo $action_list[$_GET["action"]]; ?>
207
							<input type="hidden" name="action" value="<?php echo htmlspecialchars($_GET["action"]); ?>" />
208
						<?php if (!empty($_GET["mirror"])): ?>
209
							<br /><strong><?php echo gettext("Mirror"); ?>:</strong> <?php echo htmlspecialchars($_GET["mirror"]); ?>
210
							<input type="hidden" name="mirror" value="<?php echo htmlspecialchars($_GET["mirror"]); ?>" />
211
						<?php endif; ?>
212
						<?php if (!empty($_GET["consumer"])): ?>
213
							<br /><strong><?php echo gettext("Consumer"); ?>:</strong> <?php echo htmlspecialchars($_GET["consumer"]); ?>
214
							<input type="hidden" name="consumer" value="<?php echo htmlspecialchars($_GET["consumer"]); ?>" />
215
						<?php endif; ?>
216
							<br />
217
							<br /><input type="submit" name="confirm" value="<?php echo gettext("Confirm"); ?>" />
218
						</td>
219
					</tr>
220
<?php else: ?>
221
					<tr>
222
						<td colspan="2" valign="top" class="listtopic"><?php echo gettext("GEOM Mirror information"); ?></td>
223
					</tr>
224

    
225
					<tr>
226
						<td width="22%" valign="top" class="vncell"><?php echo gettext("Mirror Status"); ?></td>
227
						<td width="78%" class="vtable">
228

    
229
						<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="gmirror status">
230
							<tbody id="gmirror_status_table">
231
					<?php	if (count($mirror_status) > 0): ?>
232
							<tr>
233
							<td width="30%" class="vncellt"><?php echo gettext("Name"); ?></td>
234
							<td width="30%" class="vncellt"><?php echo gettext("Status"); ?></td>
235
							<td width="40%" class="vncellt"><?php echo gettext("Component"); ?></td>
236
							</tr>
237
						<?php	foreach ($mirror_status as $mirror => $name):
238
								$components = count($name["components"]); ?>
239
								<tr>
240
								<td width="30%" rowspan="<?php echo $components; ?>" class="listr">
241
									<?php echo htmlspecialchars($name['name']); ?>
242
									<br />Size: <?php echo gmirror_get_mirror_size($name['name']); ?>
243
								</td>
244
								<td width="30%" rowspan="<?php echo $components; ?>" class="listr">
245
									<?php echo htmlspecialchars($name['status']); ?>
246
								<?php	if (strtoupper($name['status']) == "DEGRADED"): ?>
247
									<br /><a href="diag_gmirror.php?action=forget&amp;mirror=<?php echo htmlspecialchars($name['name']); ?>">[<?php echo gettext("Forget Disconnected Disks"); ?>]</a>
248
								<?php	endif; ?>
249
								</td>
250
								<td width="40%" class="listr">
251
									<?php echo $name['components'][0]; ?>
252
									<?php list($cname, $cstatus) = explode(" ", $name['components'][0], 2); ?>
253
									<br />
254
								<?php	if ((strtoupper($name['status']) == "COMPLETE") && (count($name["components"]) > 1)): ?>
255
									<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>
256
									<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>
257
									<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>
258
								<?php	endif; ?>
259
								</td>
260
								</tr>
261
							<?php	if (count($name["components"]) > 1):
262
									$morecomponents = array_slice($name["components"], 1); ?>
263
								<?php	foreach ($morecomponents as $component): ?>
264
										<tr>
265
										<td width="40%" class="listr">
266
											<?php echo $component; ?>
267
											<?php list($cname, $cstatus) = explode(" ", $component, 2); ?>
268
											<br />
269
										<?php	if ((strtoupper($name['status']) == "COMPLETE") && (count($name["components"]) > 1)): ?>
270
											<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>
271
											<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>
272
											<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>
273
										<?php	endif; ?>
274
										</td>
275
										</tr>
276
								<?php	endforeach; ?>
277
							<?php	endif; ?>
278
						<?php	endforeach; ?>
279
					<?php	else: ?>
280
							<tr><td colspan="3" class="listr"><?php echo gettext("No Mirrors Found"); ?></td></tr>
281
					<?php	endif; ?>
282
							</tbody>
283
						</table>
284
						<br /><?php echo gettext("Some disk operations may only be performed when there are multiple consumers present in a mirror."); ?>
285
						</td>
286
					</tr>
287

    
288
					<tr>
289
						<td colspan="2" valign="top" class="listtopic"><?php echo gettext("Consumer information"); ?></td>
290
					</tr>
291

    
292
					<tr>
293
						<td width="22%" valign="top" class="vncell"><?php echo gettext("Available Consumers"); ?></td>
294
						<td width="78%" class="vtable">
295

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

    
353
<?php
354

    
355
// Clear the loading indicator
356
echo "<script type=\"text/javascript\">";
357
echo "jQuery('#loading').html('');";
358
echo "</script>";
359

    
360
?>
(13-13/252)