Skip to contentSkip to conversation

migration/hostmem: Allow to fail early for postcopy on specific fs type

PATCH In review Peter Xu 3 participants 12 messages Apr 19, 2023 – Apr 26, 2023

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

v2 cover migration/hostmem: Allow to fail early for postcopy on specific fs type

v2:
- Replace the hostmem patch to use qemu_fd_getfs() instead [David]
- Define enum instead of using string for fs type [Dan]
- One more patch added to deliver error to QMP response (rather than keeping some of it in STDERR), so the response should contain richer information and looks prettier.

Postcopy can fail in a weird way when guest mem is put onto a random file:

https://bugzilla.redhat.com/show_bug.cgi?id=2057267

It's because we only check userfault privilege on dest QEMU but don't check memory types. We do so only until the UFFDIO_REGISTER right after we switch to postcopy live migration from precopy but it could be too late.

This series tries to make it fail early by checking ramblock fs type if backed by a memory-backend-file.

Now when it happens it'll fail the dest QEMU from the start:

./qemu-system-x86_64 \
        -global migration.x-postcopy-ram=on \
        -incoming defer \
        -object memory-backend-file,id=mem,size=128M,mem-path=$memfile \
        -machine memory-backend=mem

qemu-system-x86_64: Postcopy is not supported: Host backend files need to be TMPFS or HUGETLBFS only

It will also fail e.g. QMP migrate-set-capabilities properly:

{ "execute": "migrate-set-capabilities" , "arguments": { "capabilities": [ { "capability": "postcopy-ram", "state": true } ] } } {"error": {"class": "GenericError", "desc": "Postcopy is not supported: Host backend files need to be TMPFS or HUGETLBFS only"}}

Please have a look, thanks.

Peter Xu (4):
util/mmap-alloc: qemu_fd_getfs()
vl.c: Create late backends before migration object migration/postcopy: Detect file system on dest host
migration: Allow postcopy_ram_supported_by_host() to report err

 include/qemu/mmap-alloc.h |  7 +++
 migration/migration.c     |  9 ++--
 migration/postcopy-ram.c  | 89 +++++++++++++++++++++++++++------------
 migration/postcopy-ram.h  |  3 +-
 migration/savevm.c        |  3 +-
 softmmu/vl.c              |  9 +++-
 util/mmap-alloc.c         | 28 ++++++++++++
 7 files changed, 111 insertions(+), 37 deletions(-)
Signature · 1 line
2.39.1
author
#1 lore raw

PATCH v2 1/4 util/mmap-alloc: qemu_fd_getfs()

This new helper fetches file system type for a fd. Only Linux is implemented so far. Currently only tmpfs and hugetlbfs is defined, but it can grow per need.

---
 include/qemu/mmap-alloc.h |  7 +++++++
 util/mmap-alloc.c         | 28 ++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
include/qemu/mmap-alloc.h +7 -0
index 2825e231a7..8344daaa03 100644
@@ -1,8 +1,15 @@
 #ifndef QEMU_MMAP_ALLOC_H
 #define QEMU_MMAP_ALLOC_H
 
+typedef enum {
+    QEMU_FS_TYPE_UNKNOWN = 0,
+    QEMU_FS_TYPE_TMPFS,
+    QEMU_FS_TYPE_HUGETLBFS,
+    QEMU_FS_TYPE_NUM,
+} QemuFsType;
 
 size_t qemu_fd_getpagesize(int fd);
