mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
qemu: consolidate duplicated monitor migration code
* src/qemu/qemu_monitor_text.h (qemuMonitorTextMigrate): Declare in place of individual monitor commands. * src/qemu/qemu_monitor_json.h (qemuMonitorJSONMigrate): Likewise. * src/qemu/qemu_monitor_text.c (qemuMonitorTextMigrateToHost) (qemuMonitorTextMigrateToCommand, qemuMonitorTextMigrateToFile) (qemuMonitorTextMigrateToUnix): Delete. * src/qemu/qemu_monitor_json.c (qemuMonitorJSONMigrateToHost) (qemuMonitorJSONMigrateToCommand, qemuMonitorJSONMigrateToFile) (qemuMonitorJSONMigrateToUnix): Delete. * src/qemu/qemu_monitor.c (qemuMonitorMigrateToHost) (qemuMonitorMigrateToCommand, qemuMonitorMigrateToFile) (qemuMonitorMigrateToUnix): Consolidate shared code.
This commit is contained in:
parent
c7af07ace4
commit
1c5dc4c607
@ -1402,6 +1402,7 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
|
||||
int port)
|
||||
{
|
||||
int ret;
|
||||
char *uri = NULL;
|
||||
VIR_DEBUG("mon=%p hostname=%s port=%d flags=%u",
|
||||
mon, hostname, port, flags);
|
||||
|
||||
@ -1411,10 +1412,18 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mon->json)
|
||||
ret = qemuMonitorJSONMigrateToHost(mon, flags, hostname, port);
|
||||
ret = qemuMonitorJSONMigrate(mon, flags, uri);
|
||||
else
|
||||
ret = qemuMonitorTextMigrateToHost(mon, flags, hostname, port);
|
||||
ret = qemuMonitorTextMigrate(mon, flags, uri);
|
||||
|
||||
VIR_FREE(uri);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1423,7 +1432,9 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char * const *argv)
|
||||
{
|
||||
int ret;
|
||||
char *argstr;
|
||||
char *dest = NULL;
|
||||
int ret = -1;
|
||||
VIR_DEBUG("mon=%p argv=%p flags=%u",
|
||||
mon, argv, flags);
|
||||
|
||||
@ -1433,10 +1444,25 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
|
||||
return -1;
|
||||
}
|
||||
|
||||
argstr = virArgvToString(argv);
|
||||
if (!argstr) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virAsprintf(&dest, "exec:%s", argstr) < 0) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (mon->json)
|
||||
ret = qemuMonitorJSONMigrateToCommand(mon, flags, argv);
|
||||
ret = qemuMonitorJSONMigrate(mon, flags, dest);
|
||||
else
|
||||
ret = qemuMonitorTextMigrateToCommand(mon, flags, argv);
|
||||
ret = qemuMonitorTextMigrate(mon, flags, dest);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(argstr);
|
||||
VIR_FREE(dest);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1446,7 +1472,10 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
|
||||
const char *target,
|
||||
unsigned long long offset)
|
||||
{
|
||||
int ret;
|
||||
char *argstr;
|
||||
char *dest = NULL;
|
||||
int ret = -1;
|
||||
char *safe_target = NULL;
|
||||
VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%u",
|
||||
mon, argv, target, offset, flags);
|
||||
|
||||
@ -1463,10 +1492,43 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
|
||||
return -1;
|
||||
}
|
||||
|
||||
argstr = virArgvToString(argv);
|
||||
if (!argstr) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Migrate to file */
|
||||
safe_target = qemuMonitorEscapeShell(target);
|
||||
if (!safe_target) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Two dd processes, sharing the same stdout, are necessary to
|
||||
* allow starting at an alignment of 512, but without wasting
|
||||
* padding to get to the larger alignment useful for speed. Use
|
||||
* <> redirection to avoid truncating a regular file. */
|
||||
if (virAsprintf(&dest, "exec:" VIR_WRAPPER_SHELL_PREFIX "%s | "
|
||||
"{ dd bs=%llu seek=%llu if=/dev/null && "
|
||||
"dd bs=%llu; } 1<>%s" VIR_WRAPPER_SHELL_SUFFIX,
|
||||
argstr, QEMU_MONITOR_MIGRATE_TO_FILE_BS,
|
||||
offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS,
|
||||
QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE,
|
||||
safe_target) < 0) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (mon->json)
|
||||
ret = qemuMonitorJSONMigrateToFile(mon, flags, argv, target, offset);
|
||||
ret = qemuMonitorJSONMigrate(mon, flags, dest);
|
||||
else
|
||||
ret = qemuMonitorTextMigrateToFile(mon, flags, argv, target, offset);
|
||||
ret = qemuMonitorTextMigrate(mon, flags, dest);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(safe_target);
|
||||
VIR_FREE(argstr);
|
||||
VIR_FREE(dest);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1474,7 +1536,8 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *unixfile)
|
||||
{
|
||||
int ret;
|
||||
char *dest = NULL;
|
||||
int ret = -1;
|
||||
VIR_DEBUG("mon=%p, unixfile=%s flags=%u",
|
||||
mon, unixfile, flags);
|
||||
|
||||
@ -1484,10 +1547,17 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virAsprintf(&dest, "unix:%s", unixfile) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mon->json)
|
||||
ret = qemuMonitorJSONMigrateToUnix(mon, flags, unixfile);
|
||||
ret = qemuMonitorJSONMigrate(mon, flags, dest);
|
||||
else
|
||||
ret = qemuMonitorTextMigrateToUnix(mon, flags, unixfile);
|
||||
ret = qemuMonitorTextMigrate(mon, flags, dest);
|
||||
|
||||
VIR_FREE(dest);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* qemu_monitor_json.c: interaction with QEMU monitor console
|
||||
*
|
||||
* Copyright (C) 2006-2010 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2011 Red Hat, Inc.
|
||||
* Copyright (C) 2006 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -1720,9 +1720,9 @@ int qemuMonitorJSONGetMigrationStatus(qemuMonitorPtr mon,
|
||||
}
|
||||
|
||||
|
||||
static int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *uri)
|
||||
int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *uri)
|
||||
{
|
||||
int ret;
|
||||
virJSONValuePtr cmd =
|
||||
@ -1747,123 +1747,6 @@ static int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int qemuMonitorJSONMigrateToHost(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *hostname,
|
||||
int port)
|
||||
{
|
||||
char *uri = NULL;
|
||||
int ret;
|
||||
|
||||
if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = qemuMonitorJSONMigrate(mon, flags, uri);
|
||||
|
||||
VIR_FREE(uri);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int qemuMonitorJSONMigrateToCommand(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char * const *argv)
|
||||
{
|
||||
char *argstr;
|
||||
char *dest = NULL;
|
||||
int ret = -1;
|
||||
|
||||
argstr = virArgvToString(argv);
|
||||
if (!argstr) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virAsprintf(&dest, "exec:%s", argstr) < 0) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = qemuMonitorJSONMigrate(mon, flags, dest);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(argstr);
|
||||
VIR_FREE(dest);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorJSONMigrateToFile(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char * const *argv,
|
||||
const char *target,
|
||||
unsigned long long offset)
|
||||
{
|
||||
char *argstr;
|
||||
char *dest = NULL;
|
||||
int ret = -1;
|
||||
char *safe_target = NULL;
|
||||
|
||||
argstr = virArgvToString(argv);
|
||||
if (!argstr) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Migrate to file */
|
||||
safe_target = qemuMonitorEscapeShell(target);
|
||||
if (!safe_target) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Two dd processes, sharing the same stdout, are necessary to
|
||||
* allow starting at an alignment of 512, but without wasting
|
||||
* padding to get to the larger alignment useful for speed. Use
|
||||
* <> redirection to avoid truncating a regular file. */
|
||||
if (virAsprintf(&dest, "exec:" VIR_WRAPPER_SHELL_PREFIX "%s | "
|
||||
"{ dd bs=%llu seek=%llu if=/dev/null && "
|
||||
"dd bs=%llu; } 1<>%s" VIR_WRAPPER_SHELL_SUFFIX,
|
||||
argstr, QEMU_MONITOR_MIGRATE_TO_FILE_BS,
|
||||
offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS,
|
||||
QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE,
|
||||
safe_target) < 0) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = qemuMonitorJSONMigrate(mon, flags, dest);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(safe_target);
|
||||
VIR_FREE(argstr);
|
||||
VIR_FREE(dest);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorJSONMigrateToUnix(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *unixfile)
|
||||
{
|
||||
char *dest = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&dest, "unix:%s", unixfile) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = qemuMonitorJSONMigrate(mon, flags, dest);
|
||||
|
||||
VIR_FREE(dest);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon)
|
||||
{
|
||||
int ret;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* qemu_monitor_json.h: interaction with QEMU monitor console
|
||||
*
|
||||
* Copyright (C) 2006-2009 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2009, 2011 Red Hat, Inc.
|
||||
* Copyright (C) 2006 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -109,24 +109,9 @@ int qemuMonitorJSONGetMigrationStatus(qemuMonitorPtr mon,
|
||||
unsigned long long *remaining,
|
||||
unsigned long long *total);
|
||||
|
||||
int qemuMonitorJSONMigrateToHost(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *hostname,
|
||||
int port);
|
||||
|
||||
int qemuMonitorJSONMigrateToCommand(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char * const *argv);
|
||||
|
||||
int qemuMonitorJSONMigrateToFile(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char * const *argv,
|
||||
const char *target,
|
||||
unsigned long long offset);
|
||||
|
||||
int qemuMonitorJSONMigrateToUnix(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *unixfile);
|
||||
int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *uri);
|
||||
|
||||
int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* qemu_monitor_text.c: interaction with QEMU monitor console
|
||||
*
|
||||
* Copyright (C) 2006-2010 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2011 Red Hat, Inc.
|
||||
* Copyright (C) 2006 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -1201,9 +1201,9 @@ cleanup:
|
||||
}
|
||||
|
||||
|
||||
static int qemuMonitorTextMigrate(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *dest)
|
||||
int qemuMonitorTextMigrate(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *dest)
|
||||
{
|
||||
char *cmd = NULL;
|
||||
char *info = NULL;
|
||||
@ -1267,121 +1267,6 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorTextMigrateToHost(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *hostname,
|
||||
int port)
|
||||
{
|
||||
char *uri = NULL;
|
||||
int ret;
|
||||
|
||||
if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = qemuMonitorTextMigrate(mon, flags, uri);
|
||||
|
||||
VIR_FREE(uri);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int qemuMonitorTextMigrateToCommand(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char * const *argv)
|
||||
{
|
||||
char *argstr;
|
||||
char *dest = NULL;
|
||||
int ret = -1;
|
||||
|
||||
argstr = virArgvToString(argv);
|
||||
if (!argstr) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virAsprintf(&dest, "exec:%s", argstr) < 0) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = qemuMonitorTextMigrate(mon, flags, dest);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(argstr);
|
||||
VIR_FREE(dest);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorTextMigrateToFile(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char * const *argv,
|
||||
const char *target,
|
||||
unsigned long long offset)
|
||||
{
|
||||
char *argstr;
|
||||
char *dest = NULL;
|
||||
int ret = -1;
|
||||
char *safe_target = NULL;
|
||||
|
||||
argstr = virArgvToString(argv);
|
||||
if (!argstr) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Migrate to file */
|
||||
safe_target = qemuMonitorEscapeShell(target);
|
||||
if (!safe_target) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* Two dd processes, sharing the same stdout, are necessary to
|
||||
* allow starting at an alignment of 512, but without wasting
|
||||
* padding to get to the larger alignment useful for speed. Use
|
||||
* <> redirection to avoid truncating a regular file. */
|
||||
if (virAsprintf(&dest, "exec:" VIR_WRAPPER_SHELL_PREFIX "%s | "
|
||||
"{ dd bs=%llu seek=%llu if=/dev/null && "
|
||||
"dd bs=%llu; } 1<>%s" VIR_WRAPPER_SHELL_SUFFIX,
|
||||
argstr, QEMU_MONITOR_MIGRATE_TO_FILE_BS,
|
||||
offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS,
|
||||
QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE,
|
||||
safe_target) < 0) {
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = qemuMonitorTextMigrate(mon, flags, dest);
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(safe_target);
|
||||
VIR_FREE(argstr);
|
||||
VIR_FREE(dest);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorTextMigrateToUnix(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *unixfile)
|
||||
{
|
||||
char *dest = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (virAsprintf(&dest, "unix:%s", unixfile) < 0) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = qemuMonitorTextMigrate(mon, flags, dest);
|
||||
|
||||
VIR_FREE(dest);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qemuMonitorTextMigrateCancel(qemuMonitorPtr mon)
|
||||
{
|
||||
char *info = NULL;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* qemu_monitor_text.h: interaction with QEMU monitor console
|
||||
*
|
||||
* Copyright (C) 2006-2009 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2009, 2011 Red Hat, Inc.
|
||||
* Copyright (C) 2006 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -107,24 +107,9 @@ int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon,
|
||||
unsigned long long *remaining,
|
||||
unsigned long long *total);
|
||||
|
||||
int qemuMonitorTextMigrateToHost(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *hostname,
|
||||
int port);
|
||||
|
||||
int qemuMonitorTextMigrateToCommand(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char * const *argv);
|
||||
|
||||
int qemuMonitorTextMigrateToFile(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char * const *argv,
|
||||
const char *target,
|
||||
unsigned long long offset);
|
||||
|
||||
int qemuMonitorTextMigrateToUnix(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *unixfile);
|
||||
int qemuMonitorTextMigrate(qemuMonitorPtr mon,
|
||||
unsigned int flags,
|
||||
const char *uri);
|
||||
|
||||
int qemuMonitorTextMigrateCancel(qemuMonitorPtr mon);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user