2015-04-16 09:24:19 +00:00
|
|
|
/*
|
|
|
|
* qemu_blockjob.c: helper functions for QEMU block jobs
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2015 Red Hat, Inc.
|
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
#include "qemu_blockjob.h"
|
2017-03-15 12:03:21 +00:00
|
|
|
#include "qemu_block.h"
|
2015-04-16 09:24:19 +00:00
|
|
|
#include "qemu_domain.h"
|
|
|
|
|
|
|
|
#include "conf/domain_conf.h"
|
|
|
|
#include "conf/domain_event.h"
|
|
|
|
|
|
|
|
#include "virlog.h"
|
|
|
|
#include "virstoragefile.h"
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
#include "virthread.h"
|
|
|
|
#include "virtime.h"
|
2016-12-16 15:06:57 +00:00
|
|
|
#include "locking/domain_lock.h"
|
2017-10-27 12:37:22 +00:00
|
|
|
#include "viralloc.h"
|
2015-04-16 09:24:19 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
|
|
|
|
|
VIR_LOG_INIT("qemu.qemu_blockjob");
|
|
|
|
|
2015-05-11 12:50:48 +00:00
|
|
|
|
2018-11-14 15:47:50 +00:00
|
|
|
static virClassPtr qemuBlockJobDataClass;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
qemuBlockJobDataDispose(void *obj)
|
2018-10-17 06:57:08 +00:00
|
|
|
{
|
2018-11-14 15:47:50 +00:00
|
|
|
qemuBlockJobDataPtr job = obj;
|
2018-10-17 06:57:08 +00:00
|
|
|
|
|
|
|
VIR_FREE(job->errmsg);
|
2018-11-14 15:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuBlockJobDataOnceInit(void)
|
|
|
|
{
|
|
|
|
if (!VIR_CLASS_NEW(qemuBlockJobData, virClassForObject()))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VIR_ONCE_GLOBAL_INIT(qemuBlockJobData)
|
|
|
|
|
|
|
|
qemuBlockJobDataPtr
|
|
|
|
qemuBlockJobDataNew(void)
|
|
|
|
{
|
|
|
|
if (qemuBlockJobDataInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return virObjectNew(qemuBlockJobDataClass);
|
2018-10-17 06:57:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-19 15:48:09 +00:00
|
|
|
static void
|
|
|
|
qemuBlockJobDataReset(qemuBlockJobDataPtr job)
|
|
|
|
{
|
|
|
|
job->started = false;
|
|
|
|
job->type = -1;
|
|
|
|
job->newstate = -1;
|
|
|
|
VIR_FREE(job->errmsg);
|
|
|
|
job->synchronous = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* qemuBlockJobDiskNew:
|
|
|
|
* @disk: disk definition
|
|
|
|
*
|
|
|
|
* Start/associate a new blockjob with @disk.
|
|
|
|
*
|
|
|
|
* Returns 0 on success and -1 on failure.
|
|
|
|
*/
|
|
|
|
qemuBlockJobDataPtr
|
2018-11-23 11:45:32 +00:00
|
|
|
qemuBlockJobDiskNew(virDomainDiskDefPtr disk,
|
|
|
|
qemuBlockJobType type)
|
2018-11-19 15:48:09 +00:00
|
|
|
{
|
|
|
|
qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob;
|
2018-11-21 14:36:47 +00:00
|
|
|
job->disk = disk;
|
2018-11-19 15:48:09 +00:00
|
|
|
|
|
|
|
qemuBlockJobDataReset(job);
|
2018-11-23 11:45:32 +00:00
|
|
|
|
|
|
|
job->type = type;
|
|
|
|
|
2018-11-19 15:48:09 +00:00
|
|
|
return virObjectRef(job);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* qemuBlockJobDiskGetJob:
|
|
|
|
* @disk: disk definition
|
|
|
|
*
|
|
|
|
* Get a reference to the block job data object associated with @disk.
|
|
|
|
*/
|
|
|
|
qemuBlockJobDataPtr
|
|
|
|
qemuBlockJobDiskGetJob(virDomainDiskDefPtr disk)
|
|
|
|
{
|
|
|
|
qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob;
|
|
|
|
|
|
|
|
if (!job)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return virObjectRef(job);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* qemuBlockJobStarted:
|
|
|
|
* @job: job data
|
|
|
|
*
|
|
|
|
* Mark @job as started in qemu.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
qemuBlockJobStarted(qemuBlockJobDataPtr job)
|
|
|
|
{
|
|
|
|
job->started = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* qemuBlockJobStartupFinalize:
|
|
|
|
* @job: job being started
|
|
|
|
*
|
|
|
|
* Cancels and clears the job private data if the job was not started with
|
|
|
|
* qemu (see qemuBlockJobStarted) or just clears up the local reference
|
|
|
|
* to @job if it was started.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
qemuBlockJobStartupFinalize(qemuBlockJobDataPtr job)
|
|
|
|
{
|
|
|
|
if (!job)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!job->started)
|
|
|
|
qemuBlockJobDataReset(job);
|
|
|
|
|
|
|
|
virObjectUnref(job);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-12 15:13:16 +00:00
|
|
|
/**
|
|
|
|
* qemuBlockJobEmitEvents:
|
|
|
|
*
|
|
|
|
* Emits the VIR_DOMAIN_EVENT_ID_BLOCK_JOB and VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2
|
2019-01-17 12:52:09 +00:00
|
|
|
* for a block job. The former event is emitted only for local disks.
|
2018-09-12 15:13:16 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
qemuBlockJobEmitEvents(virQEMUDriverPtr driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
virDomainDiskDefPtr disk,
|
|
|
|
virDomainBlockJobType type,
|
|
|
|
virConnectDomainEventBlockJobStatus status)
|
|
|
|
{
|
|
|
|
virObjectEventPtr event = NULL;
|
|
|
|
virObjectEventPtr event2 = NULL;
|
|
|
|
|
2019-01-17 12:52:09 +00:00
|
|
|
if (virStorageSourceIsLocalStorage(disk->src) &&
|
|
|
|
!virStorageSourceIsEmpty(disk->src)) {
|
|
|
|
event = virDomainEventBlockJobNewFromObj(vm, virDomainDiskGetSource(disk),
|
|
|
|
type, status);
|
|
|
|
virObjectEventStateQueue(driver->domainEventState, event);
|
|
|
|
}
|
2018-09-12 15:13:16 +00:00
|
|
|
|
|
|
|
event2 = virDomainEventBlockJob2NewFromObj(vm, disk->dst, type, status);
|
|
|
|
virObjectEventStateQueue(driver->domainEventState, event2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-17 12:51:56 +00:00
|
|
|
static void
|
|
|
|
qemuBlockJobEventProcessLegacyCompleted(virQEMUDriverPtr driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
virDomainDiskDefPtr disk,
|
|
|
|
int asyncJob)
|
|
|
|
{
|
|
|
|
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
|
|
|
virDomainDiskDefPtr persistDisk = NULL;
|
|
|
|
|
|
|
|
if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) {
|
|
|
|
if (vm->newDef) {
|
|
|
|
virStorageSourcePtr copy = NULL;
|
|
|
|
|
|
|
|
if ((persistDisk = virDomainDiskByName(vm->newDef,
|
|
|
|
disk->dst, false))) {
|
|
|
|
copy = virStorageSourceCopy(disk->mirror, false);
|
|
|
|
if (!copy ||
|
|
|
|
virStorageSourceInitChainElement(copy,
|
|
|
|
persistDisk->src,
|
|
|
|
true) < 0) {
|
|
|
|
VIR_WARN("Unable to update persistent definition "
|
|
|
|
"on vm %s after block job",
|
|
|
|
vm->def->name);
|
|
|
|
virStorageSourceFree(copy);
|
|
|
|
copy = NULL;
|
|
|
|
persistDisk = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (copy) {
|
|
|
|
virStorageSourceFree(persistDisk->src);
|
|
|
|
persistDisk->src = copy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX We want to revoke security labels as well as audit that
|
|
|
|
* revocation, before dropping the original source. But it gets
|
|
|
|
* tricky if both source and mirror share common backing files (we
|
|
|
|
* want to only revoke the non-shared portion of the chain); so for
|
|
|
|
* now, we leak the access to the original. */
|
|
|
|
virDomainLockImageDetach(driver->lockManager, vm, disk->src);
|
|
|
|
virStorageSourceFree(disk->src);
|
|
|
|
disk->src = disk->mirror;
|
|
|
|
} else {
|
|
|
|
if (disk->mirror) {
|
|
|
|
virDomainLockImageDetach(driver->lockManager, vm, disk->mirror);
|
|
|
|
virStorageSourceFree(disk->mirror);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recompute the cached backing chain to match our
|
|
|
|
* updates. Better would be storing the chain ourselves
|
|
|
|
* rather than reprobing, but we haven't quite completed
|
|
|
|
* that conversion to use our XML tracking. */
|
|
|
|
disk->mirror = NULL;
|
|
|
|
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
|
|
|
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
|
|
|
disk->src->id = 0;
|
|
|
|
virStorageSourceBackingStoreClear(disk->src);
|
|
|
|
ignore_value(qemuDomainDetermineDiskChain(driver, vm, disk, true));
|
|
|
|
ignore_value(qemuBlockNodeNamesDetect(driver, vm, asyncJob));
|
|
|
|
diskPriv->blockjob->started = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-16 09:24:19 +00:00
|
|
|
/**
|
2018-10-17 12:43:01 +00:00
|
|
|
* qemuBlockJobEventProcessLegacy:
|
2015-04-16 09:24:19 +00:00
|
|
|
* @driver: qemu driver
|
|
|
|
* @vm: domain
|
|
|
|
* @disk: domain disk
|
|
|
|
* @type: block job type
|
|
|
|
* @status: block job status
|
|
|
|
*
|
|
|
|
* Update disk's mirror state in response to a block job event
|
|
|
|
* from QEMU. For mirror state's that must survive libvirt
|
|
|
|
* restart, also update the domain's status XML.
|
|
|
|
*/
|
2018-10-16 09:54:02 +00:00
|
|
|
static void
|
2018-10-17 12:43:01 +00:00
|
|
|
qemuBlockJobEventProcessLegacy(virQEMUDriverPtr driver,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
virDomainDiskDefPtr disk,
|
|
|
|
int asyncJob,
|
|
|
|
int type,
|
|
|
|
int status)
|
2015-04-16 09:24:19 +00:00
|
|
|
{
|
|
|
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
2015-05-13 09:20:36 +00:00
|
|
|
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
2015-04-16 09:24:19 +00:00
|
|
|
|
2015-05-11 12:50:48 +00:00
|
|
|
VIR_DEBUG("disk=%s, mirrorState=%s, type=%d, status=%d",
|
|
|
|
disk->dst,
|
|
|
|
NULLSTR(virDomainDiskMirrorStateTypeToString(disk->mirrorState)),
|
|
|
|
type,
|
|
|
|
status);
|
|
|
|
|
2018-09-12 15:13:16 +00:00
|
|
|
qemuBlockJobEmitEvents(driver, vm, disk, type, status);
|
2015-04-16 09:24:19 +00:00
|
|
|
|
|
|
|
/* If we completed a block pull or commit, then update the XML
|
|
|
|
* to match. */
|
|
|
|
switch ((virConnectDomainEventBlockJobStatus) status) {
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
|
2018-10-17 12:51:56 +00:00
|
|
|
qemuBlockJobEventProcessLegacyCompleted(driver, vm, disk, asyncJob);
|
2015-04-16 09:24:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_READY:
|
|
|
|
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_READY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_FAILED:
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_CANCELED:
|
2016-12-16 15:06:57 +00:00
|
|
|
if (disk->mirror) {
|
|
|
|
virDomainLockImageDetach(driver->lockManager, vm, disk->mirror);
|
|
|
|
virStorageSourceFree(disk->mirror);
|
|
|
|
disk->mirror = NULL;
|
|
|
|
}
|
2015-05-19 06:44:16 +00:00
|
|
|
disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
|
2015-04-16 09:24:19 +00:00
|
|
|
disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
2018-10-17 06:57:08 +00:00
|
|
|
diskPriv->blockjob->started = false;
|
2015-04-16 09:24:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-28 13:21:06 +00:00
|
|
|
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
|
|
|
|
VIR_WARN("Unable to save status on vm %s after block job", vm->def->name);
|
|
|
|
|
2017-08-28 13:36:05 +00:00
|
|
|
if (status == VIR_DOMAIN_BLOCK_JOB_COMPLETED && vm->newDef) {
|
|
|
|
if (virDomainSaveConfig(cfg->configDir, driver->caps, vm->newDef) < 0)
|
|
|
|
VIR_WARN("Unable to update persistent definition on vm %s "
|
|
|
|
"after block job", vm->def->name);
|
|
|
|
}
|
2015-04-16 09:24:19 +00:00
|
|
|
|
|
|
|
virObjectUnref(cfg);
|
|
|
|
}
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
|
|
|
|
|
2018-10-16 09:54:02 +00:00
|
|
|
/**
|
2018-10-16 14:36:18 +00:00
|
|
|
* qemuBlockJobUpdateDisk:
|
2018-10-16 09:54:02 +00:00
|
|
|
* @vm: domain
|
|
|
|
* @disk: domain disk
|
|
|
|
* @error: error (output parameter)
|
|
|
|
*
|
|
|
|
* Update disk's mirror state in response to a block job event stored in
|
|
|
|
* blockJobStatus by qemuProcessHandleBlockJob event handler.
|
|
|
|
*
|
|
|
|
* Returns the block job event processed or -1 if there was no pending event.
|
|
|
|
*/
|
|
|
|
int
|
2018-10-16 14:36:18 +00:00
|
|
|
qemuBlockJobUpdateDisk(virDomainObjPtr vm,
|
2018-10-16 14:43:49 +00:00
|
|
|
int asyncJob,
|
2018-10-16 14:36:18 +00:00
|
|
|
virDomainDiskDefPtr disk,
|
|
|
|
char **error)
|
2018-10-16 09:54:02 +00:00
|
|
|
{
|
2018-10-17 06:57:08 +00:00
|
|
|
qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob;
|
2018-10-16 09:54:02 +00:00
|
|
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
2018-11-22 14:05:50 +00:00
|
|
|
int state = job->newstate;
|
2018-10-16 09:54:02 +00:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
*error = NULL;
|
|
|
|
|
2018-11-22 14:05:50 +00:00
|
|
|
if (state != -1) {
|
2018-10-17 12:43:01 +00:00
|
|
|
qemuBlockJobEventProcessLegacy(priv->driver, vm, disk, asyncJob,
|
2018-11-22 14:05:50 +00:00
|
|
|
job->type, state);
|
|
|
|
job->newstate = -1;
|
2018-10-16 09:54:02 +00:00
|
|
|
if (error)
|
2018-10-17 06:57:08 +00:00
|
|
|
VIR_STEAL_PTR(*error, job->errmsg);
|
2018-10-16 09:54:02 +00:00
|
|
|
else
|
2018-10-17 06:57:08 +00:00
|
|
|
VIR_FREE(job->errmsg);
|
2018-10-16 09:54:02 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 14:05:50 +00:00
|
|
|
return state;
|
2018-10-16 09:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
/**
|
2018-10-16 14:36:18 +00:00
|
|
|
* qemuBlockJobSyncBeginDisk:
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
* @disk: domain disk
|
|
|
|
*
|
|
|
|
* Begin a new synchronous block job for @disk. The synchronous
|
2018-10-16 14:36:18 +00:00
|
|
|
* block job is ended by a call to qemuBlockJobSyncEndDisk, or by
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
* the guest quitting.
|
|
|
|
*
|
|
|
|
* During a synchronous block job, a block job event for @disk
|
|
|
|
* will not be processed asynchronously. Instead, it will be
|
2018-10-16 14:36:18 +00:00
|
|
|
* processed only when qemuBlockJobUpdateDisk or qemuBlockJobSyncEndDisk
|
2015-05-14 12:28:12 +00:00
|
|
|
* is called.
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
*/
|
|
|
|
void
|
2018-10-16 14:36:18 +00:00
|
|
|
qemuBlockJobSyncBeginDisk(virDomainDiskDefPtr disk)
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
{
|
2018-10-17 06:57:08 +00:00
|
|
|
qemuBlockJobDataPtr job = QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob;
|
2015-05-13 09:20:36 +00:00
|
|
|
|
2015-05-14 12:28:12 +00:00
|
|
|
VIR_DEBUG("disk=%s", disk->dst);
|
2018-10-17 06:57:08 +00:00
|
|
|
job->synchronous = true;
|
2018-11-22 14:05:50 +00:00
|
|
|
job->newstate = -1;
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-10-16 14:36:18 +00:00
|
|
|
* qemuBlockJobSyncEndDisk:
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
* @vm: domain
|
|
|
|
* @disk: domain disk
|
|
|
|
*
|
|
|
|
* End a synchronous block job for @disk. Any pending block job event
|
2018-11-22 17:34:42 +00:00
|
|
|
* for the disk is processed. Note that it's not necessary to call this function
|
|
|
|
* in case the block job was not started successfully if
|
|
|
|
* qemuBlockJobStartupFinalize will be called.
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
*/
|
|
|
|
void
|
2018-10-16 14:36:18 +00:00
|
|
|
qemuBlockJobSyncEndDisk(virDomainObjPtr vm,
|
2018-10-16 14:43:49 +00:00
|
|
|
int asyncJob,
|
2018-10-16 14:36:18 +00:00
|
|
|
virDomainDiskDefPtr disk)
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
{
|
2015-05-14 12:28:12 +00:00
|
|
|
VIR_DEBUG("disk=%s", disk->dst);
|
2018-10-16 14:36:18 +00:00
|
|
|
qemuBlockJobUpdateDisk(vm, asyncJob, disk, NULL);
|
2018-10-17 06:57:08 +00:00
|
|
|
QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob->synchronous = false;
|
qemuBlockJobSync*: introduce sync block job helpers
qemuBlockJobSyncBegin and qemuBlockJobSyncEnd delimit a region of code
where block job events are processed "synchronously".
qemuBlockJobSyncWait and qemuBlockJobSyncWaitWithTimeout wait for an
event generated by a block job.
The Wait* functions may be called multiple times while the synchronous
block job is active. Any pending block job event will be processed by
only when Wait* or End is called. disk->blockJobStatus is reset by
these functions, so if it is needed a pointer to a
virConnectDomainEventBlockJobStatus variable should be passed as the
last argument. It is safe to pass NULL if you do not care about the
block job status.
All functions assume the VM object is locked. The Wait* functions will
unlock the object for as long as they are waiting. They will return -1
and report an error if the domain exits before an event is received.
Typical use is as follows:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
qemuBlockJobSyncBegin(disk);
... start block job ...
if (qemuBlockJobSyncWait(driver, vm, disk, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
... possibly start other block jobs
or wait for further events ...
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
To perform other tasks periodically while waiting for an event:
virQEMUDriverPtr driver;
virDomainObjPtr vm; /* locked */
virDomainDiskDefPtr disk;
virConnectDomainEventBlockJobStatus status;
unsigned long long timeout = 500 * 1000ull; /* milliseconds */
qemuBlockJobSyncBegin(disk);
... start block job ...
do {
... do other task ...
if (qemuBlockJobSyncWaitWithTimeout(driver, vm, disk,
timeout, &status) < 0) {
/* domain died while waiting for event */
ret = -1;
goto error;
}
} while (status == -1);
qemuBlockJobSyncEnd(driver, vm, disk, NULL);
Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2015-04-16 09:24:20 +00:00
|
|
|
}
|