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 <config.h>
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "moment_conf.h"
|
#include "moment_conf.h"
|
||||||
#include "domain_conf.h"
|
#include "domain_conf.h"
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
|
#include "virstring.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_DOMAIN
|
#define VIR_FROM_THIS VIR_FROM_DOMAIN
|
||||||
|
|
||||||
@ -38,3 +41,19 @@ void virDomainMomentDefClear(virDomainMomentDefPtr def)
|
|||||||
VIR_FREE(def->parent);
|
VIR_FREE(def->parent);
|
||||||
virDomainDefFree(def->dom);
|
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);
|
void virDomainMomentDefClear(virDomainMomentDefPtr def);
|
||||||
|
|
||||||
|
int virDomainMomentDefPostParse(virDomainMomentDefPtr def);
|
||||||
|
|
||||||
#endif /* LIBVIRT_MOMENT_CONF_H */
|
#endif /* LIBVIRT_MOMENT_CONF_H */
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
@ -199,7 +198,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
|||||||
size_t i;
|
size_t i;
|
||||||
int n;
|
int n;
|
||||||
char *creation = NULL, *state = NULL;
|
char *creation = NULL, *state = NULL;
|
||||||
struct timeval tv;
|
|
||||||
int active;
|
int active;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *memorySnapshot = NULL;
|
char *memorySnapshot = NULL;
|
||||||
@ -210,8 +208,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
|||||||
if (VIR_ALLOC(def) < 0)
|
if (VIR_ALLOC(def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
|
|
||||||
def->common.name = virXPathString("string(./name)", ctxt);
|
def->common.name = virXPathString("string(./name)", ctxt);
|
||||||
if (def->common.name == NULL) {
|
if (def->common.name == NULL) {
|
||||||
if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) {
|
if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE) {
|
||||||
@ -219,8 +215,6 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
|||||||
_("a redefined snapshot must have a name"));
|
_("a redefined snapshot must have a name"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (virAsprintf(&def->common.name, "%lld", (long long)tv.tv_sec) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def->common.description = virXPathString("string(./description)", ctxt);
|
def->common.description = virXPathString("string(./description)", ctxt);
|
||||||
@ -276,8 +270,8 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
|||||||
} else {
|
} else {
|
||||||
VIR_WARN("parsing older snapshot that lacks domain");
|
VIR_WARN("parsing older snapshot that lacks domain");
|
||||||
}
|
}
|
||||||
} else {
|
} else if (virDomainMomentDefPostParse(&def->common) < 0) {
|
||||||
def->common.creationTime = tv.tv_sec;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
memorySnapshot = virXPathString("string(./memory/@snapshot)", ctxt);
|
memorySnapshot = virXPathString("string(./memory/@snapshot)", ctxt);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user