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