diff --git a/gosa-plugins/fai/admin/fai/class_faiPartition.inc b/gosa-plugins/fai/admin/fai/class_faiPartition.inc
index 4e8ef7eb12794a49cef746a664b44535cf976f63..ad553a2348acd2107c0841b3b4bd92271772a260 100644 (file)
var $FAIdiskType = "disk";
var $FAIdiskType = "disk";
+ // Size options.
var $FAIpartitionSizeType = "fixed";
var $sizeStart = 0;
var $sizeStop = 0;
var $sizeStart_Type = "MB";
var $sizeStop_Type = "MB";
var $FAIpartitionSizeType = "fixed";
var $sizeStart = 0;
var $sizeStop = 0;
var $sizeStart_Type = "MB";
var $sizeStop_Type = "MB";
-
+
+ // Flags
var $bootable = false;
var $resize = false;
var $bootable = false;
var $resize = false;
+ var $encrypted = false;
var $preserve = false;
var $preserveType = "always";
var $preserve = false;
var $preserveType = "always";
- var $encrypted = false;
- var $status = "";
var $raidDevices = array();
// Once we've exceeded the primary partition limit,
var $raidDevices = array();
// Once we've exceeded the primary partition limit,
{
$this->parent = $parent;
{
$this->parent = $parent;
- $this->status = "new";
$this->FAIdiskType = $type;
// Check if we should be able to add primary partitions.
$this->FAIdiskType = $type;
// Check if we should be able to add primary partitions.
}
}
}
}
}
}
-
+
// Load attributes from existing partition
if($object){
// Load attributes from existing partition
if($object){
-
foreach($this->attributes as $attr){
if(isset($object[$attr])){
$this->$attr = $object[$attr];
}
}
foreach($this->attributes as $attr){
if(isset($object[$attr])){
$this->$attr = $object[$attr];
}
}
- $this->status = $object['status'];
-
if($type == "disk" || $type =="lvm"){
/* Prepare size attribute
if($type == "disk" || $type =="lvm"){
/* Prepare size attribute
* remaining * -
*/
// Fixed
* remaining * -
*/
// Fixed
- if(preg_match("/^[0-9]*(KB|MB|GB|TB|PB|%)$/",$this->FAIpartitionSize)){
+ if(preg_match("/^[0-9]{1,}(KB|MB|GB|TB|PB|%|)$/",$this->FAIpartitionSize)){
$this->sizeStart = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB|%)$/","\\1",$this->FAIpartitionSize);
$this->sizeStart_Type = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB|%)$/","\\2",$this->FAIpartitionSize);
$this->FAIpartitionSizeType = "fixed";
}else
// Dynamic range
$this->sizeStart = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB|%)$/","\\1",$this->FAIpartitionSize);
$this->sizeStart_Type = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB|%)$/","\\2",$this->FAIpartitionSize);
$this->FAIpartitionSizeType = "fixed";
}else
// Dynamic range
- if(preg_match("/^[0-9]*(KB|MB|GB|TB|PB|%)-[0-9]*(KB|MB|GB|TB|PB|%)$/",$this->FAIpartitionSize)){
+ if(preg_match("/^[0-9]{1,}(KB|MB|GB|TB|PB|%|)-[0-9]{1,}(KB|MB|GB|TB|PB|%|)$/",$this->FAIpartitionSize)){
$this->sizeStart = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB|%).*$/","\\1",$this->FAIpartitionSize);
$this->sizeStart_Type = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB|%).*$/","\\2",$this->FAIpartitionSize);
$this->sizeStop = preg_replace("/^[^\-]*\-([0-9]*)(KB|MB|GB|TB|PB|%)$/","\\1",$this->FAIpartitionSize);
$this->sizeStart = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB|%).*$/","\\1",$this->FAIpartitionSize);
$this->sizeStart_Type = preg_replace("/^([0-9]*)(KB|MB|GB|TB|PB|%).*$/","\\2",$this->FAIpartitionSize);
$this->sizeStop = preg_replace("/^[^\-]*\-([0-9]*)(KB|MB|GB|TB|PB|%)$/","\\1",$this->FAIpartitionSize);
}else
// Dynamic range
}else
// Dynamic range
- if(preg_match("/^\-$/",$this->FAIpartitionSize)){
+ if(preg_match("/^(0|)\-$/",$this->FAIpartitionSize)){
$this->FAIpartitionSizeType = "remaining";
$this->FAIpartitionSizeType = "remaining";
+ }
+ // Ensure that we've a valid value type selected.
+ if(!preg_match("/(KB|MB|GB|TB|PB|%)/",$this->sizeStart_Type)){
+ $this->sizeStart_Type = "MB";
+ }
+ if(!preg_match("/(KB|MB|GB|TB|PB|%)/",$this->sizeStop_Type)){
+ $this->sizeStop_Type = "MB";
}
/* Check for encrypted partitions
}
/* Check for encrypted partitions
}
}elseif($type == "raid"){
}
}elseif($type == "raid"){
-
- $usedDisks = split(",",$this->FAIpartitionSize);
+
+ // Extract raid devices out of the partition size attribute.
+ $usedDisks = explode(",",$this->FAIpartitionSize);
foreach($usedDisks as $disk){
$name = preg_replace("/:.*$/","",$disk);
$spare = preg_match("/:spare/",$disk);
$missing = preg_match("/:missing/",$disk);
foreach($usedDisks as $disk){
$name = preg_replace("/:.*$/","",$disk);
$spare = preg_match("/:spare/",$disk);
$missing = preg_match("/:missing/",$disk);
- $this->raidDevices[$name] =
- array(
- "name" => $name,
- "spare" => $spare,
- "missing" => $missing);
+ if(!empty($name)){
+ $this->raidDevices[$name] =
+ array(
+ "name" => $name,
+ "spare" => $spare,
+ "missing" => $missing);
+ }
}
}
}
}
}
}
"ext4" => _("ext4"),
"reiserfs" => _("reiser fs"),
"xfs" => _("xfs"),
"ext4" => _("ext4"),
"reiserfs" => _("reiser fs"),
"xfs" => _("xfs"),
- "btrfs" => _("btrfs"));
+ "btrfs" => _("btrfs"),
+ "-" => "-");
$smarty->assign("partitionTypes", $types);
$smarty->assign("partitionSizeTypes", $partitionSizeTypes);
$smarty->assign("partitionTypes", $types);
$smarty->assign("partitionSizeTypes", $partitionSizeTypes);
$smarty->assign("FAIfsTypes", $FAIfsTypes);
$smarty->assign("cn", $this->cn);
$smarty->assign("FAIfsTypes", $FAIfsTypes);
$smarty->assign("cn", $this->cn);
+ $smarty->assign("freeze", preg_match("/freeze/i",$this->parent->FAIstate));
$smarty->assign("plist",$this->getRaidlist());
$smarty->assign("physicalPartitionList",$this->getPartitionlist());
$smarty->assign("plist",$this->getRaidlist());
$smarty->assign("physicalPartitionList",$this->getPartitionlist());
return($smarty->fetch(get_template_path("faiPartition.tpl", TRUE, dirname(__FILE__))));
}
return($smarty->fetch(get_template_path("faiPartition.tpl", TRUE, dirname(__FILE__))));
}
-
+
+ /* Returns a list of all partitions that are useable
+ * for raid arrays.
+ */
function getPartitionList()
{
function getPartitionList()
{
- $array = array();
+ $may = $used = array();
foreach($this->parent->parent->disks as $disk){
foreach($this->parent->parent->disks as $disk){
- if($disk['FAIdiskType'] != "raid"){
- foreach($disk['partitions'] as $key => $part){
+
+ // Skip ourselves
+ if($disk['cn'] == $this->parent->DISKcn) continue;
+
+ // Add partition from lvm combinations
+ if($disk['FAIdiskType'] == "lvm"){
+ $used = array_merge($used,$disk['FAIlvmDevice']);
+ }
+
+ foreach($disk['partitions'] as $key => $part){
+
+ // Add disks of raid arrays, to the used list.
+ if($disk['FAIdiskType'] == "raid"){
+ foreach(explode(",",$part['FAIpartitionSize']) as $rDevice){
+ $used[] = preg_replace("/:.*$/i","",$rDevice);
+ }
+ }
+
+ // Collect all available disks
+ if($disk['FAIdiskType'] == "disk"){
$name = $part['cn'];
if(!isset($this->raidDevices[$name])){
$name = $part['cn'];
if(!isset($this->raidDevices[$name])){
- $array[$name] = $name." (".$disk['cn'].")";
+ $may[] = $name;
}
}
}
}
}
}
}
}
- return($array);
+
+ // Check which of the available disks are unused.
+ $ret = array();
+ foreach($may as $val){
+ if(!in_array($val,$used)){
+ $ret[$val] = $val;
+ }
+ }
+ return($ret);
}
}
+ /* Creates a human readable list of all used partitions
+ * of a raid device.
+ */
function getRaidList()
{
$divlist = new divSelectBox("RaidList");
function getRaidList()
{
$divlist = new divSelectBox("RaidList");
-
$disks = $this->parent->parent->disks;
$objs = array();
foreach($disks as $disk){
$disks = $this->parent->parent->disks;
$objs = array();
foreach($disks as $disk){
$list = array();
foreach($this->raidDevices as $device){
$list = array();
foreach($this->raidDevices as $device){
- $list[$device['name']] = $device['name'];
-
+ $str = $name = $device['name'];
+ $str = str_pad($str,25," ");
if(isset($objs[$device['name']]['FAIpartitionSize'])){
if(isset($objs[$device['name']]['FAIpartitionSize'])){
- $list[$device['name']].= _("Size").": ";
- $list[$device['name']].= $objs[$device['name']]['FAIpartitionSize'];
+ $str .= _("Size").": ";
+ $str .= $objs[$device['name']]['FAIpartitionSize'];
}
}
-
- $list[$device['name']].= " "._("Options").": ";
+ $str = str_pad($str,60," ");
+ $opt = "";
if($device['spare']){
if($device['spare']){
- $list[$device['name']].= " "._("spare")." ";
+ $opt.= " "._("spare")." ";
}
if($device['missing']){
}
if($device['missing']){
- $list[$device['name']].= " "._("missing")." ";
+ $opt.= " "._("missing")." ";
}
}
+ if($opt){
+ $str .= " "._("Options").": ".$opt;
+ }
+ $str = str_pad($str,80," ");
+ $list[$name] = preg_replace("/ /"," ",$str);
}
return($list);
}
}
return($list);
}
}
}
}
}
+ // Allow user defined partition names for lvm disks.
+ if($this->FAIdiskType == "lvm" && isset($_POST['cn'])){
+ $this->cn = get_post('cn');
+ }
+
// Remove partition
if(isset($_POST['delPhysicalPartition']) && isset($_POST['physicalPartition'])){
// Remove partition
if(isset($_POST['delPhysicalPartition']) && isset($_POST['physicalPartition'])){
- unset($this->raidDevices[$_POST['physicalPartition']]);
+ foreach($_POST['physicalPartition'] as $key){
+ if(isset($this->raidDevices[$key])){
+ unset($this->raidDevices[$key]);
+ }
+ }
}
// Toggle spare flag for partition entries
}
// Toggle spare flag for partition entries
}
}
}
}
}
}
+
+ // Add raid checks
if($this->FAIdiskType == "raid"){
if($this->FAIdiskType == "raid"){
- #FIME raid checks missing
- echo "Add raid checks here, disk combinations are not verified right now.";
+ if(count($this->raidDevices) < 2){
+ $msgs[] = _("Raid arrays must contain at least two partitions!");
+ }else if($this->FAIpartitionType == "raid0" && count($this->raidDevices) != 2){
+ $msgs[] = _("Raid 0 arrays can only be realized with a combination of two partitions!");
+ }
}
// check mount point
}
// check mount point
- if($this->FAIfsType != "swap"){
+ if($this->FAIfsType != "swap" && $this->FAIfsType != "-"){
if(!preg_match("#^/#",$this->FAImountPoint)){
$msgs[] = msgPool::invalid(_("Mount point"));
}
if(!preg_match("#^/#",$this->FAImountPoint)){
$msgs[] = msgPool::invalid(_("Mount point"));
}
$ret['FAIpartitionSize'] = $this->sizeStart.$this->sizeStart_Type."-".
$this->sizeStop.$this->sizeStop_Type;break;
case 'remaining' :
$ret['FAIpartitionSize'] = $this->sizeStart.$this->sizeStart_Type."-".
$this->sizeStop.$this->sizeStop_Type;break;
case 'remaining' :
- $ret['FAIpartitionSize'] = "-";break;
+ $ret['FAIpartitionSize'] = "0-";break;
default: trigger_error("Unknown partition size!");
}
default: trigger_error("Unknown partition size!");
}
}
}elseif($this->FAIdiskType == "raid"){
}
}elseif($this->FAIdiskType == "raid"){
+
+ // Save selected raid partitions in FAIpartitionSize
$ret['FAIpartitionSize'] = "";
foreach($this->raidDevices as $device){
$ret['FAIpartitionSize'] .= $device['name'];
$ret['FAIpartitionSize'] = "";
foreach($this->raidDevices as $device){
$ret['FAIpartitionSize'] .= $device['name'];
}
$ret['FAIpartitionSize'] = trim($ret['FAIpartitionSize'],",");
}
}
$ret['FAIpartitionSize'] = trim($ret['FAIpartitionSize'],",");
}
- $ret['status'] = $this->status;
if($this->FAIfsType == "swap"){
$ret['FAImountPoint'] = "swap";
}
if($this->FAIfsType == "swap"){
$ret['FAImountPoint'] = "swap";
}
-
+
return($ret);
}
}
return($ret);
}
}