mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 14:35:25 +00:00
libxl: move libxlSaveImageOpen to libxl_domain
Move libxlSaveImageOpen from libxl_driver to libxl_domain for use by other libxl modules. For consistency, rename to libxlDomainSaveImageOpen. Signed-off-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
11e97958ce
commit
7295941dea
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "libxl_domain.h"
|
#include "libxl_domain.h"
|
||||||
|
|
||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
@ -565,3 +567,77 @@ libxlDomainManagedSavePath(libxlDriverPrivatePtr driver, virDomainObjPtr vm) {
|
|||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Open a saved image file and initialize domain definition from the header.
|
||||||
|
*
|
||||||
|
* Returns the opened fd on success, -1 on failure.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
libxlDomainSaveImageOpen(libxlDriverPrivatePtr driver,
|
||||||
|
libxlDriverConfigPtr cfg,
|
||||||
|
const char *from,
|
||||||
|
virDomainDefPtr *ret_def,
|
||||||
|
libxlSavefileHeaderPtr ret_hdr)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
virDomainDefPtr def = NULL;
|
||||||
|
libxlSavefileHeader hdr;
|
||||||
|
char *xml = NULL;
|
||||||
|
|
||||||
|
if ((fd = virFileOpenAs(from, O_RDONLY, 0, -1, -1, 0)) < 0) {
|
||||||
|
virReportSystemError(-fd,
|
||||||
|
_("Failed to open domain image file '%s'"), from);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saferead(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
|
"%s", _("failed to read libxl header"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp(hdr.magic, LIBXL_SAVE_MAGIC, sizeof(hdr.magic))) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, "%s", _("image magic is incorrect"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hdr.version > LIBXL_SAVE_VERSION) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
|
_("image version is not supported (%d > %d)"),
|
||||||
|
hdr.version, LIBXL_SAVE_VERSION);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hdr.xmlLen <= 0) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
|
_("invalid XML length: %d"), hdr.xmlLen);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_ALLOC_N(xml, hdr.xmlLen) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (saferead(fd, xml, hdr.xmlLen) != hdr.xmlLen) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to read XML"));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt,
|
||||||
|
1 << VIR_DOMAIN_VIRT_XEN,
|
||||||
|
VIR_DOMAIN_XML_INACTIVE)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
VIR_FREE(xml);
|
||||||
|
|
||||||
|
*ret_def = def;
|
||||||
|
*ret_hdr = hdr;
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
|
||||||
|
error:
|
||||||
|
VIR_FREE(xml);
|
||||||
|
virDomainDefFree(def);
|
||||||
|
VIR_FORCE_CLOSE(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
@ -99,4 +99,12 @@ char *
|
|||||||
libxlDomainManagedSavePath(libxlDriverPrivatePtr driver,
|
libxlDomainManagedSavePath(libxlDriverPrivatePtr driver,
|
||||||
virDomainObjPtr vm);
|
virDomainObjPtr vm);
|
||||||
|
|
||||||
|
int
|
||||||
|
libxlDomainSaveImageOpen(libxlDriverPrivatePtr driver,
|
||||||
|
libxlDriverConfigPtr cfg,
|
||||||
|
const char *from,
|
||||||
|
virDomainDefPtr *ret_def,
|
||||||
|
libxlSavefileHeaderPtr ret_hdr)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5);
|
||||||
|
|
||||||
#endif /* LIBXL_DOMAIN_H */
|
#endif /* LIBXL_DOMAIN_H */
|
||||||
|
@ -168,78 +168,6 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* This internal function expects the driver lock to already be held on
|
|
||||||
* entry.
|
|
||||||
*/
|
|
||||||
static int ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5)
|
|
||||||
libxlSaveImageOpen(libxlDriverPrivatePtr driver,
|
|
||||||
libxlDriverConfigPtr cfg,
|
|
||||||
const char *from,
|
|
||||||
virDomainDefPtr *ret_def,
|
|
||||||
libxlSavefileHeaderPtr ret_hdr)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
virDomainDefPtr def = NULL;
|
|
||||||
libxlSavefileHeader hdr;
|
|
||||||
char *xml = NULL;
|
|
||||||
|
|
||||||
if ((fd = virFileOpenAs(from, O_RDONLY, 0, -1, -1, 0)) < 0) {
|
|
||||||
virReportSystemError(-fd,
|
|
||||||
_("Failed to open domain image file '%s'"), from);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saferead(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
||||||
"%s", _("failed to read libxl header"));
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (memcmp(hdr.magic, LIBXL_SAVE_MAGIC, sizeof(hdr.magic))) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG, "%s", _("image magic is incorrect"));
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hdr.version > LIBXL_SAVE_VERSION) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
||||||
_("image version is not supported (%d > %d)"),
|
|
||||||
hdr.version, LIBXL_SAVE_VERSION);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hdr.xmlLen <= 0) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
||||||
_("invalid XML length: %d"), hdr.xmlLen);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC_N(xml, hdr.xmlLen) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (saferead(fd, xml, hdr.xmlLen) != hdr.xmlLen) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to read XML"));
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(def = virDomainDefParseString(xml, cfg->caps, driver->xmlopt,
|
|
||||||
1 << VIR_DOMAIN_VIRT_XEN,
|
|
||||||
VIR_DOMAIN_XML_INACTIVE)))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
VIR_FREE(xml);
|
|
||||||
|
|
||||||
*ret_def = def;
|
|
||||||
*ret_hdr = hdr;
|
|
||||||
|
|
||||||
return fd;
|
|
||||||
|
|
||||||
error:
|
|
||||||
VIR_FREE(xml);
|
|
||||||
virDomainDefFree(def);
|
|
||||||
VIR_FORCE_CLOSE(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Core dump domain to default dump path.
|
* Core dump domain to default dump path.
|
||||||
@ -712,9 +640,9 @@ libxlVmStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
|
|||||||
|
|
||||||
if (virFileExists(managed_save_path)) {
|
if (virFileExists(managed_save_path)) {
|
||||||
|
|
||||||
managed_save_fd = libxlSaveImageOpen(driver, cfg,
|
managed_save_fd = libxlDomainSaveImageOpen(driver, cfg,
|
||||||
managed_save_path,
|
managed_save_path,
|
||||||
&def, &hdr);
|
&def, &hdr);
|
||||||
if (managed_save_fd < 0)
|
if (managed_save_fd < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
@ -2142,7 +2070,7 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = libxlSaveImageOpen(driver, cfg, from, &def, &hdr);
|
fd = libxlDomainSaveImageOpen(driver, cfg, from, &def, &hdr);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
goto cleanup_unlock;
|
goto cleanup_unlock;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user