From nobody Mon Feb 9 02:42:14 2026 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563526141; cv=none; d=zoho.com; s=zohoarc; b=GPduoIA8g/MobpDzFez/4sd1bICOmRXfYIDTxGwZ0Wpf61Q6HlWCGHSqJ4dCCg06qUIaYFqcm4prtVLGE6BJEOw2RCfIFbHico/WZgly6AIcEyCHLX/ku+pTjirlc/vG3G4UalKGph8Z/9Jd9z0ZXv2eQY0cmzXzlANzCZVd4hY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526141; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=iNWpPDMDIPfDDGWgpjcK6waYQFlU8oR/uk2ldA2zV68=; b=TCP5Zf5NRxtdkUzAI7gLmPF61YtPix7EIPh6tjmCIMJFjYU330wFr7dEuScHOPbconpBfuhhnmPfm67OoVhx4Gs0w8CQMIIUoFzzTJg/2t0gkThv48TiloJTM3eEjG+hQW0ZPGaAhJLU4FJayXkRE/bhaclOCfNq81KQsF2Cq/4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563526141486634.966343647617; Fri, 19 Jul 2019 01:49:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF9FD30860D7; Fri, 19 Jul 2019 08:48:59 +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 948A061B6A; Fri, 19 Jul 2019 08:48:59 +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 518EF180020A; Fri, 19 Jul 2019 08:48:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6J8muWv005293 for ; Fri, 19 Jul 2019 04:48:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3B235601A9; Fri, 19 Jul 2019 08:48:56 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9AB260126 for ; Fri, 19 Jul 2019 08:48:53 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:36 +0200 Message-Id: <47074637045654218ac04a868ac20c043bee54e8.1563525985.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/14] tools: Separate host related completers into a file 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: , 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 19 Jul 2019 08:49:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Mixing all completers in one file does not support maintainability. Separate those completers which relate to host (e.g. they complete various host aspects) into virsh-completer-host.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-host.c | 148 +++++++++++++++++++++++++++++++++++ tools/virsh-completer-host.h | 31 ++++++++ tools/virsh-completer.c | 119 ---------------------------- tools/virsh-completer.h | 9 +-- 5 files changed, 181 insertions(+), 127 deletions(-) create mode 100644 tools/virsh-completer-host.c create mode 100644 tools/virsh-completer-host.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 231ee0e0bd..2364812e73 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -218,6 +218,7 @@ virsh_SOURCES =3D \ virsh.c virsh.h \ virsh-completer.c virsh-completer.h \ virsh-completer-domain.c virsh-completer-domain.h \ + virsh-completer-host.c virsh-completer-host.h \ virsh-completer-interface.c virsh-completer-interface.h \ virsh-completer-network.c virsh-completer-network.h \ virsh-completer-nodedev.c virsh-completer-nodedev.h \ diff --git a/tools/virsh-completer-host.c b/tools/virsh-completer-host.c new file mode 100644 index 0000000000..7e31ca2bf3 --- /dev/null +++ b/tools/virsh-completer-host.c @@ -0,0 +1,148 @@ +/* + * virsh-completer-host.c: virsh completer callbacks related to host + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virsh-completer-host.h" +#include "viralloc.h" +#include "virsh.h" +#include "virstring.h" +#include "virxml.h" +#include "virutil.h" + +static char * +virshPagesizeNodeToString(xmlNodePtr node) +{ + VIR_AUTOFREE(char *) pagesize =3D NULL; + VIR_AUTOFREE(char *) unit =3D NULL; + unsigned long long byteval =3D 0; + const char *suffix =3D NULL; + double size =3D 0; + char *ret; + + pagesize =3D virXMLPropString(node, "size"); + unit =3D virXMLPropString(node, "unit"); + if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0) + return NULL; + if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) + return NULL; + size =3D vshPrettyCapacity(byteval, &suffix); + if (virAsprintf(&ret, "%.0f%s", size, suffix) < 0) + return NULL; + return ret; +} + +char ** +virshAllocpagesPagesizeCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + virshControlPtr priv =3D ctl->privData; + unsigned int npages =3D 0; + VIR_AUTOFREE(xmlNodePtr *) pages =3D NULL; + VIR_AUTOPTR(xmlDoc) doc =3D NULL; + size_t i =3D 0; + const char *cellnum =3D NULL; + bool cellno =3D vshCommandOptBool(cmd, "cellno"); + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) cap_xml =3D NULL; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) + return NULL; + + if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) + return NULL; + + if (cellno && vshCommandOptStringQuiet(ctl, cmd, "cellno", &cellnum) >= 0) { + if (virAsprintf(&path, + "/capabilities/host/topology/cells/cell[@id=3D\"%s= \"]/pages", + cellnum) < 0) + return NULL; + } else { + if (virAsprintf(&path, "/capabilities/host/cpu/pages") < 0) + return NULL; + } + + npages =3D virXPathNodeSet(path, ctxt, &pages); + if (npages <=3D 0) + return NULL; + + if (VIR_ALLOC_N(tmp, npages + 1) < 0) + return NULL; + + for (i =3D 0; i < npages; i++) { + if (!(tmp[i] =3D virshPagesizeNodeToString(pages[i]))) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} + + +char ** +virshCellnoCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + virshControlPtr priv =3D ctl->privData; + unsigned int ncells =3D 0; + VIR_AUTOFREE(xmlNodePtr *) cells =3D NULL; + VIR_AUTOPTR(xmlDoc) doc =3D NULL; + size_t i =3D 0; + VIR_AUTOFREE(char *) cap_xml =3D NULL; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) + return NULL; + + if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) + return NULL; + + ncells =3D virXPathNodeSet("/capabilities/host/topology/cells/cell", c= txt, &cells); + if (ncells <=3D 0) + return NULL; + + if (VIR_ALLOC_N(tmp, ncells + 1)) + return NULL; + + for (i =3D 0; i < ncells; i++) { + if (!(tmp[i] =3D virXMLPropString(cells[i], "id"))) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} diff --git a/tools/virsh-completer-host.h b/tools/virsh-completer-host.h new file mode 100644 index 0000000000..921beb7a2d --- /dev/null +++ b/tools/virsh-completer-host.h @@ -0,0 +1,31 @@ +/* + * virsh-completer-host.h: virsh completer callbacks related to host + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "vsh.h" + +char ** virshAllocpagesPagesizeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshCellnoCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index fc46cb6575..0f1709b4ba 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -141,122 +141,3 @@ virshCommaStringListComplete(const char *input, =20 VIR_RETURN_PTR(ret); } -static char * -virshPagesizeNodeToString(xmlNodePtr node) -{ - VIR_AUTOFREE(char *) pagesize =3D NULL; - VIR_AUTOFREE(char *) unit =3D NULL; - unsigned long long byteval =3D 0; - const char *suffix =3D NULL; - double size =3D 0; - char *ret; - - pagesize =3D virXMLPropString(node, "size"); - unit =3D virXMLPropString(node, "unit"); - if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0) - return NULL; - if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) - return NULL; - size =3D vshPrettyCapacity(byteval, &suffix); - if (virAsprintf(&ret, "%.0f%s", size, suffix) < 0) - return NULL; - return ret; -} - -char ** -virshAllocpagesPagesizeCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; - virshControlPtr priv =3D ctl->privData; - unsigned int npages =3D 0; - VIR_AUTOFREE(xmlNodePtr *) pages =3D NULL; - VIR_AUTOPTR(xmlDoc) doc =3D NULL; - size_t i =3D 0; - const char *cellnum =3D NULL; - bool cellno =3D vshCommandOptBool(cmd, "cellno"); - VIR_AUTOFREE(char *) path =3D NULL; - VIR_AUTOFREE(char *) cap_xml =3D NULL; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(0, NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) - return NULL; - - if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) - return NULL; - - if (cellno && vshCommandOptStringQuiet(ctl, cmd, "cellno", &cellnum) >= 0) { - if (virAsprintf(&path, - "/capabilities/host/topology/cells/cell[@id=3D\"%s= \"]/pages", - cellnum) < 0) - return NULL; - } else { - if (virAsprintf(&path, "/capabilities/host/cpu/pages") < 0) - return NULL; - } - - npages =3D virXPathNodeSet(path, ctxt, &pages); - if (npages <=3D 0) - return NULL; - - if (VIR_ALLOC_N(tmp, npages + 1) < 0) - return NULL; - - for (i =3D 0; i < npages; i++) { - if (!(tmp[i] =3D virshPagesizeNodeToString(pages[i]))) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} - - -char ** -virshCellnoCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; - virshControlPtr priv =3D ctl->privData; - unsigned int ncells =3D 0; - VIR_AUTOFREE(xmlNodePtr *) cells =3D NULL; - VIR_AUTOPTR(xmlDoc) doc =3D NULL; - size_t i =3D 0; - VIR_AUTOFREE(char *) cap_xml =3D NULL; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(0, NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) - return NULL; - - if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) - return NULL; - - ncells =3D virXPathNodeSet("/capabilities/host/topology/cells/cell", c= txt, &cells); - if (ncells <=3D 0) - return NULL; - - if (VIR_ALLOC_N(tmp, ncells + 1)) - return NULL; - - for (i =3D 0; i < ncells; i++) { - if (!(tmp[i] =3D virXMLPropString(cells[i], "id"))) - return NULL; - } - - VIR_STEAL_PTR(ret, tmp); - return ret; -} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 79a41c0a8a..7ea3345973 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -23,6 +23,7 @@ #include "vsh.h" =20 #include "virsh-completer-domain.h" +#include "virsh-completer-host.h" #include "virsh-completer-interface.h" #include "virsh-completer-network.h" #include "virsh-completer-nodedev.h" @@ -34,11 +35,3 @@ =20 char ** virshCommaStringListComplete(const char *input, const char **options); - -char ** virshAllocpagesPagesizeCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - -char ** virshCellnoCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list