[pve-devel] [PATCH qemu 3/3] rename config_to_vma into pvebackup_co_add_config
Dietmar Maurer
dietmar at proxmox.com
Thu Oct 24 08:06:52 CEST 2019
- mark it with coroutine_fn
- add an additional parameter 'name'
- return -1 on error (instead of 1)
- code cleanup
Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
blockdev.c | 40 ++++++++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 6d16043131..786921da0a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3416,10 +3416,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;
@@ -3429,28 +3435,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);
@@ -3526,6 +3534,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;
@@ -3670,16 +3681,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;
}
}
--
2.20.1
More information about the pve-devel
mailing list