From ae48f3f9e90ccae04a4b9e1946594cf62f217f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 5 Aug 2019 13:47:17 +0200 Subject: [PATCH] btrfs-progs: scan devices in preinit instead of init script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no gain to do device scan in init. Commonly we want to always scan BTRFS devices to ensure that after boot raids are correctly linked. It should be done before any init script tries to mount any raid FS. Comparing init scripts and preinit scripts there are I think two primary considerations. First is if user is expected to restart/reload/stop given service on will. I think that there is no such reason for this as user can easily enough just call btrfs utility it self. Second consideration is if it makes sense to have it optional. This means if we want to have ability to enable and disable given service. I think that there is no such need in this case. It is pretty much doing nothing if you don't have BTRFS FS connected and when you have you probably want to scan it. Signed-off-by: Karel Kočí --- utils/btrfs-progs/Makefile | 4 ++-- utils/btrfs-progs/files/btrfs-scan.init | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/utils/btrfs-progs/Makefile b/utils/btrfs-progs/Makefile index 167c51c85..3ad77c981 100644 --- a/utils/btrfs-progs/Makefile +++ b/utils/btrfs-progs/Makefile @@ -79,8 +79,8 @@ define Package/btrfs-progs/install $(INSTALL_BIN) $(PKG_BUILD_DIR)/btrfs.box $(1)/usr/bin/btrfs $(foreach prog,$(boxprogs),$(LN) btrfs $(1)/usr/bin/$(prog);) $(foreach prog,$(progs),$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(prog) $(1)/usr/bin/;) - $(INSTALL_DIR) $(1)/etc/init.d - $(INSTALL_BIN) ./files/btrfs-scan.init $(1)/etc/init.d/btrfs-scan + $(INSTALL_DIR) $(1)/lib/preinit + $(INSTALL_BIN) ./files/btrfs-scan.init $(1)/lib/preinit/85_btrfs_scan endef $(eval $(call BuildPackage,btrfs-progs)) diff --git a/utils/btrfs-progs/files/btrfs-scan.init b/utils/btrfs-progs/files/btrfs-scan.init index 762e0b840..608d3d6c5 100644 --- a/utils/btrfs-progs/files/btrfs-scan.init +++ b/utils/btrfs-progs/files/btrfs-scan.init @@ -1,9 +1,7 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2014 OpenWrt.org +#!/bin/sh -START=19 - -start() { - grep -q btrfs /proc/filesystems && /usr/bin/btrfs device scan +preinit_btrfs_scan() { + grep -vq btrfs /proc/filesystems || btrfs device scan } +boot_hook_add preinit_main preinit_btrfs_scan