This patch moves qemuDomainJobObj into hypervisor/ as generalized virDomainJobObj along with generalized private job callbacks as virDomainObjPrivateJobCallbacks. Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx> --- src/hypervisor/domain_job.h | 62 ++++++++++++++++++++++++++++++ src/qemu/qemu_domain.c | 6 +-- src/qemu/qemu_domain.h | 2 +- src/qemu/qemu_domainjob.c | 22 +++++------ src/qemu/qemu_domainjob.h | 66 +++----------------------------- src/qemu/qemu_migration.c | 2 +- src/qemu/qemu_migration.h | 2 +- src/qemu/qemu_migration_params.c | 2 +- src/qemu/qemu_process.c | 12 +++--- 9 files changed, 91 insertions(+), 85 deletions(-) diff --git a/src/hypervisor/domain_job.h b/src/hypervisor/domain_job.h index 30f950ec23..c56c22e63c 100644 --- a/src/hypervisor/domain_job.h +++ b/src/hypervisor/domain_job.h @@ -7,6 +7,9 @@ #include "internal.h" #include "virenum.h" +#include "virthread.h" +#include "virbuffer.h" +#include "domain_conf.h" #define JOB_MASK(job) (job == 0 ? 0 : 1 << (job - 1)) #define VIR_JOB_DEFAULT_MASK \ @@ -99,6 +102,7 @@ struct _virDomainJobDataPrivateDataCallbacks { virDomainJobDataPrivateDataFree freePrivateData; }; + typedef struct _virDomainJobData virDomainJobData; struct _virDomainJobData { virDomainJobType jobType; @@ -139,3 +143,61 @@ virDomainJobDataCopy(virDomainJobData *data); virDomainJobType virDomainJobStatusToType(virDomainJobStatus status); + + +typedef struct _virDomainObjPrivateJobCallbacks virDomainObjPrivateJobCallbacks; + +typedef struct _virDomainJobObj virDomainJobObj; +struct _virDomainJobObj { + virCond cond; /* Use to coordinate jobs */ + + int jobsQueued; + + /* The following members are for VIR_JOB_* */ + virDomainJob active; /* currently running job */ + unsigned long long owner; /* Thread id which set current job */ + char *ownerAPI; /* The API which owns the job */ + unsigned long long started; /* When the current job started */ + + /* The following members are for VIR_AGENT_JOB_* */ + virDomainAgentJob agentActive; /* Currently running agent job */ + unsigned long long agentOwner; /* Thread id which set current agent job */ + char *agentOwnerAPI; /* The API which owns the agent job */ + unsigned long long agentStarted; /* When the current agent job started */ + + /* The following members are for VIR_ASYNC_JOB_* */ + virCond asyncCond; /* Use to coordinate with async jobs */ + virDomainAsyncJob asyncJob; /* Currently active async job */ + unsigned long long asyncOwner; /* Thread which set current async job */ + char *asyncOwnerAPI; /* The API which owns the async job */ + unsigned long long asyncStarted; /* When the current async job started */ + int phase; /* Job phase (mainly for migrations) */ + unsigned long long mask; /* Jobs allowed during async job */ + virDomainJobData *current; /* async job progress data */ + virDomainJobData *completed; /* statistics data of a recently completed job */ + bool abortJob; /* abort of the job requested */ + char *error; /* job event completion error */ + unsigned long apiFlags; /* flags passed to the API which started the async job */ + + void *privateData; /* job specific collection of data */ + virDomainObjPrivateJobCallbacks *cb; +}; + + +typedef void *(*virDomainObjPrivateJobAlloc)(void); +typedef void (*virDomainObjPrivateJobFree)(void *); +typedef void (*virDomainObjPrivateJobReset)(void *); +typedef int (*virDomainObjPrivateJobFormat)(virBuffer *, + virDomainJobObj *, + virDomainObj *); +typedef int (*virDomainObjPrivateJobParse)(xmlXPathContextPtr, + virDomainJobObj *, + virDomainObj *); + +struct _virDomainObjPrivateJobCallbacks { + virDomainObjPrivateJobAlloc allocJobPrivate; + virDomainObjPrivateJobFree freeJobPrivate; + virDomainObjPrivateJobReset resetJobPrivate; + virDomainObjPrivateJobFormat formatJob; + virDomainObjPrivateJobParse parseJob; +}; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 94b2e3118c..a643dd03af 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -199,7 +199,7 @@ qemuDomainObjPrivateXMLFormatMigrateTempBitmap(virBuffer *buf, static int qemuDomainFormatJobPrivate(virBuffer *buf, - qemuDomainJobObj *job, + virDomainJobObj *job, virDomainObj *vm) { qemuDomainJobPrivate *priv = job->privateData; @@ -342,7 +342,7 @@ qemuDomainObjPrivateXMLParseMigrateTempBitmap(qemuDomainJobPrivate *jobPriv, static int qemuDomainParseJobPrivate(xmlXPathContextPtr ctxt, - qemuDomainJobObj *job, + virDomainJobObj *job, virDomainObj *vm) { qemuDomainJobPrivate *priv = job->privateData; @@ -360,7 +360,7 @@ qemuDomainParseJobPrivate(xmlXPathContextPtr ctxt, } -static qemuDomainObjPrivateJobCallbacks qemuPrivateJobCallbacks = { +static virDomainObjPrivateJobCallbacks qemuPrivateJobCallbacks = { .allocJobPrivate = qemuJobAllocPrivate, .freeJobPrivate = qemuJobFreePrivate, .resetJobPrivate = qemuJobResetPrivate, diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 499ad03f91..4680df1098 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -99,7 +99,7 @@ typedef struct _qemuDomainObjPrivate qemuDomainObjPrivate; struct _qemuDomainObjPrivate { virQEMUDriver *driver; - qemuDomainJobObj job; + virDomainJobObj job; virBitmap *namespaces; diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c index 1f6d976558..05480239b1 100644 --- a/src/qemu/qemu_domainjob.c +++ b/src/qemu/qemu_domainjob.c @@ -151,8 +151,8 @@ qemuDomainEventEmitJobCompleted(virQEMUDriver *driver, int -qemuDomainObjInitJob(qemuDomainJobObj *job, - qemuDomainObjPrivateJobCallbacks *cb) +qemuDomainObjInitJob(virDomainJobObj *job, + virDomainObjPrivateJobCallbacks *cb) { memset(job, 0, sizeof(*job)); job->cb = cb; @@ -177,7 +177,7 @@ qemuDomainObjInitJob(qemuDomainJobObj *job, static void -qemuDomainObjResetJob(qemuDomainJobObj *job) +qemuDomainObjResetJob(virDomainJobObj *job) { job->active = VIR_JOB_NONE; job->owner = 0; @@ -187,7 +187,7 @@ qemuDomainObjResetJob(qemuDomainJobObj *job) static void -qemuDomainObjResetAgentJob(qemuDomainJobObj *job) +qemuDomainObjResetAgentJob(virDomainJobObj *job) { job->agentActive = VIR_AGENT_JOB_NONE; job->agentOwner = 0; @@ -197,7 +197,7 @@ qemuDomainObjResetAgentJob(qemuDomainJobObj *job) static void -qemuDomainObjResetAsyncJob(qemuDomainJobObj *job) +qemuDomainObjResetAsyncJob(virDomainJobObj *job) { job->asyncJob = VIR_ASYNC_JOB_NONE; job->asyncOwner = 0; @@ -226,7 +226,7 @@ qemuDomainObjResetAsyncJob(qemuDomainJobObj *job) */ int qemuDomainObjPreserveJob(virDomainObj *obj, - qemuDomainJobObj *job) + virDomainJobObj *job) { qemuDomainObjPrivate *priv = obj->privateData; @@ -262,7 +262,7 @@ qemuDomainObjRestoreAsyncJob(virDomainObj *vm, unsigned long long allowedJobs) { qemuDomainObjPrivate *priv = vm->privateData; - qemuDomainJobObj *job = &priv->job; + virDomainJobObj *job = &priv->job; VIR_DEBUG("Restoring %s async job for domain %s", virDomainAsyncJobTypeToString(asyncJob), vm->def->name); @@ -287,7 +287,7 @@ qemuDomainObjRestoreAsyncJob(virDomainObj *vm, void -qemuDomainObjClearJob(qemuDomainJobObj *job) +qemuDomainObjClearJob(virDomainJobObj *job) { qemuDomainObjResetJob(job); qemuDomainObjResetAsyncJob(job); @@ -820,7 +820,7 @@ qemuDomainObjReleaseAsyncJob(virDomainObj *obj) } static bool -qemuDomainNestedJobAllowed(qemuDomainJobObj *jobs, virDomainJob newJob) +qemuDomainNestedJobAllowed(virDomainJobObj *jobs, virDomainJob newJob) { return !jobs->asyncJob || newJob == VIR_JOB_NONE || @@ -828,7 +828,7 @@ qemuDomainNestedJobAllowed(qemuDomainJobObj *jobs, virDomainJob newJob) } static bool -qemuDomainObjCanSetJob(qemuDomainJobObj *job, +qemuDomainObjCanSetJob(virDomainJobObj *job, virDomainJob newJob, virDomainAgentJob newAgentJob) { @@ -1308,7 +1308,7 @@ qemuDomainObjPrivateXMLParseJob(virDomainObj *vm, xmlXPathContextPtr ctxt) { qemuDomainObjPrivate *priv = vm->privateData; - qemuDomainJobObj *job = &priv->job; + virDomainJobObj *job = &priv->job; VIR_XPATH_NODE_AUTORESTORE(ctxt) g_autofree char *tmp = NULL; diff --git a/src/qemu/qemu_domainjob.h b/src/qemu/qemu_domainjob.h index e8021a7f04..b39b04edcb 100644 --- a/src/qemu/qemu_domainjob.h +++ b/src/qemu/qemu_domainjob.h @@ -60,62 +60,6 @@ struct _qemuDomainJobDataPrivate { extern virDomainJobDataPrivateDataCallbacks qemuJobDataPrivateDataCallbacks; -typedef struct _qemuDomainJobObj qemuDomainJobObj; - -typedef void *(*qemuDomainObjPrivateJobAlloc)(void); -typedef void (*qemuDomainObjPrivateJobFree)(void *); -typedef void (*qemuDomainObjPrivateJobReset)(void *); -typedef int (*qemuDomainObjPrivateJobFormat)(virBuffer *, - qemuDomainJobObj *, - virDomainObj *); -typedef int (*qemuDomainObjPrivateJobParse)(xmlXPathContextPtr, - qemuDomainJobObj *, - virDomainObj *); - -typedef struct _qemuDomainObjPrivateJobCallbacks qemuDomainObjPrivateJobCallbacks; -struct _qemuDomainObjPrivateJobCallbacks { - qemuDomainObjPrivateJobAlloc allocJobPrivate; - qemuDomainObjPrivateJobFree freeJobPrivate; - qemuDomainObjPrivateJobReset resetJobPrivate; - qemuDomainObjPrivateJobFormat formatJob; - qemuDomainObjPrivateJobParse parseJob; -}; - -struct _qemuDomainJobObj { - virCond cond; /* Use to coordinate jobs */ - - int jobsQueued; - - /* The following members are for VIR_JOB_* */ - virDomainJob active; /* Currently running job */ - unsigned long long owner; /* Thread id which set current job */ - char *ownerAPI; /* The API which owns the job */ - unsigned long long started; /* When the current job started */ - - /* The following members are for VIR_AGENT_JOB_* */ - virDomainAgentJob agentActive; /* Currently running agent job */ - unsigned long long agentOwner; /* Thread id which set current agent job */ - char *agentOwnerAPI; /* The API which owns the agent job */ - unsigned long long agentStarted; /* When the current agent job started */ - - /* The following members are for VIR_ASYNC_JOB_* */ - virCond asyncCond; /* Use to coordinate with async jobs */ - virDomainAsyncJob asyncJob; /* Currently active async job */ - unsigned long long asyncOwner; /* Thread which set current async job */ - char *asyncOwnerAPI; /* The API which owns the async job */ - unsigned long long asyncStarted; /* When the current async job started */ - int phase; /* Job phase (mainly for migrations) */ - unsigned long long mask; /* Jobs allowed during async job */ - virDomainJobData *current; /* async job progress data */ - virDomainJobData *completed; /* statistics data of a recently completed job */ - bool abortJob; /* abort of the job requested */ - char *error; /* job event completion error */ - unsigned long apiFlags; /* flags passed to the API which started the async job */ - - void *privateData; /* job specific collection of data */ - qemuDomainObjPrivateJobCallbacks *cb; -}; - void qemuDomainJobSetStatsType(virDomainJobData *jobData, qemuDomainJobStatsType type); @@ -162,7 +106,7 @@ qemuDomainObjStartJobPhase(virDomainObj *obj, void qemuDomainObjSetAsyncJobMask(virDomainObj *obj, unsigned long long allowedJobs); int qemuDomainObjPreserveJob(virDomainObj *obj, - qemuDomainJobObj *job); + virDomainJobObj *job); void qemuDomainObjRestoreAsyncJob(virDomainObj *vm, virDomainAsyncJob asyncJob, @@ -191,12 +135,12 @@ int qemuDomainJobDataToParams(virDomainJobData *jobData, bool qemuDomainTrackJob(virDomainJob job); -void qemuDomainObjClearJob(qemuDomainJobObj *job); -G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(qemuDomainJobObj, qemuDomainObjClearJob); +void qemuDomainObjClearJob(virDomainJobObj *job); +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virDomainJobObj, qemuDomainObjClearJob); int -qemuDomainObjInitJob(qemuDomainJobObj *job, - qemuDomainObjPrivateJobCallbacks *cb); +qemuDomainObjInitJob(virDomainJobObj *job, + virDomainObjPrivateJobCallbacks *cb); int qemuDomainObjPrivateXMLFormatJob(virBuffer *buf, diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index b12cb518ee..b096e56824 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -6385,7 +6385,7 @@ qemuMigrationDstComplete(virQEMUDriver *driver, virDomainObj *vm, bool inPostCopy, virDomainAsyncJob asyncJob, - qemuDomainJobObj *job) + virDomainJobObj *job) { qemuDomainObjPrivate *priv = vm->privateData; qemuDomainJobPrivate *jobPriv = job->privateData; diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index 81cc1e91c0..65c29d5744 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -204,7 +204,7 @@ qemuMigrationDstComplete(virQEMUDriver *driver, virDomainObj *vm, bool inPostCopy, virDomainAsyncJob asyncJob, - qemuDomainJobObj *job); + virDomainJobObj *job); int qemuMigrationSrcConfirm(virQEMUDriver *driver, diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c index 0bce358ac3..1fd0c55905 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -1181,7 +1181,7 @@ qemuMigrationParamsGetULL(qemuMigrationParams *migParams, * qemuMigrationParamsCheck: * * Check supported migration parameters and keep their original values in - * qemuDomainJobObj so that we can properly reset them at the end of migration. + * virDomainJobObj so that we can properly reset them at the end of migration. * Reports an error if any of the currently used capabilities in @migParams * are unsupported by QEMU. */ diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 486be9344a..d42333195a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3457,7 +3457,7 @@ qemuProcessCleanupMigrationJob(virQEMUDriver *driver, static void qemuProcessRestoreMigrationJob(virDomainObj *vm, - qemuDomainJobObj *job) + virDomainJobObj *job) { qemuDomainObjPrivate *priv = vm->privateData; qemuDomainJobPrivate *jobPriv = job->privateData; @@ -3496,7 +3496,7 @@ qemuProcessRestoreMigrationJob(virDomainObj *vm, static int qemuProcessRecoverMigrationIn(virQEMUDriver *driver, virDomainObj *vm, - qemuDomainJobObj *job, + virDomainJobObj *job, virDomainState state) { VIR_DEBUG("Active incoming migration in phase %s", @@ -3567,7 +3567,7 @@ qemuProcessRecoverMigrationIn(virQEMUDriver *driver, static int qemuProcessRecoverMigrationOut(virQEMUDriver *driver, virDomainObj *vm, - qemuDomainJobObj *job, + virDomainJobObj *job, virDomainJobStatus migStatus, virDomainState state, int reason, @@ -3673,7 +3673,7 @@ qemuProcessRecoverMigrationOut(virQEMUDriver *driver, static int qemuProcessRecoverMigration(virQEMUDriver *driver, virDomainObj *vm, - qemuDomainJobObj *job, + virDomainJobObj *job, unsigned int *stopFlags) { virDomainJobStatus migStatus = VIR_DOMAIN_JOB_STATUS_NONE; @@ -3735,7 +3735,7 @@ qemuProcessRecoverMigration(virQEMUDriver *driver, static int qemuProcessRecoverJob(virQEMUDriver *driver, virDomainObj *vm, - qemuDomainJobObj *job, + virDomainJobObj *job, unsigned int *stopFlags) { qemuDomainObjPrivate *priv = vm->privateData; @@ -8866,7 +8866,7 @@ qemuProcessReconnect(void *opaque) virQEMUDriver *driver = data->driver; virDomainObj *obj = data->obj; qemuDomainObjPrivate *priv; - g_auto(qemuDomainJobObj) oldjob = { + g_auto(virDomainJobObj) oldjob = { .cb = NULL, }; int state; -- 2.35.3