networking: persistent trip ID to prevent purge loop in parallel install
The following tests have been performed: we have two sets: old install
(O) and new (N). O->N success N->N success N->O success N->N with the
same trip ID injected (success).
Platforms-Affected: all ttf
Tested: yes
Google-Bug-Id: 425490715
Tested: in progress.
Fusion-Link: fusion2 n/a
Change-Id: I28ed2957e6195d9dcbdca9cd0b714a288074774b
Signed-off-by: Mo Elbadry <elbadrym@google.com>
(cherry picked from commit 1d0a72b62246638b77037d23a38e70b02d388b37)
(cherry picked from commit a8801d24081bf7581a3cf3b7abe183d110210ca0)
diff --git a/recipes-google/networking/gbmc-bridge/49-purge-rwfs.sh b/recipes-google/networking/gbmc-bridge/49-purge-rwfs.sh
index d2e643a..2da7a68 100644
--- a/recipes-google/networking/gbmc-bridge/49-purge-rwfs.sh
+++ b/recipes-google/networking/gbmc-bridge/49-purge-rwfs.sh
@@ -18,9 +18,29 @@
gbmc_purge_rwfs_hook() {
# Ensure that we don't succeed unless it clears
GBMC_BR_DHCP_OUTSTANDING[gbmc_purge_rwfs]=1
+ local trip_id_regex="/Installer/TRIP/ID/(.*)$"
+
+ # Scan the metadata and directly request the first capture group (the ID).
+ local matched_line
+ local trip_id=""
+
+ matched_line=$(gbmc_upgrade_metadata_first_match "${trip_id_regex}")
update_netboot_status "rwfs_check" "clear rwfs hook started" "START"
- # Only execute this hook if we aren't already purged and we don't
+ if [[ -n "${matched_line}" && "${matched_line}" =~ ${trip_id_regex} ]]; then
+ # The ID is in the first capture group.
+ trip_id="${BASH_REMATCH[1]}"
+ if [ -r "/var/google/rwfs-purged" ]; then
+ local purged_id
+ purged_id=$(</var/google/rwfs-purged)
+ # If the existing purge ID matches the one from metadata, we're done.
+ if [ "${trip_id}" = "${purged_id}" ]; then
+ update_netboot_status "rwfs_check" "RWFS already purged with correct TRIP ID: ${trip_id}" "SUCCESS"
+ return 0 # Exit successfully, no action needed.
+ fi
+ fi
+ fi
+
# require a powercycle that would spuriously erase the purge status.
if [ -z "${gbmc_psu_hardreset_needed-}" -a -e '/run/initramfs/rwfs-purged' ]; then
update_netboot_status "rwfs_check" "RWFS already purged" "SUCCESS"
@@ -28,10 +48,15 @@
fi
update_netboot_status "rwfs_check" "RWFS purge needed" "SUCCESS"
update_netboot_status "rwfs_set" "Setting RWFS purge flag" "START"
- mkdir -p /var/google/ || return
- touch /var/google/do-rwfs-purge
- update_netboot_status "rwfs_set" "RWFS purge flag placed, powercycle needed to complete" "SUCCESS"
+ mkdir -p /var/google/ || return
+ if [ -n "${trip_id}" ]; then
+ echo "${trip_id}" > /var/google/do-rwfs-purge
+ update_netboot_status "rwfs_set" "RWFS purge flag with TRIP ID placed, powercycle needed" "SUCCESS"
+ else
+ touch /var/google/do-rwfs-purge
+ update_netboot_status "rwfs_set" "RWFS purge flag placed, powercycle needed" "SUCCESS"
+ fi
gbmc_reboot_needed=1
}
diff --git a/recipes-google/networking/gbmc-bridge/53-clear-purge-rwfs.sh b/recipes-google/networking/gbmc-bridge/53-clear-purge-rwfs.sh
index 7335e3e..0a6de26 100644
--- a/recipes-google/networking/gbmc-bridge/53-clear-purge-rwfs.sh
+++ b/recipes-google/networking/gbmc-bridge/53-clear-purge-rwfs.sh
@@ -17,6 +17,17 @@
gbmc_clear_purge_rwfs_hook() {
update_netboot_status "rwfs_unset" "unsetting RWFS clear flag" "START"
+ if [ -s "/run/initramfs/rwfs-purged" ]; then
+ update_netboot_status "rwfs_id_copy" "Purge flag has value, copying it to /var/google/rwfs-purged" "START"
+
+ # Create the destination directory if it doesn't exist.
+ mkdir -p "/var/google/"
+
+ # Copy the file to the new location with the specified name.
+ cp "/run/initramfs/rwfs-purged" "/var/google/rwfs-purged"
+ update_netboot_status "rwfs_id_copy" "Purge trip ID copied to /var/google/rwfs-purged" "SUCCESS"
+ fi
+
rm -f /run/initramfs/rwfs-purged
unset GBMC_BR_DHCP_OUTSTANDING[gbmc_purge_rwfs]
update_netboot_status "rwfs_unset" "RWFS clear flag unset" "SUCCESS"
diff --git a/recipes-phosphor/initrdscripts/obmc-phosphor-initfs/0001-obmc-phosphor-initfs-Add-support-for-purging-RWFS.patch b/recipes-phosphor/initrdscripts/obmc-phosphor-initfs/0001-obmc-phosphor-initfs-Add-support-for-purging-RWFS.patch
index 06fdaac..176f108 100644
--- a/recipes-phosphor/initrdscripts/obmc-phosphor-initfs/0001-obmc-phosphor-initfs-Add-support-for-purging-RWFS.patch
+++ b/recipes-phosphor/initrdscripts/obmc-phosphor-initfs/0001-obmc-phosphor-initfs-Add-support-for-purging-RWFS.patch
@@ -4,15 +4,17 @@
Subject: [PATCH] obmc-phosphor-initfs: Add support for purging RWFS
This adds a flag to the RWFS that makes it possible to purge on the next
-bootup.
+bootup. We now copy the purge content to retain certain metadata for
+install
Patch Tracking Bug: b/263910116
+Patch Tracking Bug: b/425490715
Upstream info / review: N/A
-Upstream-Status: Pending
Justification: Contains a google specific directory path
Signed-off-by: William A. Kennington III <wak@google.com>
Signed-off-by: Nan Zhou <nanzhou@google.com>
+Signed-off-by: Mo Elbadry <elbadrym@google.com>
---
obmc-init.sh | 6 ++++++
1 file changed, 6 insertions(+)
@@ -27,8 +29,8 @@
+if [ -e $upper/var/google/do-rwfs-purge ]; then
+ echo 'Purging RWFS'
++ cp $upper/var/google/do-rwfs-purge run/initramfs/rwfs-purged
+ rm -rf $upper
-+ touch run/initramfs/rwfs-purged
+fi
+
mkdir -p $upper $work