Subject: Re: bug#78202: "parted -s /dev/nbd0 mklabel gpt" fails without error message only in release automation

From: "Brian C. Lane" <[email-masked]>
Date: Fri, 2 May 2025 09:19:36 -0700

On Thu, May 01, 2025 at 10:37:10PM +0200, Andreas K. Huettel wrote:
> Dear all, 
> 
> I'm recently running into a strange problem in the Gentoo release build automation, and need help.
> 
> We use parted to create label and partitions in a qcow2 image available via qemu-nbd.
>   https://gitweb.gentoo.org/proj/catalyst.git/tree/targets/support/create-qcow2.sh#n96
> 
> This worked fine for quite some time.
> 
> Recently, it stopped working, there is no error message at all, but the command
>   parted -s /dev/nbd0 mklabel gpt
> returns 1. 
> 
> If I run the same command outside the release automation manually, the return code is 0 and
> everything is fine.
> 
> I inserted strace to see what's wrong. The log follows- any ideas?
> 
> Thanks in advance,
> Andreas
> 

[snip]

>    6480 ioctl(3, BLKSSZGET, [512])              = 0
>    6481 fadvise64(3, 0, 0, POSIX_FADV_RANDOM)   = 0
>    6482 fstat(3, {st_mode=S_IFBLK|0660, st_rdev=makedev(0x2b, 0), ...}) = 0
>    6483 ioctl(3, BLKGETSIZE64, [0])             = 0

That looks bad :) It's reporting the disk size is zero. No idea why, it
seems to get the sector size and later on the io size, etc. ok but a
zero length disk will certainly cause problems.

I've never used nbd much, but my guess would be that this is a setup
timing issue, that you need to do something else to make double extra
sure that the nbd device is really completely setup and ready to use.

Adding a sleep may help identify the problem, but I wouldn't depend on
it as a solution.

I'd also recommend adding some checks to make sure device nodes are
really present before you create the filesystem, as well as 'udevadm
settle' to make sure udev has finished up in the background. These are
problems we used to hit in the parted test suite, and came up with this
code:

https://github.com/bcl/parted/blob/master/tests/t-local.sh#L45

Good luck!

Brian

-- 
Brian C. Lane (PST8PDT) - weldr.io - lorax - parted - pykickstart