virsh: cmdIOThreadSet: Refactor to use virTypedParamList

Refactor to use the new data type so that we can use the APIs of it in
upcoming patches.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-04-18 22:51:24 +02:00
parent 07652410a7
commit e094d21004

View File

@ -7846,14 +7846,13 @@ cmdIOThreadSet(vshControl *ctl, const vshCmd *cmd)
{ {
g_autoptr(virshDomain) dom = NULL; g_autoptr(virshDomain) dom = NULL;
int id = 0; int id = 0;
bool ret = false;
bool current = vshCommandOptBool(cmd, "current"); bool current = vshCommandOptBool(cmd, "current");
bool config = vshCommandOptBool(cmd, "config"); bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live"); bool live = vshCommandOptBool(cmd, "live");
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
virTypedParameterPtr params = NULL; g_autoptr(virTypedParamList) params = virTypedParamListNew();
int nparams = 0; virTypedParameterPtr par;
int maxparams = 0; size_t npar = 0;
unsigned long long poll_max; unsigned long long poll_max;
unsigned int poll_val; unsigned int poll_val;
int thread_val; int thread_val;
@ -7871,64 +7870,49 @@ cmdIOThreadSet(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptInt(ctl, cmd, "id", &id) < 0) if (vshCommandOptInt(ctl, cmd, "id", &id) < 0)
goto cleanup; return false;
if (id <= 0) { if (id <= 0) {
vshError(ctl, _("Invalid IOThread id value: '%1$d'"), id); vshError(ctl, _("Invalid IOThread id value: '%1$d'"), id);
goto cleanup; return false;
} }
poll_val = 0;
if ((rc = vshCommandOptULongLong(ctl, cmd, "poll-max-ns", &poll_max)) < 0) if ((rc = vshCommandOptULongLong(ctl, cmd, "poll-max-ns", &poll_max)) < 0)
goto cleanup; return false;
if (rc > 0 && virTypedParamsAddULLong(&params, &nparams, &maxparams, if (rc > 0)
VIR_DOMAIN_IOTHREAD_POLL_MAX_NS, virTypedParamListAddULLong(params, poll_max, VIR_DOMAIN_IOTHREAD_POLL_MAX_NS);
poll_max) < 0)
goto save_error;
#define VSH_IOTHREAD_SET_UINT_PARAMS(opt, param) \ if ((rc = vshCommandOptUInt(ctl, cmd, "poll-grow", &poll_val)) < 0)
poll_val = 0; \ return false;
if ((rc = vshCommandOptUInt(ctl, cmd, opt, &poll_val)) < 0) \ if (rc > 0)
goto cleanup; \ virTypedParamListAddUInt(params, poll_val, VIR_DOMAIN_IOTHREAD_POLL_GROW);
if (rc > 0 && \
virTypedParamsAddUInt(&params, &nparams, &maxparams, \
param, poll_val) < 0) \
goto save_error;
VSH_IOTHREAD_SET_UINT_PARAMS("poll-grow", VIR_DOMAIN_IOTHREAD_POLL_GROW) if ((rc = vshCommandOptUInt(ctl, cmd, "poll-shrink", &poll_val)) < 0)
VSH_IOTHREAD_SET_UINT_PARAMS("poll-shrink", VIR_DOMAIN_IOTHREAD_POLL_SHRINK) return false;
if (rc > 0)
virTypedParamListAddUInt(params, poll_val, VIR_DOMAIN_IOTHREAD_POLL_SHRINK);
#undef VSH_IOTHREAD_SET_UINT_PARAMS if ((rc = vshCommandOptInt(ctl, cmd, "thread-pool-min", &thread_val)) < 0)
return false;
if (rc > 0)
virTypedParamListAddInt(params, thread_val, VIR_DOMAIN_IOTHREAD_THREAD_POOL_MIN);
#define VSH_IOTHREAD_SET_INT_PARAMS(opt, param) \ if ((rc = vshCommandOptInt(ctl, cmd, "thread-pool-max", &thread_val)) < 0)
thread_val = -1; \ return false;
if ((rc = vshCommandOptInt(ctl, cmd, opt, &thread_val)) < 0) \ if (rc > 0)
goto cleanup; \ virTypedParamListAddInt(params, thread_val, VIR_DOMAIN_IOTHREAD_THREAD_POOL_MAX);
if (rc > 0 && \
virTypedParamsAddInt(&params, &nparams, &maxparams, \
param, thread_val) < 0) \
goto save_error;
VSH_IOTHREAD_SET_INT_PARAMS("thread-pool-min", VIR_DOMAIN_IOTHREAD_THREAD_POOL_MIN) if (virTypedParamListFetch(params, &par, &npar) < 0)
VSH_IOTHREAD_SET_INT_PARAMS("thread-pool-max", VIR_DOMAIN_IOTHREAD_THREAD_POOL_MAX) return false;
#undef VSH_IOTHREAD_SET_INT_PARAMS
if (nparams == 0) { if (npar == 0) {
vshError(ctl, _("Not enough arguments passed, nothing to set")); vshError(ctl, _("Not enough arguments passed, nothing to set"));
goto cleanup; return false;
} }
if (virDomainSetIOThreadParams(dom, id, params, nparams, flags) < 0) if (virDomainSetIOThreadParams(dom, id, par, npar, flags) < 0)
goto cleanup; return false;
ret = true; return true;
cleanup:
virTypedParamsFree(params, nparams);
return ret;
save_error:
vshSaveLibvirtError();
goto cleanup;
} }