git: 7b0593fdcbbb - main - Cirrus-CI: use makefs if root size exceeds QEMU's virtual FAT limit

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Tue, 14 Feb 2023 20:44:58 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=7b0593fdcbbb9c73d282fc0024d844c044423b31

commit 7b0593fdcbbb9c73d282fc0024d844c044423b31
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2023-02-13 17:39:39 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-02-14 20:41:01 +0000

    Cirrus-CI: use makefs if root size exceeds QEMU's virtual FAT limit
    
    We use QEMU's virtual FAT support to avoid having to create a disk
    image because it is much faster, but it has a limit of about 500MB.
    Artifacts produced by the GCC 12 CI job exceeded this size.
    
    Add support for creating a FAT partition image and MBR-partitioned disk
    image and use it when the file system is too large for QEMU.
    
    In one run the Cirrus-CI LLVM test task took 1m33s using QEMU's virtual
    FAT while the GCC task took 6m48s using makefs+mkimg.
    
    Reviewed by:    imp
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D38589
---
 tools/boot/ci-qemu-test.sh | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/tools/boot/ci-qemu-test.sh b/tools/boot/ci-qemu-test.sh
index e6481c794af5..b730e9725014 100755
--- a/tools/boot/ci-qemu-test.sh
+++ b/tools/boot/ci-qemu-test.sh
@@ -21,7 +21,7 @@ die()
 tempdir_cleanup()
 {
 	trap - EXIT SIGINT SIGHUP SIGTERM SIGQUIT
-	rm -rf ${ROOTDIR}
+	rm -rf ${WORKDIR}
 }
 
 tempdir_setup()
@@ -99,18 +99,31 @@ arm64)
 esac
 
 # Create a temp dir to hold the boot image.
-ROOTDIR=$(mktemp -d -t ci-qemu-test-fat-root)
+WORKDIR=$(mktemp -d -t ci-qemu-test-fat-root)
+ROOTDIR=${WORKDIR}/stage-root
 trap tempdir_cleanup EXIT SIGINT SIGHUP SIGTERM SIGQUIT
 
 # Populate the boot image in a temp dir.
 ( cd ${SRCTOP} && tempdir_setup )
 
+# Using QEMU's virtual FAT support is much faster than creating a disk image,
+# but only supports about 500MB.  Fall back to creating a disk image if the
+# staged root is too large.
+hda="fat:${ROOTDIR}"
+rootsize=$(du -skA ${ROOTDIR} | sed 's/[[:space:]].*$//')
+if [ $rootsize -gt 512000 ]; then
+	echo "Root size ${rootsize}K too large for QEMU virtual FAT" >&2
+	makefs -t msdos -s 1g $WORKDIR/image.fat $ROOTDIR
+	mkimg -s mbr -p efi:=$WORKDIR/image.fat -o $WORKDIR/image.mbr
+	hda="$WORKDIR/image.mbr"
+fi
+
 # And, boot in QEMU.
 : ${BOOTLOG:=${TMPDIR:-/tmp}/ci-qemu-test-boot.log}
 timeout 300 \
     $QEMU -m 256M -nodefaults \
         -serial stdio -vga none -nographic -monitor none \
-        -snapshot -hda fat:${ROOTDIR} 2>&1 | tee ${BOOTLOG}
+        -snapshot -hda $hda 2>&1 | tee ${BOOTLOG}
 
 # Check whether we succesfully booted...
 if grep -q 'Hello world.' ${BOOTLOG}; then