#include "sysemu/numa.h"
#include "sysemu/sysemu.h"
#include "sysemu/reset.h"
+#include "sysemu/runstate.h"
#include "hw/virtio/virtio.h"
#include "hw/virtio/virtio-bus.h"
#include "hw/virtio/virtio-mem.h"
return;
}
- ret = ram_block_discard_range(rb, 0, qemu_ram_get_used_length(rb));
- if (ret) {
- error_setg_errno(errp, -ret, "Unexpected error discarding RAM");
- ram_block_coordinated_discard_require(false);
- return;
+ /*
+ * We don't know at this point whether shared RAM is migrated using
+ * QEMU or migrated using the file content. "x-ignore-shared" will be
+ * configured after realizing the device. So in case we have an
+ * incoming migration, simply always skip the discard step.
+ *
+ * Otherwise, make sure that we start with a clean slate: either the
+ * memory backend might get reused or the shared file might still have
+ * memory allocated.
+ */
+ if (!runstate_check(RUN_STATE_INMIGRATE)) {
+ ret = ram_block_discard_range(rb, 0, qemu_ram_get_used_length(rb));
+ if (ret) {
+ error_setg_errno(errp, -ret, "Unexpected error discarding RAM");
+ ram_block_coordinated_discard_require(false);
+ return;
+ }
}
virtio_mem_resize_usable_region(vmem, vmem->requested_size, true);
RamDiscardListener *rdl;
int ret;
- if (vmem->prealloc && !vmem->early_migration) {
- warn_report("Proper preallocation with migration requires a newer QEMU machine");
- }
-
/*
* We started out with all memory discarded and our memory region is mapped
* into an address space. Replay, now that we updated the bitmap.
}
}
+ /*
+ * If shared RAM is migrated using the file content and not using QEMU,
+ * don't mess with preallocation and postcopy.
+ */
+ if (migrate_ram_is_ignored(vmem->memdev->mr.ram_block)) {
+ return 0;
+ }
+
+ if (vmem->prealloc && !vmem->early_migration) {
+ warn_report("Proper preallocation with migration requires a newer QEMU machine");
+ }
+
if (migration_in_incoming_postcopy()) {
return 0;
}
return 0;
}
+ /*
+ * If shared RAM is migrated using the file content and not using QEMU,
+ * don't mess with preallocation and postcopy.
+ */
+ if (migrate_ram_is_ignored(rb)) {
+ return 0;
+ }
+
/*
* We restored the bitmap and verified that the basic properties
* match on source and destination, so we can go ahead and preallocate