+QemuFsType qemu_fd_getfs(int fd);
 
 /**
  * qemu_ram_mmap: mmap anonymous memory, the specified file or device.
util/mmap-alloc.c +28 -0
index 5ed7d29183..ed14f9c64d 100644
@@ -27,8 +27,36 @@
 
 #ifdef CONFIG_LINUX
 #include <sys/vfs.h>
+#include <linux/magic.h>
 #endif
 
+QemuFsType qemu_fd_getfs(int fd)
+{
+#ifdef CONFIG_LINUX
+    struct statfs fs;
+    int ret;
+
+    if (fd < 0) {
+        return QEMU_FS_TYPE_UNKNOWN;
+    }
+
+    do {
+        ret = fstatfs(fd, &fs);
+    } while (ret != 0 && errno == EINTR);
+
+    switch (fs.f_type) {
+    case TMPFS_MAGIC:
+        return QEMU_FS_TYPE_TMPFS;
+    case HUGETLBFS_MAGIC:
+        return QEMU_FS_TYPE_HUGETLBFS;
+    default:
+        return QEMU_FS_TYPE_UNKNOWN;
+    }
+#else
+    return QEMU_FS_TYPE_UNKNOWN;
+#endif
+}
+
 size_t qemu_fd_getpagesize(int fd)
 {
 #ifdef CONFIG_LINUX
Signature · 1 line
2.39.1
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] util/mmap-alloc: qemu_fd_getfs()

Quoted 57 lines · Peter Xu

This new helper fetches file system type for a fd. Only Linux is implemented so far. Currently only tmpfs and hugetlbfs is defined, but it can grow per need.

---
  include/qemu/mmap-alloc.h |  7 +++++++
  util/mmap-alloc.c         | 28 ++++++++++++++++++++++++++++
  2 files changed, 35 insertions(+)
include/qemu/mmap-alloc.h +7 -0
index 2825e231a7..8344daaa03 100644
@@ -1,8 +1,15 @@
  #ifndef QEMU_MMAP_ALLOC_H
  #define QEMU_MMAP_ALLOC_H
 
+typedef enum {
+    QEMU_FS_TYPE_UNKNOWN = 0,
+    QEMU_FS_TYPE_TMPFS,
+    QEMU_FS_TYPE_HUGETLBFS,
+    QEMU_FS_TYPE_NUM,
+} QemuFsType;
 
  size_t qemu_fd_getpagesize(int fd);
+QemuFsType qemu_fd_getfs(int fd);
 
  /**
   * qemu_ram_mmap: mmap anonymous memory, the specified file or device.
util/mmap-alloc.c +17 -0
index 5ed7d29183..ed14f9c64d 100644
@@ -27,8 +27,36 @@
 
  #ifdef CONFIG_LINUX
  #include <sys/vfs.h>
+#include <linux/magic.h>
  #endif
 
+QemuFsType qemu_fd_getfs(int fd)
+{
+#ifdef CONFIG_LINUX
+    struct statfs fs;
+    int ret;
+
+    if (fd < 0) {
+        return QEMU_FS_TYPE_UNKNOWN;
+    }
+
+    do {
+        ret = fstatfs(fd, &fs);
+    } while (ret != 0 && errno == EINTR);
+
+    switch (fs.f_type) {
+    case TMPFS_MAGIC:

util/mmap-alloc.c line 58

Quoted 10 lines
util/mmap-alloc.c +10 -0
+        return QEMU_FS_TYPE_TMPFS;
+    case HUGETLBFS_MAGIC:
+        return QEMU_FS_TYPE_HUGETLBFS;
+    default:
+        return QEMU_FS_TYPE_UNKNOWN;
+    }
+#else
+    return QEMU_FS_TYPE_UNKNOWN;
+#endif
+}

I guess you could do

#ifdef CONFIG_LINUX
...

    default:
        break
    }
#endif
    return QEMU_FS_TYPE_UNKNOWN;

To avoid duplicating the default handling. Whatever you prefer:

Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v2 1/4
#3 lore raw

Re: [PATCH v2 1/4] util/mmap-alloc: qemu_fd_getfs()

In reply to Peter Xu
Quoted 2 lines · Peter Xu

This new helper fetches file system type for a fd. Only Linux is implemented so far. Currently only tmpfs and hugetlbfs is defined, but it

s/is/are/

Quoted 3 lines

can grow per need.

...

Quoted 1 line

+#include <linux/magic.h>

...

Quoted 1 line

+ case TMPFS_MAGIC:

...

Quoted 1 line

+ case HUGETLBFS_MAGIC:

Everybody loves magic, right? O:-)

author
#4 lore raw

PATCH v2 2/4 vl.c: Create late backends before migration object

In reply to Peter Xu

The migration object may want to check against different types of memory when initialized. Delay the creation to be after late backends.

---
 softmmu/vl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
softmmu/vl.c +7 -2
index ea20b23e4c..ad394b402f 100644
@@ -3583,14 +3583,19 @@ void qemu_init(int argc, char **argv)
                      machine_class->name, machine_class->deprecation_reason);
     }
 
+    /*
+     * Create backends before creating migration objects, so that it can
+     * check against compatibilities on the backend memories (e.g. postcopy
+     * over memory-backend-file objects).
+     */
+    qemu_create_late_backends();
+
     /*
      * Note: creates a QOM object, must run only after global and
      * compat properties have been set up.
      */
     migration_object_init();
 
