X-Git-Url: http://git.datanom.net/omvzfs.git/blobdiff_plain/6b3ce31b7350912d6080771f0f02f0990fdcbf5e..c6117b32379445101780af97836973ba9151cac7:/gui/rpc/zfs.inc diff --git a/gui/rpc/zfs.inc b/gui/rpc/zfs.inc index bdf8c44..16b5a13 100644 --- a/gui/rpc/zfs.inc +++ b/gui/rpc/zfs.inc @@ -10,22 +10,66 @@ require_once("zfs/Utils.php"); require_once("zfs/Dataset.php"); require_once("zfs/Snapshot.php"); require_once("zfs/Zvol.php"); +require_once("zfs/Zpool.php"); +require_once("zfs/NotifyListener.php"); class OMVRpcServiceZFS extends OMVRpcServiceAbstract { - public function getName() { return "ZFS";} // RPC Service name. Same as in .js files + public function getName() { + return "ZFS"; // RPC Service name. Same as in .js files + } + + /* Initialize the RPC service. Different methods of the RPC service are declared here*/ + public function initialize() { + $this->registerMethod("addPool"); + $this->registerMethod("getObjectTree"); + $this->registermethod("passParam"); + $this->registermethod("addObject"); + $this->registermethod("deleteObject"); + $this->registermethod("getProperties"); + $this->registermethod("setProperties"); + $this->registermethod("inherit"); + $this->registermethod("getSharedParams"); + $this->registermethod("createShare"); + } - /* Initialize the RPC service. Different methods of the RPC service are declared here*/ - public function initialize() { - $this->registerMethod("getObjectTree"); - $this->registermethod("passParam"); - $this->registermethod("addObject"); - $this->registermethod("deleteObject"); - $this->registermethod("getProperties"); - $this->registermethod("setProperties"); - $this->registermethod("inherit"); - $this->registermethod("getSharedParams"); - $this->registermethod("createShare"); + public function addPool($params, $context) { + $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); + switch ($params['pooltype']) { + case "basic": + $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSPLAIN; + break; + case "mirror": + $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSMIRROR; + break; + case "raidz1": + $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ1; + break; + case "raidz2": + $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ2; + break; + case "raidz3": + $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ3; + break; + default: + throw new OMVModuleZFSException("Incorrect pool type specified"); + break; + } + //Check for user supplied options + $opts = ""; + if ($params['force']) { + $opts .= "-f "; } + if (strlen($params['mountpoint']) > 0) { + $opts .= "-m " . $params['mountpoint'] . " "; + } + + $disks = preg_split("/[,;]/", $params['devices']); + $vdev = new OMVModuleZFSVdev($params['name'], $pooltype, $disks); + $pool = new OMVModuleZFSZpool($vdev, $opts); + //Ugly fix to solve the problem of blkid not displaying info on newly created pools + $pool->export(); + $pool->import($pool->getName()); + } public function getObjectTree($params, $context) { $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); @@ -35,6 +79,7 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $new[$a['parentid']][] = $a; } $tree = OMVModuleZFSUtil::createTree($new, $new['root']); + OMVModuleZFSUtil::addMissingOMVMntEnt(); //Adds missing ZFS filesystems to the OMV core return $tree; } @@ -70,7 +115,8 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { public function deleteObject($params, $context) { $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); switch ($params['type']) { - case "Filesystem" || "Clone": + case "Filesystem": + case "Clone": $name = $params['name']; $tmp = new OMVModuleZFSDataset($name); $tmp->destroy(); @@ -85,6 +131,11 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $tmp = new OMVModuleZFSZvol($name); $tmp->destroy(); break; + case "Pool": + $name = $params['name']; + $tmp = new OMVModuleZFSZpool($name); + $tmp->destroy(); + break; default: throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); break; @@ -96,7 +147,8 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $objects = array(); $name = $params['name']; switch ($params['type']) { - case "Filesystem" || "Clone": + case "Filesystem": + case "Clone": $tmp = new OMVModuleZFSDataset($name); break; case "Snapshot": @@ -105,6 +157,9 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { case "Volume": $tmp = new OMVModuleZFSZvol($name); break; + case "Pool": + $tmp = new OMVModuleZFSZpool($name); + break; default: throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); break; @@ -125,7 +180,8 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); $objects = array(); switch ($params['type']) { - case "Filesystem" || "Clone": + case "Filesystem": + case "Clone": $tmp = new OMVModuleZFSDataset($params['name']); break; case "Snapshot": @@ -134,10 +190,13 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { case "Volume": $tmp = new OMVModuleZFSZvol($params['name']); break; + case "Pool": + $tmp = new OMVModuleZFSZpool($params['name']); + break; default: throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); break; - } + } foreach ($params['properties'] as $property) { $objects[$property['property']] = $property['value']; } @@ -158,7 +217,8 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $bgOutputFilename = $this->createBgProcOutput(); $this->updateBgProcStatus($bgStatusFilename, "outputfilename", $bgOutputFilename); switch ($params['type']) { - case "Filesystem" || "Clone": + case "Filesystem": + case "Clone": $tmp = new OMVModuleZFSDataset($params['name']); break; case "Snapshot": @@ -167,6 +227,9 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { case "Volume": $tmp = new OMVModuleZFSZvol($params['name']); break; + case "Pool": + $tmp = new OMVModuleZFSZpool($params['name']); + break; default: throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); break; @@ -197,40 +260,23 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { //Get the UUID of the Pool $pooluuid = OMVModuleZFSUtil::getUUIDbyName($params['name']); - preg_match('/^([A-Za-z0-9]+)\/?.*$/', $params['name'], $result); + preg_match('/^([A-Za-z0-9]+)\/?.*$/', $params['name'], $result); $poolname = $result[1]; unset($result); - //Check if the UUID is already stored as an mntent object. If it isn't then create it. - $xpath = "//system/fstab/mntent[fsname=" . $pooluuid . "]"; - $object = $xmlConfig->get($xpath); - if(is_null($object)) { - $uuid = OMVUtil::uuid(); - $ds = new OMVModuleZFSDataset($poolname); - $dir = $ds->getMountPoint(); - $object = array( - "uuid" => $uuid, - "fsname" => $pooluuid, - "dir" => $dir, - "type" => "zfs", - "opts" => "rw,relatime,xattr", - "freq" => "0", - "passno" => "2" - ); - $xmlConfig->set("//system/fstab",array("mntent" => $object)); - $dispatcher = &OMVNotifyDispatcher::getInstance(); - $dispatcher->notify(OMV_NOTIFY_CREATE,"org.openmediavault.system.fstab.mntent", $object); - } - //Get the mntent object and fetch it's uuid. + $xpath = "//system/fstab/mntent[fsname=" . $pooluuid . "]"; $object = $xmlConfig->get($xpath); $mntentref = $object['uuid']; // Prepare the configuration object. Use the name of the shared // folder as the relative directory name of the share. switch ($params['type']) { - case "Filesystem" || "Clone": - $tmp = new OMVModuleZFSDataset($name); + case "Filesystem": + $tmp = new OMVModuleZFSDataset($params['name']); + break; + case "Clone": + $tmp = new OMVModuleZFSDataset($params['name']); break; default: throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); @@ -239,7 +285,7 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $uuid = OMVUtil::uuid(); $pathName = $tmp->getMountPoint(); - $subdirs = preg_split('/\//',$pathName); + $subdirs = preg_split('/\//',$pathName); $reldirpath = $subdirs[count($subdirs)-1]; $object = array( "uuid" => $uuid, @@ -301,13 +347,12 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $dispatcher->notify(OMV_NOTIFY_CREATE,"org.openmediavault.system.shares.sharedfolder", $object); // Return the configuration object. return $object; - } } // Register the RPC service. -$rpcServiceMgr = &OMVRpcServiceMgr::getInstance(); // Get the "root" instance for the Services +$rpcServiceMgr = &OMVRpcServiceMgr::getInstance(); // Get the "root" instance for the Services $rpcServiceMgr->registerService(new OMVRpcServiceZFS()); // Register a new instance of the RPC service described above ?>