提交 1c5dc4c6 编写于 作者: E Eric Blake

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.
上级 c7af07ac
...@@ -1402,6 +1402,7 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon, ...@@ -1402,6 +1402,7 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
int port) int port)
{ {
int ret; int ret;
char *uri = NULL;
VIR_DEBUG("mon=%p hostname=%s port=%d flags=%u", VIR_DEBUG("mon=%p hostname=%s port=%d flags=%u",
mon, hostname, port, flags); mon, hostname, port, flags);
...@@ -1411,10 +1412,18 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon, ...@@ -1411,10 +1412,18 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
return -1; return -1;
} }
if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) {
virReportOOMError();
return -1;
}
if (mon->json) if (mon->json)
ret = qemuMonitorJSONMigrateToHost(mon, flags, hostname, port); ret = qemuMonitorJSONMigrate(mon, flags, uri);
else else
ret = qemuMonitorTextMigrateToHost(mon, flags, hostname, port); ret = qemuMonitorTextMigrate(mon, flags, uri);
VIR_FREE(uri);
return ret; return ret;
} }
...@@ -1423,7 +1432,9 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon, ...@@ -1423,7 +1432,9 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
unsigned int flags, unsigned int flags,
const char * const *argv) const char * const *argv)
{ {
int ret; char *argstr;
char *dest = NULL;
int ret = -1;
VIR_DEBUG("mon=%p argv=%p flags=%u", VIR_DEBUG("mon=%p argv=%p flags=%u",
mon, argv, flags); mon, argv, flags);
...@@ -1433,10 +1444,25 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon, ...@@ -1433,10 +1444,25 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
return -1; return -1;
} }
argstr = virArgvToString(argv);
if (!argstr) {
virReportOOMError();
goto cleanup;
}
if (virAsprintf(&dest, "exec:%s", argstr) < 0) {
virReportOOMError();
goto cleanup;
}
if (mon->json) if (mon->json)
ret = qemuMonitorJSONMigrateToCommand(mon, flags, argv); ret = qemuMonitorJSONMigrate(mon, flags, dest);
else else
ret = qemuMonitorTextMigrateToCommand(mon, flags, argv); ret = qemuMonitorTextMigrate(mon, flags, dest);
cleanup:
VIR_FREE(argstr);
VIR_FREE(dest);
return ret; return ret;
} }
...@@ -1446,7 +1472,10 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon, ...@@ -1446,7 +1472,10 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
const char *target, const char *target,
unsigned long long offset) 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", VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%u",
mon, argv, target, offset, flags); mon, argv, target, offset, flags);
...@@ -1463,10 +1492,43 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon, ...@@ -1463,10 +1492,43 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
return -1; 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) if (mon->json)
ret = qemuMonitorJSONMigrateToFile(mon, flags, argv, target, offset); ret = qemuMonitorJSONMigrate(mon, flags, dest);
else 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; return ret;
} }
...@@ -1474,7 +1536,8 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon, ...@@ -1474,7 +1536,8 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
unsigned int flags, unsigned int flags,
const char *unixfile) const char *unixfile)
{ {
int ret; char *dest = NULL;
int ret = -1;
VIR_DEBUG("mon=%p, unixfile=%s flags=%u", VIR_DEBUG("mon=%p, unixfile=%s flags=%u",
mon, unixfile, flags); mon, unixfile, flags);
...@@ -1484,10 +1547,17 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon, ...@@ -1484,10 +1547,17 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
return -1; return -1;
} }
if (virAsprintf(&dest, "unix:%s", unixfile) < 0) {
virReportOOMError();
return -1;
}
if (mon->json) if (mon->json)
ret = qemuMonitorJSONMigrateToUnix(mon, flags, unixfile); ret = qemuMonitorJSONMigrate(mon, flags, dest);
else else
ret = qemuMonitorTextMigrateToUnix(mon, flags, unixfile); ret = qemuMonitorTextMigrate(mon, flags, dest);
VIR_FREE(dest);
return ret; return ret;
} }
......
/* /*
* qemu_monitor_json.c: interaction with QEMU monitor console * 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 * Copyright (C) 2006 Daniel P. Berrange
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -1720,9 +1720,9 @@ int qemuMonitorJSONGetMigrationStatus(qemuMonitorPtr mon, ...@@ -1720,9 +1720,9 @@ int qemuMonitorJSONGetMigrationStatus(qemuMonitorPtr mon,
} }
static int qemuMonitorJSONMigrate(qemuMonitorPtr mon, int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
unsigned int flags, unsigned int flags,
const char *uri) const char *uri)
{ {
int ret; int ret;
virJSONValuePtr cmd = virJSONValuePtr cmd =
...@@ -1747,123 +1747,6 @@ static int qemuMonitorJSONMigrate(qemuMonitorPtr mon, ...@@ -1747,123 +1747,6 @@ static int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
return ret; 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 qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon)
{ {
int ret; int ret;
......
/* /*
* qemu_monitor_json.h: interaction with QEMU monitor console * 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 * Copyright (C) 2006 Daniel P. Berrange
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -109,24 +109,9 @@ int qemuMonitorJSONGetMigrationStatus(qemuMonitorPtr mon, ...@@ -109,24 +109,9 @@ int qemuMonitorJSONGetMigrationStatus(qemuMonitorPtr mon,
unsigned long long *remaining, unsigned long long *remaining,
unsigned long long *total); unsigned long long *total);
int qemuMonitorJSONMigrateToHost(qemuMonitorPtr mon, int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
unsigned int flags, unsigned int flags,
const char *hostname, const char *uri);
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 qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon); int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon);
......
/* /*
* qemu_monitor_text.c: interaction with QEMU monitor console * 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 * Copyright (C) 2006 Daniel P. Berrange
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -1201,9 +1201,9 @@ cleanup: ...@@ -1201,9 +1201,9 @@ cleanup:
} }
static int qemuMonitorTextMigrate(qemuMonitorPtr mon, int qemuMonitorTextMigrate(qemuMonitorPtr mon,
unsigned int flags, unsigned int flags,
const char *dest) const char *dest)
{ {
char *cmd = NULL; char *cmd = NULL;
char *info = NULL; char *info = NULL;
...@@ -1267,121 +1267,6 @@ cleanup: ...@@ -1267,121 +1267,6 @@ cleanup:
return ret; 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) int qemuMonitorTextMigrateCancel(qemuMonitorPtr mon)
{ {
char *info = NULL; char *info = NULL;
......
/* /*
* qemu_monitor_text.h: interaction with QEMU monitor console * 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 * Copyright (C) 2006 Daniel P. Berrange
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -107,24 +107,9 @@ int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon, ...@@ -107,24 +107,9 @@ int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon,
unsigned long long *remaining, unsigned long long *remaining,
unsigned long long *total); unsigned long long *total);
int qemuMonitorTextMigrateToHost(qemuMonitorPtr mon, int qemuMonitorTextMigrate(qemuMonitorPtr mon,
unsigned int flags, unsigned int flags,
const char *hostname, const char *uri);
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 qemuMonitorTextMigrateCancel(qemuMonitorPtr mon); int qemuMonitorTextMigrateCancel(qemuMonitorPtr mon);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册