From: Vincent Hanquez Subject: [PATCH 1/6] tests a lots more of xl return value inside the library and in xl. Date: Mon, 11 Jan 2010 21:48:21 +0000 Message-ID: <1263246506-5488-2-git-send-email-vincent.hanquez@eu.citrix.com> References: <1263246506-5488-1-git-send-email-vincent.hanquez@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.6.6" Return-path: In-Reply-To: <1263246506-5488-1-git-send-email-vincent.hanquez@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Vincent Hanquez List-Id: xen-devel@lists.xenproject.org --------------1.6.6 Content-Type: text/plain; charset="UTF-8"; format=fixed Content-Transfer-Encoding: quoted-printable 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 domai= n'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 j= ust succeed). make xl a lot more robust regarding all those random errors possible. Signed-off-by: Vincent Hanquez --- tools/libxl/libxl.c | 37 +++++++++++++++++++++++++------------ tools/libxl/xl.c | 29 ++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 17 deletions(-) --------------1.6.6 Content-Type: text/x-patch; name="0001-tests-a-lots-more-of-xl-return-value-inside-the-libr.patch" Content-Disposition: attachment; filename="0001-tests-a-lots-more-of-xl-return-value-inside-the-libr.patch" Content-Transfer-Encoding: quoted-printable diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index c2dcbcc..15299ea 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 *i= nfo, uint32_t domid, libxl_domain_build_state *state) { char **vments =3D NULL, **localents =3D NULL; - int i; + int i, ret; + + ret =3D build_pre(ctx, domid, info, state); + if (ret) goto out; =20 - build_pre(ctx, domid, info, state); if (info->hvm) { - build_hvm(ctx, domid, info, state); + ret =3D build_hvm(ctx, domid, info, state); + if (ret) goto out; + vments =3D libxl_calloc(ctx, 5, sizeof(char *)); vments[0] =3D "rtc/timeoffset"; vments[1] =3D (info->u.hvm.timeoffset) ? info->u.hvm.timeoffset = : ""; vments[2] =3D "image/ostype"; vments[3] =3D "hvm"; } else { - build_pv(ctx, domid, info, state); + ret =3D build_pv(ctx, domid, info, state); + if (ret) goto out; + vments =3D libxl_calloc(ctx, 9, sizeof(char *)); i =3D 0; vments[i++] =3D "image/ostype"; @@ -203,8 +209,9 @@ int libxl_domain_build(struct libxl_ctx *ctx, libxl_d= omain_build_info *info, uin vments[i++] =3D (char*) info->u.pv.cmdline; } } - build_post(ctx, domid, info, state, vments, localents); - return 0; + ret =3D build_post(ctx, domid, info, state, vments, localents); +out: + return ret; } =20 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, lib= xl_domain_build_info *info, libxl_device_model_info *dm_info) { char **vments =3D NULL, **localents =3D NULL; - int i; + int i, ret; + + ret =3D build_pre(ctx, domid, info, state); + if (ret) goto out; + + ret =3D restore_common(ctx, domid, info, state, fd); + if (ret) goto out; =20 - build_pre(ctx, domid, info, state); - restore_common(ctx, domid, info, state, fd); if (info->hvm) { vments =3D libxl_calloc(ctx, 5, sizeof(char *)); vments[0] =3D "rtc/timeoffset"; @@ -238,13 +249,15 @@ int libxl_domain_restore(struct libxl_ctx *ctx, lib= xl_domain_build_info *info, vments[i++] =3D (char*) info->u.pv.cmdline; } } - build_post(ctx, domid, info, state, vments, localents); + ret =3D 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", d= omid); else dm_info->saved_state =3D NULL; - - return 0; +out: + return ret; } =20 int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid) diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c index 996965b..851519f 100644 --- a/tools/libxl/xl.c +++ b/tools/libxl/xl.c @@ -750,6 +750,7 @@ static void create_domain(int debug, int daemonize, c= onst char *config_file, con int num_disks =3D 0, num_vifs =3D 0, num_pcidevs =3D 0, num_vfbs =3D= 0, num_vkbs =3D 0; int i, fd; int need_daemon =3D 1; + int ret; libxl_device_model_starting *dm_starting =3D 0; libxl_waiter *w1 =3D NULL, *w2 =3D NULL; memset(&dm_info, 0x00, sizeof(dm_info)); @@ -768,29 +769,47 @@ start: } =20 libxl_ctx_set_log(&ctx, log_callback, NULL); - libxl_domain_make(&ctx, &info1, &domid); + + ret =3D libxl_domain_make(&ctx, &info1, &domid); + if (ret) { + fprintf(stderr, "cannot make domain: %d\n", ret); + return; + } =20 if (!restore_file || !need_daemon) { if (dm_info.saved_state) { free(dm_info.saved_state); dm_info.saved_state =3D NULL; } - libxl_domain_build(&ctx, &info2, domid, &state); + ret =3D libxl_domain_build(&ctx, &info2, domid, &state); } else { int restore_fd; =20 restore_fd =3D open(restore_file, O_RDONLY); - libxl_domain_restore(&ctx, &info2, domid, restore_fd, &state, &d= m_info); + ret =3D libxl_domain_restore(&ctx, &info2, domid, restore_fd, &s= tate, &dm_info); close(restore_fd); } =20 + if (ret) { + fprintf(stderr, "cannot (re-)build domain: %d\n", ret); + return; + } + for (i =3D 0; i < num_disks; i++) { disks[i].domid =3D domid; - libxl_device_disk_add(&ctx, domid, &disks[i]); + ret =3D 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 =3D 0; i < num_vifs; i++) { vifs[i].domid =3D domid; - libxl_device_nic_add(&ctx, domid, &vifs[i]); + ret =3D 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 =3D domid; --------------1.6.6 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------1.6.6--