[PATCH v2 15/25] migration: introduce vmstate_event_notifier

Vladimir Sementsov-Ogievskiy posted 25 patches 4 weeks, 1 day ago
[PATCH v2 15/25] migration: introduce vmstate_event_notifier
Posted by Vladimir Sementsov-Ogievskiy 4 weeks, 1 day ago
This will be used to support backend-transfer migration for
vhost-user-blk, we'll migrate event notifier fds through
migration stream, to avoid extra contact with backend.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 include/migration/vmstate.h        |  7 ++++
 migration/meson.build              |  1 +
 migration/vmstate-event-notifier.c | 54 ++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 migration/vmstate-event-notifier.c

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index f243518fb5..7f1f1c166a 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -1294,4 +1294,11 @@ void vmstate_register_ram_global(struct MemoryRegion *memory);
 
 bool vmstate_check_only_migratable(const VMStateDescription *vmsd);
 
+extern const VMStateDescription vmstate_event_notifier;
+
+#define VMSTATE_EVENT_NOTIFIER(_field, _struct) \
+    VMSTATE_STRUCT(_field, _struct, 0, vmstate_event_notifier, \
+                   EventNotifier)
+
+
 #endif
diff --git a/migration/meson.build b/migration/meson.build
index 16909d54c5..b5341ae0cb 100644
--- a/migration/meson.build
+++ b/migration/meson.build
@@ -5,6 +5,7 @@ migration_files = files(
   'xbzrle.c',
   'vmstate-types.c',
   'vmstate.c',
+  'vmstate-event-notifier.c',
   'qemu-file.c',
   'yank_functions.c',
 )
