-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait AC Power #45
base: master
Are you sure you want to change the base?
Wait AC Power #45
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,3 +76,38 @@ is_btrfs() { | |
[ "$FS" == "btrfs" ] && return 0 | ||
return 1 | ||
} | ||
|
||
# function: check_power_status | ||
# parameter: paths to check the status | ||
# | ||
# Return true if at least one path is online | ||
check_power_status() { | ||
local status=$(cat "$@" 2>/dev/null) | ||
[ -z "$status" ] && return 0 | ||
case "$status" in | ||
*1*) | ||
return 0 | ||
;; | ||
*) | ||
return 1 | ||
;; | ||
esac | ||
} | ||
|
||
# function: wait_ac_power | ||
# parameter: {timeout} {AC power online device} | ||
# | ||
# wait until ac power goes online | ||
wait_ac_power() { | ||
local timecount=0 | ||
local timeout=$1 | ||
|
||
while ! check_power_status "$@"; do | ||
# AC is not online | ||
[ $timeout -gt 0 ] && [ $timecount -ge $timeout ] && return 1 | ||
sleep 30s | ||
timecount=$((timecount+1)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If my math is correct, this will wait the 30 times more than the config value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was 1s but i changed just before to commit ("1s is too short" I said). |
||
done | ||
|
||
return 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,20 @@ | |
# 'btrfs-scrub' etc. | ||
BTRFS_LOG_OUTPUT="stdout" | ||
|
||
## Path: System/File systems/btrfs | ||
## Type: number | ||
## Default: 3600 | ||
# | ||
# Second to wait the AC Power before to continue anyway | ||
BTRFS_AC_POWER_TIMEOUT=3600 | ||
|
||
## Path: System/File systems/btrfs | ||
## Type: string | ||
## Default: "/sys/class/power_supply/*/online" | ||
# | ||
# Path of AC status flag | ||
BTRFS_AC_POWER_DEVICE="/sys/class/power_supply/*/online" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it will do the trick for laptops. I mentioned upower in another comment, because I think that /sys/class/power_supply/*/online will return true even when a server is on UPS battery. (eg: NUT or apcupsd). IIRC it provides a generic interface, and alternatives are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to revisit that later, with support for UPS, but for now I'm fine with the more relaxed check. Meanwhile I verified the path exists on my other systems, so I think there's nothing more left to discuss. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had no time to dedicate to search a portable solution yet. @sten0, can you provide some example of upower, upsmon, apsacces (with outputs). I have a very basic system (my home NAS) and I cannot checks all these tools. |
||
|
||
## Path: System/File systems/btrfs | ||
## Type: string | ||
## Default: "" | ||
|
@@ -31,6 +45,14 @@ BTRFS_DEFRAG_PERIOD="none" | |
# Minimal file size to consider for defragmentation | ||
BTRFS_DEFRAG_MIN_SIZE="+1M" | ||
|
||
## Path: System/File systems/btrfs | ||
## Type: boolean | ||
## Default: "false" | ||
# | ||
# Wait AC Power before defrag | ||
BTRFS_DEFRAG_WAIT_AC_POWER="false" | ||
|
||
|
||
## Path: System/File systems/btrfs | ||
## Type: string | ||
## Default: "/" | ||
|
@@ -72,6 +94,13 @@ BTRFS_BALANCE_DUSAGE="1 5 10 20 30 40 50" | |
# this will increase IO load on the system. | ||
BTRFS_BALANCE_MUSAGE="1 5 10 20 30" | ||
|
||
## Path: System/File systems/btrfs | ||
## Type: boolean | ||
## Default: "false" | ||
# | ||
# Wait AC Power before balance | ||
BTRFS_BALANCE_WAIT_AC_POWER="false" | ||
|
||
## Path: System/File systems/btrfs | ||
## Type: string | ||
## Default: "/" | ||
|
@@ -104,6 +133,13 @@ BTRFS_SCRUB_PRIORITY="idle" | |
# Do read-only scrub and don't try to repair anything. | ||
BTRFS_SCRUB_READ_ONLY="false" | ||
|
||
## Path: System/File systems/btrfs | ||
## Type: boolean | ||
## Default: "false" | ||
# | ||
# Wait AC Power before scrub | ||
BTRFS_SCRUB_WAIT_AC_POWER="false" | ||
|
||
## Path: System/File systems/btrfs | ||
## Description: Configuration for periodic fstrim | ||
## Type: string(none,daily,weekly,monthly) | ||
|
@@ -124,3 +160,10 @@ BTRFS_TRIM_PERIOD="none" | |
# (Colon separated paths) | ||
# The special word/mountpoint "auto" will evaluate all mounted btrfs filesystems at runtime | ||
BTRFS_TRIM_MOUNTPOINTS="/" | ||
|
||
## Path: System/File systems/btrfs | ||
## Type: boolean | ||
## Default: "false" | ||
# | ||
# Wait AC Power before trim | ||
BTRFS_TRIM_WAIT_AC_POWER="false" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The timeout value will be propagated to
check_power_status
, so we need ashift