From a04d6c1b2f10459cd77278a4c41058e610821060 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Tue, 29 Sep 2026 15:40:03 -0300 Subject: [PATCH] boot: an overlay is mounted once its NBD device has a size On the kvm runner, the report's second boot mounted /dev/nbd0 while it still had zero bytes - qemu-nbd returns before the kernel learns the device's size, and the capacity change was logged 7 ms after the failed mount ("can't read superblock"). The wait for a filesystem asked blkid, which answers from its cache and said ext4 about the empty device. It now waits for a non-zero size and probes with blkid -p. Co-Authored-By: Claude Opus 5.5 (1M context) --- boot/bench_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/boot/bench_test.go b/boot/bench_test.go index f103874..d804ab2 100644 --- a/boot/bench_test.go +++ b/boot/bench_test.go @@ -621,11 +621,15 @@ func editOverlay(t *testing.T, overlay string, v variant) { mustRun(t, "sudo", "qemu-nbd", "--connect="+dev, "-f", "qcow2", overlay) defer mustRun(t, "sudo", "qemu-nbd", "--disconnect", dev) - // The kernel needs a moment to read the partition table it will not find: this image is - // partitionless, so the device itself is the filesystem. + // The device's size arrives after qemu-nbd returns: a mount before it reads a device of + // zero bytes and fails with "can't read superblock", which a runner reconnecting right after + // the previous boot's disconnect did (the kernel logged the capacity change 7 ms after the + // failed mount). blkid -p and not blkid: without it blkid answers from its cache, and said + // ext4 about a device that was still empty. var ok bool for range 20 { - if exec.Command("sudo", "blkid", dev).Run() == nil { + size, err := exec.Command("sudo", "blockdev", "--getsize64", dev).Output() + if err == nil && strings.TrimSpace(string(size)) != "0" && exec.Command("sudo", "blkid", "-p", dev).Run() == nil { ok = true break }