From patchwork Tue Dec 22 18:44:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Jackson X-Patchwork-Id: 7906681 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 045E09F349 for ; Tue, 22 Dec 2015 18:48:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1989D20502 for ; Tue, 22 Dec 2015 18:48:11 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 245E7204FC for ; Tue, 22 Dec 2015 18:48:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aBRvy-0001Iz-Vb; Tue, 22 Dec 2015 18:45:18 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aBRvy-0001I4-86 for xen-devel@lists.xensource.com; Tue, 22 Dec 2015 18:45:18 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id 38/97-01753-D3A99765; Tue, 22 Dec 2015 18:45:17 +0000 X-Env-Sender: prvs=791371759=Ian.Jackson@citrix.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1450809915!12303365!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 42128 invoked from network); 22 Dec 2015 18:45:16 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 22 Dec 2015 18:45:16 -0000 X-IronPort-AV: E=Sophos;i="5.20,465,1444694400"; d="scan'208";a="320985060" From: Ian Jackson To: Date: Tue, 22 Dec 2015 18:44:48 +0000 Message-ID: <1450809903-3393-14-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1450809903-3393-1-git-send-email-ian.jackson@eu.citrix.com> References: <1450809903-3393-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Ian Jackson , Wei Liu , Ian Campbell , Stefano Stabellini Subject: [Xen-devel] [PATCH 13/28] libxl: emuids: Record which emuids we have started to create X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Record in xenstore which emulator(s) we have started. Right now this information is not used. The _get_bodgeerrors function is going to be needed in several call sites where errors are currently not handled well. I don't want to try to combine an error handling rework with this series. Signed-off-by: Ian Jackson --- v6: New patch - storing this information here is a new approach in v6. --- docs/misc/xenstore-paths.markdown | 5 +++ tools/libxl/libxl_create.c | 2 ++ tools/libxl/libxl_dm.c | 61 +++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 14 +++++++++ 4 files changed, 82 insertions(+) diff --git a/docs/misc/xenstore-paths.markdown b/docs/misc/xenstore-paths.markdown index 197bb0f..208b64b 100644 --- a/docs/misc/xenstore-paths.markdown +++ b/docs/misc/xenstore-paths.markdown @@ -505,6 +505,11 @@ The guest's virtual time offset from UTC in seconds. The device model version for a domain. +#### ~/libxl/$DOMID/dm-emuidmap = INTEGER + +Which emulator IDs are serving a domain. This is a bitmask of +`1u<emuidmap = 0; + ret = libxl__build_pre(gc, domid, d_config, state); if (ret) goto out; diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 916d12c..2bd1eb0 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -1459,6 +1459,9 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss, goto out; } + ret = libxl__dm_emuidmap_add(gc, guest_domid, d_state, emuid); + if (ret) goto out; + sdss->pvqemu.guest_domid = 0; libxl_domain_create_info_init(&dm_config->c_info); @@ -1801,6 +1804,9 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss, abort(); } + rc = libxl__dm_emuidmap_add(gc, domid, state, emuid); + if (rc) goto out; + dm = libxl__domain_device_model(gc, b_info); if (!dm) { rc = ERROR_FAIL; @@ -2417,6 +2423,61 @@ static void dm_support_check_done(libxl__egc *egc, ch->callback(egc, ch, rc); } +/* emuid recording */ + +static const char *emuidmap_path(libxl__gc *gc, int domid) +{ + return GCSPRINTF("libxl/%d/dm-emuidmap", domid); +} + +int libxl__dm_emuidmap_add(libxl__gc *gc, int domid, + libxl__domain_build_state *bstate, int emuid) +{ + unsigned newflag = 1u << emuid; + + assert(!(bstate->emuidmap & newflag)); + bstate->emuidmap |= newflag; + return libxl__xs_printf(gc, XBT_NULL, emuidmap_path(gc, domid), + "%u", bstate->emuidmap); +} + +int libxl__dm_emuidmap_get(libxl__gc *gc, int domid, + unsigned *emuidmap_r) +{ + const char *s; + int rc; + + rc = libxl__xs_read_checked(gc, XBT_NULL, emuidmap_path(gc, domid), &s); + if (rc) goto out; + + if (!s) { + *emuidmap_r = 0; + return 0; + } + + *emuidmap_r = atoi(s); + return 0; + + out: + return rc; +} + +void libxl__dm_emuidmap_get_bodgeerrors(libxl__gc *gc, int domid, + unsigned *emuidmap_r) +{ + int rc; + + rc = libxl__dm_emuidmap_get(gc, domid, emuidmap_r); + if (rc) { + *emuidmap_r = + (1u << EMUID_DM) | + (1u << EMUID_PV); + LOG(ERROR, +"Failed libxl_dm_emuidmap_get (rc=%d), using %#x (probably a wrong answer)", + rc, *emuidmap_r); + } +} + /* * Local variables: * mode: C diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 71c1e17..0194823 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1097,6 +1097,8 @@ typedef struct { char *saved_state; + unsigned emuidmap; + libxl__file_reference pv_kernel; libxl__file_reference pv_ramdisk; const char * pv_cmdline; @@ -1962,6 +1964,18 @@ enum { /* NB stubdom and its PV service domain not recorded here */ }; +_hidden int libxl__dm_emuidmap_add(libxl__gc*, int domid, + libxl__domain_build_state*, int emuid); + +_hidden int libxl__dm_emuidmap_get(libxl__gc*, int domid, + unsigned *emuidmap_r); + +_hidden void libxl__dm_emuidmap_get_bodgeerrors(libxl__gc*, int domid, + unsigned *emuidmap_r); + /* *emuidmap_r is set to a default (but unreliable) value even + * if we get an error, which is logged. Try to avoid calling + * this if you can! */ + _hidden char *libxl__device_model_xs_path(libxl__gc *gc, uint32_t dm_domid, uint32_t domid, int emuid,