memory: Add Error** argument to the global_dirty_log routines

Now that the log_global*() handlers take an Error** parameter and
return a bool, do the same for memory_global_dirty_log_start() and
memory_global_dirty_log_stop(). The error is reported in the callers
for now and it will be propagated in the call stack in the next
changes.

To be noted a functional change in ram_init_bitmaps(), if the dirty
pages logger fails to start, there is no need to synchronize the dirty
pages bitmaps. colo_incoming_start_dirty_log() could be modified in a
similar way.

Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Paul Durrant <paul@xen.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Hyman Huang <yong.huang@smartx.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Acked-by: Peter Xu <peterx@redhat.com>
Link: https://lore.kernel.org/r/20240320064911.545001-12-clg@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
Cédric Le Goater 2024-03-20 07:49:07 +01:00 committed by Peter Xu
parent 92c20b2fc5
commit 639ec3fbf9
5 changed files with 42 additions and 12 deletions

View file

@ -669,7 +669,7 @@ void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
void qmp_xen_set_global_dirty_log(bool enable, Error **errp) void qmp_xen_set_global_dirty_log(bool enable, Error **errp)
{ {
if (enable) { if (enable) {
memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION, errp);
} else { } else {
memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION); memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION);
} }

View file

@ -2570,8 +2570,11 @@ void memory_listener_unregister(MemoryListener *listener);
* memory_global_dirty_log_start: begin dirty logging for all regions * memory_global_dirty_log_start: begin dirty logging for all regions
* *
* @flags: purpose of starting dirty log, migration or dirty rate * @flags: purpose of starting dirty log, migration or dirty rate
* @errp: pointer to Error*, to store an error if it happens.
*
* Return: true on success, else false setting @errp with error.
*/ */
void memory_global_dirty_log_start(unsigned int flags); bool memory_global_dirty_log_start(unsigned int flags, Error **errp);
/** /**
* memory_global_dirty_log_stop: end dirty logging for all regions * memory_global_dirty_log_stop: end dirty logging for all regions

View file

@ -90,9 +90,15 @@ static int64_t do_calculate_dirtyrate(DirtyPageRecord dirty_pages,
void global_dirty_log_change(unsigned int flag, bool start) void global_dirty_log_change(unsigned int flag, bool start)
{ {
Error *local_err = NULL;
bool ret;
bql_lock(); bql_lock();
if (start) { if (start) {
memory_global_dirty_log_start(flag); ret = memory_global_dirty_log_start(flag, &local_err);
if (!ret) {
error_report_err(local_err);
}
} else { } else {
memory_global_dirty_log_stop(flag); memory_global_dirty_log_stop(flag);
} }
@ -608,9 +614,12 @@ static void calculate_dirtyrate_dirty_bitmap(struct DirtyRateConfig config)
{ {
int64_t start_time; int64_t start_time;
DirtyPageRecord dirty_pages; DirtyPageRecord dirty_pages;
Error *local_err = NULL;
bql_lock(); bql_lock();
memory_global_dirty_log_start(GLOBAL_DIRTY_DIRTY_RATE); if (!memory_global_dirty_log_start(GLOBAL_DIRTY_DIRTY_RATE, &local_err)) {
error_report_err(local_err);
}
/* /*
* 1'round of log sync may return all 1 bits with * 1'round of log sync may return all 1 bits with

View file

@ -2862,18 +2862,32 @@ static void migration_bitmap_clear_discarded_pages(RAMState *rs)
static void ram_init_bitmaps(RAMState *rs) static void ram_init_bitmaps(RAMState *rs)
{ {
Error *local_err = NULL;
bool ret = true;
qemu_mutex_lock_ramlist(); qemu_mutex_lock_ramlist();
WITH_RCU_READ_LOCK_GUARD() { WITH_RCU_READ_LOCK_GUARD() {
ram_list_init_bitmaps(); ram_list_init_bitmaps();
/* We don't use dirty log with background snapshots */ /* We don't use dirty log with background snapshots */
if (!migrate_background_snapshot()) { if (!migrate_background_snapshot()) {
memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); ret = memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION,
&local_err);
if (!ret) {
error_report_err(local_err);
goto out_unlock;
}
migration_bitmap_sync_precopy(rs, false); migration_bitmap_sync_precopy(rs, false);
} }
} }
out_unlock:
qemu_mutex_unlock_ramlist(); qemu_mutex_unlock_ramlist();
if (!ret) {
ram_bitmaps_destroy();
return;
}
/* /*
* After an eventual first bitmap sync, fixup the initial bitmap * After an eventual first bitmap sync, fixup the initial bitmap
* containing all 1s to exclude any discarded pages from migration. * containing all 1s to exclude any discarded pages from migration.
@ -3665,6 +3679,8 @@ int colo_init_ram_cache(void)
void colo_incoming_start_dirty_log(void) void colo_incoming_start_dirty_log(void)
{ {
RAMBlock *block = NULL; RAMBlock *block = NULL;
Error *local_err = NULL;
/* For memory_global_dirty_log_start below. */ /* For memory_global_dirty_log_start below. */
bql_lock(); bql_lock();
qemu_mutex_lock_ramlist(); qemu_mutex_lock_ramlist();
@ -3676,7 +3692,10 @@ void colo_incoming_start_dirty_log(void)
/* Discard this dirty bitmap record */ /* Discard this dirty bitmap record */
bitmap_zero(block->bmap, block->max_length >> TARGET_PAGE_BITS); bitmap_zero(block->bmap, block->max_length >> TARGET_PAGE_BITS);
} }
memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); if (!memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION,
&local_err)) {
error_report_err(local_err);
}
} }
ram_state->migration_dirty_pages = 0; ram_state->migration_dirty_pages = 0;
qemu_mutex_unlock_ramlist(); qemu_mutex_unlock_ramlist();

View file

@ -2937,10 +2937,9 @@ err:
return false; return false;
} }
void memory_global_dirty_log_start(unsigned int flags) bool memory_global_dirty_log_start(unsigned int flags, Error **errp)
{ {
unsigned int old_flags; unsigned int old_flags;
Error *local_err = NULL;
assert(flags && !(flags & (~GLOBAL_DIRTY_MASK))); assert(flags && !(flags & (~GLOBAL_DIRTY_MASK)));
@ -2952,7 +2951,7 @@ void memory_global_dirty_log_start(unsigned int flags)
flags &= ~global_dirty_tracking; flags &= ~global_dirty_tracking;
if (!flags) { if (!flags) {
return; return true;
} }
old_flags = global_dirty_tracking; old_flags = global_dirty_tracking;
@ -2960,17 +2959,17 @@ void memory_global_dirty_log_start(unsigned int flags)
trace_global_dirty_changed(global_dirty_tracking); trace_global_dirty_changed(global_dirty_tracking);
if (!old_flags) { if (!old_flags) {
if (!memory_global_dirty_log_do_start(&local_err)) { if (!memory_global_dirty_log_do_start(errp)) {
global_dirty_tracking &= ~flags; global_dirty_tracking &= ~flags;
trace_global_dirty_changed(global_dirty_tracking); trace_global_dirty_changed(global_dirty_tracking);
error_report_err(local_err); return false;
return;
} }
memory_region_transaction_begin(); memory_region_transaction_begin();
memory_region_update_pending = true; memory_region_update_pending = true;
memory_region_transaction_commit(); memory_region_transaction_commit();
} }
return true;
} }
static void memory_global_dirty_log_do_stop(unsigned int flags) static void memory_global_dirty_log_do_stop(unsigned int flags)