]>
Commit | Line | Data |
---|---|---|
6b3ce31b MR |
1 | <?php |
2 | ||
3 | require_once("openmediavault/object.inc"); | |
4 | require_once("openmediavault/config.inc"); | |
5 | require_once("openmediavault/error.inc"); | |
6 | require_once("openmediavault/util.inc"); | |
7 | require_once("openmediavault/rpcservice.inc"); | |
8 | require_once("openmediavault/notify.inc"); | |
9 | require_once("zfs/Utils.php"); | |
10 | require_once("zfs/Dataset.php"); | |
11 | require_once("zfs/Snapshot.php"); | |
12 | require_once("zfs/Zvol.php"); | |
503ffcc8 | 13 | require_once("zfs/Zpool.php"); |
c0253592 | 14 | require_once("zfs/NotifyListener.php"); |
6b3ce31b MR |
15 | |
16 | class OMVRpcServiceZFS extends OMVRpcServiceAbstract { | |
a36352f7 NB |
17 | public function getName() { |
18 | return "ZFS"; // RPC Service name. Same as in .js files | |
19 | } | |
6b3ce31b | 20 | |
a36352f7 NB |
21 | /* Initialize the RPC service. Different methods of the RPC service are declared here*/ |
22 | public function initialize() { | |
42856e8b | 23 | $this->registerMethod("addPool"); |
a36352f7 NB |
24 | $this->registerMethod("getObjectTree"); |
25 | $this->registermethod("passParam"); | |
26 | $this->registermethod("addObject"); | |
27 | $this->registermethod("deleteObject"); | |
28 | $this->registermethod("getProperties"); | |
29 | $this->registermethod("setProperties"); | |
30 | $this->registermethod("inherit"); | |
31 | $this->registermethod("getSharedParams"); | |
32 | $this->registermethod("createShare"); | |
54b9d43e | 33 | $this->registermethod("getObjectDetails"); |
a6c3a4dd | 34 | $this->registermethod("expandPool"); |
a36352f7 | 35 | } |
6b3ce31b | 36 | |
42856e8b NB |
37 | public function addPool($params, $context) { |
38 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
ecee099b NB |
39 | // Validate the parameters of the RPC service method. |
40 | $this->validateMethodParams($params, '{ | |
41 | "type":"object", | |
42 | "properties":{ | |
43 | "pooltype":{"type":"string","enum":["basic","mirror",' . | |
44 | '"raidz1","raidz2","raidz3"]}, | |
45 | "force":{"type":"boolean"}, | |
46 | "mountpoint":{"type":"string"}, | |
47 | "name":{"type":"string"}, | |
48 | "devices":{"type":"string"} | |
49 | } | |
50 | }'); | |
42856e8b NB |
51 | switch ($params['pooltype']) { |
52 | case "basic": | |
53 | $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSPLAIN; | |
54 | break; | |
55 | case "mirror": | |
56 | $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSMIRROR; | |
57 | break; | |
58 | case "raidz1": | |
59 | $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ1; | |
60 | break; | |
61 | case "raidz2": | |
62 | $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ2; | |
63 | break; | |
64 | case "raidz3": | |
65 | $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ3; | |
66 | break; | |
67 | default: | |
68 | throw new OMVModuleZFSException("Incorrect pool type specified"); | |
69 | break; | |
70 | } | |
7d6b772c NB |
71 | //Check for user supplied options |
72 | $opts = ""; | |
73 | if ($params['force']) { | |
74 | $opts .= "-f "; | |
75 | } | |
c6117b32 NB |
76 | if (strlen($params['mountpoint']) > 0) { |
77 | $opts .= "-m " . $params['mountpoint'] . " "; | |
78 | } | |
79 | ||
e20fe312 | 80 | //Use /dev/disk/by-path as deafult when creating new pools as suggested in ZoL FAQ. |
42856e8b | 81 | $disks = preg_split("/[,;]/", $params['devices']); |
e20fe312 NB |
82 | if (file_exists("/dev/disk/by-path/")) { |
83 | $tmp_disks = array(); | |
84 | foreach ($disks as $disk) { | |
85 | $tmp_disks[] = OMVModuleZFSUtil::getDiskPath($disk); | |
86 | } | |
87 | $disks = $tmp_disks; | |
88 | } | |
89 | ||
42856e8b | 90 | $vdev = new OMVModuleZFSVdev($params['name'], $pooltype, $disks); |
7d6b772c | 91 | $pool = new OMVModuleZFSZpool($vdev, $opts); |
57667eb1 NB |
92 | //Ugly fix to solve the problem of blkid not displaying info on newly created pools |
93 | $pool->export(); | |
94 | $pool->import($pool->getName()); | |
42856e8b NB |
95 | } |
96 | ||
6b3ce31b MR |
97 | public function getObjectTree($params, $context) { |
98 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
99 | $objects = OMVModuleZFSUtil::getZFSFlatArray(); | |
100 | $new = array(); | |
101 | foreach ($objects as $a){ | |
102 | $new[$a['parentid']][] = $a; | |
103 | } | |
104 | $tree = OMVModuleZFSUtil::createTree($new, $new['root']); | |
a36352f7 | 105 | OMVModuleZFSUtil::addMissingOMVMntEnt(); //Adds missing ZFS filesystems to the OMV core |
6b3ce31b MR |
106 | return $tree; |
107 | } | |
108 | ||
109 | public function passParam($params, $context) { | |
110 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
ecee099b NB |
111 | // Validate the parameters of the RPC service method. |
112 | $this->validateMethodParams($params, '{ | |
113 | "type":"object", | |
114 | "properties":{ | |
115 | "key":{"type":"string"}, | |
116 | "value":{"type":"string"} | |
117 | } | |
118 | }'); | |
6b3ce31b MR |
119 | return array($params['key'] => $params['value']); |
120 | } | |
121 | ||
122 | public function addObject($params, $context) { | |
123 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
ecee099b NB |
124 | // Validate the parameters of the RPC service method. |
125 | $this->validateMethodParams($params, '{ | |
126 | "type":"object", | |
127 | "properties":{ | |
128 | "type":{"type":"string","enum":["filesystem","snapshot",' . | |
bcf5fe52 | 129 | '"volume","clone"]}, |
ecee099b NB |
130 | "path":{"type":"string"}, |
131 | "name":{"type":"string"}, | |
bcf5fe52 | 132 | "size":{"type":"string"}, |
c247043c NB |
133 | "clonename":{"type":"string"}, |
134 | "mountpoint":{"type":"string"} | |
ecee099b NB |
135 | } |
136 | }'); | |
6b3ce31b | 137 | switch ($params['type']) { |
bcf5fe52 NB |
138 | case "clone": |
139 | $tmp = new OMVModuleZFSSnapshot($params['path']); | |
140 | $tmp->clonesnap($params['clonename']); | |
141 | break; | |
57667eb1 | 142 | case "filesystem": |
6b3ce31b MR |
143 | $name = $params['path'] . "/" . $params['name']; |
144 | $tmp = new OMVModuleZFSDataset($name); | |
c247043c NB |
145 | if (strlen($params['mountpoint']) > 0) { |
146 | $properties = array("mountpoint"=>$params['mountpoint']); | |
147 | $tmp->setProperties($properties); | |
148 | } | |
6b3ce31b | 149 | break; |
57667eb1 | 150 | case "snapshot": |
6b3ce31b MR |
151 | $name = $params['path'] . "@" . $params['name']; |
152 | $tmp = new OMVModuleZFSSnapshot($name); | |
153 | break; | |
57667eb1 | 154 | case "volume": |
6b3ce31b MR |
155 | $name = $params['path'] . "/" . $params['name']; |
156 | $tmp = new OMVModuleZFSZvol($name); | |
157 | $tmp->create($params['size']); | |
158 | break; | |
159 | default: | |
160 | throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); | |
161 | break; | |
162 | } | |
163 | } | |
164 | ||
165 | public function deleteObject($params, $context) { | |
166 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
ecee099b NB |
167 | // Validate the parameters of the RPC service method. |
168 | $this->validateMethodParams($params, '{ | |
169 | "type":"object", | |
170 | "properties":{ | |
171 | "type":{"type":"string","enum":["Filesystem","Snapshot",' . | |
bcf5fe52 | 172 | '"Volume","Pool"]}, |
ecee099b NB |
173 | "name":{"type":"string"} |
174 | } | |
175 | }'); | |
97e4887b NB |
176 | global $xmlConfig; |
177 | $name = $params['name']; | |
6b3ce31b | 178 | switch ($params['type']) { |
81500319 | 179 | case "Filesystem": |
216661f4 NB |
180 | OMVModuleZFSUtil::deleteShares($name); |
181 | $tmp = new OMVModuleZFSDataset($name); | |
182 | $tmp->destroy(); | |
183 | break; | |
6b3ce31b | 184 | case "Snapshot": |
6b3ce31b MR |
185 | $tmp = new OMVModuleZFSSnapshot($name); |
186 | $tmp->destroy(); | |
187 | break; | |
188 | case "Volume": | |
6b3ce31b MR |
189 | $tmp = new OMVModuleZFSZvol($name); |
190 | $tmp->destroy(); | |
191 | break; | |
503ffcc8 | 192 | case "Pool": |
97e4887b NB |
193 | $disks = OMVModuleZFSUtil::getDevDisksByPool($name); |
194 | $pooluuid = OMVModuleZFSUtil::getUUIDbyName($name); | |
503ffcc8 MR |
195 | $tmp = new OMVModuleZFSZpool($name); |
196 | $tmp->destroy(); | |
97e4887b NB |
197 | $xpath = "//system/fstab/mntent[fsname='" . $pooluuid . "' and type='zfs']"; |
198 | $object = $xmlConfig->get($xpath); | |
199 | $xmlConfig->delete($xpath); | |
97e4887b | 200 | OMVModuleZFSUtil::clearZFSLabel($disks); |
503ffcc8 | 201 | break; |
6b3ce31b MR |
202 | default: |
203 | throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); | |
204 | break; | |
205 | } | |
206 | } | |
207 | ||
208 | public function getProperties($params, $context) { | |
209 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
ecee099b NB |
210 | // Validate the parameters of the RPC service method. |
211 | $this->validateMethodParams($params, '{ | |
212 | "type":"object", | |
213 | "properties":{ | |
214 | "type":{"type":"string"}, | |
215 | "name":{"type":"string"}, | |
216 | "start":{"type":"integer"}, | |
217 | "limit":{'.$GLOBALS['OMV_JSONSCHEMA_COUNTFIELD'].'}, | |
218 | "sortfield":{'.$GLOBALS['OMV_JSONSCHEMA_SORTFIELD'].'}, | |
219 | "sortdir":{'.$GLOBALS['OMV_JSONSCHEMA_SORTDIR'].'} | |
220 | } | |
221 | }'); | |
6b3ce31b MR |
222 | $objects = array(); |
223 | $name = $params['name']; | |
224 | switch ($params['type']) { | |
5ff626ba | 225 | case "Filesystem": |
6b3ce31b MR |
226 | $tmp = new OMVModuleZFSDataset($name); |
227 | break; | |
228 | case "Snapshot": | |
229 | $tmp = new OMVModuleZFSSnapshot($name); | |
230 | break; | |
231 | case "Volume": | |
232 | $tmp = new OMVModuleZFSZvol($name); | |
233 | break; | |
503ffcc8 | 234 | case "Pool": |
a36352f7 NB |
235 | $tmp = new OMVModuleZFSZpool($name); |
236 | break; | |
6b3ce31b MR |
237 | default: |
238 | throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); | |
239 | break; | |
240 | } | |
241 | $properties = $tmp->getProperties(); | |
242 | foreach ($properties as $propertyk => $propertyv) { | |
243 | if (!(strcmp($propertyv['source'], "-") == 0)) { | |
244 | $objects[] = array('property' => $propertyk, | |
245 | 'value' => $propertyv['value'], | |
246 | 'source' => $propertyv['source'], | |
247 | 'modified' => "false"); | |
248 | } | |
249 | } | |
250 | return $objects; | |
251 | } | |
252 | ||
253 | public function setProperties($params, $context) { | |
254 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
ecee099b NB |
255 | // Validate the parameters of the RPC service method. |
256 | $this->validateMethodParams($params, '{ | |
257 | "type":"object", | |
258 | "properties":{ | |
259 | "type":{"type":"string","enum":["Filesystem","Snapshot",' . | |
bcf5fe52 | 260 | '"Volume","Pool"]}, |
ecee099b NB |
261 | "name":{"type":"string"}, |
262 | "properties":{"type":"array","items":{ | |
263 | "type":"object", | |
264 | "properties":{ | |
265 | "property":{"type":"string"}, | |
266 | "value":{"type":"string"}}}} | |
267 | } | |
268 | }'); | |
cc1caa78 | 269 | global $xmlConfig; |
6b3ce31b | 270 | switch ($params['type']) { |
5ff626ba | 271 | case "Filesystem": |
6b3ce31b MR |
272 | $tmp = new OMVModuleZFSDataset($params['name']); |
273 | break; | |
274 | case "Snapshot": | |
275 | $tmp = new OMVModuleZFSSnapshot($params['name']); | |
276 | break; | |
277 | case "Volume": | |
278 | $tmp = new OMVModuleZFSZvol($params['name']); | |
279 | break; | |
503ffcc8 MR |
280 | case "Pool": |
281 | $tmp = new OMVModuleZFSZpool($params['name']); | |
282 | break; | |
6b3ce31b MR |
283 | default: |
284 | throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); | |
285 | break; | |
81500319 | 286 | } |
6b3ce31b | 287 | foreach ($params['properties'] as $property) { |
cc1caa78 NB |
288 | unset($objects); |
289 | $objects = array(); | |
6b3ce31b | 290 | $objects[$property['property']] = $property['value']; |
cc1caa78 NB |
291 | $tmp->setProperties($objects); |
292 | if ((strcmp($property['property'], "mountpoint") === 0) && (strcmp($params['type'], "Filesystem") === 0)) { | |
293 | OMVModuleZFSUtil::relocateFilesystem($params['name']); | |
294 | } | |
6b3ce31b | 295 | } |
6b3ce31b MR |
296 | } |
297 | ||
298 | public function inherit($params, $context) { | |
299 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
ecee099b NB |
300 | // Validate the parameters of the RPC service method. |
301 | $this->validateMethodParams($params, '{ | |
302 | "type":"object", | |
303 | "properties":{ | |
304 | "type":{"type":"string","enum":["Filesystem","Snapshot",' . | |
bcf5fe52 | 305 | '"Volume","Pool"]}, |
ecee099b NB |
306 | "name":{"type":"string"}, |
307 | "property":{"type":"string"} | |
308 | } | |
309 | }'); | |
6b3ce31b MR |
310 | // Create a background process. |
311 | $bgStatusFilename = $this->createBgProcStatus(); | |
312 | $pid = $this->fork(); | |
313 | if($pid > 0) { // Parent process. | |
314 | $this->initializeBgProcStatus($bgStatusFilename, $pid); | |
315 | return $bgStatusFilename; | |
316 | } | |
317 | // Child process. | |
318 | try { | |
319 | $bgOutputFilename = $this->createBgProcOutput(); | |
320 | $this->updateBgProcStatus($bgStatusFilename, "outputfilename", $bgOutputFilename); | |
321 | switch ($params['type']) { | |
5ff626ba | 322 | case "Filesystem": |
6b3ce31b MR |
323 | $tmp = new OMVModuleZFSDataset($params['name']); |
324 | break; | |
325 | case "Snapshot": | |
326 | $tmp = new OMVModuleZFSSnapshot($params['name']); | |
327 | break; | |
328 | case "Volume": | |
329 | $tmp = new OMVModuleZFSZvol($params['name']); | |
330 | break; | |
503ffcc8 MR |
331 | case "Pool": |
332 | $tmp = new OMVModuleZFSZpool($params['name']); | |
333 | break; | |
6b3ce31b MR |
334 | default: |
335 | throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); | |
336 | break; | |
337 | } | |
338 | $tmp->inherit($params['property']); | |
339 | $this->finalizeBgProcStatus($bgStatusFilename, $output); | |
340 | exit(0); | |
341 | } catch(Exception $e) { | |
342 | $this->finalizeBgProcStatus($bgStatusFilename, "", $e); | |
343 | exit(1); | |
344 | } | |
345 | } | |
346 | ||
347 | public function getSharedParams($params, $context) { | |
348 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
ecee099b NB |
349 | // Validate the parameters of the RPC service method. |
350 | $this->validateMethodParams($params, '{ | |
351 | "type":"object", | |
352 | "properties":{ | |
353 | "type":{"type":"string"}, | |
354 | "name":{"type":"string"} | |
355 | } | |
356 | }'); | |
6b3ce31b | 357 | $objects = array(); |
cc1caa78 NB |
358 | //$ds = new OMVModuleZFSDataset($params['name']); |
359 | //$mountpoint = $ds->getMountPoint(); | |
6b3ce31b | 360 | return array( |
cc1caa78 | 361 | //"mountpoint" => $mountpoint, |
6b3ce31b MR |
362 | "name" => $params['name'], |
363 | "type" => $params['type']); | |
364 | } | |
365 | ||
366 | public function createShare($params, $context) { | |
367 | global $xmlConfig; | |
368 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
ecee099b NB |
369 | // Validate the parameters of the RPC service method. |
370 | $this->validateMethodParams($params, '{ | |
371 | "type":"object", | |
372 | "properties":{ | |
373 | "name":{"type":"string"}, | |
bcf5fe52 | 374 | "type":{"type":"string","enum":["Filesystem"]}, |
ecee099b NB |
375 | "sharename":{'.$GLOBALS['OMV_JSONSCHEMA_SHARENAME'].'}, |
376 | "comment":{"type":"string"}, | |
377 | "mode":{"type":"string","enum":["700","750","755",'. | |
378 | '"770","775","777"],"optional":true}, | |
379 | "mountpoint":{"type":"string"} | |
380 | } | |
381 | }'); | |
cc1caa78 NB |
382 | |
383 | // The field 'reldirpath' may not contain the characters '..'. This | |
384 | // is because of security reasons: the given canonicalized absolute | |
385 | // path MUST be below the given mount point. | |
386 | if(1 == preg_match("/\.\./", $params['mountpoint'])) { | |
387 | throw new OMVException(OMVErrorMsg::E_RPC_SERVICE_METHOD_INVALID_PARAMS, | |
388 | sprintf(gettext("The field '%s' contains forbidden two-dot symbols"), "mountpoint")); | |
389 | } | |
390 | ||
6b3ce31b MR |
391 | // Prepare the configuration object. Use the name of the shared |
392 | // folder as the relative directory name of the share. | |
393 | switch ($params['type']) { | |
5ff626ba | 394 | case "Filesystem": |
a36352f7 NB |
395 | $tmp = new OMVModuleZFSDataset($params['name']); |
396 | break; | |
6b3ce31b MR |
397 | default: |
398 | throw new OMVModuleZFSException("Illegal type provided: " . $params['type']); | |
399 | break; | |
400 | } | |
401 | ||
cc1caa78 NB |
402 | $poolname = OMVModuleZFSUtil::getPoolname($params['name']); |
403 | $pooluuid = OMVModuleZFSUtil::getUUIDbyName($poolname); | |
404 | $dir = $tmp->getMountPoint(); | |
405 | ||
406 | //Get the mntent object and fetch it's uuid. | |
407 | $xpath = "//system/fstab/mntent[fsname='" . $pooluuid . "' and dir='" . $dir . "' and type='zfs']"; | |
408 | $mountpoint = $xmlConfig->get($xpath); | |
409 | $mntentref = $mountpoint['uuid']; | |
410 | ||
6b3ce31b | 411 | $uuid = OMVUtil::uuid(); |
cc1caa78 NB |
412 | $pathName = $dir . "/" . trim($params['mountpoint'], "/"); |
413 | $reldirpath = trim($params['mountpoint'], "/"); | |
6b3ce31b MR |
414 | $object = array( |
415 | "uuid" => $uuid, | |
416 | "name" => $params['sharename'], | |
cc1caa78 | 417 | "comment" => $params['comment'] . "*** ZFS share on " . $params['name'] . " ***", |
6b3ce31b MR |
418 | "mntentref" => $mntentref, |
419 | "reldirpath" => $reldirpath | |
420 | ); | |
421 | ||
422 | // Set the configuration object. | |
423 | $success = FALSE; | |
424 | // Check uniqueness. The share name must be global unique because | |
425 | // the name is also used when exporting a shared folder via NFS for | |
426 | // example. | |
427 | $xpath = sprintf("//system/shares/sharedfolder[name='%s']", | |
428 | $params['name']); | |
429 | if(TRUE === $xmlConfig->exists($xpath)) { | |
430 | throw new OMVException(OMVErrorMsg::E_CONFIG_OBJECT_UNIQUENESS, | |
431 | gettext("A shared folder with the given name already exists")); | |
432 | } | |
433 | ||
434 | // Add empty list of privileges per default. | |
435 | $object['privileges'] = array(); | |
436 | ||
437 | // Append object to configuration. | |
438 | $success = $xmlConfig->set("//system/shares", | |
439 | array("sharedfolder" => $object)); | |
440 | if(FALSE === $success) { | |
441 | throw new OMVException(OMVErrorMsg::E_CONFIG_SET_OBJECT_FAILED); | |
442 | } | |
443 | ||
444 | // Append the file mode field to the notification object if set. | |
445 | // Defaults to 775. | |
446 | $object['mode'] = "775"; | |
447 | if(array_key_exists("mode", $params)) { | |
448 | $object['mode'] = $params['mode']; | |
449 | } | |
450 | ||
cc1caa78 NB |
451 | // Create the shared folder directory if necessary. |
452 | if(FALSE === file_exists($pathName)) { | |
453 | // Create the directory. Note, the function seems to have a bug | |
454 | // when using the mask parameter. E.g. octdec("777") does not | |
455 | // create the correct permissions as expected, thus change the | |
456 | // mode using chmod. | |
457 | if(FALSE === mkdir($pathName, 0700, TRUE)) { | |
458 | throw new OMVException(OMVErrorMsg::E_MISC_FAILURE, | |
459 | sprintf("Failed to create the directory '%s'", $pathName)); | |
460 | } | |
461 | // Change the directory mode. | |
462 | if(FALSE === chmod($pathName, octdec($object['mode']))) { | |
463 | throw new OMVException(OMVErrorMsg::E_MISC_FAILURE, | |
464 | sprintf("Failed to set file mode to '%s' for '%s'", | |
465 | $object['mode'], $pathName)); | |
466 | } | |
467 | } | |
468 | ||
6b3ce31b MR |
469 | // Change group owner of directory to configured default group, |
470 | // e.g. 'users'. | |
471 | if(FALSE === chgrp($pathName, $GLOBALS['OMV_USERMGMT_DEFAULT_GROUP'])) { | |
472 | throw new OMVException(OMVErrorMsg::E_MISC_FAILURE, | |
473 | sprintf("Failed to set file group to '%s' for '%s'", | |
474 | $GLOBALS['OMV_USERMGMT_DEFAULT_GROUP'], $pathName)); | |
475 | } | |
476 | ||
477 | // Set the setgid bit. Setting this permission means that all files | |
478 | // created in the folder will inherit the group of the folder rather | |
479 | // than the primary group of the user who creates the file. | |
480 | $mode = fileperms($pathName) | 02000; | |
481 | if(FALSE === chmod($pathName, $mode)) { | |
482 | throw new OMVException(OMVErrorMsg::E_MISC_FAILURE, | |
483 | sprintf("Failed to set file mode to '%o' for '%s'", | |
484 | $mode, $pathName)); | |
485 | } | |
486 | ||
487 | // Notify configuration changes. | |
488 | $dispatcher = &OMVNotifyDispatcher::getInstance(); | |
489 | $dispatcher->notify(OMV_NOTIFY_CREATE,"org.openmediavault.system.shares.sharedfolder", $object); | |
490 | // Return the configuration object. | |
491 | return $object; | |
6b3ce31b MR |
492 | } |
493 | ||
54b9d43e NB |
494 | public function getObjectDetails($params, $context) { |
495 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
496 | // Validate the parameters of the RPC service method. | |
497 | $this->validateMethodParams($params, '{ | |
498 | "type":"object", | |
499 | "properties":{ | |
500 | "name":{"type":"string"}, | |
501 | "type":{"type":"string"} | |
502 | } | |
503 | }'); | |
504 | $output = ""; | |
505 | switch ($params['type']) { | |
506 | case "Filesystem": | |
507 | $output .= "Filesystem details (zfs get all):\n\r\n\r"; | |
508 | $cmd = "zfs get all {$params['name']}"; | |
509 | break; | |
510 | case "Volume": | |
511 | $output .= "Volume details (zfs get all):\n\r\n\r"; | |
512 | $cmd = "zfs get all {$params['name']}"; | |
513 | break; | |
514 | case "Snapshot": | |
515 | $output .= "Snapshot details (zfs get all):\n\r\n\r"; | |
516 | $cmd = "zfs get all {$params['name']}"; | |
517 | break; | |
518 | case "Pool": | |
a238c1a1 NB |
519 | $output .= "Pool status (zpool status):\n\r\n\r"; |
520 | $cmd = "zpool status {$params['name']}"; | |
521 | OMVModuleZFSUtil::exec($cmd,$out,$res); | |
522 | $output .= implode("\n\r", $out); | |
523 | unset($out); | |
524 | $output .= "\n\r\n\rPool details (zpool get all):\n\r\n\r"; | |
54b9d43e | 525 | $cmd = "zpool get all {$params['name']}"; |
a238c1a1 NB |
526 | OMVModuleZFSUtil::exec($cmd,$out,$res); |
527 | $output .= implode("\n\r", $out); | |
528 | unset($out); | |
529 | $output .= "\n\r\n\rPool filesystem details (zfs get all):\n\r\n\r"; | |
530 | $cmd = "zfs get all {$params['name']}"; | |
54b9d43e NB |
531 | break; |
532 | default: | |
533 | throw new OMVModuleZFSException("Incorrect type provided"); | |
534 | } | |
535 | OMVModuleZFSUtil::exec($cmd,$out,$res); | |
536 | $output .= implode("\n\r", $out); | |
537 | return array("details" => $output); | |
538 | } | |
a6c3a4dd NB |
539 | |
540 | public function expandPool($params, $context) { | |
541 | $this->validateMethodContext($context, array("role" => OMV_ROLE_ADMINISTRATOR)); | |
542 | // Validate the parameters of the RPC service method. | |
543 | $this->validateMethodParams($params, '{ | |
544 | "type":"object", | |
545 | "properties":{ | |
77a007e0 NB |
546 | "vdevtype":{"type":"string","enum":["basic","mirror",' . |
547 | '"raidz1","raidz2","raidz3"]}, | |
a6c3a4dd | 548 | "name":{"type":"string"}, |
47e63d33 NB |
549 | "devices":{"type":"string"}, |
550 | "force":{"type":"boolean"} | |
a6c3a4dd NB |
551 | } |
552 | }'); | |
553 | $pool = new OMVModuleZFSZpool($params['name']); | |
77a007e0 NB |
554 | switch ($params['vdevtype']) { |
555 | case "basic": | |
a6c3a4dd NB |
556 | $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSPLAIN; |
557 | break; | |
77a007e0 | 558 | case "mirror": |
a6c3a4dd NB |
559 | $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSMIRROR; |
560 | break; | |
77a007e0 | 561 | case "raidz1": |
a6c3a4dd NB |
562 | $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ1; |
563 | break; | |
77a007e0 | 564 | case "raidz2": |
a6c3a4dd NB |
565 | $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ2; |
566 | break; | |
77a007e0 | 567 | case "raidz3": |
a6c3a4dd NB |
568 | $pooltype = OMVModuleZFSVdevType::OMVMODULEZFSRAIDZ3; |
569 | break; | |
570 | default: | |
571 | throw new OMVModuleZFSException("Incorrect pool type specified"); | |
572 | break; | |
573 | } | |
47e63d33 NB |
574 | if ($params['force']) { |
575 | $opts .= "-f "; | |
576 | } | |
a6c3a4dd NB |
577 | //Use /dev/disk/by-path as deafult when creating new pools as suggested in ZoL FAQ. |
578 | $disks = preg_split("/[,;]/", $params['devices']); | |
579 | if (file_exists("/dev/disk/by-path/")) { | |
580 | $tmp_disks = array(); | |
581 | foreach ($disks as $disk) { | |
582 | $tmp_disks[] = OMVModuleZFSUtil::getDiskPath($disk); | |
583 | } | |
584 | $disks = $tmp_disks; | |
585 | } | |
586 | $vdev[] = new OMVModuleZFSVdev($params['name'], $pooltype, $disks); | |
47e63d33 | 587 | $pool->addVdev($vdev, $opts); |
a6c3a4dd NB |
588 | //Ugly fix to solve the problem of blkid not displaying info on newly created pools |
589 | $pool->export(); | |
590 | $pool->import($pool->getName()); | |
591 | } | |
6b3ce31b MR |
592 | } |
593 | ||
594 | // Register the RPC service. | |
81500319 | 595 | $rpcServiceMgr = &OMVRpcServiceMgr::getInstance(); // Get the "root" instance for the Services |
6b3ce31b MR |
596 | $rpcServiceMgr->registerService(new OMVRpcServiceZFS()); // Register a new instance of the RPC service described above |
597 | ?> | |
598 |