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

View File

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

View File

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