From: Michael Rasmussen Date: Sun, 2 Mar 2014 01:45:55 +0000 (+0100) Subject: Changes made to design. Begin implementation of zpool. X-Git-Url: http://git.datanom.net/omvzfs.git/commitdiff_plain/b76f4e1734bec3862fa9326982e50386e7a6b6c1 Changes made to design. Begin implementation of zpool. --- diff --git a/class-diagram.dia b/class-diagram.dia index 989c339..122bcb3 100644 Binary files a/class-diagram.dia and b/class-diagram.dia differ diff --git a/class-diagram.png b/class-diagram.png index ca6f4ef..eccf872 100644 Binary files a/class-diagram.png and b/class-diagram.png differ diff --git a/class-diagram.svg b/class-diagram.svg index bf14ae4..1c08e25 100644 --- a/class-diagram.svg +++ b/class-diagram.svg @@ -1,5 +1,5 @@ - + @@ -141,67 +141,67 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -331,8 +331,8 @@ - - + + @@ -406,30 +406,32 @@ - - - + + + + + - + - - + + - - - - - + + + + + - + @@ -441,10 +443,10 @@ - + - + @@ -460,11 +462,11 @@ - + - + @@ -478,16 +480,16 @@ - + - + - - + + @@ -498,17 +500,17 @@ - + - + - - + + @@ -518,55 +520,57 @@ - + - + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + - + - + - + @@ -575,50 +579,49 @@ - + - + - - + + - - + + - - + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - + - - + + - - + + @@ -627,62 +630,63 @@ - + - + - - + + - - + + - + - - + + - + - + - + - - - - - - - - - - - - - + + + + + + + + + + + + + + - + - - + + @@ -691,23 +695,23 @@ - + - + - - + + - + - + @@ -716,27 +720,29 @@ - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -748,27 +754,29 @@ - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -778,8 +786,8 @@ - - + + @@ -789,16 +797,16 @@ - + - + - - + + @@ -806,22 +814,22 @@ - + - + - + - + - - + + @@ -832,24 +840,24 @@ - + - + - + - - + + - + @@ -859,7 +867,7 @@ - + @@ -868,20 +876,20 @@ - + - + - + - - + + @@ -891,15 +899,15 @@ - + - + - - + + @@ -908,14 +916,14 @@ - + - + @@ -927,7 +935,7 @@ - + @@ -936,14 +944,14 @@ - + - + - - - - + + + + @@ -952,15 +960,15 @@ - + - + - - + + @@ -971,16 +979,16 @@ - + - + - + - + @@ -993,7 +1001,7 @@ - + @@ -1001,299 +1009,333 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1334,7 +1376,7 @@ - + @@ -1346,10 +1388,10 @@ - + - + @@ -1365,11 +1407,11 @@ - + - + @@ -1383,16 +1425,16 @@ - + - + - - + + @@ -1403,16 +1445,16 @@ - + - + - - + + @@ -1420,22 +1462,22 @@ - + - + - + - + - - + + @@ -1446,20 +1488,20 @@ - + - + - + - - + + @@ -1469,24 +1511,24 @@ - + - + - + - - + + - + @@ -1496,7 +1538,7 @@ - + @@ -1547,7 +1589,7 @@ - + @@ -1559,10 +1601,10 @@ - + - + @@ -1578,11 +1620,11 @@ - + - + @@ -1596,16 +1638,16 @@ - + - + - - + + @@ -1616,16 +1658,16 @@ - + - + - - + + @@ -1633,22 +1675,22 @@ - + - + - + - + - - + + @@ -1659,20 +1701,20 @@ - + - + - + - - + + @@ -1682,24 +1724,24 @@ - + - + - + - - + + - + @@ -1709,7 +1751,7 @@ - + @@ -1759,7 +1801,7 @@ - + @@ -1771,10 +1813,10 @@ - + - + @@ -1790,11 +1832,11 @@ - + - + @@ -1808,16 +1850,16 @@ - + - + - - + + @@ -1828,16 +1870,16 @@ - + - + - - + + @@ -1845,22 +1887,22 @@ - + - + - + - + - - + + @@ -1871,20 +1913,20 @@ - + - + - + - - + + @@ -1894,24 +1936,24 @@ - + - + - + - - + + - + @@ -1921,7 +1963,7 @@ - + @@ -1929,13 +1971,13 @@ - - + + - + - + @@ -1953,16 +1995,16 @@ - + - - - - + + + + @@ -1987,16 +2029,16 @@ - + - + - - + + @@ -2015,9 +2057,9 @@ - + - + @@ -2045,12 +2087,12 @@ - - + + - + @@ -2059,38 +2101,38 @@ - + - - + + - - - - + + + + - + - + - - + + - + @@ -2102,194 +2144,196 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Vdev.php b/src/Vdev.php index d6c0047..b9183d8 100644 --- a/src/Vdev.php +++ b/src/Vdev.php @@ -42,6 +42,7 @@ class OMVModuleZFSVdev { * Constructor * * @param $pool pool this mirror belongs to + * @throws OMVModuleZFSException */ public function __construct($pool, OMVModuleZFSVdevType $type, array $disks) { @@ -188,6 +189,16 @@ class OMVModuleZFSVdev { return $pool; } + /** + * Get type + * + * @return OMVModuleZFSVdevType + * @access public + */ + public function getType() { + return $type; + } + } ?> diff --git a/src/Zpool.php b/src/Zpool.php index ef4f835..61a31d2 100644 --- a/src/Zpool.php +++ b/src/Zpool.php @@ -1,208 +1,289 @@ */ -class OMVModuleZFSZpool { +class OMVModuleZFSZpool extends OMVModuleAbstract + implements OMVNotifyListener { // Attributes /** - * XXX + * Name of pool * * @var string $name * @access private */ - private $_name; + private $name; /** - * XXX + * List of Vdev * - * @var list $vdevs + * @var array $vdevs * @access private + * @accociation OMVModuleZFSVdev to vdevs */ - private $_vdevs; + private $vdevs; /** - * XXX + * List of spares * - * @var list $spare + * @var array $spare * @access private + * @accociation OMVModuleZFSVdev to spare */ - private $_spare; + private $spare; /** - * XXX + * List of log * - * @var Log $log + * @var array $log * @access private + * @accociation OMVModuleZFSVdev to log */ - private $_log; + private $log; /** - * XXX + * List of cache * - * @var Cache $cache + * @var array $cache * @access private + * @accociation OMVModuleZFSVdev to cache */ - private $_cache; + private $cache; /** - * XXX + * Pool size * * @var int $size * @access private */ - private $_size; + private $size; /** - * XXX + * Pool's mountpoint * * @var string $mountPoint * @access private */ - private $_mountPoint; + private $mountPoint; /** - * XXX + * List of features * - * @var list $features + * @var array $features * @access private */ - private $_features; + private $features; // Associations /** - * XXX - * - * @var Snapshot $unnamed - * @access private - * @accociation Snapshot to unnamed - */ - #var $unnamed; - - /** - * XXX + * Array of OMVModuleZFSSnapshot. * - * @var Dataset $unnamed + * @var array $snapshot * @access private - * @accociation Dataset to unnamed + * @accociation OMVModuleZFSSnapshot to snapshot */ - #var $unnamed; + private $snapshot; /** - * XXX + * Array of OMVModuleZFSDataset * - * @var Zvol $unnamed + * @var Dataset $dataset * @access private - * @accociation Zvol to unnamed + * @accociation OMVModuleZFSDataset to dataset */ - #var $unnamed; + private $dataset; /** - * XXX + * Array of OMVModuleZFSZvol * - * @var Vdev $unnamed + * @var Zvol $zvol * @access private - * @accociation Vdev to unnamed + * @accociation OMVModuleZFSZvol to zvol */ - #var $unnamed; + private $zvol; // Operations + /** + * Constructor + * + * @param $pool pool this mirror belongs to + * @throws OMVModuleZFSException + */ + + public function __construct($vdev) { + if (is_array($vdev)) { + $cmd = $this->getCommandString($vdev); + $name = $vdev[0]->getPool(); + $type = $vdev[0]->getType(); + } + else { + $cmd = $this->getCommandString(array($vdev)); + $name = $vdev->getPool(); + $type = $vdev->getType(); + } + $cmd = "zpool create $name $cmd"; + + OMVUtil::exec($cmd, $output, $result); + if ($result) + throw new OMVModuleZFSException($output); + else { + $this->vdevs = array(); + $this->spare = array(); + $this->log = array(); + $this->cache = array(); + $this->features = array(); + $this->name = $name; + $this->type = $type; + if (is_array($vdev)) + $this->vdevs = $vdev; + else + array_push ($this->vdevs, $vdev); + $this->size = $this->getAttribute("size"); + $this->mountPoint = $this->getAttribute("mountpoint"); + } + } + /** - * XXX + * Get pool name * - * @return string XXX + * @return string * @access public */ public function getName() { - trigger_error('Not Implemented!', E_USER_WARNING); + return $this->name; } /** - * XXX + * Get array of Vdev * - * @return list XXX + * @return array * @access public */ public function getVdevs() { - trigger_error('Not Implemented!', E_USER_WARNING); + return $this->vdevs; } /** - * XXX + * Add Vdev to pool * - * @param Vdev $vdev XXX - * @return void XXX + * @param array $vdev array of OMVModuleZFSVdev + * @return void + * @throws OMVModuleZFSException * @access public */ - public function addVdev($vdev) { - trigger_error('Not Implemented!', E_USER_WARNING); + public function addVdev(array $vdevs) { + $cmd = "zpool add " . $this->getName() . " " . $this->getCommandString($vdevs); + OMVUtil::exec($cmd, $output, $result); + if ($result) + throw new OMVModuleZFSException($output); + else + $this->vdevs = array_merge($this->vdevs, $vdevs); } /** * XXX * - * @param Vdev $vdev XXX - * @return void XXX + * @param OMVModuleZFSVdev $vdev + * @return void + * @throws OMVModuleZFSException * @access public */ - public function removeVdev($vdev) { - trigger_error('Not Implemented!', E_USER_WARNING); + public function removeVdev(OMVModuleZFSVdev $vdev) { + throw new OMVModuleZFSException("Cannot remove vdevs from a pool"); } /** * XXX * - * @param Cache $cache XXX - * @return void XXX + * @param OMVModuleZFSVdev $cache + * @return void + * @throws OMVModuleZFSException * @access public */ - public function addCache($cache) { - trigger_error('Not Implemented!', E_USER_WARNING); + public function addCache(OMVModuleZFSVdev $cache) { + if ($cache->getType() != OMVModuleZFSVdevType::OMVMODULEZFSPLAIN) + throw new OMVModuleZFSException("Only a plain Vdev can be added as cache"); + + $cmd = "zpool add " . $this->getName() . " cache " . $this->getCommandString($vdevs); + OMVUtil::exec($cmd, $output, $result); + if ($result) + throw new OMVModuleZFSException($output); + + $disks = $cache->getDisks(); + foreach ($disks as $disk) { + array_push ($this->cache, $disk); + } } /** * XXX * - * @return void XXX + * @param array $disks + * @return void + * @throws OMVModuleZFSException * @access public */ - public function removeCache() { - trigger_error('Not Implemented!', E_USER_WARNING); + public function removeCache(array $disks = null) { + $errors = array(); + $exception = null; + + if (! $disks) + $disks = $this->cache; + + foreach ($disks as $disk) { + $cmd = "zpool remove " . $this->getName() . " $disk"; + OMVUtil::exec($cmd, $output, $result); + if ($result) + array_push ($errors, $output); + else + $this->cache = $this->removeDisk($this->cache, $disk); + } + + foreach ($errors as $error) { + if ($exception) + $exception .= "\n$error"; + else + $exception = $error; + } + + if ($exception) + throw new OMVModuleZFSException($exception); } /** * XXX * - * @return Cache XXX + * @return Cache * @access public */ public function getCache() { - trigger_error('Not Implemented!', E_USER_WARNING); + return $this->cache; } /** * XXX * - * @param Log $log XXX - * @return void XXX + * @param OMVModuleZFSVdev $log + * @return void * @access public */ - public function addLog($log) { + public function addLog(OMVModuleZFSVdev $log) { trigger_error('Not Implemented!', E_USER_WARNING); } /** * XXX * - * @return void XXX + * @return void * @access public */ public function removeLog() { @@ -212,7 +293,7 @@ class OMVModuleZFSZpool { /** * XXX * - * @return Log XXX + * @return Log * @access public */ public function getLog() { @@ -222,19 +303,19 @@ class OMVModuleZFSZpool { /** * XXX * - * @param Disk $spare XXX - * @return void XXX + * @param array $spares + * @return void * @access public */ - public function addSpare($spare) { + public function addSpare(array $spares) { trigger_error('Not Implemented!', E_USER_WARNING); } /** * XXX * - * @param Disk $spare XXX - * @return void XXX + * @param Disk $spare + * @return void * @access public */ public function removeSpare($spare) { @@ -244,7 +325,7 @@ class OMVModuleZFSZpool { /** * XXX * - * @return list XXX + * @return list * @access public */ public function getSpares() { @@ -254,7 +335,7 @@ class OMVModuleZFSZpool { /** * XXX * - * @return int XXX + * @return int * @access public */ public function getSize() { @@ -264,7 +345,7 @@ class OMVModuleZFSZpool { /** * XXX * - * @return string XXX + * @return string * @access public */ public function getMountPoint() { @@ -274,18 +355,18 @@ class OMVModuleZFSZpool { /** * XXX * - * @param list $features XXX - * @return void XXX + * @param array $features + * @return void * @access public */ - public function setFeatures($features) { + public function setFeatures(array $features) { trigger_error('Not Implemented!', E_USER_WARNING); } /** * XXX * - * @return list XXX + * @return list * @access public */ public function getFeatures() { @@ -295,7 +376,7 @@ class OMVModuleZFSZpool { /** * XXX * - * @return void XXX + * @return void * @access public */ public function export() { @@ -305,8 +386,8 @@ class OMVModuleZFSZpool { /** * XXX * - * @param string $name XXX - * @return void XXX + * @param string $name + * @return void * @access public */ public function import($name) { @@ -316,7 +397,7 @@ class OMVModuleZFSZpool { /** * XXX * - * @return void XXX + * @return void * @access public */ public function scrub() { @@ -326,13 +407,28 @@ class OMVModuleZFSZpool { /** * XXX * - * @return string XXX + * @return string * @access public */ public function status() { trigger_error('Not Implemented!', E_USER_WARNING); } + public function bindListeners(OMVNotifyDispatcher $dispatcher) { + $dispatcher->addListener( + OMV_NOTIFY_EVENT, + "org.openmediavault.module.service.nfs.start", + array($this, "onNotify")); + $dispatcher->addListener( + OMV_NOTIFY_EVENT, + "org.openmediavault.module.service.nfs.stop", + array($this, "onNotify")); + $dispatcher->addListener( + OMV_NOTIFY_EVENT, + "org.openmediavault.module.service.nfs.applyconfig", + array($this, "onNotify")); + } + /** * XXX * org.openmediavault.module.service..start @@ -347,30 +443,75 @@ class OMVModuleZFSZpool { } /** - * XXX + * Convert array of Vdev to command string * - * @access public + * @param array $vdevs + * @return string + * @throws OMVMODULEZFSException */ - public function applyConfig() { - trigger_error('Not Implemented!', E_USER_WARNING); + private function getCommandString(array $vdevs) { + $adds = array(); + + foreach ($vdevs as $vdev) { + $type = $vdev->getType(); + $command = ""; + + switch ($type) { + case OMVModuleZFSVdevType::OMVMODULEZFSPLAIN: break; + case OMVModuleZFSVdevType::OMVMODULEZFSMIRROR: $command = "mirror"; break; + case OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ1: $command = "raidz1"; break; + case OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ2: $command = "raidz2"; break; + case OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ3: $command = "raidz3"; break; + default: + throw new OMVMODULEZFSException("Unknown Vdev type"); + } + $disks = $vdev->getDisks(); + $diskStr = ""; + foreach($disks as $disk) { + $diskStr .= " $disk"; + } + + array_push ($adds, $command . $diskStr); + } + + return join(" ", $adds); } /** - * XXX + * Get an attribute from pool * - * @access public + * @param string $attribute + * @return string value */ - public function stopService() { - trigger_error('Not Implemented!', E_USER_WARNING); + private function getAttribute($attribute) { + $cmd = "zpool list -H -o $attribute {$this->name}"; + OMVUtil::exec($cmd, $output, $result); + if ($result) { + $cmd = "zfs list -H -o $attribute {$this->name}"; + OMVUtil::exec($cmd, $output, $result); + if ($result) + return null; + } + + return $output; } /** - * XXX + * Remove a disk from array * - * @access public + * @param array $array + * @param string $disk + * @return array */ - public function startService() { - trigger_error('Not Implemented!', E_USER_WARNING); + private function removeDisk(array $array, $disk) { + $new_disks = array(); + + foreach ($array as $item) { + if (strcmp($item, $disk) != 0) + array_push ($new_disks, $item); + } + + return $new_disks; } }