diff --git a/gosa-plugins/fai/admin/fai/class_faiPartition.inc b/gosa-plugins/fai/admin/fai/class_faiPartition.inc
index e3ed5dac8dd8bb6f2b900034f0f497eb7410d6b1..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();
var $raidDevices = array();
+ // Once we've exceeded the primary partition limit,
+ // hide the the 'primary' option from the select box.
+ var $disablePrimary = FALSE;
+
function __construct($config, $object, $parent,$type)
{
$this->parent = $parent;
function __construct($config, $object, $parent,$type)
{
$this->parent = $parent;
- $this->status = "new";
-
+ $this->FAIdiskType = $type;
+
+ // Check if we should be able to add primary partitions.
+ if(!$object || $object['FAIpartitionType'] == "logical"){
+ if($this->FAIdiskType == "disk"){
+ $types = array('logical' => array(), 'primary' => array());
+ foreach($this->parent->partitions as $key => $part){
+ $types[$part['FAIpartitionType']][$part['FAIpartitionNr']] = 1;
+ }
+ if(count($types['logical']) && count($types['primary']) >= 3){
+ $this->disablePrimary = TRUE;
+ }elseif(count($types['logical']) >= 4){
+ $this->disablePrimary = TRUE;
+ }
+ }
+ }
+
// 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'];
- $this->FAIdiskType = $type;
-
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);
+ }
}
}
}
}
}
}
// Create a list of selectable partition types
if($this->FAIdiskType == "disk"){
// Create a list of selectable partition types
if($this->FAIdiskType == "disk"){
- $types = array(
- "primary" => _("Primary"),
- "secondary" => _("Secondary"));
+
+ if($this->disablePrimary){
+ $types = array(
+ "logical" => _("Logical"));
+ }else{
+ $types = array(
+ "primary" => _("Primary"),
+ "logical" => _("Logical"));
+ }
+
}elseif($this->FAIdiskType == "raid"){
$types = array(
}elseif($this->FAIdiskType == "raid"){
$types = array(
- "raid0" => _("Raid 0"),
- "raid1" => _("Raid 1"),
- "raid5" => _("Raid 5"),
- "raid6" => _("Raid 6"));
+ "raid0" => _("RAID 0"),
+ "raid1" => _("RAID 1"),
+ "raid5" => _("RAID 5"),
+ "raid6" => _("RAID 6"));
}else{
$types = "";
}
// Create a list of all size options
$partitionSizeTypes = array(
}else{
$types = "";
}
// Create a list of all size options
$partitionSizeTypes = array(
- "fixed" => _("Fixed"),
- "dynamic" => _("Dynamic"),
- "remaining" => _("Use remaining space")
+ "fixed" => _("fixed"),
+ "dynamic" => _("dynamic"),
+ "remaining" => _("remaining space")
);
// Create a list of all size options
);
// Create a list of all size options
"GB" => _("GB"),
"TB" => _("TB"),
"PB" => _("PB"),
"GB" => _("GB"),
"TB" => _("TB"),
"PB" => _("PB"),
- "%" => _("Percent")
+ "%" => _("%")
);
// Preserve types
$preserveTypes = array(
);
// Preserve types
$preserveTypes = array(
- "always" => _("Always"),
- "reinstall" => _("Reinstall"));
+ "always" => _("always"),
+ "reinstall" => _("reinstall"));
// File system types.
$FAIfsTypes = array(
// File system types.
$FAIfsTypes = array(
- "swap" => _("Swap"),
- "ext2" => _("Ext 2"),
- "ext3" => _("Ext 3"),
- "ext4" => _("Ext 4"),
- "reiserfs" => _("Reiser fs"),
- "xfs" => _("Xfs"),
- "btrfs" => _("Btrfs"));
+ "swap" => _("swap space"),
+ "ext2" => _("ext2"),
+ "ext3" => _("ext3"),
+ "ext4" => _("ext4"),
+ "reiserfs" => _("reiser fs"),
+ "xfs" => _("xfs"),
+ "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());
+ $smarty->assign("disablePrimary", $this->disablePrimary);
foreach($this->attributes as $attr){
$smarty->assign($attr,$this->$attr);
foreach($this->attributes as $attr){
$smarty->assign($attr,$this->$attr);
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){
+
+ // 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){
foreach($disk['partitions'] as $key => $part){
- $name = $disk['cn'];
- if(!isset($this->raidDevices[$name])){
- $array[$name] = $name;
+
+ // 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])){
+ $may[] = $name;
+ }
+ }
+ }
+ }
+
+ // Check which of the available disks are unused.
+ $ret = array();
+ foreach($may as $val){
+ if(!in_array($val,$used)){
+ $ret[$val] = $val;
}
}
}
}
- return($array);
+ 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;
$disks = $this->parent->parent->disks;
- $objs = $disks;
+ $objs = array();
foreach($disks as $disk){
foreach($disks as $disk){
- foreach($disk['partitions'] as $id => $part){
- $objs[$disk['cn']] = $part;
+ if($disk['FAIdiskType'] != "raid"){
+ foreach($disk['partitions'] as $id => $part){
+ $objs[$part['cn']] = $part;
+ }
}
}
}
}
-
+
$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
$res1 = $this->sizeStart * $mp[$this->sizeStart_Type];
$res2 = $this->sizeStop * $mp[$this->sizeStop_Type];
if($res1 > $res2){
$res1 = $this->sizeStart * $mp[$this->sizeStart_Type];
$res2 = $this->sizeStop * $mp[$this->sizeStop_Type];
if($res1 > $res2){
- $msgs[] = msgPool::toobig(_("Partition start size"), "'"._("Partition stop size")."'");
+ $msgs[] = msgPool::toobig(_("Minimum partition size"), "'"._("Maximum partition size")."'");
}
}
}
}
}
}
+ // Add raid checks
+ if($this->FAIdiskType == "raid"){
+ 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);
}
}