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