diff --git a/migration/vmstate-event-notifier.c b/migration/vmstate-event-notifier.c
new file mode 100644
index 0000000000..2076eec961
--- /dev/null
+++ b/migration/vmstate-event-notifier.c
@@ -0,0 +1,54 @@
+/*
+ * Event notifier migration support
+ * Copyright (c) Yandex Technologies LLC, 2025
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/event_notifier.h"
+#include "migration/vmstate.h"
+
+static int event_notifier_pre_save(void *opaque)
+{
+    struct EventNotifier *e = opaque;
+
+    if (!e->initialized || e->rfd != e->wfd) {
+        return -1;
+    }
+
+    return 0;
+}
+
+static int event_notifier_pre_load(void *opaque)
+{
+    struct EventNotifier *e = opaque;
+
+    if (e->initialized) {
+        return -1;
+    }
+
+    return 0;
+}
+
+static int event_notifier_post_load(void *opaque, int version_id)
+{
+    struct EventNotifier *e = opaque;
+
+    if (e->rfd < 0) {
+        return -1;
+    }
+
+    e->wfd = e->rfd;
+    e->initialized = true;
+
+    return 0;
+}
+
+const VMStateDescription vmstate_event_notifier = {
+    .name = "event-notifier",
+    .pre_save = event_notifier_pre_save,
+    .pre_load = event_notifier_pre_load,
+    .post_load = event_notifier_post_load,
+    .fields = (const VMStateField[]){VMSTATE_FD(rfd, EventNotifier),
+                                     VMSTATE_END_OF_LIST()},
+};
-- 
2.48.1
Re: [PATCH v2 15/25] migration: introduce vmstate_event_notifier
Posted by Peter Xu 4 weeks, 1 day ago
On Thu, Oct 16, 2025 at 02:40:52PM +0300, Vladimir Sementsov-Ogievskiy wrote:
> This will be used to support backend-transfer migration for
> vhost-user-blk, we'll migrate event notifier fds through
> migration stream, to avoid extra contact with backend.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

Acked-by: Peter Xu <peterx@redhat.com>

Note: we recently merged _errp versions of all below three hooks.  You can
also switch to that if all of them can fail.  You can keep my A-b if you
switch over.

> ---
>  include/migration/vmstate.h        |  7 ++++
>  migration/meson.build              |  1 +
>  migration/vmstate-event-notifier.c | 54 ++++++++++++++++++++++++++++++
>  3 files changed, 62 insertions(+)
>  create mode 100644 migration/vmstate-event-notifier.c
> 
> diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
> index f243518fb5..7f1f1c166a 100644
> --- a/include/migration/vmstate.h
> +++ b/include/migration/vmstate.h
> @@ -1294,4 +1294,11 @@ void vmstate_register_ram_global(struct MemoryRegion *memory);
>  
>  bool vmstate_check_only_migratable(const VMStateDescription *vmsd);
>  
> +extern const VMStateDescription vmstate_event_notifier;
> +
> +#define VMSTATE_EVENT_NOTIFIER(_field, _struct) \
> +    VMSTATE_STRUCT(_field, _struct, 0, vmstate_event_notifier, \
> +                   EventNotifier)
> +
> +
>  #endif
> diff --git a/migration/meson.build b/migration/meson.build
> index 16909d54c5..b5341ae0cb 100644
> --- a/migration/meson.build
> +++ b/migration/meson.build
> @@ -5,6 +5,7 @@ migration_files = files(
>    'xbzrle.c',
>    'vmstate-types.c',
>    'vmstate.c',
> +  'vmstate-event-notifier.c',
>    'qemu-file.c',
>    'yank_functions.c',
>  )
> diff --git a/migration/vmstate-event-notifier.c b/migration/vmstate-event-notifier.c
> new file mode 100644
> index 0000000000..2076eec961
> --- /dev/null
> +++ b/migration/vmstate-event-notifier.c
> @@ -0,0 +1,54 @@
> +/*
> + * Event notifier migration support
> + * Copyright (c) Yandex Technologies LLC, 2025
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu/event_notifier.h"
> +#include "migration/vmstate.h"
> +
> +static int event_notifier_pre_save(void *opaque)
> +{
> +    struct EventNotifier *e = opaque;
> +
> +    if (!e->initialized || e->rfd != e->wfd) {
> +        return -1;
> +    }
> +
> +    return 0;
> +}
> +
> +static int event_notifier_pre_load(void *opaque)
> +{
> +    struct EventNotifier *e = opaque;
> +
> +    if (e->initialized) {
> +        return -1;
> +    }
> +
> +    return 0;
> +}
> +
> +static int event_notifier_post_load(void *opaque, int version_id)
> +{
> +    struct EventNotifier *e = opaque;
> +
> +    if (e->rfd < 0) {
> +        return -1;
> +    }
> +
> +    e->wfd = e->rfd;
> +    e->initialized = true;
> +
> +    return 0;
> +}
> +
> +const VMStateDescription vmstate_event_notifier = {
> +    .name = "event-notifier",
> +    .pre_save = event_notifier_pre_save,
> +    .pre_load = event_notifier_pre_load,
> +    .post_load = event_notifier_post_load,
> +    .fields = (const VMStateField[]){VMSTATE_FD(rfd, EventNotifier),
> +                                     VMSTATE_END_OF_LIST()},
> +};
> -- 
> 2.48.1
> 

-- 
Peter Xu
Re: [PATCH v2 15/25] migration: introduce vmstate_event_notifier
Posted by Vladimir Sementsov-Ogievskiy 4 weeks, 1 day ago
On 16.10.25 21:59, Peter Xu wrote:
> On Thu, Oct 16, 2025 at 02:40:52PM +0300, Vladimir Sementsov-Ogievskiy wrote:
>> This will be used to support backend-transfer migration for
>> vhost-user-blk, we'll migrate event notifier fds through
>> migration stream, to avoid extra contact with backend.
>>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
> 
> Acked-by: Peter Xu <peterx@redhat.com>
> 
> Note: we recently merged _errp versions of all below three hooks.  You can
> also switch to that if all of them can fail.  You can keep my A-b if you
> switch over.

O, yes, will do, thanks.



-- 
Best regards,
Vladimir