From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7201062888117633024 X-Received: by 2002:a05:6102:e8d:b0:416:7e96:87c7 with SMTP id l13-20020a0561020e8d00b004167e9687c7mr1961316vst.58.1677087606427; Wed, 22 Feb 2023 09:40:06 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a67:eb11:0:b0:412:6005:4f8e with SMTP id a17-20020a67eb11000000b0041260054f8els2183264vso.7.-pod-prod-gmail; Wed, 22 Feb 2023 09:40:05 -0800 (PST) X-Google-Smtp-Source: AK7set+vzh9gGD5mM6414d6zCLUmuep8ydq45QRdnqZ3RnqZ+zwBAVa3YJiJuFjXxvzV7nhGNnBz X-Received: by 2002:a67:d49b:0:b0:414:a305:9ba with SMTP id g27-20020a67d49b000000b00414a30509bamr7306815vsj.5.1677087605372; Wed, 22 Feb 2023 09:40:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677087605; cv=none; d=google.com; s=arc-20160816; b=pCKnMnvJWbJBvKfEkBPuvR+QDGYC7ri+1nAQYiKGKQJIsKEGxrrfsEqrV/S70c8O5L ftnDWWSncvvKywlsOZUUXOV4VfNb4gCCYWjr+7NZAk02HXWubjB5SxeP+F+2uiE4gsEf SoRMntqK2atp1sCckjco4E1DkxRirtauDybHnorl3dnt12xKo3qChmhydLEOmyLOzIxT geiTc5TuseC5sz91OPQfUTyI0r8OUYhgGzXRaEslcvU21iFrjXMQ/Z7mmvGwKEYUZN4r FMt6/1aByC3luIwCwAucIQ722r+ueqqrAjBMKrpTJTZB8TOWAXiEhPfrVNRG9rdPmomC vY9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from; bh=k7Rg0L3xWwOUrH1lmZjBaCkYxwI2oxCfdbQy0Sd7JJw=; b=0jS5mBAD5lju0Xovtrlqgavy/GRvRkPHwDqvu2Pd/GvQBPJJi6GNOu9MKXZRzpO9E0 vgvjIppmygF/iAwdEoWJGCALOWwk0e1IkifxTuCWucmJgALGS6uB4VP5MQS1g1SdvbLH dBPez+e0MdmNsx2OmxQXrHpDvRG1coNyuYd/rjw7ygdh3UYafbq1sEa/7SHOXTILOkg0 OSJ2KXOnfAauBubjZrBISyzEjZZ0QVY6TKcKgUE72cmf2tYeQF8wPGrfllcjbnrcFyPz bZd2CmVKcZDGRv8y1VMPLYCXb5NqViPLeeYbD/N1DPXiGNE9SL+M9PegAxBfdCleTWyf n52Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of ubely@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=ubely@ilbers.de Return-Path: Received: from shymkent.ilbers.de (shymkent.ilbers.de. [85.214.156.166]) by gmr-mx.google.com with ESMTPS id q40-20020a05613002a800b0068b840992aesi603136uac.2.2023.02.22.09.40.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Feb 2023 09:40:05 -0800 (PST) Received-SPF: pass (google.com: domain of ubely@ilbers.de designates 85.214.156.166 as permitted sender) client-ip=85.214.156.166; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of ubely@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=ubely@ilbers.de Received: from home.localnet (44-208-124-178-static.mgts.by [178.124.208.44] (may be forged)) (authenticated bits=0) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPSA id 31MHe29m016935 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Feb 2023 18:40:03 +0100 From: Uladzimir Bely To: isar-users@googlegroups.com, Felix Moessbauer Subject: Re: [PATCH v2 3/3] fix race-cond between default and custom initrd Date: Wed, 22 Feb 2023 20:40:03 +0300 Message-ID: <5500062.ZASKD2KPVS@home> In-Reply-To: <20230218103038.3005105-4-felix.moessbauer@siemens.com> References: <20230218103038.3005105-1-felix.moessbauer@siemens.com> <20230218103038.3005105-4-felix.moessbauer@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shymkent.ilbers.de X-TUID: VbjIRRqm1R5J In the email from Saturday, 18 February 2023 13:30:38 +03 user Felix Moessbauer wrote: > This patch fixes a data race happening when building a custom initrd. > Previously, both custom and default initrds were deployed to the image > deploy dir. The race is fixed by conditionally deploying either the > custom or the default one. For that, we introduce a new variable > INITRD_DEPLOY_FILE which provides the name of the initrd in the deploy > directory. The existing INITRD_IMAGE variable is defaulted to the empty > string and used to control if a custom initrd is requrested. Only if > this variable is empty, the default one is deployed. > > Signed-off-by: Felix Moessbauer > --- > RECIPE-API-CHANGELOG.md | 8 ++++++++ > meta/classes/image.bbclass | 20 ++++++++++++-------- > scripts/start_vm | 4 ++-- > testsuite/start_vm.py | 2 +- > 4 files changed, 23 insertions(+), 11 deletions(-) > > diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md > index e48c98c7..1e8dbfc8 100644 > --- a/RECIPE-API-CHANGELOG.md > +++ b/RECIPE-API-CHANGELOG.md > @@ -476,3 +476,11 @@ Bitbake 2.0 for better performance. It also requires isar-sstate script to be > migrated to zstd. > Mixing old Gzip-based and new ZStandatd-based sstate cache is not recommended > and should be avoid for correct compatibility. > + > +### Working with a custom initramfs > + > +The existing `INITRD_IMAGE` variable is defaulted to the empty string and used to > +control if a custom initrd is requrested. Only if this variable is empty, the > +default one is deployed. By that, the variable cannot be used to get the name of > +the images initramfs. Instead, the variable `INITRD_DEPLOY_FILE` is provided which > +always povides the name of the initrd file (also when the default one is used). > diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass > index 6277069f..7b3551b0 100644 > --- a/meta/classes/image.bbclass > +++ b/meta/classes/image.bbclass > @@ -23,7 +23,8 @@ IMAGE_FULLNAME = "${PN}-${DISTRO}-${MACHINE}" > > # These variables are used by wic and start_vm > KERNEL_IMAGE ?= "${IMAGE_FULLNAME}-${KERNEL_FILE}" > -INITRD_IMAGE ?= "${IMAGE_FULLNAME}-initrd.img" > +INITRD_IMAGE ?= "" > +INITRD_DEPLOY_FILE = "${@ d.getVar('INITRD_IMAGE', True) or '${IMAGE_FULLNAME}-initrd.img'}" > > # This defines the deployed dtbs for reuse by imagers > DTB_FILES ?= "" > @@ -353,7 +354,7 @@ EOF > > # Default kernel, initrd and dtb image deploy paths (inside imager) > KERNEL_IMG = "${PP_DEPLOY}/${KERNEL_IMAGE}" > -INITRD_IMG = "${PP_DEPLOY}/${INITRD_IMAGE}" > +INITRD_IMG = "${PP_DEPLOY}/${INITRD_DEPLOY_FILE}" > # only one dtb file supported, pick the first > DTB_IMG = "${PP_DEPLOY}/${@(d.getVar('DTB_FILES').split() or [''])[0]}" > > @@ -370,12 +371,15 @@ do_copy_boot_files() { > sudo cat "$kernel" > "${DEPLOYDIR}/${KERNEL_IMAGE}" > fi > > - initrd="$(realpath -q '${IMAGE_ROOTFS}/initrd.img')" > - if [ ! -f "$initrd" ]; then > - initrd="$(realpath -q '${IMAGE_ROOTFS}/boot/initrd.img')" > - fi > - if [ -f "$initrd" ]; then > - cp -f "$initrd" '${DEPLOYDIR}/${INITRD_IMAGE}' > + if [ -e "${INITRD_IMAGE}" ]; then > + # deploy default initrd if no custom one is build > + initrd="$(realpath -q '${IMAGE_ROOTFS}/initrd.img')" > + if [ ! -f "$initrd" ]; then > + initrd="$(realpath -q '${IMAGE_ROOTFS}/boot/initrd.img')" > + fi > + if [ -f "$initrd" ]; then > + cp -f "$initrd" '${DEPLOYDIR}/${INITRD_DEPLOY_FILE}' > + fi > fi > > for file in ${DTB_FILES}; do > diff --git a/scripts/start_vm b/scripts/start_vm > index 17091d72..8c696a4a 100755 > --- a/scripts/start_vm > +++ b/scripts/start_vm > @@ -125,10 +125,10 @@ case "$IMAGE_FSTYPES" in > readonly ROOTFS_IMAGE=$IMAGE_FULLNAME.ext4 > > eval $(bitbake -e mc:qemu$ARCH-$DISTRO:isar-image-base | grep "^KERNEL_IMAGE=") > - eval $(bitbake -e mc:qemu$ARCH-$DISTRO:isar-image-base | grep "^INITRD_IMAGE=") > + eval $(bitbake -e mc:qemu$ARCH-$DISTRO:isar-image-base | grep "^INITRD_DEPLOY_FILE=") > QKERNEL=$IMAGE_DIR/${KERNEL_IMAGE} > QINITRD=/dev/null > - [ -n "$INITRD_IMAGE" ] && QINITRD=$IMAGE_DIR/${INITRD_IMAGE} > + [ -n "$INITRD_DEPLOY_FILE" ] && QINITRD=$IMAGE_DIR/${INITRD_DEPLOY_FILE} > if [ "$ARCH" = "riscv64" ]; then > EXTRA_ARGS="$EXTRA_ARGS -device loader,file=$QKERNEL,addr=0x80200000" > QKERNEL="/usr/lib/riscv64-linux-gnu/opensbi/qemu/virt/fw_jump.elf" > diff --git a/testsuite/start_vm.py b/testsuite/start_vm.py > index 82ecc17d..ba1ba127 100755 > --- a/testsuite/start_vm.py > +++ b/testsuite/start_vm.py > @@ -35,7 +35,7 @@ def format_qemu_cmdline(arch, build, distro, out, pid, enforce_pcbios=False): > if image_type == 'ext4': > rootfs_image = 'isar-image-base-' + base + '-' + distro + '-qemu' + arch + '.ext4' > kernel_image = deploy_dir_image + '/' + get_bitbake_var(bb_output, 'KERNEL_IMAGE') > - initrd_image = get_bitbake_var(bb_output, 'INITRD_IMAGE') > + initrd_image = get_bitbake_var(bb_output, 'INITRD_DEPLOY_FILE') This seems to be not enough to change the name without directory, since it's later concatenated with old one (deploy_dir_image) > > if not initrd_image: > initrd_image = '/dev/null' > else: initrd_image = deploy_dir_image + '/' + initrd_image` Moreover, I would say, it's not good that we should now look for initrd file somewhere in DEPLOYDIR="${WORKDIR}/deploy", while everyone would expect to find it DEPLOY_DIR_IMAGE="${DEPLOY_DIR}/images/${MACHINE}"...