Skip to content

Commit

Permalink
Various fix
Browse files Browse the repository at this point in the history
  • Loading branch information
luxflow committed Sep 9, 2016
1 parent 6555c64 commit 95b324c
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 117 deletions.
9 changes: 9 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> Fri, 09 Sep 2016 22:43:27 +0900

openmediavault-zfs (3.0.2) stable; urgency=low

* Porting to OMV 3.0.26
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion usr/share/omvzfs/Dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
29 changes: 12 additions & 17 deletions usr/share/omvzfs/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -74,6 +65,7 @@ public function getName() {
* @access public
*/
public function getProperty($property) {
$this->updateProperty($property);
return $this->properties["$property"];
}

Expand All @@ -85,6 +77,7 @@ public function getProperty($property) {
* @access public
*/
public function getProperties() {
$this->updateAllProperties();
return $this->properties;
}

Expand Down Expand Up @@ -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();
}

/**
Expand Down
41 changes: 14 additions & 27 deletions usr/share/omvzfs/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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=[];
Expand All @@ -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);
Expand Down Expand Up @@ -362,6 +343,7 @@ public static function addMissingOMVMntEnt($context) {
Rpc::call("FsTab","set", $object, $context);
}
}

return null;
}

Expand Down Expand Up @@ -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;
}
}

?>
22 changes: 9 additions & 13 deletions usr/share/omvzfs/Zpool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -396,7 +396,7 @@ private function setSize() {
* @access public
*/
public function getAvailable() {
return $this->getAttribute("available")[0];
return $this->getAttribute("available");
}

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
23 changes: 18 additions & 5 deletions usr/share/omvzfs/Zvol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -108,6 +118,7 @@ public function getName() {
* @access public
*/
public function getProperty($property) {
$this->updateAllProperties();
return $this->properties["$property"];
}

Expand All @@ -119,6 +130,7 @@ public function getProperty($property) {
* @access public
*/
public function getProperties() {
$this->updateAllProperties();
return $this->properties;
}

Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 95b324c

Please sign in to comment.