Commit 4f1f5fec authored by Thom Cherryhomes's avatar Thom Cherryhomes

Fixes #2781 - Tighten up ZFS and make sure it's all working.

parent cfacc108
Pipeline #669 passed with stage
in 11 seconds
#!/bin/bash
. /usr/pluto/bin/SQL_Ops.sh
Device=$1
RaidDevice=$2
HARD_DRIVE_DEVICE_TEMPLATE=1850
BLOCK_DEVICE_ID=152
NO_DISK_ID=199
Q="SELECT IK_DeviceData FROM Device_DeviceData WHERE FK_Device = $Device and FK_DeviceData = $BLOCK_DEVICE_ID"
Disk=$(RunSQL "$Q")
Q="SELECT IK_DeviceData FROM Device_DeviceData WHERE FK_Device = $RaidDevice AND FK_DeviceData = $BLOCK_DEVICE_ID"
Raid=$(RunSQL "$Q")
zpool add $Raid spare $Disk
Q="SELECT IK_DeviceData FROM Device_DeviceData WHERE FK_Device = $RaidDevice and FK_DeviceData = $NO_DISK_ID"
noDisks=$(RunSQL "$Q")
noDisks=$(($noDisks+1))
Q="UPDATE Device_DeviceData SET IK_DeviceData = $noDisks WHERE FK_Device = $RaidDevice and FK_DeviceData = $NO_DISK_ID"
RunSQL "$Q"
......@@ -14,7 +14,13 @@ Disk=$(RunSQL "$Q")
Q="SELECT IK_DeviceData FROM Device_DeviceData WHERE FK_Device = $PoolDevice AND FK_DeviceData = $BLOCK_DEVICE_ID"
Pool=$(RunSQL "$Q")
parted -a optimal -s $R mklabel gpt
zpool add $Pool spare $Disk
zpool_err="$?"
if [[ $zpool_err == 1 ]]; then
zpool create $Pool spare $Disk
fi
Q="SELECT IK_DeviceData FROM Device_DeviceData WHERE FK_Device = $PoolDevice and FK_DeviceData = $NO_DISK_ID"
noDisks=$(RunSQL "$Q")
......
......@@ -4,7 +4,7 @@
function Log {
echo "$(date -R) $$ $*" >&2
echo "$(date -R) $$ $*" >> /var/log/pluto/CreateZFSPool.log
echo "$(date -R) $$ $*" >> /var/log/pluto/CreateZFSMirror.log
}
......@@ -22,11 +22,13 @@ if [[ "$3" != "demonized" ]] ;then
#if is new added get the list of active drives and spares
NewAdd=$(RunSQL "SELECT IK_DeviceData FROM Device_DeviceData WHERE FK_Device = $Device and FK_DeviceData = $NEW_ADD_ID")
if [[ $NewAdd == 0 ]] ;then
Log "Creating new RAID 0 on /dev/$name"
Log "Creating new ZFS Mirror on /dev/$name"
## Counting the number of spares and active diskes
## Creating a list with spares and active disks
ActiveDrives=
SpareDrives=
AddSpares=0
NrDrives=
HardDriveList=$(RunSQL "SELECT PK_Device FROM Device WHERE FK_DeviceTemplate = $HARD_DRIVE_DEVICE_TEMPLATE AND FK_Device_ControlledVia = $Device")
for Drive in $HardDriveList; do
......@@ -44,20 +46,35 @@ if [[ "$3" != "demonized" ]] ;then
R=$(RunSQL "$Q")
Disk=$(Field 1 "$R")
IsSpare=$(Field 2 "$R")
Log "Adding Active drive $Disk to $name"
ActiveDrives="$ActiveDrives "$Disk
NrDrives=$(($NrDrives+1))
if [[ $IsSpare == 1 ]]; then
Log "Adding Spare Disk $Disk to $name"
AddSpares=1
SpareDrives="$SpareDrives "$Disk
else
Log "Adding Active drive $Disk to $name"
ActiveDrives="$ActiveDrives "$Disk
fi
done
## Create the array with mdadm
Log "Using parted to create GPT disklabels"
for d in $ActiveDrives; do parted -a optimal -s $d mklabel gpt; done
if [[ $AddSpares == 1 ]]; then
for d in $SpareDrives; do parted -a optimal -s $d mklabel gpt; done
else
for d in $ActiveDrives; do parted -a optimal -s $d mklabel gpt; done
fi
Log "Using zpool to actually create the pool"
zpool create -m legacy "$name" mirror $ActiveDrives
zpool_err="$?"
Log "Process 'zpool create $name $ActiveDrives' exited with error $zpool_err"
if [[ $AddSpares == 1 ]]; then
zpool_err="$?"
Log "Process 'zpool create $name mirror $ActiveDrives' spare '$SpareDrives' exited with error $zpool_err"
zpool create -m legacy "$name" mirror $ActiveDrives spare $SpareDrives
else
zpool create -m legacy "$name" mirror $ActiveDrives
zpool_err="$?"
Log "Process 'zpool create $name mirror $ActiveDrives' exited with error $zpool_err"
fi
sleep 3
......@@ -77,6 +94,8 @@ if [[ "$3" != "demonized" ]] ;then
## Format the new raid
LogFile="/usr/pluto/var/${Device}_Raid.log"
echo "FORMAT,100" > $LogFile
sleep 5
rm $LogFile
fi
......@@ -28,7 +28,9 @@ if [[ "$3" != "demonized" ]] ;then
## Counting the number of spares and active diskes
## Creating a list with spares and active disks
ActiveDrives=
SpareDrives=
NrDrives=
AddSpares=0
HardDriveList=$(RunSQL "SELECT PK_Device FROM Device WHERE FK_DeviceTemplate = $HARD_DRIVE_DEVICE_TEMPLATE AND FK_Device_ControlledVia = $Device")
for Drive in $HardDriveList; do
......@@ -45,20 +47,37 @@ if [[ "$3" != "demonized" ]] ;then
R=$(RunSQL "$Q")
Disk=$(Field 1 "$R")
IsSpare=$(Field 2 "$R")
Log "Adding Active drive $Disk to $name"
ActiveDrives="$ActiveDrives "$Disk
if [[ $IsSpare == 1 ]]; then
Log "Adding Spare Disk $Disk to $name"
AddSpares=1
SpareDrives="$SpareDrives "$Disk
else
Log "Adding Active drive $Disk to $name"
ActiveDrives="$ActiveDrives "$Disk
fi
NrDrives=$(($NrDrives+1))
done
## Create the array with mdadm
Log "Using parted to create GPT disklabels"
for d in $ActiveDrives; do parted -a optimal -s $d mklabel gpt; done
if [[ $AddSpares == 1 ]]; then
for d in $SpareDrives; do parted -a optimal -s $d mklabel gpt; done
else
for d in $ActiveDrives; do parted -a optimal -s $d mklabel gpt; done
fi
Log "Using zpool to actually create the pool"
zpool create -m legacy "$name" $ActiveDrives
zpool_err="$?"
Log "Process 'zpool create $name $ActiveDrives' exited with error $zpool_err"
if [[ $AddSpares == 1 ]]; then
zpool_err="$?"
Log "Process 'zpool create $name $ActiveDrives' spare '$SpareDrives' exited with error $zpool_err"
zpool create -m legacy "$name" $ActiveDrives spare $SpareDrives
else
zpool create -m legacy "$name" $ActiveDrives
zpool_err="$?"
Log "Process 'zpool create $name $ActiveDrives' exited with error $zpool_err"
fi
sleep 3
......@@ -78,6 +97,8 @@ if [[ "$3" != "demonized" ]] ;then
## Format the new raid
LogFile="/usr/pluto/var/${Device}_Raid.log"
echo "FORMAT,100" > $LogFile
sleep 5
rm $LogFile
fi
......@@ -4,7 +4,7 @@
function Log {
echo "$(date -R) $$ $*" >&2
echo "$(date -R) $$ $*" >> /var/log/pluto/CreateZFSPool.log
echo "$(date -R) $$ $*" >> /var/log/pluto/CreateZFSRaidZ1.log
}
......@@ -28,9 +28,10 @@ if [[ "$3" != "demonized" ]] ;then
## Creating a list with spares and active disks
ActiveDrives=
NrDrives=
AddSpares=0
SpareDrives=
HardDriveList=$(RunSQL "SELECT PK_Device FROM Device WHERE FK_DeviceTemplate = $HARD_DRIVE_DEVICE_TEMPLATE AND FK_Device_ControlledVia = $Device")
for Drive in $HardDriveList; do
Q="
SELECT
Block.IK_DeviceData,
......@@ -44,20 +45,34 @@ if [[ "$3" != "demonized" ]] ;then
R=$(RunSQL "$Q")
Disk=$(Field 1 "$R")
IsSpare=$(Field 2 "$R")
Log "Adding Active drive $Disk to $name"
ActiveDrives="$ActiveDrives "$Disk
NrDrives=$(($NrDrives+1))
if [[ $IsSpare == 1 ]]; then
Log "Adding Spare Disk $Disk to $name"
AddSpares=1
SpareDrives="$SpareDrives "$Disk
else
Log "Adding Active drive $Disk to $name"
ActiveDrives="$ActiveDrives "$Disk
fi
done
## Create the array with mdadm
Log "Using parted to create GPT disklabels"
for d in $ActiveDrives; do parted -a optimal -s $d mklabel gpt; done
if [[ $AddSpares == 1 ]]; then
for d in $SpareDrives; do parted -a optimal -s $d mklabel gpt; done
else
for d in $ActiveDrives; do parted -a optimal -s $d mklabel gpt; done
fi
Log "Using zpool to actually create the pool"
zpool create -m legacy "$name" raidz1 $ActiveDrives
zpool_err="$?"
Log "Process 'zpool create $name $ActiveDrives' exited with error $zpool_err"
if [[ $AddSpares == 1 ]]; then
zpool_err="$?"
Log "Process 'zpool create $name raidz1 $ActiveDrives' spare '$SpareDrives' exited with error $zpool_err"
zpool create -m legacy "$name" raidz1 $ActiveDrives spare $SpareDrives
else
zpool create -m legacy "$name" raidz1 $ActiveDrives
zpool_err="$?"
Log "Process 'zpool create $name raidz1 $ActiveDrives' exited with error $zpool_err"
fi
sleep 3
......@@ -77,6 +92,8 @@ if [[ "$3" != "demonized" ]] ;then
## Format the new raid
LogFile="/usr/pluto/var/${Device}_Raid.log"
echo "FORMAT,100" > $LogFile
sleep 5
rm $LogFile
fi
......@@ -4,7 +4,7 @@
function Log {
echo "$(date -R) $$ $*" >&2
echo "$(date -R) $$ $*" >> /var/log/pluto/CreateZFSPool.log
echo "$(date -R) $$ $*" >> /var/log/pluto/CreateZFSRaidZ2.log
}
......@@ -28,9 +28,10 @@ if [[ "$3" != "demonized" ]] ;then
## Creating a list with spares and active disks
ActiveDrives=
NrDrives=
AddSpares=0
SpareDrives=
HardDriveList=$(RunSQL "SELECT PK_Device FROM Device WHERE FK_DeviceTemplate = $HARD_DRIVE_DEVICE_TEMPLATE AND FK_Device_ControlledVia = $Device")
for Drive in $HardDriveList; do
Q="
SELECT
Block.IK_DeviceData,
......@@ -44,20 +45,34 @@ if [[ "$3" != "demonized" ]] ;then
R=$(RunSQL "$Q")
Disk=$(Field 1 "$R")
IsSpare=$(Field 2 "$R")
Log "Adding Active drive $Disk to $name"
ActiveDrives="$ActiveDrives "$Disk
NrDrives=$(($NrDrives+1))
if [[ $IsSpare == 1 ]]; then
Log "Adding Spare Disk $Disk to $name"
AddSpares=1
SpareDrives="$SpareDrives "$Disk
else
Log "Adding Active drive $Disk to $name"
ActiveDrives="$ActiveDrives "$Disk
fi
done
## Create the array with mdadm
Log "Using parted to create GPT disklabels"
for d in $ActiveDrives; do parted -a optimal -s $d mklabel gpt; done
if [[ $AddSpares == 1 ]]; then
for d in $SpareDrives; do parted -a optimal -s $d mklabel gpt; done
else
for d in $ActiveDrives; do parted -a optimal -s $d mklabel gpt; done
fi
Log "Using zpool to actually create the pool"
zpool create -m legacy "$name" raidz2 $ActiveDrives
zpool_err="$?"
Log "Process 'zpool create $name $ActiveDrives' exited with error $zpool_err"
if [[ $AddSpares == 1 ]]; then
zpool_err="$?"
Log "Process 'zpool create $name raidz2 $ActiveDrives' spare '$SpareDrives' exited with error $zpool_err"
zpool create -m legacy "$name" raidz2 $ActiveDrives spare $SpareDrives
else
zpool create -m legacy "$name" raidz2 $ActiveDrives
zpool_err="$?"
Log "Process 'zpool create $name raidz2 $ActiveDrives' exited with error $zpool_err"
fi
sleep 3
......@@ -77,6 +92,8 @@ if [[ "$3" != "demonized" ]] ;then
## Format the new raid
LogFile="/usr/pluto/var/${Device}_Raid.log"
echo "FORMAT,100" > $LogFile
sleep 5
rm $LogFile
fi
......@@ -4,7 +4,7 @@
function Log {
echo "$(date -R) $$ $*" >&2
echo "$(date -R) $$ $*" >> /var/log/pluto/CreateZFSPool.log
echo "$(date -R) $$ $*" >> /var/log/pluto/CreateZFSRaidZ3.log
}
......@@ -28,9 +28,10 @@ if [[ "$3" != "demonized" ]] ;then
## Creating a list with spares and active disks
ActiveDrives=
NrDrives=
AddSpares=0
SpareDrives=
HardDriveList=$(RunSQL "SELECT PK_Device FROM Device WHERE FK_DeviceTemplate = $HARD_DRIVE_DEVICE_TEMPLATE AND FK_Device_ControlledVia = $Device")
for Drive in $HardDriveList; do
Q="
SELECT
Block.IK_DeviceData,
......@@ -44,20 +45,34 @@ if [[ "$3" != "demonized" ]] ;then
R=$(RunSQL "$Q")
Disk=$(Field 1 "$R")
IsSpare=$(Field 2 "$R")
Log "Adding Active drive $Disk to $name"
ActiveDrives="$ActiveDrives "$Disk
NrDrives=$(($NrDrives+1))
if [[ $IsSpare == 1 ]]; then
Log "Adding Spare Disk $Disk to $name"
AddSpares=1
SpareDrives="$SpareDrives "$Disk
else
Log "Adding Active drive $Disk to $name"
ActiveDrives="$ActiveDrives "$Disk
fi
done
## Create the array with mdadm
Log "Using parted to create GPT disklabels"
for d in $ActiveDrives; do parted -a optimal -s $d mklabel gpt; done
if [[ $AddSpares == 1 ]]; then
for d in $SpareDrives; do parted -a optimal -s $d mklabel gpt; done
else
for d in $ActiveDrives; do parted -a optimal -s $d mklabel gpt; done
fi
Log "Using zpool to actually create the pool"
zpool create -m legacy $name raidz3 $ActiveDrives
zpool_err="$?"
Log "Process 'zpool create "$name" $ActiveDrives' exited with error $zpool_err"
if [[ $AddSpares == 1 ]]; then
zpool_err="$?"
Log "Process 'zpool create $name raidz3 $ActiveDrives' spare '$SpareDrives' exited with error $zpool_err"
zpool create -m legacy "$name" raidz3 $ActiveDrives spare $SpareDrives
else
zpool create -m legacy "$name" raidz3 $ActiveDrives
zpool_err="$?"
Log "Process 'zpool create $name raidz3 $ActiveDrives' exited with error $zpool_err"
fi
sleep 3
......@@ -77,6 +92,8 @@ if [[ "$3" != "demonized" ]] ;then
## Format the new raid
LogFile="/usr/pluto/var/${Device}_Raid.log"
echo "FORMAT,100" > $LogFile
sleep 5
rm $LogFile
fi
......@@ -179,15 +179,8 @@ function raid($output,$dbADO) {
foreach ($raidDevices AS $device){
if(isset($_POST['delete_'.$device])){
$parentIP=$_REQUEST['parentIP_'.$device];
if ($_POST["template"] == $GLOBALS["ZFSPool"] || $_POST["template"] == $GLOBALS["ZFSMirror"] || $_POST["template"] == $GLOBALS["ZFSRaid1"] ||
$_POST["template"] == $GLOBALS["ZFSRaid2"] || $_POST["template"] == $GLOBALS["ZFSRaid3"])
{
$cmd='sudo -u root /usr/pluto/bin/LaunchRemoteCmd.sh '.$parentIP.' "/usr/pluto/bin/delete_ZFS.sh '.$device.'"';
}
else
{
$cmd='sudo -u root /usr/pluto/bin/LaunchRemoteCmd.sh '.$parentIP.' "/usr/pluto/bin/delete_raid.sh '.$device.'"';
}
$cmd='sudo -u root /usr/pluto/bin/LaunchRemoteCmd.sh '.$parentIP.' "/usr/pluto/bin/delete_raid.sh '.$device.'"';
$ret=exec_batch_command($cmd,1);
// delete moved in delete_raid.sh
......
......@@ -65,17 +65,8 @@ function raidDrives($output,$dbADO) {
if($RAIDStatus!=0){
// send sommand to update raid status
// /usr/pluto/bin/refresh_status_RAID.sh <DEVICE_ID>
if ($raidTemplate==$GLOBALS['ZFSPool'] || $raidTemplate==$GLOBALS['ZFSMirror'] || $raidTemplate==$GLOBALS['ZFSRaidZ1'] ||
$raidTemplate==$GLOBALS['ZFSRaidZ2'] || $raidTemplate==$GLOBALS['ZFSRaidZ3'])
{
$cmd='sudo -u root /usr/pluto/bin/refresh_status_ZFS.sh "'.$deviceID.'"';
}
else
{
$cmd='sudo -u root /usr/pluto/bin/refresh_status_RAID.sh "'.$deviceID.'"';
}
$cmd='sudo -u root /usr/pluto/bin/refresh_status_RAID.sh "'.$deviceID.'"';
$ret=exec_batch_command($cmd,1);
}
......@@ -286,15 +277,7 @@ function raidDrives($output,$dbADO) {
// if is spare and raid is created or in progress
if($spare==1){
if ($raidTemplate==$GLOBALS['ZFSPool'] || $raidTemplate==$GLOBALS['ZFSMirror'] || $raidTemplate==$GLOBALS['ZFSRaidZ1'] ||
$raidTemplate==$GLOBALS['ZFSRaidZ2'] || $raidTemplate==$GLOBALS['ZFSRaidZ3'])
{
$cmd='sudo -u root /usr/pluto/bin/LaunchRemoteCmd.sh '.$parentIP.' "/usr/pluto/bin/add_ZFS_spare.sh '.$newDrive.' '.$deviceID.'"';
}
else
{
$cmd='sudo -u root /usr/pluto/bin/LaunchRemoteCmd.sh '.$parentIP.' "/usr/pluto/bin/add_spare.sh '.$newDrive.' '.$deviceID.'"';
}
$cmd='sudo -u root /usr/pluto/bin/LaunchRemoteCmd.sh '.$parentIP.' "/usr/pluto/bin/add_spare.sh '.$newDrive.' '.$deviceID.'"';
exec_batch_command($cmd);
}
......@@ -305,17 +288,7 @@ function raidDrives($output,$dbADO) {
$raidDrives=explode(',',$_POST['raidDrives']);
foreach ($raidDrives AS $drive){
if(isset($_POST['delete_'.$drive])){
if ($raidTemplate==$GLOBALS['ZFSPool'] || $raidTemplate==$GLOBALS['ZFSMirror'] || $raidTemplate==$GLOBALS['ZFSRaidZ1'] ||
$raidTemplate==$GLOBALS['ZFSRaidZ2'] || $raidTemplate==$GLOBALS['ZFSRaidZ3'])
{
// Deletion of drives from ZFS pools are not permitted.
header("Location: index.php?section=raidDrives&deviceID=$deviceID&msg=".urlencode($TEXT_ZFS_DRIVE_DELETE_NOT_ALLOWED));
exit();
}
else
{
$cmd='sudo -u root /usr/pluto/bin/LaunchRemoteCmd.sh '.$parentIP.' "/usr/pluto/bin/delete_drive.sh 0 '.$deviceID.' '.$drive.'"';
}
$cmd='sudo -u root /usr/pluto/bin/LaunchRemoteCmd.sh '.$parentIP.' "/usr/pluto/bin/delete_drive.sh 0 '.$deviceID.' '.$drive.'"';
exec_batch_command($cmd);
deleteDevice($drive,$dbADO);
......@@ -326,15 +299,7 @@ function raidDrives($output,$dbADO) {
//get path for drive determined by id
$res =getFieldsAsArray('Device_DeviceData','IK_DeviceData',$dbADO,'WHERE FK_Device='.$drive);
if ($raidTemplate==$GLOBALS['ZFSPool'] || $raidTemplate==$GLOBALS['ZFSMirror'] || $raidTemplate==$GLOBALS['ZFSRaidZ1'] ||
$raidTemplate==$GLOBALS['ZFSRaidZ2'] || $raidTemplate==$GLOBALS['ZFSRaidZ3'])
{
$cmd='sudo -u root /usr/pluto/bin/add_ZFS_drive.sh '.$blockDevice.' '.$res['IK_DeviceData'][0];
}
else
{
$cmd='sudo -u root /usr/pluto/bin/add_drive.sh '.$blockDevice.' '.$res['IK_DeviceData'][0];
}
$cmd='sudo -u root /usr/pluto/bin/add_drive.sh '.$blockDevice.' '.$res['IK_DeviceData'][0];
$msg= exec_batch_command($cmd);
header("Location: index.php?section=raidDrives&deviceID=$deviceID&msg=".urlencode(@$msg));
exit();
......@@ -359,22 +324,7 @@ function raidDrives($output,$dbADO) {
break;
case $GLOBALS['Raid5']:
$cmd='/usr/pluto/bin/create_RAID5.sh';
break;
case $GLOBALS['ZFSPool']:
$cmd='/usr/pluto/bin/create_ZFSPool.sh';
break;
case $GLOBALS['ZFSMirror']:
$cmd='/usr/pluto/bin/create_ZFSMirror.sh';
break;
case $GLOBALS['ZFSRaidZ1']:
$cmd='/usr/pluto/bin/create_ZFSRaidZ1.sh';
break;
case $GLOBALS['ZFSRaidZ2']:
$cmd='/usr/pluto/bin/create_ZFSRaidZ2.sh';
break;
case $GLOBALS['ZFSRaidZ3']:
$cmd='/usr/pluto/bin/create_ZFSRaidZ3.sh';
break;
break;
}
$full_cmd='sudo -u root /usr/pluto/bin/LaunchRemoteCmd.sh '.$parentIP.' "'.$cmd.' '.$deviceID.'"';
......@@ -390,15 +340,7 @@ function raidDrives($output,$dbADO) {
exit();
}
if(isset($_POST['grow'])){
if($raidTemplate==$GLOBALS['ZFSPool'] || $raidTemplate==$GLOBALS['ZFSMirror'] || $raidTemplate==$GLOBALS['ZFSRaidZ1'] ||
$raidTemplate==$GLOBALS['ZFSRaidZ2'] || $raidTemplate==$GLOBALS['ZFSRaidZ3'])
{
$cmd = 'sudo -u root /usr/pluto/bin/grow_raid.sh '.$blockDevice.' '.$numSparesToGrow;
}
else
{
$cmd = 'sudo -u root /usr/pluto/bin/grow_raid.sh '.$blockDevice.' '.$numSparesToGrow;
}
$cmd = 'sudo -u root /usr/pluto/bin/grow_raid.sh '.$blockDevice.' '.$numSparesToGrow;
$res=exec_batch_command($cmd);
if($res){
header("Location: index.php?section=raidDrives&deviceID=$deviceID&error=".urlencode(@$res));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment