Merge pull request #1754 from dlandon/master

Add more info to btrfs pools and more user friendly xfs repairs.
This commit is contained in:
tom mortensen
2024-06-06 10:42:13 -07:00
committed by GitHub
3 changed files with 207 additions and 45 deletions

View File

@@ -756,14 +756,30 @@ _(Critical disk utilization threshold)_ (%):
</form>
<?if (fsType('btrfs')):?>
<?if (!maintenance_mode()):?>
<div class="title nocontrol"><span class="left"><i class="title fa fa-hdd-o"></i>_(Pool Device Status)_</span></div>
<form markdown="1" method="POST" action="/update.php" target="progressFrame">
_(pool device stats)_:
: <?echo "<pre>".shell_exec("/sbin/btrfs dev stats -T /mnt/$tag")."</pre>"?>
<input type="hidden" name="#command" value="/webGui/scripts/btrfs_check">
<input type="hidden" name="#arg[1]" value="reset">
<input type="hidden" name="#arg[2]" value="/mnt/<?=$tag?>">
&nbsp;
: <input type="submit" value="_(Reset)_">
</form>
<?endif;?>
<div class="title nocontrol"><span class="left"><i class="title fa fa-balance-scale"></i>_(Balance Status)_</span></div>
<form markdown="1" method="POST" action="/update.php" target="progressFrame" onsubmit="prepareFS(this,'btrfs-balance-<?=$tag?>','/mnt/<?=$tag?>')">
<?if (_var($disk,'fsStatus')=="Mounted"):?>
<?exec("$docroot/webGui/scripts/btrfs_balance status /mnt/$tag", $balance_status, $retval)?>
<?$usage = exec("/sbin/btrfs fi usage /mnt/$tag|grep -Pom1 '^Data,.+ \\(\\K[^%]+'");?>
_(btrfs filesystem df)_:
: <?echo "<pre>".shell_exec("/sbin/btrfs filesystem df /mnt/$tag")."</pre>"?>
_(btrfs filesystem usage)_:
: <?echo "<pre>".shell_exec("/sbin/btrfs fi usage -T /mnt/$tag")."</pre>"?>
_(btrfs balance status)_:
: <?echo "<pre id='btrfs-balance'>".implode("\n", $balance_status)."</pre>"?>
@@ -803,7 +819,7 @@ _(btrfs balance status)_:
<input type="hidden" name="#arg[2]" value="/mnt/<?=$tag?>">
&nbsp;
: <input type="submit" value="_(Cancel)_">
: <input type="submit" value="_(Cancel)_"> *_(Running)_*
:info_balance_cancel_help:
@@ -811,7 +827,7 @@ _(btrfs balance status)_:
<?else:?>
&nbsp;
: <input type="submit" value="_(Balance)_" disabled><?=$tag==prefix($tag) ? "<b>"._('Balance')."</b> "._('is only available when array is Started') : sprintf(_('See %s Settings'),ucfirst(prefix($tag)))?>
: <input type="submit" value="_(Balance)_" disabled><b>_(Balance)_</b> _(is only available when the filesyestem is mounted)_
<?endif;?>
</form>
@@ -885,10 +901,10 @@ _(btrfs scrub status)_:
<input type="hidden" name="#command" value="/webGui/scripts/btrfs_scrub">
<input type="hidden" name="#arg[1]" value="start">
<input type="hidden" name="#arg[2]" value="/mnt/<?=$tag?>">
<input type="hidden" name="#arg[3]" value="-r">
<input type="hidden" name="#arg[3]" value="">
&nbsp;
: <input type="submit" value="_(Scrub)_"><label><input type="checkbox" name="#arg[3]" value=""> _(Repair corrupted blocks)_</label>
: <input type="submit" value="_(Scrub)_">
:info_btrfs_scrub_help:
@@ -898,7 +914,7 @@ _(btrfs scrub status)_:
<input type="hidden" name="#arg[2]" value="/mnt/<?=$tag?>">
&nbsp;
: <input type="submit" value="_(Cancel)_">
: <input type="submit" value="_(Cancel)_"> *_(Running)_*
:info_scrub_cancel_help:
@@ -906,7 +922,7 @@ _(btrfs scrub status)_:
<?else:?>
&nbsp;
: <input type="submit" value="_(Scrub)_" disabled><?=$tag==prefix($tag) ? "<b>"._('Scrub')."</b> "._('is only available when array is Started') : sprintf(_('See %s Settings'),ucfirst(prefix($tag)))?>
: <input type="submit" value="_(Scrub)_" disabled><b>_(Scrub)_</b> _(is only available when the filesyestem is mounted)_
<?endif;?>
</form>
@@ -973,7 +989,7 @@ _(Time of the day)_:
_(btrfs check status)_:
: <?echo "<pre id='btrfs-check'>".implode("\n", $check_status)."</pre>"?>
<?if ($retval != 0):?>
<?if ($retval == 0):?>
<input type="hidden" name="#command" value="/webGui/scripts/btrfs_check">
<input type="hidden" name="#arg[1]" value="start">
<input type="hidden" name="#arg[2]" value="/dev/<?=_var($disk,'deviceSb')?>">
@@ -998,15 +1014,9 @@ _(btrfs check status)_:
<?endif;?>
<?else:?>
<?if ($tag==prefix($tag)):?>
&nbsp;
: <input type="submit" value="_(Check)_" disabled> **_(Check)_** _(is only available when array is Started in **Maintenance** mode)_.
<?else:?>
&nbsp;
: <input type="submit" value="_(Check)_" disabled> <?=sprintf(_('See %s Settings'),ucfirst(prefix($tag)))?>.
<?endif;?>
<?endif;?>
</form>
<?endif;?>
@@ -1036,7 +1046,7 @@ _(zfs pool status)_:
<input type="hidden" name="#arg[2]" value="<?=$tag?>">
&nbsp;
: <input type="submit" value="_(Cancel)_">
: <input type="submit" value="_(Cancel)_"> *_(Running)_*
:info_scrub_cancel_help:
@@ -1044,7 +1054,7 @@ _(zfs pool status)_:
<?else:?>
&nbsp;
: <input type="submit" value="_(Scrub)_" disabled><?=$tag==prefix($tag) ? "<b>"._('Scrub')."</b> "._('is only available when array is Started') : sprintf(_('See %s Settings'),ucfirst(prefix($tag)))?>
: <input type="submit" value="_(Scrub)_" disabled><?=!$tag||$tag==prefix($tag) ? "<b>"._('Scrub')."</b> "._('is only available when the filesyestem is mounted') : sprintf(_('See %s Settings'),ucfirst(prefix($tag)))?>
<?endif;?>
</form>
@@ -1152,18 +1162,57 @@ _(reiserfsck status)_:
_(xfs_repair status)_:
: <?echo "<pre id='xfs-check'>".implode("\n", $check_status)."</pre>"?>
<?if ($retval != 0):?>
<?if ($retval == 0 || $retval == 8):?>
<input type="hidden" name="#command" value="/webGui/scripts/xfs_check">
<input type="hidden" name="#arg[1]" value="start">
<input type="hidden" name="#arg[2]" value="/dev/<?=_var($disk,'deviceSb')?>">
<input type="hidden" name="#arg[3]" value="<?=_var($disk,'id')?>">
<input type="hidden" name="#arg[4]" value="-n">
&nbsp;
: <input type="submit" value="_(Check)_"><input type="text" name="#arg[4]" class="narrow" maxlength="256" value="-n"> _(Options (see Help))_
: <input type="submit" value="_(Check)_"><?if ($retval == 0): ?> _(No file system corruption detected)_.<?endif; ?>
:info_xfs_check_help:
<?else:?>
<?elseif ($retval == 1):?>
<input type="hidden" name="#command" value="/webGui/scripts/xfs_check">
<input type="hidden" name="#arg[1]" value="start">
<input type="hidden" name="#arg[2]" value="/dev/<?=_var($disk,'deviceSb')?>">
<input type="hidden" name="#arg[3]" value="<?=_var($disk,'id')?>">
<input type="hidden" name="#arg[4]" value="-e">
&nbsp;
: <input type="submit" value="_(Fix)_"><span style="color: red;">_(File system corruption detected)_.</span>
:info_xfs_check_help:
<?elseif ($retval == 2):?>
<input type="hidden" name="#command" value="/webGui/scripts/xfs_check">
<input type="hidden" name="#arg[1]" value="start">
<input type="hidden" name="#arg[2]" value="/dev/<?=_var($disk,'deviceSb')?>">
<input type="hidden" name="#arg[3]" value="<?=_var($disk,'id')?>">
<input type="hidden" name="#arg[4]" value="-eL">
&nbsp;
: <input type="submit" value="_(Zero Log)_"><span style="color: red;">_(Dirty log detected)_.</span>
<p>_(Note)_: _(While there is some risk, if it is not possible to first mount the filesystem to clear the log, zeroing it is the only option to try and repair the filesystem, and in most cases it results in little or no data loss)_.</p>
:info_xfs_check_help:
<?elseif ($retval == 4):?>
<input type="hidden" name="#command" value="/webGui/scripts/xfs_check">
<input type="hidden" name="#arg[1]" value="start">
<input type="hidden" name="#arg[2]" value="/dev/<?=_var($disk,'deviceSb')?>">
<input type="hidden" name="#arg[3]" value="<?=_var($disk,'id')?>">
<input type="hidden" name="#arg[4]" value="-n">
&nbsp;
: <input type="submit" value="_(Check)_">_(File system corruption fixed)_
:info_xfs_check_help:
<?elseif ($retval == 9):?>
<input type="hidden" name="#command" value="/webGui/scripts/xfs_check">
<input type="hidden" name="#arg[1]" value="cancel">
<input type="hidden" name="#arg[2]" value="/dev/<?=_var($disk,'deviceSb')?>">

