On Thu, Dec 10, 2015 at 03:18:29PM -0500, John Ferlan wrote:
On 12/01/2015 12:35 PM, Martin Kletzander wrote:
> Add new parameter to virDomainObjListLoadConfig() and
> virDomainObjListLoadAllConfigs() that controls whether domains with
> invalid XML (which could not be parsed) should be kept in order not to
> lose track of them. For now, the parameter is set to false in all
> callers. Each driver can switch it to true when it is prepared to deal
> with such domains.
>
> For the domain object to be created add virDomainDefParseMinimal() that
> parses only name and UUID from the XML definition. UUID must be
> present, it will not be generated. The purpose of this function is to
> be used when all else fails, but we still want a domain object to work
> with.
>
> Also explicitly disable adding the invalid domain into the list of
> active ones, as that would render our internal structures inconsistent.
>
> Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
> ---
> src/bhyve/bhyve_driver.c | 2 ++
> src/conf/domain_conf.c | 36 +++++++++++++++++++++++
> src/conf/domain_conf.h | 7 +++++
> src/conf/virdomainobjlist.c | 71 ++++++++++++++++++++++++++++++++++++++++++---
> src/conf/virdomainobjlist.h | 1 +
> src/libvirt_private.syms | 1 +
> src/libxl/libxl_driver.c | 3 ++
> src/lxc/lxc_driver.c | 3 ++
> src/qemu/qemu_driver.c | 3 ++
> src/uml/uml_driver.c | 2 ++
> 10 files changed, 125 insertions(+), 4 deletions(-)
>
[...]
> @@ -406,13 +416,57 @@ virDomainObjListLoadConfig(virDomainObjListPtr doms,
> virDomainObjPtr dom;
> int autostart;
> virDomainDefPtr oldDef = NULL;
> + char *xmlStr = NULL;
> + char *xmlErr = NULL;
>
> if ((configFile = virDomainConfigFile(configDir, name)) == NULL)
> goto error;
> - if (!(def = virDomainDefParseFile(configFile, caps, xmlopt,
> - VIR_DOMAIN_DEF_PARSE_INACTIVE |
> - VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)))
> - goto error;
> +
> + def = virDomainDefParseFile(configFile, caps, xmlopt,
> + VIR_DOMAIN_DEF_PARSE_INACTIVE |
> + VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS);
> + if (!def) {
> + char *tmp = NULL;
> +
> + if (!keep_invalid)
> + goto error;
> +
> + if (VIR_STRDUP(xmlErr, virGetLastErrorMessage()) < 0)
> + goto error;
> +
> + if (virFileReadAll(configFile, 1024*1024*10, &xmlStr) < 0)
Any reason to not use MAX_CONFIG_FILE_SIZE? Cannot imagine this
failing, but I mention for consistency
This was a copy-paste from somewhere else, but I will add
MAX_CONFIG_FILE_SIZE both here and to that copy-paste source as well (if
I can find it ;)
ACK
John
> + goto error;
> +
> + if (!(def = virDomainDefParseMinimal(NULL, xmlStr)))
> + goto error;
> +
>
[...]