|
|
9119d9 |
From 5c6c436d14fa9f504f5889f3e60fdecc65208b26 Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <5c6c436d14fa9f504f5889f3e60fdecc65208b26@dist-git>
|
|
|
9119d9 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
9119d9 |
Date: Mon, 22 Sep 2014 17:52:39 +0200
|
|
|
9119d9 |
Subject: [PATCH] qemu: save image: Split out checks done only when editing the
|
|
|
9119d9 |
save img
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1142693
|
|
|
9119d9 |
|
|
|
9119d9 |
Move them to the single corresponding function rather than having them
|
|
|
9119d9 |
in the common chunk of code.
|
|
|
9119d9 |
|
|
|
9119d9 |
(cherry picked from commit 3035123d65714975dcc8527289fe68c7b5d3526f)
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
src/qemu/qemu_driver.c | 76 +++++++++++++++++++++++++++-----------------------
|
|
|
9119d9 |
1 file changed, 41 insertions(+), 35 deletions(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
|
|
|
9119d9 |
index 96c7dd2..580ac17 100644
|
|
|
9119d9 |
--- a/src/qemu/qemu_driver.c
|
|
|
9119d9 |
+++ b/src/qemu/qemu_driver.c
|
|
|
9119d9 |
@@ -5380,10 +5380,22 @@ qemuDomainSaveImageUpdateDef(virQEMUDriverPtr driver,
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
|
|
|
9119d9 |
-/* Return -1 on most failures after raising error, -2 if edit was specified
|
|
|
9119d9 |
- * but xmlin and state (-1 for no change, 0 for paused, 1 for running) do
|
|
|
9119d9 |
- * not represent any changes (no error raised), -3 if corrupt image was
|
|
|
9119d9 |
- * unlinked (no error raised), and opened fd on success. */
|
|
|
9119d9 |
+/**
|
|
|
9119d9 |
+ * qemuDomainSaveImageOpen:
|
|
|
9119d9 |
+ * @driver: qemu driver data
|
|
|
9119d9 |
+ * @path: path of the save image
|
|
|
9119d9 |
+ * @ret_def: returns domain definition created from the XML stored in the image
|
|
|
9119d9 |
+ * @ret_header: returns structure filled with data from the image header
|
|
|
9119d9 |
+ * @xmlout: returns the XML from the image file (may be NULL)
|
|
|
9119d9 |
+ * @bypass_cache: bypass cache when opening the file
|
|
|
9119d9 |
+ * @wrapperFd: returns the file wrapper structure
|
|
|
9119d9 |
+ * @open_write: open the file for writing (for updates)
|
|
|
9119d9 |
+ * @unlink_corrupt: remove the image file if it is corrupted
|
|
|
9119d9 |
+ *
|
|
|
9119d9 |
+ * Returns the opened fd of the save image file and fills the apropriate fields
|
|
|
9119d9 |
+ * on success. On error returns -1 on most failures, -3 if corrupt image was
|
|
|
9119d9 |
+ * unlinked (no error raised).
|
|
|
9119d9 |
+ */
|
|
|
9119d9 |
static int ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4)
|
|
|
9119d9 |
qemuDomainSaveImageOpen(virQEMUDriverPtr driver,
|
|
|
9119d9 |
const char *path,
|
|
|
9119d9 |
@@ -5392,14 +5404,14 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver,
|
|
|
9119d9 |
char **xmlout,
|
|
|
9119d9 |
bool bypass_cache,
|
|
|
9119d9 |
virFileWrapperFdPtr *wrapperFd,
|
|
|
9119d9 |
- const char *xmlin, int state, bool edit,
|
|
|
9119d9 |
+ bool open_write,
|
|
|
9119d9 |
bool unlink_corrupt)
|
|
|
9119d9 |
{
|
|
|
9119d9 |
int fd = -1;
|
|
|
9119d9 |
virQEMUSaveHeader header;
|
|
|
9119d9 |
char *xml = NULL;
|
|
|
9119d9 |
virDomainDefPtr def = NULL;
|
|
|
9119d9 |
- int oflags = edit ? O_RDWR : O_RDONLY;
|
|
|
9119d9 |
+ int oflags = open_write ? O_RDWR : O_RDONLY;
|
|
|
9119d9 |
virCapsPtr caps = NULL;
|
|
|
9119d9 |
|
|
|
9119d9 |
if (bypass_cache) {
|
|
|
9119d9 |
@@ -5484,18 +5496,6 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver,
|
|
|
9119d9 |
goto error;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (edit && STREQ(xml, xmlin) &&
|
|
|
9119d9 |
- (state < 0 || state == header.was_running)) {
|
|
|
9119d9 |
- VIR_FREE(xml);
|
|
|
9119d9 |
- if (VIR_CLOSE(fd) < 0) {
|
|
|
9119d9 |
- virReportSystemError(errno, _("cannot close file: %s"), path);
|
|
|
9119d9 |
- goto error;
|
|
|
9119d9 |
- }
|
|
|
9119d9 |
- return -2;
|
|
|
9119d9 |
- }
|
|
|
9119d9 |
- if (state >= 0)
|
|
|
9119d9 |
- header.was_running = state;
|
|
|
9119d9 |
-
|
|
|
9119d9 |
/* Create a domain from this XML */
|
|
|
9119d9 |
if (!(def = virDomainDefParseString(xml, caps, driver->xmlopt,
|
|
|
9119d9 |
QEMU_EXPECTED_VIRT_TYPES,
|
|
|
9119d9 |
@@ -5650,21 +5650,15 @@ qemuDomainRestoreFlags(virConnectPtr conn,
|
|
|
9119d9 |
int ret = -1;
|
|
|
9119d9 |
virQEMUSaveHeader header;
|
|
|
9119d9 |
virFileWrapperFdPtr wrapperFd = NULL;
|
|
|
9119d9 |
- int state = -1;
|
|
|
9119d9 |
|
|
|
9119d9 |
virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE |
|
|
|
9119d9 |
VIR_DOMAIN_SAVE_RUNNING |
|
|
|
9119d9 |
VIR_DOMAIN_SAVE_PAUSED, -1);
|
|
|
9119d9 |
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (flags & VIR_DOMAIN_SAVE_RUNNING)
|
|
|
9119d9 |
- state = 1;
|
|
|
9119d9 |
- else if (flags & VIR_DOMAIN_SAVE_PAUSED)
|
|
|
9119d9 |
- state = 0;
|
|
|
9119d9 |
-
|
|
|
9119d9 |
fd = qemuDomainSaveImageOpen(driver, path, &def, &header, NULL,
|
|
|
9119d9 |
(flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) != 0,
|
|
|
9119d9 |
- &wrapperFd, dxml, state, false, false);
|
|
|
9119d9 |
+ &wrapperFd, false, false);
|
|
|
9119d9 |
if (fd < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -5687,6 +5681,11 @@ qemuDomainRestoreFlags(virConnectPtr conn,
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
def = NULL;
|
|
|
9119d9 |
|
|
|
9119d9 |
+ if (flags & VIR_DOMAIN_SAVE_RUNNING)
|
|
|
9119d9 |
+ header.was_running = 1;
|
|
|
9119d9 |
+ else if (flags & VIR_DOMAIN_SAVE_PAUSED)
|
|
|
9119d9 |
+ header.was_running = 0;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
@@ -5732,7 +5731,7 @@ qemuDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *path,
|
|
|
9119d9 |
virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL);
|
|
|
9119d9 |
|
|
|
9119d9 |
fd = qemuDomainSaveImageOpen(driver, path, &def, &header, NULL,
|
|
|
9119d9 |
- false, NULL, NULL, -1, false, false);
|
|
|
9119d9 |
+ false, NULL, false, false);
|
|
|
9119d9 |
|
|
|
9119d9 |
if (fd < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
@@ -5770,22 +5769,30 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, const char *path,
|
|
|
9119d9 |
else if (flags & VIR_DOMAIN_SAVE_PAUSED)
|
|
|
9119d9 |
state = 0;
|
|
|
9119d9 |
|
|
|
9119d9 |
- fd = qemuDomainSaveImageOpen(driver, path, &def, &header, NULL,
|
|
|
9119d9 |
- false, NULL, dxml, state, true, false);
|
|
|
9119d9 |
+ fd = qemuDomainSaveImageOpen(driver, path, &def, &header, &xml,
|
|
|
9119d9 |
+ false, NULL, true, false);
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (fd < 0) {
|
|
|
9119d9 |
- /* Check for special case of no change needed. */
|
|
|
9119d9 |
- if (fd == -2)
|
|
|
9119d9 |
- ret = 0;
|
|
|
9119d9 |
+ if (fd < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
- }
|
|
|
9119d9 |
|
|
|
9119d9 |
if (virDomainSaveImageDefineXMLEnsureACL(conn, def) < 0)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
+ if (STREQ(xml, dxml) &&
|
|
|
9119d9 |
+ (state < 0 || state == header.was_running)) {
|
|
|
9119d9 |
+ /* no change to the XML */
|
|
|
9119d9 |
+ ret = 0;
|
|
|
9119d9 |
+ goto cleanup;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ if (state >= 0)
|
|
|
9119d9 |
+ header.was_running = state;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
if (!(newdef = qemuDomainSaveImageUpdateDef(driver, def, dxml)))
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
|
|
|
9119d9 |
+ VIR_FREE(xml);
|
|
|
9119d9 |
+
|
|
|
9119d9 |
xml = qemuDomainDefFormatXML(driver, newdef,
|
|
|
9119d9 |
VIR_DOMAIN_XML_INACTIVE |
|
|
|
9119d9 |
VIR_DOMAIN_XML_SECURE |
|
|
|
9119d9 |
@@ -5840,8 +5847,7 @@ qemuDomainObjRestore(virConnectPtr conn,
|
|
|
9119d9 |
virFileWrapperFdPtr wrapperFd = NULL;
|
|
|
9119d9 |
|
|
|
9119d9 |
fd = qemuDomainSaveImageOpen(driver, path, &def, &header, NULL,
|
|
|
9119d9 |
- bypass_cache, &wrapperFd, NULL, -1, false,
|
|
|
9119d9 |
- true);
|
|
|
9119d9 |
+ bypass_cache, &wrapperFd, false, true);
|
|
|
9119d9 |
if (fd < 0) {
|
|
|
9119d9 |
if (fd == -3)
|
|
|
9119d9 |
ret = 1;
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.1
|
|
|
9119d9 |
|