View File

@@ -1,28 +1,64 @@
#!/bin/bash
# btrfs_check start <dev> <id> <options>
# btrfs_check start <dev> <id> <options>
# btrfs_check status <dev> <id>
# btrfs_check cancel <dev> <id>
# btrfs_check reset <mountpoint>
# by default btrfs-check outputs to /var/lib/btrfs
# By default btrfs-check outputs to /var/lib/btrfs
mkdir -p /var/lib/btrfs
case "$1" in
'start')
exec /sbin/btrfs check $4 $2 &> /var/lib/btrfs/check.status.$3 &
# Start the btrfs check process in the background and log output
/sbin/btrfs check $4 $2 &> /var/lib/btrfs/check.status.$3 &
pid=$!
echo $pid > /var/lib/btrfs/check.pid.$3
exit 0
;;
'status')
if [ -f /var/lib/btrfs/check.status.$3 ]; then
cat /var/lib/btrfs/check.status.$3
else
echo "Not available"
fi;
# establish retval of this script: 0 running, 1 not running
pgrep -f "/sbin/btrfs check .*$2" >/dev/null
# Check if the process is running and set the return value accordingly
if [ -f /var/lib/btrfs/check.pid.$3 ]; then
cat /var/lib/btrfs/check.status.$3
pid=$(cat /var/lib/btrfs/check.pid.$3)
if kill -0 $pid 2>/dev/null; then
# Process is running
exit 9
else
if [ -f /var/lib/btrfs/check.status.$3 ]; then
rm -f /var/lib/btrfs/check.pid.$3
fi
fi
else
if [ -f /var/lib/btrfs/check.status.$3 ]; then
cat /var/lib/btrfs/check.status.$3
else
echo "Not available"
fi
fi
exit 0
;;
'cancel')
pkill -f "/sbin/btrfs_check.*$2"
while pgrep -f "/sbin/btrfs check .*$2" >/dev/null ; do
sleep 1
done
echo "Cancelled" >> /var/lib/btrfs/check.status.$3
# Cancel the btrfs check process
if [ -f /var/lib/btrfs/check.pid.$3 ]; then
pid=$(cat /var/lib/btrfs/check.pid.$3)
kill $pid
while kill -0 $pid 2>/dev/null; do
sleep 1
done
echo -e "\nCancelled" >> /var/lib/btrfs/check.status.$3
rm -f /var/lib/btrfs/check.pid.$3
else
echo "No process to cancel"
fi
exit 0
;;
'reset')
exec /sbin/btrfs device stats -z $2
;;
*)
echo "Invalid command"
exit 0
;;
esac

