libxl: remove usage of virDomainJobData

Struct virDomainJobData is meant for statistics for async jobs.
It was used to keep track of only two attributes, one of which is
also in the generalized virDomainJobObj ("started") and one which
is always set to the same value, if any job is active
("jobType").

This patch removes usage & allocation of virDomainJobData
structure and rewrites libxlDomainJobUpdateTime() into more
suitable libxlDomainJobGetTimeElapsed().

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Kristina Hanicova 2022-09-05 15:57:00 +02:00 committed by Ján Tomko
parent 3b1ad4cb17
commit 15e9c5ae2f
3 changed files with 16 additions and 20 deletions

View File

@ -81,8 +81,7 @@ libxlDomainObjBeginJob(libxlDriverPrivate *driver G_GNUC_UNUSED,
VIR_DEBUG("Starting job: %s", virDomainJobTypeToString(job)); VIR_DEBUG("Starting job: %s", virDomainJobTypeToString(job));
priv->job.active = job; priv->job.active = job;
priv->job.owner = virThreadSelfID(); priv->job.owner = virThreadSelfID();
priv->job.current->started = now; priv->job.started = now;
priv->job.current->jobType = VIR_DOMAIN_JOB_UNBOUNDED;
return 0; return 0;
@ -129,23 +128,22 @@ libxlDomainObjEndJob(libxlDriverPrivate *driver G_GNUC_UNUSED,
} }
int int
libxlDomainJobUpdateTime(virDomainJobObj *job) libxlDomainJobGetTimeElapsed(virDomainJobObj *job, unsigned long long *timeElapsed)
{ {
virDomainJobData *jobData = job->current;
unsigned long long now; unsigned long long now;
if (!jobData->started) if (!job->started)
return 0; return 0;
if (virTimeMillisNow(&now) < 0) if (virTimeMillisNow(&now) < 0)
return -1; return -1;
if (now < jobData->started) { if (now < job->started) {
jobData->started = 0; job->started = 0;
return 0; return 0;
} }
jobData->timeElapsed = now - jobData->started; *timeElapsed = now - job->started;
return 0; return 0;
} }
@ -167,8 +165,6 @@ libxlDomainObjPrivateAlloc(void *opaque G_GNUC_UNUSED)
return NULL; return NULL;
} }
priv->job.current = virDomainJobDataInit(NULL);
return priv; return priv;
} }

View File

@ -62,8 +62,8 @@ libxlDomainObjEndJob(libxlDriverPrivate *driver,
virDomainObj *obj); virDomainObj *obj);
int int
libxlDomainJobUpdateTime(virDomainJobObj *job) libxlDomainJobGetTimeElapsed(virDomainJobObj *job,
G_GNUC_WARN_UNUSED_RESULT; unsigned long long *timeElapsed);
char * char *
libxlDomainManagedSavePath(libxlDriverPrivate *driver, libxlDomainManagedSavePath(libxlDriverPrivate *driver,

View File

@ -5207,6 +5207,7 @@ libxlDomainGetJobInfo(virDomainPtr dom,
libxlDomainObjPrivate *priv; libxlDomainObjPrivate *priv;
virDomainObj *vm; virDomainObj *vm;
int ret = -1; int ret = -1;
unsigned long long timeElapsed = 0;
if (!(vm = libxlDomObjFromDomain(dom))) if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup; goto cleanup;
@ -5225,14 +5226,14 @@ libxlDomainGetJobInfo(virDomainPtr dom,
/* In libxl we don't have an estimated completion time /* In libxl we don't have an estimated completion time
* thus we always set to unbounded and update time * thus we always set to unbounded and update time
* for the active job. */ * for the active job. */
if (libxlDomainJobUpdateTime(&priv->job) < 0) if (libxlDomainJobGetTimeElapsed(&priv->job, &timeElapsed) < 0)
goto cleanup; goto cleanup;
/* setting only these two attributes is enough because libxl never sets /* setting only these two attributes is enough because libxl never sets
* anything else */ * anything else */
memset(info, 0, sizeof(*info)); memset(info, 0, sizeof(*info));
info->type = priv->job.current->jobType; info->type = VIR_DOMAIN_JOB_UNBOUNDED;
info->timeElapsed = priv->job.current->timeElapsed; info->timeElapsed = timeElapsed;
ret = 0; ret = 0;
cleanup: cleanup:
@ -5249,9 +5250,9 @@ libxlDomainGetJobStats(virDomainPtr dom,
{ {
libxlDomainObjPrivate *priv; libxlDomainObjPrivate *priv;
virDomainObj *vm; virDomainObj *vm;
virDomainJobData *jobData;
int ret = -1; int ret = -1;
int maxparams = 0; int maxparams = 0;
unsigned long long timeElapsed = 0;
/* VIR_DOMAIN_JOB_STATS_COMPLETED not supported yet */ /* VIR_DOMAIN_JOB_STATS_COMPLETED not supported yet */
virCheckFlags(0, -1); virCheckFlags(0, -1);
@ -5263,7 +5264,6 @@ libxlDomainGetJobStats(virDomainPtr dom,
goto cleanup; goto cleanup;
priv = vm->privateData; priv = vm->privateData;
jobData = priv->job.current;
if (!priv->job.active) { if (!priv->job.active) {
*type = VIR_DOMAIN_JOB_NONE; *type = VIR_DOMAIN_JOB_NONE;
*params = NULL; *params = NULL;
@ -5275,15 +5275,15 @@ libxlDomainGetJobStats(virDomainPtr dom,
/* In libxl we don't have an estimated completion time /* In libxl we don't have an estimated completion time
* thus we always set to unbounded and update time * thus we always set to unbounded and update time
* for the active job. */ * for the active job. */
if (libxlDomainJobUpdateTime(&priv->job) < 0) if (libxlDomainJobGetTimeElapsed(&priv->job, &timeElapsed) < 0)
goto cleanup; goto cleanup;
if (virTypedParamsAddULLong(params, nparams, &maxparams, if (virTypedParamsAddULLong(params, nparams, &maxparams,
VIR_DOMAIN_JOB_TIME_ELAPSED, VIR_DOMAIN_JOB_TIME_ELAPSED,
jobData->timeElapsed) < 0) timeElapsed) < 0)
goto cleanup; goto cleanup;
*type = jobData->jobType; *type = VIR_DOMAIN_JOB_UNBOUNDED;
ret = 0; ret = 0;
cleanup: cleanup: