From nobody Fri May 3 15:22:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1526903652351205.00435665880605; Mon, 21 May 2018 04:54:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2421831677FF; Mon, 21 May 2018 11:54:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04D705DD85; Mon, 21 May 2018 11:54:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C5DF8180B536; Mon, 21 May 2018 11:54:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4LBs2ua020334 for ; Mon, 21 May 2018 07:54:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id CA25B977D3; Mon, 21 May 2018 11:54:02 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C35A5977D2 for ; Mon, 21 May 2018 11:53:59 +0000 (UTC) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0415530CE3B4 for ; Mon, 21 May 2018 11:53:48 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id l1-v6so26189663wmb.2 for ; Mon, 21 May 2018 04:53:47 -0700 (PDT) Received: from rolandPC.redhat.com ([213.175.37.12]) by smtp.gmail.com with ESMTPSA id q81-v6sm12709240wmd.14.2018.05.21.04.53.45 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 May 2018 04:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=HRa1lz/dwuLvrrjy+p/kQWdRsKut04TdgyHbG9bzE0g=; b=cmk9otaxC9UdkRzCVVls8eR0FO+MrlZ4CpqwC6vmoOuQnXGuIX3058n7wNCZrWJ/+p 3gjhWZB8t6edPNiw0izfg5GnAhFp0SMCL36dAgdDJKNnvXMhU/i1RnU6d3WbsdH6fuvO uin0gatje1wN8wMgXApeaWC/kJKLX5/iLLBXGM7Y6MPwLZJn8NlXpir9kcvknIwCn7aU m7cz1gw3b/hLthm7fYvG97/kYP78zHVmEhH48Ic+uSIiLzeTZIlWYYJQZAQhqKR3pnQZ SFx/jTUiCifM54TdRQUjCCb345acLTh2cmMaF908Qee9ndMNgUE0lOgvoWcY7Cg5DmEg m0fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=HRa1lz/dwuLvrrjy+p/kQWdRsKut04TdgyHbG9bzE0g=; b=GgDwPF/rcGQnzp/dki1sV658QCiNqrmCPWJyWlt+brln4vD3eDZ1EhALq6dZL/Z9pc th3kepvU41fWAhNkN6Gd7bYlPhdgal8F5WySFSseE3B9F+Uhk2tuXmuWOAwpo6+z1oFm d6u1X+AvGQWdU9jeg4gS2pKyW/qKHceBYKVQP+PvtInGjAHl2rXhLa44WHwLWWJr/qYS ZT62NPhPClg/1ze7h0IFF3NilQi0EjC51CCIhzjDMK65wbkLlxi1DBbr9aN9JUpf5A9m SgzvxETDghOTrsQhpza4GOMzQlxzKMYji4atLx4EYC5ZuzhH5OCeFp64f9VSDjnnQNmr EMOQ== X-Gm-Message-State: ALKqPwfEZBnprSNKzrB/YUhK1fAX331c532XzPUpqVcac0K0Ul0nogf8 K7YAtNwRNbREOe8g+vn56Vi31A== X-Google-Smtp-Source: AB8JxZpJOtaqIRfOEklN19qBwAGQPzuxRjNWYMarc+yxcBwDh3x+WMaHd1Bi5hbcxfKtBAN+3wWJOA== X-Received: by 2002:a1c:8b88:: with SMTP id n130-v6mr10134814wmd.8.1526903626337; Mon, 21 May 2018 04:53:46 -0700 (PDT) From: Roland Schulz To: libvir-list@redhat.com Date: Mon, 21 May 2018 13:53:44 +0200 Message-Id: <20180521115344.4165-1-schullzroll@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 21 May 2018 11:53:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 21 May 2018 11:53:48 +0000 (UTC) for IP:'74.125.82.65' DOMAIN:'mail-wm0-f65.google.com' HELO:'mail-wm0-f65.google.com' FROM:'schullzroll@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 74.125.82.65 mail-wm0-f65.google.com 74.125.82.65 mail-wm0-f65.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] Add virshAllocpagesPagesizeCompleter X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 21 May 2018 11:54:11 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Returns list of host page sizes from capabilities xml Signed-off-by: Roland Schulz --- tools/virsh-completer.c | 71 +++++++++++++++++++++++++++++++++++++++++ tools/virsh-completer.h | 4 +++ tools/virsh-host.c | 1 + 3 files changed, 76 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index eb091070c..5f8a35b5f 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -27,6 +27,7 @@ #include "virsh-pool.h" #include "virsh-util.h" #include "internal.h" +#include "virutil.h" #include "viralloc.h" #include "virstring.h" #include "virxml.h" @@ -570,3 +571,73 @@ virshSnapshotNameCompleter(vshControl *ctl, virshDomainFree(dom); return NULL; } + +char ** +virshAllocpagesPagesizeCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + unsigned long long byteval =3D 0; + xmlXPathContextPtr ctxt =3D NULL; + virshControlPtr priv =3D ctl->privData; + unsigned int npages =3D 0; + xmlNodePtr *pages =3D NULL; + double size =3D 0; + size_t i =3D 0; + const char *suffix =3D NULL; + char *pagesize =3D NULL; + char *cap_xml =3D NULL; + char **ret =3D NULL; + char *unit =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + goto error; + + if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) + goto error; + + if (!(virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt))) + goto error; + + npages =3D virXPathNodeSet("/capabilities/host/cpu/pages", ctxt, &page= s); + if (npages <=3D 0) + goto error; + + if (VIR_ALLOC_N(ret, npages + 1) < 0) + goto error; + + for (i =3D 0; i < npages; i++) { + VIR_FREE(pagesize); + VIR_FREE(unit); + pagesize =3D virXMLPropString(pages[i], "size"); + unit =3D virXMLPropString(pages[i], "unit"); + if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0) + goto error; + if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) + goto error; + size =3D vshPrettyCapacity(byteval, &suffix); + if (virAsprintf(&ret[i], "%.0f%s", size, suffix) < 0) + goto error; + } + + cleanup: + xmlXPathFreeContext(ctxt); + for (i =3D 0; i < npages; i++) + VIR_FREE(pages[i]); + VIR_FREE(pages); + VIR_FREE(cap_xml); + VIR_FREE(pagesize); + VIR_FREE(unit); + + return ret; + + error: + if (ret) { + for (i =3D 0; i < npages; i++) + VIR_FREE(ret[i]); + } + VIR_FREE(ret); + goto cleanup; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index ae9626fea..c7b181879 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -74,4 +74,8 @@ char ** virshSnapshotNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 +char ** virshAllocpagesPagesizeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-host.c b/tools/virsh-host.c index ecaf830e3..293f06e9e 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -472,6 +472,7 @@ static const vshCmdOptDef opts_allocpages[] =3D { {.name =3D "pagesize", .type =3D VSH_OT_INT, .flags =3D VSH_OFLAG_REQ, + .completer =3D virshAllocpagesPagesizeCompleter, .help =3D N_("page size (in kibibytes)") }, {.name =3D "pagecount", --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list