From nobody Sat Feb 7 07:31:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582381550; cv=none; d=zohomail.com; s=zohoarc; b=KScA+HWpTScPOeqmbNemh0jrPJMwU3SlPbggGi/8FDwp/hWpj+NMqeZCraecqgLNy3ePE+InxkMiookIGwGUBYDKUq39ybHXeeNu5zXKcaq5/bCB/eU0o5Is4egC7OkSghVJ/ytiMxq5xjR7cM82/7bB1N/DclphW52er5GIME4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582381550; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VXpjq0koGwDjVxeT8Chz8XHkdljRxIc/+9fJzmwjnMM=; b=OpcOW9RiZMJSgHqj4Sue/hfTT4HpYLqV1s6Uh9+44oBHWez9/3mwrQ5tDQMK55XHV+52P55oWT2pr+mu/b7uw7dthk058iyfK+N7KQFbU7/231rUoH3yIXkcXzbP8s0kKO2Zt4XVUbIB57TpL9BzuoiiPwcCBkp3LvdRel7+Wng= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1582381550577182.31204534037; Sat, 22 Feb 2020 06:25:50 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-201-SJzCy8uRN_eQ3_J4Peym9Q-1; Sat, 22 Feb 2020 09:25:47 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C58D5107ACC9; Sat, 22 Feb 2020 14:25:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 990F75C1B5; Sat, 22 Feb 2020 14:25:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3BC7635AF3; Sat, 22 Feb 2020 14:25:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01MEPJQf008547 for ; Sat, 22 Feb 2020 09:25:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3FFBA87B0A; Sat, 22 Feb 2020 14:25:19 +0000 (UTC) Received: from lpt.redhat.com (ovpn-200-17.brq.redhat.com [10.40.200.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id A50FB90784 for ; Sat, 22 Feb 2020 14:25:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582381549; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VXpjq0koGwDjVxeT8Chz8XHkdljRxIc/+9fJzmwjnMM=; b=dC1X7YxK2RU4M77GLTLncATp6JFKbLsk8YQEfNQsnkH/hZ2aCVBcKxe2bmcfboW4vx8QVF aY15TIGEaJ8pvNf+2/yL7tdTkx52HWzWvXDJdlYoTfCjxh5yvwhOMVF2bPFoRbb0A4qx9b YXlPPKDjFznLZlI+FuIzptN22YRG7Do= X-MC-Unique: SJzCy8uRN_eQ3_J4Peym9Q-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/7] libxl: split out DriverConfigInit out of DriverConfigNew Date: Sat, 22 Feb 2020 15:25:08 +0100 Message-Id: <6e48e93a13fe7ed33dddfbd733ad75c958ebb1c4.1582381502.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Take the parts affected by the host state out of DriverConfigNew and put them into a separate function. Adjust all the callers to call both functions. Signed-off-by: J=C3=A1n Tomko --- src/libxl/libxl_conf.c | 81 ++++++++++++++++++++++------------------ src/libxl/libxl_conf.h | 2 + src/libxl/libxl_driver.c | 3 ++ tests/testutilsxen.c | 3 ++ 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 9c722342ba..907df525c5 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1686,8 +1686,6 @@ libxlDriverConfigPtr libxlDriverConfigNew(void) { libxlDriverConfigPtr cfg; - char ebuf[1024]; - unsigned int free_mem; =20 if (libxlConfigInitialize() < 0) return NULL; @@ -1705,41 +1703,6 @@ libxlDriverConfigNew(void) cfg->autoDumpDir =3D g_strdup(LIBXL_DUMP_DIR); cfg->channelDir =3D g_strdup(LIBXL_CHANNEL_DIR); =20 - if (virFileMakePath(cfg->logDir) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to create log dir '%s': %s"), - cfg->logDir, - virStrerror(errno, ebuf, sizeof(ebuf))); - goto error; - } - - cfg->logger =3D libxlLoggerNew(cfg->logDir, virLogGetDefaultPriority()= ); - if (!cfg->logger) { - VIR_ERROR(_("cannot create logger for libxenlight, disabling drive= r")); - goto error; - } - - if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, (xentoollog_logger *)= cfg->logger)) { - VIR_ERROR(_("cannot initialize libxenlight context, probably not " - "running in a Xen Dom0, disabling driver")); - goto error; - } - - if ((cfg->verInfo =3D libxl_get_version_info(cfg->ctx)) =3D=3D NULL) { - VIR_ERROR(_("cannot version information from libxenlight, " - "disabling driver")); - goto error; - } - cfg->version =3D (cfg->verInfo->xen_version_major * 1000000) + - (cfg->verInfo->xen_version_minor * 1000); - - /* This will fill xenstore info about free and dom0 memory if missing, - * should be called before starting first domain */ - if (libxl_get_free_memory(cfg->ctx, &free_mem)) { - VIR_ERROR(_("Unable to configure libxl's memory management paramet= ers")); - goto error; - } - #ifdef DEFAULT_LOADER_NVRAM if (virFirmwareParseList(DEFAULT_LOADER_NVRAM, &cfg->firmwares, @@ -1774,6 +1737,50 @@ libxlDriverConfigNew(void) return NULL; } =20 +int +libxlDriverConfigInit(libxlDriverConfigPtr cfg) +{ + char ebuf[1024]; + unsigned int free_mem; + + if (virFileMakePath(cfg->logDir) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to create log dir '%s': %s"), + cfg->logDir, + virStrerror(errno, ebuf, sizeof(ebuf))); + return -1; + } + + cfg->logger =3D libxlLoggerNew(cfg->logDir, virLogGetDefaultPriority()= ); + if (!cfg->logger) { + VIR_ERROR(_("cannot create logger for libxenlight, disabling drive= r")); + return -1; + } + + if (libxl_ctx_alloc(&cfg->ctx, LIBXL_VERSION, 0, (xentoollog_logger *)= cfg->logger)) { + VIR_ERROR(_("cannot initialize libxenlight context, probably not " + "running in a Xen Dom0, disabling driver")); + return -1; + } + + if ((cfg->verInfo =3D libxl_get_version_info(cfg->ctx)) =3D=3D NULL) { + VIR_ERROR(_("cannot version information from libxenlight, " + "disabling driver")); + return -1; + } + cfg->version =3D (cfg->verInfo->xen_version_major * 1000000) + + (cfg->verInfo->xen_version_minor * 1000); + + /* This will fill xenstore info about free and dom0 memory if missing, + * should be called before starting first domain */ + if (libxl_get_free_memory(cfg->ctx, &free_mem)) { + VIR_ERROR(_("Unable to configure libxl's memory management paramet= ers")); + return -1; + } + + return 0; +} + libxlDriverConfigPtr libxlDriverConfigGet(libxlDriverPrivatePtr driver) { diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index b61c52f1a5..07b3373170 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -164,6 +164,8 @@ struct _libxlSavefileHeader { =20 libxlDriverConfigPtr libxlDriverConfigNew(void); +int +libxlDriverConfigInit(libxlDriverConfigPtr cfg); =20 libxlDriverConfigPtr libxlDriverConfigGet(libxlDriverPrivatePtr driver); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 0b88c9f9d9..d10529ac5b 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -707,6 +707,9 @@ libxlStateInitialize(bool privileged, if (libxlDriverConfigLoadFile(cfg, driverConf) < 0) goto error; =20 + if (libxlDriverConfigInit(cfg) < 0) + goto error; + /* Register the callbacks providing access to libvirt's event loop */ libxl_osevent_register_hooks(cfg->ctx, &libxl_osevent_callbacks, cfg->= ctx); =20 diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c index 76da33826c..b1260dcebf 100644 --- a/tests/testutilsxen.c +++ b/tests/testutilsxen.c @@ -97,6 +97,9 @@ libxlDriverPrivatePtr testXLInitDriver(void) if (!(driver->config =3D libxlDriverConfigNew())) return NULL; =20 + if (libxlDriverConfigInit(driver->config) < 0) + return NULL; + driver->config->caps =3D testXLInitCaps(); =20 driver->xmlopt =3D libxlCreateXMLConf(driver); --=20 2.24.1