mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-23 20:02:21 +00:00
snapshot: Factor out post-parse code
Move the non-deterministic code that sets snapshot properties independently of what the incoming XML described to instead live in a default post-parse function common to virDomainMoment (as checkpoints will also reuse it in later patches). This patch is just code motion, with no difference to any callers; but the next patch will further refactor things to allow for a per-driver override, used by the testsuite to perform deterministic post-parse actions for better coverage of parser/formatter code. Note that the post-parse code is intentionally not run during a snapshot redefine, since that code path already requires a valid snapshot name and creation time from the XML. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
a007fcab3b
commit
5ba4d81ce9
@ -21,11 +21,14 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "moment_conf.h"
|
||||
#include "domain_conf.h"
|
||||
#include "virlog.h"
|
||||
#include "viralloc.h"
|
||||
#include "virstring.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_DOMAIN
|
||||
|
||||
@ -38,3 +41,19 @@ void virDomainMomentDefClear(virDomainMomentDefPtr def)
|
||||
VIR_FREE(def->parent);
|
||||
virDomainDefFree(def->dom);
|
||||
}
|
||||
|
||||
/* Provide defaults for creation time and moment name after parsing XML */
|
||||
int
|
||||
virDomainMomentDefPostParse(virDomainMomentDefPtr def)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
if (!def->name &&
|
||||
virAsprintf(&def->name, "%lld", (long long)tv.tv_sec) < 0)
|
||||
return -1;
|
||||
|
||||
def->creationTime = tv.tv_sec;
|
||||
return 0;
|
||||
}
|
||||
|
@ -39,4 +39,6 @@ struct _virDomainMomentDef {
|
||||
|
||||
void virDomainMomentDefClear(virDomainMomentDefPtr def);
|
||||
|
||||
int virDomainMomentDefPostParse(virDomainMomentDefPtr def);
|
||||
|
||||
#endif /* LIBVIRT_MOMENT_CONF_H */
|
||||
|
@ -23,7 +23,6 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "internal.h"
|
||||
@ -199,7 +198,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
||||
size_t i;
|
||||
int n;
|
||||
char *creation = NULL, *state = NULL;
|
||||
struct timeval tv;
|
||||
int active;
|
||||
char *tmp;
|
||||
char *memorySnapshot = NULL;
|
||||
@ -210,8 +208,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
||||
if (VIR_ALLOC(def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
def->common.name = virXPathString("string(./name)", ctxt);
|
||||
if (def->common.name == NULL) {
|
||||
if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) {
|
||||
@ -219,8 +215,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
||||
_("a redefined snapshot must have a name"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (virAsprintf(&def->common.name, "%lld", (long long)tv.tv_sec) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
def->common.description = virXPathString("string(./description)", ctxt);
|
||||
@ -276,8 +270,8 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
||||
} else {
|
||||
VIR_WARN("parsing older snapshot that lacks domain");
|
||||
}
|
||||
} else {
|
||||
def->common.creationTime = tv.tv_sec;
|
||||
} else if (virDomainMomentDefPostParse(&def->common) < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
memorySnapshot = virXPathString("string(./memory/@snapshot)", ctxt);
|
||||
|
Loading…
x
Reference in New Issue
Block a user