From: hickert Date: Thu, 6 Aug 2009 13:23:26 +0000 (+0000) Subject: Updated FAI partition stuff X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=98b06228d7bff9353993e10ea0b634d70aad37ad;p=gosa.git Updated FAI partition stuff -Added check to avoid the removal of used partitions. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13985 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc b/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc index aa1d1e23b..577a2365b 100644 --- a/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc +++ b/gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc @@ -379,33 +379,72 @@ class faiDiskEntry extends plugin function removePartition($id) { $start = false; - foreach($this->partitions as $key => $part){ - if($id == $key){ - $start = true; - } - if($start){ - if($this->partitions[$key]['status'] == "edited"){ - $this->deletePartitions[$key]= $this->partitions[$key]; - $this->deletePartitions[$key]['FAIpartitionNr']=$key; - unset($this->partitions[$key]); - }else{ - unset($this->partitions[$key]); + + /* Create a list of all partitions that are used in + * lvm or raid compilations. + */ + $list = array(); + foreach($this->parent->disks as $dname => $disk){ + if($disk['FAIdiskType'] != "disk"){ + if($disk['status'] == "delete") continue; + if($disk['FAIdiskType'] == "lvm"){ + foreach($disk['FAIlvmDevice'] as $partname){ + $list[preg_replace("/:.*$/","",$partname)][] = $disk; + } } - if(isset($this->partitions[($key+1)])){ - if(isset($this->deletePartitions[$key])){ - unset($this->deletePartitions[$key]); + foreach($disk['partitions'] as $partkey => $part){ + if($part['status'] == "delete") continue; + if($disk['FAIdiskType'] == "raid"){ + foreach(split(",",$part['FAIpartitionSize']) as $partname){ + $list[preg_replace("/:.*$/","",$partname)][] = $disk; + } } - $this->partitions[$key] = $this->partitions[($key+1)]; - $this->partitions[$key]['FAIpartitionNr'] = $key; - $this->partitions[$key]['status'] = "new"; } } } - $tmp= array(); - foreach($this->partitions as $part){ - $tmp[count($tmp)+1]=$part; + + /* Now that we've a list of all partition references, lets check if + * one of the partitions we are going to remove is still in use. + */ + if(isset($list[$this->partitions[$id]['cn']])){ + $used = array(); + foreach($list[$this->partitions[$id]['cn']] as $disk){ + $used[$disk['cn']] = $disk['cn']; + } + $used = implode(",",$used); + msg_dialog::display(_("Error"), + sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"), + $used), ERROR_DIALOG); + + }else{ + foreach($this->partitions as $key => $part){ + if($id == $key){ + $start = true; + } + if($start){ + if($this->partitions[$key]['status'] == "edited"){ + $this->deletePartitions[$key]= $this->partitions[$key]; + $this->deletePartitions[$key]['FAIpartitionNr']=$key; + unset($this->partitions[$key]); + }else{ + unset($this->partitions[$key]); + } + if(isset($this->partitions[($key+1)])){ + if(isset($this->deletePartitions[$key])){ + unset($this->deletePartitions[$key]); + } + $this->partitions[$key] = $this->partitions[($key+1)]; + $this->partitions[$key]['FAIpartitionNr'] = $key; + $this->partitions[$key]['status'] = "new"; + } + } + } + $tmp= array(); + foreach($this->partitions as $part){ + $tmp[count($tmp)+1]=$part; + } + $this->partitions = $tmp; } - $this->partitions = $tmp; }