[libvirt] [PATCH 06/12] virsh: Create macros for VSH_OT_ARGV "domain" option
by Lin Ma
Signed-off-by: Lin Ma <lma(a)suse.com>
---
tools/virsh-domain-monitor.c | 3 +++
tools/virsh-domain.c | 3 +++
tools/virsh-snapshot.c | 3 +++
tools/virsh.h | 9 +++++++++
4 files changed, 18 insertions(+)
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 8ad651626b..e4a21534cb 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -46,6 +46,9 @@
#define VIRSH_COMMON_OPT_DOMAIN_OT_STRING_FULL(cflags) \
VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("domain name, id or uuid"), cflags)
+#define VIRSH_COMMON_OPT_DOMAIN_OT_ARGV_FULL(cflags) \
+ VIRSH_COMMON_OPT_DOMAIN_OT_ARGV(N_("domain name, id or uuid"), cflags)
+
VIR_ENUM_DECL(virshDomainIOError)
VIR_ENUM_IMPL(virshDomainIOError,
VIR_DOMAIN_DISK_ERROR_LAST,
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 689f9d686b..89aefbf86a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -71,6 +71,9 @@
#define VIRSH_COMMON_OPT_DOMAIN_OT_STRING_FULL(cflags) \
VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("domain name, id or uuid"), cflags)
+#define VIRSH_COMMON_OPT_DOMAIN_OT_ARGV_FULL(cflags) \
+ VIRSH_COMMON_OPT_DOMAIN_OT_ARGV(N_("domain name, id or uuid"), cflags)
+
#define VIRSH_COMMON_OPT_DOMAIN_PERSISTENT \
{.name = "persistent", \
.type = VSH_OT_BOOL, \
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index 3d86ac84d1..0c86b6c950 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -48,6 +48,9 @@
#define VIRSH_COMMON_OPT_DOMAIN_OT_STRING_FULL(cflags) \
VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("domain name, id or uuid"), cflags)
+#define VIRSH_COMMON_OPT_DOMAIN_OT_ARGV_FULL(cflags) \
+ VIRSH_COMMON_OPT_DOMAIN_OT_ARGV(N_("domain name, id or uuid"), cflags)
+
/* Helper for snapshot-create and snapshot-create-as */
static bool
virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
diff --git a/tools/virsh.h b/tools/virsh.h
index 9dcf104cc4..a33d108b2d 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -115,6 +115,15 @@
.completer_flags = cflags, \
}
+# define VIRSH_COMMON_OPT_DOMAIN_OT_ARGV(_helpstr, cflags) \
+ {.name = "domain", \
+ .type = VSH_OT_ARGV, \
+ .flags = VSH_OFLAG_NONE, \
+ .help = _helpstr, \
+ .completer = virshDomainNameCompleter, \
+ .completer_flags = cflags, \
+ }
+
typedef struct _virshControl virshControl;
typedef virshControl *virshControlPtr;
--
2.15.1
6 years, 7 months
[libvirt] [PATCH 02/12] virsh: Conditionally Ignore the first entry in list of completions
by Lin Ma
The first entry in the returned array is the substitution for TEXT. It
causes unnecessary output if other commands or options share the same
prefix, e.g.
$ virsh des<TAB><TAB>
des desc destroy
or
$ virsh domblklist --d<TAB><TAB>
--d --details --domain
This patch fixes the above issue.
Signed-off-by: Lin Ma <lma(a)suse.com>
---
tools/vsh.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/vsh.c b/tools/vsh.c
index 73ec007e56..38058c874a 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -3458,6 +3458,7 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd)
const vshCmdOpt *opt = NULL;
char **matches = NULL, **iter;
virBuffer buf = VIR_BUFFER_INITIALIZER;
+ int n;
if (vshCommandOptStringQuiet(ctl, cmd, "string", &arg) <= 0)
goto cleanup;
@@ -3493,8 +3494,11 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd)
if (!(matches = vshReadlineCompletion(arg, 0, 0)))
goto cleanup;
- for (iter = matches; *iter; iter++)
+ for (n =0, iter = matches; *iter; iter++, n++) {
+ if (n == 0 && matches[1])
+ continue;
printf("%s\n", *iter);
+ }
ret = true;
cleanup:
--
2.15.1
6 years, 7 months
[libvirt] [PATCH 11/12] domain_event: Introduce function virDomainEventGetName
by Lin Ma
It will be used in next patch for event name completion.
Signed-off-by: Lin Ma <lma(a)suse.com>
---
src/conf/domain_event.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
src/conf/domain_event.h | 3 +++
src/libvirt_private.syms | 1 +
3 files changed, 66 insertions(+)
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 97520706c9..f8bd457b34 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -1968,6 +1968,68 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
}
+const char *
+virDomainEventGetName(int event)
+{
+ virResetLastError();
+
+ switch (event) {
+ case VIR_DOMAIN_EVENT_ID_LIFECYCLE:
+ return VIR_DOMAIN_EVENT_LIFECYCLE;
+ case VIR_DOMAIN_EVENT_ID_REBOOT:
+ return VIR_DOMAIN_EVENT_REBOOT;
+ case VIR_DOMAIN_EVENT_ID_RTC_CHANGE:
+ return VIR_DOMAIN_EVENT_RTC_CHANGE;
+ case VIR_DOMAIN_EVENT_ID_WATCHDOG:
+ return VIR_DOMAIN_EVENT_WATCHDOG;
+ case VIR_DOMAIN_EVENT_ID_IO_ERROR:
+ return VIR_DOMAIN_EVENT_IO_ERROR;
+ case VIR_DOMAIN_EVENT_ID_GRAPHICS:
+ return VIR_DOMAIN_EVENT_GRAPHICS;
+ case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
+ return VIR_DOMAIN_EVENT_IO_ERROR_REASON;
+ case VIR_DOMAIN_EVENT_ID_CONTROL_ERROR:
+ return VIR_DOMAIN_EVENT_CONTROL_ERROR;
+ case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
+ return VIR_DOMAIN_EVENT_BLOCK_JOB;
+ case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
+ return VIR_DOMAIN_EVENT_DISK_CHANGE;
+ case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
+ return VIR_DOMAIN_EVENT_TRAY_CHANGE;
+ case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
+ return VIR_DOMAIN_EVENT_PMWAKEUP;
+ case VIR_DOMAIN_EVENT_ID_PMSUSPEND:
+ return VIR_DOMAIN_EVENT_PMSUSPEND;
+ case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE:
+ return VIR_DOMAIN_EVENT_BALLOON_CHANGE;
+ case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK:
+ return VIR_DOMAIN_EVENT_PMSUSPEND_DISK;
+ case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
+ return VIR_DOMAIN_EVENT_DEVICE_REMOVED;
+ case VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2:
+ return VIR_DOMAIN_EVENT_BLOCK_JOB_2;
+ case VIR_DOMAIN_EVENT_ID_TUNABLE:
+ return VIR_DOMAIN_EVENT_TUNABLE;
+ case VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE:
+ return VIR_DOMAIN_EVENT_AGENT_LIFECYCLE;
+ case VIR_DOMAIN_EVENT_ID_DEVICE_ADDED:
+ return VIR_DOMAIN_EVENT_DEVICE_ADDED;
+ case VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION:
+ return VIR_DOMAIN_EVENT_MIGRATION_ITERATION;
+ case VIR_DOMAIN_EVENT_ID_JOB_COMPLETED:
+ return VIR_DOMAIN_EVENT_JOB_COMPLETED;
+ case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED:
+ return VIR_DOMAIN_EVENT_DEVICE_REMOVAL_FAILED;
+ case VIR_DOMAIN_EVENT_ID_METADATA_CHANGE:
+ return VIR_DOMAIN_EVENT_METADATA_CHANGE;
+ case VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD:
+ return VIR_DOMAIN_EVENT_BLOCK_THRESHOLD;
+ default:
+ return NULL;
+ }
+}
+
+
virObjectEventPtr
virDomainQemuMonitorEventNew(int id,
const char *name,
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index 3992a29c58..9c3a1e3b88 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -327,4 +327,7 @@ virDomainQemuMonitorEventNew(int id,
const char *details)
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
+const char *
+virDomainEventGetName(int event);
+
#endif
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 92b5e0fa2b..0b6c414b66 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -641,6 +641,7 @@ virDomainEventWatchdogNewFromDom;
virDomainEventWatchdogNewFromObj;
virDomainQemuMonitorEventNew;
virDomainQemuMonitorEventStateRegisterID;
+virDomainEventGetName;
# conf/domain_nwfilter.h
--
2.15.1
6 years, 7 months
[libvirt] [PATCH 12/12] virsh: Add event name completion to 'event' command
by Lin Ma
Signed-off-by: Lin Ma <lma(a)suse.com>
---
tools/virsh-completer.c | 36 ++++++++++++++++++++++++++++++++++++
tools/virsh-completer.h | 3 +++
tools/virsh-domain.c | 1 +
3 files changed, 40 insertions(+)
diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index e3b8234b41..a188a8d7ab 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -30,6 +30,7 @@
#include "viralloc.h"
#include "virstring.h"
#include "virxml.h"
+extern const char *virDomainEventGetName(int event);
char **
@@ -522,3 +523,38 @@ virshSnapshotNameCompleter(vshControl *ctl,
virshDomainFree(dom);
return NULL;
}
+
+
+char **
+virshEventNameCompleter(vshControl *ctl,
+ const vshCmd *cmd ATTRIBUTE_UNUSED,
+ unsigned int flags)
+{
+ virshControlPtr priv = ctl->privData;
+ size_t i = 0;
+ char **ret = NULL;
+
+ virCheckFlags(0, NULL);
+
+ if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+ return NULL;
+
+ if (VIR_ALLOC_N(ret, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0)
+ goto error;
+
+ for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) {
+ const char *name = virDomainEventGetName(i);
+
+ if (name == NULL)
+ goto error;
+
+ if (VIR_STRDUP(ret[i], name) < 0)
+ goto error;
+ }
+
+ return ret;
+
+error:
+ VIR_FREE(ret);
+ return NULL;
+}
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index fa443d3ad7..27d78dc7ac 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -69,5 +69,8 @@ char ** virshSecretUUIDCompleter(vshControl *ctl,
char ** virshSnapshotNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
+char ** virshEventNameCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int flags);
#endif
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index e21ba0117b..ce72d414b9 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -13369,6 +13369,7 @@ static const vshCmdOptDef opts_event[] = {
},
{.name = "event",
.type = VSH_OT_ARGV,
+ .completer = virshEventNameCompleter,
.help = N_("which event type to wait for")
},
{.name = NULL}
--
2.15.1
6 years, 7 months
[libvirt] [PATCH 10/12] virsh: Introduce some VIR_DOMAIN_EVENT_* macros representing domain event names
by Lin Ma
Signed-off-by: Lin Ma <lma(a)suse.com>
---
include/libvirt/libvirt-domain.h | 201 +++++++++++++++++++++++++++++++++++++++
tools/virsh-domain.c | 50 +++++-----
2 files changed, 226 insertions(+), 25 deletions(-)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 12fd34037e..f7dd510f7f 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -4424,6 +4424,207 @@ typedef enum {
} virDomainEventID;
+/**
+ * VIR_DOMAIN_EVENT_LIFECYCLE:
+ *
+ * Macro for the event name "lifecycle"
+ */
+
+# define VIR_DOMAIN_EVENT_LIFECYCLE "lifecycle"
+
+/**
+ * VIR_DOMAIN_EVENT_REBOOT:
+ *
+ * Macro for the event name "reboot"
+ */
+
+# define VIR_DOMAIN_EVENT_REBOOT "reboot"
+
+/**
+ * VIR_DOMAIN_EVENT_RTC_CHANGE:
+ *
+ * Macro for the event name "rtc-change"
+ */
+
+# define VIR_DOMAIN_EVENT_RTC_CHANGE "rtc-change"
+
+/**
+ * VIR_DOMAIN_EVENT_WATCHDOG:
+ *
+ * Macro for the event name "watchdog"
+ */
+
+# define VIR_DOMAIN_EVENT_WATCHDOG "watchdog"
+
+/**
+ * VIR_DOMAIN_EVENT_IO_ERROR:
+ *
+ * Macro for the event name "io-error"
+ */
+
+# define VIR_DOMAIN_EVENT_IO_ERROR "io-error"
+
+/**
+ * VIR_DOMAIN_EVENT_GRAPHICS:
+ *
+ * Macro for the event name "graphics"
+ */
+
+# define VIR_DOMAIN_EVENT_GRAPHICS "graphics"
+
+/**
+ * VIR_DOMAIN_EVENT_IO_ERROR_REASON:
+ *
+ * Macro for the event name "io-error-reason"
+ */
+
+# define VIR_DOMAIN_EVENT_IO_ERROR_REASON "io-error-reason"
+
+/**
+ * VIR_DOMAIN_EVENT_CONTROL_ERROR:
+ *
+ * Macro for the event name "control-error"
+ */
+
+# define VIR_DOMAIN_EVENT_CONTROL_ERROR "control-error"
+
+/**
+ * VIR_DOMAIN_EVENT_BLOCK_JOB:
+ *
+ * Macro for the event name "block-job"
+ */
+
+# define VIR_DOMAIN_EVENT_BLOCK_JOB "block-job"
+
+/**
+ * VIR_DOMAIN_EVENT_DISK_CHANGE:
+ *
+ * Macro for the event name "disk-change"
+ */
+
+# define VIR_DOMAIN_EVENT_DISK_CHANGE "disk-change"
+
+/**
+ * VIR_DOMAIN_EVENT_TRAY_CHANGE:
+ *
+ * Macro for the event name "tray-change"
+ */
+
+# define VIR_DOMAIN_EVENT_TRAY_CHANGE "tray-change"
+
+/**
+ * VIR_DOMAIN_EVENT_PMWAKEUP:
+ *
+ * Macro for the event name "pm-wakeup"
+ */
+
+# define VIR_DOMAIN_EVENT_PMWAKEUP "pm-wakeup"
+
+/**
+ * VIR_DOMAIN_EVENT_PMSUSPEND:
+ *
+ * Macro for the event name "pm-suspend"
+ */
+
+# define VIR_DOMAIN_EVENT_PMSUSPEND "pm-suspend"
+
+/**
+ * VIR_DOMAIN_EVENT_BALLOON_CHANGE:
+ *
+ * Macro for the event name "balloon-change"
+ */
+
+# define VIR_DOMAIN_EVENT_BALLOON_CHANGE "balloon-change"
+
+/**
+ * VIR_DOMAIN_EVENT_PMSUSPEND_DISK:
+ *
+ * Macro for the event name "pm-suspend-disk"
+ */
+
+# define VIR_DOMAIN_EVENT_PMSUSPEND_DISK "pm-suspend-disk"
+
+/**
+ * VIR_DOMAIN_EVENT_DEVICE_REMOVED:
+ *
+ * Macro for the event name "device-removed"
+ */
+
+# define VIR_DOMAIN_EVENT_DEVICE_REMOVED "device-removed"
+
+/**
+ * VIR_DOMAIN_EVENT_BLOCK_JOB_2:
+ *
+ * Macro for the event name "block-job-2"
+ */
+
+# define VIR_DOMAIN_EVENT_BLOCK_JOB_2 "block-job-2"
+
+/**
+ * VIR_DOMAIN_EVENT_TUNABLE:
+ *
+ * Macro for the event name "tunable"
+ */
+
+# define VIR_DOMAIN_EVENT_TUNABLE "tunable"
+
+/**
+ * VIR_DOMAIN_EVENT_AGENT_LIFECYCLE:
+ *
+ * Macro for the event name "agent-lifecycle"
+ */
+
+# define VIR_DOMAIN_EVENT_AGENT_LIFECYCLE "agent-lifecycle"
+
+/**
+ * VIR_DOMAIN_EVENT_DEVICE_ADDED:
+ *
+ * Macro for the event name "device-added"
+ */
+
+# define VIR_DOMAIN_EVENT_DEVICE_ADDED "device-added"
+
+/**
+ * VIR_DOMAIN_EVENT_MIGRATION_ITERATION:
+ *
+ * Macro for the event name "migration-iteration"
+ */
+
+# define VIR_DOMAIN_EVENT_MIGRATION_ITERATION "migration-iteration"
+
+/**
+ * VIR_DOMAIN_EVENT_JOB_COMPLETED:
+ *
+ * Macro for the event name "job-completed"
+ */
+
+# define VIR_DOMAIN_EVENT_JOB_COMPLETED "job-completed"
+
+/**
+ * VIR_DOMAIN_EVENT_DEVICE_REMOVAL_FAILED:
+ *
+ * Macro for the event name "device-removal-failed"
+ */
+
+# define VIR_DOMAIN_EVENT_DEVICE_REMOVAL_FAILED "device-removal-failed"
+
+/**
+ * VIR_DOMAIN_EVENT_METADATA_CHANGE:
+ *
+ * Macro for the event name "metadata-change"
+ */
+
+# define VIR_DOMAIN_EVENT_METADATA_CHANGE "metadata-change"
+
+/**
+ * VIR_DOMAIN_EVENT_BLOCK_THRESHOLD:
+ *
+ * Macro for the event name "block-threshold"
+ */
+
+# define VIR_DOMAIN_EVENT_BLOCK_THRESHOLD "block-threshold"
+
+
/* Use VIR_DOMAIN_EVENT_CALLBACK() to cast the 'cb' parameter */
int virConnectDomainEventRegisterAny(virConnectPtr conn,
virDomainPtr dom, /* Optional, to filter */
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index b35c9adaaa..e21ba0117b 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -13283,53 +13283,53 @@ virshEventBlockThresholdPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
static vshEventCallback vshEventCallbacks[] = {
- { "lifecycle",
+ { VIR_DOMAIN_EVENT_LIFECYCLE,
VIR_DOMAIN_EVENT_CALLBACK(virshEventLifecyclePrint), },
- { "reboot", virshEventGenericPrint, },
- { "rtc-change",
+ { VIR_DOMAIN_EVENT_REBOOT, virshEventGenericPrint, },
+ { VIR_DOMAIN_EVENT_RTC_CHANGE,
VIR_DOMAIN_EVENT_CALLBACK(virshEventRTCChangePrint), },
- { "watchdog",
+ { VIR_DOMAIN_EVENT_WATCHDOG,
VIR_DOMAIN_EVENT_CALLBACK(virshEventWatchdogPrint), },
- { "io-error",
+ { VIR_DOMAIN_EVENT_IO_ERROR,
VIR_DOMAIN_EVENT_CALLBACK(virshEventIOErrorPrint), },
- { "graphics",
+ { VIR_DOMAIN_EVENT_GRAPHICS,
VIR_DOMAIN_EVENT_CALLBACK(virshEventGraphicsPrint), },
- { "io-error-reason",
+ { VIR_DOMAIN_EVENT_IO_ERROR_REASON,
VIR_DOMAIN_EVENT_CALLBACK(virshEventIOErrorReasonPrint), },
- { "control-error", virshEventGenericPrint, },
- { "block-job",
+ { VIR_DOMAIN_EVENT_CONTROL_ERROR, virshEventGenericPrint, },
+ { VIR_DOMAIN_EVENT_BLOCK_JOB,
VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockJobPrint), },
- { "disk-change",
+ { VIR_DOMAIN_EVENT_DISK_CHANGE,
VIR_DOMAIN_EVENT_CALLBACK(virshEventDiskChangePrint), },
- { "tray-change",
+ { VIR_DOMAIN_EVENT_TRAY_CHANGE,
VIR_DOMAIN_EVENT_CALLBACK(virshEventTrayChangePrint), },
- { "pm-wakeup",
+ { VIR_DOMAIN_EVENT_PMWAKEUP,
VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), },
- { "pm-suspend",
+ { VIR_DOMAIN_EVENT_PMSUSPEND,
VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), },
- { "balloon-change",
+ { VIR_DOMAIN_EVENT_BALLOON_CHANGE,
VIR_DOMAIN_EVENT_CALLBACK(virshEventBalloonChangePrint), },
- { "pm-suspend-disk",
+ { VIR_DOMAIN_EVENT_PMSUSPEND_DISK,
VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), },
- { "device-removed",
+ { VIR_DOMAIN_EVENT_DEVICE_REMOVED,
VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceRemovedPrint), },
- { "block-job-2",
+ { VIR_DOMAIN_EVENT_BLOCK_JOB_2,
VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockJobPrint), },
- { "tunable",
+ { VIR_DOMAIN_EVENT_TUNABLE,
VIR_DOMAIN_EVENT_CALLBACK(virshEventTunablePrint), },
- { "agent-lifecycle",
+ { VIR_DOMAIN_EVENT_AGENT_LIFECYCLE,
VIR_DOMAIN_EVENT_CALLBACK(virshEventAgentLifecyclePrint), },
- { "device-added",
+ { VIR_DOMAIN_EVENT_DEVICE_ADDED,
VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceAddedPrint), },
- { "migration-iteration",
+ { VIR_DOMAIN_EVENT_MIGRATION_ITERATION,
VIR_DOMAIN_EVENT_CALLBACK(virshEventMigrationIterationPrint), },
- { "job-completed",
+ { VIR_DOMAIN_EVENT_JOB_COMPLETED,
VIR_DOMAIN_EVENT_CALLBACK(virshEventJobCompletedPrint), },
- { "device-removal-failed",
+ { VIR_DOMAIN_EVENT_DEVICE_REMOVAL_FAILED,
VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceRemovalFailedPrint), },
- { "metadata-change",
+ { VIR_DOMAIN_EVENT_METADATA_CHANGE,
VIR_DOMAIN_EVENT_CALLBACK(virshEventMetadataChangePrint), },
- { "block-threshold",
+ { VIR_DOMAIN_EVENT_BLOCK_THRESHOLD,
VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockThresholdPrint), },
};
verify(VIR_DOMAIN_EVENT_ID_LAST == ARRAY_CARDINALITY(vshEventCallbacks));
--
2.15.1
6 years, 7 months
[libvirt] [dbus PATCH v2] Implement SetGuestVcpus method for Domain Interface
by Katerina Koukiou
Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
Fixed conditions since v1 was creating incorrect vcpumap.
If all vcpus will be passed False the API will not work, since '' is not
valid cpumap but this scenario should not be used.
data/org.libvirt.Domain.xml | 7 +++++
src/domain.c | 62 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+)
diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
index db43b1c..eae6d97 100644
--- a/data/org.libvirt.Domain.xml
+++ b/data/org.libvirt.Domain.xml
@@ -463,6 +463,13 @@
<arg name="params" type="a{sv}" direction="in"/>
<arg name="flags" type="u" direction="in"/>
</method>
+ <method name="SetGuestVcpus">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetGuestVcpus"/>
+ <arg name="vcpumap" type="ab" direction="in"/>
+ <arg name="state" type="i" direction="in"/>
+ <arg name="flags" type="u" direction="in"/>
+ </method>
<method name="SetInterfaceParameters">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetInterfac..."/>
diff --git a/src/domain.c b/src/domain.c
index e305fa3..28cbe76 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -72,6 +72,39 @@ VIRT_DBUS_ENUM_IMPL(virtDBusDomainMetadata,
"title",
"element")
+static gchar *
+virtDBusDomainConvertBoolArrayToGuestVcpumap(GVariantIter *iter)
+{
+ g_autoptr(GVariantIter) tmpIter = NULL;
+ gint intervalCnt = 0;
+ guint intervalStart = 0;
+ gboolean set;
+ gboolean setPrev = 0;
+ g_autofree GString *ret = NULL;
+
+ ret = g_string_new("");
+ for (guint i = 0; ; i++) {
+ gboolean next = g_variant_iter_loop(iter, "b", &set);
+
+ if (next && set && !setPrev)
+ intervalStart = i;
+ else if ((!next && setPrev) || (!set && setPrev)) {
+ if (intervalCnt > 0)
+ g_string_append_printf(ret, ",");
+ if (intervalStart != i - 1)
+ g_string_append_printf(ret, "%d-%d", intervalStart, i - 1);
+ else
+ g_string_append_printf(ret, "%d", intervalStart);
+ intervalCnt++;
+ }
+ setPrev = set;
+ if (!next)
+ break;
+ }
+
+ return ret->str;
+}
+
struct _virtDBusDomainFSInfoList {
virDomainFSInfoPtr *info;
gint count;
@@ -2490,6 +2523,34 @@ virtDBusDomainSetBlockIOTune(GVariant *inArgs,
}
}
+static void
+virtDBusDomainSetGuestVcpus(GVariant *inArgs,
+ GUnixFDList *inFDs G_GNUC_UNUSED,
+ const gchar *objectPath,
+ gpointer userData,
+ GVariant **outArgs G_GNUC_UNUSED,
+ GUnixFDList **outFDs G_GNUC_UNUSED,
+ GError **error)
+{
+ virtDBusConnect *connect = userData;
+ g_autoptr(virDomain) domain = NULL;
+ g_autoptr(GVariantIter) iter = NULL;
+ gint state;
+ guint flags;
+ g_autofree gchar *ret = NULL;
+
+ g_variant_get(inArgs, "(abiu)", &iter, &state, &flags);
+
+ domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
+ if (!domain)
+ return;
+
+ ret = virtDBusDomainConvertBoolArrayToGuestVcpumap(iter);
+
+ if (virDomainSetGuestVcpus(domain, ret, state, flags) < 0)
+ virtDBusUtilSetLastVirtError(error);
+}
+
static void
virtDBusDomainSetInterfaceParameters(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -2988,6 +3049,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = {
{ "SendProcessSignal", virtDBusDomainSendProcessSignal },
{ "SetBlkioParameters", virtDBusDomainSetBlkioParameters },
{ "SetBlockIOTune", virtDBusDomainSetBlockIOTune },
+ { "SetGuestVcpus", virtDBusDomainSetGuestVcpus },
{ "SetInterfaceParameters", virtDBusDomainSetInterfaceParameters },
{ "SetVcpus", virtDBusDomainSetVcpus },
{ "SetMemory", virtDBusDomainSetMemory },
--
2.15.0
6 years, 7 months
[libvirt] [PATCH 08/12] vshReadlineOptionsGenerator: Add already provided VSH_OT_ARGV options to list
by Lin Ma
It's helpful for users while they type certain kind of VSH_OT_ARGV options.
e.g.
$ virsh domstats --domain sles12sp3 --d<TAB>
Signed-off-by: Lin Ma <lma(a)suse.com>
---
tools/vsh.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/vsh.c b/tools/vsh.c
index 5a9916cbb0..9cfd4d92b8 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2685,7 +2685,7 @@ vshReadlineOptionsGenerator(const char *text,
}
while (opt) {
- if (STREQ(opt->def->name, name)) {
+ if (STREQ(opt->def->name, name) && opt->def->type != VSH_OT_ARGV) {
exists = true;
break;
}
--
2.15.1
6 years, 7 months
[libvirt] [PATCH 07/12] virsh: Apply macro for current VSH_OT_ARGV "domain" options
by Lin Ma
Signed-off-by: Lin Ma <lma(a)suse.com>
---
tools/virsh-domain-monitor.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index e4a21534cb..1e1ee60198 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -2000,11 +2000,7 @@ static const vshCmdOptDef opts_domstats[] = {
.type = VSH_OT_BOOL,
.help = N_("add backing chain information to block stats"),
},
- {.name = "domain",
- .type = VSH_OT_ARGV,
- .flags = VSH_OFLAG_NONE,
- .help = N_("list of domains to get stats for"),
- },
+ VIRSH_COMMON_OPT_DOMAIN_OT_ARGV(N_("list of domains to get stats for"), 0),
{.name = NULL}
};
--
2.15.1
6 years, 7 months
[libvirt] [PATCH 05/12] vshReadlineParse: Ignore vshReadlineOptionsGenerator for VSH_OT_ARGV options
by Lin Ma
Currently the VSH_OT_ARGV options don't support complete, But some of
VSH_OT_ARGV options are gonna support complete in upcoming patches.
Once applied the upcoming completion patches for VSH_OT_ARGV options, If
we don't ignore VSH_OT_ARGV here, The vshReadlineOptionsGenerator will
be called, Hence complete output will consist of the result by command
completer + the result by option completer, It's confusing.
e.g.
$ virsh domstats --domain <TAB><TAB>
--backing --interface --list-paused --perf --vcpu
--balloon leap42.3 --list-persistent --raw win10
--block --list-active --list-running sles12sp3
--cpu-total --list-inactive --list-shutoff sles15
--enforce --list-other --list-transient --state
After this patch and the upcoming completion patches:
$ virsh domstats --domain <TAB><TAB>
leap42.3 sles12sp3 sles15 win10
Signed-off-by: Lin Ma <lma(a)suse.com>
---
tools/vsh.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/vsh.c b/tools/vsh.c
index 38058c874a..5a9916cbb0 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2824,7 +2824,9 @@ vshReadlineParse(const char *text, int state)
if (!cmd) {
list = vshReadlineCommandGenerator(text);
} else {
- if (!opt || (opt->type != VSH_OT_DATA && opt->type != VSH_OT_STRING))
+ if (!opt || (opt->type != VSH_OT_DATA &&
+ opt->type != VSH_OT_STRING &&
+ opt->type != VSH_OT_ARGV))
list = vshReadlineOptionsGenerator(text, cmd, partial);
if (opt && opt->completer) {
--
2.15.1
6 years, 7 months
[libvirt] [PATCH 04/12] virsh: Apply macro for current VSH_OT_STRING "domain" options
by Lin Ma
These VSH_OT_STRING "domain" options support domain name completion now.
Signed-off-by: Lin Ma <lma(a)suse.com>
---
tools/virsh-domain.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 8a63761fab..689f9d686b 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9601,10 +9601,8 @@ static const vshCmdInfo info_qemu_monitor_event[] = {
};
static const vshCmdOptDef opts_qemu_monitor_event[] = {
- {.name = "domain",
- .type = VSH_OT_STRING,
- .help = N_("filter by domain name, id or uuid")
- },
+ VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("filter by domain name, id or uuid"),
+ 0),
{.name = "event",
.type = VSH_OT_STRING,
.help = N_("filter by event name")
@@ -10157,11 +10155,7 @@ static const vshCmdOptDef opts_domxmltonative[] = {
.flags = VSH_OFLAG_REQ,
.help = N_("target config data type format")
},
- {.name = "domain",
- .type = VSH_OT_STRING,
- .flags = VSH_OFLAG_REQ_OPT,
- .help = N_("domain name, id or uuid")
- },
+ VIRSH_COMMON_OPT_DOMAIN_OT_STRING_FULL(0),
{.name = "xml",
.type = VSH_OT_STRING,
.help = N_("xml data file to export from")
@@ -13348,10 +13342,8 @@ static const vshCmdInfo info_event[] = {
};
static const vshCmdOptDef opts_event[] = {
- {.name = "domain",
- .type = VSH_OT_STRING,
- .help = N_("filter by domain name, id, or uuid")
- },
+ VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("filter by domain name, id or uuid"),
+ 0),
{.name = "event",
.type = VSH_OT_STRING,
.help = N_("which event type to wait for")
--
2.15.1
6 years, 7 months