mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 03:55:16 +00:00
qemu_driver.c: factor out duplication in compression-type handling
* src/qemu_driver.c (QEMUD_SAVE_FORMAT_LAST): Define. (qemudSaveCompressionTypeFromString): Declare. (qemudSaveCompressionTypeToString): Declare. (qemudDomainSave): Use those functions rather than open-coding them. Use "cat >> '%s' ..." in place of equivalent "dd of='%s' oflag=append conv=notrunc ...".
This commit is contained in:
parent
1aec7d8606
commit
aec22258ef
@ -3628,8 +3628,19 @@ enum qemud_save_formats {
|
|||||||
/* Note: add new members only at the end.
|
/* Note: add new members only at the end.
|
||||||
These values are used in the on-disk format.
|
These values are used in the on-disk format.
|
||||||
Do not change or re-use numbers. */
|
Do not change or re-use numbers. */
|
||||||
|
|
||||||
|
QEMUD_SAVE_FORMAT_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
|
VIR_ENUM_DECL(qemudSaveCompression)
|
||||||
|
VIR_ENUM_IMPL(qemudSaveCompression, QEMUD_SAVE_FORMAT_LAST,
|
||||||
|
"raw",
|
||||||
|
"gzip",
|
||||||
|
"bzip2",
|
||||||
|
"lzma",
|
||||||
|
"lzop",
|
||||||
|
"xz")
|
||||||
|
|
||||||
struct qemud_save_header {
|
struct qemud_save_header {
|
||||||
char magic[sizeof(QEMUD_SAVE_MAGIC)-1];
|
char magic[sizeof(QEMUD_SAVE_MAGIC)-1];
|
||||||
int version;
|
int version;
|
||||||
@ -3660,22 +3671,15 @@ static int qemudDomainSave(virDomainPtr dom,
|
|||||||
|
|
||||||
if (driver->saveImageFormat == NULL)
|
if (driver->saveImageFormat == NULL)
|
||||||
header.compressed = QEMUD_SAVE_FORMAT_RAW;
|
header.compressed = QEMUD_SAVE_FORMAT_RAW;
|
||||||
else if (STREQ(driver->saveImageFormat, "raw"))
|
|
||||||
header.compressed = QEMUD_SAVE_FORMAT_RAW;
|
|
||||||
else if (STREQ(driver->saveImageFormat, "gzip"))
|
|
||||||
header.compressed = QEMUD_SAVE_FORMAT_GZIP;
|
|
||||||
else if (STREQ(driver->saveImageFormat, "bzip2"))
|
|
||||||
header.compressed = QEMUD_SAVE_FORMAT_BZIP2;
|
|
||||||
else if (STREQ(driver->saveImageFormat, "lzma"))
|
|
||||||
header.compressed = QEMUD_SAVE_FORMAT_LZMA;
|
|
||||||
else if (STREQ(driver->saveImageFormat, "lzop"))
|
|
||||||
header.compressed = QEMUD_SAVE_FORMAT_LZOP;
|
|
||||||
else if (STREQ(driver->saveImageFormat, "xz"))
|
|
||||||
header.compressed = QEMUD_SAVE_FORMAT_XZ;
|
|
||||||
else {
|
else {
|
||||||
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
header.compressed =
|
||||||
"%s", _("Invalid save image format specified in configuration file"));
|
qemudSaveCompressionTypeFromString(driver->saveImageFormat);
|
||||||
return -1;
|
if (header.compressed < 0) {
|
||||||
|
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
||||||
|
"%s", _("Invalid save image format specified "
|
||||||
|
"in configuration file"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qemuDriverLock(driver);
|
qemuDriverLock(driver);
|
||||||
@ -3751,31 +3755,18 @@ static int qemudDomainSave(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header.compressed == QEMUD_SAVE_FORMAT_RAW)
|
const char *prog = qemudSaveCompressionTypeToString(header.compressed);
|
||||||
internalret = virAsprintf(&command, "migrate \"exec:"
|
if (prog == NULL) {
|
||||||
"dd of='%s' oflag=append conv=notrunc 2>/dev/null"
|
|
||||||
"\"", safe_path);
|
|
||||||
else if (header.compressed == QEMUD_SAVE_FORMAT_GZIP)
|
|
||||||
internalret = virAsprintf(&command, "migrate \"exec:"
|
|
||||||
"gzip -c >> '%s' 2>/dev/null\"", safe_path);
|
|
||||||
else if (header.compressed == QEMUD_SAVE_FORMAT_BZIP2)
|
|
||||||
internalret = virAsprintf(&command, "migrate \"exec:"
|
|
||||||
"bzip2 -c >> '%s' 2>/dev/null\"", safe_path);
|
|
||||||
else if (header.compressed == QEMUD_SAVE_FORMAT_LZMA)
|
|
||||||
internalret = virAsprintf(&command, "migrate \"exec:"
|
|
||||||
"lzma -c >> '%s' 2>/dev/null\"", safe_path);
|
|
||||||
else if (header.compressed == QEMUD_SAVE_FORMAT_LZOP)
|
|
||||||
internalret = virAsprintf(&command, "migrate \"exec:"
|
|
||||||
"lzop -c >> '%s' 2>/dev/null\"", safe_path);
|
|
||||||
else if (header.compressed == QEMUD_SAVE_FORMAT_XZ)
|
|
||||||
internalret = virAsprintf(&command, "migrate \"exec:"
|
|
||||||
"xz -c >> '%s' 2>/dev/null\"", safe_path);
|
|
||||||
else {
|
|
||||||
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Invalid compress format %d"),
|
_("Invalid compress format %d"), header.compressed);
|
||||||
header.compressed);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (STREQ (prog, "raw"))
|
||||||
|
prog = "cat";
|
||||||
|
internalret = virAsprintf(&command, "migrate \"exec:"
|
||||||
|
"%s -c >> '%s' 2>/dev/null\"", prog, safe_path);
|
||||||
|
|
||||||
if (internalret < 0) {
|
if (internalret < 0) {
|
||||||
virReportOOMError(dom->conn);
|
virReportOOMError(dom->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user