From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496654837948827.952411744442; Mon, 5 Jun 2017 02:27:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C51A823E6D9; Mon, 5 Jun 2017 09:27:14 +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 F0C5217F20; Mon, 5 Jun 2017 09:27:13 +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 81E8B4BB74; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559RARS002006 for ; Mon, 5 Jun 2017 05:27:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 32C238401E; Mon, 5 Jun 2017 09:27:10 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BC7E98199A for ; Mon, 5 Jun 2017 09:27:05 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 99C6E10008A; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C51A823E6D9 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C51A823E6D9 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:49 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/15] conf: Make error reporting in virCPUDefIsEqual optional 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 05 Jun 2017 09:27:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The function will be used in paths where mismatching CPU defs are not an error. Signed-off-by: Jiri Denemark --- src/conf/cpu_conf.c | 119 ++++++++++++++++++++++++++++++---------------= ---- src/conf/cpu_conf.h | 3 +- src/conf/domain_conf.c | 2 +- 3 files changed, 77 insertions(+), 47 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index a4be5742e..79ed5e646 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -811,7 +811,8 @@ virCPUDefAddFeature(virCPUDefPtr def, =20 bool virCPUDefIsEqual(virCPUDefPtr src, - virCPUDefPtr dst) + virCPUDefPtr dst, + bool reportError) { bool identical =3D false; size_t i; @@ -820,97 +821,123 @@ virCPUDefIsEqual(virCPUDefPtr src, return true; =20 if ((src && !dst) || (!src && dst)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Target CPU does not match source")); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Target CPU does not match source")); + } goto cleanup; } =20 if (src->type !=3D dst->type) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU type %s does not match source %s"), - virCPUTypeToString(dst->type), - virCPUTypeToString(src->type)); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU type %s does not match source %s"= ), + virCPUTypeToString(dst->type), + virCPUTypeToString(src->type)); + } goto cleanup; } =20 if (src->mode !=3D dst->mode) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU mode %s does not match source %s"), - virCPUModeTypeToString(dst->mode), - virCPUModeTypeToString(src->mode)); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU mode %s does not match source %s"= ), + virCPUModeTypeToString(dst->mode), + virCPUModeTypeToString(src->mode)); + } goto cleanup; } =20 if (src->arch !=3D dst->arch) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU arch %s does not match source %s"), - virArchToString(dst->arch), - virArchToString(src->arch)); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU arch %s does not match source %s"= ), + virArchToString(dst->arch), + virArchToString(src->arch)); + } goto cleanup; } =20 if (STRNEQ_NULLABLE(src->model, dst->model)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU model %s does not match source %s"), - NULLSTR(dst->model), NULLSTR(src->model)); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU model %s does not match source %s= "), + NULLSTR(dst->model), NULLSTR(src->model)); + } goto cleanup; } =20 if (STRNEQ_NULLABLE(src->vendor, dst->vendor)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU vendor %s does not match source %s"), - NULLSTR(dst->vendor), NULLSTR(src->vendor)); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU vendor %s does not match source %= s"), + NULLSTR(dst->vendor), NULLSTR(src->vendor)); + } goto cleanup; } =20 if (STRNEQ_NULLABLE(src->vendor_id, dst->vendor_id)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU vendor id %s does not match source %s= "), - NULLSTR(dst->vendor_id), NULLSTR(src->vendor_id)); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU vendor id %s does not match sourc= e %s"), + NULLSTR(dst->vendor_id), NULLSTR(src->vendor_id= )); + } goto cleanup; } =20 if (src->sockets !=3D dst->sockets) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU sockets %d does not match source %d"), - dst->sockets, src->sockets); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU sockets %d does not match source = %d"), + dst->sockets, src->sockets); + } goto cleanup; } =20 if (src->cores !=3D dst->cores) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU cores %d does not match source %d"), - dst->cores, src->cores); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU cores %d does not match source %d= "), + dst->cores, src->cores); + } goto cleanup; } =20 if (src->threads !=3D dst->threads) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU threads %d does not match source %d"), - dst->threads, src->threads); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU threads %d does not match source = %d"), + dst->threads, src->threads); + } goto cleanup; } =20 if (src->nfeatures !=3D dst->nfeatures) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU feature count %zu does not match sour= ce %zu"), - dst->nfeatures, src->nfeatures); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU feature count %zu does not match = source %zu"), + dst->nfeatures, src->nfeatures); + } goto cleanup; } =20 for (i =3D 0; i < src->nfeatures; i++) { if (STRNEQ(src->features[i].name, dst->features[i].name)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU feature %s does not match source = %s"), - dst->features[i].name, src->features[i].name); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU feature %s does not match sou= rce %s"), + dst->features[i].name, src->features[i].nam= e); + } goto cleanup; } =20 if (src->features[i].policy !=3D dst->features[i].policy) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Target CPU feature policy %s does not match = source %s"), - virCPUFeaturePolicyTypeToString(dst->features[i= ].policy), - virCPUFeaturePolicyTypeToString(src->features[i= ].policy)); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Target CPU feature policy %s does not ma= tch source %s"), + virCPUFeaturePolicyTypeToString(dst->featur= es[i].policy), + virCPUFeaturePolicyTypeToString(src->featur= es[i].policy)); + } goto cleanup; } } @@ -920,8 +947,10 @@ virCPUDefIsEqual(virCPUDefPtr src, (src->cache && dst->cache && (src->cache->level !=3D dst->cache->level || src->cache->mode !=3D dst->cache->mode))) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Target CPU cache does not match source")); + if (reportError) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Target CPU cache does not match source")); + } goto cleanup; } =20 diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index 09438b68b..b0d891552 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -189,7 +189,8 @@ virCPUDefParseXML(xmlNodePtr node, =20 bool virCPUDefIsEqual(virCPUDefPtr src, - virCPUDefPtr dst); + virCPUDefPtr dst, + bool reportError); =20 char * virCPUDefFormat(virCPUDefPtr def, diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9cd39edf2..a61d293c9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -20090,7 +20090,7 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr = src, goto error; } =20 - if (!virCPUDefIsEqual(src->cpu, dst->cpu)) + if (!virCPUDefIsEqual(src->cpu, dst->cpu, true)) goto error; =20 if (!virSysinfoIsEqual(src->sysinfo, dst->sysinfo)) --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496769725987137.8951758730019; Tue, 6 Jun 2017 10:22:05 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id AA51481F07; Tue, 6 Jun 2017 17:21:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73FE05C8BB; Tue, 6 Jun 2017 17:21:58 +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 188F0180BAFD; Tue, 6 Jun 2017 17:21:58 +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 v559R8AG001978 for ; Mon, 5 Jun 2017 05:27:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9B52B17CFF; Mon, 5 Jun 2017 09:27:08 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 219B317CC0 for ; Mon, 5 Jun 2017 09:27:05 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 9CCA810CCF7; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AA51481F07 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AA51481F07 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:50 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/15] conf: Refactor virCPUDefParseXML 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 06 Jun 2017 17:21:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark --- src/conf/cpu_conf.c | 105 +++++++++++++++++++++++++++------------------= ---- src/conf/cpu_conf.h | 9 +++-- src/conf/domain_conf.c | 12 +----- src/cpu/cpu.c | 5 +-- tests/cputest.c | 5 +-- 5 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 79ed5e646..f7f726761 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -245,12 +245,21 @@ virCPUDefCopy(const virCPUDef *cpu) } =20 =20 -virCPUDefPtr -virCPUDefParseXML(xmlNodePtr node, - xmlXPathContextPtr ctxt, - virCPUType type) +/* + * Parses CPU definition XML from a node pointed to by @xpath. If @xpath is + * NULL, the current node of @ctxt is used (i.e., it is a shortcut to "."). + * + * Returns 0 on success, + * 1 when @xpath element cannot be found in @ctxt, + * -1 on error. + */ +int +virCPUDefParseXML(xmlXPathContextPtr ctxt, + const char *xpath, + virCPUType type, + virCPUDefPtr *cpu) { - virCPUDefPtr def; + virCPUDefPtr def =3D NULL; xmlNodePtr *nodes =3D NULL; xmlNodePtr oldnode =3D ctxt->node; int n; @@ -258,15 +267,23 @@ virCPUDefParseXML(xmlNodePtr node, char *cpuMode; char *fallback =3D NULL; char *vendor_id =3D NULL; + int ret =3D -1; =20 - if (!xmlStrEqual(node->name, BAD_CAST "cpu")) { + *cpu =3D NULL; + + if (xpath && !(ctxt->node =3D virXPathNode(xpath, ctxt))) { + ret =3D 1; + goto cleanup; + } + + if (!xmlStrEqual(ctxt->node->name, BAD_CAST "cpu")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("XML does not contain expected 'cpu' element")); - return NULL; + goto cleanup; } =20 if (VIR_ALLOC(def) < 0) - return NULL; + goto cleanup; =20 if (type =3D=3D VIR_CPU_TYPE_AUTO) { if (virXPathBoolean("boolean(./arch)", ctxt)) { @@ -274,7 +291,7 @@ virCPUDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_XML_ERROR, "%s", _("'arch' element cannot be used inside 'cp= u'" " element with 'match' attribute'")); - goto error; + goto cleanup; } def->type =3D VIR_CPU_TYPE_HOST; } else { @@ -284,12 +301,12 @@ virCPUDefParseXML(xmlNodePtr node, def->type =3D type; } =20 - if ((cpuMode =3D virXMLPropString(node, "mode"))) { + if ((cpuMode =3D virXMLPropString(ctxt->node, "mode"))) { if (def->type =3D=3D VIR_CPU_TYPE_HOST) { VIR_FREE(cpuMode); virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Attribute mode is only allowed for guest CPU= ")); - goto error; + goto cleanup; } else { def->mode =3D virCPUModeTypeFromString(cpuMode); =20 @@ -298,7 +315,7 @@ virCPUDefParseXML(xmlNodePtr node, _("Invalid mode attribute '%s'"), cpuMode); VIR_FREE(cpuMode); - goto error; + goto cleanup; } VIR_FREE(cpuMode); } @@ -310,7 +327,7 @@ virCPUDefParseXML(xmlNodePtr node, } =20 if (def->type =3D=3D VIR_CPU_TYPE_GUEST) { - char *match =3D virXMLPropString(node, "match"); + char *match =3D virXMLPropString(ctxt->node, "match"); char *check; =20 if (!match) { @@ -326,11 +343,11 @@ virCPUDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Invalid match attribute for CPU " "specification")); - goto error; + goto cleanup; } } =20 - if ((check =3D virXMLPropString(node, "check"))) { + if ((check =3D virXMLPropString(ctxt->node, "check"))) { int value =3D virCPUCheckTypeFromString(check); VIR_FREE(check); =20 @@ -338,7 +355,7 @@ virCPUDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Invalid check attribute for CPU " "specification")); - goto error; + goto cleanup; } def->check =3D value; } @@ -349,13 +366,13 @@ virCPUDefParseXML(xmlNodePtr node, if (!arch) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing CPU architecture")); - goto error; + goto cleanup; } if ((def->arch =3D virArchFromString(arch)) =3D=3D VIR_ARCH_NONE) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown architecture %s"), arch); VIR_FREE(arch); - goto error; + goto cleanup; } VIR_FREE(arch); } @@ -364,7 +381,7 @@ virCPUDefParseXML(xmlNodePtr node, def->type =3D=3D VIR_CPU_TYPE_HOST) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing CPU model name")); - goto error; + goto cleanup; } =20 if (def->type =3D=3D VIR_CPU_TYPE_GUEST && @@ -374,7 +391,7 @@ virCPUDefParseXML(xmlNodePtr node, if ((def->fallback =3D virCPUFallbackTypeFromString(fallback))= < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Invalid fallback attribute")); - goto error; + goto cleanup; } } =20 @@ -384,14 +401,14 @@ virCPUDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_XML_ERROR, _("vendor_id must be exactly %d characters = long"), VIR_CPU_VENDOR_ID_LENGTH); - goto error; + goto cleanup; } =20 /* ensure that the string can be passed to qemu*/ if (strchr(vendor_id, ',')) { virReportError(VIR_ERR_XML_ERROR, "%s", _("vendor id is invalid")); - goto error; + goto cleanup; } =20 def->vendor_id =3D vendor_id; @@ -403,61 +420,54 @@ virCPUDefParseXML(xmlNodePtr node, if (def->vendor && !def->model) { virReportError(VIR_ERR_XML_ERROR, "%s", _("CPU vendor specified without CPU model")); - goto error; + goto cleanup; } =20 if (virXPathNode("./topology[1]", ctxt)) { - int ret; unsigned long ul; =20 - ret =3D virXPathULong("string(./topology[1]/@sockets)", - ctxt, &ul); - if (ret < 0) { + if (virXPathULong("string(./topology[1]/@sockets)", ctxt, &ul) < 0= ) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing 'sockets' attribute in CPU topology"= )); - goto error; + goto cleanup; } def->sockets =3D (unsigned int) ul; =20 - ret =3D virXPathULong("string(./topology[1]/@cores)", - ctxt, &ul); - if (ret < 0) { + if (virXPathULong("string(./topology[1]/@cores)", ctxt, &ul) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing 'cores' attribute in CPU topology")); - goto error; + goto cleanup; } def->cores =3D (unsigned int) ul; =20 - ret =3D virXPathULong("string(./topology[1]/@threads)", - ctxt, &ul); - if (ret < 0) { + if (virXPathULong("string(./topology[1]/@threads)", ctxt, &ul) < 0= ) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing 'threads' attribute in CPU topology"= )); - goto error; + goto cleanup; } def->threads =3D (unsigned int) ul; =20 if (!def->sockets || !def->cores || !def->threads) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Invalid CPU topology")); - goto error; + goto cleanup; } } =20 if ((n =3D virXPathNodeSet("./feature", ctxt, &nodes)) < 0) - goto error; + goto cleanup; =20 if (n > 0) { if (!def->model && def->mode =3D=3D VIR_CPU_MODE_CUSTOM) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Non-empty feature list specified without " "CPU model")); - goto error; + goto cleanup; } =20 if (VIR_RESIZE_N(def->features, def->nfeatures_max, def->nfeatures, n) < 0) - goto error; + goto cleanup; =20 def->nfeatures =3D n; } @@ -480,7 +490,7 @@ virCPUDefParseXML(xmlNodePtr node, if (policy < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Invalid CPU feature policy")); - goto error; + goto cleanup; } } else { policy =3D -1; @@ -490,7 +500,7 @@ virCPUDefParseXML(xmlNodePtr node, VIR_FREE(name); virReportError(VIR_ERR_XML_ERROR, "%s", _("Invalid CPU feature name")); - goto error; + goto cleanup; } =20 for (j =3D 0; j < i; j++) { @@ -499,7 +509,7 @@ virCPUDefParseXML(xmlNodePtr node, _("CPU feature '%s' specified more than onc= e"), name); VIR_FREE(name); - goto error; + goto cleanup; } } =20 @@ -542,17 +552,16 @@ virCPUDefParseXML(xmlNodePtr node, def->cache->mode =3D mode; } =20 + VIR_STEAL_PTR(*cpu, def); + ret =3D 0; + cleanup: ctxt->node =3D oldnode; VIR_FREE(fallback); VIR_FREE(vendor_id); VIR_FREE(nodes); - return def; - - error: virCPUDefFree(def); - def =3D NULL; - goto cleanup; + return ret; } =20 =20 diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index b0d891552..b44974f47 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -182,10 +182,11 @@ virCPUDefCopy(const virCPUDef *cpu); virCPUDefPtr virCPUDefCopyWithoutModel(const virCPUDef *cpu); =20 -virCPUDefPtr -virCPUDefParseXML(xmlNodePtr node, - xmlXPathContextPtr ctxt, - virCPUType mode); +int +virCPUDefParseXML(xmlXPathContextPtr ctxt, + const char *xpath, + virCPUType mode, + virCPUDefPtr *cpu); =20 bool virCPUDefIsEqual(virCPUDefPtr src, diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a61d293c9..7144914cf 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17444,16 +17444,8 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); =20 - /* analysis of cpu handling */ - if ((node =3D virXPathNode("./cpu[1]", ctxt)) !=3D NULL) { - xmlNodePtr oldnode =3D ctxt->node; - ctxt->node =3D node; - def->cpu =3D virCPUDefParseXML(node, ctxt, VIR_CPU_TYPE_GUEST); - ctxt->node =3D oldnode; - - if (def->cpu =3D=3D NULL) - goto error; - } + if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, &def->cpu)= < 0) + goto error; =20 if (virDomainNumaDefCPUParseXML(def->numa, ctxt) < 0) goto error; diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 702b14dbb..96160901e 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -130,7 +130,7 @@ virCPUCompareXML(virArch arch, if (!(doc =3D virXMLParseStringCtxt(xml, _("(CPU_definition)"), &ctxt)= )) goto cleanup; =20 - if (!(cpu =3D virCPUDefParseXML(ctxt->node, ctxt, VIR_CPU_TYPE_AUTO))) + if (virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_AUTO, &cpu) < 0) goto cleanup; =20 ret =3D virCPUCompare(arch, host, cpu, failIncompatible); @@ -562,8 +562,7 @@ cpuBaselineXML(const char **xmlCPUs, if (!(doc =3D virXMLParseStringCtxt(xmlCPUs[i], _("(CPU_definition= )"), &ctxt))) goto error; =20 - cpus[i] =3D virCPUDefParseXML(ctxt->node, ctxt, VIR_CPU_TYPE_HOST); - if (cpus[i] =3D=3D NULL) + if (virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_HOST, &cpus[i]) < 0) goto error; =20 xmlXPathFreeContext(ctxt); diff --git a/tests/cputest.c b/tests/cputest.c index d5e023c40..89c645e64 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -88,7 +88,7 @@ cpuTestLoadXML(virArch arch, const char *name) if (!(doc =3D virXMLParseFileCtxt(xml, &ctxt))) goto cleanup; =20 - cpu =3D virCPUDefParseXML(ctxt->node, ctxt, VIR_CPU_TYPE_AUTO); + virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_AUTO, &cpu); =20 cleanup: xmlXPathFreeContext(ctxt); @@ -126,8 +126,7 @@ cpuTestLoadMultiXML(virArch arch, =20 for (i =3D 0; i < n; i++) { ctxt->node =3D nodes[i]; - cpus[i] =3D virCPUDefParseXML(nodes[i], ctxt, VIR_CPU_TYPE_HOST); - if (!cpus[i]) + if (virCPUDefParseXML(ctxt, NULL, VIR_CPU_TYPE_HOST, &cpus[i]) < 0) goto cleanup_cpus; } =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496769722558653.9009345334335; Tue, 6 Jun 2017 10:22:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7D70C04B326; Tue, 6 Jun 2017 17:21:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4E126031D; Tue, 6 Jun 2017 17:21:54 +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 5E504180BAFA; Tue, 6 Jun 2017 17:21:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559R8B5001973 for ; Mon, 5 Jun 2017 05:27:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1576584018; Mon, 5 Jun 2017 09:27:08 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D618284011 for ; Mon, 5 Jun 2017 09:27:05 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 9EACD10CCF8; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D7D70C04B326 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D7D70C04B326 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:51 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/15] conf: Make virDomainSnapshotDefFormat easier to read 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 06 Jun 2017 17:21:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark --- src/conf/snapshot_conf.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index b6cba5ac3..7daa9b22a 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -686,11 +686,13 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); } =20 -char *virDomainSnapshotDefFormat(const char *domain_uuid, - virDomainSnapshotDefPtr def, - virCapsPtr caps, - unsigned int flags, - int internal) + +char * +virDomainSnapshotDefFormat(const char *domain_uuid, + virDomainSnapshotDefPtr def, + virCapsPtr caps, + unsigned int flags, + int internal) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; size_t i; @@ -702,12 +704,14 @@ char *virDomainSnapshotDefFormat(const char *domain_u= uid, =20 virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); + virBufferEscapeString(&buf, "%s\n", def->name); if (def->description) virBufferEscapeString(&buf, "%s\n", def->description); virBufferAsprintf(&buf, "%s\n", virDomainSnapshotStateTypeToString(def->state)); + if (def->parent) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); @@ -715,14 +719,17 @@ char *virDomainSnapshotDefFormat(const char *domain_u= uid, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); } + virBufferAsprintf(&buf, "%lld\n", def->creationTime); + if (def->memory) { virBufferAsprintf(&buf, "memor= y)); virBufferEscapeString(&buf, " file=3D'%s'", def->file); virBufferAddLit(&buf, "/>\n"); } + if (def->ndisks) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); @@ -731,11 +738,10 @@ char *virDomainSnapshotDefFormat(const char *domain_u= uid, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); } + if (def->dom) { - if (virDomainDefFormatInternal(def->dom, caps, flags, &buf) < 0) { - virBufferFreeAndReset(&buf); - return NULL; - } + if (virDomainDefFormatInternal(def->dom, caps, flags, &buf) < 0) + goto error; } else if (domain_uuid) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); @@ -743,8 +749,10 @@ char *virDomainSnapshotDefFormat(const char *domain_uu= id, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); } + if (internal) virBufferAsprintf(&buf, "%d\n", def->current); + virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); =20 @@ -752,6 +760,10 @@ char *virDomainSnapshotDefFormat(const char *domain_uu= id, return NULL; =20 return virBufferContentAndReset(&buf); + + error: + virBufferFreeAndReset(&buf); + return NULL; } =20 /* Snapshot Obj functions */ --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496769730293421.968624594977; Tue, 6 Jun 2017 10:22:10 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 9418CC04B31B; Tue, 6 Jun 2017 17:22:02 +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 5872E5C888; Tue, 6 Jun 2017 17:22: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 005254A48D; Tue, 6 Jun 2017 17:22:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559R9Yi001991 for ; Mon, 5 Jun 2017 05:27:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id CC3E97E641; Mon, 5 Jun 2017 09:27:09 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 61EE37E64F for ; Mon, 5 Jun 2017 09:27:05 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A07A210CCF9; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9418CC04B31B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9418CC04B31B From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:52 +0200 Message-Id: <4f73ce6524502eb269b9cf6859953effb3bd0aeb.1496654484.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/15] conf: Pass xmlopt to virDomainSnapshotDefFormat 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 06 Jun 2017 17:22:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark --- Notes: I know the line in vbox_common.c is too long, but I don't really want to touch that horrible piece of code more than making it compile. src/conf/snapshot_conf.c | 1 + src/conf/snapshot_conf.h | 1 + src/esx/esx_driver.c | 2 +- src/qemu/qemu_domain.c | 4 +++- src/qemu/qemu_domain.h | 1 + src/qemu/qemu_driver.c | 16 ++++++++++++---- src/test/test_driver.c | 1 + src/vbox/vbox_common.c | 4 ++-- src/vz/vz_driver.c | 1 + tests/domainsnapshotxml2xmltest.c | 1 + 10 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 7daa9b22a..e3bba985d 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -691,6 +691,7 @@ char * virDomainSnapshotDefFormat(const char *domain_uuid, virDomainSnapshotDefPtr def, virCapsPtr caps, + virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED, unsigned int flags, int internal) { diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index da904f946..2ce526fa6 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -114,6 +114,7 @@ void virDomainSnapshotDefFree(virDomainSnapshotDefPtr d= ef); char *virDomainSnapshotDefFormat(const char *domain_uuid, virDomainSnapshotDefPtr def, virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, unsigned int flags, int internal); int virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr snapshot, diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 6333855c7..1f4f2c7a7 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -4265,7 +4265,7 @@ esxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snap= shot, =20 virUUIDFormat(snapshot->domain->uuid, uuid_string); =20 - xml =3D virDomainSnapshotDefFormat(uuid_string, &def, priv->caps, + xml =3D virDomainSnapshotDefFormat(uuid_string, &def, priv->caps, priv= ->xmlopt, virDomainDefFormatConvertXMLFlags(fla= gs), 0); =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 698632489..814232164 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4820,6 +4820,7 @@ int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, virDomainSnapshotObjPtr snapshot, virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, char *snapshotDir) { char *newxml =3D NULL; @@ -4830,7 +4831,7 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, =20 virUUIDFormat(vm->def->uuid, uuidstr); newxml =3D virDomainSnapshotDefFormat( - uuidstr, snapshot->def, caps, + uuidstr, snapshot->def, caps, xmlopt, virDomainDefFormatConvertXMLFlags(QEMU_DOMAIN_FORMAT_LIVE_FLAGS), 1); if (newxml =3D=3D NULL) @@ -4991,6 +4992,7 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver, } else { parentsnap->def->current =3D true; if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, driver= ->caps, + driver->xmlopt, cfg->snapshotDir) < 0)= { VIR_WARN("failed to set parent snapshot '%s' as curren= t", snap->def->parent); diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 829f7746e..d0e2e0628 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -555,6 +555,7 @@ const char *qemuFindQemuImgBinary(virQEMUDriverPtr driv= er); int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, virDomainSnapshotObjPtr snapshot, virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, char *snapshotDir); =20 int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver, diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f0cdea659..f97d41030 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14649,7 +14649,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, if (update_current) { vm->current_snapshot->def->current =3D false; if (qemuDomainSnapshotWriteMetadata(vm, vm->current_snapshot, - driver->caps, + driver->caps, driver->xmlo= pt, cfg->snapshotDir) < 0) goto endjob; vm->current_snapshot =3D NULL; @@ -14699,6 +14699,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, endjob: if (snapshot && !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)) { if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->caps, + driver->xmlopt, cfg->snapshotDir) < 0) { /* if writing of metadata fails, error out rather than trying * to silently carry on without completing the snapshot */ @@ -15036,7 +15037,8 @@ qemuDomainSnapshotGetXMLDesc(virDomainSnapshotPtr s= napshot, =20 virUUIDFormat(snapshot->domain->uuid, uuidstr); =20 - xml =3D virDomainSnapshotDefFormat(uuidstr, snap->def, driver->caps, + xml =3D virDomainSnapshotDefFormat(uuidstr, snap->def, + driver->caps, driver->xmlopt, virDomainDefFormatConvertXMLFlags(fla= gs), 0); =20 @@ -15218,7 +15220,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, if (vm->current_snapshot) { vm->current_snapshot->def->current =3D false; if (qemuDomainSnapshotWriteMetadata(vm, vm->current_snapshot, - driver->caps, cfg->snapshotDir= ) < 0) + driver->caps, driver->xmlopt, + cfg->snapshotDir) < 0) goto endjob; vm->current_snapshot =3D NULL; /* XXX Should we restore vm->current_snapshot after this point @@ -15458,6 +15461,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, cleanup: if (ret =3D=3D 0) { if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->caps, + driver->xmlopt, cfg->snapshotDir) < 0) ret =3D -1; else @@ -15494,6 +15498,7 @@ struct _virQEMUSnapReparent { virDomainSnapshotObjPtr parent; virDomainObjPtr vm; virCapsPtr caps; + virDomainXMLOptionPtr xmlopt; int err; virDomainSnapshotObjPtr last; }; @@ -15522,7 +15527,8 @@ qemuDomainSnapshotReparentChildren(void *payload, if (!snap->sibling) rep->last =3D snap; =20 - rep->err =3D qemuDomainSnapshotWriteMetadata(rep->vm, snap, rep->caps, + rep->err =3D qemuDomainSnapshotWriteMetadata(rep->vm, snap, + rep->caps, rep->xmlopt, rep->cfg->snapshotDir); return 0; } @@ -15593,6 +15599,7 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snaps= hot, if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { snap->def->current =3D true; if (qemuDomainSnapshotWriteMetadata(vm, snap, driver->caps, + driver->xmlopt, cfg->snapshotDir) < 0)= { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to set snapshot '%s' as curre= nt"), @@ -15610,6 +15617,7 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snaps= hot, rep.err =3D 0; rep.last =3D NULL; rep.caps =3D driver->caps; + rep.xmlopt =3D driver->xmlopt; virDomainSnapshotForEachChild(snap, qemuDomainSnapshotReparentChildren, &rep); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 604f09b19..521c12c11 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -6235,6 +6235,7 @@ testDomainSnapshotGetXMLDesc(virDomainSnapshotPtr sna= pshot, virUUIDFormat(snapshot->domain->uuid, uuidstr); =20 xml =3D virDomainSnapshotDefFormat(uuidstr, snap->def, privconn->caps, + privconn->xmlopt, virDomainDefFormatConvertXMLFlags(fla= gs), 0); =20 diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index c66939e01..1a90d00aa 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -5105,7 +5105,7 @@ vboxSnapshotRedefine(virDomainPtr dom, VIR_FREE(currentSnapshotXmlFilePath); if (virAsprintf(¤tSnapshotXmlFilePath, "%s%s.xml", machineLo= cationPath, snapshotMachineDesc->currentSnapshot) < 0) goto cleanup; - char *snapshotContent =3D virDomainSnapshotDefFormat(NULL, def, da= ta->caps, VIR_DOMAIN_DEF_FORMAT_SECURE, 0); + char *snapshotContent =3D virDomainSnapshotDefFormat(NULL, def, da= ta->caps, data->xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE, 0); if (snapshotContent =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to get snapshot content")); @@ -6027,7 +6027,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSn= apshotPtr snapshot, =20 virUUIDFormat(dom->uuid, uuidstr); memcpy(def->dom->uuid, dom->uuid, VIR_UUID_BUFLEN); - ret =3D virDomainSnapshotDefFormat(uuidstr, def, data->caps, + ret =3D virDomainSnapshotDefFormat(uuidstr, def, data->caps, data->xml= opt, virDomainDefFormatConvertXMLFlags(fl= ags), 0); =20 diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 2c021884f..e6bb20182 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -2303,6 +2303,7 @@ vzDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snaps= hot, unsigned int flags) virUUIDFormat(snapshot->domain->uuid, uuidstr); =20 xml =3D virDomainSnapshotDefFormat(uuidstr, snap->def, privconn->drive= r->caps, + privconn->driver->xmlopt, virDomainDefFormatConvertXMLFlags(fla= gs), 0); =20 diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xm= ltest.c index bb4d60f7d..3a6f86b4a 100644 --- a/tests/domainsnapshotxml2xmltest.c +++ b/tests/domainsnapshotxml2xmltest.c @@ -101,6 +101,7 @@ testCompareXMLToXMLFiles(const char *inxml, goto cleanup; =20 if (!(actual =3D virDomainSnapshotDefFormat(uuid, def, driver.caps, + driver.xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE, internal))) goto cleanup; --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496654837002233.08154433461038; Mon, 5 Jun 2017 02:27:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6D29C04F4C1; Mon, 5 Jun 2017 09:27:14 +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 EC1DA83FE1; Mon, 5 Jun 2017 09:27:13 +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 602F14A48C; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559RAKn001996 for ; Mon, 5 Jun 2017 05:27:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id F3FB68401F; Mon, 5 Jun 2017 09:27:09 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C904B81A7C for ; Mon, 5 Jun 2017 09:27:09 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A23A810CCFA; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B6D29C04F4C1 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B6D29C04F4C1 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:53 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/15] qemu: Rename xml_len in virQEMUSaveHeader as data_len 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 05 Jun 2017 09:27:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark --- src/qemu/qemu_driver.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f97d41030..b0d67adc1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2805,7 +2805,7 @@ typedef virQEMUSaveHeader *virQEMUSaveHeaderPtr; struct _virQEMUSaveHeader { char magic[sizeof(QEMU_SAVE_MAGIC)-1]; uint32_t version; - uint32_t xml_len; + uint32_t data_len; uint32_t was_running; uint32_t compressed; uint32_t unused[15]; @@ -2815,7 +2815,7 @@ static inline void bswap_header(virQEMUSaveHeaderPtr hdr) { hdr->version =3D bswap_32(hdr->version); - hdr->xml_len =3D bswap_32(hdr->xml_len); + hdr->data_len =3D bswap_32(hdr->data_len); hdr->was_running =3D bswap_32(hdr->was_running); hdr->compressed =3D bswap_32(hdr->compressed); } @@ -2836,7 +2836,7 @@ qemuDomainSaveHeader(int fd, const char *path, const = char *xml, goto endjob; } =20 - if (safewrite(fd, xml, header->xml_len) !=3D header->xml_len) { + if (safewrite(fd, xml, header->data_len) !=3D header->data_len) { ret =3D -errno; virReportError(VIR_ERR_OPERATION_FAILED, _("failed to write xml to '%s'"), path); @@ -3082,7 +3082,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, header.version =3D QEMU_SAVE_VERSION; header.was_running =3D was_running ? 1 : 0; header.compressed =3D compressed; - header.xml_len =3D strlen(domXML) + 1; + header.data_len =3D strlen(domXML) + 1; =20 /* Obtain the file handle. */ if ((flags & VIR_DOMAIN_SAVE_BYPASS_CACHE)) { @@ -6276,16 +6276,16 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, goto error; } =20 - if (header.xml_len <=3D 0) { + if (header.data_len <=3D 0) { virReportError(VIR_ERR_OPERATION_FAILED, - _("invalid XML length: %d"), header.xml_len); + _("invalid XML length: %d"), header.data_len); goto error; } =20 - if (VIR_ALLOC_N(xml, header.xml_len) < 0) + if (VIR_ALLOC_N(xml, header.data_len) < 0) goto error; =20 - if (saferead(fd, xml, header.xml_len) !=3D header.xml_len) { + if (saferead(fd, xml, header.data_len) !=3D header.data_len) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to read XML")); goto error; @@ -6629,12 +6629,12 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, co= nst char *path, goto cleanup; len =3D strlen(xml) + 1; =20 - if (len > header.xml_len) { + if (len > header.data_len) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("new xml too large to fit in file")); goto cleanup; } - if (VIR_EXPAND_N(xml, len, header.xml_len - len) < 0) + if (VIR_EXPAND_N(xml, len, header.data_len - len) < 0) goto cleanup; =20 if (lseek(fd, 0, SEEK_SET) !=3D 0) { --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496654853923474.38779659636805; Mon, 5 Jun 2017 02:27:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D668C0467DE; Mon, 5 Jun 2017 09:27:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 72AAA85235; Mon, 5 Jun 2017 09:27:32 +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 DBF8C180BAF2; Mon, 5 Jun 2017 09:27:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559RAOl002011 for ; Mon, 5 Jun 2017 05:27:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 410D78198E; Mon, 5 Jun 2017 09:27:10 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF2BA8199F for ; Mon, 5 Jun 2017 09:27:09 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A421210CCFB; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9D668C0467DE Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9D668C0467DE From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:54 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/15] qemu: Refactor save image header 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 05 Jun 2017 09:27:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Jiri Denemark --- src/qemu/qemu_driver.c | 324 ++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 198 insertions(+), 126 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b0d67adc1..96077df78 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2811,6 +2811,14 @@ struct _virQEMUSaveHeader { uint32_t unused[15]; }; =20 +typedef struct _virQEMUSaveData virQEMUSaveData; +typedef virQEMUSaveData *virQEMUSaveDataPtr; +struct _virQEMUSaveData { + virQEMUSaveHeader header; + char *xml; +}; + + static inline void bswap_header(virQEMUSaveHeaderPtr hdr) { @@ -2821,32 +2829,118 @@ bswap_header(virQEMUSaveHeaderPtr hdr) } =20 =20 -/* return -errno on failure, or 0 on success */ -static int -qemuDomainSaveHeader(int fd, const char *path, const char *xml, - virQEMUSaveHeaderPtr header) +static void +virQEMUSaveDataFree(virQEMUSaveDataPtr data) { - int ret =3D 0; + if (!data) + return; + + VIR_FREE(data->xml); + VIR_FREE(data); +} + + +/** + * This function steals @domXML on success. + */ +static virQEMUSaveDataPtr +virQEMUSaveDataNew(char *domXML, + bool running, + int compressed) +{ + virQEMUSaveDataPtr data =3D NULL; + virQEMUSaveHeaderPtr header; + + if (VIR_ALLOC(data) < 0) + return NULL; + + VIR_STEAL_PTR(data->xml, domXML); + + header =3D &data->header; + memcpy(header->magic, QEMU_SAVE_PARTIAL, sizeof(header->magic)); + header->version =3D QEMU_SAVE_VERSION; + header->was_running =3D running ? 1 : 0; + header->compressed =3D compressed; + + return data; +} + + +/* virQEMUSaveDataWrite: + * + * Writes libvirt's header (including domain XML) into a saved image of a + * running domain. If @header has data_len filled in (because it was previ= ously + * read from the file), the function will make sure the new data will fit + * within data_len. + * + * Returns -1 on failure, or 0 on success. + */ +static int +virQEMUSaveDataWrite(virQEMUSaveDataPtr data, + int fd, + const char *path) +{ + virQEMUSaveHeaderPtr header =3D &data->header; + size_t len; + int ret =3D -1; + + len =3D strlen(data->xml) + 1; + + if (header->data_len > 0) { + if (len > header->data_len) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("new xml too large to fit in file")); + goto cleanup; + } + + if (VIR_EXPAND_N(data->xml, len, header->data_len - len) < 0) + goto cleanup; + } else { + header->data_len =3D len; + } =20 if (safewrite(fd, header, sizeof(*header)) !=3D sizeof(*header)) { - ret =3D -errno; - virReportError(VIR_ERR_OPERATION_FAILED, - _("failed to write header to domain save file '%s'"= ), - path); - goto endjob; + virReportSystemError(errno, + _("failed to write header to domain save file= '%s'"), + path); + goto cleanup; } =20 - if (safewrite(fd, xml, header->data_len) !=3D header->data_len) { - ret =3D -errno; - virReportError(VIR_ERR_OPERATION_FAILED, - _("failed to write xml to '%s'"), path); - goto endjob; + if (safewrite(fd, data->xml, header->data_len) !=3D header->data_len) { + virReportSystemError(errno, + _("failed to write domain xml to '%s'"), + path); + goto cleanup; } - endjob: + + ret =3D 0; + + cleanup: return ret; } =20 =20 +static int +virQEMUSaveDataFinish(virQEMUSaveDataPtr data, + int *fd, + const char *path) +{ + virQEMUSaveHeaderPtr header =3D &data->header; + + memcpy(header->magic, QEMU_SAVE_MAGIC, sizeof(header->magic)); + + if (safewrite(*fd, header, sizeof(*header)) !=3D sizeof(*header) || + VIR_CLOSE(*fd) < 0) { + virReportSystemError(errno, + _("failed to write header to domain save file= '%s'"), + path); + return -1; + } + + return 0; +} + + static virCommandPtr qemuCompressGetCommand(virQEMUSaveFormat compression) { @@ -3061,14 +3155,11 @@ static int qemuDomainSaveMemory(virQEMUDriverPtr driver, virDomainObjPtr vm, const char *path, - const char *domXML, - int compressed, + virQEMUSaveDataPtr data, const char *compressedpath, - bool was_running, unsigned int flags, qemuDomainAsyncJob asyncJob) { - virQEMUSaveHeader header; bool bypassSecurityDriver =3D false; bool needUnlink =3D false; int ret =3D -1; @@ -3077,13 +3168,6 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, virFileWrapperFdPtr wrapperFd =3D NULL; unsigned int wrapperFlags =3D VIR_FILE_WRAPPER_NON_BLOCKING; =20 - memset(&header, 0, sizeof(header)); - memcpy(header.magic, QEMU_SAVE_PARTIAL, sizeof(header.magic)); - header.version =3D QEMU_SAVE_VERSION; - header.was_running =3D was_running ? 1 : 0; - header.compressed =3D compressed; - header.data_len =3D strlen(domXML) + 1; - /* Obtain the file handle. */ if ((flags & VIR_DOMAIN_SAVE_BYPASS_CACHE)) { wrapperFlags |=3D VIR_FILE_WRAPPER_BYPASS_CACHE; @@ -3106,8 +3190,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, if (!(wrapperFd =3D virFileWrapperFdNew(&fd, path, wrapperFlags))) goto cleanup; =20 - /* Write header to file, followed by XML */ - if (qemuDomainSaveHeader(fd, path, domXML, &header) < 0) + if (virQEMUSaveDataWrite(data, fd, path) < 0) goto cleanup; =20 /* Perform the migration */ @@ -3128,21 +3211,10 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, if (virFileWrapperFdClose(wrapperFd) < 0) goto cleanup; =20 - if ((fd =3D qemuOpenFile(driver, vm, path, O_WRONLY, NULL, NULL)) < 0) + if ((fd =3D qemuOpenFile(driver, vm, path, O_WRONLY, NULL, NULL)) < 0 = || + virQEMUSaveDataFinish(data, &fd, path) < 0) goto cleanup; =20 - memcpy(header.magic, QEMU_SAVE_MAGIC, sizeof(header.magic)); - - if (safewrite(fd, &header, sizeof(header)) !=3D sizeof(header)) { - virReportSystemError(errno, _("unable to write %s"), path); - goto cleanup; - } - - if (VIR_CLOSE(fd) < 0) { - virReportSystemError(errno, _("unable to close %s"), path); - goto cleanup; - } - ret =3D 0; =20 cleanup: @@ -3172,6 +3244,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDo= mainPtr dom, virObjectEventPtr event =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; virCapsPtr caps; + virQEMUSaveDataPtr data =3D NULL; =20 if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) goto cleanup; @@ -3237,9 +3310,12 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virD= omainPtr dom, goto endjob; } =20 - ret =3D qemuDomainSaveMemory(driver, vm, path, xml, compressed, - compressedpath, was_running, flags, - QEMU_ASYNC_JOB_SAVE); + if (!(data =3D virQEMUSaveDataNew(xml, was_running, compressed))) + goto endjob; + xml =3D NULL; + + ret =3D qemuDomainSaveMemory(driver, vm, path, data, compressedpath, + flags, QEMU_ASYNC_JOB_SAVE); if (ret < 0) goto endjob; =20 @@ -3272,6 +3348,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDo= mainPtr dom, =20 cleanup: VIR_FREE(xml); + virQEMUSaveDataFree(data); qemuDomainEventQueue(driver, event); virObjectUnref(caps); return ret; @@ -6180,8 +6257,7 @@ qemuDomainSaveImageUpdateDef(virQEMUDriverPtr driver, * @driver: qemu driver data * @path: path of the save image * @ret_def: returns domain definition created from the XML stored in the = image - * @ret_header: returns structure filled with data from the image header - * @xmlout: returns the XML from the image file (may be NULL) + * @ret_data: returns structure filled with data from the image header * @bypass_cache: bypass cache when opening the file * @wrapperFd: returns the file wrapper structure * @open_write: open the file for writing (for updates) @@ -6195,16 +6271,15 @@ static int ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) qemuDomainSaveImageOpen(virQEMUDriverPtr driver, const char *path, virDomainDefPtr *ret_def, - virQEMUSaveHeaderPtr ret_header, - char **xmlout, + virQEMUSaveDataPtr *ret_data, bool bypass_cache, virFileWrapperFdPtr *wrapperFd, bool open_write, bool unlink_corrupt) { int fd =3D -1; - virQEMUSaveHeader header; - char *xml =3D NULL; + virQEMUSaveDataPtr data =3D NULL; + virQEMUSaveHeaderPtr header; virDomainDefPtr def =3D NULL; int oflags =3D open_write ? O_RDWR : O_RDONLY; virCapsPtr caps =3D NULL; @@ -6229,81 +6304,82 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, VIR_FILE_WRAPPER_BYPASS_CACHE))) goto error; =20 - if (saferead(fd, &header, sizeof(header)) !=3D sizeof(header)) { + if (VIR_ALLOC(data) < 0) + goto error; + + header =3D &data->header; + if (saferead(fd, header, sizeof(*header)) !=3D sizeof(*header)) { if (unlink_corrupt) { if (VIR_CLOSE(fd) < 0 || unlink(path) < 0) { virReportSystemError(errno, _("cannot remove corrupt file: %s"), path); - goto error; + } else { + fd =3D -3; } - return -3; + } else { + virReportError(VIR_ERR_OPERATION_FAILED, + "%s", _("failed to read qemu header")); } - virReportError(VIR_ERR_OPERATION_FAILED, - "%s", _("failed to read qemu header")); goto error; } =20 - if (memcmp(header.magic, QEMU_SAVE_MAGIC, sizeof(header.magic)) !=3D 0= ) { + if (memcmp(header->magic, QEMU_SAVE_MAGIC, sizeof(header->magic)) !=3D= 0) { const char *msg =3D _("image magic is incorrect"); =20 - if (memcmp(header.magic, QEMU_SAVE_PARTIAL, - sizeof(header.magic)) =3D=3D 0) { + if (memcmp(header->magic, QEMU_SAVE_PARTIAL, + sizeof(header->magic)) =3D=3D 0) { msg =3D _("save image is incomplete"); if (unlink_corrupt) { if (VIR_CLOSE(fd) < 0 || unlink(path) < 0) { virReportSystemError(errno, _("cannot remove corrupt file: %s= "), path); - goto error; + } else { + fd =3D -3; } - return -3; + goto error; } } virReportError(VIR_ERR_OPERATION_FAILED, "%s", msg); goto error; } =20 - if (header.version > QEMU_SAVE_VERSION) { + if (header->version > QEMU_SAVE_VERSION) { /* convert endianess and try again */ - bswap_header(&header); + bswap_header(header); } =20 - if (header.version > QEMU_SAVE_VERSION) { + if (header->version > QEMU_SAVE_VERSION) { virReportError(VIR_ERR_OPERATION_FAILED, _("image version is not supported (%d > %d)"), - header.version, QEMU_SAVE_VERSION); + header->version, QEMU_SAVE_VERSION); goto error; } =20 - if (header.data_len <=3D 0) { + if (header->data_len <=3D 0) { virReportError(VIR_ERR_OPERATION_FAILED, - _("invalid XML length: %d"), header.data_len); + _("invalid header data length: %d"), header->data_l= en); goto error; } =20 - if (VIR_ALLOC_N(xml, header.data_len) < 0) + if (VIR_ALLOC_N(data->xml, header->data_len) < 0) goto error; =20 - if (saferead(fd, xml, header.data_len) !=3D header.data_len) { + if (saferead(fd, data->xml, header->data_len) !=3D header->data_len) { virReportError(VIR_ERR_OPERATION_FAILED, - "%s", _("failed to read XML")); + "%s", _("failed to read domain XML")); goto error; } =20 /* Create a domain from this XML */ - if (!(def =3D virDomainDefParseString(xml, caps, driver->xmlopt, NULL, + if (!(def =3D virDomainDefParseString(data->xml, caps, driver->xmlopt,= NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE= ))) goto error; =20 - if (xmlout) - *xmlout =3D xml; - else - VIR_FREE(xml); - *ret_def =3D def; - *ret_header =3D header; + *ret_data =3D data; =20 virObjectUnref(caps); =20 @@ -6311,11 +6387,11 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, =20 error: virDomainDefFree(def); - VIR_FREE(xml); + virQEMUSaveDataFree(data); VIR_FORCE_CLOSE(fd); virObjectUnref(caps); =20 - return -1; + return fd; } =20 static int ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(6) @@ -6323,7 +6399,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, virQEMUDriverPtr driver, virDomainObjPtr vm, int *fd, - const virQEMUSaveHeader *header, + virQEMUSaveDataPtr data, const char *path, bool start_paused, qemuDomainAsyncJob asyncJob) @@ -6335,6 +6411,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, virCommandPtr cmd =3D NULL; char *errbuf =3D NULL; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + virQEMUSaveHeaderPtr header =3D &data->header; =20 if ((header->version =3D=3D 2) && (header->compressed !=3D QEMU_SAVE_FORMAT_RAW)) { @@ -6444,12 +6521,11 @@ qemuDomainRestoreFlags(virConnectPtr conn, qemuDomainObjPrivatePtr priv =3D NULL; virDomainDefPtr def =3D NULL; virDomainObjPtr vm =3D NULL; - char *xml =3D NULL; char *xmlout =3D NULL; const char *newxml =3D dxml; int fd =3D -1; int ret =3D -1; - virQEMUSaveHeader header; + virQEMUSaveDataPtr data =3D NULL; virFileWrapperFdPtr wrapperFd =3D NULL; bool hook_taint =3D false; =20 @@ -6460,7 +6536,7 @@ qemuDomainRestoreFlags(virConnectPtr conn, =20 virNWFilterReadLockFilterUpdates(); =20 - fd =3D qemuDomainSaveImageOpen(driver, path, &def, &header, &xml, + fd =3D qemuDomainSaveImageOpen(driver, path, &def, &data, (flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) != =3D 0, &wrapperFd, false, false); if (fd < 0) @@ -6476,7 +6552,7 @@ qemuDomainRestoreFlags(virConnectPtr conn, VIR_HOOK_QEMU_OP_RESTORE, VIR_HOOK_SUBOP_BEGIN, NULL, - dxml ? dxml : xml, + dxml ? dxml : data->xml, &xmlout)) < 0) goto cleanup; =20 @@ -6506,9 +6582,9 @@ qemuDomainRestoreFlags(virConnectPtr conn, def =3D NULL; =20 if (flags & VIR_DOMAIN_SAVE_RUNNING) - header.was_running =3D 1; + data->header.was_running =3D 1; else if (flags & VIR_DOMAIN_SAVE_PAUSED) - header.was_running =3D 0; + data->header.was_running =3D 0; =20 if (hook_taint) { priv =3D vm->privateData; @@ -6518,7 +6594,7 @@ qemuDomainRestoreFlags(virConnectPtr conn, if (qemuProcessBeginJob(driver, vm, VIR_DOMAIN_JOB_OPERATION_RESTORE) = < 0) goto cleanup; =20 - ret =3D qemuDomainSaveImageStartVM(conn, driver, vm, &fd, &header, pat= h, + ret =3D qemuDomainSaveImageStartVM(conn, driver, vm, &fd, data, path, false, QEMU_ASYNC_JOB_START); if (virFileWrapperFdClose(wrapperFd) < 0) VIR_WARN("Failed to close %s", path); @@ -6528,7 +6604,7 @@ qemuDomainRestoreFlags(virConnectPtr conn, cleanup: virDomainDefFree(def); VIR_FORCE_CLOSE(fd); - VIR_FREE(xml); + virQEMUSaveDataFree(data); VIR_FREE(xmlout); virFileWrapperFdFree(wrapperFd); if (vm && ret < 0) @@ -6553,12 +6629,12 @@ qemuDomainSaveImageGetXMLDesc(virConnectPtr conn, c= onst char *path, char *ret =3D NULL; virDomainDefPtr def =3D NULL; int fd =3D -1; - virQEMUSaveHeader header; + virQEMUSaveDataPtr data =3D NULL; =20 /* We only take subset of virDomainDefFormat flags. */ virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL); =20 - fd =3D qemuDomainSaveImageOpen(driver, path, &def, &header, NULL, + fd =3D qemuDomainSaveImageOpen(driver, path, &def, &data, false, NULL, false, false); =20 if (fd < 0) @@ -6570,6 +6646,7 @@ qemuDomainSaveImageGetXMLDesc(virConnectPtr conn, con= st char *path, ret =3D qemuDomainDefFormatXML(driver, def, flags); =20 cleanup: + virQEMUSaveDataFree(data); virDomainDefFree(def); VIR_FORCE_CLOSE(fd); return ret; @@ -6584,9 +6661,7 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, cons= t char *path, virDomainDefPtr def =3D NULL; virDomainDefPtr newdef =3D NULL; int fd =3D -1; - virQEMUSaveHeader header; - char *xml =3D NULL; - size_t len; + virQEMUSaveDataPtr data =3D NULL; int state =3D -1; =20 virCheckFlags(VIR_DOMAIN_SAVE_RUNNING | @@ -6597,7 +6672,7 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, cons= t char *path, else if (flags & VIR_DOMAIN_SAVE_PAUSED) state =3D 0; =20 - fd =3D qemuDomainSaveImageOpen(driver, path, &def, &header, &xml, + fd =3D qemuDomainSaveImageOpen(driver, path, &def, &data, false, NULL, true, false); =20 if (fd < 0) @@ -6606,45 +6681,37 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, co= nst char *path, if (virDomainSaveImageDefineXMLEnsureACL(conn, def) < 0) goto cleanup; =20 - if (STREQ(xml, dxml) && - (state < 0 || state =3D=3D header.was_running)) { + if (STREQ(data->xml, dxml) && + (state < 0 || state =3D=3D data->header.was_running)) { /* no change to the XML */ ret =3D 0; goto cleanup; } =20 if (state >=3D 0) - header.was_running =3D state; + data->header.was_running =3D state; =20 if (!(newdef =3D qemuDomainSaveImageUpdateDef(driver, def, dxml))) goto cleanup; =20 - VIR_FREE(xml); + VIR_FREE(data->xml); =20 - xml =3D qemuDomainDefFormatXML(driver, newdef, - VIR_DOMAIN_XML_INACTIVE | - VIR_DOMAIN_XML_SECURE | - VIR_DOMAIN_XML_MIGRATABLE); - if (!xml) - goto cleanup; - len =3D strlen(xml) + 1; - - if (len > header.data_len) { - virReportError(VIR_ERR_OPERATION_FAILED, "%s", - _("new xml too large to fit in file")); - goto cleanup; - } - if (VIR_EXPAND_N(xml, len, header.data_len - len) < 0) + if (!(data->xml =3D qemuDomainDefFormatXML(driver, newdef, + VIR_DOMAIN_XML_INACTIVE | + VIR_DOMAIN_XML_SECURE | + VIR_DOMAIN_XML_MIGRATABLE))) goto cleanup; =20 if (lseek(fd, 0, SEEK_SET) !=3D 0) { virReportSystemError(errno, _("cannot seek in '%s'"), path); goto cleanup; } - if (safewrite(fd, &header, sizeof(header)) !=3D sizeof(header) || - safewrite(fd, xml, len) !=3D len || - VIR_CLOSE(fd) < 0) { - virReportSystemError(errno, _("failed to write xml to '%s'"), path= ); + + if (virQEMUSaveDataWrite(data, fd, path) < 0) + goto cleanup; + + if (VIR_CLOSE(fd) < 0) { + virReportSystemError(errno, _("failed to write header data to '%s'= "), path); goto cleanup; } =20 @@ -6654,7 +6721,7 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, cons= t char *path, virDomainDefFree(def); virDomainDefFree(newdef); VIR_FORCE_CLOSE(fd); - VIR_FREE(xml); + virQEMUSaveDataFree(data); return ret; } =20 @@ -6673,12 +6740,11 @@ qemuDomainObjRestore(virConnectPtr conn, qemuDomainObjPrivatePtr priv =3D vm->privateData; int fd =3D -1; int ret =3D -1; - char *xml =3D NULL; char *xmlout =3D NULL; - virQEMUSaveHeader header; + virQEMUSaveDataPtr data =3D NULL; virFileWrapperFdPtr wrapperFd =3D NULL; =20 - fd =3D qemuDomainSaveImageOpen(driver, path, &def, &header, &xml, + fd =3D qemuDomainSaveImageOpen(driver, path, &def, &data, bypass_cache, &wrapperFd, false, true); if (fd < 0) { if (fd =3D=3D -3) @@ -6692,7 +6758,7 @@ qemuDomainObjRestore(virConnectPtr conn, if ((hookret =3D virHookCall(VIR_HOOK_DRIVER_QEMU, def->name, VIR_HOOK_QEMU_OP_RESTORE, VIR_HOOK_SUBOP_BEGIN, - NULL, xml, &xmlout)) < 0) + NULL, data->xml, &xmlout)) < 0) goto cleanup; =20 if (hookret =3D=3D 0 && !virStringIsEmpty(xmlout)) { @@ -6726,13 +6792,13 @@ qemuDomainObjRestore(virConnectPtr conn, virDomainObjAssignDef(vm, def, true, NULL); def =3D NULL; =20 - ret =3D qemuDomainSaveImageStartVM(conn, driver, vm, &fd, &header, pat= h, + ret =3D qemuDomainSaveImageStartVM(conn, driver, vm, &fd, data, path, start_paused, asyncJob); if (virFileWrapperFdClose(wrapperFd) < 0) VIR_WARN("Failed to close %s", path); =20 cleanup: - VIR_FREE(xml); + virQEMUSaveDataFree(data); VIR_FREE(xmlout); virDomainDefFree(def); VIR_FORCE_CLOSE(fd); @@ -14298,6 +14364,7 @@ qemuDomainSnapshotCreateActiveExternal(virConnectPt= r conn, virQEMUDriverConfigPtr cfg =3D NULL; int compressed; char *compressedpath =3D NULL; + virQEMUSaveDataPtr data =3D NULL; =20 /* If quiesce was requested, then issue a freeze command, and a * counterpart thaw command when it is actually sent to agent. @@ -14369,9 +14436,13 @@ qemuDomainSnapshotCreateActiveExternal(virConnectP= tr conn, if (!(xml =3D qemuDomainDefFormatLive(driver, vm->def, true, true)= )) goto cleanup; =20 - if ((ret =3D qemuDomainSaveMemory(driver, vm, snap->def->file, xml, - compressed, compressedpath, resume, - 0, QEMU_ASYNC_JOB_SNAPSHOT)) < 0) + if (!(data =3D virQEMUSaveDataNew(xml, resume, compressed))) + goto cleanup; + xml =3D NULL; + + if ((ret =3D qemuDomainSaveMemory(driver, vm, snap->def->file, dat= a, + compressedpath, 0, + QEMU_ASYNC_JOB_SNAPSHOT)) < 0) goto cleanup; =20 /* the memory image was created, remove it on errors */ @@ -14439,6 +14510,7 @@ qemuDomainSnapshotCreateActiveExternal(virConnectPt= r conn, ret =3D -1; } =20 + virQEMUSaveDataFree(data); VIR_FREE(xml); VIR_FREE(compressedpath); virObjectUnref(cfg); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149665486458841.395425733656; Mon, 5 Jun 2017 02:27:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4F52796E9; Mon, 5 Jun 2017 09:27:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C2FEA7E642; Mon, 5 Jun 2017 09:27:42 +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 8214E180BAFA; Mon, 5 Jun 2017 09:27:42 +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 v559RDn3002078 for ; Mon, 5 Jun 2017 05:27:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 46D2A8A0CC; Mon, 5 Jun 2017 09:27:13 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E84158A0AC for ; Mon, 5 Jun 2017 09:27:09 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id A88B010CCFC; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E4F52796E9 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E4F52796E9 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:55 +0200 Message-Id: <3359ae1ad91246a9a3c894a8ad8d5d28869bf4b9.1496654484.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/15] conf: Introduce virSaveCookie 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 05 Jun 2017 09:27:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The code will be used by snapshots and domain save/restore code to store additional data for a saved running domain. It is analogous to migration cookies, but simple and one way only. Signed-off-by: Jiri Denemark --- po/POTFILES.in | 1 + src/Makefile.am | 1 + src/conf/virsavecookie.c | 144 +++++++++++++++++++++++++++++++++++++++++++= ++++ src/conf/virsavecookie.h | 62 ++++++++++++++++++++ src/libvirt_private.syms | 7 +++ 5 files changed, 215 insertions(+) create mode 100644 src/conf/virsavecookie.c create mode 100644 src/conf/virsavecookie.h diff --git a/po/POTFILES.in b/po/POTFILES.in index 142b4d337..1ca77a4cf 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -48,6 +48,7 @@ src/conf/virinterfaceobj.c src/conf/virnetworkobj.c src/conf/virnodedeviceobj.c src/conf/virnwfilterobj.c +src/conf/virsavecookie.c src/conf/virsecretobj.c src/conf/virstorageobj.c src/cpu/cpu.c diff --git a/src/Makefile.am b/src/Makefile.am index 0b7cfc89a..eae32dc58 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -402,6 +402,7 @@ DOMAIN_CONF_SOURCES =3D \ conf/domain_conf.c conf/domain_conf.h \ conf/domain_audit.c conf/domain_audit.h \ conf/domain_nwfilter.c conf/domain_nwfilter.h \ + conf/virsavecookie.c conf/virsavecookie.h \ conf/snapshot_conf.c conf/snapshot_conf.h \ conf/numa_conf.c conf/numa_conf.h \ conf/virdomainobjlist.c conf/virdomainobjlist.h diff --git a/src/conf/virsavecookie.c b/src/conf/virsavecookie.c new file mode 100644 index 000000000..502c04d0f --- /dev/null +++ b/src/conf/virsavecookie.c @@ -0,0 +1,144 @@ +/** + * virsavecookie.c: Save cookie handling + * + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virerror.h" +#include "virlog.h" +#include "virobject.h" +#include "virbuffer.h" +#include "virxml.h" +#include "virsavecookie.h" + +#define VIR_FROM_THIS VIR_FROM_CONF + +VIR_LOG_INIT("conf.savecookie"); + + +static int +virSaveCookieParseNode(xmlXPathContextPtr ctxt, + virObjectPtr *obj, + virSaveCookieCallbacksPtr saveCookie) +{ + *obj =3D NULL; + + if (!xmlStrEqual(ctxt->node->name, BAD_CAST "cookie")) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("XML does not contain expected 'cookie' element")= ); + return -1; + } + + if (!saveCookie || !saveCookie->parse) + return 0; + + return saveCookie->parse(ctxt, obj); +} + + +int +virSaveCookieParse(xmlXPathContextPtr ctxt, + virObjectPtr *obj, + virSaveCookieCallbacksPtr saveCookie) +{ + xmlNodePtr node =3D ctxt->node; + int ret =3D -1; + + *obj =3D NULL; + + if (!(ctxt->node =3D virXPathNode("./cookie", ctxt))) { + ret =3D 0; + goto cleanup; + } + + ret =3D virSaveCookieParseNode(ctxt, obj, saveCookie); + + cleanup: + ctxt->node =3D node; + return ret; +} + + +int +virSaveCookieParseString(const char *xml, + virObjectPtr *obj, + virSaveCookieCallbacksPtr saveCookie) +{ + xmlDocPtr doc =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + int ret =3D -1; + + *obj =3D NULL; + + if (!xml) { + ret =3D 0; + goto cleanup; + } + + if (!(doc =3D virXMLParseStringCtxt(xml, _("(save cookie)"), &ctxt))) + goto cleanup; + + ret =3D virSaveCookieParseNode(ctxt, obj, saveCookie); + + cleanup: + xmlXPathFreeContext(ctxt); + xmlFreeDoc(doc); + return ret; +} + + +int +virSaveCookieFormatBuf(virBufferPtr buf, + virObjectPtr obj, + virSaveCookieCallbacksPtr saveCookie) +{ + if (!obj || !saveCookie || !saveCookie->format) + return 0; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + if (saveCookie->format(buf, obj) < 0) + return -1; + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + return 0; +} + + +char * +virSaveCookieFormat(virObjectPtr obj, + virSaveCookieCallbacksPtr saveCookie) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + if (virSaveCookieFormatBuf(&buf, obj, saveCookie) < 0) + goto error; + + if (virBufferCheckError(&buf) < 0) + goto error; + + return virBufferContentAndReset(&buf); + + error: + virBufferFreeAndReset(&buf); + return NULL; +} diff --git a/src/conf/virsavecookie.h b/src/conf/virsavecookie.h new file mode 100644 index 000000000..4aed18466 --- /dev/null +++ b/src/conf/virsavecookie.h @@ -0,0 +1,62 @@ +/** + * virsavecookie.h: Save cookie handling + * + * Copyright (C) 2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ +#ifndef __VIR_SAVE_COOKIE_H__ +# define __VIR_SAVE_COOKIE_H__ + +# include + +# include "internal.h" +# include "virobject.h" +# include "virbuffer.h" + + +typedef int (*virSaveCookieParseFunc)(xmlXPathContextPtr ctxt, + virObjectPtr *obj); +typedef int (*virSaveCookieFormatFunc)(virBufferPtr buf, + virObjectPtr obj); + +typedef struct _virSaveCookieCallbacks virSaveCookieCallbacks; +typedef virSaveCookieCallbacks *virSaveCookieCallbacksPtr; +struct _virSaveCookieCallbacks { + virSaveCookieParseFunc parse; + virSaveCookieFormatFunc format; +}; + + +int +virSaveCookieParse(xmlXPathContextPtr ctxt, + virObjectPtr *obj, + virSaveCookieCallbacksPtr saveCookie); + +int +virSaveCookieParseString(const char *xml, + virObjectPtr *obj, + virSaveCookieCallbacksPtr saveCookie); + +int +virSaveCookieFormatBuf(virBufferPtr buf, + virObjectPtr obj, + virSaveCookieCallbacksPtr saveCookie); + +char * +virSaveCookieFormat(virObjectPtr obj, + virSaveCookieCallbacksPtr saveCookie); + +#endif /*__VIR_SAVE_COOKIE_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 886245c24..863c71cf3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -991,6 +991,13 @@ virNWFilterObjUnlock; virNWFilterObjWantRemoved; =20 =20 +# conf/virsavecookie.h +virSaveCookieFormat; +virSaveCookieFormatBuf; +virSaveCookieParse; +virSaveCookieParseString; + + # conf/virsecretobj.h virSecretLoadAllConfigs; virSecretObjDeleteConfig; --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496769740203195.53700717724598; Tue, 6 Jun 2017 10:22:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C54738A003; Tue, 6 Jun 2017 17:22:17 +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 5DC707E570; Tue, 6 Jun 2017 17:22:17 +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 101604A490; Tue, 6 Jun 2017 17:22:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559RClg002073 for ; Mon, 5 Jun 2017 05:27:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC29E785B8; Mon, 5 Jun 2017 09:27:12 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 70B34869FC for ; Mon, 5 Jun 2017 09:27:09 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id ABB2010CCFD; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C54738A003 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C54738A003 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:56 +0200 Message-Id: <25516b40e08065a230bd8abbad7927bf334ccec4.1496654484.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/15] conf: Add save cookie callbacks to xmlopt 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 06 Jun 2017 17:22:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" virDomainXMLOption gains driver specific callbacks for parsing and formatting save cookies. Signed-off-by: Jiri Denemark --- src/bhyve/bhyve_domain.c | 2 +- src/conf/domain_conf.c | 16 +++++++++++++++- src/conf/domain_conf.h | 7 ++++++- src/conf/snapshot_conf.c | 11 ++++++++++- src/conf/snapshot_conf.h | 2 ++ src/libvirt_private.syms | 1 + src/libxl/libxl_conf.c | 2 +- src/lxc/lxc_conf.c | 2 +- src/openvz/openvz_driver.c | 2 +- src/phyp/phyp_driver.c | 2 +- src/qemu/qemu_capabilities.c | 2 +- src/qemu/qemu_conf.c | 3 ++- src/security/virt-aa-helper.c | 2 +- src/test/test_driver.c | 2 +- src/uml/uml_driver.c | 2 +- src/vbox/vbox_common.c | 2 +- src/vmware/vmware_driver.c | 3 ++- src/vmx/vmx.c | 2 +- src/vz/vz_driver.c | 2 +- src/xen/xen_driver.c | 2 +- src/xenapi/xenapi_driver.c | 2 +- tests/bhyveargv2xmltest.c | 2 +- tests/testutils.c | 2 +- 23 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 0a99550af..20c82937b 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -144,7 +144,7 @@ virBhyveDriverCreateXMLConf(bhyveConnPtr driver) virBhyveDriverDomainDefParserConfig.priv =3D driver; return virDomainXMLOptionNew(&virBhyveDriverDomainDefParserConfig, &virBhyveDriverPrivateDataCallbacks, - NULL, NULL); + NULL, NULL, NULL); } =20 virDomainDefParserConfig virBhyveDriverDomainDefParserConfig =3D { diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7144914cf..d3bc3655e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -79,6 +79,9 @@ struct _virDomainXMLOption { =20 /* ABI stability callbacks */ virDomainABIStability abi; + + /* Private data for save image stored in snapshot XML */ + virSaveCookieCallbacks saveCookie; }; =20 #define VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS \ @@ -1054,7 +1057,8 @@ virDomainXMLOptionPtr virDomainXMLOptionNew(virDomainDefParserConfigPtr config, virDomainXMLPrivateDataCallbacksPtr priv, virDomainXMLNamespacePtr xmlns, - virDomainABIStabilityPtr abi) + virDomainABIStabilityPtr abi, + virSaveCookieCallbacksPtr saveCookie) { virDomainXMLOptionPtr xmlopt; =20 @@ -1076,6 +1080,9 @@ virDomainXMLOptionNew(virDomainDefParserConfigPtr con= fig, if (abi) xmlopt->abi =3D *abi; =20 + if (saveCookie) + xmlopt->saveCookie =3D *saveCookie; + /* Technically this forbids to use one of Xerox's MAC address prefixes= in * our hypervisor drivers. This shouldn't ever be a problem. * @@ -1106,6 +1113,13 @@ virDomainXMLOptionGetNamespace(virDomainXMLOptionPtr= xmlopt) } =20 =20 +virSaveCookieCallbacksPtr +virDomainXMLOptionGetSaveCookie(virDomainXMLOptionPtr xmlopt) +{ + return &xmlopt->saveCookie; +} + + void virBlkioDeviceArrayClear(virBlkioDevicePtr devices, int ndevices) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 446b117b7..1231aeac6 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -55,6 +55,7 @@ # include "virgic.h" # include "virperf.h" # include "virtypedparam.h" +# include "virsavecookie.h" =20 /* forward declarations of all device types, required by * virDomainDeviceDef @@ -2549,7 +2550,11 @@ struct _virDomainABIStability { virDomainXMLOptionPtr virDomainXMLOptionNew(virDomainDefParserConfigPtr co= nfig, virDomainXMLPrivateDataCallbac= ksPtr priv, virDomainXMLNamespacePtr xmlns, - virDomainABIStabilityPtr abi); + virDomainABIStabilityPtr abi, + virSaveCookieCallbacksPtr save= Cookie); + +virSaveCookieCallbacksPtr +virDomainXMLOptionGetSaveCookie(virDomainXMLOptionPtr xmlopt); =20 void virDomainNetGenerateMAC(virDomainXMLOptionPtr xmlopt, virMacAddrPtr m= ac); =20 diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index e3bba985d..6330f7d1f 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -102,6 +102,7 @@ void virDomainSnapshotDefFree(virDomainSnapshotDefPtr d= ef) virDomainSnapshotDiskDefClear(&def->disks[i]); VIR_FREE(def->disks); virDomainDefFree(def->dom); + virObjectUnref(def->cookie); VIR_FREE(def); } =20 @@ -214,6 +215,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, char *memorySnapshot =3D NULL; char *memoryFile =3D NULL; bool offline =3D !!(flags & VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE); + virSaveCookieCallbacksPtr saveCookie =3D virDomainXMLOptionGetSaveCook= ie(xmlopt); =20 if (VIR_ALLOC(def) < 0) goto cleanup; @@ -365,6 +367,9 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, def->current =3D active !=3D 0; } =20 + if (!offline && virSaveCookieParse(ctxt, &def->cookie, saveCookie) < 0) + goto cleanup; + ret =3D def; =20 cleanup: @@ -691,7 +696,7 @@ char * virDomainSnapshotDefFormat(const char *domain_uuid, virDomainSnapshotDefPtr def, virCapsPtr caps, - virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED, + virDomainXMLOptionPtr xmlopt, unsigned int flags, int internal) { @@ -751,6 +756,10 @@ virDomainSnapshotDefFormat(const char *domain_uuid, virBufferAddLit(&buf, "\n"); } =20 + if (virSaveCookieFormatBuf(&buf, def->cookie, + virDomainXMLOptionGetSaveCookie(xmlopt)) < = 0) + goto error; + if (internal) virBufferAsprintf(&buf, "%d\n", def->current); =20 diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 2ce526fa6..1d663c77b 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -76,6 +76,8 @@ struct _virDomainSnapshotDef { =20 virDomainDefPtr dom; =20 + virObjectPtr cookie; + /* Internal use. */ bool current; /* At most one snapshot in the list should have this set= */ }; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 863c71cf3..fad31b475 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -535,6 +535,7 @@ virDomainWatchdogActionTypeToString; virDomainWatchdogModelTypeFromString; virDomainWatchdogModelTypeToString; virDomainXMLOptionGetNamespace; +virDomainXMLOptionGetSaveCookie; virDomainXMLOptionNew; =20 =20 diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 886dc629f..04d9dd1bd 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -2255,5 +2255,5 @@ libxlCreateXMLConf(void) { return virDomainXMLOptionNew(&libxlDomainDefParserConfig, &libxlDomainXMLPrivateDataCallbacks, - NULL, NULL); + NULL, NULL, NULL); } diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index ff975decc..92a82a476 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -216,7 +216,7 @@ lxcDomainXMLConfInit(void) return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig, &virLXCDriverPrivateDataCallbacks, &virLXCDriverDomainXMLNamespace, - NULL); + NULL, NULL); } =20 =20 diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 8e305a85c..a1485fc88 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1483,7 +1483,7 @@ static virDrvOpenStatus openvzConnectOpen(virConnectP= tr conn, goto cleanup; =20 if (!(driver->xmlopt =3D virDomainXMLOptionNew(&openvzDomainDefParserC= onfig, - NULL, NULL, NULL))) + NULL, NULL, NULL, NULL))) goto cleanup; =20 if (openvzLoadDomains(driver) < 0) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 4465ac862..9121581fe 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1202,7 +1202,7 @@ phypConnectOpen(virConnectPtr conn, goto failure; =20 if (!(phyp_driver->xmlopt =3D virDomainXMLOptionNew(&virPhypDriverDoma= inDefParserConfig, - NULL, NULL, NULL))) + NULL, NULL, NULL, NU= LL))) goto failure; =20 conn->privateData =3D phyp_driver; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 03c55853f..7f2249259 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -5026,7 +5026,7 @@ virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPComman= dPtr cmd, goto ignore; } =20 - if (!(xmlopt =3D virDomainXMLOptionNew(NULL, NULL, NULL, NULL)) || + if (!(xmlopt =3D virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) = || !(cmd->vm =3D virDomainObjNew(xmlopt))) goto cleanup; =20 diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index d8b88386d..d02e776b0 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -910,7 +910,8 @@ virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver) return virDomainXMLOptionNew(&virQEMUDriverDomainDefParserConfig, &virQEMUDriverPrivateDataCallbacks, &virQEMUDriverDomainXMLNamespace, - &virQEMUDriverDomainABIStability); + &virQEMUDriverDomainABIStability, + NULL); } =20 =20 diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 48201d5b8..97436e5dc 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -667,7 +667,7 @@ get_definition(vahControl * ctl, const char *xmlStr) goto exit; } =20 - if (!(ctl->xmlopt =3D virDomainXMLOptionNew(NULL, NULL, NULL, NULL))) { + if (!(ctl->xmlopt =3D virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NU= LL))) { vah_error(ctl, 0, _("Failed to create XML config object")); goto exit; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 521c12c11..2cfaf70b2 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -414,7 +414,7 @@ testDriverNew(void) goto error; } =20 - if (!(ret->xmlopt =3D virDomainXMLOptionNew(NULL, NULL, &ns, NULL)) || + if (!(ret->xmlopt =3D virDomainXMLOptionNew(NULL, NULL, &ns, NULL, NUL= L)) || !(ret->eventState =3D virObjectEventStateNew()) || !(ret->ifaces =3D virInterfaceObjListNew()) || !(ret->domains =3D virDomainObjListNew()) || diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 58ab033c8..080fea47d 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -533,7 +533,7 @@ umlStateInitialize(bool privileged, goto out_of_memory; =20 if (!(uml_driver->xmlopt =3D virDomainXMLOptionNew(¨DriverDomainDef= ParserConfig, - &privcb, NULL, NULL))) + &privcb, NULL, NULL, = NULL))) goto error; =20 if ((uml_driver->inotifyFD =3D inotify_init()) < 0) { diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 1a90d00aa..c46e71bcf 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -142,7 +142,7 @@ vboxDriverObjNew(void) =20 if (!(driver->caps =3D vboxCapsInit()) || !(driver->xmlopt =3D virDomainXMLOptionNew(&vboxDomainDefParserCon= fig, - NULL, NULL, NULL))) + NULL, NULL, NULL, NULL))) goto cleanup; =20 return driver; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 9e369e67b..0ee1c5bb9 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -114,7 +114,8 @@ vmwareDomainXMLConfigInit(void) virDomainXMLPrivateDataCallbacks priv =3D { .alloc =3D vmwareDataAlloc= Func, .free =3D vmwareDataFreeFunc= }; =20 - return virDomainXMLOptionNew(&vmwareDomainDefParserConfig, &priv, NULL= , NULL); + return virDomainXMLOptionNew(&vmwareDomainDefParserConfig, &priv, + NULL, NULL, NULL); } =20 static virDrvOpenStatus diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 3289a2002..96507f10f 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -591,7 +591,7 @@ virDomainXMLOptionPtr virVMXDomainXMLConfInit(void) { return virDomainXMLOptionNew(&virVMXDomainDefParserConfig, NULL, - &virVMXDomainXMLNamespace, NULL); + &virVMXDomainXMLNamespace, NULL, NULL); } =20 char * diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index e6bb20182..7aa0c4c48 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -328,7 +328,7 @@ vzDriverObjNew(void) if (!(driver->caps =3D vzBuildCapabilities()) || !(driver->xmlopt =3D virDomainXMLOptionNew(&vzDomainDefParserConfi= g, &vzDomainXMLPrivateDataCa= llbacksPtr, - NULL, NULL)) || + NULL, NULL, NULL)) || !(driver->domains =3D virDomainObjListNew()) || !(driver->domainEventState =3D virObjectEventStateNew()) || (vzInitVersion(driver) < 0) || diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index f81ee20ad..8e7bc350c 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -401,7 +401,7 @@ virDomainXMLOptionPtr xenDomainXMLConfInit(void) { return virDomainXMLOptionNew(&xenDomainDefParserConfig, - NULL, NULL, NULL); + NULL, NULL, NULL, NULL); } =20 =20 diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 380c3a1de..fb462cd3a 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -200,7 +200,7 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr= auth, } =20 if (!(privP->xmlopt =3D virDomainXMLOptionNew(&xenapiDomainDefParserCo= nfig, - NULL, NULL, NULL))) { + NULL, NULL, NULL, NULL))) { xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, _("Failed to create XML conf object")); goto error; diff --git a/tests/bhyveargv2xmltest.c b/tests/bhyveargv2xmltest.c index bde7d0e05..e1c0294cb 100644 --- a/tests/bhyveargv2xmltest.c +++ b/tests/bhyveargv2xmltest.c @@ -131,7 +131,7 @@ mymain(void) return EXIT_FAILURE; =20 if ((driver.xmlopt =3D virDomainXMLOptionNew(NULL, NULL, - NULL, NULL)) =3D=3D NULL) + NULL, NULL, NULL)) =3D=3D N= ULL) return EXIT_FAILURE; =20 # define DO_TEST_FULL(name, flags) \ diff --git a/tests/testutils.c b/tests/testutils.c index 4b8cf79ef..f45596997 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1136,7 +1136,7 @@ virDomainXMLOptionPtr virTestGenericDomainXMLConfInit= (void) { return virDomainXMLOptionNew(&virTestGenericDomainDefParserConfig, &virTestGenericPrivateDataCallbacks, - NULL, NULL); + NULL, NULL, NULL); } =20 =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496654860871127.668371803161; Mon, 5 Jun 2017 02:27:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 928F5CED6; Mon, 5 Jun 2017 09:27:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 66E528B1C8; Mon, 5 Jun 2017 09:27:39 +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 252FF180BAF5; Mon, 5 Jun 2017 09:27:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559RC2J002063 for ; Mon, 5 Jun 2017 05:27:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8D1E7A31E; Mon, 5 Jun 2017 09:27:12 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82C907A303 for ; Mon, 5 Jun 2017 09:27:10 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id ADDB610CCFE; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 928F5CED6 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 928F5CED6 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:57 +0200 Message-Id: <5e81c5e65b7e5c23b152b38dd03cd35e661788c9.1496654484.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/15] qemu: Implement virSaveCookie object and callbacks 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 05 Jun 2017 09:27:40 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch implements a new save cookie object and callbacks for qemu driver. The actual useful content will be added in the object later. Signed-off-by: Jiri Denemark --- src/qemu/qemu_conf.c | 2 +- src/qemu/qemu_domain.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++= ++-- src/qemu/qemu_domain.h | 9 ++++++ 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index d02e776b0..73c33d678 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -911,7 +911,7 @@ virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver) &virQEMUDriverPrivateDataCallbacks, &virQEMUDriverDomainXMLNamespace, &virQEMUDriverDomainABIStability, - NULL); + &virQEMUDriverDomainSaveCookie); } =20 =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 814232164..80e9fea98 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -122,11 +122,13 @@ struct _qemuDomainLogContext { }; =20 static virClassPtr qemuDomainLogContextClass; +static virClassPtr qemuDomainSaveCookieClass; =20 static void qemuDomainLogContextDispose(void *obj); +static void qemuDomainSaveCookieDispose(void *obj); =20 static int -qemuDomainLogContextOnceInit(void) +qemuDomainOnceInit(void) { if (!(qemuDomainLogContextClass =3D virClassNew(virClassForObject(), "qemuDomainLogContext", @@ -134,10 +136,16 @@ qemuDomainLogContextOnceInit(void) qemuDomainLogContextDispo= se))) return -1; =20 + if (!(qemuDomainSaveCookieClass =3D virClassNew(virClassForObject(), + "qemuDomainSaveCookie", + sizeof(qemuDomainSaveCoo= kie), + qemuDomainSaveCookieDisp= ose))) + return -1; + return 0; } =20 -VIR_ONCE_GLOBAL_INIT(qemuDomainLogContext) +VIR_ONCE_GLOBAL_INIT(qemuDomain) =20 static void qemuDomainLogContextDispose(void *obj) @@ -4554,7 +4562,7 @@ qemuDomainLogContextPtr qemuDomainLogContextNew(virQE= MUDriverPtr driver, virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); qemuDomainLogContextPtr ctxt =3D NULL; =20 - if (qemuDomainLogContextInitialize() < 0) + if (qemuDomainInitialize() < 0) goto cleanup; =20 if (!(ctxt =3D virObjectNew(qemuDomainLogContextClass))) @@ -9105,3 +9113,68 @@ qemuDomainGetStorageSourceByDevstr(const char *devst= r, VIR_FREE(target); return src; } + + +static void +qemuDomainSaveCookieDispose(void *obj) +{ + qemuDomainSaveCookiePtr cookie =3D obj; + + VIR_DEBUG("cookie=3D%p", cookie); +} + + +qemuDomainSaveCookiePtr +qemuDomainSaveCookieNew(virDomainObjPtr vm ATTRIBUTE_UNUSED) +{ + qemuDomainSaveCookiePtr cookie =3D NULL; + + if (qemuDomainInitialize() < 0) + goto error; + + if (!(cookie =3D virObjectNew(qemuDomainSaveCookieClass))) + goto error; + + VIR_DEBUG("Save cookie %p", cookie); + + return cookie; + + error: + virObjectUnref(cookie); + return NULL; +} + + +static int +qemuDomainSaveCookieParse(xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED, + virObjectPtr *obj) +{ + qemuDomainSaveCookiePtr cookie =3D NULL; + + if (qemuDomainInitialize() < 0) + goto error; + + if (!(cookie =3D virObjectNew(qemuDomainSaveCookieClass))) + goto error; + + *obj =3D (virObjectPtr) cookie; + return 0; + + error: + virObjectUnref(cookie); + return -1; +} + + +static int +qemuDomainSaveCookieFormat(virBufferPtr buf ATTRIBUTE_UNUSED, + virObjectPtr obj ATTRIBUTE_UNUSED) +{ + return 0; +} + + +virSaveCookieCallbacks virQEMUDriverDomainSaveCookie =3D { + .parse =3D qemuDomainSaveCookieParse, + .format =3D qemuDomainSaveCookieFormat, +}; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index d0e2e0628..cc2e21bdf 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -416,6 +416,14 @@ struct qemuProcessEvent { typedef struct _qemuDomainLogContext qemuDomainLogContext; typedef qemuDomainLogContext *qemuDomainLogContextPtr; =20 +typedef struct _qemuDomainSaveCookie qemuDomainSaveCookie; +typedef qemuDomainSaveCookie *qemuDomainSaveCookiePtr; +struct _qemuDomainSaveCookie { + virObject parent; +}; + +qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm); + const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job, int phase); int qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job, @@ -638,6 +646,7 @@ extern virDomainXMLPrivateDataCallbacks virQEMUDriverPr= ivateDataCallbacks; extern virDomainXMLNamespace virQEMUDriverDomainXMLNamespace; extern virDomainDefParserConfig virQEMUDriverDomainDefParserConfig; extern virDomainABIStability virQEMUDriverDomainABIStability; +extern virSaveCookieCallbacks virQEMUDriverDomainSaveCookie; =20 int qemuDomainUpdateDeviceList(virQEMUDriverPtr driver, virDomainObjPtr vm, int asyncJob); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496769736605127.49372575746656; Tue, 6 Jun 2017 10:22:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D7C880471; Tue, 6 Jun 2017 17:22:14 +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 B41F981B54; Tue, 6 Jun 2017 17:22:13 +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 6AE934A48C; Tue, 6 Jun 2017 17:22:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559RCwg002062 for ; Mon, 5 Jun 2017 05:27:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8A01869FE; Mon, 5 Jun 2017 09:27:12 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82D2C7A319 for ; Mon, 5 Jun 2017 09:27:09 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id AF9FD10CCFF; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0D7C880471 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0D7C880471 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:58 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/15] qemu: Store save cookie in save images and snapshots 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 06 Jun 2017 17:22:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The following patches will add an actual content in the cookie and use the data when restoring a domain. Signed-off-by: Jiri Denemark --- docs/formatsnapshot.html.in | 6 +++ docs/schemas/domainsnapshot.rng | 7 ++++ src/qemu/qemu_driver.c | 90 ++++++++++++++++++++++++++++++++++++-= ---- 3 files changed, 93 insertions(+), 10 deletions(-) diff --git a/docs/formatsnapshot.html.in b/docs/formatsnapshot.html.in index c3ab516fa..5e8e21c8a 100644 --- a/docs/formatsnapshot.html.in +++ b/docs/formatsnapshot.html.in @@ -235,6 +235,12 @@ at the time of the snapshot (since 0.9.5). Readonly. +
cookie
+
Save image cookie containing additional data libvirt may need to + properly restore a domain from an active snapshot when such data + cannot be stored directly in the domain to maintain + compatibility with older libvirt or hypervisor. Readonly. +
=20

Examples

diff --git a/docs/schemas/domainsnapshot.rng b/docs/schemas/domainsnapshot.= rng index 4ab1b828f..268088709 100644 --- a/docs/schemas/domainsnapshot.rng +++ b/docs/schemas/domainsnapshot.rng @@ -90,6 +90,13 @@ + + + + + + + diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 96077df78..10df56e61 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2808,7 +2808,8 @@ struct _virQEMUSaveHeader { uint32_t data_len; uint32_t was_running; uint32_t compressed; - uint32_t unused[15]; + uint32_t cookie; + uint32_t unused[14]; }; =20 typedef struct _virQEMUSaveData virQEMUSaveData; @@ -2816,6 +2817,7 @@ typedef virQEMUSaveData *virQEMUSaveDataPtr; struct _virQEMUSaveData { virQEMUSaveHeader header; char *xml; + char *cookie; }; =20 =20 @@ -2826,6 +2828,7 @@ bswap_header(virQEMUSaveHeaderPtr hdr) hdr->data_len =3D bswap_32(hdr->data_len); hdr->was_running =3D bswap_32(hdr->was_running); hdr->compressed =3D bswap_32(hdr->compressed); + hdr->cookie =3D bswap_32(hdr->cookie); } =20 =20 @@ -2836,6 +2839,7 @@ virQEMUSaveDataFree(virQEMUSaveDataPtr data) return; =20 VIR_FREE(data->xml); + VIR_FREE(data->cookie); VIR_FREE(data); } =20 @@ -2845,8 +2849,10 @@ virQEMUSaveDataFree(virQEMUSaveDataPtr data) */ static virQEMUSaveDataPtr virQEMUSaveDataNew(char *domXML, + qemuDomainSaveCookiePtr cookie, bool running, - int compressed) + int compressed, + virDomainXMLOptionPtr xmlopt) { virQEMUSaveDataPtr data =3D NULL; virQEMUSaveHeaderPtr header; @@ -2856,6 +2862,11 @@ virQEMUSaveDataNew(char *domXML, =20 VIR_STEAL_PTR(data->xml, domXML); =20 + if (cookie && + !(data->cookie =3D virSaveCookieFormat((virObjectPtr) cookie, + virDomainXMLOptionGetSaveCook= ie(xmlopt)))) + goto error; + header =3D &data->header; memcpy(header->magic, QEMU_SAVE_PARTIAL, sizeof(header->magic)); header->version =3D QEMU_SAVE_VERSION; @@ -2863,6 +2874,10 @@ virQEMUSaveDataNew(char *domXML, header->compressed =3D compressed; =20 return data; + + error: + virQEMUSaveDataFree(data); + return NULL; } =20 =20 @@ -2882,9 +2897,15 @@ virQEMUSaveDataWrite(virQEMUSaveDataPtr data, { virQEMUSaveHeaderPtr header =3D &data->header; size_t len; + size_t xml_len; + size_t cookie_len =3D 0; int ret =3D -1; =20 - len =3D strlen(data->xml) + 1; + xml_len =3D strlen(data->xml) + 1; + if (data->cookie) + cookie_len =3D strlen(data->cookie) + 1; + + len =3D xml_len + cookie_len; =20 if (header->data_len > 0) { if (len > header->data_len) { @@ -2893,12 +2914,15 @@ virQEMUSaveDataWrite(virQEMUSaveDataPtr data, goto cleanup; } =20 - if (VIR_EXPAND_N(data->xml, len, header->data_len - len) < 0) + if (VIR_EXPAND_N(data->xml, xml_len, header->data_len - len) < 0) goto cleanup; } else { header->data_len =3D len; } =20 + if (data->cookie) + header->cookie =3D xml_len; + if (safewrite(fd, header, sizeof(*header)) !=3D sizeof(*header)) { virReportSystemError(errno, _("failed to write header to domain save file= '%s'"), @@ -2906,13 +2930,21 @@ virQEMUSaveDataWrite(virQEMUSaveDataPtr data, goto cleanup; } =20 - if (safewrite(fd, data->xml, header->data_len) !=3D header->data_len) { + if (safewrite(fd, data->xml, xml_len) !=3D xml_len) { virReportSystemError(errno, _("failed to write domain xml to '%s'"), path); goto cleanup; } =20 + if (data->cookie && + safewrite(fd, data->cookie, cookie_len) !=3D cookie_len) { + virReportSystemError(errno, + _("failed to write cookie to '%s'"), + path); + goto cleanup; + } + ret =3D 0; =20 cleanup: @@ -3245,6 +3277,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDo= mainPtr dom, qemuDomainObjPrivatePtr priv =3D vm->privateData; virCapsPtr caps; virQEMUSaveDataPtr data =3D NULL; + qemuDomainSaveCookiePtr cookie =3D NULL; =20 if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) goto cleanup; @@ -3310,7 +3343,11 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virD= omainPtr dom, goto endjob; } =20 - if (!(data =3D virQEMUSaveDataNew(xml, was_running, compressed))) + if (!(cookie =3D qemuDomainSaveCookieNew(vm))) + goto endjob; + + if (!(data =3D virQEMUSaveDataNew(xml, cookie, was_running, compressed, + driver->xmlopt))) goto endjob; xml =3D NULL; =20 @@ -3347,6 +3384,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDo= mainPtr dom, qemuDomainRemoveInactive(driver, vm); =20 cleanup: + virObjectUnref(cookie); VIR_FREE(xml); virQEMUSaveDataFree(data); qemuDomainEventQueue(driver, event); @@ -6283,6 +6321,8 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, virDomainDefPtr def =3D NULL; int oflags =3D open_write ? O_RDWR : O_RDONLY; virCapsPtr caps =3D NULL; + size_t xml_len; + size_t cookie_len; =20 if (bypass_cache) { int directFlag =3D virFileDirectFdFlag(); @@ -6363,15 +6403,33 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver, goto error; } =20 - if (VIR_ALLOC_N(data->xml, header->data_len) < 0) + if (header->cookie) + xml_len =3D header->cookie; + else + xml_len =3D header->data_len; + + cookie_len =3D header->data_len - xml_len; + + if (VIR_ALLOC_N(data->xml, xml_len) < 0) goto error; =20 - if (saferead(fd, data->xml, header->data_len) !=3D header->data_len) { + if (saferead(fd, data->xml, xml_len) !=3D xml_len) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to read domain XML")); goto error; } =20 + if (cookie_len > 0) { + if (VIR_ALLOC_N(data->cookie, cookie_len) < 0) + goto error; + + if (saferead(fd, data->cookie, cookie_len) !=3D cookie_len) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to read cookie")); + goto error; + } + } + /* Create a domain from this XML */ if (!(def =3D virDomainDefParseString(data->xml, caps, driver->xmlopt,= NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE | @@ -6412,6 +6470,11 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, char *errbuf =3D NULL; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); virQEMUSaveHeaderPtr header =3D &data->header; + qemuDomainSaveCookiePtr cookie =3D NULL; + + if (virSaveCookieParseString(data->cookie, (virObjectPtr *) &cookie, + virDomainXMLOptionGetSaveCookie(driver->x= mlopt)) < 0) + goto cleanup; =20 if ((header->version =3D=3D 2) && (header->compressed !=3D QEMU_SAVE_FORMAT_RAW)) { @@ -6502,6 +6565,7 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, ret =3D 0; =20 cleanup: + virObjectUnref(cookie); virCommandFree(cmd); VIR_FREE(errbuf); if (qemuSecurityRestoreSavedStateLabel(driver->securityManager, @@ -13554,6 +13618,9 @@ qemuDomainSnapshotCreateActiveInternal(virConnectPt= r conn, if (ret < 0) goto cleanup; =20 + if (!(snap->def->cookie =3D (virObjectPtr) qemuDomainSaveCookieNew(vm)= )) + goto cleanup; + if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT) { event =3D virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_S= TOPPED, VIR_DOMAIN_EVENT_STOPPED_FROM_SNA= PSHOT); @@ -14433,10 +14500,13 @@ qemuDomainSnapshotCreateActiveExternal(virConnect= Ptr conn, "snapshot", false)) < = 0) goto cleanup; =20 - if (!(xml =3D qemuDomainDefFormatLive(driver, vm->def, true, true)= )) + if (!(xml =3D qemuDomainDefFormatLive(driver, vm->def, true, true)= ) || + !(snap->def->cookie =3D (virObjectPtr) qemuDomainSaveCookieNew= (vm))) goto cleanup; =20 - if (!(data =3D virQEMUSaveDataNew(xml, resume, compressed))) + if (!(data =3D virQEMUSaveDataNew(xml, + (qemuDomainSaveCookiePtr) snap->de= f->cookie, + resume, compressed, driver->xmlopt= ))) goto cleanup; xml =3D NULL; =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496769735157703.753787965646; Tue, 6 Jun 2017 10:22:15 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 68640142A6F; Tue, 6 Jun 2017 17:22:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 466C117D10; Tue, 6 Jun 2017 17:22:10 +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 07A6D181A104; Tue, 6 Jun 2017 17:22:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559RCo4002051 for ; Mon, 5 Jun 2017 05:27:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 70424869FD; Mon, 5 Jun 2017 09:27:12 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34E5A869FF for ; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B15F610CD00; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 68640142A6F Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 68640142A6F From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:26:59 +0200 Message-Id: <1f4c51a67449e33bd660a7f141b9d3334d81c06e.1496654484.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/15] qemu: Remember CPU def from domain start 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 06 Jun 2017 17:22:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When starting a domain we update the guest CPU definition to match what QEMU actually provided (since it is allowed to add or removed some features unless check=3D'full' is specified). Let's store the original CPU in domain private data so that we can use it to provide a backward compatible domain XML. Signed-off-by: Jiri Denemark --- src/libvirt_private.syms | 2 ++ src/qemu/qemu_domain.c | 7 +++++++ src/qemu/qemu_domain.h | 4 ++++ src/qemu/qemu_process.c | 13 +++++++++++-- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fad31b475..3b91145c5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -77,9 +77,11 @@ virCPUDefCopyModelFilter; virCPUDefCopyWithoutModel; virCPUDefFormat; virCPUDefFormatBuf; +virCPUDefFormatBufFull; virCPUDefFree; virCPUDefFreeFeatures; virCPUDefFreeModel; +virCPUDefIsEqual; virCPUDefParseXML; virCPUDefStealModel; virCPUDefUpdateFeature; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 80e9fea98..ba8079ba0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1726,6 +1726,8 @@ qemuDomainObjPrivateFree(void *data) VIR_FREE(priv->migTLSAlias); qemuDomainMasterKeyFree(priv); =20 + virCPUDefFree(priv->origCPU); + VIR_FREE(priv); } =20 @@ -1881,6 +1883,8 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, virBufferEscapeString(buf, "\n", priv->channelTargetDir); =20 + virCPUDefFormatBufFull(buf, priv->origCPU, NULL, false); + return 0; } =20 @@ -2149,6 +2153,9 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, if (qemuDomainSetPrivatePathsOld(driver, vm) < 0) goto error; =20 + if (virCPUDefParseXML(ctxt, "./cpu", VIR_CPU_TYPE_GUEST, &priv->origCP= U) < 0) + goto error; + return 0; =20 error: diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index cc2e21bdf..f6dad4378 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -293,6 +293,10 @@ struct _qemuDomainObjPrivate { /* Used when fetching/storing the current 'tls-creds' migration settin= g */ /* (not to be saved in our private XML). */ char *migTLSAlias; + + /* CPU def used to start the domain when it differs from the one actua= lly + * provided by QEMU. */ + virCPUDefPtr origCPU; }; =20 # define QEMU_DOMAIN_PRIVATE(vm) \ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index be031b56b..8f4902e10 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3913,6 +3913,7 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver, qemuDomainObjPrivatePtr priv =3D vm->privateData; int rc; int ret =3D -1; + virCPUDefPtr orig =3D NULL; =20 if (ARCH_IS_X86(def->os.arch)) { if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) @@ -3943,10 +3944,17 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driv= er, if (qemuProcessVerifyCPUFeatures(def, cpu) < 0) goto cleanup; =20 - if ((rc =3D virCPUUpdateLive(def->os.arch, def->cpu, cpu, disabled= )) < 0) + if (!(orig =3D virCPUDefCopy(def->cpu))) goto cleanup; - else if (rc =3D=3D 0) + + if ((rc =3D virCPUUpdateLive(def->os.arch, def->cpu, cpu, disabled= )) < 0) { + goto cleanup; + } else if (rc =3D=3D 0) { + if (!virCPUDefIsEqual(def->cpu, orig, false)) + VIR_STEAL_PTR(priv->origCPU, orig); + def->cpu->check =3D VIR_CPU_CHECK_FULL; + } } =20 ret =3D 0; @@ -3954,6 +3962,7 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver, cleanup: virCPUDataFree(cpu); virCPUDataFree(disabled); + virCPUDefFree(orig); return ret; } =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496769728954353.7572328041306; Tue, 6 Jun 2017 10:22:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17A45155E4; Tue, 6 Jun 2017 17:22:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D35E87D4E6; Tue, 6 Jun 2017 17:22:06 +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 8C5F1180BAFE; Tue, 6 Jun 2017 17:22:06 +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 v559RBaM002038 for ; Mon, 5 Jun 2017 05:27:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id A274D8B1C3; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A8E78B1CC for ; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B471910CD01; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 17A45155E4 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 17A45155E4 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:27:00 +0200 Message-Id: <809ea075c3b3558a6c5d021bf06276ffd4468c12.1496654484.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/15] qemu: Report the original CPU in migratable xml 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 06 Jun 2017 17:22:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The destination host may not be able to start a domain using the live updated CPU definition because either libvirt or QEMU may not be new enough. Thus we need to send the original guest CPU definition. Signed-off-by: Jiri Denemark --- src/qemu/qemu_domain.c | 61 ++++++++++++++++++++++++++++++++++++++-----= ---- src/qemu/qemu_domain.h | 1 + src/qemu/qemu_driver.c | 13 ++++++---- src/qemu/qemu_migration.c | 5 ++-- 4 files changed, 63 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ba8079ba0..0da44f066 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4216,11 +4216,13 @@ qemuDomainDefCopy(virQEMUDriverPtr driver, return ret; } =20 -int -qemuDomainDefFormatBuf(virQEMUDriverPtr driver, - virDomainDefPtr def, - unsigned int flags, - virBuffer *buf) + +static int +qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver, + virDomainDefPtr def, + virCPUDefPtr origCPU, + unsigned int flags, + virBuffer *buf) { int ret =3D -1; virDomainDefPtr copy =3D NULL; @@ -4341,6 +4343,16 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver, if (qemuDomainChrDefDropDefaultPath(def->channels[i], driver) = < 0) goto cleanup; } + + /* Replace the CPU definition updated according to QEMU with the o= ne + * used for starting the domain. The updated def will be sent + * separately for backward compatibility. + */ + if (origCPU) { + virCPUDefFree(def->cpu); + if (!(def->cpu =3D virCPUDefCopy(origCPU))) + goto cleanup; + } } =20 format: @@ -4354,13 +4366,26 @@ qemuDomainDefFormatBuf(virQEMUDriverPtr driver, return ret; } =20 -char *qemuDomainDefFormatXML(virQEMUDriverPtr driver, - virDomainDefPtr def, - unsigned int flags) + +int +qemuDomainDefFormatBuf(virQEMUDriverPtr driver, + virDomainDefPtr def, + unsigned int flags, + virBufferPtr buf) +{ + return qemuDomainDefFormatBufInternal(driver, def, NULL, flags, buf); +} + + +static char * +qemuDomainDefFormatXMLInternal(virQEMUDriverPtr driver, + virDomainDefPtr def, + virCPUDefPtr origCPU, + unsigned int flags) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; =20 - if (qemuDomainDefFormatBuf(driver, def, flags, &buf) < 0) { + if (qemuDomainDefFormatBufInternal(driver, def, origCPU, flags, &buf) = < 0) { virBufferFreeAndReset(&buf); return NULL; } @@ -4374,26 +4399,40 @@ char *qemuDomainDefFormatXML(virQEMUDriverPtr drive= r, return virBufferContentAndReset(&buf); } =20 + +char * +qemuDomainDefFormatXML(virQEMUDriverPtr driver, + virDomainDefPtr def, + unsigned int flags) +{ + return qemuDomainDefFormatXMLInternal(driver, def, NULL, flags); +} + + char *qemuDomainFormatXML(virQEMUDriverPtr driver, virDomainObjPtr vm, unsigned int flags) { virDomainDefPtr def; + qemuDomainObjPrivatePtr priv =3D vm->privateData; + virCPUDefPtr origCPU =3D NULL; =20 if ((flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef) { def =3D vm->newDef; } else { def =3D vm->def; + origCPU =3D priv->origCPU; if (virDomainObjIsActive(vm)) flags &=3D ~VIR_DOMAIN_XML_UPDATE_CPU; } =20 - return qemuDomainDefFormatXML(driver, def, flags); + return qemuDomainDefFormatXMLInternal(driver, def, origCPU, flags); } =20 char * qemuDomainDefFormatLive(virQEMUDriverPtr driver, virDomainDefPtr def, + virCPUDefPtr origCPU, bool inactive, bool compatible) { @@ -4404,7 +4443,7 @@ qemuDomainDefFormatLive(virQEMUDriverPtr driver, if (compatible) flags |=3D VIR_DOMAIN_XML_MIGRATABLE; =20 - return qemuDomainDefFormatXML(driver, def, flags); + return qemuDomainDefFormatXMLInternal(driver, def, origCPU, flags); } =20 =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index f6dad4378..08c0b32f1 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -515,6 +515,7 @@ char *qemuDomainFormatXML(virQEMUDriverPtr driver, =20 char *qemuDomainDefFormatLive(virQEMUDriverPtr driver, virDomainDefPtr def, + virCPUDefPtr origCPU, bool inactive, bool compatible); =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 10df56e61..10b9b10bc 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3333,9 +3333,9 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDo= mainPtr dom, virDomainDefFree(def); goto endjob; } - xml =3D qemuDomainDefFormatLive(driver, def, true, true); + xml =3D qemuDomainDefFormatLive(driver, def, NULL, true, true); } else { - xml =3D qemuDomainDefFormatLive(driver, vm->def, true, true); + xml =3D qemuDomainDefFormatLive(driver, vm->def, priv->origCPU, tr= ue, true); } if (!xml) { virReportError(VIR_ERR_OPERATION_FAILED, @@ -14500,7 +14500,8 @@ qemuDomainSnapshotCreateActiveExternal(virConnectPt= r conn, "snapshot", false)) < = 0) goto cleanup; =20 - if (!(xml =3D qemuDomainDefFormatLive(driver, vm->def, true, true)= ) || + if (!(xml =3D qemuDomainDefFormatLive(driver, vm->def, priv->origC= PU, + true, true)) || !(snap->def->cookie =3D (virObjectPtr) qemuDomainSaveCookieNew= (vm))) goto cleanup; =20 @@ -14611,6 +14612,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, bool align_match =3D true; virQEMUDriverConfigPtr cfg =3D NULL; virCapsPtr caps =3D NULL; + qemuDomainObjPrivatePtr priv; =20 virCheckFlags(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE | VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT | @@ -14728,6 +14730,8 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, =20 qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_NONE); =20 + priv =3D vm->privateData; + if (redefine) { if (virDomainSnapshotRedefinePrep(domain, vm, &def, &snap, driver->xmlopt, @@ -14736,7 +14740,8 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, } else { /* Easiest way to clone inactive portion of vm->def is via * conversion in and back out of xml. */ - if (!(xml =3D qemuDomainDefFormatLive(driver, vm->def, true, true)= ) || + if (!(xml =3D qemuDomainDefFormatLive(driver, vm->def, priv->origC= PU, + true, true)) || !(def->dom =3D virDomainDefParseString(xml, caps, driver->xmlo= pt, NULL, VIR_DOMAIN_DEF_PARSE_INAC= TIVE | VIR_DOMAIN_DEF_PARSE_SKIP= _VALIDATE))) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 3c0d7e957..2cd862875 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2059,9 +2059,10 @@ qemuMigrationBeginPhase(virQEMUDriverPtr driver, if (!qemuDomainDefCheckABIStability(driver, vm->def, def)) goto cleanup; =20 - rv =3D qemuDomainDefFormatLive(driver, def, false, true); + rv =3D qemuDomainDefFormatLive(driver, def, NULL, false, true); } else { - rv =3D qemuDomainDefFormatLive(driver, vm->def, false, true); + rv =3D qemuDomainDefFormatLive(driver, vm->def, priv->origCPU, + false, true); } =20 cleanup: --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496654857896721.7302594394043; Mon, 5 Jun 2017 02:27:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A756104C9; Mon, 5 Jun 2017 09:27:36 +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 153D57E643; Mon, 5 Jun 2017 09:27:36 +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 C22754A48D; Mon, 5 Jun 2017 09:27:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559RBHP002025 for ; Mon, 5 Jun 2017 05:27:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8CD183FE0; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 79B2983FF6 for ; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B6DD710CD02; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3A756104C9 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3A756104C9 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:27:01 +0200 Message-Id: <3cba38ca3dd4dda9e049c1c06908270309f07465.1496654484.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/15] qemu: Send updated CPU in migration cookie 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 05 Jun 2017 09:27:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since the domain XML send during migration uses the original guest CPU definition but we still want the destination to enforce ABI if it is new enough, we send the live updated CPU definition in a migration cookie. Signed-off-by: Jiri Denemark --- src/qemu/qemu_migration.c | 11 ++++++++--- src/qemu/qemu_migration_cookie.c | 31 ++++++++++++++++++++++++++++++- src/qemu/qemu_migration_cookie.h | 5 +++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 2cd862875..134c76c5e 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2020,6 +2020,9 @@ qemuMigrationBeginPhase(virQEMUDriverPtr driver, vm->newDef && !qemuDomainVcpuHotplugIsInOrder(vm->newDef))) cookieFlags |=3D QEMU_MIGRATION_COOKIE_CPU_HOTPLUG; =20 + if (priv->origCPU) + cookieFlags |=3D QEMU_MIGRATION_COOKIE_CPU; + if (!(mig =3D qemuMigrationEatCookie(driver, vm, NULL, 0, 0))) goto cleanup; =20 @@ -2644,7 +2647,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, QEMU_MIGRATION_COOKIE_LOCKSTATE | QEMU_MIGRATION_COOKIE_NBD | QEMU_MIGRATION_COOKIE_MEMORY_HOTPLU= G | - QEMU_MIGRATION_COOKIE_CPU_HOTPLUG))) + QEMU_MIGRATION_COOKIE_CPU_HOTPLUG | + QEMU_MIGRATION_COOKIE_CPU))) goto cleanup; =20 if (STREQ_NULLABLE(protocol, "rdma") && @@ -3644,8 +3648,9 @@ qemuMigrationRun(virQEMUDriverPtr driver, if (!(persistDef =3D qemuMigrationPrepareDef(driver, persist_x= ml, NULL, NULL))) goto cleanup; - } else if (vm->newDef) { - if (!(persistDef =3D qemuDomainDefCopy(driver, vm->newDef, + } else { + virDomainDefPtr def =3D vm->newDef ? vm->newDef : vm->def; + if (!(persistDef =3D qemuDomainDefCopy(driver, def, VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_MIGRATABLE= ))) goto cleanup; diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_coo= kie.c index 12887892d..9d8bdbe72 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -48,7 +48,8 @@ VIR_ENUM_IMPL(qemuMigrationCookieFlag, "nbd", "statistics", "memory-hotplug", - "cpu-hotplug"); + "cpu-hotplug", + "cpu"); =20 =20 static void @@ -109,6 +110,7 @@ qemuMigrationCookieFree(qemuMigrationCookiePtr mig) VIR_FREE(mig->lockState); VIR_FREE(mig->lockDriver); VIR_FREE(mig->jobInfo); + virCPUDefFree(mig->cpu); VIR_FREE(mig); } =20 @@ -519,6 +521,22 @@ qemuMigrationCookieAddStatistics(qemuMigrationCookiePt= r mig, } =20 =20 +static int +qemuMigrationCookieAddCPU(qemuMigrationCookiePtr mig, + virDomainObjPtr vm) +{ + if (mig->cpu) + return 0; + + if (!(mig->cpu =3D virCPUDefCopy(vm->def->cpu))) + return -1; + + mig->flags |=3D QEMU_MIGRATION_COOKIE_CPU; + + return 0; +} + + static void qemuMigrationCookieGraphicsXMLFormat(virBufferPtr buf, qemuMigrationCookieGraphicsPtr grap) @@ -755,6 +773,9 @@ qemuMigrationCookieXMLFormat(virQEMUDriverPtr driver, if (mig->flags & QEMU_MIGRATION_COOKIE_STATS && mig->jobInfo) qemuMigrationCookieStatisticsXMLFormat(buf, mig->jobInfo); =20 + if (mig->flags & QEMU_MIGRATION_COOKIE_CPU && mig->cpu) + virCPUDefFormatBufFull(buf, mig->cpu, NULL, false); + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); return 0; @@ -1198,6 +1219,10 @@ qemuMigrationCookieXMLParse(qemuMigrationCookiePtr m= ig, (!(mig->jobInfo =3D qemuMigrationCookieStatisticsXMLParse(ctxt)))) goto error; =20 + if (flags & QEMU_MIGRATION_COOKIE_CPU && + virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, &mig->cpu)= < 0) + goto error; + virObjectUnref(caps); return 0; =20 @@ -1274,6 +1299,10 @@ qemuMigrationBakeCookie(qemuMigrationCookiePtr mig, if (flags & QEMU_MIGRATION_COOKIE_CPU_HOTPLUG) mig->flagsMandatory |=3D QEMU_MIGRATION_COOKIE_CPU_HOTPLUG; =20 + if (flags & QEMU_MIGRATION_COOKIE_CPU && + qemuMigrationCookieAddCPU(mig, dom) < 0) + return -1; + if (!(*cookieout =3D qemuMigrationCookieXMLFormatStr(driver, mig))) return -1; =20 diff --git a/src/qemu/qemu_migration_cookie.h b/src/qemu/qemu_migration_coo= kie.h index b009d5bf5..e5f3d75a9 100644 --- a/src/qemu/qemu_migration_cookie.h +++ b/src/qemu/qemu_migration_cookie.h @@ -28,6 +28,7 @@ typedef enum { QEMU_MIGRATION_COOKIE_FLAG_STATS, QEMU_MIGRATION_COOKIE_FLAG_MEMORY_HOTPLUG, QEMU_MIGRATION_COOKIE_FLAG_CPU_HOTPLUG, + QEMU_MIGRATION_COOKIE_FLAG_CPU, =20 QEMU_MIGRATION_COOKIE_FLAG_LAST } qemuMigrationCookieFlags; @@ -43,6 +44,7 @@ typedef enum { QEMU_MIGRATION_COOKIE_STATS =3D (1 << QEMU_MIGRATION_COOKIE_FLAG_STATS= ), QEMU_MIGRATION_COOKIE_MEMORY_HOTPLUG =3D (1 << QEMU_MIGRATION_COOKIE_F= LAG_MEMORY_HOTPLUG), QEMU_MIGRATION_COOKIE_CPU_HOTPLUG =3D (1 << QEMU_MIGRATION_COOKIE_FLAG= _CPU_HOTPLUG), + QEMU_MIGRATION_COOKIE_CPU =3D (1 << QEMU_MIGRATION_COOKIE_FLAG_CPU), } qemuMigrationCookieFeatures; =20 typedef struct _qemuMigrationCookieGraphics qemuMigrationCookieGraphics; @@ -122,6 +124,9 @@ struct _qemuMigrationCookie { =20 /* If (flags & QEMU_MIGRATION_COOKIE_STATS) */ qemuDomainJobInfoPtr jobInfo; + + /* If flags & QEMU_MIGRATION_COOKIE_CPU */ + virCPUDefPtr cpu; }; =20 =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496654858885562.2196709137544; Mon, 5 Jun 2017 02:27:38 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31AB53DBE1; Mon, 5 Jun 2017 09:27:37 +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 0914A81975; Mon, 5 Jun 2017 09:27:37 +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 B9F564A492; Mon, 5 Jun 2017 09:27:36 +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 v559RBML002029 for ; Mon, 5 Jun 2017 05:27:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8F3B18B1C9; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FDC27E9F6 for ; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B939610CD03; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 31AB53DBE1 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 31AB53DBE1 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:27:02 +0200 Message-Id: <4a87f7d2fae5883e53e9e7194ba8e9f9f7a9eec9.1496654484.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/15] qemu: Store updated CPU in save cookie 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 05 Jun 2017 09:27:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since the domain XML saved in a snapshot or saved image uses the original guest CPU definition but we still want to enforce ABI when restoring the domain if libvirt and QEMU are new enough, we save the live updated CPU definition in a save cookie. Signed-off-by: Jiri Denemark --- src/qemu/qemu_domain.c | 22 +++++++++++++++++++--- src/qemu/qemu_domain.h | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0da44f066..ec43d06d7 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9167,12 +9167,15 @@ qemuDomainSaveCookieDispose(void *obj) qemuDomainSaveCookiePtr cookie =3D obj; =20 VIR_DEBUG("cookie=3D%p", cookie); + + virCPUDefFree(cookie->cpu); } =20 =20 qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm ATTRIBUTE_UNUSED) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; qemuDomainSaveCookiePtr cookie =3D NULL; =20 if (qemuDomainInitialize() < 0) @@ -9181,7 +9184,10 @@ qemuDomainSaveCookieNew(virDomainObjPtr vm ATTRIBUTE= _UNUSED) if (!(cookie =3D virObjectNew(qemuDomainSaveCookieClass))) goto error; =20 - VIR_DEBUG("Save cookie %p", cookie); + if (priv->origCPU && !(cookie->cpu =3D virCPUDefCopy(vm->def->cpu))) + goto error; + + VIR_DEBUG("Save cookie %p, cpu=3D%p", cookie, cookie->cpu); =20 return cookie; =20 @@ -9203,6 +9209,10 @@ qemuDomainSaveCookieParse(xmlXPathContextPtr ctxt AT= TRIBUTE_UNUSED, if (!(cookie =3D virObjectNew(qemuDomainSaveCookieClass))) goto error; =20 + if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, + &cookie->cpu) < 0) + goto error; + *obj =3D (virObjectPtr) cookie; return 0; =20 @@ -9213,9 +9223,15 @@ qemuDomainSaveCookieParse(xmlXPathContextPtr ctxt AT= TRIBUTE_UNUSED, =20 =20 static int -qemuDomainSaveCookieFormat(virBufferPtr buf ATTRIBUTE_UNUSED, - virObjectPtr obj ATTRIBUTE_UNUSED) +qemuDomainSaveCookieFormat(virBufferPtr buf, + virObjectPtr obj) { + qemuDomainSaveCookiePtr cookie =3D (qemuDomainSaveCookiePtr) obj; + + if (cookie->cpu && + virCPUDefFormatBufFull(buf, cookie->cpu, NULL, false) < 0) + return -1; + return 0; } =20 diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 08c0b32f1..44c466cb7 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -424,6 +424,8 @@ typedef struct _qemuDomainSaveCookie qemuDomainSaveCook= ie; typedef qemuDomainSaveCookie *qemuDomainSaveCookiePtr; struct _qemuDomainSaveCookie { virObject parent; + + virCPUDefPtr cpu; }; =20 qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 04:54:44 2024 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.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; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496654855600514.6449806601786; Mon, 5 Jun 2017 02:27:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E23B3DBC0; Mon, 5 Jun 2017 09:27:33 +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 7770281975; Mon, 5 Jun 2017 09:27:33 +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 37AC44A490; Mon, 5 Jun 2017 09:27:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v559RBHR002024 for ; Mon, 5 Jun 2017 05:27:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id C7CAB83FE4; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: from virval.usersys.redhat.com (dhcp129-92.brq.redhat.com [10.34.129.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7682783FEF for ; Mon, 5 Jun 2017 09:27:11 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id BBAB210CD04; Mon, 5 Jun 2017 11:27:04 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9E23B3DBC0 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9E23B3DBC0 From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 5 Jun 2017 11:27:03 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 15/15] qemu: Use updated CPU when starting QEMU if possible 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 05 Jun 2017 09:27:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If QEMU is new enough and we have the live updated CPU definition in either save or migration cookie, we can use it to enforce ABI. The original guest CPU from domain XML will be stored in private data. Signed-off-by: Jiri Denemark --- src/qemu/qemu_domain.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 5 +++++ src/qemu/qemu_driver.c | 30 ++++++++++++++++++++++++------ src/qemu/qemu_migration.c | 2 +- src/qemu/qemu_process.c | 24 ++++++++++++++++++++++-- src/qemu/qemu_process.h | 2 ++ 6 files changed, 94 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ec43d06d7..2aa3aaa47 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9240,3 +9240,43 @@ virSaveCookieCallbacks virQEMUDriverDomainSaveCookie= =3D { .parse =3D qemuDomainSaveCookieParse, .format =3D qemuDomainSaveCookieFormat, }; + + +/** + * qemuDomainUpdateCPU: + * @vm: domain which is being started + * @cpu: CPU updated when the domain was running previously (before migrat= ion, + * snapshot, or save) + * @origCPU: where to store the original CPU from vm->def in case @cpu was + * used instead + * + * Replace the CPU definition with the updated one when QEMU is new enough= to + * allow us to check extra features it is about to enable or disable when + * starting a domain. The original CPU is stored in @origCPU. + * + * Returns 0 on success, -1 on error. + */ +int +qemuDomainUpdateCPU(virDomainObjPtr vm, + virCPUDefPtr cpu, + virCPUDefPtr *origCPU) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + + *origCPU =3D NULL; + + if (!cpu || !vm->def->cpu || + !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSIO= N) || + virCPUDefIsEqual(vm->def->cpu, cpu, false)) + return 0; + + if (!(cpu =3D virCPUDefCopy(cpu))) + return -1; + + VIR_DEBUG("Replacing CPU def with the updated one"); + + *origCPU =3D vm->def->cpu; + vm->def->cpu =3D cpu; + + return 0; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 44c466cb7..ef3a33076 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -919,4 +919,9 @@ char *qemuDomainDiskBackingStoreGetName(virDomainDiskDe= fPtr disk, virStorageSourcePtr qemuDomainGetStorageSourceByDevstr(const char *devstr, virDomainDefPtr def= ); =20 +int +qemuDomainUpdateCPU(virDomainObjPtr vm, + virCPUDefPtr cpu, + virCPUDefPtr *origCPU); + #endif /* __QEMU_DOMAIN_H__ */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 10b9b10bc..0f38f8d85 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1779,7 +1779,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr= conn, goto cleanup; } =20 - if (qemuProcessStart(conn, driver, vm, QEMU_ASYNC_JOB_START, + if (qemuProcessStart(conn, driver, vm, NULL, QEMU_ASYNC_JOB_START, NULL, -1, NULL, NULL, VIR_NETDEV_VPORT_PROFILE_OP_CREATE, start_flags) < 0) { @@ -6495,8 +6495,8 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, } } =20 - if (qemuProcessStart(conn, driver, vm, asyncJob, - "stdio", *fd, path, NULL, + if (qemuProcessStart(conn, driver, vm, cookie ? cookie->cpu : NULL, + asyncJob, "stdio", *fd, path, NULL, VIR_NETDEV_VPORT_PROFILE_OP_RESTORE, VIR_QEMU_PROCESS_START_PAUSED) =3D=3D 0) restored =3D true; @@ -7113,7 +7113,7 @@ qemuDomainObjStart(virConnectPtr conn, } } =20 - ret =3D qemuProcessStart(conn, driver, vm, asyncJob, + ret =3D qemuProcessStart(conn, driver, vm, NULL, asyncJob, NULL, -1, NULL, NULL, VIR_NETDEV_VPORT_PROFILE_OP_CREATE, start_flags= ); virDomainAuditStart(vm, "booted", ret >=3D 0); @@ -15283,6 +15283,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, virCapsPtr caps =3D NULL; bool was_running =3D false; bool was_stopped =3D false; + qemuDomainSaveCookiePtr cookie; + virCPUDefPtr origCPU =3D NULL; =20 virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED | @@ -15388,6 +15390,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, goto endjob; } =20 + cookie =3D (qemuDomainSaveCookiePtr) snap->def->cookie; + switch ((virDomainState) snap->def->state) { case VIR_DOMAIN_RUNNING: case VIR_DOMAIN_PAUSED: @@ -15399,6 +15403,15 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sn= apshot, * to have finer control. */ if (virDomainObjIsActive(vm)) { /* Transitions 5, 6, 8, 9 */ + /* Replace the CPU in config and put the original one in priv + * once we're done. + */ + if (cookie && cookie->cpu && config->cpu) { + origCPU =3D config->cpu; + if (!(config->cpu =3D virCPUDefCopy(cookie->cpu))) + goto endjob; + } + /* Check for ABI compatibility. We need to do this check again= st * the migratable XML or it will always fail otherwise */ if (config && @@ -15458,8 +15471,11 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sn= apshot, * failed loadvm attempt? */ goto endjob; } - if (config) + if (config) { virDomainObjAssignDef(vm, config, false, NULL); + virCPUDefFree(priv->origCPU); + VIR_STEAL_PTR(priv->origCPU, origCPU); + } } else { /* Transitions 2, 3 */ load: @@ -15468,6 +15484,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, virDomainObjAssignDef(vm, config, false, NULL); =20 rc =3D qemuProcessStart(snapshot->domain->conn, driver, vm, + cookie ? cookie->cpu : NULL, QEMU_ASYNC_JOB_START, NULL, -1, NULL, sn= ap, VIR_NETDEV_VPORT_PROFILE_OP_CREATE, VIR_QEMU_PROCESS_START_PAUSED); @@ -15561,7 +15578,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, start_flags |=3D paused ? VIR_QEMU_PROCESS_START_PAUSED : 0; =20 qemuDomainEventQueue(driver, event); - rc =3D qemuProcessStart(snapshot->domain->conn, driver, vm, + rc =3D qemuProcessStart(snapshot->domain->conn, driver, vm, NU= LL, QEMU_ASYNC_JOB_START, NULL, -1, NULL, NU= LL, VIR_NETDEV_VPORT_PROFILE_OP_CREATE, start_flags); @@ -15633,6 +15650,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, virObjectUnref(caps); virObjectUnref(cfg); virNWFilterUnlockFilterUpdates(); + virCPUDefFree(origCPU); =20 return ret; } diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 134c76c5e..505e61e5f 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2681,7 +2681,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, goto stopjob; } =20 - if (qemuProcessInit(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN, + if (qemuProcessInit(driver, vm, mig->cpu, QEMU_ASYNC_JOB_MIGRATION_IN, true, VIR_QEMU_PROCESS_START_AUTODESTROY) < 0) goto stopjob; stopProcess =3D true; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8f4902e10..842557bfd 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3944,6 +3944,13 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr drive= r, if (qemuProcessVerifyCPUFeatures(def, cpu) < 0) goto cleanup; =20 + /* Don't update the CPU if we already did so when starting a domain + * during migration, restore or snapshot revert. */ + if (priv->origCPU) { + ret =3D 0; + goto cleanup; + } + if (!(orig =3D virCPUDefCopy(def->cpu))) goto cleanup; =20 @@ -4862,6 +4869,7 @@ qemuProcessStartValidate(virQEMUDriverPtr driver, int qemuProcessInit(virQEMUDriverPtr driver, virDomainObjPtr vm, + virCPUDefPtr updatedCPU, qemuDomainAsyncJob asyncJob, bool migration, unsigned int flags) @@ -4870,6 +4878,7 @@ qemuProcessInit(virQEMUDriverPtr driver, virCapsPtr caps =3D NULL; qemuDomainObjPrivatePtr priv =3D vm->privateData; int stopFlags; + virCPUDefPtr origCPU =3D NULL; int ret =3D -1; =20 VIR_DEBUG("vm=3D%p name=3D%s id=3D%d migration=3D%d", @@ -4894,6 +4903,9 @@ qemuProcessInit(virQEMUDriverPtr driver, vm->def->os.machine)= )) goto cleanup; =20 + if (qemuDomainUpdateCPU(vm, updatedCPU, &origCPU) < 0) + goto cleanup; + if (qemuProcessStartValidate(driver, vm, priv->qemuCaps, caps, flags) = < 0) goto cleanup; =20 @@ -4926,11 +4938,14 @@ qemuProcessInit(virQEMUDriverPtr driver, =20 if (qemuDomainSetPrivatePaths(driver, vm) < 0) goto stop; + + VIR_STEAL_PTR(priv->origCPU, origCPU); } =20 ret =3D 0; =20 cleanup: + virCPUDefFree(origCPU); virObjectUnref(cfg); virObjectUnref(caps); return ret; @@ -5961,6 +5976,7 @@ int qemuProcessStart(virConnectPtr conn, virQEMUDriverPtr driver, virDomainObjPtr vm, + virCPUDefPtr updatedCPU, qemuDomainAsyncJob asyncJob, const char *migrateFrom, int migrateFd, @@ -5991,7 +6007,8 @@ qemuProcessStart(virConnectPtr conn, if (!migrateFrom && !snapshot) flags |=3D VIR_QEMU_PROCESS_START_NEW; =20 - if (qemuProcessInit(driver, vm, asyncJob, !!migrateFrom, flags) < 0) + if (qemuProcessInit(driver, vm, updatedCPU, + asyncJob, !!migrateFrom, flags) < 0) goto cleanup; =20 if (migrateFrom) { @@ -6070,7 +6087,8 @@ qemuProcessCreatePretendCmd(virConnectPtr conn, flags |=3D VIR_QEMU_PROCESS_START_PRETEND; flags |=3D VIR_QEMU_PROCESS_START_NEW; =20 - if (qemuProcessInit(driver, vm, QEMU_ASYNC_JOB_NONE, !!migrateURI, fla= gs) < 0) + if (qemuProcessInit(driver, vm, NULL, QEMU_ASYNC_JOB_NONE, + !!migrateURI, flags) < 0) goto cleanup; =20 if (qemuProcessPrepareDomain(conn, driver, vm, flags) < 0) @@ -6474,6 +6492,8 @@ void qemuProcessStop(virQEMUDriverPtr driver, =20 /* clean up migration data */ VIR_FREE(priv->migTLSAlias); + virCPUDefFree(priv->origCPU); + priv->origCPU =3D NULL; =20 /* clear previously used namespaces */ virBitmapFree(priv->namespaces); diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 830d8cef8..c38310b47 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -75,6 +75,7 @@ typedef enum { int qemuProcessStart(virConnectPtr conn, virQEMUDriverPtr driver, virDomainObjPtr vm, + virCPUDefPtr updatedCPU, qemuDomainAsyncJob asyncJob, const char *migrateFrom, int stdin_fd, @@ -93,6 +94,7 @@ virCommandPtr qemuProcessCreatePretendCmd(virConnectPtr c= onn, =20 int qemuProcessInit(virQEMUDriverPtr driver, virDomainObjPtr vm, + virCPUDefPtr updatedCPU, qemuDomainAsyncJob asyncJob, bool migration, unsigned int flags); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list