From nobody Tue Feb 10 01:15:29 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=1565166700; cv=none; d=zoho.com; s=zohoarc; b=ETOL6KLBjWIXSCfp8MO2fBHFDvNakBoNDXYDSY9j5Zc1JWzVN+dznuBo0/vqFCW3h6VqDDeePhfTnlUWIf/cI13KV1opfai7v5Rgqq+Il/oAvcJu+ZmO9HglitiK068niPnQPFjrR0hG+i5YFdJY9Th5n4glI+/2oNhdotAd+XI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565166700; 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=kxR26H48eWkkOLvvbnQ0HTAceYpC6uPGRV798NbuV4s=; b=jdTnz+HwSfMT9iU5Du0jlJkPs8o4RzVLyxdSuk9MAaDsZrFHmuF1RCuNJ6r3Z+9bSI/JcjwULACrLQ5a8JMtEpxxFwn6REGj5u9BWmRdFzWoUE3qr7redRI8gcRKYH0VAm2ilLOya/lz1vR23XaBTcq9HHDOGxjjG5/ToH5JWLQ= 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 1565166700132740.1138645216454; Wed, 7 Aug 2019 01:31:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EBA42F30D8; Wed, 7 Aug 2019 08:31:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 13D435D704; Wed, 7 Aug 2019 08:31:38 +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 C5E1F24F30; Wed, 7 Aug 2019 08:31:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x778VTPR025088 for ; Wed, 7 Aug 2019 04:31:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id B24CD10016F3; Wed, 7 Aug 2019 08:31:29 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D28810016E9 for ; Wed, 7 Aug 2019 08:31:29 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 7 Aug 2019 10:30:54 +0200 Message-Id: <0a737cab0c2366b83fad1e3d4e5df8f47a433da6.1565166420.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 11/15] tools: Separate snapshot 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 07 Aug 2019 08:31:39 +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 snapshot (e.g. they complete various snapshot aspects) into virsh-completer-snapshot.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-snapshot.c | 73 ++++++++++++++++++++++++++++++++ tools/virsh-completer-snapshot.h | 27 ++++++++++++ tools/virsh-completer.c | 45 -------------------- tools/virsh-completer.h | 5 +-- 5 files changed, 102 insertions(+), 49 deletions(-) create mode 100644 tools/virsh-completer-snapshot.c create mode 100644 tools/virsh-completer-snapshot.h diff --git a/tools/Makefile.am b/tools/Makefile.am index f229db39d8..3a89ec70a2 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -225,6 +225,7 @@ virsh_SOURCES =3D \ virsh-completer-nwfilter.c virsh-completer-nwfilter.h \ virsh-completer-pool.c virsh-completer-pool.h \ virsh-completer-secret.c virsh-completer-secret.h \ + virsh-completer-snapshot.c virsh-completer-snapshot.h \ virsh-completer-volume.c virsh-completer-volume.h \ virsh-console.c virsh-console.h \ virsh-domain.c virsh-domain.h \ diff --git a/tools/virsh-completer-snapshot.c b/tools/virsh-completer-snaps= hot.c new file mode 100644 index 0000000000..cad56e2fba --- /dev/null +++ b/tools/virsh-completer-snapshot.c @@ -0,0 +1,73 @@ +/* + * virsh-completer-snapshot.c: virsh completer callbacks related to snapsh= ots + * + * 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-snapshot.h" +#include "viralloc.h" +#include "virsh-util.h" +#include "virsh.h" +#include "virstring.h" + +char ** +virshSnapshotNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virDomainPtr dom =3D NULL; + virDomainSnapshotPtr *snapshots =3D NULL; + int rc; + int nsnapshots =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return NULL; + + if ((rc =3D virDomainListAllSnapshots(dom, &snapshots, flags)) < 0) + goto cleanup; + nsnapshots =3D rc; + + if (VIR_ALLOC_N(tmp, nsnapshots + 1) < 0) + goto cleanup; + + for (i =3D 0; i < nsnapshots; i++) { + const char *name =3D virDomainSnapshotGetName(snapshots[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + virshDomainFree(dom); + for (i =3D 0; i < nsnapshots; i++) + virshDomainSnapshotFree(snapshots[i]); + VIR_FREE(snapshots); + return ret; +} diff --git a/tools/virsh-completer-snapshot.h b/tools/virsh-completer-snaps= hot.h new file mode 100644 index 0000000000..1af32e28ca --- /dev/null +++ b/tools/virsh-completer-snapshot.h @@ -0,0 +1,27 @@ +/* + * virsh-completer-snapshot.h: virsh completer callbacks related to snapsh= ots + * + * 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 ** virshSnapshotNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 3489f8741a..72223803dd 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -194,51 +194,6 @@ virshCheckpointNameCompleter(vshControl *ctl, return NULL; } =20 -char ** -virshSnapshotNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virDomainPtr dom =3D NULL; - virDomainSnapshotPtr *snapshots =3D NULL; - int rc; - int nsnapshots =3D 0; - size_t i =3D 0; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(0, NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - return NULL; - - if ((rc =3D virDomainListAllSnapshots(dom, &snapshots, flags)) < 0) - goto cleanup; - nsnapshots =3D rc; - - if (VIR_ALLOC_N(tmp, nsnapshots + 1) < 0) - goto cleanup; - - for (i =3D 0; i < nsnapshots; i++) { - const char *name =3D virDomainSnapshotGetName(snapshots[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - virshDomainFree(dom); - for (i =3D 0; i < nsnapshots; i++) - virshDomainSnapshotFree(snapshots[i]); - VIR_FREE(snapshots); - return ret; -} =20 static char * virshPagesizeNodeToString(xmlNodePtr node) diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index e27d58e536..4ebd61f3be 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -29,6 +29,7 @@ #include "virsh-completer-nwfilter.h" #include "virsh-completer-pool.h" #include "virsh-completer-secret.h" +#include "virsh-completer-snapshot.h" #include "virsh-completer-volume.h" =20 char ** virshCommaStringListComplete(const char *input, @@ -38,10 +39,6 @@ char ** virshCheckpointNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); =20 -char ** virshSnapshotNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshAllocpagesPagesizeCompleter(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