From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id bkmRE0nfc2HKGQAAgWs5BA (envelope-from ) for ; Sat, 23 Oct 2021 12:09:13 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id kAW2Dknfc2EENAAAbx9fmQ (envelope-from ) for ; Sat, 23 Oct 2021 10:09:13 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id F15C2162F8 for ; Sat, 23 Oct 2021 12:09:12 +0200 (CEST) Received: from localhost ([::1]:38530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meDxg-0000NW-6J for larch@yhetil.org; Sat, 23 Oct 2021 06:09:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meDxW-0000NJ-IS for guix-patches@gnu.org; Sat, 23 Oct 2021 06:09:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:51115) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1meDxV-0007TO-Vv for guix-patches@gnu.org; Sat, 23 Oct 2021 06:09:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1meDxV-0004RF-R2 for guix-patches@gnu.org; Sat, 23 Oct 2021 06:09:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51347] [PATCH] gnu: qemu: Add Guix support to QEMU guest agent. Resent-From: Timotej Lazar Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 23 Oct 2021 10:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51347 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51347@debbugs.gnu.org Cc: Timotej Lazar X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.163498368816979 (code B ref -1); Sat, 23 Oct 2021 10:09:01 +0000 Received: (at submit) by debbugs.gnu.org; 23 Oct 2021 10:08:08 +0000 Received: from localhost ([127.0.0.1]:34422 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meDwY-0004Ph-1s for submit@debbugs.gnu.org; Sat, 23 Oct 2021 06:08:08 -0400 Received: from lists.gnu.org ([209.51.188.17]:41916) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meDwV-0004PI-LR for submit@debbugs.gnu.org; Sat, 23 Oct 2021 06:08:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meDwV-0008Vx-Hi for guix-patches@gnu.org; Sat, 23 Oct 2021 06:07:59 -0400 Received: from araneo.si ([2001:15c0:2110:3400::2]:56056) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meDwS-0004jq-VT for guix-patches@gnu.org; Sat, 23 Oct 2021 06:07:59 -0400 Received: from araneo.si (localhost.lan [127.0.0.1]) by araneo.si (OpenSMTPD) with ESMTP id 64f41fcd for ; Sat, 23 Oct 2021 10:07:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=araneo.si; h=from:to:cc :subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=20180623; bh=OJRi7ZZ+cNUKx/FDehu5x dxfJ8E=; b=TLn6nL6qiiNfni4SADWLMBh/kLhKqWJ8b1+1ASlOJiV2MGMe7+cVk 8JnFNmcuPnr5UYJQNNDDGeNHmVxELNuOXB6cEFO2Zus95k0C7+G/E79X2LD5uI24 z3esNacKIwHHYwoR8MuX/LZmNlDWo+sFqeK1ml5B1DD9yLSPFq6xqapLobVXiLTu Y4sr/UaYJ1kWBGBu6+89BrPaDTN9R/ViD8qW4HosTvYblZ68wt3V5PU74QfvraRa 9biHlCH4aTjbORUeMYevjFV2PZEk0L7iKndnOSb06czSsiXRGky6sBs+1O4S3qW2 sC7rYqO6qrch7y6CkraXu4Gun6w/RrjiQ== Received: by araneo.si (OpenSMTPD) with ESMTPSA id d9e5457b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 23 Oct 2021 10:07:52 +0000 (UTC) From: Timotej Lazar Date: Sat, 23 Oct 2021 12:03:18 +0200 Message-Id: <20211023100317.17718-1-timotej.lazar@araneo.si> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2001:15c0:2110:3400::2; envelope-from=timotej.lazar@araneo.si; helo=araneo.si X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1634983753; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=cGJz2/NLx27iOoer98ACO6IbgbY1DaR9ONLCRp6OyiY=; b=SKsRHp/xY/826cnaDciF1fCIaAKOs7fSfzO4V3GP873L6/Xyc+QZj2/REv7A3kxD7y5fY9 qK5g/mFnCf58ppayBVlWwEPB39htOckzi3Yxg6qzuDhSBGk23gOy5Q9mVxh/AkRdy6Kzy3 ys/nSl4E2fnYPtyu/jFJCLodrOwyVd86py9FJDAQFNxDG76rd/ZG2a0ZtFz7rnWwtpX4rp FZJJfw5kCd4tL/nyJlKaZ2sLkyKFgsQJC65opeWtQjdWNJ+/S7LmB9uwbzmMTmRHDCw9Tk q+PUomD4yfSh5rwU7TURNnOBFIODnbE1apmm9oK6tCCOHhu2sriF72bUv9M9wg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1634983753; a=rsa-sha256; cv=none; b=j9y7sKSV+xa6x00ojhzrz1sg95Tv2VDn+xePPs33UY9Mef7aTys0/p0rtociEIbn4SLPrA OFzYj9Kg3CI6gp/lADOd2RNcxdKRab1hO51vcFNcHns52HByk29cA2/SnbWfG57LdSi4kZ 34cQMNbwzl5U6LrKSdccQVEaoh8rmJ2PSr70NZdMdX5g7JpUZ0IVmm6YRYW8MMeGIMpK8p LXLim52ik8yDHh7taMkO8zloQg1T2qDcJlEYKUGgY4zMJUPEbSv3QEkBYH+iE/UZLeleAK rgdW9x0jhq97tbIiSPP3lkHXzgNPB95Yq4wqkC8GcCkzDL2x995LZjzVT+zsvQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=araneo.si header.s=20180623 header.b=TLn6nL6q; dmarc=fail reason="SPF not aligned (relaxed)" header.from=araneo.si (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 1.17 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=araneo.si header.s=20180623 header.b=TLn6nL6q; dmarc=fail reason="SPF not aligned (relaxed)" header.from=araneo.si (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: F15C2162F8 X-Spam-Score: 1.17 X-Migadu-Scanner: scn0.migadu.com X-TUID: NlVnknuXmU1l QEMU guest agent hardcodes paths to /sbin/hwclock and /sbin/shutdown. Patch the source to try binaries under /run/current-system/profile/sbin first. * gnu/packages/patches/qemu-fix-agent-paths.patch: New file. * gnu/local.mk (dist_patch_DATA): Register the patch. * gnu/packages/virtualization.scm (qemu)[origin]: Apply it. --- This allows a QEMU host to set the time and shutdown Guix guests. Styled after the patch from the Nix package: https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/virtualization/qemu/fix-qemu-ga.patch Thanks! gnu/local.mk | 1 + .../patches/qemu-fix-agent-paths.patch | 61 +++++++++++++++++++ gnu/packages/virtualization.scm | 3 +- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 gnu/packages/patches/qemu-fix-agent-paths.patch diff --git a/gnu/local.mk b/gnu/local.mk index d432829e2d..9a900e7c30 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1707,6 +1707,7 @@ dist_patch_DATA = \ %D%/packages/patches/qemu-CVE-2021-20203.patch \ %D%/packages/patches/qemu-glibc-2.27.patch \ %D%/packages/patches/qemu-glibc-2.30.patch \ + %D%/packages/patches/qemu-fix-agent-paths.patch \ %D%/packages/patches/qpdfview-qt515-compat.patch \ %D%/packages/patches/qrcodegen-cpp-make-install.patch \ %D%/packages/patches/qt4-ldflags.patch \ diff --git a/gnu/packages/patches/qemu-fix-agent-paths.patch b/gnu/packages/patches/qemu-fix-agent-paths.patch new file mode 100644 index 0000000000..22cf883a8d --- /dev/null +++ b/gnu/packages/patches/qemu-fix-agent-paths.patch @@ -0,0 +1,61 @@ +diff --git a/qga/commands-posix.c b/qga/commands-posix.c +index 75dbaab..b416b03 100644 +--- a/qga/commands-posix.c ++++ b/qga/commands-posix.c +@@ -84,6 +84,7 @@ static void ga_wait_child(pid_t pid, int *status, Error **errp) + void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) + { + const char *shutdown_flag; ++ const char *command; + Error *local_err = NULL; + pid_t pid; + int status; +@@ -91,10 +92,13 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) + slog("guest-shutdown called, mode: %s", mode); + if (!has_mode || strcmp(mode, "powerdown") == 0) { + shutdown_flag = "-P"; ++ command = "shutdown"; + } else if (strcmp(mode, "halt") == 0) { + shutdown_flag = "-H"; ++ command = "halt"; + } else if (strcmp(mode, "reboot") == 0) { + shutdown_flag = "-r"; ++ command = "reboot"; + } else { + error_setg(errp, + "mode is invalid (valid values are: halt|powerdown|reboot"); +@@ -109,6 +113,11 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) + reopen_fd_to_null(1); + reopen_fd_to_null(2); + ++ /* try Guix’s shutdown/halt/reboot first */ ++ char *path = g_strdup_printf("/run/current-system/profile/sbin/%s", command); ++ execle(path, command, (char *)NULL, environ); ++ g_free(path); ++ + execle("/sbin/shutdown", "shutdown", "-h", shutdown_flag, "+0", + "hypervisor initiated shutdown", (char *)NULL, environ); + _exit(EXIT_FAILURE); +@@ -158,10 +167,12 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) + Error *local_err = NULL; + struct timeval tv; + static const char hwclock_path[] = "/sbin/hwclock"; ++ static const char hwclock_path_guix[] = "/run/current-system/profile/sbin/hwclock"; + static int hwclock_available = -1; + + if (hwclock_available < 0) { +- hwclock_available = (access(hwclock_path, X_OK) == 0); ++ hwclock_available = (access(hwclock_path_guix, X_OK) == 0) || ++ (access(hwclock_path, X_OK) == 0); + } + + if (!hwclock_available) { +@@ -207,6 +218,8 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) + + /* Use '/sbin/hwclock -w' to set RTC from the system time, + * or '/sbin/hwclock -s' to set the system time from RTC. */ ++ execle(hwclock_path_guix, "hwclock", has_time ? "-w" : "-s", ++ NULL, environ); + execle(hwclock_path, "hwclock", has_time ? "-w" : "-s", + NULL, environ); + _exit(EXIT_FAILURE); diff --git a/gnu/packages/virtualization.scm b/gnu/packages/virtualization.scm index fb6e8ebfa3..fd778e21a4 100644 --- a/gnu/packages/virtualization.scm +++ b/gnu/packages/virtualization.scm @@ -159,7 +159,8 @@ (define-public qemu (base32 "15iw7982g6vc4jy1l9kk1z9sl5bm1bdbwr74y7nvwjs1nffhig7f")) (patches (search-patches "qemu-CVE-2021-20203.patch" - "qemu-build-info-manual.patch")) + "qemu-build-info-manual.patch" + "qemu-fix-agent-paths.patch")) (modules '((guix build utils))) (snippet '(begin -- 2.33.1