... | ... | ||
---|---|---|---|
6 | Also add a blocker for RAM_GUEST_MEMFD. Preserving guest_memfd may be | 6 | Also add a blocker for RAM_GUEST_MEMFD. Preserving guest_memfd may be |
7 | sufficient for CPR, but it has not been tested yet. | 7 | sufficient for CPR, but it has not been tested yet. |
8 | 8 | ||
9 | Signed-off-by: Steve Sistare <steven.sistare@oracle.com> | 9 | Signed-off-by: Steve Sistare <steven.sistare@oracle.com> |
10 | Reviewed-by: Fabiano Rosas <farosas@suse.de> | 10 | Reviewed-by: Fabiano Rosas <farosas@suse.de> |
11 | Reviewed-by: Peter Xu <peterx@redhat.com> | ||
11 | --- | 12 | --- |
12 | include/exec/memory.h | 3 +++ | 13 | include/exec/memory.h | 3 +++ |
13 | include/exec/ramblock.h | 1 + | 14 | include/exec/ramblock.h | 1 + |
14 | migration/savevm.c | 2 ++ | 15 | migration/savevm.c | 2 ++ |
15 | system/physmem.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ | 16 | system/physmem.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ |
... | ... | ||
94 | return qatomic_read(&ram_block_discard_required_cnt) || | 95 | return qatomic_read(&ram_block_discard_required_cnt) || |
95 | qatomic_read(&ram_block_coordinated_discard_required_cnt); | 96 | qatomic_read(&ram_block_coordinated_discard_required_cnt); |
96 | } | 97 | } |
97 | + | 98 | + |
98 | +/* | 99 | +/* |
99 | + * Return true if ram contents would be lost during CPR. Do not exclude rom, | 100 | + * Return true if ram is compatible with CPR. Do not exclude rom, |
100 | + * because the rom file could change in new QEMU. | 101 | + * because the rom file could change in new QEMU. |
101 | + */ | 102 | + */ |
102 | +static bool ram_is_volatile(RAMBlock *rb) | 103 | +static bool ram_is_cpr_compatible(RAMBlock *rb) |
103 | +{ | 104 | +{ |
104 | + MemoryRegion *mr = rb->mr; | 105 | + MemoryRegion *mr = rb->mr; |
105 | + | 106 | + |
106 | + if (!mr || !memory_region_is_ram(mr)) { | 107 | + if (!mr || !memory_region_is_ram(mr)) { |
107 | + return false; | 108 | + return true; |
108 | + } | 109 | + } |
109 | + | 110 | + |
110 | + /* Ram device is remapped in new QEMU */ | 111 | + /* Ram device is remapped in new QEMU */ |
111 | + if (memory_region_is_ram_device(mr)) { | 112 | + if (memory_region_is_ram_device(mr)) { |
112 | + return false; | 113 | + return true; |
113 | + } | 114 | + } |
114 | + | 115 | + |
115 | + /* Named files are remapped in new QEMU, same contents if shared (no COW) */ | 116 | + /* Named files are remapped in new QEMU, same contents if shared (no COW) */ |
116 | + if (qemu_ram_is_shared(rb) && qemu_ram_is_named_file(rb)) { | 117 | + if (qemu_ram_is_shared(rb) && qemu_ram_is_named_file(rb)) { |
117 | + return false; | 118 | + return true; |
118 | + } | 119 | + } |
119 | + | 120 | + |
120 | + /* A file descriptor is remapped in new QEMU */ | 121 | + /* A file descriptor is remapped in new QEMU */ |
121 | + if (rb->fd >= 0) { | 122 | + if (rb->fd >= 0) { |
122 | + return false; | 123 | + return true; |
123 | + } | 124 | + } |
124 | + | 125 | + |
125 | + return true; | 126 | + return false; |
126 | +} | 127 | +} |
127 | + | 128 | + |
128 | +/* | 129 | +/* |
129 | + * Add a blocker for each volatile ram block. This function should only be | 130 | + * Add a blocker for each volatile ram block. This function should only be |
130 | + * called after we know that the block is migratable. Non-migratable blocks | 131 | + * called after we know that the block is migratable. Non-migratable blocks |
... | ... | ||
133 | + */ | 134 | + */ |
134 | +void ram_block_add_cpr_blocker(RAMBlock *rb, Error **errp) | 135 | +void ram_block_add_cpr_blocker(RAMBlock *rb, Error **errp) |
135 | +{ | 136 | +{ |
136 | + assert(qemu_ram_is_migratable(rb)); | 137 | + assert(qemu_ram_is_migratable(rb)); |
137 | + | 138 | + |
138 | + if (!ram_is_volatile(rb)) { | 139 | + if (ram_is_cpr_compatible(rb)) { |
139 | + return; | 140 | + return; |
140 | + } | 141 | + } |
141 | + | 142 | + |
142 | + error_setg(&rb->cpr_blocker, | 143 | + error_setg(&rb->cpr_blocker, |
143 | + "Memory region %s is volatile. share=on is required for " | 144 | + "Memory region %s is not compatible with CPR. share=on is " |
144 | + "memory-backend objects, and aux-ram-share=on is required.", | 145 | + "required for memory-backend objects, and aux-ram-share=on is " |
145 | + memory_region_name(rb->mr)); | 146 | + "required.", memory_region_name(rb->mr)); |
146 | + migrate_add_blocker_modes(&rb->cpr_blocker, errp, MIG_MODE_CPR_TRANSFER, | 147 | + migrate_add_blocker_modes(&rb->cpr_blocker, errp, MIG_MODE_CPR_TRANSFER, |
147 | + -1); | 148 | + -1); |
148 | +} | 149 | +} |
149 | + | 150 | + |
150 | +void ram_block_del_cpr_blocker(RAMBlock *rb) | 151 | +void ram_block_del_cpr_blocker(RAMBlock *rb) |
151 | +{ | 152 | +{ |
152 | + migrate_del_blocker(&rb->cpr_blocker); | 153 | + migrate_del_blocker(&rb->cpr_blocker); |
153 | +} | 154 | +} |
154 | -- | 155 | -- |
155 | 1.8.3.1 | 156 | 1.8.3.1 | diff view generated by jsdifflib |