From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Michal Novotny <minovotn@redhat.com>
Cc: xen-devel@lists.xensource.com
Subject: Re: [PATCH] Fix restore handling checks
Date: Tue, 22 Jun 2010 10:10:39 -0400 [thread overview]
Message-ID: <20100622141039.GA4552@phenom.dumpdata.com> (raw)
In-Reply-To: <4C20B2F8.4030409@redhat.com>
On Tue, Jun 22, 2010 at 02:56:24PM +0200, Michal Novotny wrote:
> On 06/22/2010 08:17 AM, Michal Novotny wrote:
> >On 06/22/2010 08:14 AM, Keir Fraser wrote:
> >>Okay, hopefully someone will be able to Ack this patch with
> >>better knwoledge
> >>of xend than me.
> >>
> >> -- Keir
> >>
> >Ok, good. If it will be accepted and put into
> >xen-staging/xen-unstable tree please let me know about it.
> >
> >Thanks,
> >Michal
> >
>
> Well, this is new version of the patch since I've tried now to both
> migrate from RHEL-5 host (python-2.4) to RHEL-6 host (python-2.6)
> using the RHEL-5 host as a source machine for migrations and also
> RHEL-6 host to restore the the guest locally using `xm restore` to
> see whether the guest memory calculated correctly and it did pass
> when there was enough memory to create the guest and failed when
> there was not enough memory to create the guest. Also, some fixing
> for comparing the values was necessary since it was treated as
> string comparison on one of the hosts.
>
> Both the host machines were having the latest Xen-4.1 installed.
>
> Michal
>
> Signed-off-by: Michal Novotny <minovotn@redhat.com>
>
> --
> Michal Novotny<minovotn@redhat.com>, RHCE
> Virtualization Team (xen userspace), Red Hat
>
> diff -r a24dbfcbdf69 tools/python/xen/xend/XendCheckpoint.py
> --- a/tools/python/xen/xend/XendCheckpoint.py Tue Jun 22 07:19:38 2010 +0100
> +++ b/tools/python/xen/xend/XendCheckpoint.py Tue Jun 22 12:52:56 2010 +0200
> @@ -64,6 +64,78 @@ def insert_after(list, pred, value):
> list.insert (i+1, value)
> return
>
> +def get_avail_memory():
> + """Get available memory for new guest creation (in KiB, for restore)"""
> + from xen.xend import XendOptions
> +
> + # First get total memory in KiB
> + xc = xen.lowlevel.xc.xc()
> + info = xc.domain_getinfo()
> + total_mem = xc.physinfo()['total_memory']
> + del xc
> +
> + # Count memory of all running guests in KiB
> + mem_used = 0L
> + for x in info:
> + if x['domid'] != 0:
> + # If blocked & paused & !paused & no online_vcpus we most
> + # probably migrate so we get maxmem instead (since mem_kb
> + # is having currently transferred amount of memory so we
> + # cannot use it for good calculations)
> + if (x['blocked'] == 1 and x['paused'] == 1 and
> + x['running'] == 0 and x['online_vcpus'] == 0):
> + log.debug("Domain %d seems to be restoring" % x['domid'])
> + mem_used += x['maxmem_kb']
> + else:
> + mem_used += x['mem_kb']
> +
> + # Get minimal memory for dom0 and convert to KiB
> + min_mem = XendOptions.instance().get_dom0_min_mem() * 1024
> +
> + return total_mem - mem_used - min_mem
> +
> +def check_for_restore_bail(msg):
> + raise VmError("Cannot restore: %s" % msg)
> +
> +def check_for_enough_mem(val):
> + mem_avail = get_avail_memory() / 1024
> + log.debug("Available memory: %s MiB, guest requires: %s MiB" % (mem_avail, val))
> + return int(mem_avail) > int(val)
> +
> +def check_for_restore_is_hvm(cfg):
> + for item in cfg:
> + if (type(item) == list):
> + if item[0] == 'image':
> + return type(item[1]) == list and item[1][0] == 'hvm'
There is no chance that 'hvm' would be in different case? Say 'HVM' ?
> +
> +def check_for_restore_hvm_have_readonly_ide(cfg):
> + """Check the configuration for read-only IDE devices
> + Fail if such a device is found."""
> + disallow = None
> + if type(cfg) == list and cfg[0] in ('tap', 'vbd'):
> + for p in cfg:
> + if (type(p) != str):
Is that right? should it not == list ?
> + if p[0] == 'dev':
> + disallow = ((p[1].find('hd') >= 0) and
> + (p[1].find('cdrom') == -1))
> + if p[0] == 'mode' and disallow:
> + if p[1] == 'r':
> + return True
> + return False
> +
> +def check_for_restore(cfg):
> + is_hvm = check_for_restore_is_hvm(cfg)
> + name = None
> + for item in cfg:
> + if (type(item) == list):
> + # Check for enough memory to create the guest
> + if item[0] == 'memory':
> + if not check_for_enough_mem(item[1]):
> + check_for_restore_bail('Host machine doesn\'t have enough memory to create the guest')
> + # We disable read-only IDE drives only for HVM guests
> + if item[0] == 'device' and is_hvm:
> + if check_for_restore_hvm_have_readonly_ide(item[1]):
> + check_for_restore_bail('HVM domains cannot be using read-only IDE drives')
>
> def save(fd, dominfo, network, live, dst, checkpoint=False, node=-1):
> from xen.xend import XendDomain
> @@ -220,6 +292,7 @@ def restore(xd, fd, dominfo = None, paus
> othervm = xd.domain_lookup_nr(domconfig["uuid"])
> if othervm is not None and othervm.domid is not None:
> raise VmError("Domain '%s' already exists with ID '%d'" % (domconfig["name_label"], othervm.domid))
> + check_for_restore(vmconfig)
>
> if dominfo:
> dominfo.resume()
> diff -r a24dbfcbdf69 tools/python/xen/xend/XendDomainInfo.py
> --- a/tools/python/xen/xend/XendDomainInfo.py Tue Jun 22 07:19:38 2010 +0100
> +++ b/tools/python/xen/xend/XendDomainInfo.py Tue Jun 22 12:52:56 2010 +0200
> @@ -82,6 +82,32 @@ log = logging.getLogger("xend.XendDomain
> log = logging.getLogger("xend.XendDomainInfo")
> #log.setLevel(logging.TRACE)
>
> +def cfg_is_hvm(cfg):
> + for item in cfg:
> + if (type(item) == list):
> + if item[0] == 'image':
> + return type(item[1]) == list and item[1][0] == 'hvm'
> +
> +def cfg_hvm_have_readonly_ide_disks(cfg):
> + """Check whether the configuration for read-only IDE disks since
> + they are not supported according to IDE specifications."""
> + if not cfg_is_hvm(cfg):
> + return False
> +
> + disallow = None
> + for item in cfg:
> + if (type(item) == list):
> + if item[0] == 'device':
> + if type(item[1]) == list and item[1][0] in ('tap', 'vbd'):
> + for p in item[1]:
> + if (type(p) != str):
> + if p[0] == 'dev':
> + disallow = ((p[1].find('hd') >= 0) and
> + (p[1].find('cdrom') == -1))
> + if p[0] == 'mode' and disallow:
> + if p[1] == 'r':
> + return True
> + return False
>
> def create(config):
> """Creates and start a VM using the supplied configuration.
> @@ -100,6 +126,10 @@ def create(config):
> othervm = XendDomain.instance().domain_lookup_nr(domconfig["uuid"])
> if othervm is not None and othervm.domid is not None:
> raise VmError("Domain '%s' already exists with ID '%d'" % (domconfig["name_label"], othervm.domid))
> +
> + if cfg_hvm_have_readonly_ide_disks(config):
> + raise VmError("HVM domains cannot be using read-only IDE drives")
> +
> log.debug("XendDomainInfo.create(%s)", scrub_password(config))
> vm = XendDomainInfo(domconfig)
> try:
Otherwise looks good to me.
next prev parent reply other threads:[~2010-06-22 14:10 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-21 16:30 [PATCH] Fix restore handling checks Michal Novotny
2010-06-21 18:04 ` Keir Fraser
2010-06-22 5:43 ` Michal Novotny
2010-06-22 6:11 ` Michal Novotny
2010-06-22 6:14 ` Keir Fraser
2010-06-22 6:17 ` Michal Novotny
2010-06-22 12:56 ` Michal Novotny
2010-06-22 14:10 ` Konrad Rzeszutek Wilk [this message]
2010-06-23 11:27 ` Michal Novotny
2010-06-22 20:46 ` Dan Magenheimer
2010-06-23 9:59 ` Michal Novotny
2010-06-23 11:21 ` Michal Novotny
2010-06-23 13:51 ` Dan Magenheimer
2010-06-23 14:14 ` Michal Novotny
2010-06-22 14:56 ` Ian Jackson
2010-06-23 11:19 ` Paolo Bonzini
2010-06-23 11:27 ` Ian Jackson
2010-06-23 11:29 ` Michal Novotny
2010-06-23 11:50 ` Ian Jackson
2010-06-23 11:54 ` Michal Novotny
2010-06-23 12:04 ` Ian Jackson
2010-06-23 12:10 ` Paolo Bonzini
2010-06-23 12:20 ` Michal Novotny
2010-06-23 12:20 ` Michal Novotny
2010-06-23 12:12 ` Michal Novotny
2010-06-23 12:33 ` Alan Cox
2010-06-23 15:12 ` George Dunlap
2010-06-23 16:26 ` Dan Magenheimer
2010-06-23 12:35 ` Alan Cox
2010-06-23 12:37 ` Michal Novotny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100622141039.GA4552@phenom.dumpdata.com \
--to=konrad.wilk@oracle.com \
--cc=minovotn@redhat.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).