-    qemu_create_late_backends();
-
     /* parse features once if machine provides default cpu_type */
     current_machine->cpu_type = machine_class->default_cpu_type;
     if (cpu_option) {
Signature · 1 line
2.39.1
Reviewed-by on v2 2/4
#5 lore raw

Re: [PATCH v2 2/4] vl.c: Create late backends before migration object

Quoted 24 lines · Peter Xu

The migration object may want to check against different types of memory when initialized. Delay the creation to be after late backends.

---
  softmmu/vl.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
softmmu/vl.c +7 -0
index ea20b23e4c..ad394b402f 100644
@@ -3583,14 +3583,19 @@ void qemu_init(int argc, char **argv)
                       machine_class->name, machine_class->deprecation_reason);
      }
 
+    /*
+     * Create backends before creating migration objects, so that it can
+     * check against compatibilities on the backend memories (e.g. postcopy
+     * over memory-backend-file objects).
+     */
+    qemu_create_late_backends();
+
      /*

softmmu/vl.c void qemu_init(int argc, char **argv) · line 3601

Quoted 10 lines
softmmu/vl.c +0 -2
       * Note: creates a QOM object, must run only after global and
       * compat properties have been set up.
       */
      migration_object_init();
 
-    qemu_create_late_backends();
-
      /* parse features once if machine provides default cpu_type */
      current_machine->cpu_type = machine_class->default_cpu_type;
      if (cpu_option) {
Signature · 3 lines
Thanks,

David / dhildenb
author
#7 lore raw

PATCH v2 3/4 migration/postcopy: Detect file system on dest host

In reply to Peter Xu

Postcopy requires the memory support userfaultfd to work. Right now we check it but it's a bit too late (when switching to postcopy migration).

Do that early right at enabling of postcopy.

Note that this is still only a best effort because ramblocks can be dynamically created. We can add check in hostmem creations and fail if postcopy enabled, but maybe that's too aggressive.

Still, we have chance to fail the most obvious where we know there's an existing unsupported ramblock.

---
 migration/postcopy-ram.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)
migration/postcopy-ram.c +30 -4
index 93f39f8e06..bbb8af61ae 100644
@@ -36,6 +36,7 @@
 #include "yank_functions.h"
 #include "tls.h"
 #include "qemu/userfaultfd.h"
+#include "qemu/mmap-alloc.h"
 
 /* Arbitrary limit on size of each discard command,
  * keeps them around ~200 bytes
@@ -336,11 +337,12 @@ static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
 
 /* Callback from postcopy_ram_supported_by_host block iterator.
  */
-static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
+static int test_ramblock_postcopiable(RAMBlock *rb)
 {
     const char *block_name = qemu_ram_get_idstr(rb);
     ram_addr_t length = qemu_ram_get_used_length(rb);
     size_t pagesize = qemu_ram_pagesize(rb);
+    QemuFsType fs;
 
     if (length % pagesize) {
         error_report("Postcopy requires RAM blocks to be a page size multiple,"
@@ -348,6 +350,15 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
                      "page size of 0x%zx", block_name, length, pagesize);
         return 1;
     }
+
+    if (rb->fd >= 0) {
+        fs = qemu_fd_getfs(rb->fd);
+        if (fs != QEMU_FS_TYPE_TMPFS && fs != QEMU_FS_TYPE_HUGETLBFS) {
+            error_report("Host backend files need to be TMPFS or HUGETLBFS only");
+            return 1;
+        }
+    }
+
     return 0;
 }
 
@@ -366,6 +377,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
     struct uffdio_range range_struct;
     uint64_t feature_mask;
     Error *local_err = NULL;
+    RAMBlock *block;
 
     if (qemu_target_page_size() > pagesize) {
         error_report("Target page size bigger than host page size");
@@ -390,9 +402,23 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
         goto out;
     }
 