View File

@@ -1,23 +1,100 @@
#!/bin/bash
# xfs_check start <dev> <id> <options>
# xfs_check status <dev> <id>
# xfs_check cancel <dev>
# xfs_check cancel <dev>
# xfs_check zero_log <dev>
# using /var/lib because that's where btrfs puts status
# Exit codes:
# 0 - No corruption detected or process not found.
# 1 - Corruption detected.
# 2 - Dirty log.
# 4 - File system corruption fixed.
# 8 - No check has been run yet.
# 9 - Process is still running.
# Using /var/lib because that's where btrfs puts status
mkdir -p /var/lib/xfs
case "$1" in
'start')
exec /sbin/xfs_repair $4 $2 &> /var/lib/xfs/check.status.$3 &
# Start the xfs_repair process in the background and log output
nohup bash -c "(
/sbin/xfs_repair $4 $2 &> /var/lib/xfs/check.status.$3
echo \$? > /var/lib/xfs/check.status.$3.exit
rm -f /var/lib/xfs/check.pid.$3
) &" &
pid=$!
echo $pid > /var/lib/xfs/check.pid.$3
exit 0
;;
'status')
if [ -f /var/lib/xfs/check.status.$3 ]; then
cat /var/lib/xfs/check.status.$3
else
echo "Not available"
fi;
pgrep -f "/sbin/xfs_repair.*$2" >/dev/null
# Check if the process is still running
if [ -f /var/lib/xfs/check.pid.$3 ]; then
pid=$(cat /var/lib/xfs/check.pid.$3)
if kill -0 $pid 2>/dev/null; then
# Process is running, return status and exit code 9
cat /var/lib/xfs/check.status.$3
exit 9
else
# Process is not running, read the exit status if available
if [ -f /var/lib/xfs/check.status.$3.exit ]; then
exit_status=$(cat /var/lib/xfs/check.status.$3.exit)
cat /var/lib/xfs/check.status.$3
rm -f /var/lib/xfs/check.pid.$3
if [[ $exit_status -eq 0 || $exit_status -eq 1 || $exit_status -eq 2 || $exit_status -eq 4 ]]; then
exit $exit_status
else
exit 0
fi
else
# Exit status file does not exist, but return status file if available
if [ -f /var/lib/xfs/check.status.$3 ]; then
cat /var/lib/xfs/check.status.$3
fi
exit 8
fi
fi
else
# No PID file found, check for existing status
if [ -f /var/lib/xfs/check.status.$3 ]; then
cat /var/lib/xfs/check.status.$3
# If no exit status file, assume process completed successfully
if [ -f /var/lib/xfs/check.status.$3.exit ]; then
exit_status=$(cat /var/lib/xfs/check.status.$3.exit)
if [[ $exit_status -eq 0 || $exit_status -eq 1 || $exit_status -eq 2 || $exit_status -eq 4 ]]; then
exit $exit_status
else
exit 0
fi
else
exit 8
fi
else
# No status file found
echo "Not available"
exit 8
fi
fi
;;
'cancel')
pkill -f "/sbin/xfs_repair.*$2"
# Cancel the xfs_repair process
if [ -f /var/lib/xfs/check.pid.$3 ]; then
pid=$(cat /var/lib/xfs/check.pid.$3)
kill $pid
while kill -0 $pid 2>/dev/null; do
sleep 1
done
echo -e "\nCancelled" >> /var/lib/xfs/check.status.$3
rm -f /var/lib/xfs/check.pid.$3
else
echo "No process to cancel"
fi
exit 0
;;
*)
# Handle invalid commands
echo "Invalid command"
exit 0
;;
esac