From nobody Mon Feb 9 03:14:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1562157675; cv=none; d=zoho.com; s=zohoarc; b=oeHrXbyUGhmolP7pXCezMU6TD9/OyfvNKEgW6Jh6GBxIPD9hv7Udes27JDdAyDZuf/wgOpOxVl7NlsuF9oisw4AprRbfFZrl1uTRP+Q9OtZwC/r8bafYnlwMaIw6LO4yJmTHdYAv3e6YFIAdd4vUUNyG2EBg022TjVVGq9YhlOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562157675; 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:ARC-Authentication-Results; bh=aWhJs/NvRrSOuL4cC3CzglM2+7UQ7BIDys/EODGFXRM=; b=IJUR/6Qv5yeaKUYH0Q8jwqD+o7uXuLHSn1V4TTEmI4XP6Y6aBUl9S58TeDgUY7Bo7eGFQ8yTeIGJ56RHuWV74cC7T0y4Up5Ar2JtJ2NX6mxjKKBHlj8foZHth+ajlYnrnircQlaOMLDfOTGaUYJ1vRtXcTeapfZQCqXo6nEwqhY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1562157675711257.4809503218437; Wed, 3 Jul 2019 05:41:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A09F130860C3; Wed, 3 Jul 2019 12:41:03 +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 67EF9106F752; Wed, 3 Jul 2019 12:41:02 +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 184E14EBC0; Wed, 3 Jul 2019 12:41:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x63CcCSC007640 for ; Wed, 3 Jul 2019 08:38:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 442C08958A; Wed, 3 Jul 2019 12:38:12 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2AA4834EB for ; Wed, 3 Jul 2019 12:38:11 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 3 Jul 2019 14:37:54 +0200 Message-Id: <3584f3bbe7dea74d9675298f88ac2c8b7c6682ee.1562157378.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/14] xenconfig: Drop sxpr formatter 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 03 Jul 2019 12:41:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" It's no longer used. Remove the dead code. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_xenconfig.syms | 4 - src/xenconfig/xen_sxpr.c | 880 ------------------------------------- src/xenconfig/xen_sxpr.h | 12 - 3 files changed, 896 deletions(-) diff --git a/src/libvirt_xenconfig.syms b/src/libvirt_xenconfig.syms index b69f2ab493..945f16e382 100644 --- a/src/libvirt_xenconfig.syms +++ b/src/libvirt_xenconfig.syms @@ -3,11 +3,7 @@ # # xenconfig/xen_sxpr.h -xenFormatSxpr; xenFormatSxprChr; -xenFormatSxprDisk; -xenFormatSxprNet; -xenFormatSxprOnePCI; xenFormatSxprSound; xenGetDomIdFromSxpr; xenGetDomIdFromSxprString; diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c index 0bff94ead5..d67a89efee 100644 --- a/src/xenconfig/xen_sxpr.c +++ b/src/xenconfig/xen_sxpr.c @@ -28,7 +28,6 @@ #include "virerror.h" #include "virconf.h" #include "viralloc.h" -#include "verify.h" #include "viruuid.h" #include "virlog.h" #include "count-one-bits.h" @@ -1493,121 +1492,6 @@ xenParseSxprString(const char *sexpr, return def; } -/************************************************************************ - * * - * Converter functions to go from the XML tree to an S-Expr for Xen * - * * - ************************************************************************/ - - -/** - * xenFormatSxprGraphicsNew: - * @def: the domain config - * @buf: a buffer for the result S-expression - * - * Convert the graphics part of the domain description into a S-expression - * in buf. (HVM > 3.0.4 or PV > 3.0.3) - * - * Returns 0 in case of success, -1 in case of error - */ -static int -xenFormatSxprGraphicsNew(virDomainGraphicsDefPtr def, - virBufferPtr buf) -{ - virDomainGraphicsListenDefPtr glisten; - - if (def->type !=3D VIR_DOMAIN_GRAPHICS_TYPE_SDL && - def->type !=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected graphics type %d"), - def->type); - return -1; - } - - virBufferAddLit(buf, "(device (vkbd))"); - virBufferAddLit(buf, "(device (vfb "); - - if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SDL) { - virBufferAddLit(buf, "(type sdl)"); - if (def->data.sdl.display) - virBufferAsprintf(buf, "(display '%s')", def->data.sdl.display= ); - if (def->data.sdl.xauth) - virBufferAsprintf(buf, "(xauthority '%s')", def->data.sdl.xaut= h); - } else if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - virBufferAddLit(buf, "(type vnc)"); - if (def->data.vnc.autoport) { - virBufferAddLit(buf, "(vncunused 1)"); - } else { - virBufferAddLit(buf, "(vncunused 0)"); - virBufferAsprintf(buf, "(vncdisplay %d)", def->data.vnc.port-5= 900); - } - - if ((glisten =3D virDomainGraphicsGetListen(def, 0)) && - glisten->address) - virBufferAsprintf(buf, "(vnclisten '%s')", glisten->address); - if (def->data.vnc.auth.passwd) - virBufferAsprintf(buf, "(vncpasswd '%s')", def->data.vnc.auth.= passwd); - if (def->data.vnc.keymap) - virBufferAsprintf(buf, "(keymap '%s')", def->data.vnc.keymap); - } - - virBufferAddLit(buf, "))"); - - return 0; -} - - -/** - * xenFormatSxprGraphicsOld: - * @def: the domain config - * @buf: a buffer for the result S-expression - * - * Convert the graphics part of the domain description into a S-expression - * in buf. (HVM <=3D 3.0.4 or PV <=3D 3.0.3) - * - * Returns 0 in case of success, -1 in case of error - */ -static int -xenFormatSxprGraphicsOld(virDomainGraphicsDefPtr def, virBufferPtr buf) -{ - virDomainGraphicsListenDefPtr glisten; - - if (def->type !=3D VIR_DOMAIN_GRAPHICS_TYPE_SDL && - def->type !=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected graphics type %d"), - def->type); - return -1; - } - - if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SDL) { - virBufferAddLit(buf, "(sdl 1)"); - if (def->data.sdl.display) - virBufferAsprintf(buf, "(display '%s')", def->data.sdl.display= ); - if (def->data.sdl.xauth) - virBufferAsprintf(buf, "(xauthority '%s')", def->data.sdl.xaut= h); - } else if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - virBufferAddLit(buf, "(vnc 1)"); - if (def->data.vnc.autoport) { - virBufferAddLit(buf, "(vncunused 1)"); - } else { - virBufferAddLit(buf, "(vncunused 0)"); - virBufferAsprintf(buf, "(vncdisplay %d)", def->data.vnc.port-5= 900); - } - - if ((glisten =3D virDomainGraphicsGetListen(def, 0)) && - glisten->address) - virBufferAsprintf(buf, "(vnclisten '%s')", glisten->address); - if (def->data.vnc.auth.passwd) - virBufferAsprintf(buf, "(vncpasswd '%s')", def->data.vnc.auth.= passwd); - if (def->data.vnc.keymap) - virBufferAsprintf(buf, "(keymap '%s')", def->data.vnc.keymap); - } - - return 0; -} - - /** * xenFormatSxprChr: * @def: the domain config @@ -1687,382 +1571,6 @@ xenFormatSxprChr(virDomainChrDefPtr def, } -/** - * xenFormatSxprDisk: - * @node: node containing the disk description - * @buf: a buffer for the result S-expression - * @hvm: true or 1 if domain is HVM - * @isAttach: create expression for device attach (1). - * - * Convert the disk device part of the domain config into a S-expression i= n buf. - * - * Returns 0 in case of success, -1 in case of error. - */ -int -xenFormatSxprDisk(virDomainDiskDefPtr def, - virBufferPtr buf, - int hvm, - int isAttach) -{ - const char *src =3D virDomainDiskGetSource(def); - const char *driver =3D virDomainDiskGetDriver(def); - - /* Xend (all versions) put the floppy device config - * under the hvm (image (os)) block - */ - if (hvm && - def->device =3D=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY) { - if (isAttach) { - virReportError(VIR_ERR_INVALID_ARG, - _("Cannot directly attach floppy %s"), src); - return -1; - } - return 0; - } - - if (!isAttach) - virBufferAddLit(buf, "(device "); - - /* Normally disks are in a (device (vbd ...)) block - * but blktap disks ended up in a differently named - * (device (tap ....)) block.... */ - if (STREQ_NULLABLE(driver, "tap")) { - virBufferAddLit(buf, "(tap "); - } else if (STREQ_NULLABLE(driver, "tap2")) { - virBufferAddLit(buf, "(tap2 "); - } else { - virBufferAddLit(buf, "(vbd "); - } - - if (hvm) { - virBufferEscapeSexpr(buf, "(dev '%s:", def->dst); - virBufferAsprintf(buf, "%s')", - def->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM ? - "cdrom" : "disk"); - } else if (def->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM) { - virBufferEscapeSexpr(buf, "(dev '%s:cdrom')", def->dst); - } else { - virBufferEscapeSexpr(buf, "(dev '%s')", def->dst); - } - - if (src) { - if (driver) { - if (STREQ(driver, "tap") || - STREQ(driver, "tap2")) { - const char *type; - int format =3D virDomainDiskGetFormat(def); - - if (!format || format =3D=3D VIR_STORAGE_FILE_RAW) - type =3D "aio"; - else - type =3D virStorageFileFormatTypeToString(format); - virBufferEscapeSexpr(buf, "(uname '%s:", driver); - virBufferEscapeSexpr(buf, "%s:", type); - virBufferEscapeSexpr(buf, "%s')", src); - } else { - virBufferEscapeSexpr(buf, "(uname '%s:", driver); - virBufferEscapeSexpr(buf, "%s')", src); - } - } else { - int type =3D virDomainDiskGetType(def); - - if (type =3D=3D VIR_STORAGE_TYPE_FILE) { - virBufferEscapeSexpr(buf, "(uname 'file:%s')", src); - } else if (type =3D=3D VIR_STORAGE_TYPE_BLOCK) { - if (src[0] =3D=3D '/') - virBufferEscapeSexpr(buf, "(uname 'phy:%s')", src); - else - virBufferEscapeSexpr(buf, "(uname 'phy:/dev/%s')", - src); - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unsupported disk type %s"), - virStorageTypeToString(type)); - return -1; - } - } - } - - if (def->src->readonly) - virBufferAddLit(buf, "(mode 'r')"); - else if (def->src->shared) - virBufferAddLit(buf, "(mode 'w!')"); - else - virBufferAddLit(buf, "(mode 'w')"); - if (def->transient) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("transient disks not supported yet")); - return -1; - } - - if (!isAttach) - virBufferAddLit(buf, ")"); - - virBufferAddLit(buf, ")"); - - return 0; -} - -/** - * xenFormatSxprNet: - * @conn: connection - * @def: the domain config - * @buf: a buffer for the result S-expression - * @hvm: true or 1 if domain is HVM - * @isAttach: create expression for device attach (1). - * - * Convert the interface description of the domain config into a S-express= ion in buf. - * This is a temporary interface as the S-Expr interface - * will be replaced by XML-RPC in the future. However the XML format should - * stay valid over time. - * - * Returns 0 in case of success, -1 in case of error. - */ -int -xenFormatSxprNet(virConnectPtr conn, - virDomainNetDefPtr def, - virBufferPtr buf, - int hvm, - int isAttach) -{ - const char *script =3D DEFAULT_VIF_SCRIPT; - char macaddr[VIR_MAC_STRING_BUFLEN]; - - if (def->type !=3D VIR_DOMAIN_NET_TYPE_BRIDGE && - def->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK && - def->type !=3D VIR_DOMAIN_NET_TYPE_ETHERNET) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unsupported network type %d"), def->type); - return -1; - } - if (def->script && - def->type !=3D VIR_DOMAIN_NET_TYPE_BRIDGE && - def->type !=3D VIR_DOMAIN_NET_TYPE_ETHERNET) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("scripts are not supported on interfaces of type = %s"), - virDomainNetTypeToString(def->type)); - return -1; - } - - if (!isAttach) - virBufferAddLit(buf, "(device "); - - virBufferAddLit(buf, "(vif "); - - virBufferAsprintf(buf, "(mac '%s')", virMacAddrFormat(&def->mac, macad= dr)); - - if (def->bandwidth && def->bandwidth->out && def->bandwidth->out->aver= age) - virBufferAsprintf(buf, "(rate '%lluKB/s')", def->bandwidth->out->a= verage); - - switch (def->type) { - case VIR_DOMAIN_NET_TYPE_BRIDGE: - virBufferEscapeSexpr(buf, "(bridge '%s')", def->data.bridge.brname= ); - if (def->script) - script =3D def->script; - - virBufferEscapeSexpr(buf, "(script '%s')", script); - if (def->guestIP.nips =3D=3D 1) { - char *ipStr =3D virSocketAddrFormat(&def->guestIP.ips[0]->addr= ess); - virBufferEscapeSexpr(buf, "(ip '%s')", ipStr); - VIR_FREE(ipStr); - } else if (def->guestIP.nips > 1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Driver does not support setting multiple IP = addresses")); - return -1; - } - break; - - case VIR_DOMAIN_NET_TYPE_NETWORK: - { - virNetworkPtr network =3D - virNetworkLookupByName(conn, def->data.network.name); - char *bridge; - - if (!network) { - virReportError(VIR_ERR_NO_NETWORK, "%s", - def->data.network.name); - return -1; - } - - bridge =3D virNetworkGetBridgeName(network); - virObjectUnref(network); - if (!bridge) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("network %s is not active"), - def->data.network.name); - return -1; - } - virBufferEscapeSexpr(buf, "(bridge '%s')", bridge); - virBufferEscapeSexpr(buf, "(script '%s')", script); - VIR_FREE(bridge); - } - break; - - case VIR_DOMAIN_NET_TYPE_ETHERNET: - if (def->script) - virBufferEscapeSexpr(buf, "(script '%s')", - def->script); - if (def->guestIP.nips =3D=3D 1) { - char *ipStr =3D virSocketAddrFormat(&def->guestIP.ips[0]->addr= ess); - virBufferEscapeSexpr(buf, "(ip '%s')", ipStr); - VIR_FREE(ipStr); - } else if (def->guestIP.nips > 1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Driver does not support setting multiple IP = addresses")); - return -1; - } - break; - - case VIR_DOMAIN_NET_TYPE_VHOSTUSER: - case VIR_DOMAIN_NET_TYPE_USER: - case VIR_DOMAIN_NET_TYPE_SERVER: - case VIR_DOMAIN_NET_TYPE_CLIENT: - case VIR_DOMAIN_NET_TYPE_MCAST: - case VIR_DOMAIN_NET_TYPE_UDP: - case VIR_DOMAIN_NET_TYPE_INTERNAL: - case VIR_DOMAIN_NET_TYPE_DIRECT: - case VIR_DOMAIN_NET_TYPE_HOSTDEV: - case VIR_DOMAIN_NET_TYPE_LAST: - break; - } - - if (def->ifname !=3D NULL && - !STRPREFIX(def->ifname, "vif")) - virBufferEscapeSexpr(buf, "(vifname '%s')", def->ifname); - - if (virDomainNetGetModelString(def)) { - if (!hvm) { - virBufferEscapeSexpr(buf, "(model '%s')", - virDomainNetGetModelString(def)); - } else { - if (def->model =3D=3D VIR_DOMAIN_NET_MODEL_NETFRONT) - virBufferAddLit(buf, "(type netfront)"); - else - virBufferEscapeSexpr(buf, "(model '%s')", - virDomainNetGetModelString(def)); - } - } - - if (!isAttach) - virBufferAddLit(buf, ")"); - - virBufferAddLit(buf, ")"); - - return 0; -} - - -/** - * xenFormatSxprPCI: - * @def: the device config - * @buf: a buffer for the result S-expression - * - * Convert a single PCI device part of the domain config into a S-expressi= on in buf. - * - * Returns 0 in case of success, -1 in case of error. - */ -static void -xenFormatSxprPCI(virDomainHostdevDefPtr def, - virBufferPtr buf) -{ - virBufferAsprintf(buf, "(dev (domain 0x%04x)(bus 0x%02x)(slot 0x%02x)(= func 0x%x))", - def->source.subsys.u.pci.addr.domain, - def->source.subsys.u.pci.addr.bus, - def->source.subsys.u.pci.addr.slot, - def->source.subsys.u.pci.addr.function); -} - - -/** - * xenFormatSxprOnePCI: - * @def: the device config - * @buf: a buffer for the result S-expression - * @detach: create expression for device detach (1). - * - * Convert a single PCI device part of the domain config into a S-expressi= on in buf. - * - * Returns 0 in case of success, -1 in case of error. - */ -int -xenFormatSxprOnePCI(virDomainHostdevDefPtr def, - virBufferPtr buf, - int detach) -{ - if (def->managed) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("managed PCI devices not supported with XenD")); - return -1; - } - - virBufferAddLit(buf, "(pci "); - xenFormatSxprPCI(def, buf); - if (detach) - virBufferAddLit(buf, "(state 'Closing')"); - else - virBufferAddLit(buf, "(state 'Initialising')"); - virBufferAddLit(buf, ")"); - - return 0; -} - - -/** - * xenFormatSxprAllPCI: - * @def: the domain config - * @buf: a buffer for the result S-expression - * - * Convert all PCI device parts of the domain config into a S-expression i= n buf. - * - * Returns 0 in case of success, -1 in case of error. - */ -static int -xenFormatSxprAllPCI(virDomainDefPtr def, - virBufferPtr buf) -{ - int hasPCI =3D 0; - size_t i; - - for (i =3D 0; i < def->nhostdevs; i++) - if (def->hostdevs[i]->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - def->hostdevs[i]->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV= _SUBSYS_TYPE_PCI) - hasPCI =3D 1; - - if (!hasPCI) - return 0; - - /* - * With the (domain ...) block we have the following odd setup - * - * (device - * (pci - * (dev (domain 0x0000) (bus 0x00) (slot 0x1b) (func 0x0)) - * (dev (domain 0x0000) (bus 0x00) (slot 0x13) (func 0x0)) - * ) - * ) - * - * Normally there is one (device ...) block per device, but in the - * weird world of Xen PCI, one (device ...) covers multiple devices. - */ - - virBufferAddLit(buf, "(device (pci "); - for (i =3D 0; i < def->nhostdevs; i++) { - if (def->hostdevs[i]->mode =3D=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && - def->hostdevs[i]->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV= _SUBSYS_TYPE_PCI) { - if (def->hostdevs[i]->managed) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("managed PCI devices not supported with X= enD")); - return -1; - } - - xenFormatSxprPCI(def->hostdevs[i], buf); - } - } - virBufferAddLit(buf, "))"); - - return 0; -} - - /** * xenFormatSxprSound: * @def: the domain config @@ -2096,391 +1604,3 @@ xenFormatSxprSound(virDomainDefPtr def, return 0; } - - -/** - * xenFormatSxprInput: - * @input: the input config - * @buf: a buffer for the result S-expression - * - * Convert all input device parts of the domain config into S-expression i= n buf. - * - * Returns 0 if successful or -1 if failed. - */ -static int -xenFormatSxprInput(virDomainInputDefPtr input, - virBufferPtr buf) -{ - if (input->bus !=3D VIR_DOMAIN_INPUT_BUS_USB) - return 0; - - if (input->type !=3D VIR_DOMAIN_INPUT_TYPE_MOUSE && - input->type !=3D VIR_DOMAIN_INPUT_TYPE_TABLET && - input->type !=3D VIR_DOMAIN_INPUT_TYPE_KBD) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected input type %d"), input->type); - return -1; - } - - switch (input->type) { - case VIR_DOMAIN_INPUT_TYPE_MOUSE: - virBufferAsprintf(buf, "(usbdevice %s)", "mouse"); - break; - case VIR_DOMAIN_INPUT_TYPE_TABLET: - virBufferAsprintf(buf, "(usbdevice %s)", "tablet"); - break; - case VIR_DOMAIN_INPUT_TYPE_KBD: - virBufferAsprintf(buf, "(usbdevice %s)", "keyboard"); - break; - } - - return 0; -} - - -/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is - either 32, or 64 on a platform where long is big enough. */ -verify(MAX_VIRT_CPUS <=3D sizeof(1UL) * CHAR_BIT); - -/** - * xenFormatSxpr: - * @conn: pointer to the hypervisor connection - * @def: domain config definition - * - * Generate an S-expression representing the domain configuration. - * - * Returns the 0 terminated S-Expr string or NULL in case of error. - * the caller must free() the returned value. - */ -char * -xenFormatSxpr(virConnectPtr conn, virDomainDefPtr def) -{ - virBuffer buf =3D VIR_BUFFER_INITIALIZER; - char uuidstr[VIR_UUID_STRING_BUFLEN]; - const char *tmp; - char *bufout; - int hvm =3D 0, vmlocaltime =3D -1; - size_t i; - bool in_image =3D false; - - VIR_DEBUG("Formatting domain sexpr"); - - virBufferAddLit(&buf, "(vm "); - virBufferEscapeSexpr(&buf, "(name '%s')", def->name); - virBufferAsprintf(&buf, "(memory %llu)(maxmem %llu)", - VIR_DIV_UP(def->mem.cur_balloon, 1024), - VIR_DIV_UP(virDomainDefGetMemoryTotal(def), 1024)); - virBufferAsprintf(&buf, "(vcpus %u)", virDomainDefGetVcpusMax(def)); - /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is - either 32, or 64 on a platform where long is big enough. */ - if (virDomainDefHasVcpusOffline(def)) - virBufferAsprintf(&buf, "(vcpu_avail %lu)", - (1UL << virDomainDefGetVcpus(def)) - 1); - - if (def->cpumask) { - char *ranges =3D virBitmapFormat(def->cpumask); - if (ranges =3D=3D NULL) - goto error; - virBufferEscapeSexpr(&buf, "(cpus '%s')", ranges); - VIR_FREE(ranges); - } - - virUUIDFormat(def->uuid, uuidstr); - virBufferAsprintf(&buf, "(uuid '%s')", uuidstr); - - if (def->description) - virBufferEscapeSexpr(&buf, "(description '%s')", def->description); - - if (def->os.bootloader) { - if (def->os.bootloader[0]) - virBufferEscapeSexpr(&buf, "(bootloader '%s')", def->os.bootlo= ader); - else - virBufferAddLit(&buf, "(bootloader)"); - - if (def->os.bootloaderArgs) - virBufferEscapeSexpr(&buf, "(bootloader_args '%s')", def->os.b= ootloaderArgs); - } - - if (!(tmp =3D virDomainLifecycleActionTypeToString(def->onPoweroff))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected lifecycle value %d"), def->onPoweroff= ); - goto error; - } - virBufferAsprintf(&buf, "(on_poweroff '%s')", tmp); - - if (!(tmp =3D virDomainLifecycleActionTypeToString(def->onReboot))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected lifecycle value %d"), def->onReboot); - goto error; - } - virBufferAsprintf(&buf, "(on_reboot '%s')", tmp); - - if (!(tmp =3D virDomainLifecycleActionTypeToString(def->onCrash))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected lifecycle value %d"), def->onCrash); - goto error; - } - virBufferAsprintf(&buf, "(on_crash '%s')", tmp); - - if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) - hvm =3D 1; - - if (!def->os.bootloader) { - if (hvm) - virBufferAddLit(&buf, "(image (hvm "); - else - virBufferAddLit(&buf, "(image (linux "); - in_image =3D true; - - if (hvm && - def->os.loader =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("no HVM domain loader")); - goto error; - } - - if (def->os.kernel) - virBufferEscapeSexpr(&buf, "(kernel '%s')", def->os.kernel); - if (def->os.initrd) - virBufferEscapeSexpr(&buf, "(ramdisk '%s')", def->os.initrd); - if (def->os.root) - virBufferEscapeSexpr(&buf, "(root '%s')", def->os.root); - if (def->os.cmdline) - virBufferEscapeSexpr(&buf, "(args '%s')", def->os.cmdline); - - if (hvm) { - char bootorder[VIR_DOMAIN_BOOT_LAST+1]; - if (def->os.kernel) - virBufferEscapeSexpr(&buf, "(loader '%s')", def->os.loader= ->path); - else - virBufferEscapeSexpr(&buf, "(kernel '%s')", def->os.loader= ->path); - - virBufferAsprintf(&buf, "(vcpus %u)", virDomainDefGetVcpusMax(= def)); - if (virDomainDefHasVcpusOffline(def)) - virBufferAsprintf(&buf, "(vcpu_avail %lu)", - (1UL << virDomainDefGetVcpus(def)) - 1); - - for (i =3D 0; i < def->os.nBootDevs; i++) { - switch (def->os.bootDevs[i]) { - case VIR_DOMAIN_BOOT_FLOPPY: - bootorder[i] =3D 'a'; - break; - default: - case VIR_DOMAIN_BOOT_DISK: - bootorder[i] =3D 'c'; - break; - case VIR_DOMAIN_BOOT_CDROM: - bootorder[i] =3D 'd'; - break; - case VIR_DOMAIN_BOOT_NET: - bootorder[i] =3D 'n'; - break; - } - } - if (def->os.nBootDevs =3D=3D 0) { - bootorder[0] =3D 'c'; - bootorder[1] =3D '\0'; - } else { - bootorder[def->os.nBootDevs] =3D '\0'; - } - virBufferAsprintf(&buf, "(boot %s)", bootorder); - - if (def->features[VIR_DOMAIN_FEATURE_ACPI] =3D=3D VIR_TRISTATE= _SWITCH_ON) - virBufferAddLit(&buf, "(acpi 1)"); - if (def->features[VIR_DOMAIN_FEATURE_APIC] =3D=3D VIR_TRISTATE= _SWITCH_ON) - virBufferAddLit(&buf, "(apic 1)"); - if (def->features[VIR_DOMAIN_FEATURE_PAE] =3D=3D VIR_TRISTATE_= SWITCH_ON) - virBufferAddLit(&buf, "(pae 1)"); - if (def->features[VIR_DOMAIN_FEATURE_HAP] =3D=3D VIR_TRISTATE_= SWITCH_ON) - virBufferAddLit(&buf, "(hap 1)"); - if (def->features[VIR_DOMAIN_FEATURE_VIRIDIAN] =3D=3D VIR_TRIS= TATE_SWITCH_ON) - virBufferAddLit(&buf, "(viridian 1)"); - - virBufferAddLit(&buf, "(usb 1)"); - - for (i =3D 0; i < def->ninputs; i++) - if (xenFormatSxprInput(def->inputs[i], &buf) < 0) - goto error; - - if (def->parallels) { - virBufferAddLit(&buf, "(parallel "); - if (xenFormatSxprChr(def->parallels[0], &buf) < 0) - goto error; - virBufferAddLit(&buf, ")"); - } else { - virBufferAddLit(&buf, "(parallel none)"); - } - if (def->serials) { - if ((def->nserials > 1) || (def->serials[0]->target.port != =3D 0)) { - int maxport =3D -1, port; - size_t j =3D 0; - - virBufferAddLit(&buf, "(serial ("); - for (i =3D 0; i < def->nserials; i++) - if (def->serials[i]->target.port > maxport) - maxport =3D def->serials[i]->target.port; - - for (port =3D 0; port <=3D maxport; port++) { - virDomainChrDefPtr chr =3D NULL; - - if (port) - virBufferAddLit(&buf, " "); - for (j =3D 0; j < def->nserials; j++) { - if (def->serials[j]->target.port =3D=3D port) { - chr =3D def->serials[j]; - break; - } - } - if (chr) { - if (xenFormatSxprChr(chr, &buf) < 0) - goto error; - } else { - virBufferAddLit(&buf, "none"); - } - } - virBufferAddLit(&buf, "))"); - } else { - virBufferAddLit(&buf, "(serial "); - if (xenFormatSxprChr(def->serials[0], &buf) < 0) - goto error; - virBufferAddLit(&buf, ")"); - } - } else { - virBufferAddLit(&buf, "(serial none)"); - } - - if (def->sounds) { - virBufferAddLit(&buf, "(soundhw '"); - if (xenFormatSxprSound(def, &buf) < 0) - goto error; - virBufferAddLit(&buf, "')"); - } - } /* hvm */ - - /* get the device emulation model */ - if (def->emulator && hvm) - virBufferEscapeSexpr(&buf, "(device_model '%s')", def->emulato= r); - - /* look for HPET in order to override the hypervisor/xend default = */ - for (i =3D 0; i < def->clock.ntimers; i++) { - if (def->clock.timers[i]->name =3D=3D VIR_DOMAIN_TIMER_NAME_HP= ET && - def->clock.timers[i]->present !=3D -1) { - virBufferAsprintf(&buf, "(hpet %d)", - def->clock.timers[i]->present); - break; - } - } - - /* PV graphics for xen <=3D 3.0.4, or HVM graphics */ - if (hvm) { - if ((def->ngraphics =3D=3D 1) && - xenFormatSxprGraphicsOld(def->graphics[0], &buf) < 0) - goto error; - } - } else { - /* PV domains accept kernel cmdline args */ - if (def->os.cmdline) { - virBufferEscapeSexpr(&buf, "(image (linux (args '%s')", def->o= s.cmdline); - in_image =3D true; - } - } /* os.bootloader */ - - if (!in_image) { - if (hvm) - virBufferAddLit(&buf, "(image (hvm "); - else - virBufferAddLit(&buf, "(image (linux "); - in_image =3D true; - } - if (hvm) { - /* >=3D3.1 HV: VARIABLE */ - int rtc_timeoffset; - switch (def->clock.offset) { - case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE: - vmlocaltime =3D (int)def->clock.data.variable.basis; - rtc_timeoffset =3D def->clock.data.variable.adjustment; - break; - case VIR_DOMAIN_CLOCK_OFFSET_UTC: - if (def->clock.data.utc_reset) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unsupported clock adjustment=3D'reset'")= ); - goto error; - } - vmlocaltime =3D 0; - rtc_timeoffset =3D 0; - break; - case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: - if (def->clock.data.utc_reset) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unsupported clock adjustment=3D'reset'")= ); - goto error; - } - vmlocaltime =3D 1; - rtc_timeoffset =3D 0; - break; - default: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unsupported clock offset=3D'%s'"), - virDomainClockOffsetTypeToString(def->clock.off= set)); - goto error; - } - virBufferAsprintf(&buf, "(rtc_timeoffset %d)", rtc_timeoffset); - } else { - /* >=3D3.1 PV: UTC and LOCALTIME */ - switch (def->clock.offset) { - case VIR_DOMAIN_CLOCK_OFFSET_UTC: - vmlocaltime =3D 0; - break; - case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: - vmlocaltime =3D 1; - break; - default: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unsupported clock offset=3D'%s'"), - virDomainClockOffsetTypeToString(def->clock.off= set)); - goto error; - } - } /* !hvm */ - /* default post-XenD-3.1 location: */ - virBufferAsprintf(&buf, "(localtime %d)", vmlocaltime); - - if (in_image) { - /* closes (image(hvm|linux */ - virBufferAddLit(&buf, "))"); - in_image =3D false; - } - /* pre-XenD-3.1 and compatibility location */ - virBufferAsprintf(&buf, "(localtime %d)", vmlocaltime); - - - for (i =3D 0; i < def->ndisks; i++) - if (xenFormatSxprDisk(def->disks[i], &buf, hvm, 0) < 0) - goto error; - - for (i =3D 0; i < def->nnets; i++) - if (xenFormatSxprNet(conn, def->nets[i], &buf, hvm, 0) < 0) - goto error; - - if (xenFormatSxprAllPCI(def, &buf) < 0) - goto error; - - /* New style PV graphics config xen >=3D 3.0.4 */ - if (!hvm) { - if ((def->ngraphics =3D=3D 1) && - xenFormatSxprGraphicsNew(def->graphics[0], &buf) < 0) - goto error; - } - - virBufferAddLit(&buf, ")"); /* closes (vm */ - - if (virBufferCheckError(&buf) < 0) - goto error; - - bufout =3D virBufferContentAndReset(&buf); - VIR_DEBUG("Formatted sexpr: \n%s", bufout); - return bufout; - - error: - virBufferFreeAndReset(&buf); - return NULL; -} diff --git a/src/xenconfig/xen_sxpr.h b/src/xenconfig/xen_sxpr.h index 019657380c..93af981544 100644 --- a/src/xenconfig/xen_sxpr.h +++ b/src/xenconfig/xen_sxpr.h @@ -50,17 +50,5 @@ virDomainChrDefPtr xenParseSxprChar(const char *value, c= onst char *tty); int xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_s= ec); -int xenFormatSxprDisk(virDomainDiskDefPtr def, virBufferPtr buf, int hvm, - int isAttach); - -int xenFormatSxprNet(virConnectPtr conn, - virDomainNetDefPtr def, virBufferPtr buf, int hvm, - int isAttach); - -int xenFormatSxprOnePCI(virDomainHostdevDefPtr def, virBufferPtr buf, - int detach); - int xenFormatSxprChr(virDomainChrDefPtr def, virBufferPtr buf); int xenFormatSxprSound(virDomainDefPtr def, virBufferPtr buf); - -char * xenFormatSxpr(virConnectPtr conn, virDomainDefPtr def); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list