Device filtering in snapshot API

This commit is contained in:
Andrea Fioraldi 2023-07-31 11:46:06 +02:00
parent 6df19ab8f1
commit cbb34bf927
4 changed files with 45 additions and 16 deletions

View File

@ -19,6 +19,20 @@ extern void save_section_footer(QEMUFile *f, SaveStateEntry *se);
// iothread must be locked
device_save_state_t* device_save_all(void) {
return device_save_kind(DEVICE_SNAPSHOT_ALL, NULL);
}
static int is_in_list(char* str, char** list) {
while (*list) {
if (!strcmp(str, *list)) {
return 1;
}
list++;
}
return 0;
}
device_save_state_t* device_save_kind(device_snapshot_kind_t kind, char** names) {
device_save_state_t* dss = g_new0(device_save_state_t, 1);
SaveStateEntry *se;
@ -39,6 +53,20 @@ device_save_state_t* device_save_all(void) {
if (!strcmp(se->idstr, "globalstate")) {
continue;
}
switch (kind) {
case DEVICE_SNAPSHOT_ALLOWLIST:
if (!is_in_list(se->idstr, names)) {
continue;
}
break;
case DEVICE_SNAPSHOT_DENYLIST:
if (is_in_list(se->idstr, names)) {
continue;
}
break;
default:
break;
}
// SYX_PRINTF("Saving section %s...\n", se->idstr);

View File

@ -10,6 +10,14 @@ typedef struct device_save_state_s {
size_t save_buffer_size;
} device_save_state_t;
// Type of device snapshot
typedef enum device_snapshot_kind_e {
DEVICE_SNAPSHOT_ALL,
DEVICE_SNAPSHOT_ALLOWLIST,
DEVICE_SNAPSHOT_DENYLIST
} device_snapshot_kind_t;
device_save_state_t* device_save_all(void);
device_save_state_t* device_save_kind(device_snapshot_kind_t kind, char** names);
void device_restore_all(device_save_state_t* device_save_state);
void device_free_all(device_save_state_t* dss);

View File

@ -45,10 +45,10 @@ uint64_t syx_snapshot_handler(CPUState* cpu, uint32_t cmd, target_ulong target_o
return (uint64_t) -1;
}
syx_snapshot_t* syx_snapshot_create(bool track) {
syx_snapshot_t* syx_snapshot_create(bool track, device_snapshot_kind_t kind, char** devices) {
syx_snapshot_t* snapshot = g_new0(syx_snapshot_t, 1);
snapshot->root_snapshot = syx_snapshot_root_create();
snapshot->root_snapshot = syx_snapshot_root_create(kind, devices);
snapshot->last_incremental_snapshot = NULL;
snapshot->dirty_list = syx_snapshot_dirty_list_create();
@ -74,12 +74,12 @@ void syx_snapshot_free(syx_snapshot_t* snapshot) {
g_free(snapshot);
}
syx_snapshot_root_t syx_snapshot_root_create(void) {
syx_snapshot_root_t syx_snapshot_root_create(device_snapshot_kind_t kind, char** devices) {
syx_snapshot_root_t root = {0};
RAMBlock* block;
uint64_t nb_blocks = 0;
device_save_state_t* dss = device_save_all();
device_save_state_t* dss = device_save_kind(kind, devices);
RAMBLOCK_FOREACH(block) {
nb_blocks++;
@ -150,13 +150,13 @@ void syx_snapshot_stop_track(syx_snapshot_tracker_t* tracker, syx_snapshot_t* sn
abort();
}
void syx_snapshot_increment_push(syx_snapshot_t* snapshot, CPUState* cpu) {
void syx_snapshot_increment_push(syx_snapshot_t* snapshot, device_snapshot_kind_t kind, char** devices) {
syx_snapshot_increment_t* increment = g_new0(syx_snapshot_increment_t, 1);
increment->parent = snapshot->last_incremental_snapshot;
snapshot->last_incremental_snapshot = increment;
increment->dirty_page_list = syx_snapshot_dirty_list_to_dirty_page_list(&snapshot->dirty_list);
increment->dss = device_save_all();
increment->dss = device_save_kind(kind, devices);
syx_snapshot_dirty_list_flush(&snapshot->dirty_list);
}

View File

@ -5,13 +5,6 @@
#include "sysemu/sysemu.h"
#include "../syx-misc.h"
/**
* SYX Snapshot parameters
*/
typedef struct syx_snapshot_init_params_s {
uint64_t page_size;
} syx_snapshot_init_params_t;
/**
* Saved ramblock
*/
@ -112,7 +105,7 @@ uint64_t syx_snapshot_handler(CPUState* cpu, uint32_t cmd, target_ulong target_o
// Snapshot API
//
syx_snapshot_t* syx_snapshot_create(bool track);
syx_snapshot_t* syx_snapshot_create(bool track, device_snapshot_kind_t kind, char** devices);
void syx_snapshot_free(syx_snapshot_t* snapshot);
// void syx_snapshot_load(syx_snapshot_t* snapshot);
@ -121,7 +114,7 @@ void syx_snapshot_free(syx_snapshot_t* snapshot);
// Root snapshot API
//
syx_snapshot_root_t syx_snapshot_root_create(void);
syx_snapshot_root_t syx_snapshot_root_create(device_snapshot_kind_t kind, char** devices);
void syx_snapshot_root_restore(syx_snapshot_t* snapshot);
void syx_snapshot_root_free(syx_snapshot_root_t* root);
@ -139,7 +132,7 @@ void syx_snapshot_stop_track(syx_snapshot_tracker_t* tracker, syx_snapshot_t* sn
// Snapshot increment API
//
void syx_snapshot_increment_push(syx_snapshot_t* snapshot, CPUState* cpu);
void syx_snapshot_increment_push(syx_snapshot_t* snapshot, device_snapshot_kind_t kind, char** devices);
void syx_snapshot_increment_pop(syx_snapshot_t* snapshot);
void syx_snapshot_increment_restore_last(syx_snapshot_t* snapshot);
syx_snapshot_increment_t* syx_snapshot_increment_free(syx_snapshot_increment_t* increment);