From patchwork Mon Feb 11 13:04:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 157995 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2582494jaa; Mon, 11 Feb 2019 05:12:19 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ9gbLYk7lKl0b3VgDjVnCpgus7zzhtwnwNRTCNgrnVozFrRZY9bss1bYqirZsYLBK80yxr X-Received: by 2002:adf:e706:: with SMTP id c6mr13832690wrm.278.1549890739681; Mon, 11 Feb 2019 05:12:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549890739; cv=none; d=google.com; s=arc-20160816; b=qpI/b3rSv0mkcVYVRVcKMQl6wcI0Ey8Zvb4sVFFDqcurqBqdZ5ys0LvPIKunVQldVM QY4uPk58uHbVVXzPbZJadpHm8xioT5tCPu76RzE68IvArBLhwh6OilS+hSk9h4SoJimJ +uh4orkuCNSi3YPzCt/jWmFMtJvmYPzjmBugaYZlytFMf3L8pypjn5sfXFLEBfmp815e gbI/V5ROFWkxbTihzw4we5gf9tYd7RDBFP5GvcgA17Wk7SQIy3yjjNiuU/9ov5+sANJy cEzLiBmkk9Us0DzJCZZvgm2sOoONOHw/WIdsl0eVp6rLrfuSwVpM5rEea8ww/AC0+M48 WSzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=2+MelR4KT5S9gb68buZxTVHCeI3TD9oWTrbM+yRenTY=; b=FbJd1yVaYUWUokY0zKp/ISc/AZ0zkgRr4nDSAXe+5qEzHZChukaZHatbpj9PIGcJMS RUJXq/FZPepF/uCDxEvi1DbAMZ88JguY36dqirkT6ci/fZ+jzoF1CyCMpuj6N/e5Qa1A faudEDCOv79U0ROwu1VH6Mx+j4Yaga1tqRWp3E5fvocr3YvWEtJ+SrfwqfyKK9/jG+pg unFeRUUPg1VZPe8VuuPox2YMC5EkB5phmOhWzWc6nou8/cDxNmJz+eqOdz7l2eio81Lm PqhSTPqtSe88gUXsSxa86NRd3Y8E10JBYKrJEi0ET45iPDcRYH6MxAfMJlC/8BwN1g6S FnSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hHeDmCug; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n16si3920498wrv.243.2019.02.11.05.12.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Feb 2019 05:12:19 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hHeDmCug; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:50017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtBNi-0003dF-E7 for patch@linaro.org; Mon, 11 Feb 2019 08:12:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtBHZ-0007S3-17 for qemu-devel@nongnu.org; Mon, 11 Feb 2019 08:05:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtBHO-00047D-1g for qemu-devel@nongnu.org; Mon, 11 Feb 2019 08:05:51 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:51606) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gtBHI-0003qO-FW for qemu-devel@nongnu.org; Mon, 11 Feb 2019 08:05:41 -0500 Received: by mail-wm1-x32b.google.com with SMTP id b11so17638349wmj.1 for ; Mon, 11 Feb 2019 05:05:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2+MelR4KT5S9gb68buZxTVHCeI3TD9oWTrbM+yRenTY=; b=hHeDmCugBbPZlHyB/4VZnGn5j3YZyRXtxTcD6SXB6xEAuJk1GIi48aONj7uvI5s+qT K/e07UdlRNvOYmbspyz/JUqgOG5pSZxI7iqihCl9TcI0Sx7Wo7YckN0QZ1Bytu9S5Va+ cv7L/rK1h8cJ7YdpcTvIbJ7TqlSh73Z/Zu1VKuTWXmxJ7TAm0Lg0Od8WKWMoitsLyn5i WI3WdYR0ssrs2dkivWF0yGgqDyT2Sutyfs9dXmomsiw4giM3wiomfQUIhwQHRhZDWUv5 bOOWYzQEYJQosbE18I4ZLMM9Hzu3uBp+RcZSv22Z5XM7zP8BNt0jdVjyZH96god1AZ73 SeOA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=2+MelR4KT5S9gb68buZxTVHCeI3TD9oWTrbM+yRenTY=; b=cRQwUXm5EbinAe39/vd+MQOABs/hOval7tEoPZr27BlX/L/5sLTMe3TMtbIh/3KFr5 FnLv6y09UBzoj72fvT/u+1QpSLGFLwqUXx4RJuhKfeQJPfs/4Kffzd/TspR6OUWXGfmx QcijCPanRxd3ylb484cqcLY/piLYoWdKLsdKTK+92k07znrSQ3kXLfcCPmVtdVmhK8Rv SsTu86IOtb49nAjnPSEYvRvp4Jg3ki/Yg58rtxOYqPTZOITu5h0m0m/hKB6uwYBOKHtH oyw+aHJe6SF0NB90xvGpcoGCl9rVCT+VwO9Uefmr+uSKcc1BL9c3+LhE24Ex7JC7qDmC HUqg== X-Gm-Message-State: AHQUAua7cEUIm0WqT5GFc78vIZfjXovwqTfx/ESURAvmOhixu0BPkoOX Rr9rQbEtPaM346bo8eRGP5qdfNKw/kU= X-Received: by 2002:a1c:43:: with SMTP id 64mr9928366wma.72.1549890319513; Mon, 11 Feb 2019 05:05:19 -0800 (PST) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id q15sm6472690wmj.46.2019.02.11.05.05.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Feb 2019 05:05:14 -0800 (PST) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 848511FF8A; Mon, 11 Feb 2019 13:05:07 +0000 (UTC) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 11 Feb 2019 13:04:59 +0000 Message-Id: <20190211130507.8710-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211130507.8710-1-alex.bennee@linaro.org> References: <20190211130507.8710-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32b Subject: [Qemu-devel] [PULL 10/18] tests: docker.py be even smarter with persistent binfmt_misc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" If we have a persistent mapping we don't need the QEMU binary copied into the container as the kernel has already opened the file and will pass the fd in. However the support libraries will still need to be there. Signed-off-by: Alex Bennée -- 2.20.1 diff --git a/tests/docker/docker.py b/tests/docker/docker.py index 768728785f..a74338cb61 100755 --- a/tests/docker/docker.py +++ b/tests/docker/docker.py @@ -96,13 +96,22 @@ def _get_so_libs(executable): return libs -def _copy_binary_with_libs(src, dest_dir): - """Copy a binary executable and all its dependent libraries. +def _copy_binary_with_libs(src, bin_dest, dest_dir): + """Maybe copy a binary and all its dependent libraries. + + If bin_dest isn't set we only copy the support libraries because + we don't need qemu in the docker path to run (due to persistent + mapping). Indeed users may get confused if we aren't running what + is in the image. This does rely on the host file-system being fairly multi-arch - aware so the file don't clash with the guests layout.""" + aware so the file don't clash with the guests layout. + """ - _copy_with_mkdir(src, dest_dir, "/usr/bin") + if bin_dest: + _copy_with_mkdir(src, dest_dir, os.path.dirname(bin_dest)) + else: + print("only copying support libraries for %s" % (src)) libs = _get_so_libs(src) if libs: @@ -116,21 +125,26 @@ def _check_binfmt_misc(executable): The details of setting up binfmt_misc are outside the scope of this script but we should at least fail early with a useful - message if it won't work.""" + message if it won't work. + + Returns the configured binfmt path and a valid flag. For + persistent configurations we will still want to copy and dependent + libraries. + """ binary = os.path.basename(executable) binfmt_entry = "/proc/sys/fs/binfmt_misc/%s" % (binary) if not os.path.exists(binfmt_entry): print ("No binfmt_misc entry for %s" % (binary)) - return None + return None, False with open(binfmt_entry) as x: entry = x.read() if re.search("flags:.*F.*\n", entry): print("binfmt_misc for %s uses persistent(F) mapping to host binary\n" % (binary)) - return None + return None, True m = re.search("interpreter (\S+)\n", entry) interp = m.group(1) @@ -138,7 +152,8 @@ def _check_binfmt_misc(executable): print("binfmt_misc for %s does not point to %s, using %s" % (binary, executable, interp)) - return interp + return interp, True + def _read_qemu_dockerfile(img_name): # special case for Debian linux-user images @@ -345,7 +360,8 @@ class BuildCommand(SubCommand): # Validate binfmt_misc will work if args.include_executable: - if not _check_binfmt_misc(args.include_executable): + qpath, enabled = _check_binfmt_misc(args.include_executable) + if not enabled: return 1 # Is there a .pre file to run in the build context? @@ -368,7 +384,9 @@ class BuildCommand(SubCommand): # FIXME: there is no checksum of this executable and the linked # libraries, once the image built any change of this executable # or any library won't trigger another build. - _copy_binary_with_libs(args.include_executable, docker_dir) + _copy_binary_with_libs(args.include_executable, + qpath, docker_dir) + for filename in args.extra_files or []: _copy_with_mkdir(filename, docker_dir) cksum += [(filename, _file_checksum(filename))] @@ -400,14 +418,16 @@ class UpdateCommand(SubCommand): tmp_tar = TarFile(fileobj=tmp, mode='w') # Add the executable to the tarball, using the current - # configured binfmt_misc path. - ff = _check_binfmt_misc(args.executable) - if not ff: - bn = os.path.basename(args.executable) - ff = "/usr/bin/%s" % bn - print ("No binfmt_misc configured: copied to %s" % (ff)) - - tmp_tar.add(args.executable, arcname=ff) + # configured binfmt_misc path. If we don't get a path then we + # only need the support libraries copied + ff, enabled = _check_binfmt_misc(args.executable) + + if not enabled: + print("binfmt_misc not enabled, update disabled") + return 1 + + if ff: + tmp_tar.add(args.executable, arcname=ff) # Add any associated libraries libs = _get_so_libs(args.executable)