The function now return always 0. Refactor the code and remove return values. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/admin/admin_server.c | 108 ++++--------- src/qemu/qemu_domainjob.c | 45 ++---- src/qemu/qemu_driver.c | 330 ++++++++++++-------------------------- src/test/test_driver.c | 28 ++-- src/util/virtypedparam.c | 28 +--- src/util/virtypedparam.h | 28 ++-- 6 files changed, 173 insertions(+), 394 deletions(-) diff --git a/src/admin/admin_server.c b/src/admin/admin_server.c index 1d1ae97f2f..2498a1309a 100644 --- a/src/admin/admin_server.c +++ b/src/admin/admin_server.c @@ -89,29 +89,12 @@ adminServerGetThreadPoolParameters(virNetServer *srv, return -1; } - if (virTypedParamListAddUInt(paramlist, minWorkers, - "%s", VIR_THREADPOOL_WORKERS_MIN) < 0) - return -1; - - if (virTypedParamListAddUInt(paramlist, maxWorkers, - "%s", VIR_THREADPOOL_WORKERS_MAX) < 0) - return -1; - - if (virTypedParamListAddUInt(paramlist, nWorkers, - "%s", VIR_THREADPOOL_WORKERS_CURRENT) < 0) - return -1; - - if (virTypedParamListAddUInt(paramlist, freeWorkers, - "%s", VIR_THREADPOOL_WORKERS_FREE) < 0) - return -1; - - if (virTypedParamListAddUInt(paramlist, nPrioWorkers, - "%s", VIR_THREADPOOL_WORKERS_PRIORITY) < 0) - return -1; - - if (virTypedParamListAddUInt(paramlist, jobQueueDepth, - "%s", VIR_THREADPOOL_JOB_QUEUE_DEPTH) < 0) - return -1; + virTypedParamListAddUInt(paramlist, minWorkers, VIR_THREADPOOL_WORKERS_MIN); + virTypedParamListAddUInt(paramlist, maxWorkers, VIR_THREADPOOL_WORKERS_MAX); + virTypedParamListAddUInt(paramlist, nWorkers, VIR_THREADPOOL_WORKERS_CURRENT); + virTypedParamListAddUInt(paramlist, freeWorkers, VIR_THREADPOOL_WORKERS_FREE); + virTypedParamListAddUInt(paramlist, nPrioWorkers, VIR_THREADPOOL_WORKERS_PRIORITY); + virTypedParamListAddUInt(paramlist, jobQueueDepth, VIR_THREADPOOL_JOB_QUEUE_DEPTH); if (virTypedParamListSteal(paramlist, params, nparams) < 0) return -1; @@ -211,74 +194,54 @@ adminClientGetInfo(virNetServerClient *client, &sock_addr, &identity) < 0) return -1; - if (virTypedParamListAddBoolean(paramlist, readonly, - "%s", VIR_CLIENT_INFO_READONLY) < 0) - return -1; + virTypedParamListAddBoolean(paramlist, readonly, VIR_CLIENT_INFO_READONLY); if ((rc = virIdentityGetSASLUserName(identity, &attr)) < 0) return -1; - if (rc == 1 && - virTypedParamListAddString(paramlist, attr, - "%s", VIR_CLIENT_INFO_SASL_USER_NAME) < 0) - return -1; + if (rc == 1) + virTypedParamListAddString(paramlist, attr, VIR_CLIENT_INFO_SASL_USER_NAME); if (!virNetServerClientIsLocal(client)) { - if (virTypedParamListAddString(paramlist, sock_addr, - "%s", VIR_CLIENT_INFO_SOCKET_ADDR) < 0) - return -1; + virTypedParamListAddString(paramlist, sock_addr, VIR_CLIENT_INFO_SOCKET_ADDR); if ((rc = virIdentityGetX509DName(identity, &attr)) < 0) return -1; - if (rc == 1 && - virTypedParamListAddString(paramlist, attr, - "%s", VIR_CLIENT_INFO_X509_DISTINGUISHED_NAME) < 0) - return -1; + if (rc == 1) + virTypedParamListAddString(paramlist, attr, VIR_CLIENT_INFO_X509_DISTINGUISHED_NAME); } else { pid_t pid; uid_t uid; gid_t gid; if ((rc = virIdentityGetUNIXUserID(identity, &uid)) < 0) return -1; - if (rc == 1 && - virTypedParamListAddInt(paramlist, uid, - "%s", VIR_CLIENT_INFO_UNIX_USER_ID) < 0) - return -1; + if (rc == 1) + virTypedParamListAddInt(paramlist, uid, VIR_CLIENT_INFO_UNIX_USER_ID); if ((rc = virIdentityGetUserName(identity, &attr)) < 0) return -1; - if (rc == 1 && - virTypedParamListAddString(paramlist, attr, - "%s", VIR_CLIENT_INFO_UNIX_USER_NAME) < 0) - return -1; + if (rc == 1) + virTypedParamListAddString(paramlist, attr, VIR_CLIENT_INFO_UNIX_USER_NAME); if ((rc = virIdentityGetUNIXGroupID(identity, &gid)) < 0) return -1; - if (rc == 1 && - virTypedParamListAddInt(paramlist, gid, - "%s", VIR_CLIENT_INFO_UNIX_GROUP_ID) < 0) - return -1; + if (rc == 1) + virTypedParamListAddInt(paramlist, gid, VIR_CLIENT_INFO_UNIX_GROUP_ID); if ((rc = virIdentityGetGroupName(identity, &attr)) < 0) return -1; - if (rc == 1 && - virTypedParamListAddString(paramlist, attr, - "%s", VIR_CLIENT_INFO_UNIX_GROUP_NAME) < 0) - return -1; + if (rc == 1) + virTypedParamListAddString(paramlist, attr, VIR_CLIENT_INFO_UNIX_GROUP_NAME); if ((rc = virIdentityGetProcessID(identity, &pid)) < 0) return -1; - if (rc == 1 && - virTypedParamListAddInt(paramlist, pid, - "%s", VIR_CLIENT_INFO_UNIX_PROCESS_ID) < 0) - return -1; + if (rc == 1) + virTypedParamListAddInt(paramlist, pid, VIR_CLIENT_INFO_UNIX_PROCESS_ID); } if ((rc = virIdentityGetSELinuxContext(identity, &attr)) < 0) return -1; - if (rc == 1 && - virTypedParamListAddString(paramlist, attr, - "%s", VIR_CLIENT_INFO_SELINUX_CONTEXT) < 0) - return -1; + if (rc == 1) + virTypedParamListAddString(paramlist, attr, VIR_CLIENT_INFO_SELINUX_CONTEXT); if (virTypedParamListSteal(paramlist, params, nparams) < 0) return -1; @@ -305,25 +268,10 @@ adminServerGetClientLimits(virNetServer *srv, virCheckFlags(0, -1); - if (virTypedParamListAddUInt(paramlist, - virNetServerGetMaxClients(srv), - "%s", VIR_SERVER_CLIENTS_MAX) < 0) - return -1; - - if (virTypedParamListAddUInt(paramlist, - virNetServerGetCurrentClients(srv), - "%s", VIR_SERVER_CLIENTS_CURRENT) < 0) - return -1; - - if (virTypedParamListAddUInt(paramlist, - virNetServerGetMaxUnauthClients(srv), - "%s", VIR_SERVER_CLIENTS_UNAUTH_MAX) < 0) - return -1; - - if (virTypedParamListAddUInt(paramlist, - virNetServerGetCurrentUnauthClients(srv), - "%s", VIR_SERVER_CLIENTS_UNAUTH_CURRENT) < 0) - return -1; + virTypedParamListAddUInt(paramlist, virNetServerGetMaxClients(srv), VIR_SERVER_CLIENTS_MAX); + virTypedParamListAddUInt(paramlist, virNetServerGetCurrentClients(srv), VIR_SERVER_CLIENTS_CURRENT); + virTypedParamListAddUInt(paramlist, virNetServerGetMaxUnauthClients(srv), VIR_SERVER_CLIENTS_UNAUTH_MAX); + virTypedParamListAddUInt(paramlist, virNetServerGetCurrentUnauthClients(srv), VIR_SERVER_CLIENTS_UNAUTH_CURRENT); if (virTypedParamListSteal(paramlist, params, nparams) < 0) return -1; diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c index 6be48118b9..245e51f14b 100644 --- a/src/qemu/qemu_domainjob.c +++ b/src/qemu/qemu_domainjob.c @@ -480,47 +480,26 @@ qemuDomainBackupJobDataToParams(virDomainJobData *jobData, qemuDomainBackupStats *stats = &priv->stats.backup; g_autoptr(virTypedParamList) par = virTypedParamListNew(); - if (virTypedParamListAddInt(par, jobData->operation, - VIR_DOMAIN_JOB_OPERATION) < 0) - return -1; - - if (virTypedParamListAddULLong(par, jobData->timeElapsed, - VIR_DOMAIN_JOB_TIME_ELAPSED) < 0) - return -1; + virTypedParamListAddInt(par, jobData->operation, VIR_DOMAIN_JOB_OPERATION); + virTypedParamListAddULLong(par, jobData->timeElapsed, VIR_DOMAIN_JOB_TIME_ELAPSED); if (stats->transferred > 0 || stats->total > 0) { - if (virTypedParamListAddULLong(par, stats->total, - VIR_DOMAIN_JOB_DISK_TOTAL) < 0) - return -1; - - if (virTypedParamListAddULLong(par, stats->transferred, - VIR_DOMAIN_JOB_DISK_PROCESSED) < 0) - return -1; - - if (virTypedParamListAddULLong(par, stats->total - stats->transferred, - VIR_DOMAIN_JOB_DISK_REMAINING) < 0) - return -1; + virTypedParamListAddULLong(par, stats->total, VIR_DOMAIN_JOB_DISK_TOTAL); + virTypedParamListAddULLong(par, stats->transferred, VIR_DOMAIN_JOB_DISK_PROCESSED); + virTypedParamListAddULLong(par, stats->total - stats->transferred, VIR_DOMAIN_JOB_DISK_REMAINING); } if (stats->tmp_used > 0 || stats->tmp_total > 0) { - if (virTypedParamListAddULLong(par, stats->tmp_used, - VIR_DOMAIN_JOB_DISK_TEMP_USED) < 0) - return -1; - - if (virTypedParamListAddULLong(par, stats->tmp_total, - VIR_DOMAIN_JOB_DISK_TEMP_TOTAL) < 0) - return -1; + virTypedParamListAddULLong(par, stats->tmp_used, VIR_DOMAIN_JOB_DISK_TEMP_USED); + virTypedParamListAddULLong(par, stats->tmp_total, VIR_DOMAIN_JOB_DISK_TEMP_TOTAL); } - if (jobData->status != VIR_DOMAIN_JOB_STATUS_ACTIVE && - virTypedParamListAddBoolean(par, - jobData->status == VIR_DOMAIN_JOB_STATUS_COMPLETED, - VIR_DOMAIN_JOB_SUCCESS) < 0) - return -1; + if (jobData->status != VIR_DOMAIN_JOB_STATUS_ACTIVE) + virTypedParamListAddBoolean(par, jobData->status == VIR_DOMAIN_JOB_STATUS_COMPLETED, + VIR_DOMAIN_JOB_SUCCESS); - if (jobData->errmsg && - virTypedParamListAddString(par, jobData->errmsg, VIR_DOMAIN_JOB_ERRMSG) < 0) - return -1; + if (jobData->errmsg) + virTypedParamListAddString(par, jobData->errmsg, VIR_DOMAIN_JOB_ERRMSG); if (virTypedParamListSteal(par, params, nparams) < 0) return -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9c409948f0..d47c1883f0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17020,11 +17020,8 @@ qemuDomainGetStatsState(virQEMUDriver *driver G_GNUC_UNUSED, virTypedParamList *params, unsigned int privflags G_GNUC_UNUSED) { - if (virTypedParamListAddInt(params, dom->state.state, "state.state") < 0) - return -1; - - if (virTypedParamListAddInt(params, dom->state.reason, "state.reason") < 0) - return -1; + virTypedParamListAddInt(params, dom->state.state, "state.state"); + virTypedParamListAddInt(params, dom->state.reason, "state.reason"); return 0; } @@ -17183,33 +17180,16 @@ qemuDomainGetStatsMemoryBandwidth(virQEMUDriver *driver, if (nresdata == 0) return 0; - if (virTypedParamListAddUInt(params, nresdata, - "memory.bandwidth.monitor.count") < 0) - goto cleanup; + virTypedParamListAddUInt(params, nresdata, "memory.bandwidth.monitor.count"); for (i = 0; i < nresdata; i++) { - if (virTypedParamListAddString(params, resdata[i]->name, - "memory.bandwidth.monitor.%zu.name", - i) < 0) - goto cleanup; - - if (virTypedParamListAddString(params, resdata[i]->vcpus, - "memory.bandwidth.monitor.%zu.vcpus", - i) < 0) - goto cleanup; - - if (virTypedParamListAddUInt(params, resdata[i]->nstats, - "memory.bandwidth.monitor.%zu.node.count", - i) < 0) - goto cleanup; - + virTypedParamListAddString(params, resdata[i]->name, "memory.bandwidth.monitor.%zu.name", i); + virTypedParamListAddString(params, resdata[i]->vcpus, "memory.bandwidth.monitor.%zu.vcpus", i); + virTypedParamListAddUInt(params, resdata[i]->nstats, "memory.bandwidth.monitor.%zu.node.count", i); for (j = 0; j < resdata[i]->nstats; j++) { - if (virTypedParamListAddUInt(params, resdata[i]->stats[j]->id, - "memory.bandwidth.monitor.%zu." - "node.%zu.id", - i, j) < 0) - goto cleanup; + virTypedParamListAddUInt(params, resdata[i]->stats[j]->id, + "memory.bandwidth.monitor.%zu.node.%zu.id", i, j); features = resdata[i]->stats[j]->features; @@ -17217,23 +17197,15 @@ qemuDomainGetStatsMemoryBandwidth(virQEMUDriver *driver, if (STREQ(features[k], "mbm_local_bytes")) { /* The accumulative data passing through local memory * controller is recorded with 64 bit counter. */ - if (virTypedParamListAddULLong(params, - resdata[i]->stats[j]->vals[k], - "memory.bandwidth.monitor." - "%zu.node.%zu.bytes.local", - i, j) < 0) - goto cleanup; + virTypedParamListAddULLong(params, resdata[i]->stats[j]->vals[k], + "memory.bandwidth.monitor.%zu.node.%zu.bytes.local", i, j); } if (STREQ(features[k], "mbm_total_bytes")) { /* The accumulative data passing through local and remote * memory controller is recorded with 64 bit counter. */ - if (virTypedParamListAddULLong(params, - resdata[i]->stats[j]->vals[k], - "memory.bandwidth.monitor." - "%zu.node.%zu.bytes.total", - i, j) < 0) - goto cleanup; + virTypedParamListAddULLong(params, resdata[i]->stats[j]->vals[k], + "memory.bandwidth.monitor.%zu.node.%zu.bytes.total", i, j); } } } @@ -17266,26 +17238,16 @@ qemuDomainGetStatsCpuCache(virQEMUDriver *driver, VIR_RESCTRL_MONITOR_TYPE_CACHE) < 0) goto cleanup; - if (virTypedParamListAddUInt(params, nresdata, "cpu.cache.monitor.count") < 0) - goto cleanup; + virTypedParamListAddUInt(params, nresdata, "cpu.cache.monitor.count"); for (i = 0; i < nresdata; i++) { - if (virTypedParamListAddString(params, resdata[i]->name, - "cpu.cache.monitor.%zu.name", i) < 0) - goto cleanup; - - if (virTypedParamListAddString(params, resdata[i]->vcpus, - "cpu.cache.monitor.%zu.vcpus", i) < 0) - goto cleanup; - - if (virTypedParamListAddUInt(params, resdata[i]->nstats, - "cpu.cache.monitor.%zu.bank.count", i) < 0) - goto cleanup; + virTypedParamListAddString(params, resdata[i]->name, "cpu.cache.monitor.%zu.name", i); + virTypedParamListAddString(params, resdata[i]->vcpus, "cpu.cache.monitor.%zu.vcpus", i); + virTypedParamListAddUInt(params, resdata[i]->nstats, "cpu.cache.monitor.%zu.bank.count", i); for (j = 0; j < resdata[i]->nstats; j++) { - if (virTypedParamListAddUInt(params, resdata[i]->stats[j]->id, - "cpu.cache.monitor.%zu.bank.%zu.id", i, j) < 0) - goto cleanup; + virTypedParamListAddUInt(params, resdata[i]->stats[j]->id, + "cpu.cache.monitor.%zu.bank.%zu.id", i, j); /* 'resdata[i]->stats[j]->vals[0]' keeps the value of how many last * level cache in bank j currently occupied by the vcpus listed in @@ -17296,11 +17258,8 @@ qemuDomainGetStatsCpuCache(virQEMUDriver *driver, * than 4G bytes in size, to keep the 'domstats' interface * historically consistent, it is safe to report the value with a * truncated 'UInt' data type here. */ - if (virTypedParamListAddUInt(params, - (unsigned int)resdata[i]->stats[j]->vals[0], - "cpu.cache.monitor.%zu.bank.%zu.bytes", - i, j) < 0) - goto cleanup; + virTypedParamListAddUInt(params, (unsigned int)resdata[i]->stats[j]->vals[0], + "cpu.cache.monitor.%zu.bank.%zu.bytes", i, j); } } @@ -17321,20 +17280,17 @@ qemuDomainGetStatsCpuCgroup(virDomainObj *dom, unsigned long long cpu_time = 0; unsigned long long user_time = 0; unsigned long long sys_time = 0; - int err = 0; if (!priv->cgroup) return 0; - err = virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time); - if (!err && virTypedParamListAddULLong(params, cpu_time, "cpu.time") < 0) - return -1; + if (virCgroupGetCpuacctUsage(priv->cgroup, &cpu_time) == 0) + virTypedParamListAddULLong(params, cpu_time, "cpu.time"); - err = virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time); - if (!err && virTypedParamListAddULLong(params, user_time, "cpu.user") < 0) - return -1; - if (!err && virTypedParamListAddULLong(params, sys_time, "cpu.system") < 0) - return -1; + if (virCgroupGetCpuacctStat(priv->cgroup, &user_time, &sys_time) == 0) { + virTypedParamListAddULLong(params, user_time, "cpu.user"); + virTypedParamListAddULLong(params, sys_time, "cpu.system"); + } return 0; } @@ -17354,10 +17310,9 @@ qemuDomainGetStatsCpuProc(virDomainObj *vm, return 0; } - if (virTypedParamListAddULLong(params, cpuTime, "cpu.time") < 0 || - virTypedParamListAddULLong(params, userTime, "cpu.user") < 0 || - virTypedParamListAddULLong(params, sysTime, "cpu.system") < 0) - return -1; + virTypedParamListAddULLong(params, cpuTime, "cpu.time"); + virTypedParamListAddULLong(params, userTime, "cpu.user"); + virTypedParamListAddULLong(params, sysTime, "cpu.system"); return 0; } @@ -17445,9 +17400,8 @@ qemuDomainGetStatsCpuHaltPollTime(virDomainObj *dom, virHostCPUGetHaltPollTime(dom->pid, &haltPollSuccess, &haltPollFail) < 0) return 0; - if (virTypedParamListAddULLong(params, haltPollSuccess, "cpu.haltpoll.success.time") < 0 || - virTypedParamListAddULLong(params, haltPollFail, "cpu.haltpoll.fail.time") < 0) - return -1; + virTypedParamListAddULLong(params, haltPollSuccess, "cpu.haltpoll.success.time"); + virTypedParamListAddULLong(params, haltPollFail, "cpu.haltpoll.fail.time"); return 0; } @@ -17506,12 +17460,8 @@ qemuDomainGetStatsBalloon(virQEMUDriver *driver G_GNUC_UNUSED, cur_balloon = dom->def->mem.cur_balloon; } - if (virTypedParamListAddULLong(params, cur_balloon, "balloon.current") < 0) - return -1; - - if (virTypedParamListAddULLong(params, virDomainDefGetMemoryTotal(dom->def), - "balloon.maximum") < 0) - return -1; + virTypedParamListAddULLong(params, cur_balloon, "balloon.current"); + virTypedParamListAddULLong(params, virDomainDefGetMemoryTotal(dom->def), "balloon.maximum"); if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom)) return 0; @@ -17523,8 +17473,7 @@ qemuDomainGetStatsBalloon(virQEMUDriver *driver G_GNUC_UNUSED, #define STORE_MEM_RECORD(TAG, NAME) \ if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_ ##TAG) \ - if (virTypedParamListAddULLong(params, stats[i].val, "balloon." NAME) < 0) \ - return -1; + virTypedParamListAddULLong(params, stats[i].val, "balloon." NAME); for (i = 0; i < nr_stats; i++) { STORE_MEM_RECORD(SWAP_IN, "swap_in") @@ -17593,16 +17542,14 @@ qemuDomainAddStatsFromHashTable(GHashTable *stats, if (virJSONValueGetBoolean(value, &stat) < 0) continue; - ignore_value(virTypedParamListAddBoolean(params, stat, "%s.%s.%s", - prefix, key, type)); + virTypedParamListAddBoolean(params, stat, "%s.%s.%s", prefix, key, type); } else { unsigned long long stat; if (virJSONValueGetNumberUlong(value, &stat) < 0) continue; - ignore_value(virTypedParamListAddULLong(params, stat, "%s.%s.%s", - prefix, key, type)); + virTypedParamListAddULLong(params, stat, "%s.%s.%s", prefix, key, type); } } } @@ -17623,13 +17570,8 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC_UNUSED, qemuDomainObjPrivate *priv = dom->privateData; g_autoptr(virJSONValue) queried_stats = NULL; - if (virTypedParamListAddUInt(params, virDomainDefGetVcpus(dom->def), - "vcpu.current") < 0) - return -1; - - if (virTypedParamListAddUInt(params, virDomainDefGetVcpusMax(dom->def), - "vcpu.maximum") < 0) - return -1; + virTypedParamListAddUInt(params, virDomainDefGetVcpus(dom->def), "vcpu.current"); + virTypedParamListAddUInt(params, virDomainDefGetVcpusMax(dom->def), "vcpu.maximum"); cpuinfo = g_new0(virVcpuInfo, virDomainDefGetVcpus(dom->def)); cpuwait = g_new0(unsigned long long, virDomainDefGetVcpus(dom->def)); @@ -17662,25 +17604,15 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC_UNUSED, g_autoptr(GHashTable) stats = NULL; g_autofree char *prefix = g_strdup_printf("vcpu.%u", cpuinfo[i].number); - if (virTypedParamListAddInt(params, cpuinfo[i].state, - "vcpu.%u.state", cpuinfo[i].number) < 0) - return -1; + virTypedParamListAddInt(params, cpuinfo[i].state, "vcpu.%u.state", cpuinfo[i].number); /* stats below are available only if the VM is alive */ if (!virDomainObjIsActive(dom)) continue; - if (virTypedParamListAddULLong(params, cpuinfo[i].cpuTime, - "vcpu.%u.time", cpuinfo[i].number) < 0) - return -1; - - if (virTypedParamListAddULLong(params, cpuwait[i], - "vcpu.%u.wait", cpuinfo[i].number) < 0) - return -1; - - if (virTypedParamListAddULLong(params, cpudelay[i], - "vcpu.%u.delay", cpuinfo[i].number) < 0) - return -1; + virTypedParamListAddULLong(params, cpuinfo[i].cpuTime, "vcpu.%u.time", cpuinfo[i].number); + virTypedParamListAddULLong(params, cpuwait[i], "vcpu.%u.wait", cpuinfo[i].number); + virTypedParamListAddULLong(params, cpudelay[i], "vcpu.%u.delay", cpuinfo[i].number); /* state below is extracted from the individual vcpu structs */ if (!(vcpu = virDomainDefGetVcpu(dom->def, cpuinfo[i].number))) @@ -17689,11 +17621,8 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC_UNUSED, vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu); if (vcpupriv->halted != VIR_TRISTATE_BOOL_ABSENT) { - if (virTypedParamListAddBoolean(params, - vcpupriv->halted == VIR_TRISTATE_BOOL_YES, - "vcpu.%u.halted", - cpuinfo[i].number) < 0) - return -1; + virTypedParamListAddBoolean(params, vcpupriv->halted == VIR_TRISTATE_BOOL_YES, + "vcpu.%u.halted", cpuinfo[i].number); } if (!queried_stats) @@ -17709,9 +17638,8 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC_UNUSED, } #define QEMU_ADD_NET_PARAM(params, num, name, value) \ - if (value >= 0 && \ - virTypedParamListAddULLong((params), (value), "net.%zu.%s", (num), (name)) < 0) \ - return -1; + if (value >= 0)\ + virTypedParamListAddULLong((params), (value), "net.%zu.%s", (num), (name)); static int qemuDomainGetStatsInterface(virQEMUDriver *driver G_GNUC_UNUSED, @@ -17725,8 +17653,7 @@ qemuDomainGetStatsInterface(virQEMUDriver *driver G_GNUC_UNUSED, if (!virDomainObjIsActive(dom)) return 0; - if (virTypedParamListAddUInt(params, dom->def->nnets, "net.count") < 0) - return -1; + virTypedParamListAddUInt(params, dom->def->nnets, "net.count"); /* Check the path is one of the domain's network interfaces. */ for (i = 0; i < dom->def->nnets; i++) { @@ -17740,8 +17667,7 @@ qemuDomainGetStatsInterface(virQEMUDriver *driver G_GNUC_UNUSED, actualType = virDomainNetGetActualType(net); - if (virTypedParamListAddString(params, net->ifname, "net.%zu.name", i) < 0) - return -1; + virTypedParamListAddString(params, net->ifname, "net.%zu.name", i); if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) { if (virNetDevOpenvswitchInterfaceStats(net->ifname, &tmp) < 0) { @@ -17756,22 +17682,14 @@ qemuDomainGetStatsInterface(virQEMUDriver *driver G_GNUC_UNUSED, } } - QEMU_ADD_NET_PARAM(params, i, - "rx.bytes", tmp.rx_bytes); - QEMU_ADD_NET_PARAM(params, i, - "rx.pkts", tmp.rx_packets); - QEMU_ADD_NET_PARAM(params, i, - "rx.errs", tmp.rx_errs); - QEMU_ADD_NET_PARAM(params, i, - "rx.drop", tmp.rx_drop); - QEMU_ADD_NET_PARAM(params, i, - "tx.bytes", tmp.tx_bytes); - QEMU_ADD_NET_PARAM(params, i, - "tx.pkts", tmp.tx_packets); - QEMU_ADD_NET_PARAM(params, i, - "tx.errs", tmp.tx_errs); - QEMU_ADD_NET_PARAM(params, i, - "tx.drop", tmp.tx_drop); + QEMU_ADD_NET_PARAM(params, i, "rx.bytes", tmp.rx_bytes); + QEMU_ADD_NET_PARAM(params, i, "rx.pkts", tmp.rx_packets); + QEMU_ADD_NET_PARAM(params, i, "rx.errs", tmp.rx_errs); + QEMU_ADD_NET_PARAM(params, i, "rx.drop", tmp.rx_drop); + QEMU_ADD_NET_PARAM(params, i, "tx.bytes", tmp.tx_bytes); + QEMU_ADD_NET_PARAM(params, i, "tx.pkts", tmp.tx_packets); + QEMU_ADD_NET_PARAM(params, i, "tx.errs", tmp.tx_errs); + QEMU_ADD_NET_PARAM(params, i, "tx.drop", tmp.tx_drop); } return 0; @@ -17799,20 +17717,14 @@ qemuDomainGetStatsOneBlockFallback(virQEMUDriver *driver, return 0; } - if (src->allocation && - virTypedParamListAddULLong(params, src->allocation, - "block.%zu.allocation", block_idx) < 0) - return -1; + if (src->allocation) + virTypedParamListAddULLong(params, src->allocation, "block.%zu.allocation", block_idx); - if (src->capacity && - virTypedParamListAddULLong(params, src->capacity, - "block.%zu.capacity", block_idx) < 0) - return -1; + if (src->capacity) + virTypedParamListAddULLong(params, src->capacity, "block.%zu.capacity", block_idx); - if (src->physical && - virTypedParamListAddULLong(params, src->physical, - "block.%zu.physical", block_idx) < 0) - return -1; + if (src->physical) + virTypedParamListAddULLong(params, src->physical, "block.%zu.physical", block_idx); return 0; } @@ -17843,24 +17755,16 @@ qemuDomainGetStatsOneBlock(virQEMUDriver *driver, if (!stats || !entryname || !(entry = virHashLookup(stats, entryname))) return 0; - if (virTypedParamListAddULLong(params, entry->wr_highest_offset, - "block.%zu.allocation", block_idx) < 0) - return -1; + virTypedParamListAddULLong(params, entry->wr_highest_offset, "block.%zu.allocation", block_idx); - if (entry->capacity && - virTypedParamListAddULLong(params, entry->capacity, - "block.%zu.capacity", block_idx) < 0) - return -1; + if (entry->capacity) + virTypedParamListAddULLong(params, entry->capacity, "block.%zu.capacity", block_idx); if (entry->physical) { - if (virTypedParamListAddULLong(params, entry->physical, - "block.%zu.physical", block_idx) < 0) - return -1; + virTypedParamListAddULLong(params, entry->physical, "block.%zu.physical", block_idx); } else { if (qemuDomainStorageUpdatePhysical(driver, cfg, dom, src) == 0) { - if (virTypedParamListAddULLong(params, src->physical, - "block.%zu.physical", block_idx) < 0) - return -1; + virTypedParamListAddULLong(params, src->physical, "block.%zu.physical", block_idx); } } @@ -17879,10 +17783,8 @@ qemuDomainGetStatsBlockExportBackendStorage(const char *entryname, if (!stats || !entryname || !(entry = virHashLookup(stats, entryname))) return 0; - if (entry->write_threshold && - virTypedParamListAddULLong(params, entry->write_threshold, - "block.%zu.threshold", recordnr) < 0) - return -1; + if (entry->write_threshold) + virTypedParamListAddULLong(params, entry->write_threshold, "block.%zu.threshold", recordnr); return 0; } @@ -17902,15 +17804,14 @@ qemuDomainGetStatsBlockExportFrontend(const char *frontendname, if (!stats || !frontendname || !(en = virHashLookup(stats, frontendname))) return 0; - if (virTypedParamListAddULLong(par, en->rd_req, "block.%zu.rd.reqs", idx) < 0 || - virTypedParamListAddULLong(par, en->rd_bytes, "block.%zu.rd.bytes", idx) < 0 || - virTypedParamListAddULLong(par, en->rd_total_times, "block.%zu.rd.times", idx) < 0 || - virTypedParamListAddULLong(par, en->wr_req, "block.%zu.wr.reqs", idx) < 0 || - virTypedParamListAddULLong(par, en->wr_bytes, "block.%zu.wr.bytes", idx) < 0 || - virTypedParamListAddULLong(par, en->wr_total_times, "block.%zu.wr.times", idx) < 0 || - virTypedParamListAddULLong(par, en->flush_req, "block.%zu.fl.reqs", idx) < 0 || - virTypedParamListAddULLong(par, en->flush_total_times, "block.%zu.fl.times", idx) < 0) - return -1; + virTypedParamListAddULLong(par, en->rd_req, "block.%zu.rd.reqs", idx); + virTypedParamListAddULLong(par, en->rd_bytes, "block.%zu.rd.bytes", idx); + virTypedParamListAddULLong(par, en->rd_total_times, "block.%zu.rd.times", idx); + virTypedParamListAddULLong(par, en->wr_req, "block.%zu.wr.reqs", idx); + virTypedParamListAddULLong(par, en->wr_bytes, "block.%zu.wr.bytes", idx); + virTypedParamListAddULLong(par, en->wr_total_times, "block.%zu.wr.times", idx); + virTypedParamListAddULLong(par, en->flush_req, "block.%zu.fl.reqs", idx); + virTypedParamListAddULLong(par, en->flush_total_times, "block.%zu.fl.times", idx); return 0; } @@ -17922,16 +17823,13 @@ qemuDomainGetStatsBlockExportHeader(virDomainDiskDef *disk, size_t recordnr, virTypedParamList *params) { - if (virTypedParamListAddString(params, disk->dst, "block.%zu.name", recordnr) < 0) - return -1; + virTypedParamListAddString(params, disk->dst, "block.%zu.name", recordnr); - if (virStorageSourceIsLocalStorage(src) && src->path && - virTypedParamListAddString(params, src->path, "block.%zu.path", recordnr) < 0) - return -1; + if (virStorageSourceIsLocalStorage(src) && src->path) + virTypedParamListAddString(params, src->path, "block.%zu.path", recordnr); - if (src->id && - virTypedParamListAddUInt(params, src->id, "block.%zu.backingIndex", recordnr) < 0) - return -1; + if (src->id) + virTypedParamListAddUInt(params, src->id, "block.%zu.backingIndex", recordnr); return 0; } @@ -18133,9 +18031,7 @@ qemuDomainGetStatsBlock(virQEMUDriver *driver, return -1; } - if (virTypedParamListAddUInt(params, 0, "block.count") < 0) - return -1; - + virTypedParamListAddUInt(params, 0, "block.count"); virTypedParamListConcat(params, &blockparams); return 0; @@ -18166,23 +18062,19 @@ qemuDomainGetStatsIOThread(virQEMUDriver *driver G_GNUC_UNUSED, goto cleanup; } - if (virTypedParamListAddUInt(params, niothreads, "iothread.count") < 0) - goto cleanup; + virTypedParamListAddUInt(params, niothreads, "iothread.count"); for (i = 0; i < niothreads; i++) { if (iothreads[i]->poll_valid) { - if (virTypedParamListAddULLong(params, iothreads[i]->poll_max_ns, - "iothread.%u.poll-max-ns", - iothreads[i]->iothread_id) < 0) - goto cleanup; - if (virTypedParamListAddUInt(params, iothreads[i]->poll_grow, - "iothread.%u.poll-grow", - iothreads[i]->iothread_id) < 0) - goto cleanup; - if (virTypedParamListAddUInt(params, iothreads[i]->poll_shrink, - "iothread.%u.poll-shrink", - iothreads[i]->iothread_id) < 0) - goto cleanup; + virTypedParamListAddULLong(params, iothreads[i]->poll_max_ns, + "iothread.%u.poll-max-ns", + iothreads[i]->iothread_id); + virTypedParamListAddUInt(params, iothreads[i]->poll_grow, + "iothread.%u.poll-grow", + iothreads[i]->iothread_id); + virTypedParamListAddUInt(params, iothreads[i]->poll_shrink, + "iothread.%u.poll-shrink", + iothreads[i]->iothread_id); } } @@ -18207,9 +18099,7 @@ qemuDomainGetStatsPerfOneEvent(virPerf *perf, if (virPerfReadEvent(perf, type, &value) < 0) return -1; - if (virTypedParamListAddULLong(params, value, "perf.%s", - virPerfEventTypeToString(type)) < 0) - return -1; + virTypedParamListAddULLong(params, value, "perf.%s", virPerfEventTypeToString(type)); return 0; } @@ -18262,35 +18152,21 @@ qemuDomainGetStatsDirtyRate(virQEMUDriver *driver G_GNUC_UNUSED, if (qemuDomainGetStatsDirtyRateMon(dom, &info) < 0) return -1; - if (virTypedParamListAddInt(params, info.status, - "dirtyrate.calc_status") < 0) - return -1; - - if (virTypedParamListAddLLong(params, info.startTime, - "dirtyrate.calc_start_time") < 0) - return -1; - - if (virTypedParamListAddInt(params, info.calcTime, - "dirtyrate.calc_period") < 0) - return -1; - - if (virTypedParamListAddString(params, - qemuMonitorDirtyRateCalcModeTypeToString(info.mode), - "dirtyrate.calc_mode") < 0) - return -1; + virTypedParamListAddInt(params, info.status, "dirtyrate.calc_status"); + virTypedParamListAddLLong(params, info.startTime, "dirtyrate.calc_start_time"); + virTypedParamListAddInt(params, info.calcTime, "dirtyrate.calc_period"); + virTypedParamListAddString(params, qemuMonitorDirtyRateCalcModeTypeToString(info.mode), + "dirtyrate.calc_mode"); if (info.status == VIR_DOMAIN_DIRTYRATE_MEASURED) { - if (virTypedParamListAddLLong(params, info.dirtyRate, - "dirtyrate.megabytes_per_second") < 0) - return -1; + virTypedParamListAddLLong(params, info.dirtyRate, "dirtyrate.megabytes_per_second"); if (info.mode == QEMU_MONITOR_DIRTYRATE_CALC_MODE_DIRTY_RING) { size_t i; for (i = 0; i < info.nvcpus; i++) { - if (virTypedParamListAddULLong(params, info.rates[i].value, - "dirtyrate.vcpu.%d.megabytes_per_second", - info.rates[i].idx) < 0) - return -1; + virTypedParamListAddULLong(params, info.rates[i].value, + "dirtyrate.vcpu.%d.megabytes_per_second", + info.rates[i].idx); } } } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ac12488de9..e7fce053b4 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9784,11 +9784,8 @@ static int testDomainGetStatsState(virDomainObj *dom, virTypedParamList *params) { - if (virTypedParamListAddInt(params, dom->state.state, "state.state") < 0) - return -1; - - if (virTypedParamListAddInt(params, dom->state.reason, "state.reason") < 0) - return -1; + virTypedParamListAddInt(params, dom->state.state, "state.state"); + virTypedParamListAddInt(params, dom->state.reason, "state.reason"); return 0; } @@ -9810,24 +9807,17 @@ testDomainGetStatsIOThread(virDomainObj *dom, return 0; } - if (virTypedParamListAddUInt(params, niothreads, "iothread.count") < 0) - return -1; + virTypedParamListAddUInt(params, niothreads, "iothread.count"); for (i = 0; i < niothreads; i++) { testIOThreadInfo iothread = g_array_index(priv->iothreads, testIOThreadInfo, i); - if (virTypedParamListAddULLong(params, iothread.poll_max_ns, - "iothread.%u.poll-max-ns", - iothread.iothread_id) < 0) - return -1; - if (virTypedParamListAddUInt(params, iothread.poll_grow, - "iothread.%u.poll-grow", - iothread.iothread_id) < 0) - return -1; - if (virTypedParamListAddUInt(params, iothread.poll_shrink, - "iothread.%u.poll-shrink", - iothread.iothread_id) < 0) - return -1; + virTypedParamListAddULLong(params, iothread.poll_max_ns, + "iothread.%u.poll-max-ns", iothread.iothread_id); + virTypedParamListAddUInt(params, iothread.poll_grow, + "iothread.%u.poll-grow", iothread.iothread_id); + virTypedParamListAddUInt(params, iothread.poll_shrink, + "iothread.%u.poll-shrink", iothread.iothread_id); } return 0; diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index 046164d36c..ee9c6d1c45 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -853,7 +853,7 @@ virTypedParamListExtend(virTypedParamList *list) } -int +void virTypedParamListAddInt(virTypedParamList *list, int value, const char *namefmt, @@ -867,12 +867,10 @@ virTypedParamListAddInt(virTypedParamList *list, va_start(ap, namefmt); virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - - return 0; } -int +void virTypedParamListAddUInt(virTypedParamList *list, unsigned int value, const char *namefmt, @@ -886,12 +884,10 @@ virTypedParamListAddUInt(virTypedParamList *list, va_start(ap, namefmt); virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - - return 0; } -int +void virTypedParamListAddLLong(virTypedParamList *list, long long value, const char *namefmt, @@ -905,12 +901,10 @@ virTypedParamListAddLLong(virTypedParamList *list, va_start(ap, namefmt); virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - - return 0; } -int +void virTypedParamListAddULLong(virTypedParamList *list, unsigned long long value, const char *namefmt, @@ -924,12 +918,10 @@ virTypedParamListAddULLong(virTypedParamList *list, va_start(ap, namefmt); virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - - return 0; } -int +void virTypedParamListAddString(virTypedParamList *list, const char *value, const char *namefmt, @@ -943,12 +935,10 @@ virTypedParamListAddString(virTypedParamList *list, va_start(ap, namefmt); virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - - return 0; } -int +void virTypedParamListAddBoolean(virTypedParamList *list, bool value, const char *namefmt, @@ -962,12 +952,10 @@ virTypedParamListAddBoolean(virTypedParamList *list, va_start(ap, namefmt); virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - - return 0; } -int +void virTypedParamListAddDouble(virTypedParamList *list, double value, const char *namefmt, @@ -981,6 +969,4 @@ virTypedParamListAddDouble(virTypedParamList *list, va_start(ap, namefmt); virTypedParamSetNameVPrintf(list, par, namefmt, ap); va_end(ap); - - return 0; } diff --git a/src/util/virtypedparam.h b/src/util/virtypedparam.h index b2869173e1..7065683297 100644 --- a/src/util/virtypedparam.h +++ b/src/util/virtypedparam.h @@ -162,45 +162,45 @@ void virTypedParamListConcat(virTypedParamList *to, virTypedParamList **fromptr); -int +void virTypedParamListAddInt(virTypedParamList *list, int value, const char *namefmt, ...) - G_GNUC_PRINTF(3, 4) G_GNUC_WARN_UNUSED_RESULT; -int + G_GNUC_PRINTF(3, 4); +void virTypedParamListAddUInt(virTypedParamList *list, unsigned int value, const char *namefmt, ...) - G_GNUC_PRINTF(3, 4) G_GNUC_WARN_UNUSED_RESULT; -int + G_GNUC_PRINTF(3, 4); +void virTypedParamListAddLLong(virTypedParamList *list, long long value, const char *namefmt, ...) - G_GNUC_PRINTF(3, 4) G_GNUC_WARN_UNUSED_RESULT; -int + G_GNUC_PRINTF(3, 4); +void virTypedParamListAddULLong(virTypedParamList *list, unsigned long long value, const char *namefmt, ...) - G_GNUC_PRINTF(3, 4) G_GNUC_WARN_UNUSED_RESULT; -int + G_GNUC_PRINTF(3, 4); +void virTypedParamListAddString(virTypedParamList *list, const char *value, const char *namefmt, ...) - G_GNUC_PRINTF(3, 4) G_GNUC_WARN_UNUSED_RESULT; -int + G_GNUC_PRINTF(3, 4); +void virTypedParamListAddBoolean(virTypedParamList *list, bool value, const char *namefmt, ...) - G_GNUC_PRINTF(3, 4) G_GNUC_WARN_UNUSED_RESULT; -int + G_GNUC_PRINTF(3, 4); +void virTypedParamListAddDouble(virTypedParamList *list, double value, const char *namefmt, ...) - G_GNUC_PRINTF(3, 4) G_GNUC_WARN_UNUSED_RESULT; + G_GNUC_PRINTF(3, 4); -- 2.39.2