From nobody Sun Feb 8 01:30:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1594365134; cv=none; d=zohomail.com; s=zohoarc; b=Yd4hckMQPoVsL/ve/UojERUgOv2q7Oy7URMNpoCnIMq4RvSXxAvM1/EgFK8mXIyq63QQ+4hn3NYnh0ouYW3cr6pHADDBx2nqBuMCdGiqswOvyucbkg8iaxzAgsNVBzUDp5kdDul0bKve4ecIOJlHylKmTLgd/VO8jE/eK/rIPRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594365134; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=+pmiWcvaSb9Devu8x5lftKyk1LCix8d1Gfkc7Xn40IM=; b=SC0bf3BLJebHEH1lLEGxteEAccroFObyW5OwI7KAoeNXi850GBehL7bRksK82cBEy768eNjoOE9nFhpFJbhEg5sd1JOjN5GyXPo0JA+cuHShslFCitADVazmAoXrtGh5zkZrKgNVRlJC6ox9hLht3ueXD7sT0ZXb2HGIA4nGRDM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1594365134247633.8658056086068; Fri, 10 Jul 2020 00:12:14 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-176-Rv0YZVgRNxuSs4pX5AcBDw-1; Fri, 10 Jul 2020 03:12:10 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CEC76100CCC1; Fri, 10 Jul 2020 07:12:04 +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 AAA0E19D9E; Fri, 10 Jul 2020 07:12:04 +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 7C3BF72F79; Fri, 10 Jul 2020 07:12:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06A7BxdC010592 for ; Fri, 10 Jul 2020 03:11:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 487908A4DF; Fri, 10 Jul 2020 07:11:59 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 443248A4D4 for ; Fri, 10 Jul 2020 07:11:59 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 281C98007AC for ; Fri, 10 Jul 2020 07:11:59 +0000 (UTC) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-64-vqqeJPE0MCSP4gzsZjvKWw-1; Fri, 10 Jul 2020 03:11:55 -0400 Received: by mail-pl1-f176.google.com with SMTP id x11so1877343plo.7 for ; Fri, 10 Jul 2020 00:11:55 -0700 (PDT) Received: from localhost.localdomain ([116.72.86.98]) by smtp.gmail.com with ESMTPSA id y10sm4771990pfn.121.2020.07.10.00.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2020 00:11:53 -0700 (PDT) X-MC-Unique: Rv0YZVgRNxuSs4pX5AcBDw-1 X-MC-Unique: vqqeJPE0MCSP4gzsZjvKWw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+pmiWcvaSb9Devu8x5lftKyk1LCix8d1Gfkc7Xn40IM=; b=MNV5rYF6SFzqnu/QPu+vVKxaSPrmRS89ZXntLgM9pxH9l5imVpdeuMR2ql/AFXj+oJ nUlxdHbjO/utfWYUT8CkZot9xQoeNJdUbdFwe5eoZYbAfSeV1RFiYEXHUHe/0Bvg1sbp ZuoOnNrWqJczyvGBnQLfmSm8RXcJD7NmSAee875WNpZQnYiPp2vhXHuu9j3eSuh9qCsx YJrG2cb/8/fWGV7B6WcJMb3Pqo26H5kuomxgM5Napf5xzMboVnIyKurfl6Xam86MEN1o 6xtMpBTH5XpG76kghKOh9TwFBrMqwEnEL+RXsk+t2h2jFc1a3sY9Y8yV+4ouFFSKkSNZ uEAg== X-Gm-Message-State: AOAM532HrXJmazeAivFJQSbnk0gE7+CGKbT9ZR5sHxlkXxcux8T8lF4C +UZukImO37UlH0RMtEh2zVqo0F1M X-Google-Smtp-Source: ABdhPJwT+RNWqO2B+DN4YGzrivpczb6XyzJ8ae1FaZSIfBboxBCJypX88DcN55ib/GmcgUBG1YiVBA== X-Received: by 2002:a17:902:7c0a:: with SMTP id x10mr34801131pll.76.1594365114082; Fri, 10 Jul 2020 00:11:54 -0700 (PDT) From: Prathamesh Chavan To: libvir-list@redhat.com Subject: [PATCH 2/4] qemu_domainjob: job funcitons moved out of `qemu_domain` Date: Fri, 10 Jul 2020 12:41:38 +0530 Message-Id: <20200710071140.4836-3-pc44800@gmail.com> In-Reply-To: <20200710071140.4836-1-pc44800@gmail.com> References: <20200710071140.4836-1-pc44800@gmail.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Prathamesh Chavan X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We move functions `qemuDomainObjPrivateXMLParseJob` and `qemuDomainObjPrivateXMLFormatJob` to `qemu_domainjob`. To make this happen, corresponding changes in their parameters were made, as well as they were exposed to be used in `qemu_domain` file. Signed-off-by: Prathamesh Chavan --- src/qemu/qemu_domain.c | 245 +------------------------------------- src/qemu/qemu_domainjob.c | 244 +++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domainjob.h | 8 ++ 3 files changed, 254 insertions(+), 243 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 2d9d8226d6..10d2033db1 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2168,102 +2168,6 @@ qemuDomainObjPrivateXMLFormatPR(virBufferPtr buf, } =20 =20 -static int -qemuDomainObjPrivateXMLFormatNBDMigrationSource(virBufferPtr buf, - virStorageSourcePtr src, - virDomainXMLOptionPtr xmlo= pt) -{ - g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); - - virBufferAsprintf(&attrBuf, " type=3D'%s' format=3D'%s'", - virStorageTypeToString(src->type), - virStorageFileFormatTypeToString(src->format)); - - if (virDomainDiskSourceFormat(&childBuf, src, "source", 0, false, - VIR_DOMAIN_DEF_FORMAT_STATUS, - false, false, xmlopt) < 0) - return -1; - - virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf); - - return 0; -} - - -static int -qemuDomainObjPrivateXMLFormatNBDMigration(virBufferPtr buf, - virDomainObjPtr vm) -{ - qemuDomainObjPrivatePtr priv =3D vm->privateData; - size_t i; - virDomainDiskDefPtr disk; - qemuDomainDiskPrivatePtr diskPriv; - - for (i =3D 0; i < vm->def->ndisks; i++) { - g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); - disk =3D vm->def->disks[i]; - diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); - - virBufferAsprintf(&attrBuf, " dev=3D'%s' migrating=3D'%s'", - disk->dst, diskPriv->migrating ? "yes" : "no"); - - if (diskPriv->migrSource && - qemuDomainObjPrivateXMLFormatNBDMigrationSource(&childBuf, - diskPriv->migr= Source, - priv->driver->= xmlopt) < 0) - return -1; - - virXMLFormatElement(buf, "disk", &attrBuf, &childBuf); - } - - return 0; -} - - -static int -qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf, - virDomainObjPtr vm, - qemuDomainObjPrivatePtr priv) -{ - g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); - qemuDomainJob job =3D priv->job.active; - - if (!qemuDomainTrackJob(job)) - job =3D QEMU_JOB_NONE; - - if (job =3D=3D QEMU_JOB_NONE && - priv->job.asyncJob =3D=3D QEMU_ASYNC_JOB_NONE) - return 0; - - virBufferAsprintf(&attrBuf, " type=3D'%s' async=3D'%s'", - qemuDomainJobTypeToString(job), - qemuDomainAsyncJobTypeToString(priv->job.asyncJob)); - - if (priv->job.phase) { - virBufferAsprintf(&attrBuf, " phase=3D'%s'", - qemuDomainAsyncJobPhaseToString(priv->job.asyncJ= ob, - priv->job.phase)= ); - } - - if (priv->job.asyncJob !=3D QEMU_ASYNC_JOB_NONE) - virBufferAsprintf(&attrBuf, " flags=3D'0x%lx'", priv->job.apiFlags= ); - - if (priv->job.asyncJob =3D=3D QEMU_ASYNC_JOB_MIGRATION_OUT && - qemuDomainObjPrivateXMLFormatNBDMigration(&childBuf, vm) < 0) - return -1; - - if (priv->job.migParams) - qemuMigrationParamsFormat(&childBuf, priv->job.migParams); - - virXMLFormatElement(buf, "job", &attrBuf, &childBuf); - - return 0; -} - - static bool qemuDomainHasSlirp(virDomainObjPtr vm) { @@ -2399,7 +2303,7 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, if (priv->lockState) virBufferAsprintf(buf, "%s\n", priv->lockSt= ate); =20 - if (qemuDomainObjPrivateXMLFormatJob(buf, vm, priv) < 0) + if (qemuDomainObjPrivateXMLFormatJob(buf, vm) < 0) return -1; =20 if (priv->fakeReboot) @@ -2899,151 +2803,6 @@ qemuDomainObjPrivateXMLParsePR(xmlXPathContextPtr c= txt, } =20 =20 -static int -qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node, - xmlXPathContextPtr ctxt, - virDomainDiskDefPtr disk, - virDomainXMLOptionPtr xmlopt) -{ - VIR_XPATH_NODE_AUTORESTORE(ctxt); - qemuDomainDiskPrivatePtr diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); - g_autofree char *format =3D NULL; - g_autofree char *type =3D NULL; - g_autoptr(virStorageSource) migrSource =3D NULL; - xmlNodePtr sourceNode; - - ctxt->node =3D node; - - if (!(ctxt->node =3D virXPathNode("./migrationSource", ctxt))) - return 0; - - if (!(type =3D virXMLPropString(ctxt->node, "type"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing storage source type")); - return -1; - } - - if (!(format =3D virXMLPropString(ctxt->node, "format"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing storage source format")); - return -1; - } - - if (!(migrSource =3D virDomainStorageSourceParseBase(type, format, NUL= L))) - return -1; - - /* newer libvirt uses the subelement instead of formatting the - * source directly into */ - if ((sourceNode =3D virXPathNode("./source", ctxt))) - ctxt->node =3D sourceNode; - - if (virDomainStorageSourceParse(ctxt->node, ctxt, migrSource, - VIR_DOMAIN_DEF_PARSE_STATUS, xmlopt) <= 0) - return -1; - - diskPriv->migrSource =3D g_steal_pointer(&migrSource); - return 0; -} - - -static int -qemuDomainObjPrivateXMLParseJobNBD(virDomainObjPtr vm, - qemuDomainObjPrivatePtr priv, - xmlXPathContextPtr ctxt) -{ - g_autofree xmlNodePtr *nodes =3D NULL; - size_t i; - int n; - - if ((n =3D virXPathNodeSet("./disk[@migrating=3D'yes']", ctxt, &nodes)= ) < 0) - return -1; - - if (n > 0) { - if (priv->job.asyncJob !=3D QEMU_ASYNC_JOB_MIGRATION_OUT) { - VIR_WARN("Found disks marked for migration but we were not " - "migrating"); - n =3D 0; - } - for (i =3D 0; i < n; i++) { - virDomainDiskDefPtr disk; - g_autofree char *dst =3D NULL; - - if ((dst =3D virXMLPropString(nodes[i], "dev")) && - (disk =3D virDomainDiskByTarget(vm->def, dst))) { - QEMU_DOMAIN_DISK_PRIVATE(disk)->migrating =3D true; - - if (qemuDomainObjPrivateXMLParseJobNBDSource(nodes[i], ctx= t, - disk, - priv->driver-= >xmlopt) < 0) - return -1; - } - } - } - - return 0; -} - - -static int -qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm, - qemuDomainObjPrivatePtr priv, - xmlXPathContextPtr ctxt) -{ - VIR_XPATH_NODE_AUTORESTORE(ctxt); - g_autofree char *tmp =3D NULL; - - if (!(ctxt->node =3D virXPathNode("./job[1]", ctxt))) - return 0; - - if ((tmp =3D virXPathString("string(@type)", ctxt))) { - int type; - - if ((type =3D qemuDomainJobTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown job type %s"), tmp); - return -1; - } - VIR_FREE(tmp); - priv->job.active =3D type; - } - - if ((tmp =3D virXPathString("string(@async)", ctxt))) { - int async; - - if ((async =3D qemuDomainAsyncJobTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown async job type %s"), tmp); - return -1; - } - VIR_FREE(tmp); - priv->job.asyncJob =3D async; - - if ((tmp =3D virXPathString("string(@phase)", ctxt))) { - priv->job.phase =3D qemuDomainAsyncJobPhaseFromString(async, t= mp); - if (priv->job.phase < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown job phase %s"), tmp); - return -1; - } - VIR_FREE(tmp); - } - } - - if (virXPathULongHex("string(@flags)", ctxt, &priv->job.apiFlags) =3D= =3D -2) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid job flags"= )); - return -1; - } - - if (qemuDomainObjPrivateXMLParseJobNBD(vm, priv, ctxt) < 0) - return -1; - - if (qemuMigrationParamsParse(ctxt, &priv->job.migParams) < 0) - return -1; - - return 0; -} - - static int qemuDomainObjPrivateXMLParseSlirpFeatures(xmlNodePtr featuresNode, xmlXPathContextPtr ctxt, @@ -3203,7 +2962,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, =20 priv->lockState =3D virXPathString("string(./lockstate)", ctxt); =20 - if (qemuDomainObjPrivateXMLParseJob(vm, priv, ctxt) < 0) + if (qemuDomainObjPrivateXMLParseJob(vm, ctxt) < 0) goto error; =20 priv->fakeReboot =3D virXPathBoolean("boolean(./fakereboot)", ctxt) = =3D=3D 1; diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c index 654f1c4f90..454a5a2c23 100644 --- a/src/qemu/qemu_domainjob.c +++ b/src/qemu/qemu_domainjob.c @@ -1184,3 +1184,247 @@ qemuDomainObjAbortAsyncJob(virDomainObjPtr obj) priv->job.abortJob =3D true; virDomainObjBroadcast(obj); } + + +static int +qemuDomainObjPrivateXMLFormatNBDMigrationSource(virBufferPtr buf, + virStorageSourcePtr src, + virDomainXMLOptionPtr xmlo= pt) +{ + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + + virBufferAsprintf(&attrBuf, " type=3D'%s' format=3D'%s'", + virStorageTypeToString(src->type), + virStorageFileFormatTypeToString(src->format)); + + if (virDomainDiskSourceFormat(&childBuf, src, "source", 0, false, + VIR_DOMAIN_DEF_FORMAT_STATUS, + false, false, xmlopt) < 0) + return -1; + + virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf); + + return 0; +} + + +static int +qemuDomainObjPrivateXMLFormatNBDMigration(virBufferPtr buf, + virDomainObjPtr vm) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + size_t i; + virDomainDiskDefPtr disk; + qemuDomainDiskPrivatePtr diskPriv; + + for (i =3D 0; i < vm->def->ndisks; i++) { + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + disk =3D vm->def->disks[i]; + diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); + + virBufferAsprintf(&attrBuf, " dev=3D'%s' migrating=3D'%s'", + disk->dst, diskPriv->migrating ? "yes" : "no"); + + if (diskPriv->migrSource && + qemuDomainObjPrivateXMLFormatNBDMigrationSource(&childBuf, + diskPriv->migr= Source, + priv->driver->= xmlopt) < 0) + return -1; + + virXMLFormatElement(buf, "disk", &attrBuf, &childBuf); + } + + return 0; +} + + +int +qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf, + virDomainObjPtr vm) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + qemuDomainJobObjPtr jobObj =3D &priv->job; + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + qemuDomainJob job =3D jobObj->active; + + if (!qemuDomainTrackJob(job)) + job =3D QEMU_JOB_NONE; + + if (job =3D=3D QEMU_JOB_NONE && + jobObj->asyncJob =3D=3D QEMU_ASYNC_JOB_NONE) + return 0; + + virBufferAsprintf(&attrBuf, " type=3D'%s' async=3D'%s'", + qemuDomainJobTypeToString(job), + qemuDomainAsyncJobTypeToString(jobObj->asyncJob)); + + if (jobObj->phase) { + virBufferAsprintf(&attrBuf, " phase=3D'%s'", + qemuDomainAsyncJobPhaseToString(jobObj->asyncJob, + jobObj->phase)); + } + + if (jobObj->asyncJob !=3D QEMU_ASYNC_JOB_NONE) + virBufferAsprintf(&attrBuf, " flags=3D'0x%lx'", jobObj->apiFlags); + + if (jobObj->asyncJob =3D=3D QEMU_ASYNC_JOB_MIGRATION_OUT && + qemuDomainObjPrivateXMLFormatNBDMigration(&childBuf, vm) < 0) + return -1; + + if (jobObj->migParams) + qemuMigrationParamsFormat(&childBuf, jobObj->migParams); + + virXMLFormatElement(buf, "job", &attrBuf, &childBuf); + + return 0; +} + + +static int +qemuDomainObjPrivateXMLParseJobNBDSource(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virDomainDiskDefPtr disk, + virDomainXMLOptionPtr xmlopt) +{ + VIR_XPATH_NODE_AUTORESTORE(ctxt); + qemuDomainDiskPrivatePtr diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); + g_autofree char *format =3D NULL; + g_autofree char *type =3D NULL; + g_autoptr(virStorageSource) migrSource =3D NULL; + xmlNodePtr sourceNode; + + ctxt->node =3D node; + + if (!(ctxt->node =3D virXPathNode("./migrationSource", ctxt))) + return 0; + + if (!(type =3D virXMLPropString(ctxt->node, "type"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing storage source type")); + return -1; + } + + if (!(format =3D virXMLPropString(ctxt->node, "format"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing storage source format")); + return -1; + } + + if (!(migrSource =3D virDomainStorageSourceParseBase(type, format, NUL= L))) + return -1; + + /* newer libvirt uses the subelement instead of formatting the + * source directly into */ + if ((sourceNode =3D virXPathNode("./source", ctxt))) + ctxt->node =3D sourceNode; + + if (virDomainStorageSourceParse(ctxt->node, ctxt, migrSource, + VIR_DOMAIN_DEF_PARSE_STATUS, xmlopt) <= 0) + return -1; + + diskPriv->migrSource =3D g_steal_pointer(&migrSource); + return 0; +} + + +static int +qemuDomainObjPrivateXMLParseJobNBD(virDomainObjPtr vm, + xmlXPathContextPtr ctxt) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + qemuDomainJobObjPtr job =3D &priv->job; + virDomainXMLOptionPtr xmlopt =3D priv->driver->xmlopt; + g_autofree xmlNodePtr *nodes =3D NULL; + size_t i; + int n; + + if ((n =3D virXPathNodeSet("./disk[@migrating=3D'yes']", ctxt, &nodes)= ) < 0) + return -1; + + if (n > 0) { + if (job->asyncJob !=3D QEMU_ASYNC_JOB_MIGRATION_OUT) { + VIR_WARN("Found disks marked for migration but we were not " + "migrating"); + n =3D 0; + } + for (i =3D 0; i < n; i++) { + virDomainDiskDefPtr disk; + g_autofree char *dst =3D NULL; + + if ((dst =3D virXMLPropString(nodes[i], "dev")) && + (disk =3D virDomainDiskByTarget(vm->def, dst))) { + QEMU_DOMAIN_DISK_PRIVATE(disk)->migrating =3D true; + + if (qemuDomainObjPrivateXMLParseJobNBDSource(nodes[i], ctx= t, + disk, + xmlopt) < 0) + return -1; + } + } + } + + return 0; +} + +int +qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm, + xmlXPathContextPtr ctxt) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + qemuDomainJobObjPtr job =3D &priv->job; + VIR_XPATH_NODE_AUTORESTORE(ctxt); + g_autofree char *tmp =3D NULL; + + if (!(ctxt->node =3D virXPathNode("./job[1]", ctxt))) + return 0; + + if ((tmp =3D virXPathString("string(@type)", ctxt))) { + int type; + + if ((type =3D qemuDomainJobTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown job type %s"), tmp); + return -1; + } + VIR_FREE(tmp); + job->active =3D type; + } + + if ((tmp =3D virXPathString("string(@async)", ctxt))) { + int async; + + if ((async =3D qemuDomainAsyncJobTypeFromString(tmp)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown async job type %s"), tmp); + return -1; + } + VIR_FREE(tmp); + job->asyncJob =3D async; + + if ((tmp =3D virXPathString("string(@phase)", ctxt))) { + job->phase =3D qemuDomainAsyncJobPhaseFromString(async, tmp); + if (job->phase < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown job phase %s"), tmp); + return -1; + } + VIR_FREE(tmp); + } + } + + if (virXPathULongHex("string(@flags)", ctxt, &job->apiFlags) =3D=3D -2= ) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid job flags"= )); + return -1; + } + + if (qemuDomainObjPrivateXMLParseJobNBD(vm, ctxt) < 0) + return -1; + + if (qemuMigrationParamsParse(ctxt, &job->migParams) < 0) + return -1; + + return 0; +} diff --git a/src/qemu/qemu_domainjob.h b/src/qemu/qemu_domainjob.h index 124664354d..9d2ee14584 100644 --- a/src/qemu/qemu_domainjob.h +++ b/src/qemu/qemu_domainjob.h @@ -267,3 +267,11 @@ void qemuDomainObjFreeJob(qemuDomainJobObjPtr job); int qemuDomainObjInitJob(qemuDomainJobObjPtr job); =20 bool qemuDomainJobAllowed(qemuDomainJobObjPtr jobs, qemuDomainJob newJob); + +int +qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf, + virDomainObjPtr vm); + +int +qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm, + xmlXPathContextPtr ctxt); --=20 2.17.1