[libvirt] [ [PATCH v3 0/8] virsh completion for event, secret-event, pool-event and nodedev-event

v2 -> v3: Most of patches in original v2 patchset were pushed, only 2 patches left, So create a new patchset for including the 2 patches and 6 new completion patches which about secret-event, pool-event and nodedev-event. (Borrowed code & idea from Michal Privoznik for these patches design) Lin Ma (8): virsh-secret: Rename vshEventCallback to vshSecretEventCallback virsh: Add event name completion to 'secret-event' command virsh: Move vshEventCallback structure definition to virsh-domain.h virsh: Add event name completion to 'event' command virsh-pool: Rename vshEventCallback to vshPoolEventCallback virsh: Add event name completion to 'pool-event' command virsh-nodedev: Rename vshEventCallback to vshNodedevEventCallback virsh: Add event name completion to 'nodedev-event' command tools/virsh-completer.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh-completer.h | 15 ++++++ tools/virsh-domain.c | 9 +--- tools/virsh-domain.h | 8 ++++ tools/virsh-nodedev.c | 19 +++----- tools/virsh-nodedev.h | 8 ++++ tools/virsh-pool.c | 19 +++----- tools/virsh-pool.h | 8 ++++ tools/virsh-secret.c | 18 +++----- tools/virsh-secret.h | 8 ++++ 10 files changed, 189 insertions(+), 42 deletions(-) -- 2.16.2

The next patch will use it in virsh-completer.c for returning the name list of secret events. The patch code originally authored by Michal Privoznik, Please refer to https://www.redhat.com/archives/libvir-list/2018-May/msg01022.html I splitted it to 2 patches with tiny change. Signed-off-by: Lin Ma <lma@suse.com> --- tools/virsh-secret.c | 17 ++++++----------- tools/virsh-secret.h | 8 ++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 9e4ec61a88..07bc54d1bf 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -571,18 +571,12 @@ virshSecretEventToString(int event) return str ? _(str) : _("unknown"); } -struct vshEventCallback { - const char *name; - virConnectSecretEventGenericCallback cb; -}; -typedef struct vshEventCallback vshEventCallback; - struct virshSecretEventData { vshControl *ctl; bool loop; bool timestamp; int count; - vshEventCallback *cb; + vshSecretEventCallback *cb; }; typedef struct virshSecretEventData virshSecretEventData; @@ -652,11 +646,12 @@ vshEventGenericPrint(virConnectPtr conn ATTRIBUTE_UNUSED, vshEventDone(data->ctl); } -static vshEventCallback vshEventCallbacks[] = { +vshSecretEventCallback vshSecretEventCallbacks[] = { { "lifecycle", VIR_SECRET_EVENT_CALLBACK(vshEventLifecyclePrint), }, { "value-changed", vshEventGenericPrint, }, }; +verify(VIR_SECRET_EVENT_ID_LAST == ARRAY_CARDINALITY(vshSecretEventCallbacks)); static const vshCmdInfo info_secret_event[] = { {.name = "help", @@ -713,7 +708,7 @@ cmdSecretEvent(vshControl *ctl, const vshCmd *cmd) size_t i; for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) - vshPrint(ctl, "%s\n", vshEventCallbacks[i].name); + vshPrint(ctl, "%s\n", vshSecretEventCallbacks[i].name); return true; } @@ -724,7 +719,7 @@ cmdSecretEvent(vshControl *ctl, const vshCmd *cmd) return false; } for (event = 0; event < VIR_SECRET_EVENT_ID_LAST; event++) - if (STREQ(eventName, vshEventCallbacks[event].name)) + if (STREQ(eventName, vshSecretEventCallbacks[event].name)) break; if (event == VIR_SECRET_EVENT_ID_LAST) { vshError(ctl, _("unknown event type %s"), eventName); @@ -735,7 +730,7 @@ cmdSecretEvent(vshControl *ctl, const vshCmd *cmd) data.loop = vshCommandOptBool(cmd, "loop"); data.timestamp = vshCommandOptBool(cmd, "timestamp"); data.count = 0; - data.cb = &vshEventCallbacks[event]; + data.cb = &vshSecretEventCallbacks[event]; if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; diff --git a/tools/virsh-secret.h b/tools/virsh-secret.h index dda22b021e..c70a2b5c75 100644 --- a/tools/virsh-secret.h +++ b/tools/virsh-secret.h @@ -28,6 +28,14 @@ # include "virsh.h" +struct vshSecretEventCallback { + const char *name; + virConnectSecretEventGenericCallback cb; +}; +typedef struct vshSecretEventCallback vshSecretEventCallback; + +extern vshSecretEventCallback vshSecretEventCallbacks[]; + extern const vshCmdDef secretCmds[]; #endif /* VIRSH_SECRET_H */ -- 2.16.2

The patch code originally authored by Michal Privoznik, Please refer to https://www.redhat.com/archives/libvir-list/2018-May/msg01022.html Signed-off-by: Lin Ma <lma@suse.com> --- tools/virsh-completer.c | 27 +++++++++++++++++++++++++++ tools/virsh-completer.h | 4 ++++ tools/virsh-secret.c | 1 + 3 files changed, 32 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 1435d1d4c6..b402fd22c3 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -26,6 +26,7 @@ #include "virsh.h" #include "virsh-pool.h" #include "virsh-util.h" +#include "virsh-secret.h" #include "internal.h" #include "virutil.h" #include "viralloc.h" @@ -649,3 +650,29 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, VIR_FREE(ret); goto cleanup; } + + +char ** +virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + size_t i; + char **ret = NULL; + + virCheckFlags(0, NULL); + + if (VIR_ALLOC_N(ret, VIR_SECRET_EVENT_ID_LAST) < 0) + goto error; + + for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { + if (VIR_STRDUP(ret[i], vshSecretEventCallbacks[i].name) < 0) + goto error; + } + + return ret; + + error: + virStringListFree(ret); + return NULL; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index c7b181879e..c662267882 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -78,4 +78,8 @@ char ** virshAllocpagesPagesizeCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); +char ** virshSecretEventNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + #endif diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 07bc54d1bf..ba0210e765 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -671,6 +671,7 @@ static const vshCmdOptDef opts_secret_event[] = { }, {.name = "event", .type = VSH_OT_STRING, + .completer = virshSecretEventNameCompleter, .help = N_("which event type to wait for") }, {.name = "loop", -- 2.16.2

The next patch will use it in virsh-completer.c for returning the strings of domain event name. Signed-off-by: Lin Ma <lma@suse.com> --- tools/virsh-domain.c | 8 +------- tools/virsh-domain.h | 8 ++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index cfbbf5a7bc..347c744bc9 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -12832,12 +12832,6 @@ virshDomainEventTrayChangeToString(int reason) return str ? _(str) : _("unknown"); } -struct vshEventCallback { - const char *name; - virConnectDomainEventGenericCallback cb; -}; -typedef struct vshEventCallback vshEventCallback; - struct virshDomEventData { vshControl *ctl; bool loop; @@ -13278,7 +13272,7 @@ virshEventBlockThresholdPrint(virConnectPtr conn ATTRIBUTE_UNUSED, } -static vshEventCallback vshEventCallbacks[] = { +vshEventCallback vshEventCallbacks[] = { { "lifecycle", VIR_DOMAIN_EVENT_CALLBACK(virshEventLifecyclePrint), }, { "reboot", virshEventGenericPrint, }, diff --git a/tools/virsh-domain.h b/tools/virsh-domain.h index 3f9d12a5ff..e8e5611244 100644 --- a/tools/virsh-domain.h +++ b/tools/virsh-domain.h @@ -28,6 +28,14 @@ # include "virsh.h" +struct vshEventCallback { + const char *name; + virConnectDomainEventGenericCallback cb; +}; +typedef struct vshEventCallback vshEventCallback; + +extern vshEventCallback vshEventCallbacks[]; + extern const vshCmdDef domManagementCmds[]; #endif /* VIRSH_DOMAIN_H */ -- 2.16.2
participants (1)
-
Lin Ma