Wire up the server threadpool tunable APIs to virt-admin client.
---
tools/virt-admin.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 132 insertions(+)
diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index 3c818a3..21be830 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -350,6 +350,127 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
return ret;
}
+
+/* --------------------
+ * Command srv-workertune
+ * --------------------
+ */
+
+static const vshCmdInfo info_srv_workertune[] = {
+ {.name = "help",
+ .data = N_("Get or set server workerpool parameters")
+ },
+ {.name = "desc",
+ .data = N_("Get or set server workerpool parameters. Some parameters are
"
+ "read-only, thus only \n"
+ " a subset of all supported parameters can actually be "
+ "set via OPTIONS.\n"
+ " To retrieve workerpool parameters, use the command "
+ "without any options: \n\n"
+ " virt-admin # srv-workertune <server>")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_srv_workertune[] = {
+ {.name = "server",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("Server to get threadpool parameters for."),
+ },
+ {.name = "min-workers",
+ .type = VSH_OT_INT,
+ .help = N_("Change the value of bottom limit to number of workers."),
+ },
+ {.name = "max-workers",
+ .type = VSH_OT_INT,
+ .help = N_("Change the value of top limit to number of workers."),
+ },
+ {.name = "priority-workers",
+ .type = VSH_OT_INT,
+ .help = N_("Change the current number of priority workers"),
+ },
+ {.name = NULL}
+};
+
+static bool
+cmdSrvWorkertune(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+{
+ virTypedParameterPtr params = NULL;
+ int nparams = 0;
+ int maxparams = 0;
+ unsigned int val;
+ unsigned int min, max;
+ int rv = 0;
+ size_t i;
+ bool ret = false;
+ const char *srvname = NULL;
+ virAdmServerPtr srv = NULL;
+ vshAdmControlPtr priv = ctl->privData;
+
+ if (vshCommandOptStringReq(ctl, cmd, "server", &srvname) < 0)
+ return false;
+
+#define PARSE_WORKERTUNE_PARAM(NAME, FIELD) \
+ if ((rv = vshCommandOptUInt(ctl, cmd, NAME, &val)) < 0) { \
+ vshError(ctl, _("Unable to parse integer parameter '%s'"),
NAME); \
+ goto cleanup; \
+ } else if (rv > 0) { \
+ if (virTypedParamsAddUInt(¶ms, &nparams, &maxparams,
\
+ FIELD, val) < 0) \
+ goto save_error; \
+ }
+
+ PARSE_WORKERTUNE_PARAM("max-workers", VIR_THREADPOOL_WORKERS_MAX);
+ PARSE_WORKERTUNE_PARAM("min-workers", VIR_THREADPOOL_WORKERS_MIN);
+ PARSE_WORKERTUNE_PARAM("priority-workers",
VIR_THREADPOOL_WORKERS_PRIORITY);
+
+#undef PARSE_WORKERTUNE_PARAM
+
+ if (virTypedParamsGetUInt(params, nparams,
+ VIR_THREADPOOL_WORKERS_MAX, &max) &&
+ virTypedParamsGetUInt(params, nparams,
+ VIR_THREADPOOL_WORKERS_MIN, &min) && min >
max) {
+ vshError(ctl, "%s", _("--min-workers must be less than
--max-workers"));
+ goto cleanup;
+ }
+
+ if (!(srv = virAdmConnectServerLookupByName(priv->conn, srvname)))
+ goto cleanup;
+
+ /* set server threadpool parameters */
+ if (nparams) {
+ if (virAdmServerSetThreadPoolParameters(srv, params,
+ nparams, 0) < 0)
+ goto error;
+ } else {
+ if (virAdmServerGetThreadPoolParameters(srv, ¶ms,
+ &nparams, 0) < 0) {
+ vshError(ctl, "%s",
+ _("Unable to get server workerpool parameters"));
+ goto cleanup;
+ }
+
+ for (i = 0; i < nparams; i++)
+ vshPrint(ctl, "%-15s: %d\n", params[i].field, params[i].value.ui);
+ }
+
+ ret = true;
+
+ cleanup:
+ virTypedParamsFree(params, nparams);
+ if (srv)
+ virAdmServerFree(srv);
+ return ret;
+
+ save_error:
+ vshSaveLibvirtError();
+
+ error:
+ vshError(ctl, "%s", _("Unable to change server workerpool
parameters"));
+ goto cleanup;
+}
+
static void *
vshAdmConnectionHandler(vshControl *ctl)
{
@@ -652,9 +773,20 @@ static const vshCmdDef monitoringCmds[] = {
{.name = NULL}
};
+static const vshCmdDef managementCmds[] = {
+ {.name = "srv-workertune",
+ .handler = cmdSrvWorkertune,
+ .opts = opts_srv_workertune,
+ .info = info_srv_workertune,
+ .flags = 0
+ },
+ {.name = NULL}
+};
+
static const vshCmdGrp cmdGroups[] = {
{"Virt-admin itself", "virt-admin", vshAdmCmds},
{"Monitoring commands", "monitor", monitoringCmds},
+ {"Management commands", "management", managementCmds},
{NULL, NULL, NULL}
};
--
2.4.3