From e75c15bfdafa2af35e569425c5b26e7295884d10 Mon Sep 17 00:00:00 2001 From: Samuel Angebault Date: Tue, 22 Dec 2020 00:07:10 -0800 Subject: [PATCH] [aboot]: Better handle tmpfs management in boot0 (#6268) To limit IO and space usage on the flash device the boot0 script makes sure the SWI is in memory. Because SONiC maps /tmp on the flash, some logic is required to make sure of it. However it is possible for some provisioning mechanism to already download the swi in a memory file system. This was not properly handled by the boot0 script. It now properly detect if the image is on a tmpfs or a ramfs and keep it there if that is the case. - How I did it Check the filesystem on which the SWI pointed by swipath lies. If this filesystem is a ramfs or a tmpfs the move_swi_to_tmpfs becomes a no-op. Made sure the cleanup logic would not behave unexpectedly. - How to verify it In SONiC: Download the swi under /tmp and makes sure it gets moved to /tmp/tmp-swi which gets mounted for that purpose. Make sure /tmp/tmp-swi gets unmounted once the install process is done. Create a new mountpoint under /ram using either ramfs or tmpfs and download the swi there. Install the swi using sonic-installer and makes sure the image doesn't get moved by looking at the logs. --- files/Aboot/boot0.j2 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/files/Aboot/boot0.j2 b/files/Aboot/boot0.j2 index 3c61c631af93..7191f2c11c5e 100644 --- a/files/Aboot/boot0.j2 +++ b/files/Aboot/boot0.j2 @@ -130,10 +130,27 @@ update_next_boot() { fi } +is_in_memory() { + local file="$1" + local filedev=$(df "$file" | tail -n 1 | tr -s ' ' | cut -f6 -d' ') + local filedevfs=$(mount | grep " $filedev " | cut -f5 -d' ') + + case "$filedevfs" in + tmpfs|ramfs) return 0;; + *) return 1;; + esac +} + move_swi_to_tmpfs() { local oldswi="$1" local newswi="$swi_tmpfs/$(basename $oldswi)" + # check if the swi is already in memory + if ! $in_aboot && is_in_memory "$oldswi"; then + echo "$oldswi" + return 0 + fi + mkdir -p "$swi_tmpfs" if ! $in_aboot && ! mount | grep -q ' /tmp type tmpfs'; then # mount a real tmpfs on /tmp/tmp-swi if /tmp is not one already.