From patchwork Tue May 14 07:27:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 10942365 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 226B6933 for ; Tue, 14 May 2019 07:30:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04C3528455 for ; Tue, 14 May 2019 07:30:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6096284A5; Tue, 14 May 2019 07:30:01 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8E7C328455 for ; Tue, 14 May 2019 07:30:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQRqu-00054Y-5o; Tue, 14 May 2019 07:27:56 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQRqt-00054T-25 for xen-devel@lists.xenproject.org; Tue, 14 May 2019 07:27:55 +0000 X-Inumbo-ID: c8789d40-7619-11e9-8980-bc764e045a96 Received: from mo6-p00-ob.smtp.rzone.de (unknown [2a01:238:20a:202:5300::1]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id c8789d40-7619-11e9-8980-bc764e045a96; Tue, 14 May 2019 07:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1557818871; s=strato-dkim-0002; d=aepfle.de; h=Message-Id:Date:Subject:Cc:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=Z+/W6qAnPWdbvmNiT7UZIi6BFUT8XPMx97FjAvRopH8=; b=Z2K0OHAhTHk0skLTsGnRT3scj2NnIz7AFu1MyP/b8z3z3AHF+B10sIKbAQ5tarNtFG TpaUhCRH7lAWWLIsyKwtThaMvFGsOAFYDKun/jTjzE+uML9JLaeXb3PEnsRB+xfd4bTY nOq8iMnNmn2n+zEoNl7IcVbIxT7c65XA2fm+kEpM3A+vMh+V7dHlDUB1RrTKFPLtwrlU Vaw+mltYKJG0FbSMA76pxNOjXihTF7tHm2D78F55wt6qCDSnGeBi/np/2euPNXseg6k4 QKqDR3Dq8UYyOJlhZ3sJRnsRsbU5jlRYeYmJglpso42APNcHLAhA6Im/zC37FWAZmhdW AffQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3GpFjw==" X-RZG-CLASS-ID: mo00 Received: from sender by smtp.strato.de (RZmta 44.20 DYNA|AUTH) with ESMTPSA id U080cav4E7Rh4AY (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Tue, 14 May 2019 09:27:43 +0200 (CEST) From: Olaf Hering To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 09:27:41 +0200 Message-Id: <20190514072741.11760-1-olaf@aepfle.de> X-Mailer: git-send-email 2.16.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v1] libxl: add helper function to set device_model_version X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Olaf Hering , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP An upcoming change will set the value of device_model_version properly also for the non-HVM case. Move existing code to new function libxl__domain_set_device_model. Move also initialization for device_model_stubdomain to that function. Make sure libxl__domain_build_info_setdefault is called with device_model_version set. Update libxl__spawn_stub_dm() and initiate_domain_create() to call the new function prior libxl__domain_build_info_setdefault() because device_mode_version is expected to be initialzed. libxl_domain_need_memory() needs no update because it does not have a d_config available anyway, and the callers provide a populated b_info. Signed-off-by: Olaf Hering Reviewed-by: Roger Pau Monné Acked-by: Wei Liu --- tools/libxl/libxl_create.c | 90 +++++++++++++++++++++++++++----------------- tools/libxl/libxl_dm.c | 2 + tools/libxl/libxl_internal.h | 2 + 3 files changed, 59 insertions(+), 35 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 89fe80fc9c..3f0431cc84 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -27,6 +27,53 @@ #include +int libxl__domain_set_device_model(libxl__gc *gc, libxl_domain_config *d_config) +{ + libxl_domain_build_info *b_info = &d_config->b_info; + int ret; + + libxl_defbool_setdefault(&b_info->device_model_stubdomain, false); + + if (b_info->device_model_version) + return 0; + + switch (b_info->type) { + case LIBXL_DOMAIN_TYPE_HVM: + if (libxl_defbool_val(b_info->device_model_stubdomain)) { + b_info->device_model_version = + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; + } else { + b_info->device_model_version = libxl__default_device_model(gc); + } + break; + default: + b_info->device_model_version = + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; + break; + } + + if (b_info->device_model_version == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { + const char *dm; + + dm = libxl__domain_device_model(gc, b_info); + ret = access(dm, X_OK); + if (ret < 0) { + /* qemu-xen unavailable, use qemu-xen-traditional */ + if (errno == ENOENT) { + LOGE(INFO, "qemu-xen is unavailable" + ", using qemu-xen-traditional instead"); + b_info->device_model_version = + LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; + } else { + LOGE(ERROR, "qemu-xen access error"); + return ERROR_FAIL; + } + } + } + + return 0; +} + int libxl__domain_create_info_setdefault(libxl__gc *gc, libxl_domain_create_info *c_info) { @@ -73,6 +120,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, return ERROR_INVAL; } + assert(b_info->device_model_version); + /* Copy deprecated options to it's new position. */ rc = libxl__domain_build_info_copy_deprecated(CTX, b_info); if (rc) { @@ -80,45 +129,10 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc, return rc; } - libxl_defbool_setdefault(&b_info->device_model_stubdomain, false); - if (libxl_defbool_val(b_info->device_model_stubdomain) && !b_info->device_model_ssidref) b_info->device_model_ssidref = SECINITSID_DOMDM; - if (!b_info->device_model_version) { - if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) { - if (libxl_defbool_val(b_info->device_model_stubdomain)) { - b_info->device_model_version = - LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; - } else { - b_info->device_model_version = libxl__default_device_model(gc); - } - } else { - b_info->device_model_version = - LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN; - } - if (b_info->device_model_version - == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { - const char *dm; - - dm = libxl__domain_device_model(gc, b_info); - rc = access(dm, X_OK); - if (rc < 0) { - /* qemu-xen unavailable, use qemu-xen-traditional */ - if (errno == ENOENT) { - LOGE(INFO, "qemu-xen is unavailable" - ", using qemu-xen-traditional instead"); - b_info->device_model_version = - LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL; - } else { - LOGE(ERROR, "qemu-xen access error"); - return ERROR_FAIL; - } - } - } - } - if (b_info->blkdev_start == NULL) b_info->blkdev_start = libxl__strdup(NOGC, "xvda"); @@ -938,6 +952,12 @@ static void initiate_domain_create(libxl__egc *egc, goto error_out; } + ret = libxl__domain_set_device_model(gc, d_config); + if (ret) { + LOGD(ERROR, domid, "Unable to set domain device model"); + goto error_out; + } + ret = libxl__domain_create_info_setdefault(gc, &d_config->c_info); if (ret) { LOGD(ERROR, domid, "Unable to set domain create info defaults"); diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 2f19786bdd..086e566311 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -2168,6 +2168,8 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) dm_config->c_info.run_hotplug_scripts = guest_config->c_info.run_hotplug_scripts; + ret = libxl__domain_set_device_model(gc, dm_config); + if (ret) goto out; ret = libxl__domain_create_info_setdefault(gc, &dm_config->c_info); if (ret) goto out; ret = libxl__domain_build_info_setdefault(gc, &dm_config->b_info); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 44e0221284..25f113404b 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1374,6 +1374,8 @@ _hidden int libxl__device_nextid(libxl__gc *gc, uint32_t domid, _hidden int libxl__resolve_domid(libxl__gc *gc, const char *name, uint32_t *domid); +_hidden int libxl__domain_set_device_model(libxl__gc *gc, + libxl_domain_config *d_config); /* * For each aggregate type which can be used as an input we provide: *