Make-initrd development discussion
 help / color / mirror / Atom feed
* [make-initrd] [PATCH v6 14/22] bootchain-core: extends bootchain-sh-functions API
@ 2021-10-24 17:22 Leonid Krivoshein
  0 siblings, 0 replies; only message in thread
From: Leonid Krivoshein @ 2021-10-24 17:22 UTC (permalink / raw)
  To: make-initrd

Signed-off-by: Leonid Krivoshein <klark.devel@gmail.com>
---
 features/bootchain-core/README.md             | 19 ++++++
 .../data/bin/bootchain-sh-functions           | 61 +++++++++++++++++++
 features/bootchain-core/data/sbin/chaind      |  2 +-
 3 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/features/bootchain-core/README.md b/features/bootchain-core/README.md
index 14db55f..ffed599 100644
--- a/features/bootchain-core/README.md
+++ b/features/bootchain-core/README.md
@@ -59,6 +59,10 @@ us to optimize fill in `initramfs` only which we are need.
   relative addressing it is safe in any case and can often be more convenient.
 - Allows you to work with shorter and more familiar paths to special files
   devices thanks to the use of `DEVNAME` along with `dev`.
+- Provides the ability to associate the <IN> of a step with the <OUT>
+  of the previous step through symbolic links to mount points inside initramfs,
+  outside the tree the results of the steps, which provides, if necessary, the
+  overlap mounting mechanism inherent in the program `propagator`.
 - The daemon can be configured when building initramfs via the included file
   configurations of `/etc/sysconfig/bootchain`, and not only through boot
   parameters, see the details in the corresponding section.
@@ -134,6 +138,21 @@ own needs.
   debugging.
 - assign() - assignment of the specified value to a variable that gets into
   the log with advanced debugging. The left-hand expression is also computable.
+- next_bootchain() - command to the daemon to change the sequence of the
+  following steps.
+- is_step_passed() - returns 0 if the current step has been passed at
+  least once.
+- launch_step_once() - if the current step has already been completed,
+  it completes the work through the fatal() call.
+- break_bc_loop() - informs the daemon that the current step is the last and
+  after after its successful completion, you can switch to stage2. The script
+  of this step, however, must work to the end and end with a zero status code
+  in order for the daemon to process the received signal.
+- bc_reboot() - performs a logged restart of the computer.
+- bypass_results() - asks the daemon to associate the <OUT> of the previous
+  step with the <IN> the next step. It is also used to inform the daemon about
+  the result (mounted directory) inside the current initramfs root, outside the
+  $mntdir tree.
 - initrd_version() - output of the current version of make-initrd. It is proposed
   to move to make-initrd/data/bin/initrd-sh-functions after has_module().
 
diff --git a/features/bootchain-core/data/bin/bootchain-sh-functions b/features/bootchain-core/data/bin/bootchain-sh-functions
index dcc1ab2..d1d0cef 100644
--- a/features/bootchain-core/data/bin/bootchain-sh-functions
+++ b/features/bootchain-core/data/bin/bootchain-sh-functions
@@ -22,6 +22,8 @@ else
 	mntdir="${mntdir:-/dev/bootchain}"
 fi
 
+BC_NEXTCHAIN=/.initrd/bootchain/bootchain.next
+BC_PASSED=/.initrd/bootchain/passed
 handlerdir=/lib/bootchain
 
 
@@ -153,6 +155,65 @@ assign()
 	debug "LET: ${_k}=\"${_v}\""
 }
 
+next_bootchain()
+{
+	local _v="${1-}"
+
+	printf 'chainsteps="%s"\n' "${_v}" >>"$BC_NEXTCHAIN"
+	debug "BOOTCHAIN REPLACED: '${_v}'"
+}
+
+is_step_passed()
+{
+	[ -f "$BC_PASSED/$PROG" ] ||
+		return 1
+}
+
+launch_step_once()
+{
+	[ ! -f "$BC_PASSED/$PROG" ] ||
+		fatal "this step has been already passed"
+}
+
+break_bc_loop()
+{
+	enter "break_bc_loop"
+
+	:> "$BC_PASSED/chaind"
+
+	leave "break_bc_loop"
+}
+
+bc_reboot()
+{
+	run reboot -f -d
+}
+
+bypass_results()
+{
+	enter "bypass_results"
+
+	local realdir="${1-}"
+	local srcdir="${realdir:-$prevdir}"
+
+	if [ -n "$srcdir" ] && [ "$srcdir" != "$destdir" ]; then
+		if [ -d "$realdir" ] || [ -L "$prevdir" ] ||
+			[ "$srcdir" = "${srcdir#$mntdir/}" ]
+		then
+			run rmdir -- "$destdir" ||:
+			run ln -snf -- "$(readlink-e "$srcdir")" "$destdir"
+		elif mountpoint -q -- "$prevdir"; then
+			run mkdir -p -- "$destdir"
+			run mount --move -- "$prevdir" "$destdir"
+		else
+			run rmdir -- "$destdir" ||:
+			run mv -f -- "$prevdir" "$destdir"
+		fi
+	fi
+
+	leave "bypass_results"
+}
+
 initrd_version()
 {
 	[ ! -s /etc/initrd-release ] ||
diff --git a/features/bootchain-core/data/sbin/chaind b/features/bootchain-core/data/sbin/chaind
index c1b2451..9224c40 100755
--- a/features/bootchain-core/data/sbin/chaind
+++ b/features/bootchain-core/data/sbin/chaind
@@ -34,7 +34,7 @@ message "Starting server [$(initrd_version)]..."
 debug "Booting with /proc/cmdline:"
 fdump /proc/cmdline
 
-run mkdir -p -- "$mntdir"
+run mkdir -p -- "$mntdir" "$BC_PASSED"
 
 mountpoint -q -- "$mntdir" ||
 	run mount -t tmpfs tmpfs "$mntdir" ||:
-- 
2.24.1



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-24 17:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-24 17:22 [make-initrd] [PATCH v6 14/22] bootchain-core: extends bootchain-sh-functions API Leonid Krivoshein

Make-initrd development discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/make-initrd/0 make-initrd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 make-initrd make-initrd/ http://lore.altlinux.org/make-initrd \
		make-initrd@lists.altlinux.org make-initrd@lists.altlinux.ru make-initrd@lists.altlinux.com
	public-inbox-index make-initrd

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.make-initrd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git