X-Git-Url: http://git.datanom.net/omvzfs.git/blobdiff_plain/c4ed2435c5b0a0d048369b6c52fbddfcd3c08cbb..a36352f77c28bdf8f2834a64bd8520b73bfcf040:/src/Utils.php diff --git a/src/Utils.php b/src/Utils.php index 86d9205..251157a 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -8,6 +8,59 @@ require_once("Dataset.php"); */ class OMVModuleZFSUtil { + /** + * Get UUID of ZFS pool by name + * + * @return string UUID of the pool + */ + public static function getUUIDbyName($name) { + preg_match('/^([A-Za-z0-9]+)\/?.*$/', $name, $result); + $name = $result[1]; + unset($result); + $cmd = "blkid -o full"; + OMVModuleZFSUtil::exec($cmd, $out, $res); + foreach($out as $line) { + if(preg_match('/^.*LABEL=\"' . $name . '\" UUID=\"([A-Za-z0-9]+)\".*TYPE=\"zfs_member\"$/', $line, $result)) { + return($result[1]); + } + } + return null; + } + + /** + * Add any missing ZFS pool to the OMV backend + * + */ + public static function addMissingOMVMntEnt() { + global $xmlConfig; + $msg = ""; + $cmd = "zpool list -H -o name"; + OMVModuleZFSUtil::exec($cmd, $out, $res); + foreach($out as $name) { + $pooluuid = OMVModuleZFSUtil::getUUIDbyName($name); + $xpath = "//system/fstab/mntent[fsname=" . $pooluuid . "]"; + $object = $xmlConfig->get($xpath); + if(is_null($object)) { + $uuid = OMVUtil::uuid(); + $ds = new OMVModuleZFSDataset($name); + $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); + } + } + return null; + } + /** * Get an array with all ZFS objects * @@ -26,7 +79,7 @@ class OMVModuleZFSUtil { $subdirs = preg_split('/\//',$path); $root = $subdirs[0]; $tmp = array(); - + switch ($type) { case "filesystem": if (strpos($path,'/') === false) {