> +static void coroutine_fn backup_start_savevm(void *opaque)
> +{
> + assert(backup_state.driver);
> + assert(backup_state.writer);
> + int ret;
> + char *err = NULL;
> + uint64_t remaining;
> + int64_t maxlen;
> + MigrationParams params = {
> + .blk = 0,
> + .shared = 0
> + };
> +
> + int restart = 0;
> +
> + QEMUFile *file = qemu_fopen_ops(NULL, &backup_file_ops);
> +
> + ret = qemu_savevm_state_begin(file, ¶ms);
> + if (ret < 0) {
> + qemu_fclose(file);
> + err = g_strdup("qemu_savevm_state_begin failed");
> + goto abort;
> + }
> +
> + while (1) {
> + ret = qemu_savevm_state_iterate(file);
> + remaining = ram_bytes_remaining();
> +
> + if (ret < 0) {
> + qemu_fclose(file);
> + err = g_strdup_printf("qemu_savevm_state_iterate error %d", ret);
> + goto abort;
> + }
> +
> + /* stop the VM if we use too much space,
> + * or if remaining is just a few MB
> + */
> + maxlen = ram_bytes_total();
> + size_t cpos = backup_state.buf_cluster_num * BACKUP_CLUSTER_SIZE;
> + if ((remaining < 100000) || ((cpos + remaining) >= maxlen)) {
> + if (runstate_is_running()) {
> + restart = 1;
> + vm_stop(RUN_STATE_SAVE_VM);
> + }
> + }
> +
> + if (ret == 1) { /* finished */
> + if (runstate_is_running()) {
> + restart = 1;
> + vm_stop(RUN_STATE_SAVE_VM);
> + }
> +
> + ret = qemu_savevm_state_complete(file);
> + if (ret < 0) {
> + qemu_fclose(file);
> + err = g_strdup("qemu_savevm_state_complete error");
> + goto abort;
> +
> + } else {
> + if (qemu_fclose(file) < 0) {
> + error_setg(&backup_state.error,
> + "backup_start_savevm: qemu_fclose failed");
> + goto abort;
> + }
> + if (backup_state.driver->complete_cb(backup_state.writer,
> + backup_state.vmstate_dev_id, 0) < 0) {
> + err = g_strdup("backup_start_savevm: complete_cb
> failed");
> + goto abort;
> + }
> + backup_start_jobs();
backup_start_jobs() was called after qemu_savevm_state_complete(),
and then VM got resumed with block backup jobs alone, would this cause
saved vm state not sync with the saved block contents, if there is
vmstate changing after backup_start_jobs()?
> + goto out;
> + }
> + }
> + }
--
Best Regards
Wenchao Xia