debuggers.hg
changeset 22243:a0044f16d3df
libxl: use transactions in libxl_set_memory_target
[fixed up for conflicts with libxl__ naming policy changes]
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
[fixed up for conflicts with libxl__ naming policy changes]
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author | Stefano Stabellini <stefano.stabellini@eu.citrix.com> |
---|---|
date | Wed Sep 22 17:31:45 2010 +0100 (2010-09-22) |
parents | 4f90c1fde133 |
children | 4b00f89e15f1 |
files | tools/libxl/libxl.c |
line diff
1.1 --- a/tools/libxl/libxl.c Wed Sep 22 17:27:21 2010 +0100 1.2 +++ b/tools/libxl/libxl.c Wed Sep 22 17:31:45 2010 +0100 1.3 @@ -2774,58 +2774,66 @@ out: 1.4 return rc; 1.5 } 1.6 1.7 -int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce) 1.8 +int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, uint32_t 1.9 + target_memkb, int enforce) 1.10 { 1.11 libxl__gc gc = LIBXL_INIT_GC(ctx); 1.12 - int rc = 1; 1.13 - uint32_t memorykb = 0, videoram = 0; 1.14 - char *memmax, *endptr, *videoram_s = NULL; 1.15 + int rc = 1, abort = 0; 1.16 + uint32_t videoram = 0; 1.17 + char *videoram_s = NULL; 1.18 char *dompath = libxl__xs_get_dompath(&gc, domid); 1.19 xc_domaininfo_t info; 1.20 libxl_dominfo ptr; 1.21 char *uuid; 1.22 - 1.23 - if (domid) { 1.24 - memmax = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/memory/static-max", dompath)); 1.25 - if (!memmax) { 1.26 + xs_transaction_t t; 1.27 + 1.28 +retry_transaction: 1.29 + t = xs_transaction_start(ctx->xsh); 1.30 + 1.31 + videoram_s = libxl__xs_read(&gc, t, libxl__sprintf(&gc, "%s/memory/videoram", 1.32 + dompath)); 1.33 + videoram = videoram_s ? atoi(videoram_s) : 0; 1.34 + 1.35 + if (enforce) { 1.36 + rc = xc_domain_setmaxmem(ctx->xch, domid, target_memkb + 1.37 + LIBXL_MAXMEM_CONSTANT); 1.38 + if (rc != 0) { 1.39 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 1.40 - "cannot get memory info from %s/memory/static-max\n", dompath); 1.41 - goto out; 1.42 - } 1.43 - memorykb = strtoul(memmax, &endptr, 10); 1.44 - if (*endptr != '\0') { 1.45 - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 1.46 - "invalid max memory %s from %s/memory/static-max\n", memmax, dompath); 1.47 - goto out; 1.48 - } 1.49 - 1.50 - if (target_memkb > memorykb) { 1.51 - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, 1.52 - "memory_dynamic_max must be less than or equal to memory_static_max\n"); 1.53 + "xc_domain_setmaxmem domid=%d memkb=%d failed " 1.54 + "rc=%d\n", domid, target_memkb + LIBXL_MAXMEM_CONSTANT, rc); 1.55 + abort = 1; 1.56 goto out; 1.57 } 1.58 } 1.59 1.60 - videoram_s = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/memory/videoram", dompath)); 1.61 - videoram = videoram_s ? atoi(videoram_s) : 0; 1.62 - 1.63 - libxl__xs_write(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/memory/target", dompath), "%"PRIu32, target_memkb); 1.64 - 1.65 + rc = xc_domain_memory_set_pod_target(ctx->xch, domid, (target_memkb - 1.66 + videoram) / 4, NULL, NULL, NULL); 1.67 + if (rc != 0) { 1.68 + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, 1.69 + "xc_domain_memory_set_pod_target domid=%d, memkb=%d " 1.70 + "failed rc=%d\n", domid, (target_memkb - videoram) / 4, 1.71 + rc); 1.72 + abort = 1; 1.73 + goto out; 1.74 + } 1.75 + 1.76 + libxl__xs_write(&gc, t, libxl__sprintf(&gc, "%s/memory/target", dompath), 1.77 + "%"PRIu32, target_memkb); 1.78 rc = xc_domain_getinfolist(ctx->xch, domid, 1, &info); 1.79 - if (rc != 1 || info.domain != domid) 1.80 + if (rc != 1 || info.domain != domid) { 1.81 + abort = 1; 1.82 goto out; 1.83 + } 1.84 xcinfo2xlinfo(&info, &ptr); 1.85 uuid = libxl__uuid2string(&gc, ptr.uuid); 1.86 - libxl__xs_write(&gc, XBT_NULL, libxl__sprintf(&gc, "/vm/%s/memory", uuid), "%"PRIu32, target_memkb / 1024); 1.87 - 1.88 - if (enforce || !domid) 1.89 - memorykb = target_memkb; 1.90 - rc = xc_domain_setmaxmem(ctx->xch, domid, memorykb + LIBXL_MAXMEM_CONSTANT); 1.91 - if (rc != 0) 1.92 - goto out; 1.93 - rc = xc_domain_memory_set_pod_target(ctx->xch, domid, (target_memkb - videoram) / 4, NULL, NULL, NULL); 1.94 + libxl__xs_write(&gc, t, libxl__sprintf(&gc, "/vm/%s/memory", uuid), "%"PRIu32, 1.95 + target_memkb / 1024); 1.96 1.97 out: 1.98 + if (!xs_transaction_end(ctx->xsh, t, abort) && !abort) 1.99 + if (errno == EAGAIN) 1.100 + goto retry_transaction; 1.101 + 1.102 libxl__free_all(&gc); 1.103 return rc; 1.104 }