ia64/xen-unstable
changeset 6240:a06430752462
fail domU creation if memory need couldn't be succeed after ballooning out dom0
Signed-off-by: Vincent Hanquez <vincent@xensource.com>
Signed-off-by: Vincent Hanquez <vincent@xensource.com>
author | vh249@arcadians.cl.cam.ac.uk |
---|---|
date | Thu Aug 18 01:13:49 2005 +0000 (2005-08-18) |
parents | 02789fed726a |
children | 2bab84a5d122 |
files | tools/python/xen/xm/create.py |
line diff
1.1 --- a/tools/python/xen/xm/create.py Wed Aug 17 23:11:56 2005 +0000 1.2 +++ b/tools/python/xen/xm/create.py Thu Aug 18 01:13:49 2005 +0000 1.3 @@ -23,6 +23,7 @@ import string 1.4 import sys 1.5 import socket 1.6 import commands 1.7 +import time 1.8 1.9 import xen.lowlevel.xc 1.10 1.11 @@ -674,18 +675,33 @@ def get_dom0_alloc(): 1.12 return 0 1.13 1.14 def balloon_out(dom0_min_mem, opts): 1.15 - """Balloon out to get memory for domU, if necessarily""" 1.16 + """Balloon out memory from dom0 if necessary""" 1.17 SLACK = 4 1.18 + timeout = 20 # 2s 1.19 + ret = 0 1.20 1.21 xc = xen.lowlevel.xc.new() 1.22 pinfo = xc.physinfo() 1.23 - free_mem = pinfo['free_pages']/256 1.24 - if free_mem < opts.vals.memory + SLACK: 1.25 - need_mem = opts.vals.memory + SLACK - free_mem 1.26 - cur_alloc = get_dom0_alloc() 1.27 - if cur_alloc - need_mem >= dom0_min_mem: 1.28 - server.xend_domain_mem_target_set(0, cur_alloc - need_mem) 1.29 + free_mem = pinfo['free_pages'] / 256 1.30 + domU_need_mem = opts.vals.memory + SLACK 1.31 + 1.32 + dom0_cur_alloc = get_dom0_alloc() 1.33 + dom0_new_alloc = dom0_cur_alloc - (domU_need_mem - free_mem) 1.34 + 1.35 + if free_mem < domU_need_mem and dom0_new_alloc >= dom0_min_mem: 1.36 + 1.37 + server.xend_domain_mem_target_set(0, dom0_new_alloc) 1.38 + 1.39 + while dom0_cur_alloc > dom0_new_alloc and timeout > 0: 1.40 + time.sleep(0.1) # sleep 100ms 1.41 + dom0_cur_alloc = get_dom0_alloc() 1.42 + timeout -= 1 1.43 + 1.44 + if dom0_cur_alloc > dom0_new_alloc: 1.45 + ret = 1 1.46 + 1.47 del xc 1.48 + return ret 1.49 1.50 def main(argv): 1.51 random.seed() 1.52 @@ -717,7 +733,8 @@ def main(argv): 1.53 else: 1.54 dom0_min_mem = xroot.get_dom0_min_mem() 1.55 if dom0_min_mem != 0: 1.56 - balloon_out(dom0_min_mem, opts) 1.57 + if balloon_out(dom0_min_mem, opts): 1.58 + return 1.59 1.60 dom = make_domain(opts, config) 1.61 if opts.vals.console_autoconnect: