[libvirt] [PATCHv3 0/3] query-cpu-model-baseline QMP command
by Chris Venteicher
This is part of resolution of: https://bugzilla.redhat.com/show_bug.cgi?id=1511999
Signed-off-by: Chris Venteicher <cventeic(a)redhat.com>
diff to v1:
- Replaced c++ style comments with c style
- qemuMonitorJSONGetCPUModelInfo{ToJSON,FromJSON} use To/From form
- qemuMonitorJSONGetCPUModelInfo{ToJSON,FromJSON} return pointers not integers
- VIR_STEAL_PTR form used
- switch statement uses virReportEnumRangeError
- qemuMonitorJSONHasError(reply, "GenericError") treated as no info, not fatal error
- virJSONValueFree(cpu_props) during error case
diff to v2:
- qemuMonitorJSONGetCPUModelInfo{ToJSON,FromJSON}
works on {"name": "IvyBridge", "props": {}}
rather than {"model": {"name": "IvyBridge", "props": {}}}
- additional cleanups and fixes
Chris Venteicher (3):
qemu_monitor_json: Populate CPUModelInfo struct from json
qemu_monitor_json: Build Json CPU Model Info
qemu_monitor: query-cpu-model-baseline QMP command
src/qemu/qemu_monitor.c | 13 ++++
src/qemu/qemu_monitor.h | 5 ++
src/qemu/qemu_monitor_json.c | 179 +++++++++++++++++++++++++++++++++++++------
src/qemu/qemu_monitor_json.h | 7 ++
4 files changed, 182 insertions(+), 22 deletions(-)
--
2.14.1
6 years, 8 months
[libvirt] [PATCH] util: Clean up consumers of virJSONValueArraySize
by John Ferlan
Rather than have virJSONValueArraySize return a -1 when the input
is not an array and then splat an error message, let's check for
an array before calling and then change the return to be a size_t
instead of ssize_t.
That means using the helper virJSONValueIsArray as well as using a
more generic error message such as "Malformed <something> array".
In some cases we can remove stack variables and when we cannot,
those variables should be size_t not ssize_t. Alter a few references
of if (!value) to be if (value == 0) instead as well.
Some callers can already assume an array is being worked on based
on the previous call, so there's less to do.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
Based off a review of the Coverity work from Peter:
https://www.redhat.com/archives/libvir-list/2018-April/msg01613.html
src/locking/lock_daemon.c | 7 ++--
src/logging/log_handler.c | 7 ++--
src/network/bridge_driver.c | 7 ++--
src/qemu/qemu_agent.c | 35 ++++++++++--------
src/qemu/qemu_monitor_json.c | 85 ++++++++++++++++++++-----------------------
src/rpc/virnetdaemon.c | 7 +---
src/rpc/virnetserver.c | 15 +++-----
src/rpc/virnetserverservice.c | 7 ++--
src/util/virjson.c | 5 +--
src/util/virjson.h | 2 +-
src/util/virlockspace.c | 16 ++++----
src/util/virstoragefile.c | 3 +-
tests/testutilsqemuschema.c | 18 +++------
tools/nss/libvirt_nss.c | 3 +-
14 files changed, 97 insertions(+), 120 deletions(-)
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index 7afff42246..78c33bd29c 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -248,7 +248,6 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged)
virJSONValuePtr child;
virJSONValuePtr lockspaces;
size_t i;
- ssize_t n;
const char *serverNames[] = { "virtlockd" };
if (VIR_ALLOC(lockd) < 0)
@@ -281,13 +280,13 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged)
goto error;
}
- if ((n = virJSONValueArraySize(lockspaces)) < 0) {
+ if (!virJSONValueIsArray(lockspaces)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Malformed lockspaces data from JSON file"));
+ _("Malformed lockspaces array"));
goto error;
}
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(lockspaces); i++) {
virLockSpacePtr lockspace;
child = virJSONValueArrayGet(lockspaces, i);
diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c
index 40dfa8ecae..5364e06dff 100644
--- a/src/logging/log_handler.c
+++ b/src/logging/log_handler.c
@@ -292,7 +292,6 @@ virLogHandlerNewPostExecRestart(virJSONValuePtr object,
{
virLogHandlerPtr handler;
virJSONValuePtr files;
- ssize_t n;
size_t i;
if (!(handler = virLogHandlerNew(privileged,
@@ -308,13 +307,13 @@ virLogHandlerNewPostExecRestart(virJSONValuePtr object,
goto error;
}
- if ((n = virJSONValueArraySize(files)) < 0) {
+ if (!virJSONValueIsArray(files)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Malformed files data from JSON file"));
+ _("Malformed files array"));
goto error;
}
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(files); i++) {
virLogHandlerLogFilePtr file;
virJSONValuePtr child = virJSONValueArrayGet(files, i);
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 2e9191f75d..fa9ebe2d68 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -4124,7 +4124,7 @@ networkGetDHCPLeases(virNetworkPtr net,
size_t i, j;
size_t nleases = 0;
int rv = -1;
- ssize_t size = 0;
+ size_t size = 0;
int custom_lease_file_len = 0;
bool need_results = !!leases;
long long currtime = 0;
@@ -4179,11 +4179,12 @@ networkGetDHCPLeases(virNetworkPtr net,
goto error;
}
- if ((size = virJSONValueArraySize(leases_array)) < 0) {
+ if (!virJSONValueIsArray(leases_array)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("couldn't fetch array of leases"));
+ _("Malformed lease_entries array"));
goto error;
}
+ size = virJSONValueArraySize(leases_array);
}
currtime = (long long) time(NULL);
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 488a19d4a6..ef869bf15e 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1490,7 +1490,7 @@ qemuAgentGetVCPUs(qemuAgentPtr mon,
virJSONValuePtr cmd;
virJSONValuePtr reply = NULL;
virJSONValuePtr data = NULL;
- ssize_t ndata;
+ size_t ndata;
if (!(cmd = qemuAgentMakeCommand("guest-get-vcpus", NULL)))
return -1;
@@ -1505,6 +1505,12 @@ qemuAgentGetVCPUs(qemuAgentPtr mon,
goto cleanup;
}
+ if (!virJSONValueIsArray(data)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Malformed guest-get-vcpus data array"));
+ goto cleanup;
+ }
+
ndata = virJSONValueArraySize(data);
if (VIR_ALLOC_N(*info, ndata) < 0)
@@ -1869,15 +1875,14 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, virDomainFSInfoPtr **info,
goto cleanup;
}
- if (virJSONValueGetType(data) != VIR_JSON_TYPE_ARRAY) {
+ if (!virJSONValueIsArray(data)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("guest-get-fsinfo return information was not "
- "an array"));
+ _("Malformed guest-get-fsinfo data array"));
goto cleanup;
}
ndata = virJSONValueArraySize(data);
- if (!ndata) {
+ if (ndata == 0) {
ret = 0;
*info = NULL;
goto cleanup;
@@ -1928,14 +1933,14 @@ qemuAgentGetFSInfo(qemuAgentPtr mon, virDomainFSInfoPtr **info,
goto cleanup;
}
- if (virJSONValueGetType(entry) != VIR_JSON_TYPE_ARRAY) {
+ if (!virJSONValueIsArray(entry)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("guest-get-fsinfo 'disk' data was not an array"));
+ _("Malformed guest-get-fsinfo 'disk' data array"));
goto cleanup;
}
ndisk = virJSONValueArraySize(entry);
- if (!ndisk)
+ if (ndisk == 0)
continue;
if (VIR_ALLOC_N(info_ret[i]->devAlias, ndisk) < 0)
goto cleanup;
@@ -2035,7 +2040,6 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
{
int ret = -1;
size_t i, j;
- ssize_t size = -1;
virJSONValuePtr cmd = NULL;
virJSONValuePtr reply = NULL;
virJSONValuePtr ret_array = NULL;
@@ -2065,17 +2069,16 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
goto cleanup;
}
- if ((size = virJSONValueArraySize(ret_array)) < 0) {
+ if (!virJSONValueIsArray(ret_array)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("qemu agent didn't return an array of interfaces"));
goto cleanup;
}
- for (i = 0; i < size; i++) {
+ for (i = 0; i < virJSONValueArraySize(ret_array); i++) {
virJSONValuePtr tmp_iface = virJSONValueArrayGet(ret_array, i);
virJSONValuePtr ip_addr_arr = NULL;
const char *hwaddr, *ifname_s, *name = NULL;
- ssize_t ip_addr_arr_size;
virDomainInterfacePtr iface = NULL;
/* Shouldn't happen but doesn't hurt to check neither */
@@ -2131,14 +2134,16 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
if (!ip_addr_arr)
continue;
- if ((ip_addr_arr_size = virJSONValueArraySize(ip_addr_arr)) < 0)
- /* Mmm, empty 'ip-address'? */
+ if (!virJSONValueIsArray(ip_addr_arr)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Malformed ip-addresses array"));
goto error;
+ }
/* If current iface already exists, continue with the count */
addrs_count = iface->naddrs;
- for (j = 0; j < ip_addr_arr_size; j++) {
+ for (j = 0; j < virJSONValueArraySize(ip_addr_arr); j++) {
const char *type, *addr;
virJSONValuePtr ip_addr_obj = virJSONValueArrayGet(ip_addr_arr, j);
virDomainIPAddressPtr ip_addr;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 24d37eb41d..98aec3ff10 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1627,9 +1627,9 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
struct qemuMonitorQueryCpusEntry *cpus = NULL;
int ret = -1;
size_t i;
- ssize_t ncpus;
+ size_t ncpus;
- if ((ncpus = virJSONValueArraySize(data)) <= 0)
+ if ((ncpus = virJSONValueArraySize(data)) == 0)
return -2;
if (VIR_ALLOC_N(cpus, ncpus) < 0)
@@ -3595,7 +3595,7 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr msg,
int ret = -1;
const char *tmp;
virJSONValuePtr returnArray, entry, table, element;
- ssize_t nTable;
+ size_t nTable;
size_t i;
virNetDevRxFilterPtr fil = virNetDevRxFilterNew();
@@ -3656,12 +3656,13 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr msg,
goto cleanup;
}
if ((!(table = virJSONValueObjectGet(entry, "unicast-table"))) ||
- ((nTable = virJSONValueArraySize(table)) < 0)) {
+ (!virJSONValueIsArray(table))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing or invalid 'unicast-table' array "
"in query-rx-filter response"));
goto cleanup;
}
+ nTable = virJSONValueArraySize(table);
if (VIR_ALLOC_N(fil->unicast.table, nTable))
goto cleanup;
for (i = 0; i < nTable; i++) {
@@ -3697,12 +3698,13 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr msg,
goto cleanup;
}
if ((!(table = virJSONValueObjectGet(entry, "multicast-table"))) ||
- ((nTable = virJSONValueArraySize(table)) < 0)) {
+ (!virJSONValueIsArray(table))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing or invalid 'multicast-table' array "
"in query-rx-filter response"));
goto cleanup;
}
+ nTable = virJSONValueArraySize(table);
if (VIR_ALLOC_N(fil->multicast.table, nTable))
goto cleanup;
for (i = 0; i < nTable; i++) {
@@ -3731,12 +3733,13 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr msg,
goto cleanup;
}
if ((!(table = virJSONValueObjectGet(entry, "vlan-table"))) ||
- ((nTable = virJSONValueArraySize(table)) < 0)) {
+ (!virJSONValueIsArray(table))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing or invalid 'vlan-table' array "
"in query-rx-filter response"));
goto cleanup;
}
+ nTable = virJSONValueArraySize(table);
if (VIR_ALLOC_N(fil->vlan.table, nTable))
goto cleanup;
for (i = 0; i < nTable; i++) {
@@ -4575,7 +4578,7 @@ qemuMonitorJSONGetAllBlockJobInfo(qemuMonitorPtr mon)
virJSONValuePtr cmd = NULL;
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
- ssize_t nr_results;
+ size_t nr_results;
size_t i;
virHashTablePtr blockJobs = NULL;
@@ -4591,12 +4594,7 @@ qemuMonitorJSONGetAllBlockJobInfo(qemuMonitorPtr mon)
goto cleanup;
}
- if ((nr_results = virJSONValueArraySize(data)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("unable to determine array size"));
- goto cleanup;
- }
-
+ nr_results = virJSONValueArraySize(data);
if (!(blockJobs = virHashCreate(nr_results, virHashValueFree)))
goto cleanup;
@@ -5114,7 +5112,7 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
qemuMonitorMachineInfoPtr *infolist = NULL;
- ssize_t n = 0;
+ size_t n = 0;
size_t i;
*machines = NULL;
@@ -5206,7 +5204,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
qemuMonitorCPUDefInfoPtr *cpulist = NULL;
- int n = 0;
+ size_t n = 0;
size_t i;
*cpus = NULL;
@@ -5257,7 +5255,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
if (virJSONValueObjectHasKey(child, "unavailable-features")) {
virJSONValuePtr blockers;
size_t j;
- int len;
+ size_t len;
blockers = virJSONValueObjectGetArray(child,
"unavailable-features");
@@ -5494,7 +5492,7 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
char **commandlist = NULL;
- ssize_t n = 0;
+ size_t n = 0;
size_t i;
*commands = NULL;
@@ -5550,7 +5548,7 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
char **eventlist = NULL;
- ssize_t n = 0;
+ size_t n = 0;
size_t i;
*events = NULL;
@@ -5614,7 +5612,7 @@ qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon,
virJSONValuePtr data = NULL;
virJSONValuePtr array = NULL;
char **paramlist = NULL;
- ssize_t n = 0;
+ size_t n = 0;
size_t i;
*params = NULL;
@@ -5646,17 +5644,17 @@ qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon,
"return data"));
goto cleanup;
}
- qemuMonitorSetOptions(mon, array);
- }
- if ((n = virJSONValueArraySize(array)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-command-line-options reply data was not "
- "an array"));
- goto cleanup;
+ if (!virJSONValueIsArray(array)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Malformed query-cmmand-line-options array"));
+ goto cleanup;
+ }
+
+ qemuMonitorSetOptions(mon, array);
}
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(array); i++) {
virJSONValuePtr child = virJSONValueArrayGet(array, i);
const char *tmp;
@@ -5681,12 +5679,12 @@ qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon,
if (found)
*found = true;
- if ((n = virJSONValueArraySize(data)) < 0) {
+ if (!virJSONValueIsArray(data)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("query-command-line-options parameter data was not "
- "an array"));
+ _("Malformed query-cmmand-line-options parameters array"));
goto cleanup;
}
+ n = virJSONValueArraySize(data);
/* null-terminated list */
if (VIR_ALLOC_N(paramlist, n + 1) < 0)
@@ -5776,7 +5774,7 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
char **typelist = NULL;
- ssize_t n = 0;
+ size_t n = 0;
size_t i;
*types = NULL;
@@ -5832,7 +5830,7 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitorPtr mon,
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
qemuMonitorJSONListPathPtr *pathlist = NULL;
- ssize_t n = 0;
+ size_t n = 0;
size_t i;
*paths = NULL;
@@ -6062,7 +6060,7 @@ int qemuMonitorJSONGetDeviceProps(qemuMonitorPtr mon,
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
char **proplist = NULL;
- ssize_t n = 0;
+ size_t n = 0;
size_t i;
*props = NULL;
@@ -6161,7 +6159,7 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
virJSONValuePtr caps;
char **list = NULL;
size_t i;
- ssize_t n;
+ size_t n;
*capabilities = NULL;
@@ -6272,7 +6270,7 @@ qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
virJSONValuePtr caps;
virGICCapability *list = NULL;
size_t i;
- ssize_t n;
+ size_t n;
*capabilities = NULL;
@@ -6493,7 +6491,7 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
char **list = NULL;
- ssize_t n = 0;
+ size_t n = 0;
size_t i;
*array = NULL;
@@ -6890,14 +6888,11 @@ qemuMonitorJSONParseCPUx86Features(virJSONValuePtr data)
virCPUDataPtr cpudata = NULL;
virCPUx86CPUID cpuid;
size_t i;
- ssize_t n;
-
- n = virJSONValueArraySize(data);
if (!(cpudata = virCPUDataNew(VIR_ARCH_X86_64)))
goto error;
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(data); i++) {
if (qemuMonitorJSONParseCPUx86FeatureWord(virJSONValueArrayGet(data, i),
&cpuid) < 0 ||
virCPUx86DataAddCPUID(cpudata, &cpuid) < 0)
@@ -6958,7 +6953,7 @@ qemuMonitorJSONCheckCPUx86(qemuMonitorPtr mon)
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
size_t i;
- ssize_t n;
+ size_t n;
int ret = -1;
if (!(cmd = qemuMonitorJSONMakeCommand("qom-list",
@@ -7096,7 +7091,7 @@ qemuMonitorJSONGetIOThreads(qemuMonitorPtr mon,
virJSONValuePtr reply = NULL;
virJSONValuePtr data;
qemuMonitorIOThreadInfoPtr *infolist = NULL;
- ssize_t n = 0;
+ size_t n = 0;
size_t i;
*iothreads = NULL;
@@ -7178,7 +7173,6 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
virJSONValuePtr reply = NULL;
virJSONValuePtr data = NULL;
qemuMonitorMemoryDeviceInfoPtr meminfo = NULL;
- ssize_t n;
size_t i;
if (!(cmd = qemuMonitorJSONMakeCommand("query-memory-devices", NULL)))
@@ -7196,9 +7190,8 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
goto cleanup;
data = virJSONValueObjectGetArray(reply, "return");
- n = virJSONValueArraySize(data);
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(data); i++) {
virJSONValuePtr elem = virJSONValueArrayGet(data, i);
const char *type;
@@ -7664,7 +7657,7 @@ qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon,
size_t *nentries)
{
struct qemuMonitorQueryHotpluggableCpusEntry *info = NULL;
- ssize_t ninfo = 0;
+ size_t ninfo = 0;
int ret = -1;
size_t i;
virJSONValuePtr data;
diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c
index eb0b822545..31b687de12 100644
--- a/src/rpc/virnetdaemon.c
+++ b/src/rpc/virnetdaemon.c
@@ -322,12 +322,7 @@ virNetDaemonNewPostExecRestart(virJSONValuePtr object,
goto error;
} else if (virJSONValueIsArray(servers)) {
size_t i;
- ssize_t n = virJSONValueArraySize(servers);
- if (n < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Server count %zd should be positive"), n);
- goto error;
- }
+ size_t n = virJSONValueArraySize(servers);
if (n > nDefServerNames) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Server count %zd greater than default name count %zu"),
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index f4105b1394..5aeb188900 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -411,7 +411,6 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object,
virJSONValuePtr clients;
virJSONValuePtr services;
size_t i;
- ssize_t n;
unsigned int min_workers;
unsigned int max_workers;
unsigned int priority_workers;
@@ -492,14 +491,13 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object,
goto error;
}
- n = virJSONValueArraySize(services);
- if (n < 0) {
+ if (!virJSONValueIsArray(services)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Malformed services data in JSON document"));
+ _("Malformed services array"));
goto error;
}
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(services); i++) {
virNetServerServicePtr service;
virJSONValuePtr child = virJSONValueArrayGet(services, i);
if (!child) {
@@ -525,14 +523,13 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object,
goto error;
}
- n = virJSONValueArraySize(clients);
- if (n < 0) {
+ if (!virJSONValueIsArray(clients)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Malformed clients data in JSON document"));
+ _("Malformed clients array"));
goto error;
}
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(clients); i++) {
virNetServerClientPtr client;
virJSONValuePtr child = virJSONValueArrayGet(clients, i);
if (!child) {
diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c
index fb19d09dda..23fc23cab4 100644
--- a/src/rpc/virnetserverservice.c
+++ b/src/rpc/virnetserverservice.c
@@ -325,7 +325,7 @@ virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr obj
virNetServerServicePtr svc;
virJSONValuePtr socks;
size_t i;
- ssize_t n;
+ size_t n;
unsigned int max;
if (virNetServerServiceInitialize() < 0)
@@ -358,12 +358,13 @@ virNetServerServicePtr virNetServerServiceNewPostExecRestart(virJSONValuePtr obj
goto error;
}
- if ((n = virJSONValueArraySize(socks)) < 0) {
+ if (!virJSONValueIsArray(socks)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("socks field in JSON was not an array"));
+ _("Malformed socks array"));
goto error;
}
+ n = virJSONValueArraySize(socks);
if (VIR_ALLOC_N(svc->socks, n) < 0)
goto error;
svc->nsocks = n;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index dfe00d9280..bb4e3c257b 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -971,12 +971,9 @@ virJSONValueIsArray(virJSONValuePtr array)
}
-ssize_t
+size_t
virJSONValueArraySize(const virJSONValue *array)
{
- if (array->type != VIR_JSON_TYPE_ARRAY)
- return -1;
-
return array->data.array.nvalues;
}
diff --git a/src/util/virjson.h b/src/util/virjson.h
index 0f098892b4..e4a82bdbc8 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -81,7 +81,7 @@ virJSONValuePtr virJSONValueObjectGetByType(virJSONValuePtr object,
bool virJSONValueIsObject(virJSONValuePtr object);
bool virJSONValueIsArray(virJSONValuePtr array);
-ssize_t virJSONValueArraySize(const virJSONValue *array);
+size_t virJSONValueArraySize(const virJSONValue *array);
virJSONValuePtr virJSONValueArrayGet(virJSONValuePtr object, unsigned int element);
virJSONValuePtr virJSONValueArraySteal(virJSONValuePtr object, unsigned int element);
typedef int (*virJSONArrayIteratorFunc)(size_t pos,
diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index 41af0cdb6d..3364c843aa 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -293,7 +293,6 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
{
virLockSpacePtr lockspace;
virJSONValuePtr resources;
- ssize_t n;
size_t i;
VIR_DEBUG("object=%p", object);
@@ -324,19 +323,19 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
goto error;
}
- if ((n = virJSONValueArraySize(resources)) < 0) {
+ if (!virJSONValueIsArray(resources)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Malformed resources value in JSON document"));
+ _("Malformed resources array"));
goto error;
}
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(resources); i++) {
virJSONValuePtr child = virJSONValueArrayGet(resources, i);
virLockSpaceResourcePtr res;
const char *tmp;
virJSONValuePtr owners;
size_t j;
- ssize_t m;
+ size_t m;
if (VIR_ALLOC(res) < 0)
goto error;
@@ -396,18 +395,19 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
goto error;
}
- if ((m = virJSONValueArraySize(owners)) < 0) {
+ if (!virJSONValueIsArray(owners)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Malformed owners value in JSON document"));
+ _("Malformed owners array"));
virLockSpaceResourceFree(res);
goto error;
}
- res->nOwners = m;
+ m = virJSONValueArraySize(owners);
if (VIR_ALLOC_N(res->owners, res->nOwners) < 0) {
virLockSpaceResourceFree(res);
goto error;
}
+ res->nOwners = m;
for (j = 0; j < res->nOwners; j++) {
unsigned long long int owner;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 531540ac91..117ba8430c 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2924,8 +2924,7 @@ virStorageSourceParseBackingJSONGluster(virStorageSourcePtr src,
return -1;
nservers = virJSONValueArraySize(server);
-
- if (nservers < 1) {
+ if (nservers == 0) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("at least 1 server is necessary in "
"JSON backing definition for gluster volume"));
diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c
index 21f5d119e8..46bbc4f1e5 100644
--- a/tests/testutilsqemuschema.c
+++ b/tests/testutilsqemuschema.c
@@ -101,11 +101,9 @@ testQEMUSchemaStealObjectMemberByName(const char *name,
{
virJSONValuePtr member;
virJSONValuePtr ret = NULL;
- size_t n;
size_t i;
- n = virJSONValueArraySize(members);
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(members); i++) {
member = virJSONValueArrayGet(members, i);
if (STREQ_NULLABLE(name, virJSONValueObjectGetString(member, "name"))) {
@@ -188,7 +186,6 @@ testQEMUSchemaValidateObjectMergeVariant(virJSONValuePtr root,
virHashTablePtr schema,
virBufferPtr debug)
{
- size_t n;
size_t i;
virJSONValuePtr variants = NULL;
virJSONValuePtr variant;
@@ -203,8 +200,7 @@ testQEMUSchemaValidateObjectMergeVariant(virJSONValuePtr root,
return -2;
}
- n = virJSONValueArraySize(variants);
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(variants); i++) {
variant = virJSONValueArrayGet(variants, i);
if (STREQ_NULLABLE(variantname,
@@ -342,7 +338,6 @@ testQEMUSchemaValidateEnum(virJSONValuePtr obj,
const char *objstr;
virJSONValuePtr values = NULL;
virJSONValuePtr value;
- size_t n;
size_t i;
if (virJSONValueGetType(obj) != VIR_JSON_TYPE_STRING) {
@@ -358,8 +353,7 @@ testQEMUSchemaValidateEnum(virJSONValuePtr obj,
return -2;
}
- n = virJSONValueArraySize(values);
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(values); i++) {
value = virJSONValueArrayGet(values, i);
if (STREQ_NULLABLE(objstr, virJSONValueGetString(value))) {
@@ -383,7 +377,6 @@ testQEMUSchemaValidateArray(virJSONValuePtr objs,
const char *elemtypename = virJSONValueObjectGetString(root, "element-type");
virJSONValuePtr elementschema;
virJSONValuePtr obj;
- size_t n;
size_t i;
if (virJSONValueGetType(objs) != VIR_JSON_TYPE_ARRAY) {
@@ -401,8 +394,7 @@ testQEMUSchemaValidateArray(virJSONValuePtr objs,
virBufferAddLit(debug, "[\n");
virBufferAdjustIndent(debug, 3);
- n = virJSONValueArraySize(objs);
- for (i = 0; i < n; i++) {
+ for (i = 0; i < virJSONValueArraySize(objs); i++) {
obj = virJSONValueArrayGet(objs, i);
if (testQEMUSchemaValidateRecurse(obj, elementschema, schema, debug) < 0)
@@ -423,8 +415,8 @@ testQEMUSchemaValidateAlternate(virJSONValuePtr obj,
{
virJSONValuePtr members;
virJSONValuePtr member;
- size_t n;
size_t i;
+ size_t n;
const char *membertype;
virJSONValuePtr memberschema;
int indent;
diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
index 62fe589bed..ec73ea575a 100644
--- a/tools/nss/libvirt_nss.c
+++ b/tools/nss/libvirt_nss.c
@@ -309,8 +309,7 @@ findLease(const char *name,
}
VIR_DIR_CLOSE(dir);
- if ((nleases = virJSONValueArraySize(leases_array)) < 0)
- goto cleanup;
+ nleases = virJSONValueArraySize(leases_array);
DEBUG("Read %zd leases", nleases);
#if !defined(LIBVIRT_NSS_GUEST)
--
2.13.6
6 years, 8 months
[libvirt] [PATCH v4] tests/Makefile.am: use LIBTOOL variable instead of hardcoded name
by Maciej Wolny
Fixes "can't find libtool" error when running valgrind checks.
Signed-off-by: Maciej Wolny <maciej.wolny(a)codethink.co.uk>
---
tests/Makefile.am | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7b93fbde6..05db6b119 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -487,7 +487,7 @@ VALGRIND = valgrind --quiet --leak-check=full --trace-children=yes \
--trace-children-skip="*/tools/virsh","*/tests/commandhelper" \
--suppressions=$(srcdir)/.valgrind.supp
valgrind:
- $(MAKE) check VG="libtool --mode=execute $(VALGRIND)"
+ $(MAKE) check VG="$(LIBTOOL) --mode=execute $(VALGRIND)"
sockettest_SOURCES = \
sockettest.c \
--
2.11.0
6 years, 8 months
[libvirt] [PATCH v2 0/8] tests: Mostly fix 'make check' on FreeBSD
by Andrea Bolognani
Changes from [v1]:
* drop the virnetsockettest changes, since the relationship
between the errors seen on FreeBSD and IPv4 clients connecting
to IPv6 sockets has turned out to be just a red herring;
* fix the mocking instead of dropping test cases that don't work
without it.
[v1] https://www.redhat.com/archives/libvir-list/2018-April/msg02611.html
Andrea Bolognani (8):
test: Introduce VIR_MOCK_REAL_INIT_VERSIONED()
tests: Mock realpath()
all: Use realpath() instead of canonicalize_file_name()
tests: Stop mocking canonicalize_file_name()
gnulib: Drop canonicalize-lgpl module
syntax-check: Prohibit canonicalize_file_name()
tests: Fix mode_t usage with va_arg()
tests: Build virpcimock on non-Linux
bootstrap.conf | 1 -
cfg.mk | 10 ++++
src/storage/storage_backend_fs.c | 2 +-
src/util/virfile.c | 2 +-
src/util/virpci.c | 2 +-
tests/virmock.h | 13 +++++
tests/virpcimock.c | 118 +++++++++++++++++++++++----------------
tests/virstoragetest.c | 10 ++--
tests/virtestmock.c | 13 ++---
9 files changed, 107 insertions(+), 64 deletions(-)
--
2.14.3
6 years, 8 months
[libvirt] [PATCH v3] tests/Makefile.am: use LIBTOOL variable instead of hardcoded name
by Maciej Wolny
Fixes "can't find libtool" error when running valgrind checks.
---
tests/Makefile.am | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7b93fbde6..05db6b119 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -487,7 +487,7 @@ VALGRIND = valgrind --quiet --leak-check=full --trace-children=yes \
--trace-children-skip="*/tools/virsh","*/tests/commandhelper" \
--suppressions=$(srcdir)/.valgrind.supp
valgrind:
- $(MAKE) check VG="libtool --mode=execute $(VALGRIND)"
+ $(MAKE) check VG="$(LIBTOOL) --mode=execute $(VALGRIND)"
sockettest_SOURCES = \
sockettest.c \
--
2.11.0
6 years, 8 months
[libvirt] Release of libvirt-4.3.0
by Daniel Veillard
As planned the release is done, it is tagged into git and I pushed
signed tarball and rpms to the usual place:
ftp://libvirt.org/libvirt/
I also pushed a release of the python bindings libvirt-python 4.3.0 at
ftp://libvirt.org/libvirt/python
As usual this release is a balance of features, improvement and bug fixes,
however it is to note that this release also remove the Xen daemon based driver,
hopefully by now nobody uses such very old Xen version:
New features
- qemu: Add support for the pcie-to-pci-bridge controller
Pure PCIe guests such as x86_64/q35 and aarch64/virt will now add this
controller when traditional PCI devices are in use.
- Xen: Support setting CPU features for host-passthrough model
The CPU model presented to Xen HVM domains is equivalent to libvirt's
host-passthrough model, although individual features can be enabled and
disabled via the cpuid setting. The libvirt libxl driver now supports
enabling and disabling individual features of the host-passthrough CPU
model.
Removed features
- Xen: Drop the legacy xend-based driver
The xm/xend toolstack was deprecated in Xen 4.2 and removed from the
Xen sources in the 4.5 development cycle. The libvirt driver based on
xend is now removed from the libvirt sources.
Improvements
- qemu: Support hot plug and hot unplug of mediated devices
Libvirt now allows mediated devices to be hot plugged and hot unplugged
from a guest rather than reporting an error that this isn't supported.
In fact, kernel has been supporting this since 4.10.
Bug fixes
- Improve handling of device mapper targets
When starting a domain with a disk backed by a device mapper volume
libvirt also needs to allow the storage backing the device mapper in
CGroups. In the past kernel did not care, but starting from 4.16
CGroups are consulted on each access to the device mapper target.
thanks everybody for your help on building that release, be it with ideas,
code, patches, reviews, documentation, localization, etc...
Enjoy this month's release,
Daniel
--
Daniel Veillard | Red Hat Developers Tools http://developer.redhat.com/
veillard(a)redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | virtualization library http://libvirt.org/
6 years, 8 months
[libvirt] [PATCH] conf: remove unused VIR_DOMAIN_FS_RAM_DEFAULT_USAGE
by Ján Tomko
Unused since its introduction in commit <76b644c>.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/conf/domain_conf.h | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 3c7eccb8ca..3e135c6364 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -875,9 +875,6 @@ typedef enum {
VIR_DOMAIN_FS_WRPOLICY_LAST
} virDomainFSWrpolicy;
-/* Allow 2 MB ram usage */
-# define VIR_DOMAIN_FS_RAM_DEFAULT_USAGE (1024 * 2)
-
struct _virDomainFSDef {
int type;
int fsdriver; /* enum virDomainFSDriverType */
--
2.13.6
6 years, 8 months
[libvirt] [PATCH] Makefile: fix typo
by Ján Tomko
s/atttribute/attribute/
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
Pushed as trivial.
src/Makefile.am | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 0d8d380df1..0c380780c3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -668,7 +668,7 @@ libvirt_lxc_la_LIBADD = libvirt.la $(CYGWIN_EXTRA_LIBADD)
# Since virt-login-shell will be setuid, we must do everything
# we can to avoid linking to other libraries. Many of them do
-# unsafe things in functions marked __atttribute__((constructor)).
+# unsafe things in functions marked __attribute__((constructor)).
# This library is built to include the bare minimum required to
# have a RPC client for local UNIX socket access only. We use
# the ../config-post.h header to disable all external deps that
--
2.16.1
6 years, 8 months
[libvirt] [PATCH] docs: rng: Add missing <interleave> element to panic device
by Erik Skultety
Panic device has 2 optional sub-elements - <alias> and <address> the
order of which should be interchangeable in the XML.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1456165
Signed-off-by: Erik Skultety <eskultet(a)redhat.com>
---
docs/schemas/domaincommon.rng | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 3569b92127..7c02edb7f8 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -6070,12 +6070,14 @@
</choice>
</attribute>
</optional>
- <optional>
- <ref name="alias"/>
- </optional>
- <optional>
- <ref name="address"/>
- </optional>
+ <interleave>
+ <optional>
+ <ref name="alias"/>
+ </optional>
+ <optional>
+ <ref name="address"/>
+ </optional>
+ </interleave>
</element>
</define>
<define name="rawIO">
--
2.14.3
6 years, 8 months
[libvirt] [PATCH 0/2] Fix virnetsockettest on FreeBSD
by Daniel P. Berrangé
The virnetsockettest is somewhat unreliable on FreeBSD. On a single CPU
guest it will appear to run successfully, as you add more CPUs though it
will increasingly get failures. Testing on a 8 CPU guest gives 100%
failure rate.
Daniel P. Berrangé (2):
tests: merge code for UNIX and TCP socket testing
tests: rewrite socket to do something sensible and reliable
tests/virnetsockettest.c | 228 +++++++++++++++++++++++++++++++----------------
1 file changed, 153 insertions(+), 75 deletions(-)
--
2.14.3
6 years, 8 months