2022-02-11 13:49:05 +00:00
|
|
|
/*
|
2022-07-19 12:52:01 +00:00
|
|
|
* domain_job.h: job functions shared between hypervisor drivers
|
|
|
|
*
|
2022-02-11 13:49:05 +00:00
|
|
|
* Copyright (C) 2022 Red Hat, Inc.
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "internal.h"
|
2022-03-24 15:32:42 +00:00
|
|
|
#include "virenum.h"
|
2022-07-19 13:48:20 +00:00
|
|
|
#include "virthread.h"
|
|
|
|
#include "virbuffer.h"
|
|
|
|
#include "domain_conf.h"
|
2022-03-24 15:32:42 +00:00
|
|
|
|
2022-03-24 15:32:43 +00:00
|
|
|
#define JOB_MASK(job) (job == 0 ? 0 : 1 << (job - 1))
|
|
|
|
#define VIR_JOB_DEFAULT_MASK \
|
|
|
|
(JOB_MASK(VIR_JOB_QUERY) | \
|
|
|
|
JOB_MASK(VIR_JOB_DESTROY) | \
|
|
|
|
JOB_MASK(VIR_JOB_ABORT))
|
|
|
|
|
|
|
|
/* Jobs which have to be tracked in domain state XML. */
|
|
|
|
#define VIR_DOMAIN_TRACK_JOBS \
|
|
|
|
(JOB_MASK(VIR_JOB_DESTROY) | \
|
|
|
|
JOB_MASK(VIR_JOB_ASYNC))
|
|
|
|
|
|
|
|
|
2022-03-24 15:32:42 +00:00
|
|
|
/* Only 1 job is allowed at any time
|
2022-03-24 15:32:44 +00:00
|
|
|
* A job includes *all* monitor commands / hypervisor.so api,
|
|
|
|
* even those just querying information, not merely actions */
|
2022-03-24 15:32:42 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_JOB_NONE = 0, /* Always set to 0 for easy if (jobActive) conditions */
|
|
|
|
VIR_JOB_QUERY, /* Doesn't change any state */
|
|
|
|
VIR_JOB_DESTROY, /* Destroys the domain (cannot be masked out) */
|
|
|
|
VIR_JOB_SUSPEND, /* Suspends (stops vCPUs) the domain */
|
|
|
|
VIR_JOB_MODIFY, /* May change state */
|
|
|
|
VIR_JOB_ABORT, /* Abort current async job */
|
|
|
|
VIR_JOB_MIGRATION_OP, /* Operation influencing outgoing migration */
|
2022-05-24 14:17:23 +00:00
|
|
|
VIR_JOB_MODIFY_MIGRATION_SAFE, /* Internal only job for event handlers which
|
|
|
|
need to be processed even during migration.
|
|
|
|
The code may only change state in a way
|
|
|
|
that does not affect migration. */
|
2022-03-24 15:32:42 +00:00
|
|
|
|
|
|
|
/* The following two items must always be the last items before JOB_LAST */
|
|
|
|
VIR_JOB_ASYNC, /* Asynchronous job */
|
|
|
|
VIR_JOB_ASYNC_NESTED, /* Normal job within an async job */
|
|
|
|
|
|
|
|
VIR_JOB_LAST
|
|
|
|
} virDomainJob;
|
|
|
|
VIR_ENUM_DECL(virDomainJob);
|
|
|
|
|
|
|
|
|
|
|
|
/* Currently only QEMU driver uses agent jobs */
|
|
|
|
typedef enum {
|
|
|
|
VIR_AGENT_JOB_NONE = 0, /* No agent job. */
|
|
|
|
VIR_AGENT_JOB_QUERY, /* Does not change state of domain */
|
|
|
|
VIR_AGENT_JOB_MODIFY, /* May change state of domain */
|
|
|
|
|
|
|
|
VIR_AGENT_JOB_LAST
|
|
|
|
} virDomainAgentJob;
|
|
|
|
VIR_ENUM_DECL(virDomainAgentJob);
|
|
|
|
|
|
|
|
|
|
|
|
/* Async job consists of a series of jobs that may change state. Independent
|
|
|
|
* jobs that do not change state (and possibly others if explicitly allowed by
|
|
|
|
* current async job) are allowed to be run even if async job is active.
|
|
|
|
* Currently supported by QEMU only. */
|
|
|
|
typedef enum {
|
|
|
|
VIR_ASYNC_JOB_NONE = 0,
|
|
|
|
VIR_ASYNC_JOB_MIGRATION_OUT,
|
|
|
|
VIR_ASYNC_JOB_MIGRATION_IN,
|
|
|
|
VIR_ASYNC_JOB_SAVE,
|
|
|
|
VIR_ASYNC_JOB_DUMP,
|
|
|
|
VIR_ASYNC_JOB_SNAPSHOT,
|
|
|
|
VIR_ASYNC_JOB_START,
|
|
|
|
VIR_ASYNC_JOB_BACKUP,
|
|
|
|
|
|
|
|
VIR_ASYNC_JOB_LAST
|
|
|
|
} virDomainAsyncJob;
|
|
|
|
VIR_ENUM_DECL(virDomainAsyncJob);
|
|
|
|
|
2022-02-11 13:49:05 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
VIR_DOMAIN_JOB_STATUS_NONE = 0,
|
|
|
|
VIR_DOMAIN_JOB_STATUS_ACTIVE,
|
|
|
|
VIR_DOMAIN_JOB_STATUS_MIGRATING,
|
|
|
|
VIR_DOMAIN_JOB_STATUS_HYPERVISOR_COMPLETED,
|
|
|
|
VIR_DOMAIN_JOB_STATUS_PAUSED,
|
|
|
|
VIR_DOMAIN_JOB_STATUS_POSTCOPY,
|
2022-05-10 13:20:25 +00:00
|
|
|
VIR_DOMAIN_JOB_STATUS_POSTCOPY_PAUSED,
|
2022-02-11 13:49:05 +00:00
|
|
|
VIR_DOMAIN_JOB_STATUS_COMPLETED,
|
|
|
|
VIR_DOMAIN_JOB_STATUS_FAILED,
|
|
|
|
VIR_DOMAIN_JOB_STATUS_CANCELED,
|
|
|
|
} virDomainJobStatus;
|
|
|
|
|
|
|
|
typedef void *(*virDomainJobDataPrivateDataAlloc) (void);
|
|
|
|
typedef void *(*virDomainJobDataPrivateDataCopy) (void *);
|
|
|
|
typedef void (*virDomainJobDataPrivateDataFree) (void *);
|
|
|
|
|
|
|
|
typedef struct _virDomainJobDataPrivateDataCallbacks virDomainJobDataPrivateDataCallbacks;
|
|
|
|
struct _virDomainJobDataPrivateDataCallbacks {
|
|
|
|
virDomainJobDataPrivateDataAlloc allocPrivateData;
|
|
|
|
virDomainJobDataPrivateDataCopy copyPrivateData;
|
|
|
|
virDomainJobDataPrivateDataFree freePrivateData;
|
|
|
|
};
|
|
|
|
|
2022-07-19 13:48:20 +00:00
|
|
|
|
2022-02-11 13:49:05 +00:00
|
|
|
typedef struct _virDomainJobData virDomainJobData;
|
|
|
|
struct _virDomainJobData {
|
|
|
|
virDomainJobType jobType;
|
|
|
|
|
|
|
|
virDomainJobStatus status;
|
|
|
|
virDomainJobOperation operation;
|
|
|
|
unsigned long long started; /* When the async job started */
|
|
|
|
unsigned long long stopped; /* When the domain's CPUs were stopped */
|
|
|
|
unsigned long long sent; /* When the source sent status info to the
|
|
|
|
destination (only for migrations). */
|
|
|
|
unsigned long long received; /* When the destination host received status
|
|
|
|
info from the source (migrations only). */
|
|
|
|
/* Computed values */
|
|
|
|
unsigned long long timeElapsed;
|
|
|
|
long long timeDelta; /* delta = received - sent, i.e., the difference between
|
|
|
|
the source and the destination time plus the time
|
|
|
|
between the end of Perform phase on the source and
|
|
|
|
the beginning of Finish phase on the destination. */
|
|
|
|
bool timeDeltaSet;
|
|
|
|
|
|
|
|
char *errmsg; /* optional error message for failed completed jobs */
|
|
|
|
|
|
|
|
void *privateData; /* private data of hypervisors */
|
2022-07-19 12:52:01 +00:00
|
|
|
virDomainJobDataPrivateDataCallbacks *privateDataCb; /* callbacks of private data,
|
|
|
|
hypervisor based */
|
2022-02-11 13:49:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
virDomainJobData *
|
|
|
|
virDomainJobDataInit(virDomainJobDataPrivateDataCallbacks *cb);
|
|
|
|
|
|
|
|
void
|
|
|
|
virDomainJobDataFree(virDomainJobData *data);
|
|
|
|
|
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainJobData, virDomainJobDataFree);
|
|
|
|
|
|
|
|
virDomainJobData *
|
|
|
|
virDomainJobDataCopy(virDomainJobData *data);
|
|
|
|
|
|
|
|
virDomainJobType
|
|
|
|
virDomainJobStatusToType(virDomainJobStatus status);
|
2022-07-19 13:48:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
2022-07-19 13:48:21 +00:00
|
|
|
virDomainObjPrivateJobFormat formatJobPrivate;
|
|
|
|
virDomainObjPrivateJobParse parseJobPrivate;
|
2022-07-19 13:48:20 +00:00
|
|
|
};
|
2022-07-21 11:54:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
int virDomainObjInitJob(virDomainJobObj *job,
|
|
|
|
virDomainObjPrivateJobCallbacks *cb);
|
2022-07-22 14:25:31 +00:00
|
|
|
|
|
|
|
void virDomainObjResetJob(virDomainJobObj *job);
|
2022-08-03 12:43:12 +00:00
|
|
|
|
|
|
|
void virDomainObjResetAgentJob(virDomainJobObj *job);
|
2022-08-03 12:43:13 +00:00
|
|
|
|
|
|
|
void virDomainObjResetAsyncJob(virDomainJobObj *job);
|
2022-08-03 12:43:15 +00:00
|
|
|
|
|
|
|
int virDomainObjPreserveJob(virDomainJobObj *currJob,
|
|
|
|
virDomainJobObj *job);
|
2022-08-03 12:43:16 +00:00
|
|
|
|
|
|
|
void virDomainObjClearJob(virDomainJobObj *job);
|
|
|
|
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virDomainJobObj, virDomainObjClearJob);
|
2022-08-03 12:43:20 +00:00
|
|
|
|
|
|
|
bool virDomainTrackJob(virDomainJob job);
|