|
|
a41c76 |
From 314e0b35249ff662cb76d9b03f33aeb700c6a43a Mon Sep 17 00:00:00 2001
|
|
|
a41c76 |
Message-Id: <314e0b35249ff662cb76d9b03f33aeb700c6a43a@dist-git>
|
|
|
a41c76 |
From: Jonathon Jongsma <jjongsma@redhat.com>
|
|
|
a41c76 |
Date: Thu, 20 Feb 2020 10:52:26 -0600
|
|
|
a41c76 |
Subject: [PATCH] qemu: don't access vmdef within qemu_agent.c
|
|
|
a41c76 |
MIME-Version: 1.0
|
|
|
a41c76 |
Content-Type: text/plain; charset=UTF-8
|
|
|
a41c76 |
Content-Transfer-Encoding: 8bit
|
|
|
a41c76 |
|
|
|
a41c76 |
In order to avoid holding an agent job and a normal job at the same
|
|
|
a41c76 |
time, we want to avoid accessing the domain's definition while holding
|
|
|
a41c76 |
the agent job. To achieve this, qemuAgentGetFSInfo() only returns the
|
|
|
a41c76 |
raw information from the agent query to the caller. The caller can then
|
|
|
a41c76 |
release the agent job and then proceed to look up the disk alias from
|
|
|
a41c76 |
the vm definition. This necessitates moving a few helper functions to
|
|
|
a41c76 |
qemu_driver.c and exposing the agent data structure (qemuAgentFSInfo) in
|
|
|
a41c76 |
the header.
|
|
|
a41c76 |
|
|
|
a41c76 |
In addition, because the agent function no longer returns the looked-up
|
|
|
a41c76 |
disk alias, we can't test the alias within qemuagenttest. Instead we
|
|
|
a41c76 |
simply test that we parse and return the raw agent data correctly.
|
|
|
a41c76 |
|
|
|
a41c76 |
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
a41c76 |
(cherry picked from commit 599ae372d8cf0923757c5a3792acb07dcf3e8802)
|
|
|
a41c76 |
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
|
|
|
a41c76 |
https://bugzilla.redhat.com/show_bug.cgi?id=1759566
|
|
|
a41c76 |
Message-Id: <20200220165227.11491-5-jjongsma@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
a41c76 |
---
|
|
|
a41c76 |
src/qemu/qemu_agent.c | 219 +----------------------------------
|
|
|
a41c76 |
src/qemu/qemu_agent.h | 33 ++++--
|
|
|
a41c76 |
src/qemu/qemu_driver.c | 255 ++++++++++++++++++++++++++++++++++++++---
|
|
|
a41c76 |
tests/qemuagenttest.c | 196 +++++--------------------------
|
|
|
a41c76 |
4 files changed, 299 insertions(+), 404 deletions(-)
|
|
|
a41c76 |
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
|
|
|
a41c76 |
index 4739faeed8..ef2d2c500b 100644
|
|
|
a41c76 |
--- a/src/qemu/qemu_agent.c
|
|
|
a41c76 |
+++ b/src/qemu/qemu_agent.c
|
|
|
a41c76 |
@@ -1844,30 +1844,6 @@ qemuAgentSetTime(qemuAgentPtr mon,
|
|
|
a41c76 |
return ret;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
-typedef struct _qemuAgentDiskInfo qemuAgentDiskInfo;
|
|
|
a41c76 |
-typedef qemuAgentDiskInfo *qemuAgentDiskInfoPtr;
|
|
|
a41c76 |
-struct _qemuAgentDiskInfo {
|
|
|
a41c76 |
- char *serial;
|
|
|
a41c76 |
- virPCIDeviceAddress pci_controller;
|
|
|
a41c76 |
- char *bus_type;
|
|
|
a41c76 |
- unsigned int bus;
|
|
|
a41c76 |
- unsigned int target;
|
|
|
a41c76 |
- unsigned int unit;
|
|
|
a41c76 |
- char *devnode;
|
|
|
a41c76 |
-};
|
|
|
a41c76 |
-
|
|
|
a41c76 |
-typedef struct _qemuAgentFSInfo qemuAgentFSInfo;
|
|
|
a41c76 |
-typedef qemuAgentFSInfo *qemuAgentFSInfoPtr;
|
|
|
a41c76 |
-struct _qemuAgentFSInfo {
|
|
|
a41c76 |
- char *mountpoint; /* path to mount point */
|
|
|
a41c76 |
- char *name; /* device name in the guest (e.g. "sda1") */
|
|
|
a41c76 |
- char *fstype; /* filesystem type */
|
|
|
a41c76 |
- long long total_bytes;
|
|
|
a41c76 |
- long long used_bytes;
|
|
|
a41c76 |
- size_t ndisks;
|
|
|
a41c76 |
- qemuAgentDiskInfoPtr *disks;
|
|
|
a41c76 |
-};
|
|
|
a41c76 |
-
|
|
|
a41c76 |
static void
|
|
|
a41c76 |
qemuAgentDiskInfoFree(qemuAgentDiskInfoPtr info)
|
|
|
a41c76 |
{
|
|
|
a41c76 |
@@ -1880,7 +1856,7 @@ qemuAgentDiskInfoFree(qemuAgentDiskInfoPtr info)
|
|
|
a41c76 |
VIR_FREE(info);
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
-static void
|
|
|
a41c76 |
+void
|
|
|
a41c76 |
qemuAgentFSInfoFree(qemuAgentFSInfoPtr info)
|
|
|
a41c76 |
{
|
|
|
a41c76 |
size_t i;
|
|
|
a41c76 |
@@ -1899,47 +1875,6 @@ qemuAgentFSInfoFree(qemuAgentFSInfoPtr info)
|
|
|
a41c76 |
VIR_FREE(info);
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
-static virDomainFSInfoPtr
|
|
|
a41c76 |
-qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent,
|
|
|
a41c76 |
- virDomainDefPtr vmdef)
|
|
|
a41c76 |
-{
|
|
|
a41c76 |
- virDomainFSInfoPtr ret = NULL;
|
|
|
a41c76 |
- size_t i;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (VIR_ALLOC(ret) < 0)
|
|
|
a41c76 |
- goto error;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- ret->mountpoint = g_strdup(agent->mountpoint);
|
|
|
a41c76 |
- ret->name = g_strdup(agent->name);
|
|
|
a41c76 |
- ret->fstype = g_strdup(agent->fstype);
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (agent->disks &&
|
|
|
a41c76 |
- VIR_ALLOC_N(ret->devAlias, agent->ndisks) < 0)
|
|
|
a41c76 |
- goto error;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- ret->ndevAlias = agent->ndisks;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- for (i = 0; i < ret->ndevAlias; i++) {
|
|
|
a41c76 |
- qemuAgentDiskInfoPtr agentdisk = agent->disks[i];
|
|
|
a41c76 |
- virDomainDiskDefPtr diskDef;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (!(diskDef = virDomainDiskByAddress(vmdef,
|
|
|
a41c76 |
- &agentdisk->pci_controller,
|
|
|
a41c76 |
- agentdisk->bus,
|
|
|
a41c76 |
- agentdisk->target,
|
|
|
a41c76 |
- agentdisk->unit)))
|
|
|
a41c76 |
- continue;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- ret->devAlias[i] = g_strdup(diskDef->dst);
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- return ret;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- error:
|
|
|
a41c76 |
- virDomainFSInfoFree(ret);
|
|
|
a41c76 |
- return NULL;
|
|
|
a41c76 |
-}
|
|
|
a41c76 |
-
|
|
|
a41c76 |
static int
|
|
|
a41c76 |
qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
|
|
|
a41c76 |
qemuAgentFSInfoPtr fsinfo)
|
|
|
a41c76 |
@@ -2013,7 +1948,6 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
|
|
|
a41c76 |
GET_DISK_ADDR(pci, &disk->pci_controller.bus, "bus");
|
|
|
a41c76 |
GET_DISK_ADDR(pci, &disk->pci_controller.slot, "slot");
|
|
|
a41c76 |
GET_DISK_ADDR(pci, &disk->pci_controller.function, "function");
|
|
|
a41c76 |
-
|
|
|
a41c76 |
#undef GET_DISK_ADDR
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
@@ -2024,9 +1958,9 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
|
|
|
a41c76 |
* -2 when agent command is not supported by the agent
|
|
|
a41c76 |
* -1 otherwise
|
|
|
a41c76 |
*/
|
|
|
a41c76 |
-static int
|
|
|
a41c76 |
-qemuAgentGetFSInfoInternal(qemuAgentPtr mon,
|
|
|
a41c76 |
- qemuAgentFSInfoPtr **info)
|
|
|
a41c76 |
+int
|
|
|
a41c76 |
+qemuAgentGetFSInfo(qemuAgentPtr mon,
|
|
|
a41c76 |
+ qemuAgentFSInfoPtr **info)
|
|
|
a41c76 |
{
|
|
|
a41c76 |
size_t i;
|
|
|
a41c76 |
int ret = -1;
|
|
|
a41c76 |
@@ -2158,151 +2092,6 @@ qemuAgentGetFSInfoInternal(qemuAgentPtr mon,
|
|
|
a41c76 |
return ret;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
-/* Returns: 0 on success
|
|
|
a41c76 |
- * -1 otherwise
|
|
|
a41c76 |
- */
|
|
|
a41c76 |
-int
|
|
|
a41c76 |
-qemuAgentGetFSInfo(qemuAgentPtr mon,
|
|
|
a41c76 |
- virDomainFSInfoPtr **info,
|
|
|
a41c76 |
- virDomainDefPtr vmdef)
|
|
|
a41c76 |
-{
|
|
|
a41c76 |
- int ret = -1;
|
|
|
a41c76 |
- qemuAgentFSInfoPtr *agentinfo = NULL;
|
|
|
a41c76 |
- virDomainFSInfoPtr *info_ret = NULL;
|
|
|
a41c76 |
- size_t i;
|
|
|
a41c76 |
- int nfs;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- nfs = qemuAgentGetFSInfoInternal(mon, &agentinfo);
|
|
|
a41c76 |
- if (nfs < 0)
|
|
|
a41c76 |
- return ret;
|
|
|
a41c76 |
- if (VIR_ALLOC_N(info_ret, nfs) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- for (i = 0; i < nfs; i++) {
|
|
|
a41c76 |
- if (!(info_ret[i] = qemuAgentFSInfoToPublic(agentinfo[i], vmdef)))
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- *info = g_steal_pointer(&info_ret);
|
|
|
a41c76 |
- ret = nfs;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- cleanup:
|
|
|
a41c76 |
- for (i = 0; i < nfs; i++) {
|
|
|
a41c76 |
- qemuAgentFSInfoFree(agentinfo[i]);
|
|
|
a41c76 |
- /* if there was an error, free any memory we've allocated for the
|
|
|
a41c76 |
- * return value */
|
|
|
a41c76 |
- if (info_ret)
|
|
|
a41c76 |
- virDomainFSInfoFree(info_ret[i]);
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
- VIR_FREE(agentinfo);
|
|
|
a41c76 |
- VIR_FREE(info_ret);
|
|
|
a41c76 |
- return ret;
|
|
|
a41c76 |
-}
|
|
|
a41c76 |
-
|
|
|
a41c76 |
-/* Returns: 0 on success
|
|
|
a41c76 |
- * -2 when agent command is not supported by the agent
|
|
|
a41c76 |
- * -1 otherwise
|
|
|
a41c76 |
- */
|
|
|
a41c76 |
-int
|
|
|
a41c76 |
-qemuAgentGetFSInfoParams(qemuAgentPtr mon,
|
|
|
a41c76 |
- virTypedParameterPtr *params,
|
|
|
a41c76 |
- int *nparams, int *maxparams,
|
|
|
a41c76 |
- virDomainDefPtr vmdef)
|
|
|
a41c76 |
-{
|
|
|
a41c76 |
- int ret = -1;
|
|
|
a41c76 |
- qemuAgentFSInfoPtr *fsinfo = NULL;
|
|
|
a41c76 |
- size_t i, j;
|
|
|
a41c76 |
- int nfs;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if ((nfs = qemuAgentGetFSInfoInternal(mon, &fsinfo)) < 0)
|
|
|
a41c76 |
- return nfs;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (virTypedParamsAddUInt(params, nparams, maxparams,
|
|
|
a41c76 |
- "fs.count", nfs) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- for (i = 0; i < nfs; i++) {
|
|
|
a41c76 |
- char param_name[VIR_TYPED_PARAM_FIELD_LENGTH];
|
|
|
a41c76 |
- g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
- "fs.%zu.name", i);
|
|
|
a41c76 |
- if (virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
- param_name, fsinfo[i]->name) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
- "fs.%zu.mountpoint", i);
|
|
|
a41c76 |
- if (virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
- param_name, fsinfo[i]->mountpoint) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
- "fs.%zu.fstype", i);
|
|
|
a41c76 |
- if (virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
- param_name, fsinfo[i]->fstype) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- /* disk usage values are not returned by older guest agents, so
|
|
|
a41c76 |
- * only add the params if the value is set */
|
|
|
a41c76 |
- g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
- "fs.%zu.total-bytes", i);
|
|
|
a41c76 |
- if (fsinfo[i]->total_bytes != -1 &&
|
|
|
a41c76 |
- virTypedParamsAddULLong(params, nparams, maxparams,
|
|
|
a41c76 |
- param_name, fsinfo[i]->total_bytes) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
- "fs.%zu.used-bytes", i);
|
|
|
a41c76 |
- if (fsinfo[i]->used_bytes != -1 &&
|
|
|
a41c76 |
- virTypedParamsAddULLong(params, nparams, maxparams,
|
|
|
a41c76 |
- param_name, fsinfo[i]->used_bytes) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
- "fs.%zu.disk.count", i);
|
|
|
a41c76 |
- if (virTypedParamsAddUInt(params, nparams, maxparams,
|
|
|
a41c76 |
- param_name, fsinfo[i]->ndisks) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- for (j = 0; j < fsinfo[i]->ndisks; j++) {
|
|
|
a41c76 |
- virDomainDiskDefPtr diskdef = NULL;
|
|
|
a41c76 |
- qemuAgentDiskInfoPtr d = fsinfo[i]->disks[j];
|
|
|
a41c76 |
- /* match the disk to the target in the vm definition */
|
|
|
a41c76 |
- diskdef = virDomainDiskByAddress(vmdef,
|
|
|
a41c76 |
- &d->pci_controller,
|
|
|
a41c76 |
- d->bus,
|
|
|
a41c76 |
- d->target,
|
|
|
a41c76 |
- d->unit);
|
|
|
a41c76 |
- if (diskdef) {
|
|
|
a41c76 |
- g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
- "fs.%zu.disk.%zu.alias", i, j);
|
|
|
a41c76 |
- if (diskdef->dst &&
|
|
|
a41c76 |
- virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
- param_name, diskdef->dst) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
- "fs.%zu.disk.%zu.serial", i, j);
|
|
|
a41c76 |
- if (d->serial &&
|
|
|
a41c76 |
- virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
- param_name, d->serial) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
- "fs.%zu.disk.%zu.device", i, j);
|
|
|
a41c76 |
- if (d->devnode &&
|
|
|
a41c76 |
- virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
- param_name, d->devnode) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
- ret = nfs;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- cleanup:
|
|
|
a41c76 |
- for (i = 0; i < nfs; i++)
|
|
|
a41c76 |
- qemuAgentFSInfoFree(fsinfo[i]);
|
|
|
a41c76 |
- VIR_FREE(fsinfo);
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- return ret;
|
|
|
a41c76 |
-}
|
|
|
a41c76 |
-
|
|
|
a41c76 |
/*
|
|
|
a41c76 |
* qemuAgentGetInterfaces:
|
|
|
a41c76 |
* @mon: Agent monitor
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
|
|
|
a41c76 |
index 85e436cf68..5656fe60ff 100644
|
|
|
a41c76 |
--- a/src/qemu/qemu_agent.h
|
|
|
a41c76 |
+++ b/src/qemu/qemu_agent.h
|
|
|
a41c76 |
@@ -65,19 +65,38 @@ typedef enum {
|
|
|
a41c76 |
QEMU_AGENT_SHUTDOWN_LAST,
|
|
|
a41c76 |
} qemuAgentShutdownMode;
|
|
|
a41c76 |
|
|
|
a41c76 |
+typedef struct _qemuAgentDiskInfo qemuAgentDiskInfo;
|
|
|
a41c76 |
+typedef qemuAgentDiskInfo *qemuAgentDiskInfoPtr;
|
|
|
a41c76 |
+struct _qemuAgentDiskInfo {
|
|
|
a41c76 |
+ char *serial;
|
|
|
a41c76 |
+ virPCIDeviceAddress pci_controller;
|
|
|
a41c76 |
+ char *bus_type;
|
|
|
a41c76 |
+ unsigned int bus;
|
|
|
a41c76 |
+ unsigned int target;
|
|
|
a41c76 |
+ unsigned int unit;
|
|
|
a41c76 |
+ char *devnode;
|
|
|
a41c76 |
+};
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+typedef struct _qemuAgentFSInfo qemuAgentFSInfo;
|
|
|
a41c76 |
+typedef qemuAgentFSInfo *qemuAgentFSInfoPtr;
|
|
|
a41c76 |
+struct _qemuAgentFSInfo {
|
|
|
a41c76 |
+ char *mountpoint; /* path to mount point */
|
|
|
a41c76 |
+ char *name; /* device name in the guest (e.g. "sda1") */
|
|
|
a41c76 |
+ char *fstype; /* filesystem type */
|
|
|
a41c76 |
+ long long total_bytes;
|
|
|
a41c76 |
+ long long used_bytes;
|
|
|
a41c76 |
+ size_t ndisks;
|
|
|
a41c76 |
+ qemuAgentDiskInfoPtr *disks;
|
|
|
a41c76 |
+};
|
|
|
a41c76 |
+void qemuAgentFSInfoFree(qemuAgentFSInfoPtr info);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
int qemuAgentShutdown(qemuAgentPtr mon,
|
|
|
a41c76 |
qemuAgentShutdownMode mode);
|
|
|
a41c76 |
|
|
|
a41c76 |
int qemuAgentFSFreeze(qemuAgentPtr mon,
|
|
|
a41c76 |
const char **mountpoints, unsigned int nmountpoints);
|
|
|
a41c76 |
int qemuAgentFSThaw(qemuAgentPtr mon);
|
|
|
a41c76 |
-int qemuAgentGetFSInfo(qemuAgentPtr mon, virDomainFSInfoPtr **info,
|
|
|
a41c76 |
- virDomainDefPtr vmdef);
|
|
|
a41c76 |
-
|
|
|
a41c76 |
-int qemuAgentGetFSInfoParams(qemuAgentPtr mon,
|
|
|
a41c76 |
- virTypedParameterPtr *params,
|
|
|
a41c76 |
- int *nparams, int *maxparams,
|
|
|
a41c76 |
- virDomainDefPtr vmdef);
|
|
|
a41c76 |
+int qemuAgentGetFSInfo(qemuAgentPtr mon, qemuAgentFSInfoPtr **info);
|
|
|
a41c76 |
|
|
|
a41c76 |
int qemuAgentSuspend(qemuAgentPtr mon,
|
|
|
a41c76 |
unsigned int target);
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
|
|
|
a41c76 |
index 69e4f7264b..ac3a7ad282 100644
|
|
|
a41c76 |
--- a/src/qemu/qemu_driver.c
|
|
|
a41c76 |
+++ b/src/qemu/qemu_driver.c
|
|
|
a41c76 |
@@ -21839,6 +21839,111 @@ qemuNodeAllocPages(virConnectPtr conn,
|
|
|
a41c76 |
startCell, cellCount, add);
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
+static int
|
|
|
a41c76 |
+qemuDomainGetFSInfoAgent(virQEMUDriverPtr driver,
|
|
|
a41c76 |
+ virDomainObjPtr vm,
|
|
|
a41c76 |
+ qemuAgentFSInfoPtr **info)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ int ret = -1;
|
|
|
a41c76 |
+ qemuAgentPtr agent;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (qemuDomainObjBeginAgentJob(driver, vm,
|
|
|
a41c76 |
+ QEMU_AGENT_JOB_QUERY) < 0)
|
|
|
a41c76 |
+ return ret;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (virDomainObjCheckActive(vm) < 0)
|
|
|
a41c76 |
+ goto endjob;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!qemuDomainAgentAvailable(vm, true))
|
|
|
a41c76 |
+ goto endjob;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ agent = qemuDomainObjEnterAgent(vm);
|
|
|
a41c76 |
+ ret = qemuAgentGetFSInfo(agent, info);
|
|
|
a41c76 |
+ qemuDomainObjExitAgent(vm, agent);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ endjob:
|
|
|
a41c76 |
+ qemuDomainObjEndAgentJob(vm);
|
|
|
a41c76 |
+ return ret;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+static virDomainFSInfoPtr
|
|
|
a41c76 |
+qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent,
|
|
|
a41c76 |
+ virDomainDefPtr vmdef)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ virDomainFSInfoPtr ret = NULL;
|
|
|
a41c76 |
+ size_t i;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (VIR_ALLOC(ret) < 0)
|
|
|
a41c76 |
+ goto error;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ ret->mountpoint = g_strdup(agent->mountpoint);
|
|
|
a41c76 |
+ ret->name = g_strdup(agent->name);
|
|
|
a41c76 |
+ ret->fstype = g_strdup(agent->fstype);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (agent->disks &&
|
|
|
a41c76 |
+ VIR_ALLOC_N(ret->devAlias, agent->ndisks) < 0)
|
|
|
a41c76 |
+ goto error;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ ret->ndevAlias = agent->ndisks;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ for (i = 0; i < ret->ndevAlias; i++) {
|
|
|
a41c76 |
+ qemuAgentDiskInfoPtr agentdisk = agent->disks[i];
|
|
|
a41c76 |
+ virDomainDiskDefPtr diskDef;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!(diskDef = virDomainDiskByAddress(vmdef,
|
|
|
a41c76 |
+ &agentdisk->pci_controller,
|
|
|
a41c76 |
+ agentdisk->bus,
|
|
|
a41c76 |
+ agentdisk->target,
|
|
|
a41c76 |
+ agentdisk->unit)))
|
|
|
a41c76 |
+ continue;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ ret->devAlias[i] = g_strdup(diskDef->dst);
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return ret;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ error:
|
|
|
a41c76 |
+ virDomainFSInfoFree(ret);
|
|
|
a41c76 |
+ return NULL;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+/* Returns: 0 on success
|
|
|
a41c76 |
+ * -1 otherwise
|
|
|
a41c76 |
+ */
|
|
|
a41c76 |
+static int
|
|
|
a41c76 |
+virDomainFSInfoFormat(qemuAgentFSInfoPtr *agentinfo,
|
|
|
a41c76 |
+ int nagentinfo,
|
|
|
a41c76 |
+ virDomainDefPtr vmdef,
|
|
|
a41c76 |
+ virDomainFSInfoPtr **info)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ int ret = -1;
|
|
|
a41c76 |
+ virDomainFSInfoPtr *info_ret = NULL;
|
|
|
a41c76 |
+ size_t i;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (nagentinfo < 0)
|
|
|
a41c76 |
+ return ret;
|
|
|
a41c76 |
+ if (VIR_ALLOC_N(info_ret, nagentinfo) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ for (i = 0; i < nagentinfo; i++) {
|
|
|
a41c76 |
+ if (!(info_ret[i] = qemuAgentFSInfoToPublic(agentinfo[i], vmdef)))
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ *info = g_steal_pointer(&info_ret);
|
|
|
a41c76 |
+ ret = nagentinfo;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ cleanup:
|
|
|
a41c76 |
+ for (i = 0; i < nagentinfo; i++) {
|
|
|
a41c76 |
+ qemuAgentFSInfoFree(agentinfo[i]);
|
|
|
a41c76 |
+ /* if there was an error, free any memory we've allocated for the
|
|
|
a41c76 |
+ * return value */
|
|
|
a41c76 |
+ if (info_ret)
|
|
|
a41c76 |
+ virDomainFSInfoFree(info_ret[i]);
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+ VIR_FREE(info_ret);
|
|
|
a41c76 |
+ return ret;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
|
|
|
a41c76 |
static int
|
|
|
a41c76 |
qemuDomainGetFSInfo(virDomainPtr dom,
|
|
|
a41c76 |
@@ -21847,8 +21952,9 @@ qemuDomainGetFSInfo(virDomainPtr dom,
|
|
|
a41c76 |
{
|
|
|
a41c76 |
virQEMUDriverPtr driver = dom->conn->privateData;
|
|
|
a41c76 |
virDomainObjPtr vm;
|
|
|
a41c76 |
- qemuAgentPtr agent;
|
|
|
a41c76 |
+ qemuAgentFSInfoPtr *agentinfo = NULL;
|
|
|
a41c76 |
int ret = -1;
|
|
|
a41c76 |
+ int nfs;
|
|
|
a41c76 |
|
|
|
a41c76 |
virCheckFlags(0, ret);
|
|
|
a41c76 |
|
|
|
a41c76 |
@@ -21858,25 +21964,22 @@ qemuDomainGetFSInfo(virDomainPtr dom,
|
|
|
a41c76 |
if (virDomainGetFSInfoEnsureACL(dom->conn, vm->def) < 0)
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
|
|
|
a41c76 |
- if (qemuDomainObjBeginJobWithAgent(driver, vm,
|
|
|
a41c76 |
- QEMU_JOB_QUERY,
|
|
|
a41c76 |
- QEMU_AGENT_JOB_QUERY) < 0)
|
|
|
a41c76 |
+ if ((nfs = qemuDomainGetFSInfoAgent(driver, vm, &agentinfo)) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
|
|
|
a41c76 |
if (virDomainObjCheckActive(vm) < 0)
|
|
|
a41c76 |
goto endjob;
|
|
|
a41c76 |
|
|
|
a41c76 |
- if (!qemuDomainAgentAvailable(vm, true))
|
|
|
a41c76 |
- goto endjob;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- agent = qemuDomainObjEnterAgent(vm);
|
|
|
a41c76 |
- ret = qemuAgentGetFSInfo(agent, info, vm->def);
|
|
|
a41c76 |
- qemuDomainObjExitAgent(vm, agent);
|
|
|
a41c76 |
+ ret = virDomainFSInfoFormat(agentinfo, nfs, vm->def, info);
|
|
|
a41c76 |
|
|
|
a41c76 |
endjob:
|
|
|
a41c76 |
- qemuDomainObjEndJobWithAgent(driver, vm);
|
|
|
a41c76 |
+ qemuDomainObjEndJob(driver, vm);
|
|
|
a41c76 |
|
|
|
a41c76 |
cleanup:
|
|
|
a41c76 |
+ g_free(agentinfo);
|
|
|
a41c76 |
virDomainObjEndAPI(&vm;;
|
|
|
a41c76 |
return ret;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
@@ -22882,6 +22985,103 @@ qemuDomainGetGuestInfoCheckSupport(unsigned int *types)
|
|
|
a41c76 |
*types = *types & supportedGuestInfoTypes;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
+/* Returns: 0 on success
|
|
|
a41c76 |
+ * -1 otherwise
|
|
|
a41c76 |
+ */
|
|
|
a41c76 |
+static int
|
|
|
a41c76 |
+qemuAgentFSInfoFormatParams(qemuAgentFSInfoPtr *fsinfo,
|
|
|
a41c76 |
+ int nfs,
|
|
|
a41c76 |
+ virDomainDefPtr vmdef,
|
|
|
a41c76 |
+ virTypedParameterPtr *params,
|
|
|
a41c76 |
+ int *nparams, int *maxparams)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ int ret = -1;
|
|
|
a41c76 |
+ size_t i, j;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* FIXME: get disk target */
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (virTypedParamsAddUInt(params, nparams, maxparams,
|
|
|
a41c76 |
+ "fs.count", nfs) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ for (i = 0; i < nfs; i++) {
|
|
|
a41c76 |
+ char param_name[VIR_TYPED_PARAM_FIELD_LENGTH];
|
|
|
a41c76 |
+ g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
+ "fs.%zu.name", i);
|
|
|
a41c76 |
+ if (virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
+ param_name, fsinfo[i]->name) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+ g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
+ "fs.%zu.mountpoint", i);
|
|
|
a41c76 |
+ if (virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
+ param_name, fsinfo[i]->mountpoint) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+ g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
+ "fs.%zu.fstype", i);
|
|
|
a41c76 |
+ if (virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
+ param_name, fsinfo[i]->fstype) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* disk usage values are not returned by older guest agents, so
|
|
|
a41c76 |
+ * only add the params if the value is set */
|
|
|
a41c76 |
+ g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
+ "fs.%zu.total-bytes", i);
|
|
|
a41c76 |
+ if (fsinfo[i]->total_bytes != -1 &&
|
|
|
a41c76 |
+ virTypedParamsAddULLong(params, nparams, maxparams,
|
|
|
a41c76 |
+ param_name, fsinfo[i]->total_bytes) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
+ "fs.%zu.used-bytes", i);
|
|
|
a41c76 |
+ if (fsinfo[i]->used_bytes != -1 &&
|
|
|
a41c76 |
+ virTypedParamsAddULLong(params, nparams, maxparams,
|
|
|
a41c76 |
+ param_name, fsinfo[i]->used_bytes) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
+ "fs.%zu.disk.count", i);
|
|
|
a41c76 |
+ if (virTypedParamsAddUInt(params, nparams, maxparams,
|
|
|
a41c76 |
+ param_name, fsinfo[i]->ndisks) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+ for (j = 0; j < fsinfo[i]->ndisks; j++) {
|
|
|
a41c76 |
+ virDomainDiskDefPtr diskdef = NULL;
|
|
|
a41c76 |
+ qemuAgentDiskInfoPtr d = fsinfo[i]->disks[j];
|
|
|
a41c76 |
+ /* match the disk to the target in the vm definition */
|
|
|
a41c76 |
+ diskdef = virDomainDiskByAddress(vmdef,
|
|
|
a41c76 |
+ &d->pci_controller,
|
|
|
a41c76 |
+ d->bus,
|
|
|
a41c76 |
+ d->target,
|
|
|
a41c76 |
+ d->unit);
|
|
|
a41c76 |
+ if (diskdef) {
|
|
|
a41c76 |
+ g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
+ "fs.%zu.disk.%zu.alias", i, j);
|
|
|
a41c76 |
+ if (diskdef->dst &&
|
|
|
a41c76 |
+ virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
+ param_name, diskdef->dst) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
+ "fs.%zu.disk.%zu.serial", i, j);
|
|
|
a41c76 |
+ if (d->serial &&
|
|
|
a41c76 |
+ virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
+ param_name, d->serial) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
|
a41c76 |
+ "fs.%zu.disk.%zu.device", i, j);
|
|
|
a41c76 |
+ if (d->devnode &&
|
|
|
a41c76 |
+ virTypedParamsAddString(params, nparams, maxparams,
|
|
|
a41c76 |
+ param_name, d->devnode) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+ ret = nfs;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ cleanup:
|
|
|
a41c76 |
+ return ret;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
static int
|
|
|
a41c76 |
qemuDomainGetGuestInfo(virDomainPtr dom,
|
|
|
a41c76 |
unsigned int types,
|
|
|
a41c76 |
@@ -22897,6 +23097,9 @@ qemuDomainGetGuestInfo(virDomainPtr dom,
|
|
|
a41c76 |
g_autofree char *hostname = NULL;
|
|
|
a41c76 |
unsigned int supportedTypes = types;
|
|
|
a41c76 |
int rc;
|
|
|
a41c76 |
+ int nfs = 0;
|
|
|
a41c76 |
+ qemuAgentFSInfoPtr *agentfsinfo = NULL;
|
|
|
a41c76 |
+ size_t i;
|
|
|
a41c76 |
|
|
|
a41c76 |
virCheckFlags(0, -1);
|
|
|
a41c76 |
qemuDomainGetGuestInfoCheckSupport(&supportedTypes);
|
|
|
a41c76 |
@@ -22907,13 +23110,12 @@ qemuDomainGetGuestInfo(virDomainPtr dom,
|
|
|
a41c76 |
if (virDomainGetGuestInfoEnsureACL(dom->conn, vm->def) < 0)
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
|
|
|
a41c76 |
- if (qemuDomainObjBeginJobWithAgent(driver, vm,
|
|
|
a41c76 |
- QEMU_JOB_QUERY,
|
|
|
a41c76 |
- QEMU_AGENT_JOB_QUERY) < 0)
|
|
|
a41c76 |
+ if (qemuDomainObjBeginAgentJob(driver, vm,
|
|
|
a41c76 |
+ QEMU_AGENT_JOB_QUERY) < 0)
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
|
|
|
a41c76 |
if (!qemuDomainAgentAvailable(vm, true))
|
|
|
a41c76 |
- goto endjob;
|
|
|
a41c76 |
+ goto endagentjob;
|
|
|
a41c76 |
|
|
|
a41c76 |
agent = qemuDomainObjEnterAgent(vm);
|
|
|
a41c76 |
|
|
|
a41c76 |
@@ -22948,7 +23150,7 @@ qemuDomainGetGuestInfo(virDomainPtr dom,
|
|
|
a41c76 |
}
|
|
|
a41c76 |
}
|
|
|
a41c76 |
if (supportedTypes & VIR_DOMAIN_GUEST_INFO_FILESYSTEM) {
|
|
|
a41c76 |
- rc = qemuAgentGetFSInfoParams(agent, params, nparams, &maxparams, vm->def);
|
|
|
a41c76 |
+ rc = nfs = qemuAgentGetFSInfo(agent, &agentfsinfo);
|
|
|
a41c76 |
if (rc < 0 && !(rc == -2 && types == 0))
|
|
|
a41c76 |
goto exitagent;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
@@ -22958,10 +23160,29 @@ qemuDomainGetGuestInfo(virDomainPtr dom,
|
|
|
a41c76 |
exitagent:
|
|
|
a41c76 |
qemuDomainObjExitAgent(vm, agent);
|
|
|
a41c76 |
|
|
|
a41c76 |
+ endagentjob:
|
|
|
a41c76 |
+ qemuDomainObjEndAgentJob(vm);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (nfs > 0) {
|
|
|
a41c76 |
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (virDomainObjCheckActive(vm) < 0)
|
|
|
a41c76 |
+ goto endjob;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* we need to convert the agent fsinfo struct to parameters and match
|
|
|
a41c76 |
+ * it to the vm disk target */
|
|
|
a41c76 |
+ qemuAgentFSInfoFormatParams(agentfsinfo, nfs, vm->def, params, nparams, &maxparams);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
endjob:
|
|
|
a41c76 |
- qemuDomainObjEndJobWithAgent(driver, vm);
|
|
|
a41c76 |
+ qemuDomainObjEndJob(driver, vm);
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
|
|
|
a41c76 |
cleanup:
|
|
|
a41c76 |
+ for (i = 0; i < nfs; i++)
|
|
|
a41c76 |
+ qemuAgentFSInfoFree(agentfsinfo[i]);
|
|
|
a41c76 |
+ VIR_FREE(agentfsinfo);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
virDomainObjEndAPI(&vm;;
|
|
|
a41c76 |
return ret;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
|
|
|
a41c76 |
index 644dc9d08b..a45ce4f44a 100644
|
|
|
a41c76 |
--- a/tests/qemuagenttest.c
|
|
|
a41c76 |
+++ b/tests/qemuagenttest.c
|
|
|
a41c76 |
@@ -247,14 +247,14 @@ testQemuAgentGetFSInfo(const void *data)
|
|
|
a41c76 |
virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
|
|
|
a41c76 |
qemuMonitorTestPtr test = NULL;
|
|
|
a41c76 |
virDomainDefPtr def = NULL;
|
|
|
a41c76 |
- virDomainFSInfoPtr *info = NULL;
|
|
|
a41c76 |
+ qemuAgentFSInfoPtr *info = NULL;
|
|
|
a41c76 |
int ret = -1, ninfo = 0, i;
|
|
|
a41c76 |
|
|
|
a41c76 |
if (testQemuAgentGetFSInfoCommon(xmlopt, &test, &def) < 0)
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
|
|
|
a41c76 |
if ((ninfo = qemuAgentGetFSInfo(qemuMonitorTestGetAgent(test),
|
|
|
a41c76 |
- &info, def)) < 0)
|
|
|
a41c76 |
+ &info)) < 0)
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
|
|
|
a41c76 |
if (ninfo != 3) {
|
|
|
a41c76 |
@@ -266,35 +266,48 @@ testQemuAgentGetFSInfo(const void *data)
|
|
|
a41c76 |
if (STRNEQ(info[2]->name, "sda1") ||
|
|
|
a41c76 |
STRNEQ(info[2]->mountpoint, "/") ||
|
|
|
a41c76 |
STRNEQ(info[2]->fstype, "ext4") ||
|
|
|
a41c76 |
- info[2]->ndevAlias != 1 ||
|
|
|
a41c76 |
- !info[2]->devAlias || !info[2]->devAlias[0] ||
|
|
|
a41c76 |
- STRNEQ(info[2]->devAlias[0], "hdc")) {
|
|
|
a41c76 |
+ info[2]->ndisks != 1 ||
|
|
|
a41c76 |
+ !info[2]->disks || !info[2]->disks[0]) {
|
|
|
a41c76 |
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
- "unexpected filesystems information returned for sda1 (%s,%s)",
|
|
|
a41c76 |
- info[2]->name, info[2]->devAlias ? info[2]->devAlias[0] : "null");
|
|
|
a41c76 |
+ "unexpected filesystems information returned for sda1 (%s)",
|
|
|
a41c76 |
+ info[2]->name);
|
|
|
a41c76 |
ret = -1;
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
if (STRNEQ(info[1]->name, "dm-1") ||
|
|
|
a41c76 |
STRNEQ(info[1]->mountpoint, "/opt") ||
|
|
|
a41c76 |
STRNEQ(info[1]->fstype, "vfat") ||
|
|
|
a41c76 |
- info[1]->ndevAlias != 2 ||
|
|
|
a41c76 |
- !info[1]->devAlias || !info[1]->devAlias[0] || !info[1]->devAlias[1] ||
|
|
|
a41c76 |
- STRNEQ(info[1]->devAlias[0], "vda") ||
|
|
|
a41c76 |
- STRNEQ(info[1]->devAlias[1], "vdb")) {
|
|
|
a41c76 |
+ info[1]->ndisks != 2 ||
|
|
|
a41c76 |
+ !info[1]->disks || !info[1]->disks[0] || !info[1]->disks[1] ||
|
|
|
a41c76 |
+ STRNEQ(info[1]->disks[0]->bus_type, "virtio") ||
|
|
|
a41c76 |
+ info[1]->disks[0]->bus != 0 ||
|
|
|
a41c76 |
+ info[1]->disks[0]->target != 0 ||
|
|
|
a41c76 |
+ info[1]->disks[0]->unit != 0 ||
|
|
|
a41c76 |
+ info[1]->disks[0]->pci_controller.domain != 0 ||
|
|
|
a41c76 |
+ info[1]->disks[0]->pci_controller.bus != 0 ||
|
|
|
a41c76 |
+ info[1]->disks[0]->pci_controller.slot != 6 ||
|
|
|
a41c76 |
+ info[1]->disks[0]->pci_controller.function != 0 ||
|
|
|
a41c76 |
+ STRNEQ(info[1]->disks[1]->bus_type, "virtio") ||
|
|
|
a41c76 |
+ info[1]->disks[1]->bus != 0 ||
|
|
|
a41c76 |
+ info[1]->disks[1]->target != 0 ||
|
|
|
a41c76 |
+ info[1]->disks[1]->unit != 0 ||
|
|
|
a41c76 |
+ info[1]->disks[1]->pci_controller.domain != 0 ||
|
|
|
a41c76 |
+ info[1]->disks[1]->pci_controller.bus != 0 ||
|
|
|
a41c76 |
+ info[1]->disks[1]->pci_controller.slot != 7 ||
|
|
|
a41c76 |
+ info[1]->disks[1]->pci_controller.function != 0) {
|
|
|
a41c76 |
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
- "unexpected filesystems information returned for dm-1 (%s,%s)",
|
|
|
a41c76 |
- info[0]->name, info[0]->devAlias ? info[0]->devAlias[0] : "null");
|
|
|
a41c76 |
+ "unexpected filesystems information returned for dm-1 (%s)",
|
|
|
a41c76 |
+ info[0]->name);
|
|
|
a41c76 |
ret = -1;
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
if (STRNEQ(info[0]->name, "sdb1") ||
|
|
|
a41c76 |
STRNEQ(info[0]->mountpoint, "/mnt/disk") ||
|
|
|
a41c76 |
STRNEQ(info[0]->fstype, "xfs") ||
|
|
|
a41c76 |
- info[0]->ndevAlias != 0 || info[0]->devAlias) {
|
|
|
a41c76 |
+ info[0]->ndisks != 0 || info[0]->disks) {
|
|
|
a41c76 |
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
- "unexpected filesystems information returned for sdb1 (%s,%s)",
|
|
|
a41c76 |
- info[0]->name, info[0]->devAlias ? info[0]->devAlias[0] : "null");
|
|
|
a41c76 |
+ "unexpected filesystems information returned for sdb1 (%s)",
|
|
|
a41c76 |
+ info[0]->name);
|
|
|
a41c76 |
ret = -1;
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
@@ -313,7 +326,7 @@ testQemuAgentGetFSInfo(const void *data)
|
|
|
a41c76 |
"}") < 0)
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
|
|
|
a41c76 |
- if (qemuAgentGetFSInfo(qemuMonitorTestGetAgent(test), &info, def) != -1) {
|
|
|
a41c76 |
+ if (qemuAgentGetFSInfo(qemuMonitorTestGetAgent(test), &info) >= 0) {
|
|
|
a41c76 |
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
a41c76 |
"agent get-fsinfo command should have failed");
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
@@ -323,159 +336,13 @@ testQemuAgentGetFSInfo(const void *data)
|
|
|
a41c76 |
|
|
|
a41c76 |
cleanup:
|
|
|
a41c76 |
for (i = 0; i < ninfo; i++)
|
|
|
a41c76 |
- virDomainFSInfoFree(info[i]);
|
|
|
a41c76 |
+ qemuAgentFSInfoFree(info[i]);
|
|
|
a41c76 |
VIR_FREE(info);
|
|
|
a41c76 |
virDomainDefFree(def);
|
|
|
a41c76 |
qemuMonitorTestFree(test);
|
|
|
a41c76 |
return ret;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
-static int
|
|
|
a41c76 |
-testQemuAgentGetFSInfoParams(const void *data)
|
|
|
a41c76 |
-{
|
|
|
a41c76 |
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
|
|
|
a41c76 |
- qemuMonitorTestPtr test = NULL;
|
|
|
a41c76 |
- virDomainDefPtr def = NULL;
|
|
|
a41c76 |
- virTypedParameterPtr params = NULL;
|
|
|
a41c76 |
- int nparams = 0, maxparams = 0;
|
|
|
a41c76 |
- int ret = -1;
|
|
|
a41c76 |
- unsigned int count;
|
|
|
a41c76 |
- const char *name, *mountpoint, *fstype, *alias, *serial;
|
|
|
a41c76 |
- unsigned int diskcount;
|
|
|
a41c76 |
- unsigned long long bytesused, bytestotal;
|
|
|
a41c76 |
- const char *alias2;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (testQemuAgentGetFSInfoCommon(xmlopt, &test, &def) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (qemuAgentGetFSInfoParams(qemuMonitorTestGetAgent(test),
|
|
|
a41c76 |
- ¶ms, &nparams, &maxparams, def) < 0) {
|
|
|
a41c76 |
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
a41c76 |
- "Failed to execute qemuAgentGetFSInfoParams()");
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (virTypedParamsGetUInt(params, nparams, "fs.count", &count) < 0) {
|
|
|
a41c76 |
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
a41c76 |
- "expected filesystem count");
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (count != 3) {
|
|
|
a41c76 |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
- "expected 3 filesystems information, got %d", count);
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (virTypedParamsGetString(params, nparams, "fs.2.name", &name) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.2.mountpoint", &mountpoint) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.2.fstype", &fstype) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetULLong(params, nparams, "fs.2.used-bytes", &bytesused) <= 0 ||
|
|
|
a41c76 |
- virTypedParamsGetULLong(params, nparams, "fs.2.total-bytes", &bytestotal) <= 0 ||
|
|
|
a41c76 |
- virTypedParamsGetUInt(params, nparams, "fs.2.disk.count", &diskcount) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.2.disk.0.alias", &alias) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.2.disk.0.serial", &serial) < 0) {
|
|
|
a41c76 |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
- "Missing an expected parameter for sda1 (%s,%s)",
|
|
|
a41c76 |
- name, alias);
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (STRNEQ(name, "sda1") ||
|
|
|
a41c76 |
- STRNEQ(mountpoint, "/") ||
|
|
|
a41c76 |
- STRNEQ(fstype, "ext4") ||
|
|
|
a41c76 |
- bytesused != 229019648 ||
|
|
|
a41c76 |
- bytestotal != 952840192 ||
|
|
|
a41c76 |
- diskcount != 1 ||
|
|
|
a41c76 |
- STRNEQ(alias, "hdc") ||
|
|
|
a41c76 |
- STRNEQ(serial, "ARBITRARYSTRING")) {
|
|
|
a41c76 |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
- "unexpected filesystems information returned for sda1 (%s,%s)",
|
|
|
a41c76 |
- name, alias);
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (virTypedParamsGetString(params, nparams, "fs.1.name", &name) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.1.mountpoint", &mountpoint) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.1.fstype", &fstype) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetULLong(params, nparams, "fs.1.used-bytes", &bytesused) == 1 ||
|
|
|
a41c76 |
- virTypedParamsGetULLong(params, nparams, "fs.1.total-bytes", &bytestotal) == 1 ||
|
|
|
a41c76 |
- virTypedParamsGetUInt(params, nparams, "fs.1.disk.count", &diskcount) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.1.disk.0.alias", &alias) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.1.disk.1.alias", &alias2) < 0) {
|
|
|
a41c76 |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
- "Incorrect parameters for dm-1 (%s,%s)",
|
|
|
a41c76 |
- name, alias);
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
- if (STRNEQ(name, "dm-1") ||
|
|
|
a41c76 |
- STRNEQ(mountpoint, "/opt") ||
|
|
|
a41c76 |
- STRNEQ(fstype, "vfat") ||
|
|
|
a41c76 |
- diskcount != 2 ||
|
|
|
a41c76 |
- STRNEQ(alias, "vda") ||
|
|
|
a41c76 |
- STRNEQ(alias2, "vdb")) {
|
|
|
a41c76 |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
- "unexpected filesystems information returned for dm-1 (%s,%s)",
|
|
|
a41c76 |
- name, alias);
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- alias = NULL;
|
|
|
a41c76 |
- if (virTypedParamsGetString(params, nparams, "fs.0.name", &name) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.0.mountpoint", &mountpoint) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.0.fstype", &fstype) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetULLong(params, nparams, "fs.0.used-bytes", &bytesused) == 1 ||
|
|
|
a41c76 |
- virTypedParamsGetULLong(params, nparams, "fs.0.total-bytes", &bytestotal) == 1 ||
|
|
|
a41c76 |
- virTypedParamsGetUInt(params, nparams, "fs.0.disk.count", &diskcount) < 0 ||
|
|
|
a41c76 |
- virTypedParamsGetString(params, nparams, "fs.0.disk.0.alias", &alias) == 1) {
|
|
|
a41c76 |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
- "Incorrect parameters for sdb1 (%s,%s)",
|
|
|
a41c76 |
- name, alias);
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (STRNEQ(name, "sdb1") ||
|
|
|
a41c76 |
- STRNEQ(mountpoint, "/mnt/disk") ||
|
|
|
a41c76 |
- STRNEQ(fstype, "xfs") ||
|
|
|
a41c76 |
- diskcount != 0 ||
|
|
|
a41c76 |
- alias != NULL) {
|
|
|
a41c76 |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
- "unexpected filesystems information returned for sdb1 (%s,%s)",
|
|
|
a41c76 |
- name, alias);
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (qemuMonitorTestAddItem(test, "guest-get-fsinfo",
|
|
|
a41c76 |
- "{\"error\":"
|
|
|
a41c76 |
- " {\"class\":\"CommandDisabled\","
|
|
|
a41c76 |
- " \"desc\":\"The command guest-get-fsinfo "
|
|
|
a41c76 |
- "has been disabled for "
|
|
|
a41c76 |
- "this instance\","
|
|
|
a41c76 |
- " \"data\":{\"name\":\"guest-get-fsinfo\"}"
|
|
|
a41c76 |
- " }"
|
|
|
a41c76 |
- "}") < 0)
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- if (qemuAgentGetFSInfoParams(qemuMonitorTestGetAgent(test), ¶ms,
|
|
|
a41c76 |
- &nparams, &maxparams, def) != -2) {
|
|
|
a41c76 |
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
a41c76 |
- "agent get-fsinfo command should have failed");
|
|
|
a41c76 |
- goto cleanup;
|
|
|
a41c76 |
- }
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- ret = 0;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- cleanup:
|
|
|
a41c76 |
- virTypedParamsFree(params, nparams);
|
|
|
a41c76 |
- virDomainDefFree(def);
|
|
|
a41c76 |
- qemuMonitorTestFree(test);
|
|
|
a41c76 |
- return ret;
|
|
|
a41c76 |
-}
|
|
|
a41c76 |
-
|
|
|
a41c76 |
-
|
|
|
a41c76 |
static int
|
|
|
a41c76 |
testQemuAgentSuspend(const void *data)
|
|
|
a41c76 |
{
|
|
|
a41c76 |
@@ -1438,7 +1305,6 @@ mymain(void)
|
|
|
a41c76 |
DO_TEST(FSFreeze);
|
|
|
a41c76 |
DO_TEST(FSThaw);
|
|
|
a41c76 |
DO_TEST(FSTrim);
|
|
|
a41c76 |
- DO_TEST(GetFSInfoParams);
|
|
|
a41c76 |
DO_TEST(GetFSInfo);
|
|
|
a41c76 |
DO_TEST(Suspend);
|
|
|
a41c76 |
DO_TEST(Shutdown);
|
|
|
a41c76 |
--
|
|
|
a41c76 |
2.25.0
|
|
|
a41c76 |
|