0) {
/* Loop through gmirror status output. */
foreach ($status as $line) {
/* Split the line by whitespace */
$all = preg_split("/[\s\t]+/", trim($line), 3);
if (count($all) == 3) {
/* If there are three items on a line, it is mirror name, status, and component */
$currentmirror = basename($all[0]);
$mirrors[$currentmirror]['name'] = basename($all[0]);
$mirrors[$currentmirror]['status'] = $all[1];
if (!is_array($mirrors[$currentmirror]['components'])) {
$mirrors[$currentmirror]['components'] = array();
}
$mirrors[$currentmirror]['components'][] = $all[2];
}
}
}
/* Return an hash of mirrors and components */
return $mirrors;
}
/* Get only status word for a single mirror. */
function gmirror_get_status_single($mirror) {
$status = "";
$mirror_status = gmirror_get_status();
return $mirror_status[$mirror]['status'];
}
/* Generate an HTML formatted status for mirrors and disks in a small format for the widget */
function gmirror_html_status() {
$mirrors = gmirror_get_status();
$output = "";
if (count($mirrors) < 1) {
print_info_box(gettext("No mirrors found."), 'warning', false);
return;
}
?>
=gettext("Name")?>
| =gettext("Status")?>
| =gettext("Component")?>
|
$name): ?>
">=$name['name']?> |
">=$name['status']?> |
=$name['components'][0]?> |
1): ?>
=$component?> |
0);
}
/* Find the mirror to which this consumer belongs */
function gmirror_get_consumer_metadata_mirror($consumer) {
if (!is_valid_consumer($consumer)) {
return array();
}
$metadata = gmirror_get_consumer_metadata($consumer);
foreach ($metadata as $line) {
if (substr($line, 0, 5) == "name:") {
list ($key, $value) = explode(":", $line, 2);
return trim($value);
}
}
}
/* Deactivate consumer, removing it from service in the mirror, but leave metadata intact */
function gmirror_deactivate_consumer($mirror, $consumer) {
if (!is_valid_mirror($mirror) || !is_valid_consumer($consumer)) {
return false;
}
return mwexec("/sbin/gmirror deactivate " . escapeshellarg($mirror) . " " . escapeshellarg($consumer));
}
/* Reactivate a deactivated consumer */
function gmirror_activate_consumer($mirror, $consumer) {
if (!is_valid_mirror($mirror) || !is_valid_consumer($consumer)) {
return false;
}
return mwexec("/sbin/gmirror activate " . escapeshellarg($mirror) . " " . escapeshellarg($consumer));
}
/* Find the size of the given mirror */
function gmirror_get_mirror_size($mirror) {
if (!is_valid_mirror($mirror)) {
return false;
}
$mirrorsize = "";
exec("/sbin/gmirror list " . escapeshellarg($mirror) . " | /usr/bin/grep 'Mediasize:' | /usr/bin/head -n 1 | /usr/bin/awk '{print $2;}'", $mirrorsize);
return $mirrorsize[0];
}
/* Return a list of all potential consumers on a disk with sizes. The geom part
list output is a little odd, we can't get the output for just the disk, if the disk contains
slices those get output also. */
function gmirror_get_all_unused_consumer_sizes_on_disk($disk) {
if (!is_valid_disk($disk) || !is_consumer_unused($disk)) {
return array();
}
$output = array();
exec("/sbin/geom part list " . escapeshellarg($disk) . " | /usr/bin/egrep '(Name:|Mediasize:)' | /usr/bin/cut -c4- | /usr/bin/sed -l -e 'N;s/\\nMediasize://;P;D;' | /usr/bin/cut -c7-", $output);
if (empty($output)) {
exec("/sbin/geom disk list " . escapeshellarg($disk) . " | /usr/bin/egrep '(Name:|Mediasize:)' | /usr/bin/cut -c4- | /usr/bin/sed -l -e 'N;s/\\nMediasize://;P;D;' | /usr/bin/cut -c7-", $output);
}
$disk_contents = array();
foreach ($output as $line) {
list($name, $size, $humansize) = explode(" ", $line, 3);
$consumer = array();
$consumer['name'] = $name;
$consumer['size'] = $size;
$consumer['humansize'] = $humansize;
$disk_contents[] = $consumer;
}
return $disk_contents;
}
/* Get only the size for one specific potential consumer. */
function gmirror_get_unused_consumer_size($consumer) {
$consumersizes = gmirror_get_all_unused_consumer_sizes_on_disk($consumer);
foreach ($consumersizes as $csize) {
if ($csize['name'] == $consumer) {
return $csize['size'];
}
}
return -1;
}
?>