Commit 57a77f65 by Thom Cherryhomes

Merge branch 'Issue_2781' into 'master'

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

Closes #2781

See merge request !57
2 parents cfacc108 4f1f5fec
Pipeline #670 passed
in 5 seconds
......@@ -18,6 +18,11 @@ TPL_INTERNAL_DRIVE=1790
TPL_RAID_0=1854
TPL_RAID_1=1851
TPL_RAID_5=1849
TPL_ZFS_POOL=2351
TPL_ZFS_MIRROR=2352
TPL_ZFS_RAIDZ1=2353
TPL_ZFS_RAIDZ2=2354
TPL_ZFS_RAIDZ3=2355
TPL_MEDIA_PLUGIN=2
CMD_REFRESH_LIST_OF_ONLINE_DEVICES=831
......@@ -291,7 +296,7 @@ while : ;do
LEFT JOIN Device_DeviceData BlockDev ON BlockDev.FK_Device = Device.PK_Device AND BlockDev.FK_DeviceData = '$DD_BLOCK_DEV'
LEFT JOIN Device_DeviceData UUID ON UUID.FK_Device = Device.PK_Device AND UUID.FK_DeviceData = '$DD_UUID'
WHERE
FK_DeviceTemplate IN ($TPL_INTERNAL_DRIVE, $TPL_RAID_0, $TPL_RAID_1, $TPL_RAID_5)
FK_DeviceTemplate IN ($TPL_INTERNAL_DRIVE, $TPL_RAID_0, $TPL_RAID_1, $TPL_RAID_5, $TPL_ZFS_POOL, $TPL_ZFS_MIRROR, $TPL_ZFS_RAIDZ1, $TPL_ZFS_RAIDZ2, $TPL_ZFS_RAIDZ3)
"
InternalDriveList=$(RunCSQL "$Q")
......@@ -310,111 +315,176 @@ while : ;do
## If is a New Raid with no UUID associated (UUID="") or a Internal Drive in the old format (UUID="NULL" or UUID="")
## then we translate the block device to uuid
if [[ "$IDrive_Parent" == "$PK_Device" ]] ;then
if [[ "$IDrive_UUID" == "" || "$IDrive_UUID" == "NULL" ]] && [[ "$IDrive_BlockDev" != "NULL" ]] ;then
IDrive_UUID=$(udevadm info --query=all --name="$IDrive_BlockDev" | grep 'ID_FS_UUID=' | cut -d'=' -f2)
if [[ "$IDrive_UUID" != "" ]] ;then
if [[ "$IDrive_DeviceTemplate" == "$TPL_ZFS_POOL" ]] || [[ "$IDrive_DeviceTemplate" == "$TPL_ZFS_MIRROR" ]] || [[ "$IDrive_DeviceTemplate" == "$TPL_ZFS_RAIDZ1" ]] || [[ "$IDrive_DeviceTemplate" == "$TPL_ZFS_RAIDZ2" ]] || [[ "$IDrive_DeviceTemplate" == "$TPL_ZFS_RAIDZ3" ]]; then
if [[ "$IDrive_UUID" == "" || "$IDrive_UUID" == "NULL" ]] && [[ "$IDrive_BlockDev" != "NULL" ]] ;then
IDrive_UUID=$(zfs get -H guid testz3 | cut -f3)
if [[ "$IDrive_UUID" != "" ]] ;then
RunSQL "UPDATE Device_DeviceData SET IK_DeviceData = '$IDrive_UUID' WHERE FK_Device = '$IDrive_ID' AND FK_DeviceData = '$DD_UUID'"
else
else
echo "Can't find the ZFS uuid of device $IDrive_ID"
continue
fi
fi
else
if [[ "$IDrive_UUID" == "" || "$IDrive_UUID" == "NULL" ]] && [[ "$IDrive_BlockDev" != "NULL" ]] ;then
IDrive_UUID=$(udevadm info --query=all --name="$IDrive_BlockDev" | grep 'ID_FS_UUID=' | cut -d'=' -f2)
if [[ "$IDrive_UUID" != "" ]] ;then
RunSQL "UPDATE Device_DeviceData SET IK_DeviceData = '$IDrive_UUID' WHERE FK_Device = '$IDrive_ID' AND FK_DeviceData = '$DD_UUID'"
else
echo "Can't find the uuid of device $IDrive_ID"
continue
fi
fi
fi
fi
fi
if [[ "$IDrive_DeviceTemplate" == "$TPL_ZFS_POOL" ]] || [[ "$IDrive_DeviceTemplate" == "$TPL_ZFS_MIRROR" ]] || [[ "$IDrive_DeviceTemplate" == "$TPL_ZFS_RAIDZ1" ]] || [[ "$IDrive_DeviceTemplate" == "$TPL_ZFS_RAIDZ2" ]] || [[ "$IDrive_DeviceTemplate" == "$TPL_ZFS_RAIDZ3" ]]; then
if [[ "$IDrive_Parent" == "$PK_Device" ]]; then
PoolStatus=$(zpool get -H health $IDrive_BlockDev | cut -f3)
if [[ "$PoolStatus" == "ONLINE" ]] || [[ "$poolStatus" == "DEGRADED" ]]; then
SetDeviceOnline "$IDrive_ID" "1"
else
SetDeviceOnline "$IDrive_ID" "0"
fi
elif [[ "$PK_Device" -eq "1" ]]; then
## It's a remote device.
## Get the ip of the parent device
IDrive_IP=$(RunCSQL "SELECT IPaddress FROM Device WHERE PK_Device='${IDrive_Parent}'")
IDrive_IP=$(Field "1" "$IDrive_IP")
## Test to see if the parent is online or not
ping -qnc 1 -W 1 "$IDrive_IP" &> /dev/null
HostIsUp=$?
if [[ "$HostIsUp" != "0" ]] ;then
SetKidsOnline "$IDrive_Parent" "0"
Log "Device $IDrive_Parent ($IDrive_IP) doesn't respond to our ping."
continue
fi
## Test if the share is still in the list
smbclient -A /usr/pluto/var/sambaCredentials.secret --list=//$IDrive_IP --grepable 2>/dev/null | grep "^Disk" | cut -d'|' -f2 | grep -q "^Storage$IDrive_ID\$$"
isShareInList=$?
if [[ "$isShareInList" != "0" ]] ;then
Log "Drive $IDrive_ID ($IDrive_UUID) is not advertised by it's parent smb server ($IDrive_IP)"
SetDeviceOnline "$IDrive_ID" "0"
continue
fi
## Test if the share is still mountable with the username/password that we have
smbclient -A /usr/pluto/var/sambaCredentials.secret "//$IDrive_IP/Storage$IDrive_ID\$" -c 'pwd' 1>/dev/null 2>/dev/null
isShareMountable=$?
if [[ "$isShareMountable" != "0" ]] ;then
Msg="Drive $IDrive_ID ($IDrive_IP $IDrive_UUID) cannot be mounted"
Log "$Msg"
SetDeviceOnline "$IDrive_ID" "0"
continue
fi
SetDeviceOnline "$IDrive_ID" "1"
fi
else
## Is one of our internal drives
if [[ "$IDrive_Parent" == "$PK_Device" ]] ; then
if [[ "$IDrive_Parent" == "$PK_Device" ]] ; then
if [[ "$IDrive_DeviceTemplate" == "$TPL_INTERNAL_DRIVE" ]] ; then
## See if a device with that UUID can be found in udev
## Find the drive
if [[ ! -e "/dev/disk/by-uuid/$IDrive_UUID" ]] ; then
Log "Cannot find disk $IDrive_ID with uuid=$IDrive_UUID"
# as in the StorageDevices_Radar.sh script, fall back to serial number and storage_device
if [[ ! -e "/dev/disk/by-id/$IDrive_UUID" ]] ; then
Log "Cannot find disk $IDrive_ID with id = $IDrive_UUID either"
if [[ ! -e "/dev/disk/by-label/$IDrive_UUID" ]] ; then
Log "Cannot find disk $IDrive_ID with label = $IDrive_UUID either, aborting!"
SetDeviceOnline "$IDrive_ID" "0"
continue
fi
fi
fi
## See if we have a block device associated with that UUID
IDrive_BlockDev=$(blkid -U "$IDrive_UUID")
if [[ "$IDrive_BlockDev" == "" ]] ;then
Log "Drive $IDrive_ID ($IDrive_UUID) doesn't have a block device associated"
## See if a device with that UUID can be found in udev
## Find the drive
if [[ ! -e "/dev/disk/by-uuid/$IDrive_UUID" ]] ; then
Log "Cannot find disk $IDrive_ID with uuid=$IDrive_UUID"
# as in the StorageDevices_Radar.sh script, fall back to serial number and storage_device
if [[ ! -e "/dev/disk/by-id/$IDrive_UUID" ]] ; then
Log "Cannot find disk $IDrive_ID with id = $IDrive_UUID either"
if [[ ! -e "/dev/disk/by-label/$IDrive_UUID" ]] ; then
Log "Cannot find disk $IDrive_ID with label = $IDrive_UUID either, aborting!"
SetDeviceOnline "$IDrive_ID" "0"
continue
fi
fi
fi
## See if we have a block device associated with that UUID
IDrive_BlockDev=$(blkid -U "$IDrive_UUID")
if [[ "$IDrive_BlockDev" == "" ]] ;then
Log "Drive $IDrive_ID ($IDrive_UUID) doesn't have a block device associated"
SetDeviceOnline "$IDrive_ID" "0"
fi
fi
## See if is still available in /proc/partitions
cat /proc/partitions | grep -q "${IDrive_BlockDev##/dev/}$"
isDriveAvailable=$?
if [[ "$isDriveAvailable" != "0" ]] ;then
Log "Drive $IDrive_ID ($IDrive_UUID) that's associated with $IDrive_BlockDev cannot be found in /proc/partitions"
SetDeviceOnline "$IDrive_ID" "0"
continue
Log "Drive $IDrive_ID ($IDrive_UUID) that's associated with $IDrive_BlockDev cannot be found in /proc/partitions"
SetDeviceOnline "$IDrive_ID" "0"
continue
fi
## See if the drive is mountable
mountDirTemp=$(mktemp -d /tmp/StorageDevices_StatusRadar.temp.mount.XXXXXXXXX)
mount ${IDrive_BlockDev} $mountDirTemp 1>/dev/null 2>/dev/null
isDriveMountable=$?
if [[ "$isDriveMountable" != "0" ]] ;then
Log "Drive $IDrive_ID ($IDrive_UUID) that's associated with $IDrive_BlockDev cannot be mounted"
SetDeviceOnline "$IDrive_ID" "0"
rmdir $mountDirTemp
continue
Log "Drive $IDrive_ID ($IDrive_UUID) that's associated with $IDrive_BlockDev cannot be mounted"
SetDeviceOnline "$IDrive_ID" "0"
rmdir $mountDirTemp
continue
else
umount -lf $mountDirTemp 1>/dev/null 2>/dev/null
rmdir $mountDirTemp
umount -lf $mountDirTemp 1>/dev/null 2>/dev/null
rmdir $mountDirTemp
fi
SetDeviceOnline "$IDrive_ID" "1"
## Is a internal drive located on a remote computer
elif [[ "$PK_Device" -eq "1" ]]; then
## Is a internal drive located on a remote computer
elif [[ "$PK_Device" -eq "1" ]]; then
## Get the ip of the parent device
IDrive_IP=$(RunCSQL "SELECT IPaddress FROM Device WHERE PK_Device='${IDrive_Parent}'")
IDrive_IP=$(Field "1" "$IDrive_IP")
## Test to see if the parent is online or not
ping -qnc 1 -W 1 "$IDrive_IP" &> /dev/null
HostIsUp=$?
if [[ "$HostIsUp" != "0" ]] ;then
SetKidsOnline "$IDrive_Parent" "0"
Log "Device $IDrive_Parent ($IDrive_IP) doesn't respond to our ping."
continue
SetKidsOnline "$IDrive_Parent" "0"
Log "Device $IDrive_Parent ($IDrive_IP) doesn't respond to our ping."
continue
fi
## Test if the share is still in the list
smbclient -A /usr/pluto/var/sambaCredentials.secret --list=//$IDrive_IP --grepable 2>/dev/null | grep "^Disk" | cut -d'|' -f2 | grep -q "^Storage$IDrive_ID\$$"
isShareInList=$?
if [[ "$isShareInList" != "0" ]] ;then
Log "Drive $IDrive_ID ($IDrive_UUID) is not advertised by it's parent smb server ($IDrive_IP)"
SetDeviceOnline "$IDrive_ID" "0"
continue
Log "Drive $IDrive_ID ($IDrive_UUID) is not advertised by it's parent smb server ($IDrive_IP)"
SetDeviceOnline "$IDrive_ID" "0"
continue
fi
## Test if the share is still mountable with the username/password that we have
smbclient -A /usr/pluto/var/sambaCredentials.secret "//$IDrive_IP/Storage$IDrive_ID\$" -c 'pwd' 1>/dev/null 2>/dev/null
isShareMountable=$?
if [[ "$isShareMountable" != "0" ]] ;then
Msg="Drive $IDrive_ID ($IDrive_IP $IDrive_UUID) cannot be mounted"
Log "$Msg"
SetDeviceOnline "$IDrive_ID" "0"
continue
Msg="Drive $IDrive_ID ($IDrive_IP $IDrive_UUID) cannot be mounted"
Log "$Msg"
SetDeviceOnline "$IDrive_ID" "0"
continue
fi
SetDeviceOnline "$IDrive_ID" "1"
fi
fi
done
sleep 5
......
#!/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
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!