[PATCHv2,2/4] grub-btrfsd: Use generic volume_fs_type function for FS detection

Message ID 20240327193920.14311-2-stefan.schantl@ipfire.org
State Staged
Commit 6da6f5dbe2d31c920b4cd1e21d3c3abe0ed1f267
Headers
Series [PATCHv2,1/4] initscripts: Add generic function to get the filesystem type of a volume |

Commit Message

Stefan Schantl March 27, 2024, 7:39 p.m. UTC
  Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 src/initscripts/system/grub-btrfsd | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
  

Comments

Michael Tremer March 28, 2024, 10:32 a.m. UTC | #1
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>

> On 27 Mar 2024, at 19:39, Stefan Schantl <stefan.schantl@ipfire.org> wrote:
> 
> Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
> ---
> src/initscripts/system/grub-btrfsd | 19 ++++++++-----------
> 1 file changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/src/initscripts/system/grub-btrfsd b/src/initscripts/system/grub-btrfsd
> index dc5e32ad4..90582b1b1 100644
> --- a/src/initscripts/system/grub-btrfsd
> +++ b/src/initscripts/system/grub-btrfsd
> @@ -25,21 +25,18 @@
> SNAPSHOTDIR="/.snapshots"
> PIDFILE="/run/grub-btrfsd.pid"
> 
> -root_is_btrfs() {
> -    [ "$(stat -f --format="%T" /)" == "btrfs" ] || return 1
> -
> -    return 0
> -}
> -
> case "$1" in
>         start)
> - root_is_btrfs || exit 0
> + root_fs_type=$(volume_fs_type "/")
> 
> - boot_mesg "Starting Grub/Btrfs snapshot manager..."
> - loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR"
> + case "$root_fs_type" in
> + btrfs)
> 
> - # Store the gained PID to the defined pidfile
> - echo "$!" > "$PIDFILE"
> + boot_mesg "Starting Grub/Btrfs snapshot manager..."
> + loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR"
> + echo "$!" > "$PIDFILE"
> + ;;
> + esac
> ;;
> 
> stop)
> -- 
> 2.39.2
>
  

Patch

diff --git a/src/initscripts/system/grub-btrfsd b/src/initscripts/system/grub-btrfsd
index dc5e32ad4..90582b1b1 100644
--- a/src/initscripts/system/grub-btrfsd
+++ b/src/initscripts/system/grub-btrfsd
@@ -25,21 +25,18 @@ 
 SNAPSHOTDIR="/.snapshots"
 PIDFILE="/run/grub-btrfsd.pid"
 
-root_is_btrfs() {
-    [ "$(stat -f --format="%T" /)" == "btrfs" ] || return 1
-
-    return 0
-}
-
 case "$1" in
         start)
-		root_is_btrfs || exit 0
+		root_fs_type=$(volume_fs_type "/")
 
-		boot_mesg "Starting Grub/Btrfs snapshot manager..."
-		loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR"
+		case "$root_fs_type" in
+			btrfs)
 
-		# Store the gained PID to the defined pidfile
-		echo "$!" > "$PIDFILE"
+				boot_mesg "Starting Grub/Btrfs snapshot manager..."
+				loadproc -b -p "$PIDFILE" /usr/bin/grub-btrfsd --syslog "$SNAPSHOTDIR"
+				echo "$!" > "$PIDFILE"
+			;;
+		esac
 	;;
 
 	stop)