提交 84b5415c 编写于 作者: D Daniel P. Berrange

Allow empty bootloader tag

上级 fb741174
Sat Sep 29 14:23:41 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/sexpr.h, src/sexpr.c, src/xml.c, src/xend_internal.c: Allow
bootloader tag to be empty, to indicate use of default configured
bootloader path.
Sat Sep 29 14:05:41 EST 2007 Daniel P. Berrange <berrange@redhat.com> Sat Sep 29 14:05:41 EST 2007 Daniel P. Berrange <berrange@redhat.com>
* src/sexpr.h, src/sexpr.c, src/virsh.c, src/xend_internal.c: * src/sexpr.h, src/sexpr.c, src/virsh.c, src/xend_internal.c:
......
...@@ -404,17 +404,18 @@ string2sexpr(const char *buffer) ...@@ -404,17 +404,18 @@ string2sexpr(const char *buffer)
/** /**
* sexpr_lookup: * sexpr_lookup_key:
* @sexpr: a pointer to a parsed S-Expression * @sexpr: a pointer to a parsed S-Expression
* @node: a path for the sub expression to lookup in the S-Expression * @node: a path for the sub expression to lookup in the S-Expression
* *
* Search a sub expression in the S-Expression based on its path * Search a sub expression in the S-Expression based on its path
* Returns the key node, rather than the data node.
* NOTE: path are limited to 4096 bytes. * NOTE: path are limited to 4096 bytes.
* *
* Returns the pointer to the sub expression or NULL if not found. * Returns the pointer to the sub expression or NULL if not found.
*/ */
struct sexpr * static struct sexpr *
sexpr_lookup(struct sexpr *sexpr, const char *node) sexpr_lookup_key(struct sexpr *sexpr, const char *node)
{ {
char buffer[4096], *ptr, *token; char buffer[4096], *ptr, *token;
...@@ -463,10 +464,57 @@ sexpr_lookup(struct sexpr *sexpr, const char *node) ...@@ -463,10 +464,57 @@ sexpr_lookup(struct sexpr *sexpr, const char *node)
return NULL; return NULL;
} }
if (sexpr->kind != SEXPR_CONS || sexpr->u.s.cdr->kind != SEXPR_CONS) return sexpr;
}
/**
* sexpr_lookup:
* @sexpr: a pointer to a parsed S-Expression
* @node: a path for the sub expression to lookup in the S-Expression
*
* Search a sub expression in the S-Expression based on its path.
* NOTE: path are limited to 4096 bytes.
*
* Returns the pointer to the sub expression or NULL if not found.
*/
struct sexpr *
sexpr_lookup(struct sexpr *sexpr, const char *node)
{
struct sexpr *s = sexpr_lookup_key(sexpr, node);
if (s == NULL)
return NULL;
if (s->kind != SEXPR_CONS || s->u.s.cdr->kind != SEXPR_CONS)
return NULL; return NULL;
return sexpr->u.s.cdr; return s->u.s.cdr;
}
/**
* sexpr_has:
* @sexpr: a pointer to a parsed S-Expression
* @node: a path for the sub expression to lookup in the S-Expression
*
* Search a sub expression in the S-Expression based on its path.
* NOTE: path are limited to 4096 bytes.
* NB, even if the key was found sexpr_lookup may return NULL if
* the corresponding value was empty
*
* Returns true if the key was found, false otherwise
*/
int
sexpr_has(struct sexpr *sexpr, const char *node)
{
struct sexpr *s = sexpr_lookup_key(sexpr, node);
if (s == NULL)
return 0;
if (s->kind != SEXPR_CONS)
return 0;
return 1;
} }
/** /**
......
...@@ -50,4 +50,5 @@ const char *sexpr_node(struct sexpr *sexpr, const char *node); ...@@ -50,4 +50,5 @@ const char *sexpr_node(struct sexpr *sexpr, const char *node);
const char *sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...) const char *sexpr_fmt_node(struct sexpr *sexpr, const char *fmt, ...)
ATTRIBUTE_FORMAT(printf,2,3); ATTRIBUTE_FORMAT(printf,2,3);
struct sexpr *sexpr_lookup(struct sexpr *sexpr, const char *node); struct sexpr *sexpr_lookup(struct sexpr *sexpr, const char *node);
int sexpr_has(struct sexpr *sexpr, const char *node);
#endif #endif
...@@ -1402,6 +1402,9 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi ...@@ -1402,6 +1402,9 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi
if (tmp != NULL) { if (tmp != NULL) {
bootloader = 1; bootloader = 1;
virBufferVSprintf(&buf, " <bootloader>%s</bootloader>\n", tmp); virBufferVSprintf(&buf, " <bootloader>%s</bootloader>\n", tmp);
} else if (sexpr_has(root, "domain/bootloader")) {
bootloader = 1;
virBufferVSprintf(&buf, " <bootloader/>\n");
} }
tmp = sexpr_node(root, "domain/bootloader_args"); tmp = sexpr_node(root, "domain/bootloader_args");
if (tmp != NULL && bootloader) { if (tmp != NULL && bootloader) {
...@@ -1414,7 +1417,8 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi ...@@ -1414,7 +1417,8 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi
if (domid != 0) { if (domid != 0) {
if (sexpr_lookup(root, "domain/image")) { if (sexpr_lookup(root, "domain/image")) {
hvm = sexpr_lookup(root, "domain/image/hvm") ? 1 : 0; hvm = sexpr_lookup(root, "domain/image/hvm") ? 1 : 0;
xend_parse_sexp_desc_os(conn, root, &buf, hvm, bootloader); if (xend_parse_sexp_desc_os(conn, root, &buf, hvm, bootloader) < 0)
goto error;
} }
} }
......
...@@ -1179,6 +1179,14 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name, int ...@@ -1179,6 +1179,14 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name, int
*/ */
bootloader = 1; bootloader = 1;
free(str); free(str);
} else if (virXPathNumber("count(/domain/bootloader)", ctxt, &f) == 0 &&
(f > 0)) {
virBufferVSprintf(&buf, "(bootloader)");
/*
* if using a bootloader, the kernel and initrd strings are not
* significant and should be discarded
*/
bootloader = 1;
} }
str = virXPathString("string(/domain/bootloader_args[1])", ctxt); str = virXPathString("string(/domain/bootloader_args[1])", ctxt);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册