[PATCH v4 11/11] virt-admin: Introduce srv-threadpool-info and srv-threadpool-set commands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Wire up the server threadpool tunable APIs to virt-admin client.

Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 tools/virt-admin.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 185 insertions(+)

diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index f0a49a3..38936d1 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -353,6 +353,174 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     return ret;
 }
 
+
+/* ---------------------------
+ * Command srv-threadpool-info
+ * ---------------------------
+ */
+
+static const vshCmdInfo info_srv_threadpool_info[] = {
+    {.name = "help",
+     .data = N_("get server workerpool parameters")
+    },
+    {.name = "desc",
+     .data = N_("Retrieve threadpool attributes from a server. ")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_srv_threadpool_info[] = {
+    {.name = "server",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("Server to retrieve threadpool attributes from."),
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdSrvThreadpoolInfo(vshControl *ctl, const vshCmd *cmd)
+{
+    bool ret = false;
+    virTypedParameterPtr params = NULL;
+    int nparams = 0;
+    size_t i;
+    const char *srvname = NULL;
+    virAdmServerPtr srv = NULL;
+    vshAdmControlPtr priv = ctl->privData;
+
+    if (vshCommandOptStringReq(ctl, cmd, "server", &srvname) < 0)
+        return false;
+
+    if (!(srv = virAdmConnectLookupServer(priv->conn, srvname, 0)))
+        goto cleanup;
+
+    if (virAdmServerGetThreadPoolParameters(srv, &params,
+                                            &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;
+}
+
+/* --------------------------
+ * Command srv-threadpool-set
+ * --------------------------
+ */
+
+static const vshCmdInfo info_srv_threadpool_set[] = {
+    {.name = "help",
+     .data = N_("set server workerpool parameters")
+    },
+    {.name = "desc",
+     .data = N_("Tune threadpool attributes on a server. See OPTIONS for "
+                "currently supported attributes.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_srv_threadpool_set[] = {
+    {.name = "server",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("Server to alter threadpool attributes on."),
+    },
+    {.name = "min-workers",
+     .type = VSH_OT_INT,
+     .help = N_("Change bottom limit to number of workers."),
+    },
+    {.name = "max-workers",
+     .type = VSH_OT_INT,
+     .help = N_("Change upper 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
+cmdSrvThreadpoolSet(vshControl *ctl, const vshCmd *cmd)
+{
+    bool ret = false;
+    int rv = 0;
+    unsigned int val, min, max;
+    int maxparams = 0;
+    int nparams = 0;
+    const char *srvname = NULL;
+    virTypedParameterPtr params = NULL;
+    virAdmServerPtr srv = NULL;
+    vshAdmControlPtr priv = ctl->privData;
+
+    if (vshCommandOptStringReq(ctl, cmd, "server", &srvname) < 0)
+        return false;
+
+#define PARSE_CMD_TYPED_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(&params, &nparams, &maxparams,             \
+                                  FIELD, val) < 0)                           \
+        goto save_error;                                                     \
+    }
+
+    PARSE_CMD_TYPED_PARAM("max-workers", VIR_THREADPOOL_WORKERS_MAX);
+    PARSE_CMD_TYPED_PARAM("min-workers", VIR_THREADPOOL_WORKERS_MIN);
+    PARSE_CMD_TYPED_PARAM("priority-workers", VIR_THREADPOOL_WORKERS_PRIORITY);
+
+#undef PARSE_CMD_TYPED_PARAM
+
+    if (!nparams) {
+        vshError(ctl, "%s",
+                 _("At least one of options --min-workers, --max-workers, "
+                   "--priority-workers is mandatory "));
+            goto cleanup;
+    }
+
+    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 = virAdmConnectLookupServer(priv->conn, srvname, 0)))
+        goto cleanup;
+
+    if (virAdmServerSetThreadPoolParameters(srv, params,
+                                            nparams, 0) < 0)
+        goto error;
+
+    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,12 +820,29 @@ static const vshCmdDef monitoringCmds[] = {
      .info = info_srv_list,
      .flags = 0
     },
+    {.name = "srv-threadpool-info",
+     .handler = cmdSrvThreadpoolInfo,
+     .opts = opts_srv_threadpool_info,
+     .info = info_srv_threadpool_info,
+     .flags = 0
+    },
+    {.name = NULL}
+};
+
+static const vshCmdDef managementCmds[] = {
+    {.name = "srv-threadpool-set",
+     .handler = cmdSrvThreadpoolSet,
+     .opts = opts_srv_threadpool_set,
+     .info = info_srv_threadpool_set,
+     .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.11

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]