From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 24 Oct 2019 08:06:52 +0200 Subject: [PATCH] rename config_to_vma into pvebackup_co_add_config - mark it with coroutine_fn - add an additional parameter 'name' - return -1 on error (instead of 1) - code cleanup Signed-off-by: Dietmar Maurer --- blockdev.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/blockdev.c b/blockdev.c index a95beb823e..530b76c82f 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3436,10 +3436,16 @@ void qmp_backup_cancel(Error **errp) block_on_coroutine_fn(pvebackup_co_cancel, NULL); } -static int config_to_vma(const char *file, BackupFormat format, - const char *backup_dir, VmaWriter *vmaw, - Error **errp) +static int coroutine_fn pvebackup_co_add_config( + const char *file, + const char *name, + BackupFormat format, + const char *backup_dir, + VmaWriter *vmaw, + Error **errp) { + int res = 0; + char *cdata = NULL; gsize clen = 0; GError *err = NULL; @@ -3449,28 +3455,30 @@ static int config_to_vma(const char *file, BackupFormat format, } char *basename = g_path_get_basename(file); + if (name == NULL) name = basename; if (format == BACKUP_FORMAT_VMA) { - if (vma_writer_add_config(vmaw, basename, cdata, clen) != 0) { + if (vma_writer_add_config(vmaw, name, cdata, clen) != 0) { error_setg(errp, "unable to add %s config data to vma archive", file); - g_free(cdata); - g_free(basename); - return 1; + goto err; } } else if (format == BACKUP_FORMAT_DIR) { char config_path[PATH_MAX]; - snprintf(config_path, PATH_MAX, "%s/%s", backup_dir, basename); + snprintf(config_path, PATH_MAX, "%s/%s", backup_dir, name); if (!g_file_set_contents(config_path, cdata, clen, &err)) { error_setg(errp, "unable to write config file '%s'", config_path); - g_free(cdata); - g_free(basename); - return 1; + goto err; } } + out: g_free(basename); g_free(cdata); - return 0; + return res; + + err: + res = -1; + goto out; } bool job_should_pause(Job *job); @@ -3546,6 +3554,9 @@ static void coroutine_fn pvebackup_co_start(void *opaque) BlockJob *job; int dump_cb_block_size = -1; + const char *config_name = "qemu-server.conf"; + const char *firewall_name = "qemu-server.fw"; + if (!backup_state.backup_mutex_initialized) { qemu_co_mutex_init(&backup_state.backup_mutex); backup_state.backup_mutex_initialized = true; @@ -3690,16 +3701,17 @@ static void coroutine_fn pvebackup_co_start(void *opaque) goto err; } + /* add configuration file to archive */ if (task->has_config_file) { - if (config_to_vma(task->config_file, format, backup_dir, vmaw, task->errp) != 0) { + if (pvebackup_co_add_config(task->config_file, config_name, format, backup_dir, vmaw, task->errp) != 0) { goto err; } } /* add firewall file to archive */ if (task->has_firewall_file) { - if (config_to_vma(task->firewall_file, format, backup_dir, vmaw, task->errp) != 0) { + if (pvebackup_co_add_config(task->firewall_file, firewall_name, format, backup_dir, vmaw, task->errp) != 0) { goto err; } }