[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 04/29] postcopy: Add notifier chain
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v3 04/29] postcopy: Add notifier chain |
Date: |
Fri, 16 Feb 2018 13:16:00 +0000 |
From: "Dr. David Alan Gilbert" <address@hidden>
Add a notifier chain for postcopy with a 'reason' flag
and an opportunity for a notifier member to return an error.
Call it when enabling postcopy.
This will initially used to enable devices to declare they're unable
to postcopy and later to notify of devices of stages within postcopy.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
Reviewed-by: Peter Xu <address@hidden>
---
migration/postcopy-ram.c | 36 ++++++++++++++++++++++++++++++++++++
migration/postcopy-ram.h | 26 ++++++++++++++++++++++++++
vl.c | 2 ++
3 files changed, 64 insertions(+)
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 6297979700..fa98cf353b 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -23,6 +23,8 @@
#include "savevm.h"
#include "postcopy-ram.h"
#include "ram.h"
+#include "qapi/error.h"
+#include "qemu/notify.h"
#include "sysemu/sysemu.h"
#include "sysemu/balloon.h"
#include "qemu/error-report.h"
@@ -45,6 +47,33 @@ struct PostcopyDiscardState {
unsigned int nsentcmds;
};
+static NotifierWithReturnList postcopy_notifier_list;
+
+void postcopy_infrastructure_init(void)
+{
+ notifier_with_return_list_init(&postcopy_notifier_list);
+}
+
+void postcopy_add_notifier(NotifierWithReturn *nn)
+{
+ notifier_with_return_list_add(&postcopy_notifier_list, nn);
+}
+
+void postcopy_remove_notifier(NotifierWithReturn *n)
+{
+ notifier_with_return_remove(n);
+}
+
+int postcopy_notify(enum PostcopyNotifyReason reason, Error **errp)
+{
+ struct PostcopyNotifyData pnd;
+ pnd.reason = reason;
+ pnd.errp = errp;
+
+ return notifier_with_return_list_notify(&postcopy_notifier_list,
+ &pnd);
+}
+
/* Postcopy needs to detect accesses to pages that haven't yet been copied
* across, and efficiently map new pages in, the techniques for doing this
* are target OS specific.
@@ -215,6 +244,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState
*mis)
struct uffdio_register reg_struct;
struct uffdio_range range_struct;
uint64_t feature_mask;
+ Error *local_err = NULL;
if (qemu_target_page_size() > pagesize) {
error_report("Target page size bigger than host page size");
@@ -228,6 +258,12 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState
*mis)
goto out;
}
+ /* Give devices a chance to object */
+ if (postcopy_notify(POSTCOPY_NOTIFY_PROBE, &local_err)) {
+ error_report_err(local_err);
+ goto out;
+ }
+
/* Version and features check */
if (!ufd_check_and_apply(ufd, mis)) {
goto out;
diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h
index 77ea0fd264..1eaf7975e9 100644
--- a/migration/postcopy-ram.h
+++ b/migration/postcopy-ram.h
@@ -114,4 +114,30 @@ PostcopyState postcopy_state_get(void);
/* Set the state and return the old state */
PostcopyState postcopy_state_set(PostcopyState new_state);
+/*
+ * To be called once at the start before any device initialisation
+ */
+void postcopy_infrastructure_init(void);
+
+/* Add a notifier to a list to be called when checking whether the devices
+ * can support postcopy.
+ * It's data is a *PostcopyNotifyData
+ * It should return 0 if OK, or a negative value on failure.
+ * On failure it must set the data->errp to an error.
+ *
+ */
+enum PostcopyNotifyReason {
+ POSTCOPY_NOTIFY_PROBE = 0,
+};
+
+struct PostcopyNotifyData {
+ enum PostcopyNotifyReason reason;
+ Error **errp;
+};
+
+void postcopy_add_notifier(NotifierWithReturn *nn);
+void postcopy_remove_notifier(NotifierWithReturn *n);
+/* Call the notifier list set by postcopy_add_start_notifier */
+int postcopy_notify(enum PostcopyNotifyReason reason, Error **errp);
+
#endif
diff --git a/vl.c b/vl.c
index 7a5554bc41..a092b3c6c6 100644
--- a/vl.c
+++ b/vl.c
@@ -94,6 +94,7 @@ int main(int argc, char **argv)
#include "audio/audio.h"
#include "sysemu/cpus.h"
#include "migration/colo.h"
+#include "migration/postcopy-ram.h"
#include "sysemu/kvm.h"
#include "sysemu/hax.h"
#include "qapi/qobject-input-visitor.h"
@@ -3119,6 +3120,7 @@ int main(int argc, char **argv, char **envp)
module_call_init(MODULE_INIT_OPTS);
runstate_init();
+ postcopy_infrastructure_init();
if (qcrypto_init(&err) < 0) {
error_reportf_err(err, "cannot initialize crypto: ");
--
2.14.3
- [Qemu-devel] [PATCH v3 00/29] postcopy+vhost-user/shared ram, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 01/29] migrate: Update ram_block_discard_range for shared, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 02/29] qemu_ram_block_host_offset, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 03/29] postcopy: use UFFDIO_ZEROPAGE only when available, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 04/29] postcopy: Add notifier chain,
Dr. David Alan Gilbert (git) <=
- [Qemu-devel] [PATCH v3 05/29] postcopy: Add vhost-user flag for postcopy and check it, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 08/29] libvhost-user: Open userfaultfd, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 07/29] libvhost-user: Support sending fds back to qemu, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 06/29] vhost-user: Add 'VHOST_USER_POSTCOPY_ADVISE' message, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 09/29] postcopy: Allow registering of fd handler, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 10/29] vhost+postcopy: Register shared ufd with postcopy, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 11/29] vhost+postcopy: Transmit 'listen' to client, Dr. David Alan Gilbert (git), 2018/02/16