conf: extend xmlopt with job config & add job object into domain object

This patch adds the generalized job object into the domain object
so that it can be used by all drivers without the need to extract
it from the private data.

Because of this, the job object needs to be created and set
during the creation of the domain object. This patch also extends
xmlopt with possible job config containing virDomainJobObj
callbacks, its private data callbacks and one variable
(maxQueuedJobs).

This patch includes:
* addition of virDomainJobObj into virDomainObj (used in the
  following patches)
* extending xmlopt with job config structure
* new function for freeing the virDomainJobObj

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:03 +02:00 committed by Ján Tomko
parent 0c3f023045
commit 84e9fd068c
22 changed files with 62 additions and 19 deletions

View File

@ -221,7 +221,7 @@ virBhyveDriverCreateXMLConf(struct _bhyveConn *driver)
return virDomainXMLOptionNew(&virBhyveDriverDomainDefParserConfig,
&virBhyveDriverPrivateDataCallbacks,
&virBhyveDriverDomainXMLNamespace,
NULL, NULL);
NULL, NULL, NULL);
}

View File

@ -110,7 +110,7 @@ chDomainXMLConfInit(virCHDriver *driver)
virCHDriverDomainDefParserConfig.priv = driver;
return virDomainXMLOptionNew(&virCHDriverDomainDefParserConfig,
&virCHDriverPrivateDataCallbacks,
NULL, NULL, NULL);
NULL, NULL, NULL, NULL);
}
virCHDriverConfig *

View File

@ -1605,7 +1605,8 @@ virDomainXMLOptionNew(virDomainDefParserConfig *config,
virDomainXMLPrivateDataCallbacks *priv,
virXMLNamespace *xmlns,
virDomainABIStability *abi,
virSaveCookieCallbacks *saveCookie)
virSaveCookieCallbacks *saveCookie,
virDomainJobObjConfig *jobConfig)
{
virDomainXMLOption *xmlopt;
@ -1630,6 +1631,9 @@ virDomainXMLOptionNew(virDomainDefParserConfig *config,
if (saveCookie)
xmlopt->saveCookie = *saveCookie;
if (jobConfig)
xmlopt->jobObjConfig = *jobConfig;
/* Technically this forbids to use one of Xerox's MAC address prefixes in
* our hypervisor drivers. This shouldn't ever be a problem.
*
@ -3858,6 +3862,7 @@ static void virDomainObjDispose(void *obj)
virDomainObjDeprecationFree(dom);
virDomainSnapshotObjListFree(dom->snapshots);
virDomainCheckpointObjListFree(dom->checkpoints);
virDomainJobObjFree(dom->job);
}
virDomainObj *
@ -3890,6 +3895,12 @@ virDomainObjNew(virDomainXMLOption *xmlopt)
if (!(domain->checkpoints = virDomainCheckpointObjListNew()))
goto error;
domain->job = g_new0(virDomainJobObj, 1);
if (virDomainObjInitJob(domain->job,
&xmlopt->jobObjConfig.cb,
&xmlopt->jobObjConfig.jobDataPrivateCb) < 0)
goto error;
virObjectLock(domain);
virDomainObjSetState(domain, VIR_DOMAIN_SHUTOFF,
VIR_DOMAIN_SHUTOFF_UNKNOWN);

View File

@ -56,6 +56,7 @@
#include "virsavecookie.h"
#include "virresctrl.h"
#include "virenum.h"
#include "virdomainjob.h"
/* Flags for the 'type' field in virDomainDeviceDef */
typedef enum {
@ -3093,6 +3094,8 @@ struct _virDomainObj {
virObjectLockable parent;
virCond cond;
virDomainJobObj *job;
pid_t pid; /* 0 for no PID, avoid negative values like -1 */
virDomainStateReason state;
@ -3277,11 +3280,19 @@ struct _virDomainABIStability {
virDomainABIStabilityDomain domain;
};
struct _virDomainJobObjConfig {
virDomainObjPrivateJobCallbacks cb;
virDomainJobDataPrivateDataCallbacks jobDataPrivateCb;
unsigned int maxQueuedJobs;
};
virDomainXMLOption *virDomainXMLOptionNew(virDomainDefParserConfig *config,
virDomainXMLPrivateDataCallbacks *priv,
virXMLNamespace *xmlns,
virDomainABIStability *abi,
virSaveCookieCallbacks *saveCookie);
virSaveCookieCallbacks *saveCookie,
virDomainJobObjConfig *jobConfig);
virSaveCookieCallbacks *
virDomainXMLOptionGetSaveCookie(virDomainXMLOption *xmlopt);
@ -3321,6 +3332,9 @@ struct _virDomainXMLOption {
/* Snapshot postparse callbacks */
virDomainMomentPostParseCallback momentPostParse;
/* virDomainJobObj callbacks, private data callbacks and defaults */
virDomainJobObjConfig jobObjConfig;
};
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainXMLOption, virObjectUnref);

View File

@ -150,6 +150,8 @@ typedef struct _virDomainIdMapEntry virDomainIdMapEntry;
typedef struct _virDomainInputDef virDomainInputDef;
typedef struct _virDomainJobObjConfig virDomainJobObjConfig;
typedef struct _virDomainKeyWrapDef virDomainKeyWrapDef;
typedef struct _virDomainLeaseDef virDomainLeaseDef;

View File

@ -13,6 +13,7 @@
#include "virthreadjob.h"
#include "virlog.h"
#include "virtime.h"
#include "domain_conf.h"
#define VIR_FROM_THIS VIR_FROM_NONE
@ -230,6 +231,16 @@ virDomainObjClearJob(virDomainJobObj *job)
g_clear_pointer(&job->privateData, job->cb->freeJobPrivate);
}
void
virDomainJobObjFree(virDomainJobObj *job)
{
if (!job)
return;
virDomainObjClearJob(job);
g_free(job);
}
bool
virDomainTrackJob(virDomainJob job)
{

View File

@ -11,7 +11,8 @@
#include "virenum.h"
#include "virthread.h"
#include "virbuffer.h"
#include "domain_conf.h"
#include "virconftypes.h"
#include "virxml.h"
#define JOB_MASK(job) (job == 0 ? 0 : 1 << (job - 1))
#define VIR_JOB_DEFAULT_MASK \
@ -227,6 +228,8 @@ int virDomainObjPreserveJob(virDomainJobObj *currJob,
void virDomainObjClearJob(virDomainJobObj *job);
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virDomainJobObj, virDomainObjClearJob);
void virDomainJobObjFree(virDomainJobObj *job);
bool virDomainTrackJob(virDomainJob job);
bool virDomainNestedJobAllowed(virDomainJobObj *jobs, virDomainJob newJob);

View File

@ -1766,7 +1766,7 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
goto cleanup;
/* init xmlopt for domain XML */
priv->xmlopt = virDomainXMLOptionNew(&hypervDomainDefParserConfig, NULL, NULL, NULL, NULL);
priv->xmlopt = virDomainXMLOptionNew(&hypervDomainDefParserConfig, NULL, NULL, NULL, NULL, NULL);
if (hypervGetOperatingSystem(priv, &os) < 0)
goto cleanup;

View File

@ -1182,6 +1182,7 @@ virDomainAsyncJobTypeToString;
virDomainJobDataCopy;
virDomainJobDataFree;
virDomainJobDataInit;
virDomainJobObjFree;
virDomainJobStatusToType;
virDomainJobTypeFromString;
virDomainJobTypeToString;

View File

@ -2486,5 +2486,5 @@ libxlCreateXMLConf(libxlDriverPrivate *driver)
return virDomainXMLOptionNew(&libxlDomainDefParserConfig,
&libxlDomainXMLPrivateDataCallbacks,
&libxlDriverDomainXMLNamespace,
NULL, NULL);
NULL, NULL, NULL);
}

View File

@ -189,7 +189,7 @@ lxcDomainXMLConfInit(virLXCDriver *driver, const char *defsecmodel)
return virDomainXMLOptionNew(&virLXCDriverDomainDefParserConfig,
&virLXCDriverPrivateDataCallbacks,
&virLXCDriverDomainXMLNamespace,
NULL, NULL);
NULL, NULL, NULL);
}

View File

@ -1062,5 +1062,5 @@ virDomainXMLOption *openvzXMLOption(struct openvz_driver *driver)
{
openvzDomainDefParserConfig.priv = driver;
return virDomainXMLOptionNew(&openvzDomainDefParserConfig,
NULL, NULL, NULL, NULL);
NULL, NULL, NULL, NULL, NULL);
}

