qemu: Don't store disk alias in qemuAgentDiskInfo

The qemuAgentDiskInfo structure is filled with information received from
the agent command response, except for the 'alias' field, which is
retrieved from the vm definition. Limit this structure only to data that
was received from the agent message.

This is another intermediate step in moving the responsibility for
searching the vmdef from qemu_agent.c to qemu_driver.c so that we can
avoid holding an agent job and a normal job at the same time.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jonathon Jongsma 2020-01-10 17:32:12 -06:00 committed by Michal Privoznik
parent bdb8a800b4
commit 306b4cb070

View File

@ -1851,7 +1851,6 @@ qemuAgentSetTime(qemuAgentPtr mon,
typedef struct _qemuAgentDiskInfo qemuAgentDiskInfo; typedef struct _qemuAgentDiskInfo qemuAgentDiskInfo;
typedef qemuAgentDiskInfo *qemuAgentDiskInfoPtr; typedef qemuAgentDiskInfo *qemuAgentDiskInfoPtr;
struct _qemuAgentDiskInfo { struct _qemuAgentDiskInfo {
char *alias;
char *serial; char *serial;
virPCIDeviceAddress pci_controller; virPCIDeviceAddress pci_controller;
char *bus_type; char *bus_type;
@ -1880,7 +1879,6 @@ qemuAgentDiskInfoFree(qemuAgentDiskInfoPtr info)
return; return;
VIR_FREE(info->serial); VIR_FREE(info->serial);
VIR_FREE(info->alias);
VIR_FREE(info->bus_type); VIR_FREE(info->bus_type);
VIR_FREE(info->devnode); VIR_FREE(info->devnode);
VIR_FREE(info); VIR_FREE(info);
@ -1906,7 +1904,8 @@ qemuAgentFSInfoFree(qemuAgentFSInfoPtr info)
} }
static virDomainFSInfoPtr static virDomainFSInfoPtr
qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent) qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent,
virDomainDefPtr vmdef)
{ {
virDomainFSInfoPtr ret = NULL; virDomainFSInfoPtr ret = NULL;
size_t i; size_t i;
@ -1924,8 +1923,19 @@ qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent)
ret->ndevAlias = agent->ndisks; ret->ndevAlias = agent->ndisks;
for (i = 0; i < ret->ndevAlias; i++) for (i = 0; i < ret->ndevAlias; i++) {
ret->devAlias[i] = g_strdup(agent->disks[i]->alias); qemuAgentDiskInfoPtr agentdisk = agent->disks[i];
virDomainDiskDefPtr diskDef;
if (!(diskDef = virDomainDiskByAddress(vmdef,
&agentdisk->pci_controller,
agentdisk->bus,
agentdisk->target,
agentdisk->unit)))
continue;
ret->devAlias[i] = g_strdup(diskDef->dst);
}
return ret; return ret;
@ -1936,8 +1946,7 @@ qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent)
static int static int
qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks, qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
qemuAgentFSInfoPtr fsinfo, qemuAgentFSInfoPtr fsinfo)
virDomainDefPtr vmdef)
{ {
size_t ndisks; size_t ndisks;
size_t i; size_t i;
@ -1960,7 +1969,6 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
virJSONValuePtr jsondisk = virJSONValueArrayGet(jsondisks, i); virJSONValuePtr jsondisk = virJSONValueArrayGet(jsondisks, i);
virJSONValuePtr pci; virJSONValuePtr pci;
qemuAgentDiskInfoPtr disk; qemuAgentDiskInfoPtr disk;
virDomainDiskDefPtr diskDef;
const char *val; const char *val;
if (!jsondisk) { if (!jsondisk) {
@ -2011,14 +2019,6 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
GET_DISK_ADDR(pci, &disk->pci_controller.function, "function"); GET_DISK_ADDR(pci, &disk->pci_controller.function, "function");
#undef GET_DISK_ADDR #undef GET_DISK_ADDR
if (!(diskDef = virDomainDiskByAddress(vmdef,
&disk->pci_controller,
disk->bus,
disk->target,
disk->unit)))
continue;
disk->alias = g_strdup(diskDef->dst);
} }
return 0; return 0;
@ -2030,8 +2030,7 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
*/ */
static int static int
qemuAgentGetFSInfoInternal(qemuAgentPtr mon, qemuAgentGetFSInfoInternal(qemuAgentPtr mon,
qemuAgentFSInfoPtr **info, qemuAgentFSInfoPtr **info)
virDomainDefPtr vmdef)
{ {
size_t i; size_t i;
int ret = -1; int ret = -1;
@ -2147,7 +2146,7 @@ qemuAgentGetFSInfoInternal(qemuAgentPtr mon,
goto cleanup; goto cleanup;
} }
if (qemuAgentGetFSInfoFillDisks(disk, info_ret[i], vmdef) < 0) if (qemuAgentGetFSInfoFillDisks(disk, info_ret[i]) < 0)
goto cleanup; goto cleanup;
} }
@ -2177,14 +2176,14 @@ qemuAgentGetFSInfo(qemuAgentPtr mon,
size_t i; size_t i;
int nfs; int nfs;
nfs = qemuAgentGetFSInfoInternal(mon, &agentinfo, vmdef); nfs = qemuAgentGetFSInfoInternal(mon, &agentinfo);
if (nfs < 0) if (nfs < 0)
return ret; return ret;
if (VIR_ALLOC_N(info_ret, nfs) < 0) if (VIR_ALLOC_N(info_ret, nfs) < 0)
goto cleanup; goto cleanup;
for (i = 0; i < nfs; i++) { for (i = 0; i < nfs; i++) {
if (!(info_ret[i] = qemuAgentFSInfoToPublic(agentinfo[i]))) if (!(info_ret[i] = qemuAgentFSInfoToPublic(agentinfo[i], vmdef)))
goto cleanup; goto cleanup;
} }
@ -2219,7 +2218,7 @@ qemuAgentGetFSInfoParams(qemuAgentPtr mon,
size_t i, j; size_t i, j;
int nfs; int nfs;
if ((nfs = qemuAgentGetFSInfoInternal(mon, &fsinfo, vmdef)) < 0) if ((nfs = qemuAgentGetFSInfoInternal(mon, &fsinfo)) < 0)
return nfs; return nfs;
if (virTypedParamsAddUInt(params, nparams, maxparams, if (virTypedParamsAddUInt(params, nparams, maxparams,
@ -2266,13 +2265,22 @@ qemuAgentGetFSInfoParams(qemuAgentPtr mon,
param_name, fsinfo[i]->ndisks) < 0) param_name, fsinfo[i]->ndisks) < 0)
goto cleanup; goto cleanup;
for (j = 0; j < fsinfo[i]->ndisks; j++) { for (j = 0; j < fsinfo[i]->ndisks; j++) {
virDomainDiskDefPtr diskdef = NULL;
qemuAgentDiskInfoPtr d = fsinfo[i]->disks[j]; qemuAgentDiskInfoPtr d = fsinfo[i]->disks[j];
g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, /* match the disk to the target in the vm definition */
"fs.%zu.disk.%zu.alias", i, j); diskdef = virDomainDiskByAddress(vmdef,
if (d->alias && &d->pci_controller,
virTypedParamsAddString(params, nparams, maxparams, d->bus,
param_name, d->alias) < 0) d->target,
goto cleanup; d->unit);
if (diskdef) {
g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
"fs.%zu.disk.%zu.alias", i, j);
if (diskdef->dst &&
virTypedParamsAddString(params, nparams, maxparams,
param_name, diskdef->dst) < 0)
goto cleanup;
}
g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
"fs.%zu.disk.%zu.serial", i, j); "fs.%zu.disk.%zu.serial", i, j);