diff --git a/debian/changelog b/debian/changelog index 79293b4..9d98a5d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +openmediavault-zfs (3.0.3) stable; urgency=low + + * Fix mountpoint when AddPool + * Fix deleteShares + * Improved snapshot handling + * Set By-Id as default + + -- OpenMediaVault Plugin Developers Fri, 09 Sep 2016 22:43:27 +0900 + openmediavault-zfs (3.0.2) stable; urgency=low * Porting to OMV 3.0.26 diff --git a/debian/control b/debian/control index 175d02e..8f13923 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Homepage: http://omv-extras.org/ Package: openmediavault-zfs Architecture: amd64 -Depends: ${misc:Depends}, openmediavault (>= 1.7) | openmediavault (>= 3.0.26), debian-zfs (>= 0.6.5), +Depends: ${misc:Depends}, openmediavault (>= 3.0.34), debian-zfs (>= 0.6.5), build-essential Description: OpenMediaVault plugin for ZFS ZFS is a combined file system and logical volume manager designed diff --git a/usr/share/omvzfs/Dataset.php b/usr/share/omvzfs/Dataset.php index d51435a..3b5af29 100644 --- a/usr/share/omvzfs/Dataset.php +++ b/usr/share/omvzfs/Dataset.php @@ -275,7 +275,8 @@ public function unmount() { * @access public */ public function addSnapshot($snap_name, array $properties = null) { - $snap = new OMVModuleZFSSnapshot($snap_name); + //not reachable method + $snap = new OMVModuleZFSSnapshot($snap_name,false); $snap->create($properties); $this->snapshots[$snap_name] = $snap; } diff --git a/usr/share/omvzfs/Snapshot.php b/usr/share/omvzfs/Snapshot.php index b4a2271..d8d8bfd 100644 --- a/usr/share/omvzfs/Snapshot.php +++ b/usr/share/omvzfs/Snapshot.php @@ -39,22 +39,13 @@ class OMVModuleZFSSnapshot { * @return void * @access public */ - public function __construct($name) { - $snap_exists = true; + + + public function __construct($name){ $this->name = $name; - $cmd = "zfs list -H -t snapshot \"" .$name . "\" 2>&1"; - try { - $this->exec($cmd, $out, $res); - $this->updateAllProperties(); - } - catch (\OMV\ExecException $e) { - $snap_exists = false; - } - if (!$snap_exists) { - $this->create(); - } } + /** * Return name of the Snapshot * @@ -74,6 +65,7 @@ public function getName() { * @access public */ public function getProperty($property) { + $this->updateProperty($property); return $this->properties["$property"]; } @@ -85,6 +77,7 @@ public function getProperty($property) { * @access public */ public function getProperties() { + $this->updateAllProperties(); return $this->properties; } @@ -143,10 +136,12 @@ private function updateAllProperties() { * @return void * @access private */ - private function create() { - $cmd = "zfs snapshot \"" . $this->name . "\" 2>&1"; - $this->exec($cmd,$out,$res); - $this->updateAllProperties(); + public static function create($name) { + $cmd = "zfs snapshot \"" . $name . "\" 2>&1"; + $process = new Process($cmd); + $process->execute($out,$res); + return new OMVModuleZFSSnapshot($name); + #$this->updateAllProperties(); } /** diff --git a/usr/share/omvzfs/Utils.php b/usr/share/omvzfs/Utils.php index 2b31ee2..dfe2a97 100644 --- a/usr/share/omvzfs/Utils.php +++ b/usr/share/omvzfs/Utils.php @@ -15,14 +15,12 @@ class OMVModuleZFSUtil { public static function getZFSShares($context,$name,$dir){ - $objects = Rpc::call("FsTab","enumerateEntries",[],$context); - $result=NULL; - foreach($objects as $object){ - if($object['fsname']==$name && $object['dir']==$dir && $object['type']=='zfs'){ - $result=$object; - } - } - return $result; + $object = Rpc::call("FsTab","getByFsName",["fsname"=>$name],$context); + $result=NULL; + if($object['type']=='zfs' and $object['dir']==$dir){ + $result=$object; + } + return $result; } /** * Returns the quota (if set) of a filesystem. @@ -117,22 +115,6 @@ public static function setGPTLabel($disk) { $cmd = "parted -s " . $disk . " mklabel gpt 2>&1"; OMVModuleZFSUtil::exec($cmd,$out,$res); } - - /** - * Manages relocation of ZFS filesystem mountpoints in the OMV backend. - * Needed when the user changes mountpoint of a filesystem in the GUI. - * - */ - public static function relocateFilesystem($context,$name) { - $poolname = OMVModuleZFSUtil::getPoolname($name); - $pooluuid = OMVModuleZFSUtil::getUUIDbyName($poolname); - $ds = new OMVModuleZFSDataset($name); - $dir = $ds->getMountPoint(); - $object=OMVModuleZFSUtil::getZFSShares($context,$pooluuid,$dir); - $object['dir'] = $property['value']; - Rpc::call("FsTab","set", $object, $context); - return null; - } /** * Clears all ZFS labels on specified devices. @@ -236,10 +218,9 @@ public static function getDevByPath($path) { */ public static function deleteShares($context,$dispatcher,$name) { $poolname = OMVModuleZFSUtil::getPoolname($name); - $pooluuid = OMVModuleZFSUtil::getUUIDbyName($poolname); $ds = new OMVModuleZFSDataset($name); $dir = $ds->getMountPoint(); - $mountpoint =OMVModuleZFSUtil::getZFSShares($context,$pooluuid,$dir); + $mountpoint =OMVModuleZFSUtil::getZFSShares($context,$poolname,$dir); $mntentuuid = $mountpoint['uuid']; $shares=Rpc::call("ShareMgmt","enumerateSharedFolders", [], $context); $objects=[]; @@ -254,7 +235,7 @@ public static function deleteShares($context,$dispatcher,$name) { } } foreach ($objects as $object) { - Rpc::call("FsTab","delete", ["uuid"=>$object['uuid']], $context); + Rpc::call("ShareMgmt","delete", ["uuid"=>$object['uuid']], $context); } $dispatcher->notify(OMV_NOTIFY_DELETE,"org.openmediavault.system.shares.sharedfolder",$object); @@ -362,6 +343,7 @@ public static function addMissingOMVMntEnt($context) { Rpc::call("FsTab","set", $object, $context); } } + return null; } @@ -626,6 +608,11 @@ public static function SizeTobytes($humanformat) { return $num; } + public static function isReferenced($mntent) { + $mntent = $db->get("conf.system.filesystem.mountpoint",$mntent['uuid']); + if ($db->isReferenced($mntent)) + return true; + } } ?> diff --git a/usr/share/omvzfs/Zpool.php b/usr/share/omvzfs/Zpool.php index ace64ca..b7fd845 100644 --- a/usr/share/omvzfs/Zpool.php +++ b/usr/share/omvzfs/Zpool.php @@ -385,7 +385,7 @@ public function getSize() { * @access private */ private function setSize() { - $used = OMVModuleZFSUtil::SizeTobytes($this->getAttribute("used")[0]); + $used = OMVModuleZFSUtil::SizeTobytes($this->getAttribute("used")); $avail = OMVModuleZFSUtil::SizeTobytes($this->getAvailable()); $this->size = OMVModuleZFSUtil::bytesToSize($avail + $used); } @@ -396,7 +396,7 @@ private function setSize() { * @access public */ public function getAvailable() { - return $this->getAttribute("available")[0]; + return $this->getAttribute("available"); } /** @@ -638,14 +638,15 @@ public function getAttribute($attribute) { $cmd = "zpool list -H -o $attribute \"{$this->name}\""; $process = new Process($cmd); $process->setQuiet(); - $process->execute($output,$result); + $output = $process->execute($dummy,$result); if ($result) { $cmd = "zfs list -H -o $attribute \"{$this->name}\""; $process = new Process($cmd); $process->setQuiet(); - $process->execute($output,$result); + $output = $process->execute($dummy,$result); if ($result) return null; + return $output; } return $output; @@ -659,17 +660,12 @@ public function getAttribute($attribute) { private function getAllAttributes() { $attrs = array(); $cmd = "zfs get -H all \"{$this->name}\""; - $process = new Process($cmd); - $process->execute($output,$result); - $output = implode("\n", $output); - $res = preg_match_all("/{$this->name}\s+(\w+)\s+([\w\d\.]+)\s+(\w+).*/", $output, $matches, PREG_SET_ORDER); - if ($res == false || $res == 0) - throw new OMVModuleZFSException("Error return by zpool get all: $output"); - foreach ($matches as $match) { - $attrs[$match[1]] = array('value' => $match[2], 'source' => $match[3]); + $process->execute($out,$result); + foreach ($out as $line) { + $tmpary = preg_split('/\t+/', $line); + $attrs["$tmpary[1]"] = array("value" => $tmpary[2], "source" => $tmpary[3]); } - return $attrs; } diff --git a/usr/share/omvzfs/Zvol.php b/usr/share/omvzfs/Zvol.php index 88c01a6..7de312d 100644 --- a/usr/share/omvzfs/Zvol.php +++ b/usr/share/omvzfs/Zvol.php @@ -70,17 +70,27 @@ public function __construct($name) { $cmd = "zfs list -H -t volume \"" . $name . "\" 2>&1"; try { $this->exec($cmd, $out, $res); - $this->updateAllProperties(); } catch (\OMV\ExecException $e) { $zvol_exists = false; } if ($zvol_exists) { - $cmd = "zfs list -r -d 1 -o name -H -t snapshot \"" . $name . "\" 2>&1"; - $this->exec($cmd, $out2, $res2); - foreach ($out2 as $line2) { - $this->snapshots["$line2"] = new OMVModuleZFSSnapshot($line2); + #$cmd = "zfs list -r -d 1 -o name -H -t snapshot \"" . $name . "\" 2>&1"; + $cmd = "zfs get all | grep " . $name . "@ 2>&1"; + $this->exec($cmd, $out, $res); + $snapshots=array(); + + foreach ($out as $line) { + $ary = preg_split('/\t/', $line); + $name = $ary[0]; + $snapshots[$name][]=$line; + } + + foreach ($snapshots as $key => $snapshot){ + $tmp = new OMVModuleZFSSnapshot(); + $tmp->loadfrom($key,$snapshot); } + $cmd = "zfs get -o value -Hp volsize,logicalused \"$name\" 2>&1"; $this->exec($cmd, $out3, $res3); $this->size = $out3[0]; @@ -108,6 +118,7 @@ public function getName() { * @access public */ public function getProperty($property) { + $this->updateAllProperties(); return $this->properties["$property"]; } @@ -119,6 +130,7 @@ public function getProperty($property) { * @access public */ public function getProperties() { + $this->updateAllProperties(); return $this->properties; } @@ -280,6 +292,7 @@ public function inherit($property) { * @access public */ public function addSnapshot($snap_name, array $properties = null) { + //not reachable method $snap = new OMVModuleZFSSnapshot($snap_name); $snap->create($properties); $this->snapshots[$snap_name] = $snap; diff --git a/usr/share/openmediavault/engined/rpc/zfs.inc b/usr/share/openmediavault/engined/rpc/zfs.inc index e85c8ca..9b09ade 100644 --- a/usr/share/openmediavault/engined/rpc/zfs.inc +++ b/usr/share/openmediavault/engined/rpc/zfs.inc @@ -130,7 +130,7 @@ class OMVRpcServiceZFS extends ServiceAbstract { } $disks = $tmp_disks; } - } catch (OMVModuleZFSException $e) { + } catch (Exception $e) { //Do nothing if an excpetion is thrown (fallback on /dev/) } break; @@ -143,7 +143,7 @@ class OMVRpcServiceZFS extends ServiceAbstract { } $disks = $tmp_disks; } - } catch (OMVModuleZFSException $e) { + } catch (Exception $e) { //Do nothing if an excpetion is thrown (fallback on /dev/) } break; @@ -152,27 +152,8 @@ class OMVRpcServiceZFS extends ServiceAbstract { } $vdev = new OMVModuleZFSVdev($params['name'], $pooltype, $disks); - // Create a background process. - $bgStatusFilename = $this->createBgProcStatus(); - $pid = $this->fork(); - if($pid > 0) { // Parent process. - $this->initializeBgProcStatus($bgStatusFilename, $pid); - return $bgStatusFilename; - } - // Child process. - try { - $bgOutputFilename = $this->createBgProcOutput(); - $this->updateBgProcStatus($bgStatusFilename, "outputfilename", $bgOutputFilename); - $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()); - $this->finalizeBgProcStatus($bgStatusFilename, $output); - exit(0); - } catch(Exception $e) { - $this->finalizeBgProcStatus($bgStatusFilename, "", $e); - exit(1); - } + $pool = new OMVModuleZFSZpool($vdev, $opts); + } public function importPool($params, $context) { @@ -270,7 +251,7 @@ class OMVRpcServiceZFS extends ServiceAbstract { break; case "snapshot": $name = $params['path'] . "@" . $params['name']; - $tmp = new OMVModuleZFSSnapshot($name); + $tmp = OMVModuleZFSSnapshot::create($name); break; case "volume": $name = $params['path'] . "/" . $params['name']; @@ -299,6 +280,7 @@ class OMVRpcServiceZFS extends ServiceAbstract { } }'); $name = $params['name']; + switch ($params['type']) { case "Filesystem": $tmp = new OMVModuleZFSDataset($name); @@ -417,10 +399,12 @@ class OMVRpcServiceZFS extends ServiceAbstract { unset($objects); $objects = array(); $objects[$property['property']] = $property['value']; - $tmp->setProperties($objects); - if ((strcmp($property['property'], "mountpoint") === 0) && (strcmp($params['type'], "Filesystem") === 0)) { - OMVModuleZFSUtil::relocateFilesystem($context,$params['name']); + if ((strcmp($property['property'], "mountpoint") === 0)) { + $object=OMVModuleZFSUtil::getZFSShares($context,$tmp->getName(),$tmp->getMountPoint()); + OMVModuleZFSUtil::deleteShares($context,$this->dispatcher,$tmp->getName()); + Rpc::call("FsTab","delete", ["uuid"=>$object['uuid']],$context); } + $tmp->setProperties($objects); } // If we updated a dataset, we should notify. @@ -599,27 +583,10 @@ class OMVRpcServiceZFS extends ServiceAbstract { } $vdev[] = new OMVModuleZFSVdev($params['name'], $pooltype, $disks); - // Create a background process. - $bgStatusFilename = $this->createBgProcStatus(); - $pid = $this->fork(); - if($pid > 0) { // Parent process. - $this->initializeBgProcStatus($bgStatusFilename, $pid); - return $bgStatusFilename; - } - // Child process. - try { - $bgOutputFilename = $this->createBgProcOutput(); - $this->updateBgProcStatus($bgStatusFilename, "outputfilename", $bgOutputFilename); - $pool->addVdev($vdev, $opts); - //Ugly fix to solve the problem of blkid not displaying info on newly created pools - $pool->export(); - $pool->import($pool->getName()); - $this->finalizeBgProcStatus($bgStatusFilename, $output); - exit(0); - } catch(Exception $e) { - $this->finalizeBgProcStatus($bgStatusFilename, "", $e); - exit(1); - } + $pool->addVdev($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 scrubPool($params, $context) { @@ -717,7 +684,8 @@ class OMVRpcServiceZFS extends ServiceAbstract { break; case "Volume": - $vol = new OMVModuleZFSZvol($params['oldpath']); + $vol = new OMVModuleZFSZvol(); + $vol->load($params['oldpath']); $vol->rename($newpath); break; diff --git a/var/www/openmediavault/js/omv/module/admin/storage/zfs/PoolMgmt.js b/var/www/openmediavault/js/omv/module/admin/storage/zfs/PoolMgmt.js index e053505..4ba8dac 100644 --- a/var/www/openmediavault/js/omv/module/admin/storage/zfs/PoolMgmt.js +++ b/var/www/openmediavault/js/omv/module/admin/storage/zfs/PoolMgmt.js @@ -191,8 +191,8 @@ Ext.define("OMV.module.admin.storage.zfs.AddPool", { store: Ext.create("Ext.data.ArrayStore", { fields: [ "value", "text" ], data: [ - [ "path", _("By Path") ], [ "id", _("By Id") ], + [ "path", _("By Path") ], [ "dev", _("None") ] ] }), @@ -200,7 +200,7 @@ Ext.define("OMV.module.admin.storage.zfs.AddPool", { valueField: "value", allowBlank: false, editable: false, - value: "path", + value: "id", plugins: [{ ptype: "fieldinfo", text: _("Specifies which device alias should be used. Don't change unless needed.") @@ -410,8 +410,8 @@ Ext.define("OMV.module.admin.storage.zfs.ExpandPool", { store: Ext.create("Ext.data.ArrayStore", { fields: [ "value", "text" ], data: [ - [ "path", _("By Path") ], [ "id", _("By Id") ], + [ "path", _("By Path") ], [ "dev", _("None") ] ] }), @@ -419,7 +419,7 @@ Ext.define("OMV.module.admin.storage.zfs.ExpandPool", { valueField: "value", allowBlank: false, editable: false, - value: "path", + value: "id", plugins: [{ ptype: "fieldinfo", text: _("Specifies which device alias should be used. Don't change unless needed.")