From nobody Sat Nov 23 11:47:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=anthony.perard@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1724753035; cv=none; d=zohomail.com; s=zohoarc; b=D/ckAFzFwIngzKEjFTP9NICZwIwvEU29QCaCESZm4W+yr0xipnHSVcEncnaW6LuYfINu8xH+tukOtgexJyvbKO4eT/WdRK8OEU6ZEJmtYDgM/y1YAz7mb8ya3tEaNeEm4J9g64iaTyDPVxHKwoxYCpCxUi44yQdsMClnsy5m1QM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724753035; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vchDRtHA+TPS5qyWfxue52QEMQPCyUlCs0i9CKru4ng=; b=JtDvbmhdIBCV0+TNOgM5KaY30fZkcomLYUJ266epAUShpOwFrS+o5akYy4skgqtOnZtxd6HPfoI03GV/MCESzHKdlsnDoDnuqKRdA9l1HYZK/Wd571iJ9bjDzdN399iruSeb+P5xhD/k+S66HKfnpiN6ms0ylISEsxicRg+ZkEw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=anthony.perard@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1724753035405376.43913558544307; Tue, 27 Aug 2024 03:03:55 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.783747.1193021 (Exim 4.92) (envelope-from ) id 1sit32-00019J-3N; Tue, 27 Aug 2024 10:03:36 +0000 Received: by outflank-mailman (output) from mailman id 783747.1193021; Tue, 27 Aug 2024 10:03:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sit31-00018N-VQ; Tue, 27 Aug 2024 10:03:35 +0000 Received: by outflank-mailman (input) for mailman id 783747; Tue, 27 Aug 2024 10:03:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sit31-00015r-4l for xen-devel@lists.xenproject.org; Tue, 27 Aug 2024 10:03:35 +0000 Received: from mail187-32.suw11.mandrillapp.com (mail187-32.suw11.mandrillapp.com [198.2.187.32]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9d751753-645b-11ef-99a0-01e77a169b0f; Tue, 27 Aug 2024 12:03:32 +0200 (CEST) Received: from pmta09.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail187-32.suw11.mandrillapp.com (Mailchimp) with ESMTP id 4WtNR74DkRzQXg2bp for ; Tue, 27 Aug 2024 10:03:31 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 2833161555d54724b73db1c6b0865185; Tue, 27 Aug 2024 10:03:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9d751753-645b-11ef-99a0-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1724753011; x=1725013511; bh=vchDRtHA+TPS5qyWfxue52QEMQPCyUlCs0i9CKru4ng=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=TFA8grfojzlr3qxxLXX4gwzAyudtEsXNB+EJ7DxhdMThbWtvUAUNi1gWhYjppxldd TWmJ9i7S8gIjgY1paxJZPGxP0XmQ+wYUL6pOsSlrdYpXVP41nv6ahtk3Xc2yv799z3 iHlt+KXc2yxLBU7XbzoDhwHbGF+ZnH4lJLP713U+Z8mjzndqI3R/bNx40mM1d5E76T WNaqwD+GiL3znCSqssh7Ieb5mobkjuJEj6e7kXzJdl+wkDuGFAz0BqnAsJ90R4Nf8u IGwtwfUQIWuZTYe6cpF5/gZ3kp3OXsiubgsfMbO9YJ95fTNYCmT/nvbTycXLbbq4on 1RSGpqztTvq1g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1724753011; x=1725013511; i=anthony.perard@vates.tech; bh=vchDRtHA+TPS5qyWfxue52QEMQPCyUlCs0i9CKru4ng=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=M+xtCFbDDMU2XyuuJ8tqPHS9eR8yO1wwpyCrb9wua/R6gt8thR4SBMdbT5q2hqFkd 837b0eCGY5CapNWFBAoKenSERaVVlJ4Z9h+9Y6bkEDPu3y5DK7sSDwYQEMZDw4YTmu UuVVXdt2BddwsKQka00va8bg784VRR0LnwmiFLLD8NE8LU8Jku3jgnGX/V8V0ag0yB 4PrNdWdyh4CswNPEGOhzCxZUsbyN0JGet/ai0TmW8kw7f8Z7vasIzkZQR1uxu2r/Mi 8Ypco0BgyebzIgo20usgILAD1W66llsMAlY53WoqDH1gR8O3SBJYwCNSbLSQ/POFnk pAvss3KD/WCeg== From: Anthony PERARD Subject: =?utf-8?Q?[XEN=20PATCH=201/3]=20libxl:=20Implement=20QEMU=20command=20line=20probe?= X-Mailer: git-send-email 2.39.2 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1724753010871 To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Anthony PERARD , Juergen Gross Message-Id: <20240827100328.23216-2-anthony.perard@vates.tech> In-Reply-To: <20240827100328.23216-1-anthony.perard@vates.tech> References: <20240827100328.23216-1-anthony.perard@vates.tech> X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.2833161555d54724b73db1c6b0865185?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20240827:md Date: Tue, 27 Aug 2024 10:03:31 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @mandrillapp.com) (identity anthony.perard@vates.tech) X-ZM-MESSAGEID: 1724753037372116600 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD Starting with QEMU 9.0, the option "-chroot", that we use for the "dmrestrict" feature, is removed. We need to find out which to use between "-chroot" and "-run-with chroot=3Ddir". This patch implement the machinery to spawn QEMU, and to run the QMP command "query-command-line-options" but doesn't yet look at the actual result. Whether or not to use "-run-with chroot=3Ddir" will be implemented in a follow up patch. The command line used to spawn the qemu we want to probe is mostly similar to the one we already use for the device model, "-machine none" comes from libvirt. This patch implement the probing on qemu-xen, even if we probably not going to use the result. We could check the feature wanted for the domain been created, but this could get complicated fairly quickly. We already need to check the options "b_info->dm_restrict" for "-chroot" and "state->dm_runas" for "-runas" (which is deprecated). Signed-off-by: Anthony PERARD Reviewed-by: Jason Andryuk --- tools/libs/light/libxl_dm.c | 207 ++++++++++++++++++++++++++++-- tools/libs/light/libxl_internal.h | 1 + 2 files changed, 198 insertions(+), 10 deletions(-) diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index ff8ddeec9a..46babfed0b 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -2858,6 +2858,20 @@ static void device_model_qmp_cb(libxl__egc *egc, lib= xl__ev_qmp *ev, static void device_model_spawn_outcome(libxl__egc *egc, libxl__dm_spawn_state *dmss, int rc); +static void device_model_probe_startup_failed(libxl__egc *egc, + libxl__spawn_state *spawn, int rc); +static void device_model_probe_confirm(libxl__egc *egc, + libxl__spawn_state *spawn, const char *xsdata); +static void device_model_probe_detached(libxl__egc *egc, + libxl__spawn_state *spawn); +static void device_model_probe_cmdline(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); +static void device_model_probe_quit(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); +static void device_model_probe_spawn_outcome(libxl__egc *egc, + libxl__dm_spawn_state *dmss, int rc); +static void device_model_launch(libxl__egc *egc, + libxl__dm_spawn_state *dmss, int rc); static void device_model_postconfig_chardev(libxl__egc *egc, libxl__ev_qmp *qmp, const libxl__json_object *response, int rc); static void device_model_postconfig_vnc(libxl__egc *egc, @@ -2873,25 +2887,18 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__= dm_spawn_state *dmss) { /* convenience aliases */ const int domid =3D dmss->guest_domid; - libxl__domain_build_state *const state =3D dmss->build_state; libxl__spawn_state *const spawn =3D &dmss->spawn; =20 STATE_AO_GC(dmss->spawn.ao); =20 - libxl_ctx *ctx =3D CTX; libxl_domain_config *guest_config =3D dmss->guest_config; const libxl_domain_create_info *c_info =3D &guest_config->c_info; const libxl_domain_build_info *b_info =3D &guest_config->b_info; - const libxl_vnc_info *vnc =3D libxl__dm_vnc(guest_config); - char *path; - int logfile_w, null; int rc; - char **args, **arg, **envs; - xs_transaction_t t; - char *vm_path; - char **pass_stuff; const char *dm; - int dm_state_fd =3D -1; + int logfile_w =3D -1, null =3D -1; + int qmp_probe_fd =3D -1; + bool probe_spawned =3D false; =20 dmss_init(dmss); =20 @@ -2904,6 +2911,7 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm= _spawn_state *dmss) rc =3D ERROR_FAIL; goto out; } + dmss->dm =3D dm; if (access(dm, X_OK) < 0) { LOGED(ERROR, domid, "device model %s is not executable", dm); rc =3D ERROR_FAIL; @@ -2911,6 +2919,185 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__= dm_spawn_state *dmss) } =20 rc =3D libxl__domain_get_device_model_uid(gc, dmss); + if (rc) + goto out; + + /* probe QEMU's available command line options */ + if (b_info->device_model_version + =3D=3D LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { + + logfile_w =3D libxl__create_qemu_logfile( + gc, GCSPRINTF("qemu-probe-%s", c_info->name)); + if (logfile_w < 0) { + rc =3D logfile_w; + goto out; + } + null =3D open("/dev/null", O_RDONLY); + if (null < 0) { + LOGED(ERROR, domid, "unable to open /dev/null"); + rc =3D ERROR_FAIL; + goto out; + } + + rc =3D libxl__pre_open_qmp_socket(gc, domid, &qmp_probe_fd); + if (rc) goto out; + + flexarray_t *dm_args =3D flexarray_make(gc, 16, 1); + flexarray_vappend(dm_args, dm, + "-S", + "-no-user-config", + "-nodefaults", + "-nographic", + "-machine", "none,accel=3Dxen", + NULL); + flexarray_vappend(dm_args, + "-chardev", + GCSPRINTF("socket,id=3Dlibxl-cmd,fd=3D%d,server= =3Don,wait=3Doff", + qmp_probe_fd), + "-mon", "chardev=3Dlibxl-cmd,mode=3Dcontrol", + NULL); + flexarray_append(dm_args, NULL); + char **exec_args =3D (char **) flexarray_contents(dm_args); + + const char *dom_path =3D libxl__xs_get_dompath(gc, domid); + + spawn->what =3D GCSPRINTF("domain %d qemu command line probe", dom= id); + spawn->xspath =3D "/dev/null"; /* No path to watch */ + spawn->timeout_ms =3D LIBXL_DEVICE_MODEL_START_TIMEOUT * 1000; + spawn->pidpath =3D GCSPRINTF("%s/image/device-model-pid", dom_path= ); + spawn->midproc_cb =3D libxl__spawn_record_pid; + spawn->confirm_cb =3D device_model_probe_confirm; + spawn->failure_cb =3D device_model_probe_startup_failed; + spawn->detached_cb =3D device_model_probe_detached; + + dmss->qmp.ao =3D ao; + dmss->qmp.callback =3D device_model_probe_cmdline; + dmss->qmp.domid =3D domid; + dmss->qmp.payload_fd =3D -1; + rc =3D libxl__ev_qmp_send(egc, &dmss->qmp, "query-command-line-opt= ions", NULL); + if (rc) goto out; + + rc =3D libxl__spawn_spawn(egc, spawn); + if (rc < 0) + goto out; + if (!rc) { /* inner child */ + setsid(); + libxl__exec(gc, null, logfile_w, logfile_w, dm, exec_args, NUL= L); + } + probe_spawned =3D true; + } else { + /* Continue with launching DM instead of probing it */ + probe_spawned =3D false; + } + rc =3D 0; +out: + if (qmp_probe_fd >=3D 0) + close(qmp_probe_fd); + if (null >=3D 0) + close(null); + if (logfile_w >=3D 0) + close(logfile_w); + if (rc || !probe_spawned) + device_model_launch(egc, dmss, rc); +} + +static void device_model_probe_startup_failed(libxl__egc *egc, + libxl__spawn_state *spawn, int rc) +{ + libxl__dm_spawn_state *dmss =3D CONTAINER_OF(spawn, *dmss, spawn); + device_model_probe_spawn_outcome(egc, dmss, rc); +} + +static void device_model_probe_confirm(libxl__egc *egc, + libxl__spawn_state *spawn, const char *xsdata) +{ + /* Nothing to do, confirmation is done via QMP instead */ +} + +static void device_model_probe_detached(libxl__egc *egc, + libxl__spawn_state *spawn) +{ + libxl__dm_spawn_state *dmss =3D CONTAINER_OF(spawn, *dmss, spawn); + device_model_probe_spawn_outcome(egc, dmss, 0); +} + +static void device_model_probe_cmdline(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc) +{ + libxl__dm_spawn_state *dmss =3D CONTAINER_OF(qmp, *dmss, qmp); + + if (rc) + goto out; + + /* + * query-command-line-options response: + * [ { 'option': 'str', 'parameters': [{ 'name': 'str', ... }] } ] + */ + + qmp->callback =3D device_model_probe_quit; + rc =3D libxl__ev_qmp_send(egc, qmp, "quit", NULL); + if (rc) goto out; + return; + +out: + libxl__spawn_initiate_failure(egc, &dmss->spawn, rc); +} + +static void device_model_probe_quit(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc) +{ + EGC_GC; + libxl__dm_spawn_state *dmss =3D CONTAINER_OF(qmp, *dmss, qmp); + + libxl__ev_qmp_dispose(gc, qmp); + libxl__spawn_initiate_detach(gc, &dmss->spawn); +} + +static void device_model_probe_spawn_outcome(libxl__egc *egc, + libxl__dm_spawn_state *dmss, int rc) +{ + EGC_GC; + libxl__ev_qmp_dispose(gc, &dmss->qmp); + + /* Ensure our QEMU command line probe is killed. */ + rc =3D libxl__kill_xs_path(gc, dmss->spawn.pidpath, + "qemu command-line probe"); + if (rc) { + LOGD(WARN, dmss->guest_domid, + "Killing qemu command-line probe pid from path %s", + dmss->spawn.pidpath); + } + + /* + * Ignore all failure from the QEMU command line probe, start the + * device model in any case. + */ + device_model_launch(egc, dmss, 0); +} + +static void device_model_launch(libxl__egc *egc, + libxl__dm_spawn_state *dmss, int rc) +{ + STATE_AO_GC(dmss->spawn.ao); + libxl_ctx *ctx =3D CTX; + libxl_domain_config *guest_config =3D dmss->guest_config; + const libxl_domain_create_info *c_info =3D &guest_config->c_info; + const libxl_domain_build_info *b_info =3D &guest_config->b_info; + const libxl_vnc_info *vnc =3D libxl__dm_vnc(guest_config); + char *path; + int logfile_w, null; + char **args, **arg, **envs; + xs_transaction_t t; + char *vm_path; + char **pass_stuff; + int dm_state_fd =3D -1; + + /* convenience aliases */ + const int domid =3D dmss->guest_domid; + libxl__domain_build_state *const state =3D dmss->build_state; + libxl__spawn_state *const spawn =3D &dmss->spawn; + const char *const dm =3D dmss->dm; + if (rc) goto out; =20 diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index 3b58bb2d7f..e99adc56cb 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4154,6 +4154,7 @@ struct libxl__dm_spawn_state { libxl__ev_qmp qmp; libxl__ev_time timeout; libxl__dm_resume_state dmrs; + const char *dm; /* filled in by user, must remain valid: */ uint32_t guest_domid; /* domain being served */ libxl_domain_config *guest_config; --=20 Anthony Perard | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Sat Nov 23 11:47:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=anthony.perard@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1724753037; cv=none; d=zohomail.com; s=zohoarc; b=dKQ20w8xNav3VjqXvT0ef3V+uv2vvMyUH92C94OQf9DDkE7van+PO3YjLcPSysI5jolIvbg0td2It3jjix1aXmpbuxOcsmcH4ve7QPca8Q6ml3jbaLzF/obGAkH+pordiGfMBczoY0Ma40/FF/P4me4BE9blkVsgxAtiZrmDFYM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724753037; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vvEWgBFkpI/68BpBe5Mn7aZ1DJf2R7AOv5a1MvGUyAA=; b=BrsgTDJr/7+QuYuK/A5IkDTldxhzIThhBx8xLOHOtRGUsUl7iaG7gSSiWbziQsXXZKG6OKwyGWw2v+dM2i3XHwD5ES7Sb6wuIvWcby1z3Yz5BBe+fPsnAjtR1h11zh7C0Y3eGzgtklcdBPeeV2NAhvf5aGRO43l4pKE59CvwkD8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=anthony.perard@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1724753037193498.01540676088075; Tue, 27 Aug 2024 03:03:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.783749.1193045 (Exim 4.92) (envelope-from ) id 1sit33-0001lb-KX; Tue, 27 Aug 2024 10:03:37 +0000 Received: by outflank-mailman (output) from mailman id 783749.1193045; Tue, 27 Aug 2024 10:03:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sit33-0001kL-FO; Tue, 27 Aug 2024 10:03:37 +0000 Received: by outflank-mailman (input) for mailman id 783749; Tue, 27 Aug 2024 10:03:36 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sit32-00015q-4r for xen-devel@lists.xenproject.org; Tue, 27 Aug 2024 10:03:36 +0000 Received: from mail187-32.suw11.mandrillapp.com (mail187-32.suw11.mandrillapp.com [198.2.187.32]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9e8b35ea-645b-11ef-a0b0-8be0dac302b0; Tue, 27 Aug 2024 12:03:34 +0200 (CEST) Received: from pmta09.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail187-32.suw11.mandrillapp.com (Mailchimp) with ESMTP id 4WtNR74fkXzQXg2py for ; Tue, 27 Aug 2024 10:03:31 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 1b2f93cb1b2c4edb8d0fe7e4878e8374; Tue, 27 Aug 2024 10:03:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9e8b35ea-645b-11ef-a0b0-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1724753011; x=1725013511; bh=vvEWgBFkpI/68BpBe5Mn7aZ1DJf2R7AOv5a1MvGUyAA=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=w0ve9mAV0x6jz6gRVgHuDXjyIGyXaNCA99uKIn/XC6NVvM5s4mZ28+AeKSVxmnlt+ EMNHe8WlocQfLl7T0TVftzmPkSEpt5Or3N4DdcEuevRIcObvmXYo5fZQwwFE9Ql0W/ vvDYJL1rccDRGgHWXXm0sLHoNhExmNX41SetfyHdjgdj/+pFuCzku5/mgXO69dB3sp b4NDlyfxKjQB+w5gb90LdC1CTFn7CX7+idOnEk6TwC7vKClO1QnmKLx/Rblwwve7G8 /5AcaiLZf+GLvTZpAjrXS7dDD0McM4uOBtLw4kKZVlL0lM72cZ64Nb/IPt3jlJQXdl c06/l4FI/fJSw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1724753011; x=1725013511; i=anthony.perard@vates.tech; bh=vvEWgBFkpI/68BpBe5Mn7aZ1DJf2R7AOv5a1MvGUyAA=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=XIFof5/mrgROYPkoIhrRSMVqLmf9KL71fv925M3LPb4y2T67KEyMz6ENGqdImWLhS ooFzV+jkT5r98DV1anXVUaD7EoGeRGmdeNQUD9x6jLcFjZJc/Ryjxpb5dnoXY/Eh6w iz6b4e1+UT4m1YQ59EoqgTJ1VupzvrA6EdLSgThIKkrLLdGJK25FQkZ93IF03kEPVr Hz6+XATM5fJapS60fCnUZh/UWHbt3WUYwwV/VtHThu7FIWWAhiHoAuWq7cgqz0ZKqp wfIXIMPYcjiZAHSHYfovfM4wvgmhWkybpWxEJF6q0yGNGf85wz5KAglYTDR0HKHq4j 5axScOsyJTeGQ== From: Anthony PERARD Subject: =?utf-8?Q?[XEN=20PATCH=202/3]=20libxl:=20Probe=20QEMU=20for=20-run-with=20chroot=3Ddir=20and=20use=20it?= X-Mailer: git-send-email 2.39.2 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1724753011205 To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Juergen Gross Message-Id: <20240827100328.23216-3-anthony.perard@vates.tech> In-Reply-To: <20240827100328.23216-1-anthony.perard@vates.tech> References: <20240827100328.23216-1-anthony.perard@vates.tech> X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.1b2f93cb1b2c4edb8d0fe7e4878e8374?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20240827:md Date: Tue, 27 Aug 2024 10:03:31 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity anthony.perard@vates.tech) (identity @mandrillapp.com) X-ZM-MESSAGEID: 1724753039314116600 Content-Type: text/plain; charset="utf-8" QEMU 9.0 have removed "-chroot" command line option, which have been deprecated since QEMU 8.1 in favor of "-run-with chroot=3Ddir". Look into the result of the QMP command "query-command-line-options" to find out if "-run-with chroot=3Ddir" is available. Then use it in place of "-chroot". Resolves: xen-project/xen#187 Signed-off-by: Anthony PERARD Reviewed-by: Jason Andryuk --- tools/libs/light/libxl_dm.c | 78 +++++++++++++++++++++++++------ tools/libs/light/libxl_internal.h | 5 ++ 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index 46babfed0b..298fbb84fe 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -1183,11 +1183,12 @@ static int libxl__pre_open_qmp_socket(libxl__gc *gc= , libxl_domid domid, } =20 static int libxl__build_device_model_args_new(libxl__gc *gc, - const char *dm, int guest_domid, - const libxl_domain_config *guest_c= onfig, - char ***args, char ***envs, - const libxl__domain_build_state *s= tate, - int *dm_state_fd) + const char *dm, int guest_domid, + const libxl_domain_config *guest_config, + char ***args, char ***envs, + const libxl__domain_build_state *state, + const libxl__qemu_available_cmd_line *qemu_cmdline, + int *dm_state_fd) { const libxl_domain_create_info *c_info =3D &guest_config->c_info; const libxl_domain_build_info *b_info =3D &guest_config->b_info; @@ -1778,8 +1779,13 @@ static int libxl__build_device_model_args_new(libxl_= _gc *gc, } =20 /* Add "-chroot [dir]" to command-line */ - flexarray_append(dm_args, "-chroot"); - flexarray_append(dm_args, chroot_dir); + if (qemu_cmdline->have_runwith_chroot) { + flexarray_append_pair(dm_args, "-run-with", + GCSPRINTF("chroot=3D%s", chroot_dir)); + } else { + flexarray_append(dm_args, "-chroot"); + flexarray_append(dm_args, chroot_dir); + } } =20 if (state->saved_state) { @@ -2059,11 +2065,12 @@ static int libxl__build_device_model_args_new(libxl= __gc *gc, } =20 static int libxl__build_device_model_args(libxl__gc *gc, - const char *dm, int guest_domid, - const libxl_domain_config *guest_c= onfig, - char ***args, char ***envs, - const libxl__domain_build_state *s= tate, - int *dm_state_fd) + const char *dm, int guest_domid, + const libxl_domain_config *guest_config, + char ***args, char ***envs, + const libxl__domain_build_state *state, + const libxl__qemu_available_cmd_line *qemu_cmdline, + int *dm_state_fd) /* dm_state_fd may be NULL iff caller knows we are using stubdom * and therefore will be passing a filename rather than a fd. */ { @@ -2081,7 +2088,9 @@ static int libxl__build_device_model_args(libxl__gc *= gc, return libxl__build_device_model_args_new(gc, dm, guest_domid, guest_confi= g, args, envs, - state, dm_state_fd); + state, + qemu_cmdline, + dm_state_fd); default: LOGED(ERROR, guest_domid, "unknown device model version %d", guest_config->b_info.device_model_version); @@ -2403,7 +2412,9 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stu= b_dm_spawn_state *sdss) =20 ret =3D libxl__build_device_model_args(gc, "stubdom-dm", guest_domid, guest_config, &args, NULL, - d_state, NULL); + d_state, + &sdss->dm.qemu_cmdline, + NULL); if (ret) { ret =3D ERROR_FAIL; goto out; @@ -3024,6 +3035,7 @@ static void device_model_probe_detached(libxl__egc *e= gc, static void device_model_probe_cmdline(libxl__egc *egc, libxl__ev_qmp *qmp, const libxl__json_object *response, int rc) { + EGC_GC; libxl__dm_spawn_state *dmss =3D CONTAINER_OF(qmp, *dmss, qmp); =20 if (rc) @@ -3033,6 +3045,43 @@ static void device_model_probe_cmdline(libxl__egc *e= gc, * query-command-line-options response: * [ { 'option': 'str', 'parameters': [{ 'name': 'str', ... }] } ] */ + const libxl__json_object *option; + for (int i_option =3D 0; + (option =3D libxl__json_array_get(response, i_option)); + i_option++) { + const libxl__json_object *o; + const char *opt_str; + + o =3D libxl__json_map_get("option", option, JSON_STRING); + if (!o) { + rc =3D ERROR_QEMU_API; + goto out; + } + opt_str =3D libxl__json_object_get_string(o); + + if (!strcmp("run-with", opt_str)) { + const libxl__json_object *params; + const libxl__json_object *item; + + params =3D libxl__json_map_get("parameters", option, JSON_ARRA= Y); + for (int i =3D 0; (item =3D libxl__json_array_get(params, i));= i++) { + o =3D libxl__json_map_get("name", item, JSON_STRING); + if (!o) { + rc =3D ERROR_QEMU_API; + goto out; + } + if (!strcmp("chroot", libxl__json_object_get_string(o))) { + dmss->qemu_cmdline.have_runwith_chroot =3D true; + } + } + + /* + * No need to parse more options, we are only interested with + * -run-with at the moment. + */ + break; + } + } =20 qmp->callback =3D device_model_probe_quit; rc =3D libxl__ev_qmp_send(egc, qmp, "quit", NULL); @@ -3113,6 +3162,7 @@ static void device_model_launch(libxl__egc *egc, =20 rc =3D libxl__build_device_model_args(gc, dm, domid, guest_config, &args, &envs, state, + &dmss->qemu_cmdline, &dm_state_fd); if (rc) goto out; diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index e99adc56cb..df93d904c2 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4142,6 +4142,10 @@ _hidden void libxl__add_nics(libxl__egc *egc, libxl_= _ao *ao, uint32_t domid, /* First layer; wraps libxl__spawn_spawn. */ =20 typedef struct libxl__dm_spawn_state libxl__dm_spawn_state; +typedef struct libxl__qemu_available_cmd_line libxl__qemu_available_cmd_li= ne; +struct libxl__qemu_available_cmd_line { + bool have_runwith_chroot; +}; =20 typedef void libxl__dm_spawn_cb(libxl__egc *egc, libxl__dm_spawn_state*, int rc /* if !0, error was logged */); @@ -4154,6 +4158,7 @@ struct libxl__dm_spawn_state { libxl__ev_qmp qmp; libxl__ev_time timeout; libxl__dm_resume_state dmrs; + libxl__qemu_available_cmd_line qemu_cmdline; const char *dm; /* filled in by user, must remain valid: */ uint32_t guest_domid; /* domain being served */ --=20 Anthony Perard | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech From nobody Sat Nov 23 11:47:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=anthony.perard@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=vates.tech ARC-Seal: i=1; a=rsa-sha256; t=1724753031; cv=none; d=zohomail.com; s=zohoarc; b=PAoQcqOdYSW/DVQTdhplY1ypmCpGHcy6JGXpm7AfTjyIUCQPivpBXNqsc7xMlZ+6X+pbeeLmgWsOJTaj0ulMNhOLpVhdASDdsPwWjL4NJhTO3PwhbR7UYa0tFO5+CVAHRnXt1W7cn9Vcdka9kO+kLvDUjj281JYswwe08y4f7pA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1724753031; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7a7nuSCUMb6yGcZ2VY1VCSVSooNS7myyKwj7gupd9Sg=; b=SuOeEU0LYw893ellFfHX1UsP1Cpjp9RXqHi0nVAFZxAV2J/j9gjMUsys1Mz9QFGUgyOsAZD7MxC86CoJhde2xA585kiixBgdh/zncYKShR6bszPeLJ5+kcNSQoFArmh8ucCBgequGWViYZEPkPKmOKkCAr3froKV0CSdiLVo5PY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=anthony.perard@vates.tech; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1724753031886782.8514121407807; Tue, 27 Aug 2024 03:03:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.783748.1193029 (Exim 4.92) (envelope-from ) id 1sit32-0001EO-Dl; Tue, 27 Aug 2024 10:03:36 +0000 Received: by outflank-mailman (output) from mailman id 783748.1193029; Tue, 27 Aug 2024 10:03:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sit32-0001An-5P; Tue, 27 Aug 2024 10:03:36 +0000 Received: by outflank-mailman (input) for mailman id 783748; Tue, 27 Aug 2024 10:03:35 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sit31-00015q-61 for xen-devel@lists.xenproject.org; Tue, 27 Aug 2024 10:03:35 +0000 Received: from mail137-25.atl71.mandrillapp.com (mail137-25.atl71.mandrillapp.com [198.2.137.25]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 9e1e1761-645b-11ef-a0b0-8be0dac302b0; Tue, 27 Aug 2024 12:03:33 +0200 (CEST) Received: from pmta07.mandrill.prod.atl01.rsglab.com (localhost [127.0.0.1]) by mail137-25.atl71.mandrillapp.com (Mailchimp) with ESMTP id 4WtNR76f1nz35hVnw for ; Tue, 27 Aug 2024 10:03:31 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 7a4fed8f626b46239c7b9e69b01f9ae2; Tue, 27 Aug 2024 10:03:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9e1e1761-645b-11ef-a0b0-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1724753011; x=1725013511; bh=7a7nuSCUMb6yGcZ2VY1VCSVSooNS7myyKwj7gupd9Sg=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=BGl8ryRR8i+E7ZDBck6IQcBpLcF7nJhe9aNl7Atc7IPLP5tJve2KWslIHkZhrNSpt FBqu3KVR+wKIk1YoqQof2d2XmmgNGag2tzWa9KxmYZfJN4K5sAddc4X2GTya+C0z+n 5u3O2EiihYVjoqlImseIYDzlWIn1evXFJmQ2bmfs5Y+C6ogF4bNK3xmxOzA5eyhh/O LF2vnRuXr/FsdjrMHiG2mUvDGFUnfOM0xv013wa/1UTuFlybQUcYsy8q5ncmpwKV3L uDw3c6VMVFm58oSpcyqXQWougpegSvtCtOuvkJWbUTomErFlyF8doih1DqxlQbzpGc BJRQncYbAJ7ow== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1724753011; x=1725013511; i=anthony.perard@vates.tech; bh=7a7nuSCUMb6yGcZ2VY1VCSVSooNS7myyKwj7gupd9Sg=; h=From:Subject:To:Cc:Message-Id:In-Reply-To:References:Feedback-ID: Date:MIME-Version:Content-Type:Content-Transfer-Encoding:CC:Date: Subject:From; b=PxNbPq0ciuLpzcFi2jahKY47ZkV3O+eLoj7WjM0TS3f4tMY687kk7L2Je0U8907ZX 1Nwdo00OUAWYyovSKthcRagcR6oze3zcrUFMIIEdi0u+MtGnHvsilE5g7CeaFeGeeX RdMn3N2ipWooszNxQkKFbGr1TdYkl+6f5Z44Dga64qfEC8ahJRh+d8HEpIfyuu6HbA 8UrktSRjdT6e2vJzOgffTJZ0BSlPyZrSQ+P8Af8OF/aLEoVq5MzCo0aDPclGRGelDm hvzEMQJVFIZXTQs+WLfgpNzlm1c6wEmIfW+tN1B9SYbPrhiPzf1t5EZ1tQaLW55lbt loSlDQDBRChxg== From: Anthony PERARD Subject: =?utf-8?Q?[XEN=20PATCH=203/3]=20libxl:=20Probe=20QEMU=20for=20-run-with=20user=3Duser=20and=20use=20it?= X-Mailer: git-send-email 2.39.2 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1724753011426 To: xen-devel@lists.xenproject.org Cc: Anthony PERARD , Juergen Gross Message-Id: <20240827100328.23216-4-anthony.perard@vates.tech> In-Reply-To: <20240827100328.23216-1-anthony.perard@vates.tech> References: <20240827100328.23216-1-anthony.perard@vates.tech> X-Native-Encoded: 1 X-Report-Abuse: =?UTF-8?Q?Please=20forward=20a=20copy=20of=20this=20message,=20including=20all=20headers,=20to=20abuse@mandrill.com.=20You=20can=20also=20report=20abuse=20here:=20https://mandrillapp.com/contact/abuse=3Fid=3D30504962.7a4fed8f626b46239c7b9e69b01f9ae2?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20240827:md Date: Tue, 27 Aug 2024 10:03:31 +0000 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity anthony.perard@vates.tech) (identity @mandrillapp.com) X-ZM-MESSAGEID: 1724753033270116600 Content-Type: text/plain; charset="utf-8" "-runas" is deprecated since QEMU 9.1 and will be remove in a future release. Signed-off-by: Anthony PERARD Reviewed-by: Jason Andryuk --- tools/libs/light/libxl_dm.c | 12 ++++++++++-- tools/libs/light/libxl_internal.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/libs/light/libxl_dm.c b/tools/libs/light/libxl_dm.c index 298fbb84fe..49995b14b8 100644 --- a/tools/libs/light/libxl_dm.c +++ b/tools/libs/light/libxl_dm.c @@ -2052,8 +2052,13 @@ static int libxl__build_device_model_args_new(libxl_= _gc *gc, } =20 if (state->dm_runas) { - flexarray_append(dm_args, "-runas"); - flexarray_append(dm_args, state->dm_runas); + if (qemu_cmdline->have_runwith_user) { + flexarray_append_pair(dm_args, "-run-with", + GCSPRINTF("user=3D%s", state->dm_run= as)); + } else { + flexarray_append(dm_args, "-runas"); + flexarray_append(dm_args, state->dm_runas); + } } } flexarray_append(dm_args, NULL); @@ -3073,6 +3078,9 @@ static void device_model_probe_cmdline(libxl__egc *eg= c, if (!strcmp("chroot", libxl__json_object_get_string(o))) { dmss->qemu_cmdline.have_runwith_chroot =3D true; } + else if (!strcmp("user", libxl__json_object_get_string(o))= ) { + dmss->qemu_cmdline.have_runwith_user =3D true; + } } =20 /* diff --git a/tools/libs/light/libxl_internal.h b/tools/libs/light/libxl_int= ernal.h index df93d904c2..5c61050f79 100644 --- a/tools/libs/light/libxl_internal.h +++ b/tools/libs/light/libxl_internal.h @@ -4145,6 +4145,7 @@ typedef struct libxl__dm_spawn_state libxl__dm_spawn_= state; typedef struct libxl__qemu_available_cmd_line libxl__qemu_available_cmd_li= ne; struct libxl__qemu_available_cmd_line { bool have_runwith_chroot; + bool have_runwith_user; }; =20 typedef void libxl__dm_spawn_cb(libxl__egc *egc, libxl__dm_spawn_state*, --=20 Anthony Perard | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech