]>
git.datanom.net - omvzfs.git/blob - src/Zpool.php
2 require_once("Vdev.php");
3 require_once("Snapshot.php");
4 require_once("Dataset.php");
5 require_once("Zvol.php");
6 require_once("Exception.php");
9 * Class containing information about the pool
11 * @author Michael Rasmussen
13 * @copyright Michael Rasmussen <mir@datanom.net>
15 class OMVModuleZFSZpool
extends OMVModuleAbstract
16 implements OMVNotifyListener
{
31 * @accociation OMVModuleZFSVdev to vdevs
40 * @accociation OMVModuleZFSVdev to spare
49 * @accociation OMVModuleZFSVdev to log
58 * @accociation OMVModuleZFSVdev to cache
73 * @var string $mountPoint
81 * @var array $features
88 * Array of OMVModuleZFSSnapshot.
90 * @var array $snapshot
92 * @accociation OMVModuleZFSSnapshot to snapshot
97 * Array of OMVModuleZFSDataset
99 * @var Dataset $dataset
101 * @accociation OMVModuleZFSDataset to dataset
106 * Array of OMVModuleZFSZvol
110 * @accociation OMVModuleZFSZvol to zvol
118 * @param $pool pool this mirror belongs to
119 * @throws OMVModuleZFSException
122 public function __construct($vdev) {
123 if (is_array($vdev)) {
124 $cmd = $this->getCommandString($vdev);
125 $name = $vdev[0]->getPool();
126 $type = $vdev[0]->getType();
129 $cmd = $this->getCommandString(array($vdev));
130 $name = $vdev->getPool();
131 $type = $vdev->getType();
133 $cmd = "zpool create $name $cmd";
135 OMVUtil
::exec($cmd, $output, $result);
137 throw new OMVModuleZFSException($output);
139 $this->vdevs
= array();
140 $this->spare
= array();
141 $this->log
= array();
142 $this->cache
= array();
143 $this->features
= array();
147 $this->vdevs
= $vdev;
149 array_push ($this->vdevs
, $vdev);
150 $this->size
= $this->getAttribute("size");
151 $this->mountPoint
= $this->getAttribute("mountpoint");
161 public function getName() {
171 public function getVdevs() {
178 * @param array $vdev array of OMVModuleZFSVdev
180 * @throws OMVModuleZFSException
183 public function addVdev(array $vdevs) {
184 $cmd = "zpool add " . $this->getName() . " " . $this->getCommandString($vdevs);
185 OMVUtil
::exec($cmd, $output, $result);
187 throw new OMVModuleZFSException($output);
189 $this->vdevs
= array_merge($this->vdevs
, $vdevs);
195 * @param OMVModuleZFSVdev $vdev
197 * @throws OMVModuleZFSException
200 public function removeVdev(OMVModuleZFSVdev
$vdev) {
201 throw new OMVModuleZFSException("Cannot remove vdevs from a pool");
207 * @param OMVModuleZFSVdev $cache
209 * @throws OMVModuleZFSException
212 public function addCache(OMVModuleZFSVdev
$cache) {
213 if ($cache->getType() != OMVModuleZFSVdevType
::OMVMODULEZFSPLAIN
)
214 throw new OMVModuleZFSException("Only a plain Vdev can be added as cache");
216 $cmd = "zpool add " . $this->getName() . " cache " . $this->getCommandString($vdevs);
217 OMVUtil
::exec($cmd, $output, $result);
219 throw new OMVModuleZFSException($output);
221 $disks = $cache->getDisks();
222 foreach ($disks as $disk) {
223 array_push ($this->cache
, $disk);
230 * @param array $disks
232 * @throws OMVModuleZFSException
235 public function removeCache(array $disks = null) {
240 $disks = $this->cache
;
242 foreach ($disks as $disk) {
243 $cmd = "zpool remove " . $this->getName() . " $disk";
244 OMVUtil
::exec($cmd, $output, $result);
246 array_push ($errors, $output);
248 $this->cache
= $this->removeDisk($this->cache
, $disk);
251 foreach ($errors as $error) {
253 $exception .= "\n$error";
259 throw new OMVModuleZFSException($exception);
268 public function getCache() {
275 * @param OMVModuleZFSVdev $log
279 public function addLog(OMVModuleZFSVdev
$log) {
280 trigger_error('Not Implemented!', E_USER_WARNING
);
289 public function removeLog() {
290 trigger_error('Not Implemented!', E_USER_WARNING
);
299 public function getLog() {
300 trigger_error('Not Implemented!', E_USER_WARNING
);
306 * @param array $spares
310 public function addSpare(array $spares) {
311 trigger_error('Not Implemented!', E_USER_WARNING
);
321 public function removeSpare($spare) {
322 trigger_error('Not Implemented!', E_USER_WARNING
);
331 public function getSpares() {
332 trigger_error('Not Implemented!', E_USER_WARNING
);
341 public function getSize() {
342 trigger_error('Not Implemented!', E_USER_WARNING
);
351 public function getMountPoint() {
352 trigger_error('Not Implemented!', E_USER_WARNING
);
358 * @param array $features
362 public function setFeatures(array $features) {
363 trigger_error('Not Implemented!', E_USER_WARNING
);
369 * @return list<Feature>
372 public function getFeatures() {
373 trigger_error('Not Implemented!', E_USER_WARNING
);
382 public function export() {
383 trigger_error('Not Implemented!', E_USER_WARNING
);
389 * @param string $name
393 public function import($name) {
394 trigger_error('Not Implemented!', E_USER_WARNING
);
403 public function scrub() {
404 trigger_error('Not Implemented!', E_USER_WARNING
);
413 public function status() {
414 trigger_error('Not Implemented!', E_USER_WARNING
);
417 public function bindListeners(OMVNotifyDispatcher
$dispatcher) {
418 $dispatcher->addListener(
420 "org.openmediavault.module.service.nfs.start",
421 array($this, "onNotify"));
422 $dispatcher->addListener(
424 "org.openmediavault.module.service.nfs.stop",
425 array($this, "onNotify"));
426 $dispatcher->addListener(
428 "org.openmediavault.module.service.nfs.applyconfig",
429 array($this, "onNotify"));
434 * org.openmediavault.module.service.<servicename>.start
435 * org.openmediavault.module.service.<servicename>.stop
436 * org.openmediavault.module.service.<servicename>.applyconfig
438 * @param string event
441 public function onNotify($event) {
442 trigger_error('Not Implemented!', E_USER_WARNING
);
446 * Convert array of Vdev to command string
448 * @param array $vdevs
450 * @throws OMVMODULEZFSException
452 private function getCommandString(array $vdevs) {
455 foreach ($vdevs as $vdev) {
456 $type = $vdev->getType();
460 case OMVModuleZFSVdevType
::OMVMODULEZFSPLAIN
: break;
461 case OMVModuleZFSVdevType
::OMVMODULEZFSMIRROR
: $command = "mirror"; break;
462 case OMVModuleZFSVdevType
::OMVMODULEZFSRAIDZ1
: $command = "raidz1"; break;
463 case OMVModuleZFSVdevType
::OMVMODULEZFSRAIDZ2
: $command = "raidz2"; break;
464 case OMVModuleZFSVdevType
::OMVMODULEZFSRAIDZ3
: $command = "raidz3"; break;
466 throw new OMVMODULEZFSException("Unknown Vdev type");
468 $disks = $vdev->getDisks();
470 foreach($disks as $disk) {
471 $diskStr .= " $disk";
474 array_push ($adds, $command . $diskStr);
477 return join(" ", $adds);
481 * Get an attribute from pool
483 * @param string $attribute
484 * @return string value
486 private function getAttribute($attribute) {
487 $cmd = "zpool list -H -o $attribute {$this->name}";
488 OMVUtil
::exec($cmd, $output, $result);
490 $cmd = "zfs list -H -o $attribute {$this->name}";
491 OMVUtil
::exec($cmd, $output, $result);
500 * Remove a disk from array
502 * @param array $array
503 * @param string $disk
506 private function removeDisk(array $array, $disk) {
507 $new_disks = array();
509 foreach ($array as $item) {
510 if (strcmp($item, $disk) != 0)
511 array_push ($new_disks, $item);
This page took 0.175762 seconds and 6 git commands to generate.