Skip to content

Commit ee238ef

Browse files
committed
chore: refactor file sysem check scripts again
fix: re-arrange raidz vdev selections and establish better defaults
1 parent ff34cbd commit ee238ef

File tree

3 files changed

+51
-76
lines changed

3 files changed

+51
-76
lines changed

emhttp/plugins/dynamix/DeviceInfo.page

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ function selectDiskFsWidthZFS(slots,init) {
317317
value: 1,
318318
text: _(sprintf('%s '+label,slots))
319319
}));
320-
if (selected_width == 0) selected_width = 1;
320+
selected_width = 1;
321321
} else if ($('#diskFsProfile').val() == 'mirror') {
322322
var width;
323323
for (width=2; width<=Math.min(slots,4); width++) {
@@ -336,17 +336,17 @@ function selectDiskFsWidthZFS(slots,init) {
336336
if ($('#diskFsProfile').val() == 'raidz1') min_width = 2;
337337
else if ($('#diskFsProfile').val() == 'raidz2') min_width = 3;
338338
else if ($('#diskFsProfile').val() == 'raidz3') min_width = 4;
339-
for (width=min_width; width<=slots; width++) {
339+
for (width=slots; width>=min_width; width--) {
340340
if ((slots % width) == 0) {
341341
var groups = slots / width;
342342
var label = (groups == 1) ? "vdev" : "vdevs";
343343
$('#diskFsWidth').append($('<option>', {
344344
value: width,
345345
text: _(sprintf('%s '+label+' of %s devices',groups,width)),
346346
}));
347-
if (selected_width == 0) selected_width = width;
348347
}
349348
}
349+
selected_width = slots;
350350
}
351351
$('#diskFsWidth').val(selected_width);
352352
}
@@ -565,7 +565,7 @@ function btrfsScrub(path) {
565565
}
566566
function btrfsCheck(path) {
567567
$.post('/webGui/include/FileSystemStatus.php',{cmd:'btrfs-check',path:path},function(data) {
568-
$('#btrfs-check').text(data);
568+
$('#btrfs-check').text(data.replace(/\0$/, ''));
569569
if (data.slice(-1)!='\0') {
570570
setTimeout(function(){btrfsCheck(path);},1000);
571571
} else {
@@ -615,7 +615,7 @@ function zfsExpansion(path) {
615615
}
616616
function reiserfsCheck(path) {
617617
$.post('/webGui/include/FileSystemStatus.php',{cmd:'reiserfs-check',path:path},function(data) {
618-
$('#reiserfs-check').text(data);
618+
$('#reiserfs-check').text(data.replace(/\0$/, ''));
619619
if (data.slice(-1)!='\0') {
620620
setTimeout(function(){reiserfsCheck(path);},1000);
621621
} else {
@@ -627,7 +627,7 @@ function reiserfsCheck(path) {
627627
}
628628
function xfsCheck(path) {
629629
$.post('/webGui/include/FileSystemStatus.php',{cmd:'xfs-check',path:path},function(data) {
630-
$('#xfs-check').text(data);
630+
$('#xfs-check').text(data.replace(/\0$/, ''));
631631
if (data.slice(-1)!='\0') {
632632
setTimeout(function(){xfsCheck(path);},1000);
633633
} else {
@@ -639,7 +639,7 @@ function xfsCheck(path) {
639639
}
640640
function extCheck(path) {
641641
$.post('/webGui/include/FileSystemStatus.php',{cmd:'ext-check',path:path},function(data) {
642-
$('#ext-check').text(data);
642+
$('#ext-check').text(data.replace(/\0$/, ''));
643643
if (data.slice(-1)!='\0') {
644644
setTimeout(function(){extCheck(path);},1000);
645645
} else {
@@ -651,7 +651,7 @@ function extCheck(path) {
651651
}
652652
function ntfsCheck(path) {
653653
$.post('/webGui/include/FileSystemStatus.php',{cmd:'ntfs-check',path:path},function(data) {
654-
$('#ntfs-check').text(data);
654+
$('#ntfs-check').text(data.replace(/\0$/, ''));
655655
if (data.slice(-1)!='\0') {
656656
setTimeout(function(){ntfsCheck(path);},1000);
657657
} else {
@@ -663,7 +663,7 @@ function ntfsCheck(path) {
663663
}
664664
function exfatCheck(path) {
665665
$.post('/webGui/include/FileSystemStatus.php',{cmd:'exfat-check',path:path},function(data) {
666-
$('#exfat-check').text(data);
666+
$('#exfat-check').text(data.replace(/\0$/, ''));
667667
if (data.slice(-1)!='\0') {
668668
setTimeout(function(){exfatCheck(path);},1000);
669669
} else {

emhttp/plugins/dynamix/include/FileSystemStatus.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ function zfs($data) {return "zfs-".strtok($data,' ');}
4444
case 'exfat-check':
4545
case 'reiserfs-check':
4646
$fs = explode('-',$cmd)[0];
47-
[$dev,$id] = array_pad(explode(' ',$path),2,'');
48-
exec("$docroot/webGui/scripts/{$fs}_check status $dev $id", $status, $retval);
47+
[$dev,$id] = array_pad(explode(' ',trim($path,"'")),2,'');
48+
passthru("$docroot/webGui/scripts/{$fs}_check status $dev $id", $retval);
4949
if ($retval != 9) echo "\0";
5050
}
5151
}

emhttp/plugins/dynamix/scripts/check.source

Lines changed: 40 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,65 @@
11
# source this file in "xxx_check" scripts
22
# variable FSCK should be set to the file sysem check program
33

4+
# $FSCK start <dev> <id> <options>
5+
# $FSCK status <dev> <id>
6+
# $FSCK cancel <dev> <id>
7+
48
# Exit codes:
5-
# 0 - No corruption detected or process not found.
9+
# 0 - No corruption detected
610
# N - refer to individual file system check programs
7-
# 8 - No check has been run yet.
11+
# 8 - No check has been run yet or previous check cancelled
812
# 9 - Process is still running.
913

10-
OUTDIR=/var/lib/check
11-
mkdir -p $OUTDIR
14+
DEV="$2"
15+
ID="$3"
16+
OPTIONS="$4"
17+
18+
START_CMD="$(basename $0) start $2 $3"
19+
OUTDIR="/var/lib/check"
20+
mkdir -p "$OUTDIR"
1221

1322
case "$1" in
1423
'start')
1524
# Start the process in the background and log output
16-
rm -f $OUTDIR/check.status.$3
17-
( $FSCK $4 $2 &> $OUTDIR/check.status.$3 ; echo $? > $OUTDIR/check.status.$3.exit )&
18-
pid=$!
19-
echo $pid > $OUTDIR/check.pid.$3
25+
rm -f "${OUTDIR}/check.status.${ID}"
26+
rm -f "${OUTDIR}/check.status.${ID}.exit"
27+
(
28+
$FSCK $OPTIONS $DEV &> "${OUTDIR}/check.status.${ID}"
29+
echo $? > "${OUTDIR}/check.status.${ID}.exit"
30+
31+
) </dev/null &>/dev/null &
2032
exit 0
2133
;;
2234

2335
'status')
24-
# Check if the process is still running
25-
if [ -f $OUTDIR/check.pid.$3 ]; then
26-
pid=$(cat $OUTDIR/check.pid.$3)
27-
if kill -0 $pid 2>/dev/null; then
28-
# Process is running, return status and exit code 9
29-
cat $OUTDIR/check.status.$3
30-
exit 9
31-
else
32-
# Process is not running, read the exit status if available
33-
if [ -f $OUTDIR/check.status.$3.exit ]; then
34-
exit_status=$(cat $OUTDIR/check.status.$3.exit)
35-
cat $OUTDIR/check.status.$3
36-
rm -f $OUTDIR/check.pid.$3
37-
if [[ $exit_status -eq 0 || $exit_status -eq 1 || $exit_status -eq 2 || $exit_status -eq 4 ]]; then
38-
exit $exit_status
39-
else
40-
exit 0
41-
fi
42-
else
43-
# Exit status file does not exist, but return status file if available
44-
if [ -f $OUTDIR/check.status.$3 ]; then
45-
cat $OUTDIR/check.status.$3
46-
fi
47-
exit 8
48-
fi
49-
fi
36+
# return status file if available
37+
if [[ -f "${OUTDIR}/check.status.${ID}" ]]; then
38+
cat "${OUTDIR}/check.status.${ID}"
5039
else
51-
# No PID file found, check for existing status
52-
if [ -f $OUTDIR/check.status.$3 ]; then
53-
cat $OUTDIR/check.status.$3
54-
# If no exit status file, assume process completed successfully
55-
if [ -f $OUTDIR/check.status.$3.exit ]; then
56-
exit_status=$(cat $OUTDIR/check.status.$3.exit)
57-
if [[ $exit_status -eq 0 || $exit_status -eq 1 || $exit_status -eq 2 || $exit_status -eq 4 ]]; then
58-
exit $exit_status
59-
else
60-
exit 0
61-
fi
62-
else
63-
exit 8
64-
fi
65-
else
66-
# No status file found
67-
echo "Not available"
68-
exit 8
40+
echo "Not available"
41+
fi
42+
# Check if the process is still running
43+
if pgrep -f "$START_CMD" &> /dev/null ; then
44+
# Process is running, return exit code 9
45+
exit 9
46+
fi
47+
# Process is not running, read the exit status if available
48+
if [[ -f "${OUTDIR}/check.status.${ID}.exit" ]]; then
49+
exit_status=$(cat "${OUTDIR}/check.status.${ID}.exit")
50+
if [[ $exit_status -lt 8 ]]; then
51+
exit $exit_status
6952
fi
7053
fi
54+
exit 8
7155
;;
7256

7357
'cancel')
74-
# Cancel the ntfsfix process
75-
if [ -f $OUTDIR/check.pid.$3 ]; then
76-
pid=$(cat $OUTDIR/check.pid.$3)
77-
kill $pid
78-
while kill -0 $pid 2>/dev/null; do
79-
sleep 1
80-
done
81-
echo -e "\nCancelled" >> $OUTDIR/check.status.$3
82-
rm -f $OUTDIR/check.pid.$3
83-
else
84-
echo "No process to cancel"
58+
# Cancel the process
59+
if pkill -f "$START_CMD" &> /dev/null ; then
60+
echo -e "\nCancelled" >> "${OUTDIR}/check.status.${ID}"
8561
fi
86-
87-
exit 0
62+
exit 8
8863
;;
8964

9065
*)

0 commit comments

Comments
 (0)