When using thin provisioning, management tools need to resize the disk
in certain cases. To avoid having them to poll disk fillng introduce an
event whic will be fired when a given offset of the storage is written
by the hypervisor. Together with the API which will be added later, it
will allow to register thresholds for given storage backing volumes and
this event will then notify management if the threshold is exceeded.
---
daemon/remote.c | 43 ++++++++++++++++
examples/object-events/event-test.c | 19 ++++++++
include/libvirt/libvirt-domain.h | 31 ++++++++++++
src/conf/domain_event.c | 97 +++++++++++++++++++++++++++++++++++++
src/conf/domain_event.h | 15 ++++++
src/libvirt_private.syms | 2 +
src/remote/remote_driver.c | 33 +++++++++++++
src/remote/remote_protocol.x | 18 ++++++-
src/remote_protocol-structs | 9 ++++
tools/virsh-domain.c | 21 ++++++++
10 files changed, 287 insertions(+), 1 deletion(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index f2b9b9aec..511f499de 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -1295,6 +1295,48 @@ remoteRelayDomainEventMetadataChange(virConnectPtr conn,
}
+static int
+remoteRelayDomainEventBlockThreshold(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *dev,
+ const char *path,
+ unsigned long long threshold,
+ unsigned long long excess,
+ void *opaque)
+{
+ daemonClientEventCallbackPtr callback = opaque;
+ remote_domain_event_block_threshold_msg data;
+
+ if (callback->callbackID < 0 ||
+ !remoteRelayDomainEventCheckACL(callback->client, conn, dom))
+ return -1;
+
+ VIR_DEBUG("Relaying domain block threshold event %s %d %s %s %llu %llu, callback
%d",
+ dom->name, dom->id, dev, NULLSTR(path), threshold, excess,
callback->callbackID);
+
+ /* build return data */
+ memset(&data, 0, sizeof(data));
+ data.callbackID = callback->callbackID;
+ if (VIR_STRDUP(data.dev, dev) < 0)
+ goto error;
+ if (VIR_ALLOC(data.path) < 0)
+ goto error;
+ if (VIR_STRDUP(*(data.path), path) < 0)
+ goto error;
+ data.threshold = threshold;
+ data.excess = excess;
+ make_nonnull_domain(&data.dom, dom);
+
+ remoteDispatchObjectEventSend(callback->client, remoteProgram,
+ REMOTE_PROC_DOMAIN_EVENT_BLOCK_THRESHOLD,
+ (xdrproc_t)xdr_remote_domain_event_block_threshold_msg,
&data);
+
+ return 0;
+ error:
+ VIR_FREE(data.dev);
+ return -1;
+}
+
static virConnectDomainEventGenericCallback domainEventCallbacks[] = {
VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle),
@@ -1321,6 +1363,7 @@ static virConnectDomainEventGenericCallback domainEventCallbacks[] =
{
VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventJobCompleted),
VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventDeviceRemovalFailed),
VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventMetadataChange),
+ VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockThreshold),
};
verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST);
diff --git a/examples/object-events/event-test.c b/examples/object-events/event-test.c
index 55c004f93..12690cac0 100644
--- a/examples/object-events/event-test.c
+++ b/examples/object-events/event-test.c
@@ -15,6 +15,7 @@
#define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
#define STREQ(a, b) (strcmp(a, b) == 0)
+#define NULLSTR(s) ((s) ? (s) : "<null>")
#ifndef ATTRIBUTE_UNUSED
# define ATTRIBUTE_UNUSED __attribute__((__unused__))
@@ -925,6 +926,23 @@ myDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
static int
+myDomainEventBlockThresholdCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ const char *dev,
+ const char *path,
+ unsigned long long threshold,
+ unsigned long long excess,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ printf("%s EVENT: Domain %s(%d) block threshold callback dev '%s'(%s),
"
+ "threshold: '%llu', excess: '%llu'",
+ __func__, virDomainGetName(dom), virDomainGetID(dom),
+ dev, NULLSTR(path), threshold, excess);
+ return 0;
+}
+
+
+static int
myDomainEventMigrationIterationCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainPtr dom,
int iteration,
@@ -1053,6 +1071,7 @@ struct domainEventData domainEvents[] = {
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_JOB_COMPLETED, myDomainEventJobCompletedCallback),
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED,
myDomainEventDeviceRemovalFailedCallback),
DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_METADATA_CHANGE,
myDomainEventMetadataChangeCallback),
+ DOMAIN_EVENT(VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD,
myDomainEventBlockThresholdCallback),
};
struct storagePoolEventData {
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index c0f715d66..892cf2cc5 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -4175,6 +4175,36 @@ typedef void
(*virConnectDomainEventAgentLifecycleCallback)(virConnectPtr conn,
/**
+ * virConnectDomainEventBlockThresholdCallback:
+ * @conn: connection object
+ * @dom: domain on which the event occurred
+ * @dev: name associated with the affected disk or storage backing chain
+ * element
+ * @path: for local storage, the path of the backing chain element
+ * @threshold: threshold
+ * @excess: WTF
+ * @opaque: application specified data
+ *
+ * The callback occurs when the hypervisor detects that the given storage
+ * element was written beyond the point specified by @threshold. The excess
+ * data size written beyond @threshold is reported by @excess (if supported
+ * by the hypervisor, 0 otherwise). The event is useful for thin-provisioned
+ * storage.
+ *
+ * The threshold size can be set via the virDomainSetBlockThreshold API.
+ *
+ * The callback signature to use when registering for an event of type
+ * VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD with virConnectDomainEventRegisterAny()
+ */
+typedef void (*virConnectDomainEventBlockThresholdCallback)(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *dev,
+ const char *path,
+ unsigned long long
threshold,
+ unsigned long long excess,
+ void *opaque);
+
+/**
* VIR_DOMAIN_EVENT_CALLBACK:
*
* Used to cast the event specific callback into the generic one
@@ -4215,6 +4245,7 @@ typedef enum {
VIR_DOMAIN_EVENT_ID_JOB_COMPLETED = 21, /* virConnectDomainEventJobCompletedCallback
*/
VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED = 22, /*
virConnectDomainEventDeviceRemovalFailedCallback */
VIR_DOMAIN_EVENT_ID_METADATA_CHANGE = 23, /*
virConnectDomainEventMetadataChangeCallback */
+ VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD = 24, /*
virConnectDomainEventBlockThresholdCallback */
# ifdef VIR_ENUM_SENTINELS
VIR_DOMAIN_EVENT_ID_LAST
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index da503f3ee..6243b4262 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -60,6 +60,7 @@ static virClassPtr virDomainEventMigrationIterationClass;
static virClassPtr virDomainEventJobCompletedClass;
static virClassPtr virDomainEventDeviceRemovalFailedClass;
static virClassPtr virDomainEventMetadataChangeClass;
+static virClassPtr virDomainEventBlockThresholdClass;
static void virDomainEventDispose(void *obj);
static void virDomainEventLifecycleDispose(void *obj);
@@ -81,6 +82,7 @@ static void virDomainEventMigrationIterationDispose(void *obj);
static void virDomainEventJobCompletedDispose(void *obj);
static void virDomainEventDeviceRemovalFailedDispose(void *obj);
static void virDomainEventMetadataChangeDispose(void *obj);
+static void virDomainEventBlockThresholdDispose(void *obj);
static void
virDomainEventDispatchDefaultFunc(virConnectPtr conn,
@@ -277,6 +279,17 @@ struct _virDomainEventMetadataCange {
typedef struct _virDomainEventMetadataCange virDomainEventMetadataChange;
typedef virDomainEventMetadataChange *virDomainEventMetadataChangePtr;
+struct _virDomainEventBlockThreshold {
+ virDomainEvent parent;
+
+ char *dev;
+ char *path;
+
+ unsigned long long threshold;
+ unsigned long long excess;
+};
+typedef struct _virDomainEventBlockThreshold virDomainEventBlockThreshold;
+typedef virDomainEventBlockThreshold *virDomainEventBlockThresholdPtr;
static int
@@ -402,6 +415,12 @@ virDomainEventsOnceInit(void)
sizeof(virDomainEventMetadataChange),
virDomainEventMetadataChangeDispose)))
return -1;
+ if (!(virDomainEventBlockThresholdClass =
+ virClassNew(virDomainEventClass,
+ "virDomainEventBlockThreshold",
+ sizeof(virDomainEventBlockThreshold),
+ virDomainEventBlockThresholdDispose)))
+ return -1;
return 0;
}
@@ -600,6 +619,17 @@ virDomainEventMetadataChangeDispose(void *obj)
}
+static void
+virDomainEventBlockThresholdDispose(void *obj)
+{
+ virDomainEventBlockThresholdPtr event = obj;
+ VIR_DEBUG("obj=%p", event);
+
+ VIR_FREE(event->dev);
+ VIR_FREE(event->path);
+}
+
+
static void *
virDomainEventNew(virClassPtr klass,
int eventID,
@@ -1674,6 +1704,60 @@ virDomainEventMetadataChangeNewFromDom(virDomainPtr dom,
}
+static virObjectEventPtr
+virDomainEventBlockThresholdNew(int id,
+ const char *name,
+ unsigned char *uuid,
+ const char *dev,
+ const char *path,
+ unsigned long long threshold,
+ unsigned long long excess)
+{
+ virDomainEventBlockThresholdPtr ev;
+
+ if (virDomainEventsInitialize() < 0)
+ return NULL;
+
+ if (!(ev = virDomainEventNew(virDomainEventBlockThresholdClass,
+ VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD,
+ id, name, uuid)))
+ return NULL;
+
+ if (VIR_STRDUP(ev->dev, dev) < 0 ||
+ VIR_STRDUP(ev->path, path) < 0) {
+ virObjectUnref(ev);
+ return NULL;
+ }
+ ev->threshold = threshold;
+ ev->excess = excess;
+
+ return (virObjectEventPtr)ev;
+}
+
+virObjectEventPtr
+virDomainEventBlockThresholdNewFromObj(virDomainObjPtr obj,
+ const char *dev,
+ const char *path,
+ unsigned long long threshold,
+ unsigned long long excess)
+{
+ return virDomainEventBlockThresholdNew(obj->def->id, obj->def->name,
+ obj->def->uuid, dev, path,
+ threshold, excess);
+}
+
+virObjectEventPtr
+virDomainEventBlockThresholdNewFromDom(virDomainPtr dom,
+ const char *dev,
+ const char *path,
+ unsigned long long threshold,
+ unsigned long long excess)
+{
+ return virDomainEventBlockThresholdNew(dom->id, dom->name, dom->uuid,
+ dev, path, threshold, excess);
+}
+
+
static void
virDomainEventDispatchDefaultFunc(virConnectPtr conn,
virObjectEventPtr event,
@@ -1943,6 +2027,19 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
goto cleanup;
}
+ case VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD:
+ {
+ virDomainEventBlockThresholdPtr blockThresholdEvent;
+
+ blockThresholdEvent = (virDomainEventBlockThresholdPtr)event;
+ ((virConnectDomainEventBlockThresholdCallback)cb)(conn, dom,
+
blockThresholdEvent->dev,
+
blockThresholdEvent->path,
+
blockThresholdEvent->threshold,
+
blockThresholdEvent->excess,
+ cbopaque);
+ goto cleanup;
+ }
case VIR_DOMAIN_EVENT_ID_LAST:
break;
}
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index 1933f4724..3992a29c5 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -244,6 +244,21 @@ virDomainEventMetadataChangeNewFromDom(virDomainPtr dom,
int type,
const char *nsuri);
+
+virObjectEventPtr
+virDomainEventBlockThresholdNewFromObj(virDomainObjPtr obj,
+ const char *dev,
+ const char *path,
+ unsigned long long threshold,
+ unsigned long long excess);
+
+virObjectEventPtr
+virDomainEventBlockThresholdNewFromDom(virDomainPtr dom,
+ const char *dev,
+ const char *path,
+ unsigned long long threshold,
+ unsigned long long excess);
+
int
virDomainEventStateRegister(virConnectPtr conn,
virObjectEventStatePtr state,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 078cca001..c0a037011 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -536,6 +536,8 @@ virDomainEventBlockJob2NewFromDom;
virDomainEventBlockJob2NewFromObj;
virDomainEventBlockJobNewFromDom;
virDomainEventBlockJobNewFromObj;
+virDomainEventBlockThresholdNewFromDom;
+virDomainEventBlockThresholdNewFromObj;
virDomainEventControlErrorNewFromDom;
virDomainEventControlErrorNewFromObj;
virDomainEventDeviceAddedNewFromDom;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 0c8bfeed1..efa47beaf 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -396,6 +396,11 @@ remoteSecretBuildEventValueChanged(virNetClientProgramPtr prog
ATTRIBUTE_UNUSED,
void *evdata, void *opaque);
static void
+remoteDomainBuildEventBlockThreshold(virNetClientProgramPtr prog,
+ virNetClientPtr client,
+ void *evdata, void *opaque);
+
+static void
remoteConnectNotifyEventConnectionClosed(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
virNetClientPtr client ATTRIBUTE_UNUSED,
void *evdata, void *opaque);
@@ -602,6 +607,10 @@ static virNetClientProgramEvent remoteEvents[] = {
remoteSecretBuildEventValueChanged,
sizeof(remote_secret_event_value_changed_msg),
(xdrproc_t)xdr_remote_secret_event_value_changed_msg },
+ { REMOTE_PROC_DOMAIN_EVENT_BLOCK_THRESHOLD,
+ remoteDomainBuildEventBlockThreshold,
+ sizeof(remote_domain_event_block_threshold_msg),
+ (xdrproc_t)xdr_remote_domain_event_block_threshold_msg },
};
static void
@@ -5577,6 +5586,30 @@ remoteSecretGetValue(virSecretPtr secret, size_t *value_size,
}
+static void
+remoteDomainBuildEventBlockThreshold(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
+ virNetClientPtr client ATTRIBUTE_UNUSED,
+ void *evdata, void *opaque)
+{
+ virConnectPtr conn = opaque;
+ remote_domain_event_block_threshold_msg *msg = evdata;
+ struct private_data *priv = conn->privateData;
+ virDomainPtr dom;
+ virObjectEventPtr event = NULL;
+
+ if (!(dom = get_nonnull_domain(conn, msg->dom)))
+ return;
+
+ event = virDomainEventBlockThresholdNewFromDom(dom, msg->dev,
+ msg->path ? *msg->path : NULL,
+ msg->threshold, msg->excess);
+
+ virObjectUnref(dom);
+
+ remoteEventQueue(priv, event, msg->callbackID);
+}
+
+
static int
remoteStreamSend(virStreamPtr st,
const char *data,
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index abe63af07..39dd2b728 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -3071,6 +3071,15 @@ struct remote_domain_event_block_job_2_msg {
int status;
};
+struct remote_domain_event_block_threshold_msg {
+ int callbackID;
+ remote_nonnull_domain dom;
+ remote_nonnull_string dev;
+ remote_string path;
+ unsigned hyper threshold;
+ unsigned hyper excess;
+};
+
struct remote_domain_event_callback_tunable_msg {
int callbackID;
remote_nonnull_domain dom;
@@ -6033,5 +6042,12 @@ enum remote_procedure {
* @acl: domain:save:!VIR_DOMAIN_AFFECT_CONFIG|VIR_DOMAIN_AFFECT_LIVE
* @acl: domain:save:VIR_DOMAIN_AFFECT_CONFIG
*/
- REMOTE_PROC_DOMAIN_SET_VCPU = 384
+ REMOTE_PROC_DOMAIN_SET_VCPU = 384,
+
+ /**
+ * @generate: both
+ * @acl: none
+ */
+ REMOTE_PROC_DOMAIN_EVENT_BLOCK_THRESHOLD = 385
+
};
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index e1e53d21b..67e43a4ac 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2516,6 +2516,14 @@ struct remote_domain_event_block_job_2_msg {
int type;
int status;
};
+struct remote_domain_event_block_threshold_msg {
+ int callbackID;
+ remote_nonnull_domain dom;
+ remote_nonnull_string dev;
+ remote_string path;
+ uint64_t threshold;
+ uint64_t excess;
+};
struct remote_domain_event_callback_tunable_msg {
int callbackID;
remote_nonnull_domain dom;
@@ -3217,4 +3225,5 @@ enum remote_procedure {
REMOTE_PROC_SECRET_EVENT_LIFECYCLE = 382,
REMOTE_PROC_SECRET_EVENT_VALUE_CHANGED = 383,
REMOTE_PROC_DOMAIN_SET_VCPU = 384,
+ REMOTE_PROC_DOMAIN_EVENT_BLOCK_THRESHOLD = 385,
};
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 09a9f8203..ee702f3c4 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -12870,6 +12870,25 @@ virshEventMetadataChangePrint(virConnectPtr conn
ATTRIBUTE_UNUSED,
}
+static void
+virshEventBlockThresholdPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ const char *dev,
+ const char *path,
+ unsigned long long threshold,
+ unsigned long long excess,
+ void *opaque)
+{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+ virBufferAsprintf(&buf, _("event 'block-threshold' for domain %s:
"
+ "dev: %s(%s) %llu %llu\n"),
+ virDomainGetName(dom),
+ dev, NULLSTR(path), threshold, excess);
+ virshEventPrint(opaque, &buf);
+}
+
+
static vshEventCallback vshEventCallbacks[] = {
{ "lifecycle",
VIR_DOMAIN_EVENT_CALLBACK(virshEventLifecyclePrint), },
@@ -12917,6 +12936,8 @@ static vshEventCallback vshEventCallbacks[] = {
VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceRemovalFailedPrint), },
{ "metadata-change",
VIR_DOMAIN_EVENT_CALLBACK(virshEventMetadataChangePrint), },
+ { "block-threshold",
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockThresholdPrint), },
};
verify(VIR_DOMAIN_EVENT_ID_LAST == ARRAY_CARDINALITY(vshEventCallbacks));
--
2.11.1