Skip to content

Commit 95b324c

Browse files
committed
Various fix
1 parent 6555c64 commit 95b324c

File tree

9 files changed

+86
-117
lines changed

9 files changed

+86
-117
lines changed

debian/changelog

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
openmediavault-zfs (3.0.3) stable; urgency=low
2+
3+
* Fix mountpoint when AddPool
4+
* Fix deleteShares
5+
* Improved snapshot handling
6+
* Set By-Id as default
7+
8+
-- OpenMediaVault Plugin Developers <[email protected]> Fri, 09 Sep 2016 22:43:27 +0900
9+
110
openmediavault-zfs (3.0.2) stable; urgency=low
211

312
* Porting to OMV 3.0.26

debian/control

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Homepage: http://omv-extras.org/
99

1010
Package: openmediavault-zfs
1111
Architecture: amd64
12-
Depends: ${misc:Depends}, openmediavault (>= 1.7) | openmediavault (>= 3.0.26), debian-zfs (>= 0.6.5),
12+
Depends: ${misc:Depends}, openmediavault (>= 3.0.34), debian-zfs (>= 0.6.5),
1313
build-essential
1414
Description: OpenMediaVault plugin for ZFS
1515
ZFS is a combined file system and logical volume manager designed

usr/share/omvzfs/Dataset.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ public function unmount() {
275275
* @access public
276276
*/
277277
public function addSnapshot($snap_name, array $properties = null) {
278-
$snap = new OMVModuleZFSSnapshot($snap_name);
278+
//not reachable method
279+
$snap = new OMVModuleZFSSnapshot($snap_name,false);
279280
$snap->create($properties);
280281
$this->snapshots[$snap_name] = $snap;
281282
}

usr/share/omvzfs/Snapshot.php

+12-17
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,13 @@ class OMVModuleZFSSnapshot {
3939
* @return void
4040
* @access public
4141
*/
42-
public function __construct($name) {
43-
$snap_exists = true;
42+
43+
44+
public function __construct($name){
4445
$this->name = $name;
45-
$cmd = "zfs list -H -t snapshot \"" .$name . "\" 2>&1";
46-
try {
47-
$this->exec($cmd, $out, $res);
48-
$this->updateAllProperties();
49-
}
50-
catch (\OMV\ExecException $e) {
51-
$snap_exists = false;
52-
}
53-
if (!$snap_exists) {
54-
$this->create();
55-
}
5646
}
5747

48+
5849
/**
5950
* Return name of the Snapshot
6051
*
@@ -74,6 +65,7 @@ public function getName() {
7465
* @access public
7566
*/
7667
public function getProperty($property) {
68+
$this->updateProperty($property);
7769
return $this->properties["$property"];
7870
}
7971

@@ -85,6 +77,7 @@ public function getProperty($property) {
8577
* @access public
8678
*/
8779
public function getProperties() {
80+
$this->updateAllProperties();
8881
return $this->properties;
8982
}
9083

@@ -143,10 +136,12 @@ private function updateAllProperties() {
143136
* @return void
144137
* @access private
145138
*/
146-
private function create() {
147-
$cmd = "zfs snapshot \"" . $this->name . "\" 2>&1";
148-
$this->exec($cmd,$out,$res);
149-
$this->updateAllProperties();
139+
public static function create($name) {
140+
$cmd = "zfs snapshot \"" . $name . "\" 2>&1";
141+
$process = new Process($cmd);
142+
$process->execute($out,$res);
143+
return new OMVModuleZFSSnapshot($name);
144+
#$this->updateAllProperties();
150145
}
151146

152147
/**

usr/share/omvzfs/Utils.php

+14-27
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
class OMVModuleZFSUtil {
1616

1717
public static function getZFSShares($context,$name,$dir){
18-
$objects = Rpc::call("FsTab","enumerateEntries",[],$context);
19-
$result=NULL;
20-
foreach($objects as $object){
21-
if($object['fsname']==$name && $object['dir']==$dir && $object['type']=='zfs'){
22-
$result=$object;
23-
}
24-
}
25-
return $result;
18+
$object = Rpc::call("FsTab","getByFsName",["fsname"=>$name],$context);
19+
$result=NULL;
20+
if($object['type']=='zfs' and $object['dir']==$dir){
21+
$result=$object;
22+
}
23+
return $result;
2624
}
2725
/**
2826
* Returns the quota (if set) of a filesystem.
@@ -117,22 +115,6 @@ public static function setGPTLabel($disk) {
117115
$cmd = "parted -s " . $disk . " mklabel gpt 2>&1";
118116
OMVModuleZFSUtil::exec($cmd,$out,$res);
119117
}
120-
121-
/**
122-
* Manages relocation of ZFS filesystem mountpoints in the OMV backend.
123-
* Needed when the user changes mountpoint of a filesystem in the GUI.
124-
*
125-
*/
126-
public static function relocateFilesystem($context,$name) {
127-
$poolname = OMVModuleZFSUtil::getPoolname($name);
128-
$pooluuid = OMVModuleZFSUtil::getUUIDbyName($poolname);
129-
$ds = new OMVModuleZFSDataset($name);
130-
$dir = $ds->getMountPoint();
131-
$object=OMVModuleZFSUtil::getZFSShares($context,$pooluuid,$dir);
132-
$object['dir'] = $property['value'];
133-
Rpc::call("FsTab","set", $object, $context);
134-
return null;
135-
}
136118

137119
/**
138120
* Clears all ZFS labels on specified devices.
@@ -236,10 +218,9 @@ public static function getDevByPath($path) {
236218
*/
237219
public static function deleteShares($context,$dispatcher,$name) {
238220
$poolname = OMVModuleZFSUtil::getPoolname($name);
239-
$pooluuid = OMVModuleZFSUtil::getUUIDbyName($poolname);
240221
$ds = new OMVModuleZFSDataset($name);
241222
$dir = $ds->getMountPoint();
242-
$mountpoint =OMVModuleZFSUtil::getZFSShares($context,$pooluuid,$dir);
223+
$mountpoint =OMVModuleZFSUtil::getZFSShares($context,$poolname,$dir);
243224
$mntentuuid = $mountpoint['uuid'];
244225
$shares=Rpc::call("ShareMgmt","enumerateSharedFolders", [], $context);
245226
$objects=[];
@@ -254,7 +235,7 @@ public static function deleteShares($context,$dispatcher,$name) {
254235
}
255236
}
256237
foreach ($objects as $object) {
257-
Rpc::call("FsTab","delete", ["uuid"=>$object['uuid']], $context);
238+
Rpc::call("ShareMgmt","delete", ["uuid"=>$object['uuid']], $context);
258239
}
259240

260241
$dispatcher->notify(OMV_NOTIFY_DELETE,"org.openmediavault.system.shares.sharedfolder",$object);
@@ -362,6 +343,7 @@ public static function addMissingOMVMntEnt($context) {
362343
Rpc::call("FsTab","set", $object, $context);
363344
}
364345
}
346+
365347
return null;
366348
}
367349

@@ -626,6 +608,11 @@ public static function SizeTobytes($humanformat) {
626608
return $num;
627609
}
628610

611+
public static function isReferenced($mntent) {
612+
$mntent = $db->get("conf.system.filesystem.mountpoint",$mntent['uuid']);
613+
if ($db->isReferenced($mntent))
614+
return true;
615+
}
629616
}
630617

631618
?>

usr/share/omvzfs/Zpool.php

+9-13
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public function getSize() {
385385
* @access private
386386
*/
387387
private function setSize() {
388-
$used = OMVModuleZFSUtil::SizeTobytes($this->getAttribute("used")[0]);
388+
$used = OMVModuleZFSUtil::SizeTobytes($this->getAttribute("used"));
389389
$avail = OMVModuleZFSUtil::SizeTobytes($this->getAvailable());
390390
$this->size = OMVModuleZFSUtil::bytesToSize($avail + $used);
391391
}
@@ -396,7 +396,7 @@ private function setSize() {
396396
* @access public
397397
*/
398398
public function getAvailable() {
399-
return $this->getAttribute("available")[0];
399+
return $this->getAttribute("available");
400400
}
401401

402402
/**
@@ -638,14 +638,15 @@ public function getAttribute($attribute) {
638638
$cmd = "zpool list -H -o $attribute \"{$this->name}\"";
639639
$process = new Process($cmd);
640640
$process->setQuiet();
641-
$process->execute($output,$result);
641+
$output = $process->execute($dummy,$result);
642642
if ($result) {
643643
$cmd = "zfs list -H -o $attribute \"{$this->name}\"";
644644
$process = new Process($cmd);
645645
$process->setQuiet();
646-
$process->execute($output,$result);
646+
$output = $process->execute($dummy,$result);
647647
if ($result)
648648
return null;
649+
return $output;
649650
}
650651

651652
return $output;
@@ -659,17 +660,12 @@ public function getAttribute($attribute) {
659660
private function getAllAttributes() {
660661
$attrs = array();
661662
$cmd = "zfs get -H all \"{$this->name}\"";
662-
663663
$process = new Process($cmd);
664-
$process->execute($output,$result);
665-
$output = implode("\n", $output);
666-
$res = preg_match_all("/{$this->name}\s+(\w+)\s+([\w\d\.]+)\s+(\w+).*/", $output, $matches, PREG_SET_ORDER);
667-
if ($res == false || $res == 0)
668-
throw new OMVModuleZFSException("Error return by zpool get all: $output");
669-
foreach ($matches as $match) {
670-
$attrs[$match[1]] = array('value' => $match[2], 'source' => $match[3]);
664+
$process->execute($out,$result);
665+
foreach ($out as $line) {
666+
$tmpary = preg_split('/\t+/', $line);
667+
$attrs["$tmpary[1]"] = array("value" => $tmpary[2], "source" => $tmpary[3]);
671668
}
672-
673669
return $attrs;
674670
}
675671

usr/share/omvzfs/Zvol.php

+18-5
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,27 @@ public function __construct($name) {
7070
$cmd = "zfs list -H -t volume \"" . $name . "\" 2>&1";
7171
try {
7272
$this->exec($cmd, $out, $res);
73-
$this->updateAllProperties();
7473
}
7574
catch (\OMV\ExecException $e) {
7675
$zvol_exists = false;
7776
}
7877
if ($zvol_exists) {
79-
$cmd = "zfs list -r -d 1 -o name -H -t snapshot \"" . $name . "\" 2>&1";
80-
$this->exec($cmd, $out2, $res2);
81-
foreach ($out2 as $line2) {
82-
$this->snapshots["$line2"] = new OMVModuleZFSSnapshot($line2);
78+
#$cmd = "zfs list -r -d 1 -o name -H -t snapshot \"" . $name . "\" 2>&1";
79+
$cmd = "zfs get all | grep " . $name . "@ 2>&1";
80+
$this->exec($cmd, $out, $res);
81+
$snapshots=array();
82+
83+
foreach ($out as $line) {
84+
$ary = preg_split('/\t/', $line);
85+
$name = $ary[0];
86+
$snapshots[$name][]=$line;
87+
}
88+
89+
foreach ($snapshots as $key => $snapshot){
90+
$tmp = new OMVModuleZFSSnapshot();
91+
$tmp->loadfrom($key,$snapshot);
8392
}
93+
8494
$cmd = "zfs get -o value -Hp volsize,logicalused \"$name\" 2>&1";
8595
$this->exec($cmd, $out3, $res3);
8696
$this->size = $out3[0];
@@ -108,6 +118,7 @@ public function getName() {
108118
* @access public
109119
*/
110120
public function getProperty($property) {
121+
$this->updateAllProperties();
111122
return $this->properties["$property"];
112123
}
113124

@@ -119,6 +130,7 @@ public function getProperty($property) {
119130
* @access public
120131
*/
121132
public function getProperties() {
133+
$this->updateAllProperties();
122134
return $this->properties;
123135
}
124136

@@ -280,6 +292,7 @@ public function inherit($property) {
280292
* @access public
281293
*/
282294
public function addSnapshot($snap_name, array $properties = null) {
295+
//not reachable method
283296
$snap = new OMVModuleZFSSnapshot($snap_name);
284297
$snap->create($properties);
285298
$this->snapshots[$snap_name] = $snap;

0 commit comments

Comments
 (0)