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