# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1263279749 0
# Node ID 3edbffaab2069e4eaa3f866a24819b906fa6093b
# Parent 5b45d08b7abf9316be1cc2b510631736a739064f
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@xxxxxxxxxxxxx>
---
tools/libxl/libxl.c | 41 +++++++++++++++++++++++++++--------------
tools/libxl/xl.c | 29 ++++++++++++++++++++++++-----
2 files changed, 51 insertions(+), 19 deletions(-)
diff -r 5b45d08b7abf -r 3edbffaab206 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Tue Jan 12 07:01:21 2010 +0000
+++ b/tools/libxl/libxl.c Tue Jan 12 07:02:29 2010 +0000
@@ -176,18 +176,24 @@ int libxl_domain_build(struct libxl_ctx
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;
-
- build_pre(ctx, domid, info, state);
+ int i, ret;
+
+ ret = build_pre(ctx, domid, info, state);
+ if (ret) goto out;
+
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
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_ct
libxl_device_model_info *dm_info)
{
char **vments = NULL, **localents = NULL;
- int i;
-
- build_pre(ctx, domid, info, state);
- restore_common(ctx, domid, info, state, fd);
+ 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;
+
if (info->hvm) {
vments = libxl_calloc(ctx, 5, sizeof(char *));
vments[0] = "rtc/timeoffset";
@@ -238,13 +249,15 @@ int libxl_domain_restore(struct libxl_ct
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 -r 5b45d08b7abf -r 3edbffaab206 tools/libxl/xl.c
--- a/tools/libxl/xl.c Tue Jan 12 07:01:21 2010 +0000
+++ b/tools/libxl/xl.c Tue Jan 12 07:02:29 2010 +0000
@@ -750,6 +750,7 @@ static void create_domain(int debug, int
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;
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|