From patchwork Wed Apr 4 00:14:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10321869 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 15F9360116 for ; Wed, 4 Apr 2018 00:14:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC6A028D32 for ; Wed, 4 Apr 2018 00:14:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC90628D3B; Wed, 4 Apr 2018 00:14:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 563D328D32 for ; Wed, 4 Apr 2018 00:14:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755886AbeDDAO4 (ORCPT ); Tue, 3 Apr 2018 20:14:56 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:32816 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754966AbeDDAO4 (ORCPT ); Tue, 3 Apr 2018 20:14:56 -0400 Received: by mail-pl0-f65.google.com with SMTP id s10-v6so9468098plp.0 for ; Tue, 03 Apr 2018 17:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=pZgfbGmnnSad9YD9tISRhU51Zwswyl7TdawC2HUubyg=; b=C6k+2HBhtVW5VhrdnqWwrqrhB7UZm/epPsGYMBhT0XNKDm1anAhm9idmcN1ZEgujNu 0UeGuZdJPArrtAg9JhlCGt27f4dMo/BIYnmUFzFHvB1FHAeWH5TVu68/ncXBbQkdBXWF qKbFk7c6xfxGlzp4ziQEwLI/jB53QFNw+TQcmmqG5+6gqIPeMI0XtuSqwEBdUYK3L1By /fnv1Rnixc1uyBQnm4/bhp4mzOjjvv/jhOoRUlf2QhU5eM9TkXDvx8Fzt6RjVNe8vkJR Svw40dzhZ4CZnTEE5/KarY9aE9A66onyj64XVEsBrdynvWOpSn8su98nSfpqWnnlEdL0 g+Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pZgfbGmnnSad9YD9tISRhU51Zwswyl7TdawC2HUubyg=; b=kI4OZBpCmQHTynWuyA5jWn47ONvIn2matmzwiTeMsE80+nG/ZNO/rAkQ/4I3Vrkoh4 BD/iZrhbWYuMgahX0M/0EPNh29uwbRDE6JTVdDHfEkl2MzKt23Ghw9byOx12IepYMUAv yS2xybTNfA/xCK6ZqNjO8Pq1ZlmojKbtTSYyDSHbCV3coiDXhL6lp18X0HKctwJUz9YU vsRMrrso3VENebwEk5oV9wQTosY7pR4yqDRJFCqhEyoZlxh1voIDdc0l7YCDBws5Bn1m JL4Jv3buDiJCLVO/9CE9maUSSxuFsd6iY+knHSFlP4FHt9LJkFZdMOg36/E1hvqdOvLW AYIw== X-Gm-Message-State: AElRT7E5SCHbHrtlm36c8TYSjeYV0p6tGmAyp/kQ5IUbOOQ+HZEzeiXN Es2il6IZnQASRzCJ2dpBeUEEUQ== X-Google-Smtp-Source: AIpwx49DD1rqpXIfY2ih0U7dwPmjtBAQ/ktAL9w6E0rorw6i+RnTb44QlRxaC5ot6LOYJpq1jYAQUQ== X-Received: by 10.98.227.16 with SMTP id g16mr11877135pfh.171.1522800895459; Tue, 03 Apr 2018 17:14:55 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id p6sm5884230pgq.53.2018.04.03.17.14.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Apr 2018 17:14:54 -0700 (PDT) From: Eric Biggers To: Theodore Ts'o Cc: fstests@vger.kernel.org, Eric Biggers Subject: [xfstests-bld PATCH] gen-image: fix running in a foreign build chroot Date: Tue, 3 Apr 2018 17:14:21 -0700 Message-Id: <20180404001421.81698-1-ebiggers@google.com> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Building an android-xfstests test appliance on x86_64 with the documented command (e.g. './do-all --chroot=stretch-arm64 --out-tar') no longer works. The problem is that when the gen-image script is run in a foreign build chroot, it incorrectly considers the root_fs's chroot to be a "native" chroot and doesn't copy the needed /usr/bin/qemu-*-static binary into it. This is because both 'uname -m' and 'dpkg --print-architecture' will return the same architecture (the foreign one), so is_native_chroot() returns true. This did used to work, but I think it stopped working with 5c76a88c0e57 ("test-appliance: improve image generation for chroot tar files") because previously it was using 'fakechroot' which doesn't actually change the real root directory, so the /usr/bin directory stayed the same from the kernel's perspective. But now it uses real chroot. Fix this by detecting a foreign build chroot by instead mounting binfmt_misc and checking whether there is an entry for qemu-$(uname -m). Signed-off-by: Eric Biggers --- kvm-xfstests/test-appliance/gen-image | 58 +++++++++++++++------------ 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/kvm-xfstests/test-appliance/gen-image b/kvm-xfstests/test-appliance/gen-image index bba7e88..8d4bebb 100755 --- a/kvm-xfstests/test-appliance/gen-image +++ b/kvm-xfstests/test-appliance/gen-image @@ -8,7 +8,6 @@ SUITE=stretch MIRROR=http://mirrors.kernel.org/debian DIR=$(pwd) ROOTDIR=$DIR/rootdir -#ARCH="--arch=i386" RAW_ROOT_FS=$DIR/root_fs.raw ROOT_FS=$DIR/root_fs.img COMPAT="-o compat=0.10" @@ -21,18 +20,6 @@ if test -r config.custom ; then . $(pwd)/config.custom fi -is_native_chroot() -{ - DEBIAN_ARCH="$(dpkg --print-architecture)" - case "$(uname -m)" in - x86_64) [[ $DEBIAN_ARCH = amd64 || $DEBIAN_ARCH = i386 ]] ;; - aarch64) [[ $DEBIAN_ARCH = arm64 || $DEBIAN_ARCH = armhf ]] ;; - arm) [[ $DEBIAN_ARCH = armhf ]] ;; - ppc64le) [[ $DEBIAN_ARCH = ppc64el ]] ;; - *) [[ $DEBIAN_ARCH = "$(uname -m)" ]] ;; - esac -} - while [ "$1" != "" ]; do case $1 in --save_raw_root) @@ -215,20 +202,39 @@ if test $DO_UPDATE = "yes" ; then exit 0 fi -if ! is_native_chroot ; then - case "$DEBIAN_ARCH" in - armhf) QEMU=/usr/bin/qemu-arm-static ;; - arm64) QEMU=/usr/bin/qemu-aarch64-static ;; - ppc64el) QEMU=/usr/bin/qemu-ppc64le-static ;; - *) QEMU="/usr/bin/qemu-$DEBIAN_ARCH-static" ;; - esac - if ! test -x $QEMU ; then - echo "Can't find qemu interpreter for non-native gen-image" -# cleanup_on_abort -# exit 1 +detect_foreign_chroot() +{ + local BINFMT_MISC_MNT=/proc/sys/fs/binfmt_misc + + if [ ! -d "$BINFMT_MISC_MNT" ]; then + # binfmt_misc disabled in kernel + return + fi + + if ! mountpoint "$BINFMT_MISC_MNT" &>/dev/null; then + mount binfmt_misc -t binfmt_misc "$BINFMT_MISC_MNT" + trap "umount \"$BINFMT_MISC_MNT\"" EXIT fi + + if [ "$(<"$BINFMT_MISC_MNT/status")" = "disabled" ]; then + return + fi + + local binfmt="qemu-$(uname -m)" + local binfmt_file="$BINFMT_MISC_MNT/$binfmt" + + if [ ! -e "$binfmt_file" ]; then + return + fi + + QEMU="$(awk '/^interpreter/{print $2}' "$binfmt_file")" FOREIGN="--foreign" -fi + echo "Detected foreign chroot, using user-mode emulation with $QEMU" +} + +QEMU= +FOREIGN= +detect_foreign_chroot mkdir -p var.cache.apt.archives mkdir -p var.lib.apt.lists @@ -255,7 +261,7 @@ else export FAKECHROOT_CMD_SUBST=/usr/bin/chfn=/bin/true fi trap cleanup_on_abort INT TERM -debootstrap --variant=minbase --include=$PACKAGES $EXCLUDE $ARCH \ +debootstrap --variant=minbase --include=$PACKAGES $EXCLUDE \ $FOREIGN $SUITE $ROOTDIR $MIRROR $DIR/debootstrap.script if test $? -ne 0 ; then echo "Deboostrap failed, aborting."