debuggers.hg

changeset 20829:3edbffaab206

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>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jan 12 07:02:29 2010 +0000 (2010-01-12)
parents 5b45d08b7abf
children 55109e7326cc
files tools/libxl/libxl.c tools/libxl/xl.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Tue Jan 12 07:01:21 2010 +0000
     1.2 +++ b/tools/libxl/libxl.c	Tue Jan 12 07:02:29 2010 +0000
     1.3 @@ -176,18 +176,24 @@ retry_transaction:
     1.4  int libxl_domain_build(struct libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, libxl_domain_build_state *state)
     1.5  {
     1.6      char **vments = NULL, **localents = NULL;
     1.7 -    int i;
     1.8 +    int i, ret;
     1.9 +
    1.10 +    ret = build_pre(ctx, domid, info, state);
    1.11 +    if (ret) goto out;
    1.12  
    1.13 -    build_pre(ctx, domid, info, state);
    1.14      if (info->hvm) {
    1.15 -        build_hvm(ctx, domid, info, state);
    1.16 +        ret = build_hvm(ctx, domid, info, state);
    1.17 +        if (ret) goto out;
    1.18 +
    1.19          vments = libxl_calloc(ctx, 5, sizeof(char *));
    1.20          vments[0] = "rtc/timeoffset";
    1.21          vments[1] = (info->u.hvm.timeoffset) ? info->u.hvm.timeoffset : "";
    1.22          vments[2] = "image/ostype";
    1.23          vments[3] = "hvm";
    1.24      } else {
    1.25 -        build_pv(ctx, domid, info, state);
    1.26 +        ret = build_pv(ctx, domid, info, state);
    1.27 +        if (ret) goto out;
    1.28 +
    1.29          vments = libxl_calloc(ctx, 9, sizeof(char *));
    1.30          i = 0;
    1.31          vments[i++] = "image/ostype";
    1.32 @@ -203,8 +209,9 @@ int libxl_domain_build(struct libxl_ctx 
    1.33              vments[i++] = (char*) info->u.pv.cmdline;
    1.34          }
    1.35      }
    1.36 -    build_post(ctx, domid, info, state, vments, localents);
    1.37 -    return 0;
    1.38 +    ret = build_post(ctx, domid, info, state, vments, localents);
    1.39 +out:
    1.40 +    return ret;
    1.41  }
    1.42  
    1.43  int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
    1.44 @@ -212,10 +219,14 @@ int libxl_domain_restore(struct libxl_ct
    1.45                           libxl_device_model_info *dm_info)
    1.46  {
    1.47      char **vments = NULL, **localents = NULL;
    1.48 -    int i;
    1.49 +    int i, ret;
    1.50  
    1.51 -    build_pre(ctx, domid, info, state);
    1.52 -    restore_common(ctx, domid, info, state, fd);
    1.53 +    ret = build_pre(ctx, domid, info, state);
    1.54 +    if (ret) goto out;
    1.55 +
    1.56 +    ret = restore_common(ctx, domid, info, state, fd);
    1.57 +    if (ret) goto out;
    1.58 +
    1.59      if (info->hvm) {
    1.60          vments = libxl_calloc(ctx, 5, sizeof(char *));
    1.61          vments[0] = "rtc/timeoffset";
    1.62 @@ -238,13 +249,15 @@ int libxl_domain_restore(struct libxl_ct
    1.63              vments[i++] = (char*) info->u.pv.cmdline;
    1.64          }
    1.65      }
    1.66 -    build_post(ctx, domid, info, state, vments, localents);
    1.67 +    ret = build_post(ctx, domid, info, state, vments, localents);
    1.68 +    if (ret) goto out;
    1.69 +
    1.70      if (info->hvm)
    1.71          asprintf(&(dm_info->saved_state), "/var/lib/xen/qemu-save.%d", domid);
    1.72      else
    1.73          dm_info->saved_state = NULL;
    1.74 -
    1.75 -    return 0;
    1.76 +out:
    1.77 +    return ret;
    1.78  }
    1.79  
    1.80  int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid)
     2.1 --- a/tools/libxl/xl.c	Tue Jan 12 07:01:21 2010 +0000
     2.2 +++ b/tools/libxl/xl.c	Tue Jan 12 07:02:29 2010 +0000
     2.3 @@ -750,6 +750,7 @@ static void create_domain(int debug, int
     2.4      int num_disks = 0, num_vifs = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0;
     2.5      int i, fd;
     2.6      int need_daemon = 1;
     2.7 +    int ret;
     2.8      libxl_device_model_starting *dm_starting = 0;
     2.9      libxl_waiter *w1 = NULL, *w2 = NULL;
    2.10      memset(&dm_info, 0x00, sizeof(dm_info));
    2.11 @@ -768,29 +769,47 @@ start:
    2.12      }
    2.13  
    2.14      libxl_ctx_set_log(&ctx, log_callback, NULL);
    2.15 -    libxl_domain_make(&ctx, &info1, &domid);
    2.16 +
    2.17 +    ret = libxl_domain_make(&ctx, &info1, &domid);
    2.18 +    if (ret) {
    2.19 +        fprintf(stderr, "cannot make domain: %d\n", ret);
    2.20 +        return;
    2.21 +    }
    2.22  
    2.23      if (!restore_file || !need_daemon) {
    2.24          if (dm_info.saved_state) {
    2.25              free(dm_info.saved_state);
    2.26              dm_info.saved_state = NULL;
    2.27          }
    2.28 -        libxl_domain_build(&ctx, &info2, domid, &state);
    2.29 +        ret = libxl_domain_build(&ctx, &info2, domid, &state);
    2.30      } else {
    2.31          int restore_fd;
    2.32  
    2.33          restore_fd = open(restore_file, O_RDONLY);
    2.34 -        libxl_domain_restore(&ctx, &info2, domid, restore_fd, &state, &dm_info);
    2.35 +        ret = libxl_domain_restore(&ctx, &info2, domid, restore_fd, &state, &dm_info);
    2.36          close(restore_fd);
    2.37      }
    2.38  
    2.39 +    if (ret) {
    2.40 +        fprintf(stderr, "cannot (re-)build domain: %d\n", ret);
    2.41 +        return;
    2.42 +    }
    2.43 +
    2.44      for (i = 0; i < num_disks; i++) {
    2.45          disks[i].domid = domid;
    2.46 -        libxl_device_disk_add(&ctx, domid, &disks[i]);
    2.47 +        ret = libxl_device_disk_add(&ctx, domid, &disks[i]);
    2.48 +        if (ret) {
    2.49 +            fprintf(stderr, "cannot add disk %d to domain: %d\n", i, ret);
    2.50 +            return;
    2.51 +        }
    2.52      }
    2.53      for (i = 0; i < num_vifs; i++) {
    2.54          vifs[i].domid = domid;
    2.55 -        libxl_device_nic_add(&ctx, domid, &vifs[i]);
    2.56 +        ret = libxl_device_nic_add(&ctx, domid, &vifs[i]);
    2.57 +        if (ret) {
    2.58 +            fprintf(stderr, "cannot add nic %d to domain: %d\n", i, ret);
    2.59 +            return;
    2.60 +        }
    2.61      }
    2.62      if (info1.hvm) {
    2.63          dm_info.domid = domid;