threadpool_params.c 2.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#include<stdio.h>
#include<stdlib.h>
#include<libvirt/libvirt-admin.h>

int main(int argc, char **argv)
{
    int ret = -1;
    virAdmConnectPtr conn = NULL;
    virAdmServerPtr srv = NULL;     /* which server to work with */
    virTypedParameterPtr params = NULL;
    int nparams = 0;
12
    ssize_t i;
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

    if (argc != 2) {
        fprintf(stderr, "One argument specifying the server which to work "
                "with is expected\n");
        return -1;
    }

    /* first, open a connection to the daemon */
    if (!(conn = virAdmConnectOpen(NULL, 0)))
        goto cleanup;

    /* a server handle is necessary before any API regarding threadpool
     * parameters can be issued
     */
    if (!(srv = virAdmConnectLookupServer(conn, argv[1], 0)))
        goto cleanup;

    /* get the current threadpool parameters */
    if (virAdmServerGetThreadPoolParameters(srv, &params, &nparams, 0) < 0)
        goto cleanup;

    for (i = 0; i < nparams; i++)
        printf("%-15s: %d\n", params[i].field, params[i].value.ui);

    virTypedParamsFree(params, nparams);
    params = NULL;
    nparams = 0;

    /* let's set minWorkers to 10, maxWorkers to 15 and prioWorkers to 10 */
    int maxparams = 0;
    if (virTypedParamsAddUInt(&params, &nparams, &maxparams,
                              VIR_THREADPOOL_WORKERS_MIN, 10) < 0 ||
        virTypedParamsAddUInt(&params, &nparams, &maxparams,
                              VIR_THREADPOOL_WORKERS_MAX, 15) < 0 ||
        virTypedParamsAddUInt(&params, &nparams, &maxparams,
                              VIR_THREADPOOL_WORKERS_PRIORITY, 10) < 0)
        goto cleanup;

    /* now, change the threadpool settings to some different values */
    if (virAdmServerSetThreadPoolParameters(srv, params, nparams, 0) < 0)
        goto cleanup;

    ret = 0;
 cleanup:
    virTypedParamsFree(params, nparams);

    /* Once finished deallocate the server handle and close the connection
     * properly, @conn will be deallocated automatically
     */
    virAdmServerFree(srv);
    virAdmConnectClose(conn);
    return ret;
}