diff --git a/ChangeLog b/ChangeLog index b9b39af024..6eb81fc4ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Mar 30 16:04:47 EST 2006 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. + Thu Mar 30 12:15:46 EST 2006 Daniel Veillard * src/virsh.c: catching memory allocation error and existing, as diff --git a/src/virsh.c b/src/virsh.c index e10bf1c8ad..6c7a001fd0 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -419,6 +420,61 @@ cmdSuspend(vshControl * ctl, vshCmd * cmd) return ret; } +/* + * "create" command + */ +static vshCmdInfo info_create[] = { + {"syntax", "create a domain from an XML "}, + {"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 */ @@ -896,6 +952,7 @@ cmdQuit(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED) */ static vshCmdDef commands[] = { {"connect", cmdConnect, opts_connect, info_connect}, + {"create", cmdCreate, opts_create, info_create}, {"dinfo", cmdDinfo, opts_dinfo, info_dinfo}, {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml}, {"dstate", cmdDstate, opts_dstate, info_dstate}, @@ -1640,6 +1697,11 @@ vshReadlineOptionsGenerator(const char *text, int state) return NULL; 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); cmd = vshCmddefSearch(cmdname); @@ -1850,6 +1912,10 @@ vshParseArgv(vshControl * ctl, int argc, char **argv) sz += strlen(argv[i]) + 1; /* +1 is for blank space between items */ 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++) { strncat(cmdstr, argv[i], sz); diff --git a/src/xend_internal.c b/src/xend_internal.c index 329726d59f..42335058e0 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -1362,6 +1362,9 @@ xend_parse_sexp_desc(struct sexpr *root) goto error; } virBufferVSprintf(&buf, " %s\n", tmp); + tmp = sexpr_node(root, "domain/bootloader"); + if (tmp != NULL) + virBufferVSprintf(&buf, " %s\n", tmp); tmp = sexpr_node(root, "domain/image/linux/kernel"); if (tmp == NULL) { /* @@ -1434,11 +1437,15 @@ xend_parse_sexp_desc(struct sexpr *root) serial); TODO} } else if (sexpr_lookup(node, "device/vif")) { + const char *tmp2; + 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, " \n"); - virBufferVSprintf(&buf, " \n", - tmp); + if (tmp != NULL) + virBufferVSprintf(&buf, " \n", + tmp); tmp = sexpr_node(node, "device/vif/vifname"); if (tmp != NULL) virBufferVSprintf(&buf, " \n", @@ -1451,16 +1458,15 @@ xend_parse_sexp_desc(struct sexpr *root) if (tmp != NULL) virBufferVSprintf(&buf, " \n", tmp); - tmp = sexpr_node(node, "device/vif/script"); - if (tmp != NULL) + if (tmp2 != NULL) virBufferVSprintf(&buf, "