-    /* We don't support postcopy with shared RAM yet */
-    if (foreach_not_ignored_block(test_ramblock_postcopiable, NULL)) {
-        goto out;
+    /*
+     * We don't support postcopy with some type of ramblocks.
+     *
+     * NOTE: we explicitly ignored ramblock_is_ignored() instead we checked
+     * all possible ramblocks.  This is because this function can be called
+     * when creating the migration object, during the phase RAM_MIGRATABLE
+     * is not even properly set for all the ramblocks.
+     *
+     * A side effect of this is we'll also check against RAM_SHARED
+     * ramblocks even if migrate_ignore_shared() is set (in which case
+     * we'll never migrate RAM_SHARED at all), but normally this shouldn't
+     * affect in reality, or we can revisit.
+     */
+    RAMBLOCK_FOREACH(block) {
+        if (test_ramblock_postcopiable(block)) {
+            goto out;
+        }
     }
 
     /*
Signature · 1 line
2.39.1
Reviewed-by on v2 3/4
#8 lore raw

Re: [PATCH v2 3/4] migration/postcopy: Detect file system on dest host

Quoted 5 lines · Peter Xu

Postcopy requires the memory support userfaultfd to work. Right now we check it but it's a bit too late (when switching to postcopy migration).

Do that early right at enabling of postcopy.

Quoted 8 lines

Note that this is still only a best effort because ramblocks can be dynamically created. We can add check in hostmem creations and fail if postcopy enabled, but maybe that's too aggressive.

Still, we have chance to fail the most obvious where we know there's an existing unsupported ramblock.

migration/postcopy-ram.c static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis) · line 340

Quoted 2 lines
migration/postcopy-ram.c +1 -1
-static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
+static int test_ramblock_postcopiable(RAMBlock *rb)

This should return a bool, right?
Notice that it was already there, just noticing.

Quoted 5 lines
 {
     const char *block_name = qemu_ram_get_idstr(rb);
     ram_addr_t length = qemu_ram_get_used_length(rb);
     size_t pagesize = qemu_ram_pagesize(rb);

+ QemuFsType fs;

You can move the variable definition to the only block that it is used.

migration/postcopy-ram.c static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque) · line 355

Quoted 9 lines

if (length % pagesize) {
error_report("Postcopy requires RAM blocks to be a page size multiple,"

migration/postcopy-ram.c +3 -0
@@ -348,6 +350,15 @@ static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
                      "page size of 0x%zx", block_name, length, pagesize);
         return 1;
     }
+
+    if (rb->fd >= 0) {
+        fs = qemu_fd_getfs(rb->fd);

Minor nit: Seeing it in use, I wonder if it is clearer to name the function:

qemu_fd_get_filesystem(fd)

migration/postcopy-ram.c static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque) · line 357

Quoted 2 lines
migration/postcopy-ram.c +2 -0
+        if (fs != QEMU_FS_TYPE_TMPFS && fs != QEMU_FS_TYPE_HUGETLBFS) {
+            error_report("Host backend files need to be TMPFS or HUGETLBFS only");

I think that the "only" is not needed on that error message.

Quoted 25 lines
migration/postcopy-ram.c +8 -3
+            return 1;
+        }
+    }
+
     return 0;
 }
 
@@ -366,6 +377,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
     struct uffdio_range range_struct;
     uint64_t feature_mask;
     Error *local_err = NULL;
+    RAMBlock *block;
 
     if (qemu_target_page_size() > pagesize) {
         error_report("Target page size bigger than host page size");
@@ -390,9 +402,23 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
         goto out;
     }
 
-    /* We don't support postcopy with shared RAM yet */
-    if (foreach_not_ignored_block(test_ramblock_postcopiable, NULL)) {
-        goto out;
+    /*
+     * We don't support postcopy with some type of ramblocks.
+     *

migration/postcopy-ram.c bool postcopy_ram_supported_by_host(MigrationIncomingState *mis) · line 417

Quoted 10 lines
migration/postcopy-ram.c +10 -0
+     * NOTE: we explicitly ignored ramblock_is_ignored() instead we checked
+     * all possible ramblocks.  This is because this function can be called
+     * when creating the migration object, during the phase RAM_MIGRATABLE
+     * is not even properly set for all the ramblocks.
+     *
+     * A side effect of this is we'll also check against RAM_SHARED
+     * ramblocks even if migrate_ignore_shared() is set (in which case
+     * we'll never migrate RAM_SHARED at all), but normally this shouldn't
+     * affect in reality, or we can revisit.
+     */

I think we can tweak the English of that two paragraphs.

migration/postcopy-ram.c bool postcopy_ram_supported_by_host(MigrationIncomingState *mis) · line 424

Quoted 7 lines
migration/postcopy-ram.c +4 -0
+    RAMBLOCK_FOREACH(block) {
+        if (test_ramblock_postcopiable(block)) {
+            goto out;
+        }
     }
 
     /*

In the big scheme of things, patch is ok for me.

Later, Juan.

author
#9 lore raw

PATCH v2 4/4 migration: Allow postcopy_ram_supported_by_host() to report err

In reply to Peter Xu

Instead of print it to STDERR, bring the error upwards so that it can be reported via QMP responses.

E.g.:

{ "execute": "migrate-set-capabilities" ,
"arguments": { "capabilities":
[ { "capability": "postcopy-ram", "state": true } ] } }

{ "error":
{ "class": "GenericError",
"desc": "Postcopy is not supported: Host backend files need to be TMPFS or HUGETLBFS only" } }

---
 migration/migration.c    |  9 +++---
 migration/postcopy-ram.c | 61 ++++++++++++++++++++++------------------
 migration/postcopy-ram.h |  3 +-
 migration/savevm.c       |  3 +-
 4 files changed, 42 insertions(+), 34 deletions(-)
migration/migration.c +4 -5
index bda4789193..ac15fa6092 100644
@@ -1313,6 +1313,7 @@ static bool migrate_caps_check(bool *cap_list,
     MigrationCapabilityStatusList *cap;
     bool old_postcopy_cap;
     MigrationIncomingState *mis = migration_incoming_get_current();
+    Error *local_err = NULL;
 
     old_postcopy_cap = cap_list[MIGRATION_CAPABILITY_POSTCOPY_RAM];
 
@@ -1344,11 +1345,9 @@ static bool migrate_caps_check(bool *cap_list,
          * special support.
          */
         if (!old_postcopy_cap && runstate_check(RUN_STATE_INMIGRATE) &&
-            !postcopy_ram_supported_by_host(mis)) {
-            /* postcopy_ram_supported_by_host will have emitted a more
-             * detailed message
-             */
-            error_setg(errp, "Postcopy is not supported");
+            !postcopy_ram_supported_by_host(mis, &local_err)) {
+            error_propagate_prepend(errp, local_err,
+                                    "Postcopy is not supported: ");
             return false;
         }
 
migration/postcopy-ram.c +34 -27

183 lines not on this page · raw message

migration/postcopy-ram.h +2 -1
index b4867a32d5..442ab89752 100644
@@ -14,7 +14,8 @@
 #define QEMU_POSTCOPY_RAM_H
 
 /* Return true if the host supports everything we need to do postcopy-ram */
-bool postcopy_ram_supported_by_host(MigrationIncomingState *mis);
+bool postcopy_ram_supported_by_host(MigrationIncomingState *mis,
+                                    Error **errp);
 
 /*
  * Make all of RAM sensitive to accesses to areas that haven't yet been written
migration/savevm.c +2 -1
index aa54a67fda..0d61ab6c19 100644
@@ -1752,7 +1752,8 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,
         return -EINVAL;
     }
 
-    if (!postcopy_ram_supported_by_host(mis)) {
+    if (!postcopy_ram_supported_by_host(mis, &local_err)) {
+        error_report_err(local_err);
         postcopy_state_set(POSTCOPY_INCOMING_NONE);
         return -1;
     }
Signature · 1 line
2.39.1
#10 lore raw

Re: [PATCH v2 4/4] migration: Allow postcopy_ram_supported_by_host() to report err

Quoted 27 lines · Peter Xu

Instead of print it to STDERR, bring the error upwards so that it can be reported via QMP responses.

E.g.:

{ "execute": "migrate-set-capabilities" ,
"arguments": { "capabilities":
[ { "capability": "postcopy-ram", "state": true } ] } }

{ "error":
{ "class": "GenericError",
"desc": "Postcopy is not supported: Host backend files need to be TMPFS or HUGETLBFS only" } }

---
 migration/migration.c    |  9 +++---
 migration/postcopy-ram.c | 61 ++++++++++++++++++++++------------------
 migration/postcopy-ram.h |  3 +-
 migration/savevm.c       |  3 +-
 4 files changed, 42 insertions(+), 34 deletions(-)
migration/migration.c +0 -0
index bda4789193..ac15fa6092 100644

migration/migration.c static bool migrate_caps_check(bool *cap_list, · line 1316

Quoted 4 lines
migration/migration.c +1 -0
@@ -1313,6 +1313,7 @@ static bool migrate_caps_check(bool *cap_list,
     MigrationCapabilityStatusList *cap;
     bool old_postcopy_cap;
     MigrationIncomingState *mis = migration_incoming_get_current();
+    Error *local_err = NULL;

This variable can be declared in the only block that uses it.

Quoted 7 lines
migration/postcopy-ram.c +0 -0
index bbb8af61ae..0713ddeeef 100644
@@ -282,11 +282,14 @@ static bool request_ufd_features(int ufd, uint64_t features)
     return true;
 }

migration/postcopy-ram.c static bool request_ufd_features(int ufd, uint64_t features) · line 292

Quoted 10 lines
migration/postcopy-ram.c +4 -1
 
-static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
+static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis,
+                                Error **errp)
 {
     uint64_t asked_features = 0;
     static uint64_t supported_features;
 
+    assert(errp);
+

Is this right? My impression was that you have to live with errp being NULL.

error_setg() knows how to handle it being NULL:

error_setg() -> error_setg_internal() -> error_setv()

static void error_setv(Error **errp,
const char *src, int line, const char *func, ErrorClass err_class, const char *fmt, va_list ap, const char *suffix)

{
    ....
    if (errp == NULL) {
        return;
    }

migration/postcopy-ram.c static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis) · line 343

Quoted 2 lines
migration/postcopy-ram.c +1 -1
-static int test_ramblock_postcopiable(RAMBlock *rb)
+static int test_ramblock_postcopiable(RAMBlock *rb, Error **errp)

In patch 3 you do this other change:

-static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque) +static int test_ramblock_postcopiable(RAMBlock *rb)

Can you do with a single change?

The idea of the patch is right.

Later, Juan.

author
#11 lore raw

Re: [PATCH v2 4/4] migration: Allow postcopy_ram_supported_by_host() to report err

Quoted 23 lines · Juan Quintela
Quoted 22 lines · Peter Xu

Instead of print it to STDERR, bring the error upwards so that it can be reported via QMP responses.

E.g.:

{ "execute": "migrate-set-capabilities" ,
"arguments": { "capabilities":
[ { "capability": "postcopy-ram", "state": true } ] } }

{ "error":
{ "class": "GenericError",
"desc": "Postcopy is not supported: Host backend files need to be TMPFS or HUGETLBFS only" } }

---
 migration/migration.c    |  9 +++---
 migration/postcopy-ram.c | 61 ++++++++++++++++++++++------------------
 migration/postcopy-ram.h |  3 +-
 migration/savevm.c       |  3 +-
 4 files changed, 42 insertions(+), 34 deletions(-)
Quoted 11 lines

migration/migration.c static bool migrate_caps_check(bool *cap_list, · line 1316

Quoted 9 lines
migration/migration.c +1 -0
index bda4789193..ac15fa6092 100644
@@ -1313,6 +1313,7 @@ static bool migrate_caps_check(bool *cap_list,
     MigrationCapabilityStatusList *cap;
     bool old_postcopy_cap;
     MigrationIncomingState *mis = migration_incoming_get_current();
+    Error *local_err = NULL;

This variable can be declared in the only block that uses it.

Sure, though I just remembered I can use ERRP_GUARD(), hence I'll go with that.

Quoted 16 lines
Quoted 16 lines
migration/postcopy-ram.c +2 -1
index bbb8af61ae..0713ddeeef 100644
@@ -282,11 +282,14 @@ static bool request_ufd_features(int ufd, uint64_t features)
     return true;
 }
 
-static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis)
+static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis,
+                                Error **errp)
 {
     uint64_t asked_features = 0;
     static uint64_t supported_features;
 
Quoted 4 lines

migration/postcopy-ram.c static bool request_ufd_features(int ufd, uint64_t features) · line 292

Quoted 2 lines
migration/postcopy-ram.c +2 -0
+    assert(errp);
+

Is this right? My impression was that you have to live with errp being NULL.

Right it knows, I just wanted to make sure error msg got captured, but we don't really need to worrry here, all callers are in this case I believe.

Let me also switch to ERRP_GUARD() just to still avoid error_abort being passed in, so we can still abort with a full message.

Quoted 24 lines

error_setg() knows how to handle it being NULL:

error_setg() -> error_setg_internal() -> error_setv()

static void error_setv(Error **errp,
const char *src, int line, const char *func, ErrorClass err_class, const char *fmt, va_list ap, const char *suffix)

{
    ....
    if (errp == NULL) {
        return;
    }

migration/postcopy-ram.c static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis) · line 343

Quoted 2 lines
migration/postcopy-ram.c +1 -1
-static int test_ramblock_postcopiable(RAMBlock *rb)
+static int test_ramblock_postcopiable(RAMBlock *rb, Error **errp)

In patch 3 you do this other change:

(quoted diff) +1 -1
-static int test_ramblock_postcopiable(RAMBlock *rb, void *opaque)
+static int test_ramblock_postcopiable(RAMBlock *rb)
Quoted 3 lines

Can you do with a single change?

The idea of the patch is right.

I saw that patch 3 already merged. I'll just spin this one, thanks!

Signature · 1 line
Peter Xu