From nobody Mon Sep 16 19:27:03 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 1721741777739943.3819411014982; Tue, 23 Jul 2024 06:36:17 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 87509CA6; Tue, 23 Jul 2024 09:36:16 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9D012CEE; Tue, 23 Jul 2024 09:35:50 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EC669CA6; Tue, 23 Jul 2024 09:35:46 -0400 (EDT) Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 1B6C9C92 for ; Tue, 23 Jul 2024 09:35:46 -0400 (EDT) Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7a1c7857a49so1395573a12.1 for ; Tue, 23 Jul 2024 06:35:46 -0700 (PDT) Received: from localhost.localdomain ([218.185.248.66]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ccf7c72075sm9100790a91.28.2024.07.23.06.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jul 2024 06:35:44 -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.8 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 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=1721741745; x=1722346545; 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=fkbF549dWKiMolNa2YVHnn6MZfEw7p+Malg1vlx0ytc=; b=UbWpnGN7Wu3CNwYoEiVq6Xo4PzsgOzrVPLLC8jG+6Yky35g6257+FTPwSc3Kpol2US Re5xdZah8R16gj20Q3ri13h9D+AgPsh359YM2R3sIRRp/19X2HkEWgkgdfqpByzZO56d 71+jjk+hd1Ib/f0c8mxXlS+CoFES5C60NmY6xqj4drRRkdb3jwG/b24i++Sonr6T/GuW bVFXTNpc8+7LaUMKh/qljRa1WaOagfkQUlUi1EUgLh1IAfVnOsvZQy5iqdHX7DsJyzFv WJx533JdMjk7qAOdhbyxJ19OCtGklcPY/OJN1K2U73EoKdV/gJoOICO/+2IDQe7TnT4r JCPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721741745; x=1722346545; 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=fkbF549dWKiMolNa2YVHnn6MZfEw7p+Malg1vlx0ytc=; b=ihMuLmGzYlgysYOKyfN/911WafZRR8+byToY9f3EUJBKgF8iP9ptpJ0y6pL6+VvDr9 XuU23B3czvWlGmIozQSRIng3+VPsDfZrepHwCgrCKlZEH68LXsEuuLf6j7HLG6wNWpXj qSmmmOgUvZMM7vrK8b4r6mj8hbCFlHNSCNb46mXxSecMM87jwoLVL+ICvMAyQLivMw9O rBXGHS/fHEtVmAx+ymp+klrn6z2UMmzbWQwQKSPW1W9Mxe8YkXWiznWuy1MMfoPKa9W3 YLOvG6yrTGiTrur4d6cEpW+X6hiJbSKpJufAd0/2U+Hj9igVrhV0J8Bhwr2a9b85M3/h 8JmQ== X-Gm-Message-State: AOJu0Yz+mglh9PhD9dDBU7p+UeNpSB9IfQTuqszEfLYnQIl1gRIpIU0N P98AY3uVOuM2v1Rxx30VI5XYIZvM4iqeaK/tL1SCfnN7u+adVHxiK3YlVw02 X-Google-Smtp-Source: AGHT+IEq8/6XVYheoi4P10iKyutF6hc+75Akd//K1tK6RUCUMdkkmzp9SnnKp0juBMBqKEPrp8gTjA== X-Received: by 2002:a05:6a20:b598:b0:1c3:3436:a244 with SMTP id adf61e73a8af0-1c42285f3b0mr9185182637.1.1721741744693; Tue, 23 Jul 2024 06:35:44 -0700 (PDT) From: Abhiram Tilak To: devel@lists.libvirt.org Subject: [PATCH v3] virsh: Provide completer for some pool-X-as commands Date: Tue, 23 Jul 2024 09:34:03 -0400 Message-Id: <20240723133402.64040-1-atp.exp@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: YKM5NVLW4ULLQV4V5AFAVPG7XKNG7IDU X-Message-ID-Hash: YKM5NVLW4ULLQV4V5AFAVPG7XKNG7IDU 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: notpua , 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: 1721741779544116600 Content-Type: text/plain; charset="utf-8" From: notpua 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. Related Issue: https://gitlab.com/libvirt/libvirt/-/issues/9 Signed-off-by: Abhiram Tilak --- Changes in v2: - Fix all formatting errors - Change some options using Empty completers, to use LocalPath completers. - Add completers for AdapterName and AdapterParent using information from node devices. Changes in v3: - Call virshNodeDeviceNameComplete with modified flags instead of=20 duplicating the whole implementation. src/libvirt_private.syms | 2 ++ tools/virsh-completer-pool.c | 70 ++++++++++++++++++++++++++++++++++++ tools/virsh-completer-pool.h | 20 +++++++++++ tools/virsh-pool.c | 9 +++++ 4 files changed, 101 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c35366c9e1..6ba1e8e2c5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1123,6 +1123,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..ba7855fdba 100644 --- a/tools/virsh-completer-pool.c +++ b/tools/virsh-completer-pool.c @@ -23,6 +23,7 @@ #include "virsh-completer-pool.h" #include "virsh-util.h" #include "conf/storage_conf.h" +#include "conf/node_device_conf.h" #include "virsh-pool.h" #include "virsh.h" =20 @@ -106,3 +107,72 @@ 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; + size_t 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 1; i < VIR_STORAGE_POOL_DISK_LAST; i++) + tmp[j++] =3D g_strdup(virStoragePoolFormatDiskTypeToString(i)); + + for (i =3D 1; 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); +} + + +char ** +virshAdapterNameCompleter(vshControl *ctl, + const vshCmd *cmd, unsigned int flags) +{ + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST; + return virshNodeDeviceNameCompleter(ctl, cmd, flags); +} + + +char ** +virshAdapterParentCompleter(vshControl *ctl, + const vshCmd *cmd, unsigned int flags) +{ + flags |=3D VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS; + return virshNodeDeviceNameCompleter(ctl, cmd, flags); +} diff --git a/tools/virsh-completer-pool.h b/tools/virsh-completer-pool.h index bff3e5742b..eccc08a73f 100644 --- a/tools/virsh-completer-pool.h +++ b/tools/virsh-completer-pool.h @@ -40,3 +40,23 @@ 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); + +char ** +virshAdapterNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** +virshAdapterParentCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index f9aad8ded0..0cbd1417e6 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -80,31 +80,37 @@ {.name =3D "source-path", \ .type =3D VSH_OT_STRING, \ .unwanted_positional =3D true, \ + .completer =3D virshCompletePathLocalExisting, \ .help =3D N_("source path for underlying storage") \ }, \ {.name =3D "source-dev", \ .type =3D VSH_OT_STRING, \ .unwanted_positional =3D true, \ + .completer =3D virshCompletePathLocalExisting, \ .help =3D N_("source device for underlying storage") \ }, \ {.name =3D "source-name", \ .type =3D VSH_OT_STRING, \ .unwanted_positional =3D true, \ + .completer =3D virshCompleteEmpty, \ .help =3D N_("source name for underlying storage") \ }, \ {.name =3D "target", \ .type =3D VSH_OT_STRING, \ .unwanted_positional =3D true, \ + .completer =3D virshCompletePathLocalExisting, \ .help =3D N_("target for underlying storage") \ }, \ {.name =3D "source-format", \ .type =3D VSH_OT_STRING, \ .unwanted_positional =3D true, \ + .completer =3D virshPoolFormatCompleter, \ .help =3D N_("format for underlying storage") \ }, \ {.name =3D "auth-type", \ .type =3D VSH_OT_STRING, \ .unwanted_positional =3D true, \ + .completer =3D virshPoolAuthTypeCompleter, \ .help =3D N_("auth type to be used for underlying storage") \ }, \ {.name =3D "auth-username", \ @@ -126,6 +132,7 @@ {.name =3D "adapter-name", \ .type =3D VSH_OT_STRING, \ .unwanted_positional =3D true, \ + .completer =3D virshAdapterNameCompleter, \ .help =3D N_("adapter name to be used for underlying storage") \ }, \ {.name =3D "adapter-wwnn", \ @@ -141,6 +148,7 @@ {.name =3D "adapter-parent", \ .type =3D VSH_OT_STRING, \ .unwanted_positional =3D true, \ + .completer =3D virshAdapterParentCompleter, \ .help =3D N_("adapter parent scsi_hostN to be used for underlying vHB= A storage") \ }, \ {.name =3D "adapter-parent-wwnn", \ @@ -161,6 +169,7 @@ {.name =3D "source-protocol-ver", \ .type =3D VSH_OT_STRING, \ .unwanted_positional =3D true, \ + .completer =3D virshCompleteEmpty, \ .help =3D N_("nfsvers value for NFS pool mount option") \ }, \ {.name =3D "source-initiator", \ --=20 2.39.2