aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-01-12 07:02:29 +0000
committerKeir Fraser <keir.fraser@citrix.com>2010-01-12 07:02:29 +0000
commitf777e25427e0204eaa74f8739fe02c436bdfc339 (patch)
tree4bcf09002f543bfdcceb9c0fae23b9f9a237f01f
parent60e8e9aabcca4188e5ad2d0b5c8a448bd0c4437e (diff)
downloadxen-f777e25427e0204eaa74f8739fe02c436bdfc339.tar.gz
xen-f777e25427e0204eaa74f8739fe02c436bdfc339.tar.bz2
xen-f777e25427e0204eaa74f8739fe02c436bdfc339.zip
libxenlight: tests a lots more of xl return value inside the library
and in xl. introducing a domain where the xenguest build function has fail, lead to having xenstored receiving SIGBUS, since it's trying to access some of the domain's memory, which haven't been properly allocated. (it doesn't seems to be a way to make xenstored more robust to this though since xc_map_foreign_range just succeed). make xl a lot more robust regarding all those random errors possible. Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
-rw-r--r--tools/libxl/libxl.c37
-rw-r--r--tools/libxl/xl.c29
2 files changed, 49 insertions, 17 deletions
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index c2dcbcc52d..15299ea346 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -176,18 +176,24 @@ retry_transaction:
int libxl_domain_build(struct libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, libxl_domain_build_state *state)
{
char **vments = NULL, **localents = NULL;
- int i;
+ int i, ret;
+
+ ret = build_pre(ctx, domid, info, state);
+ if (ret) goto out;
- build_pre(ctx, domid, info, state);
if (info->hvm) {
- build_hvm(ctx, domid, info, state);
+ ret = build_hvm(ctx, domid, info, state);
+ if (ret) goto out;
+
vments = libxl_calloc(ctx, 5, sizeof(char *));
vments[0] = "rtc/timeoffset";
vments[1] = (info->u.hvm.timeoffset) ? info->u.hvm.timeoffset : "";
vments[2] = "image/ostype";
vments[3] = "hvm";
} else {
- build_pv(ctx, domid, info, state);
+ ret = build_pv(ctx, domid, info, state);
+ if (ret) goto out;
+
vments = libxl_calloc(ctx, 9, sizeof(char *));
i = 0;
vments[i++] = "image/ostype";
@@ -203,8 +209,9 @@ int libxl_domain_build(struct libxl_ctx *ctx, libxl_domain_build_info *info, uin
vments[i++] = (char*) info->u.pv.cmdline;
}
}
- build_post(ctx, domid, info, state, vments, localents);
- return 0;
+ ret = build_post(ctx, domid, info, state, vments, localents);
+out:
+ return ret;
}
int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
@@ -212,10 +219,14 @@ int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
libxl_device_model_info *dm_info)
{
char **vments = NULL, **localents = NULL;
- int i;
+ int i, ret;
+
+ ret = build_pre(ctx, domid, info, state);
+ if (ret) goto out;
+
+ ret = restore_common(ctx, domid, info, state, fd);
+ if (ret) goto out;
- build_pre(ctx, domid, info, state);
- restore_common(ctx, domid, info, state, fd);
if (info->hvm) {
vments = libxl_calloc(ctx, 5, sizeof(char *));
vments[0] = "rtc/timeoffset";
@@ -238,13 +249,15 @@ int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
vments[i++] = (char*) info->u.pv.cmdline;
}
}
- build_post(ctx, domid, info, state, vments, localents);
+ ret = build_post(ctx, domid, info, state, vments, localents);
+ if (ret) goto out;
+
if (info->hvm)
asprintf(&(dm_info->saved_state), "/var/lib/xen/qemu-save.%d", domid);
else
dm_info->saved_state = NULL;
-
- return 0;
+out:
+ return ret;
}
int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid)
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
index 3be7acf0a4..2322ce4a67 100644
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -750,6 +750,7 @@ static void create_domain(int debug, int daemonize, const char *config_file, con
int num_disks = 0, num_vifs = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0;
int i, fd;
int need_daemon = 1;
+ int ret;
libxl_device_model_starting *dm_starting = 0;
libxl_waiter *w1 = NULL, *w2 = NULL;
memset(&dm_info, 0x00, sizeof(dm_info));
@@ -768,29 +769,47 @@ start:
}
libxl_ctx_set_log(&ctx, log_callback, NULL);
- libxl_domain_make(&ctx, &info1, &domid);
+
+ ret = libxl_domain_make(&ctx, &info1, &domid);
+ if (ret) {
+ fprintf(stderr, "cannot make domain: %d\n", ret);
+ return;
+ }
if (!restore_file || !need_daemon) {
if (dm_info.saved_state) {
free(dm_info.saved_state);
dm_info.saved_state = NULL;
}
- libxl_domain_build(&ctx, &info2, domid, &state);
+ ret = libxl_domain_build(&ctx, &info2, domid, &state);
} else {
int restore_fd;
restore_fd = open(restore_file, O_RDONLY);
- libxl_domain_restore(&ctx, &info2, domid, restore_fd, &state, &dm_info);
+ ret = libxl_domain_restore(&ctx, &info2, domid, restore_fd, &state, &dm_info);
close(restore_fd);
}
+ if (ret) {
+ fprintf(stderr, "cannot (re-)build domain: %d\n", ret);
+ return;
+ }
+
for (i = 0; i < num_disks; i++) {
disks[i].domid = domid;
- libxl_device_disk_add(&ctx, domid, &disks[i]);
+ ret = libxl_device_disk_add(&ctx, domid, &disks[i]);
+ if (ret) {
+ fprintf(stderr, "cannot add disk %d to domain: %d\n", i, ret);
+ return;
+ }
}
for (i = 0; i < num_vifs; i++) {
vifs[i].domid = domid;
- libxl_device_nic_add(&ctx, domid, &vifs[i]);
+ ret = libxl_device_nic_add(&ctx, domid, &vifs[i]);
+ if (ret) {
+ fprintf(stderr, "cannot add nic %d to domain: %d\n", i, ret);
+ return;
+ }
}
if (info1.hvm) {
dm_info.domid = domid;