[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH V8 25/39] cpr: notifiers
From: |
Steve Sistare |
Subject: |
[PATCH V8 25/39] cpr: notifiers |
Date: |
Wed, 15 Jun 2022 07:52:12 -0700 |
Add an interface to register notifiers for cpr transitions. It is used to
support vfio cpr in a subsequent patch.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
include/migration/cpr.h | 13 +++++++++++++
migration/cpr.c | 25 +++++++++++++++++++++++++
stubs/cpr.c | 10 ++++++++++
3 files changed, 48 insertions(+)
diff --git a/include/migration/cpr.h b/include/migration/cpr.h
index b75dec4..ab5f53e 100644
--- a/include/migration/cpr.h
+++ b/include/migration/cpr.h
@@ -9,6 +9,7 @@
#define MIGRATION_CPR_H
#include "qapi/qapi-types-cpr.h"
+#include "qemu/notify.h"
void cpr_init(int modes);
void cpr_set_mode(CprMode mode);
@@ -37,4 +38,16 @@ int cpr_add_blocker(Error **reasonp, Error **errp, CprMode
mode, ...);
int cpr_add_blocker_str(const char *reason, Error **errp, CprMode mode, ...);
void cpr_del_blocker(Error **reasonp);
+typedef enum CprNotifyState {
+ CPR_NOTIFY_EXEC,
+ CPR_NOTIFY_SAVE_FAILED,
+ CPR_NOTIFY_LOAD_FAILED,
+ CPR_NOTIFY_NUM
+} CprNotifyState;
+
+void cpr_add_notifier(Notifier *notify,
+ void (*cb)(Notifier *notifier, void *data),
+ CprNotifyState state);
+void cpr_remove_notifier(Notifier *notify);
+
#endif
diff --git a/migration/cpr.c b/migration/cpr.c
index 8b3fffd..9d6bca4 100644
--- a/migration/cpr.c
+++ b/migration/cpr.c
@@ -105,6 +105,28 @@ static bool cpr_is_blocked(Error **errp, CprMode mode)
return false;
}
+static NotifierList cpr_notifiers[CPR_NOTIFY_NUM];
+
+void cpr_add_notifier(Notifier *notify,
+ void (*cb)(Notifier *notifier, void *data),
+ CprNotifyState state)
+{
+ assert(state >= 0 && state < CPR_NOTIFY_NUM);
+ notify->notify = cb;
+ notifier_list_add(&cpr_notifiers[state], notify);
+}
+
+void cpr_remove_notifier(Notifier *notify)
+{
+ notifier_remove(notify);
+ notify->notify = NULL;
+}
+
+static void cpr_call_notifiers(CprNotifyState state)
+{
+ notifier_list_notify(&cpr_notifiers[state], 0);
+}
+
void qmp_cpr_save(const char *filename, CprMode mode, Error **errp)
{
int ret;
@@ -142,6 +164,7 @@ void qmp_cpr_save(const char *filename, CprMode mode, Error
**errp)
qemu_fclose(f);
if (ret < 0) {
error_setg(errp, "Error %d while saving VM state", ret);
+ cpr_call_notifiers(CPR_NOTIFY_SAVE_FAILED);
goto err;
}
@@ -182,6 +205,7 @@ void qmp_cpr_exec(strList *args, Error **errp)
return;
}
+ cpr_call_notifiers(CPR_NOTIFY_EXEC);
assert(qemu_system_exec_request(args, errp) == 0);
}
@@ -218,6 +242,7 @@ void qmp_cpr_load(const char *filename, CprMode mode, Error
**errp)
qemu_fclose(f);
if (ret < 0) {
error_setg(errp, "Error %d while loading VM state", ret);
+ cpr_call_notifiers(CPR_NOTIFY_LOAD_FAILED);
goto out;
}
diff --git a/stubs/cpr.c b/stubs/cpr.c
index 06a9a1c..9262e78 100644
--- a/stubs/cpr.c
+++ b/stubs/cpr.c
@@ -21,3 +21,13 @@ int cpr_add_blocker_str(const char *reason, Error **errp,
CprMode mode, ...)
void cpr_del_blocker(Error **reasonp)
{
}
+
+void cpr_add_notifier(Notifier *notify,
+ void (*cb)(Notifier *notifier, void *data),
+ CprNotifyState state)
+{
+}
+
+void cpr_remove_notifier(Notifier *notify)
+{
+}
--
1.8.3.1
- Re: [PATCH V8 02/39] migration: qemu file wrappers, (continued)
- [PATCH V8 08/39] cpr: blockers, Steve Sistare, 2022/06/15
- [PATCH V8 10/39] cpr: cpr-enable option, Steve Sistare, 2022/06/15
- [PATCH V8 12/39] memory: flat section iterator, Steve Sistare, 2022/06/15
- [PATCH V8 09/39] cpr: register blockers, Steve Sistare, 2022/06/15
- [PATCH V8 11/39] cpr: save ram blocks, Steve Sistare, 2022/06/15
- [PATCH V8 13/39] oslib: qemu_clear_cloexec, Steve Sistare, 2022/06/15
- [PATCH V8 25/39] cpr: notifiers,
Steve Sistare <=
- [PATCH V8 20/39] cpr: restart mode, Steve Sistare, 2022/06/15
- [PATCH V8 29/39] vfio-pci: cpr part 3 (intx), Steve Sistare, 2022/06/15
- [PATCH V8 17/39] qapi: strList unit tests, Steve Sistare, 2022/06/15
- [PATCH V8 14/39] qapi: strList_from_string, Steve Sistare, 2022/06/15
- [PATCH V8 18/39] vl: helper to request re-exec, Steve Sistare, 2022/06/15
- [PATCH V8 22/39] cpr: ram block blockers, Steve Sistare, 2022/06/15
- [PATCH V8 23/39] hostmem-memfd: cpr for memory-backend-memfd, Steve Sistare, 2022/06/15