提交 2b4566b5 编写于 作者: D Daniel Veillard

* src/virsh.c: allocation check (Jim Meyering) and adding a

  new create command
* src/xend_internal.c src/xml.c: trying to cope with the new
  xvda domains states generated on FC5, but Dom0 bootloader
  really break the model, so that doesn't work.
Daniel
上级 c9a8f273
Thu Mar 30 16:04:47 EST 2006 Daniel Veillard <veillard@redhat.com>
* src/virsh.c: allocation check (Jim Meyering) and adding a
new create command
* src/xend_internal.c src/xml.c: trying to cope with the new
xvda domains states generated on FC5, but Dom0 bootloader
really break the model, so that doesn't work.
Thu Mar 30 12:15:46 EST 2006 Daniel Veillard <veillard@redhat.com> Thu Mar 30 12:15:46 EST 2006 Daniel Veillard <veillard@redhat.com>
* src/virsh.c: catching memory allocation error and existing, as * src/virsh.c: catching memory allocation error and existing, as
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
#include <ctype.h> #include <ctype.h>
#include <fcntl.h>
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
...@@ -419,6 +420,61 @@ cmdSuspend(vshControl * ctl, vshCmd * cmd) ...@@ -419,6 +420,61 @@ cmdSuspend(vshControl * ctl, vshCmd * cmd)
return ret; return ret;
} }
/*
* "create" command
*/
static vshCmdInfo info_create[] = {
{"syntax", "create a domain from an XML <file>"},
{"help", "create a domain from an XML file"},
{"desc", "Create a domain."},
{NULL, NULL}
};
static vshCmdOptDef opts_create[] = {
{"file", VSH_OT_DATA, VSH_OFLAG_REQ, "file conatining an XML domain description"},
{NULL, 0, 0, NULL}
};
static int
cmdCreate(vshControl * ctl, vshCmd * cmd)
{
virDomainPtr dom;
char *from;
int found;
int ret = TRUE;
char buffer[4096];
int fd, l;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
from = vshCommandOptString(cmd, "file", &found);
if (!found)
return FALSE;
fd = open(from, O_RDONLY);
if (fd < 0) {
vshError(ctl, FALSE, "Failed to read description file %s\n", from);
return(FALSE);
}
l = read(fd, &buffer[0], sizeof(buffer));
if ((l <= 0) || (l >= (int) sizeof(buffer))) {
vshError(ctl, FALSE, "Failed to read description file %s\n", from);
close(fd);
return(FALSE);
}
buffer[l] = 0;
dom = virDomainCreateLinux(ctl->conn, &buffer[0], 0);
if (dom != NULL) {
vshPrint(ctl, VSH_MESG, "Domain %s created from %s\n",
virDomainGetName(dom), from);
} else {
vshError(ctl, FALSE, "Failed to create domain\n");
ret = FALSE;
}
return ret;
}
/* /*
* "save" command * "save" command
*/ */
...@@ -896,6 +952,7 @@ cmdQuit(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED) ...@@ -896,6 +952,7 @@ cmdQuit(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
*/ */
static vshCmdDef commands[] = { static vshCmdDef commands[] = {
{"connect", cmdConnect, opts_connect, info_connect}, {"connect", cmdConnect, opts_connect, info_connect},
{"create", cmdCreate, opts_create, info_create},
{"dinfo", cmdDinfo, opts_dinfo, info_dinfo}, {"dinfo", cmdDinfo, opts_dinfo, info_dinfo},
{"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml}, {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml},
{"dstate", cmdDstate, opts_dstate, info_dstate}, {"dstate", cmdDstate, opts_dstate, info_dstate},
...@@ -1640,6 +1697,11 @@ vshReadlineOptionsGenerator(const char *text, int state) ...@@ -1640,6 +1697,11 @@ vshReadlineOptionsGenerator(const char *text, int state)
return NULL; return NULL;
cmdname = calloc((p - rl_line_buffer) + 1, 1); cmdname = calloc((p - rl_line_buffer) + 1, 1);
if (cmdname == NULL) {
fprintf(stderr, "Failed to allocate %d bytes\n",
(p - rl_line_buffer) + 1);
exit(1);
}
memcpy(cmdname, rl_line_buffer, p - rl_line_buffer); memcpy(cmdname, rl_line_buffer, p - rl_line_buffer);
cmd = vshCmddefSearch(cmdname); cmd = vshCmddefSearch(cmdname);
...@@ -1850,6 +1912,10 @@ vshParseArgv(vshControl * ctl, int argc, char **argv) ...@@ -1850,6 +1912,10 @@ vshParseArgv(vshControl * ctl, int argc, char **argv)
sz += strlen(argv[i]) + 1; /* +1 is for blank space between items */ sz += strlen(argv[i]) + 1; /* +1 is for blank space between items */
cmdstr = calloc(sz + 1, 1); cmdstr = calloc(sz + 1, 1);
if (cmdstr == NULL) {
fprintf(stderr, "Failed to allocate %d bytes\n", sz + 1);
exit(1);
}
for (i = end; i < argc; i++) { for (i = end; i < argc; i++) {
strncat(cmdstr, argv[i], sz); strncat(cmdstr, argv[i], sz);
......
...@@ -1362,6 +1362,9 @@ xend_parse_sexp_desc(struct sexpr *root) ...@@ -1362,6 +1362,9 @@ xend_parse_sexp_desc(struct sexpr *root)
goto error; goto error;
} }
virBufferVSprintf(&buf, " <name>%s</name>\n", tmp); virBufferVSprintf(&buf, " <name>%s</name>\n", tmp);
tmp = sexpr_node(root, "domain/bootloader");
if (tmp != NULL)
virBufferVSprintf(&buf, " <bootloader>%s</bootloader>\n", tmp);
tmp = sexpr_node(root, "domain/image/linux/kernel"); tmp = sexpr_node(root, "domain/image/linux/kernel");
if (tmp == NULL) { if (tmp == NULL) {
/* /*
...@@ -1434,11 +1437,15 @@ xend_parse_sexp_desc(struct sexpr *root) ...@@ -1434,11 +1437,15 @@ xend_parse_sexp_desc(struct sexpr *root)
serial); serial);
TODO} TODO}
} else if (sexpr_lookup(node, "device/vif")) { } else if (sexpr_lookup(node, "device/vif")) {
const char *tmp2;
tmp = sexpr_node(node, "device/vif/bridge"); tmp = sexpr_node(node, "device/vif/bridge");
if (tmp != NULL) { tmp2 = sexpr_node(node, "device/vif/script");
if ((tmp != NULL) || (strstr(tmp2, "bridge"))) {
virBufferVSprintf(&buf, " <interface type='bridge'>\n"); virBufferVSprintf(&buf, " <interface type='bridge'>\n");
virBufferVSprintf(&buf, " <source bridge='%s'/>\n", if (tmp != NULL)
tmp); virBufferVSprintf(&buf, " <source bridge='%s'/>\n",
tmp);
tmp = sexpr_node(node, "device/vif/vifname"); tmp = sexpr_node(node, "device/vif/vifname");
if (tmp != NULL) if (tmp != NULL)
virBufferVSprintf(&buf, " <target dev='%s'/>\n", virBufferVSprintf(&buf, " <target dev='%s'/>\n",
...@@ -1451,16 +1458,15 @@ xend_parse_sexp_desc(struct sexpr *root) ...@@ -1451,16 +1458,15 @@ xend_parse_sexp_desc(struct sexpr *root)
if (tmp != NULL) if (tmp != NULL)
virBufferVSprintf(&buf, " <ip address='%s'/>\n", virBufferVSprintf(&buf, " <ip address='%s'/>\n",
tmp); tmp);
tmp = sexpr_node(node, "device/vif/script"); if (tmp2 != NULL)
if (tmp != NULL)
virBufferVSprintf(&buf, " <script path='%s'/>\n", virBufferVSprintf(&buf, " <script path='%s'/>\n",
tmp); tmp2);
virBufferAdd(&buf, " </interface>\n", 17); virBufferAdd(&buf, " </interface>\n", 17);
} else { } else {
char serial[1000]; char serial[1000];
TODO sexpr2string(node->car, serial, 1000); TODO sexpr2string(node, serial, 1000);
virBufferVSprintf(&buf, "<!-- Failed to parse %s -->\n", virBufferVSprintf(&buf, "<!-- Failed to parse vif: %s -->\n",
serial); serial);
} }
......
...@@ -502,6 +502,7 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) ...@@ -502,6 +502,7 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags)
* virDomainParseXMLOSDesc: * virDomainParseXMLOSDesc:
* @xmldesc: string with the XML description * @xmldesc: string with the XML description
* @buf: a buffer for the result S-Expr * @buf: a buffer for the result S-Expr
* @bootloader: indocate if a bootloader script was provided
* *
* Parse the OS part of the XML description and add it to the S-Expr in buf * Parse the OS part of the XML description and add it to the S-Expr in buf
* This is a temporary interface as the S-Expr interface * This is a temporary interface as the S-Expr interface
...@@ -511,7 +512,7 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) ...@@ -511,7 +512,7 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags)
* Returns 0 in case of success, -1 in case of error. * Returns 0 in case of success, -1 in case of error.
*/ */
static int static int
virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf, int bootloader)
{ {
xmlNodePtr cur, txt; xmlNodePtr cur, txt;
const xmlChar *type = NULL; const xmlChar *type = NULL;
...@@ -559,10 +560,13 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf) ...@@ -559,10 +560,13 @@ virDomainParseXMLOSDesc(xmlNodePtr node, virBufferPtr buf)
} }
virBufferAdd(buf, "(linux ", 7); virBufferAdd(buf, "(linux ", 7);
if (kernel == NULL) { if (kernel == NULL) {
virXMLError(VIR_ERR_NO_KERNEL, NULL, 0); if (bootloader == 0) {
return (-1); virXMLError(VIR_ERR_NO_KERNEL, NULL, 0);
return (-1);
}
} else {
virBufferVSprintf(buf, "(kernel '%s')", (const char *) kernel);
} }
virBufferVSprintf(buf, "(kernel '%s')", (const char *) kernel);
if (initrd != NULL) if (initrd != NULL)
virBufferVSprintf(buf, "(ramdisk '%s')", (const char *) initrd); virBufferVSprintf(buf, "(ramdisk '%s')", (const char *) initrd);
if (root == NULL) { if (root == NULL) {
...@@ -792,6 +796,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) ...@@ -792,6 +796,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name)
xmlXPathObjectPtr obj = NULL; xmlXPathObjectPtr obj = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
int i, res; int i, res;
int bootloader = 0;
if (name != NULL) if (name != NULL)
*name = NULL; *name = NULL;
...@@ -864,6 +869,14 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) ...@@ -864,6 +869,14 @@ virDomainParseXMLDesc(const char *xmldesc, char **name)
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "string(/domain/bootloader[1])", ctxt);
if ((obj != NULL) && (obj->type == XPATH_STRING) &&
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
virBufferVSprintf(&buf, "(bootloader '%s')", obj->stringval);
bootloader = 1;
}
xmlXPathFreeObject(obj);
/* analyze of the os description */ /* analyze of the os description */
virBufferAdd(&buf, "(image ", 7); virBufferAdd(&buf, "(image ", 7);
obj = xmlXPathEval(BAD_CAST "/domain/os[1]", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/os[1]", ctxt);
...@@ -872,7 +885,8 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) ...@@ -872,7 +885,8 @@ virDomainParseXMLDesc(const char *xmldesc, char **name)
virXMLError(VIR_ERR_NO_OS, nam, 0); virXMLError(VIR_ERR_NO_OS, nam, 0);
goto error; goto error;
} }
res = virDomainParseXMLOSDesc(obj->nodesetval->nodeTab[0], &buf); res = virDomainParseXMLOSDesc(obj->nodesetval->nodeTab[0], &buf,
bootloader);
if (res != 0) { if (res != 0) {
goto error; goto error;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册