View File

@ -1278,7 +1278,8 @@ virQEMUDriverCreateXMLConf(virQEMUDriver *driver,
&virQEMUDriverPrivateDataCallbacks,
&virQEMUDriverDomainXMLNamespace,
&virQEMUDriverDomainABIStability,
&virQEMUDriverDomainSaveCookie);
&virQEMUDriverDomainSaveCookie,
NULL);
}

View File

@ -9273,7 +9273,7 @@ qemuProcessQMPConnectMonitor(qemuProcessQMP *proc)
monConfig.data.nix.path = proc->monpath;
monConfig.data.nix.listen = false;
if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) ||
if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL, NULL)) ||
!(proc->vm = virDomainObjNew(xmlopt)) ||
!(proc->vm->def = virDomainDefNew(xmlopt)))
return -1;

View File

@ -632,7 +632,7 @@ get_definition(vahControl * ctl, const char *xmlStr)
}
if (!(ctl->xmlopt = virDomainXMLOptionNew(&virAAHelperDomainDefParserConfig,
NULL, NULL, NULL, NULL))) {
NULL, NULL, NULL, NULL, NULL))) {
vah_error(ctl, 0, _("Failed to create XML config object"));
return -1;
}

View File

@ -460,7 +460,7 @@ testDriverNew(void)
if (!(ret = virObjectLockableNew(testDriverClass)))
return NULL;
if (!(ret->xmlopt = virDomainXMLOptionNew(&config, &privatecb, &ns, NULL, NULL)) ||
if (!(ret->xmlopt = virDomainXMLOptionNew(&config, &privatecb, &ns, NULL, NULL, NULL)) ||
!(ret->eventState = virObjectEventStateNew()) ||
!(ret->ifaces = virInterfaceObjListNew()) ||
!(ret->domains = virDomainObjListNew()) ||

View File

@ -143,7 +143,7 @@ vboxDriverObjNew(void)
if (!(driver->caps = vboxCapsInit()) ||
!(driver->xmlopt = virDomainXMLOptionNew(&vboxDomainDefParserConfig,
NULL, NULL, NULL, NULL)))
NULL, NULL, NULL, NULL, NULL)))
goto cleanup;
return driver;

View File

@ -139,7 +139,7 @@ vmwareDomainXMLConfigInit(struct vmware_driver *driver)
.free = vmwareDataFreeFunc };
vmwareDomainDefParserConfig.priv = driver;
return virDomainXMLOptionNew(&vmwareDomainDefParserConfig, &priv,
NULL, NULL, NULL);
NULL, NULL, NULL, NULL);
}
static virDrvOpenStatus

View File

@ -696,7 +696,7 @@ virVMXDomainXMLConfInit(virCaps *caps)
{
virVMXDomainDefParserConfig.priv = caps;
return virDomainXMLOptionNew(&virVMXDomainDefParserConfig, NULL,
&virVMXDomainXMLNamespace, NULL, NULL);
&virVMXDomainXMLNamespace, NULL, NULL, NULL);
}
char *

View File

@ -331,7 +331,7 @@ vzDriverObjNew(void)
if (!(driver->caps = vzBuildCapabilities()) ||
!(driver->xmlopt = virDomainXMLOptionNew(&vzDomainDefParserConfig,
&vzDomainXMLPrivateDataCallbacksPtr,
NULL, NULL, NULL)) ||
NULL, NULL, NULL, NULL)) ||
!(driver->domains = virDomainObjListNew()) ||
!(driver->domainEventState = virObjectEventStateNew()) ||
(vzInitVersion(driver) < 0) ||

View File

@ -113,7 +113,7 @@ mymain(void)
if ((driver.caps = virBhyveCapsBuild()) == NULL)
return EXIT_FAILURE;
if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL,
if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL,
NULL, NULL, NULL)) == NULL)
return EXIT_FAILURE;

View File

@ -989,7 +989,7 @@ static virDomainDefParserConfig virTestGenericDomainDefParserConfig = {
virDomainXMLOption *virTestGenericDomainXMLConfInit(void)
{
return virDomainXMLOptionNew(&virTestGenericDomainDefParserConfig,
NULL, NULL, NULL, NULL);
NULL, NULL, NULL, NULL, NULL);
}