From nobody Mon Sep 16 19:22:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 171683507674869.4412276150232; Mon, 27 May 2024 11:37:56 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6EF02198C; Mon, 27 May 2024 14:37:55 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 56C031995; Mon, 27 May 2024 14:37:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1D1B718BF; Mon, 27 May 2024 14:37:00 -0400 (EDT) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id EA78C197B for ; Mon, 27 May 2024 14:36:58 -0400 (EDT) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1f480624d0fso625365ad.1 for ; Mon, 27 May 2024 11:36:58 -0700 (PDT) Received: from test.. ([14.139.82.6]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f4b411b3c1sm13722925ad.277.2024.05.27.11.36.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 11:36:57 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716835018; x=1717439818; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=D8Qz8LpupcRcZlbQ1hjRh6D8xVCUs3H61n1/krobXZM=; b=MNF5DjE4RG2k2mzOGUvcEIQvc46Jvls78w7Dvi9cmtYH987B0+1D6QsbqEIk3Loy7p letXAgBtOiB7UxIl+JeuTTE/9IFb1iOWck3e4yoy+0iB594sqi+8+KsXj06n7tERdC5d Hlwijs3/UtKjPMJlc1Zjx0n2Q+eu0+ULP8lCP62sa1/rNDDVWh9RXSVDeKWct9TmmVpc yVkljFKTIciHaLUYzy232109QSU1mGWjPgD6wW6VHrLQT8cGXcxkiOLo8hwUchQ4zWnX Dpw0kLdwOmSDmNg4akMqbt+1iGNwBkw9pifuhjLuPMMtwGHxpeLS3XgWrwY9UzUaCUkh dU9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716835018; x=1717439818; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=D8Qz8LpupcRcZlbQ1hjRh6D8xVCUs3H61n1/krobXZM=; b=LS7LYK0wctob5uzbHPp0qvf5vr7XBV6WPxS4DjFV8G0bIN+sCbGIe5VLWMQlTEm6ay 9qS25TP3DaTs9nZX43BUUyhATz5QvEH9StYSuHDiWYJcMXTPLg3NgDFQ9i10vATHvSy3 jv1FkOABeYkMPcrjDdDW/nJoVzxJqKTYeo4fhY2UjnxLJO57808LbCJPGJbwe0wG8Bbp jfxErIQz9orIf7VyJU53wZEm7LI4BJB+uRubUbCtQv53k8GlyCJYRJm0KsCXl2Rx708D 5wT/UZZtRfs6VOthoTv3BXsq7H2fqMACHhDI8bsH3jA8GZRVtjPv2Uma/Z23oO4JpNgi gv3g== X-Gm-Message-State: AOJu0Yw6k9Ckr0FIndeefNwQscIOoMOIlFZE39SkqEWQt/DHoD2Sw2wj HBLAogeOQGky1fW6GwwmVAqu1bwPj2zujIeCT0ITNcuFH2tBF/Emxwry+YIL X-Google-Smtp-Source: AGHT+IHN1vu2Yn5gfbFJoVsY/lHUeI5oqkl/8jwkudcYZC0EuPcTEzvjTRP9hwPzSuMAVE+78bG7mQ== X-Received: by 2002:a17:903:18e:b0:1f4:bcef:e970 with SMTP id d9443c01a7336-1f4bceff4ccmr13509075ad.55.1716835017441; Mon, 27 May 2024 11:36:57 -0700 (PDT) From: Abhiram Tilak To: devel@lists.libvirt.org Subject: [PATCH] virsh: Provide completer for some pool-X-as commands Date: Mon, 27 May 2024 18:34:38 +0000 Message-Id: <20240527183437.31518-1-atp.exp@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: NVGRLW3CWDVVFAECX2P5SYK3LLWMZVUY X-Message-ID-Hash: NVGRLW3CWDVVFAECX2P5SYK3LLWMZVUY X-MailFrom: atp.exp@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Abhiram Tilak X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1716835077320100001 Content-Type: text/plain; charset="utf-8" Provides completers for auth-type and source-format commands for virsh pool-create-as and pool-define-as commands. Use Empty completers for options where completions are not required. I left the ones where I was not sure if they need completers. Related Issue: https://gitlab.com/libvirt/libvirt/-/issues/9 Signed-off-by: Abhiram Tilak --- src/libvirt_private.syms | 2 ++ tools/virsh-completer-pool.c | 48 +++++++++++++++++++++++++++++++++++- tools/virsh-completer-pool.h | 10 ++++++++ tools/virsh-pool.c | 8 ++++++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 6b6bcc368a..5a413ca832 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1117,6 +1117,8 @@ virStorageAuthDefCopy; virStorageAuthDefFormat; virStorageAuthDefFree; virStorageAuthDefParse; +virStorageAuthTypeFromString; +virStorageAuthTypeToString; virStorageFileFeatureTypeFromString; virStorageFileFeatureTypeToString; virStorageFileFormatTypeFromString; diff --git a/tools/virsh-completer-pool.c b/tools/virsh-completer-pool.c index 3568bb985b..4a771d894e 100644 --- a/tools/virsh-completer-pool.c +++ b/tools/virsh-completer-pool.c @@ -84,7 +84,6 @@ virshPoolEventNameCompleter(vshControl *ctl G_GNUC_UNUSED, return g_steal_pointer(&tmp); } =20 - char ** virshPoolTypeCompleter(vshControl *ctl, const vshCmd *cmd, @@ -106,3 +105,50 @@ virshPoolTypeCompleter(vshControl *ctl, =20 return virshCommaStringListComplete(type_str, (const char **)tmp); } + +char ** +virshPoolFormatCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + size_t i =3D 0, j =3D 0; + g_auto(GStrv) tmp =3D NULL; + size_t nformats =3D VIR_STORAGE_POOL_FS_LAST + VIR_STORAGE_POOL_NETFS_= LAST + + VIR_STORAGE_POOL_DISK_LAST + VIR_STORAGE_POOL_LOGICAL_LAST; + + virCheckFlags(0, NULL); + + tmp =3D g_new0(char *, nformats + 1); + + /* Club all PoolFormats for completion */ + for (i =3D 0; i < VIR_STORAGE_POOL_FS_LAST; i++) + tmp[j++] =3D g_strdup(virStoragePoolFormatFileSystemTypeToString(i= )); + + for (i =3D 0; i < VIR_STORAGE_POOL_NETFS_LAST; i++) + tmp[j++] =3D g_strdup(virStoragePoolFormatFileSystemNetTypeToStrin= g(i)); + + for (i =3D 0; i < VIR_STORAGE_POOL_DISK_LAST; i++) + tmp[j++] =3D g_strdup(virStoragePoolFormatDiskTypeToString(i)); + + for (i =3D 0; i < VIR_STORAGE_POOL_LOGICAL_LAST; i++) + tmp[j++] =3D g_strdup(virStoragePoolFormatLogicalTypeToString(i)); + + return g_steal_pointer(&tmp); +} + +char ** virshPoolAuthTypeCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + size_t i =3D 0; + g_auto(GStrv) tmp =3D NULL; + + virCheckFlags(0, NULL); + + tmp =3D g_new0(char *, VIR_STORAGE_AUTH_TYPE_LAST + 1); + + for (i =3D 0; i < VIR_STORAGE_AUTH_TYPE_LAST; i++) + tmp[i] =3D g_strdup(virStorageAuthTypeToString(i)); + + return g_steal_pointer(&tmp); +} diff --git a/tools/virsh-completer-pool.h b/tools/virsh-completer-pool.h index bff3e5742b..4a53f99577 100644 --- a/tools/virsh-completer-pool.h +++ b/tools/virsh-completer-pool.h @@ -40,3 +40,13 @@ char ** virshPoolTypeCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** +virshPoolFormatCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshPoolAuthTypeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 67cc1b94cf..1a294bb0f6 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -81,26 +81,32 @@ }, \ {.name =3D "source-path", \ .type =3D VSH_OT_STRING, \ + .completer =3D virshCompletePathLocalExisting, \ .help =3D N_("source path for underlying storage") \ }, \ {.name =3D "source-dev", \ .type =3D VSH_OT_STRING, \ + .completer =3D virshCompleteEmpty, \ .help =3D N_("source device for underlying storage") \ }, \ {.name =3D "source-name", \ .type =3D VSH_OT_STRING, \ + .completer =3D virshCompleteEmpty, \ .help =3D N_("source name for underlying storage") \ }, \ {.name =3D "target", \ .type =3D VSH_OT_STRING, \ + .completer =3D virshCompleteEmpty, \ .help =3D N_("target for underlying storage") \ }, \ {.name =3D "source-format", \ .type =3D VSH_OT_STRING, \ + .completer =3D virshPoolFormatCompleter, \ .help =3D N_("format for underlying storage") \ }, \ {.name =3D "auth-type", \ .type =3D VSH_OT_STRING, \ + .completer =3D virshPoolAuthTypeCompleter, \ .help =3D N_("auth type to be used for underlying storage") \ }, \ {.name =3D "auth-username", \ @@ -118,6 +124,7 @@ }, \ {.name =3D "adapter-name", \ .type =3D VSH_OT_STRING, \ + .completer =3D virshCompleteEmpty, \ .help =3D N_("adapter name to be used for underlying storage") \ }, \ {.name =3D "adapter-wwnn", \ @@ -146,6 +153,7 @@ }, \ {.name =3D "source-protocol-ver", \ .type =3D VSH_OT_STRING, \ + .completer =3D virshCompleteEmpty, \ .help =3D N_("nfsvers value for NFS pool mount option") \ }, \ {.name =3D "source-initiator", \ --=20 2.34.1