From e20fe312a03771aeb3233e1ef640a3c9b8d9c737 Mon Sep 17 00:00:00 2001 From: Niclas Berglind Date: Tue, 16 Sep 2014 21:47:28 +0200 Subject: [PATCH] Use /dev/disk/by-path as default for new pools as suggested by ZoL FAQ. Signed-off-by: Niclas Berglind --- gui/rpc/zfs.inc | 9 +++++++++ src/Utils.php | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gui/rpc/zfs.inc b/gui/rpc/zfs.inc index beaefa4..84fa26d 100644 --- a/gui/rpc/zfs.inc +++ b/gui/rpc/zfs.inc @@ -63,7 +63,16 @@ class OMVRpcServiceZFS extends OMVRpcServiceAbstract { $opts .= "-m " . $params['mountpoint'] . " "; } + //Use /dev/disk/by-path as deafult when creating new pools as suggested in ZoL FAQ. $disks = preg_split("/[,;]/", $params['devices']); + if (file_exists("/dev/disk/by-path/")) { + $tmp_disks = array(); + foreach ($disks as $disk) { + $tmp_disks[] = OMVModuleZFSUtil::getDiskPath($disk); + } + $disks = $tmp_disks; + } + $vdev = new OMVModuleZFSVdev($params['name'], $pooltype, $disks); $pool = new OMVModuleZFSZpool($vdev, $opts); //Ugly fix to solve the problem of blkid not displaying info on newly created pools diff --git a/src/Utils.php b/src/Utils.php index cc0814b..4d577f8 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -8,6 +8,22 @@ require_once("Dataset.php"); */ class OMVModuleZFSUtil { + /** + * Get /dev/disk/by-path from /dev/sdX + * + * @return string Disk identifier + */ + public static function getDiskPath($disk) { + preg_match("/^.*\/([A-Za-z0-9]+)$/", $disk, $identifier); + $cmd = "ls -la /dev/disk/by-path | grep '$identifier[1]$'"; + OMVModuleZFSUtil::exec($cmd, $out, $res); + if (is_array($out)) { + $cols = preg_split('/[\s]+/', $out[0]); + return($cols[count($cols)-3]); + } + } + + /** * Get poolname from name of dataset/volume etc. * -- 2.39.2