ia64/xen-unstable

changeset 19336:1e9342bc6d6e

Domain core-dumping fixes

The code was attempting to use the domain's current number of pages
(info.nr_pages) as a maximum index. We then walk the memory map and
can easily over-write past the end of the nr_pages-sized array, if the
domain has more pages mapped in than earlier (live dump). Restrict
ourselves to the current number of pages.

Also fix the dump core method in xend to actually implement the crash
and live options. In particular this means that xend clients other
than xm now get non-live dumps by default.

Signed-off-by: John Levon <john.levon@sun.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 12 11:09:57 2009 +0000 (2009-03-12)
parents b3b6aee082d6
children fd1bbce5d533
files tools/libxc/xc_core.c tools/libxc/xenctrl.h tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/libxc/xc_core.c	Thu Mar 12 11:08:45 2009 +0000
     1.2 +++ b/tools/libxc/xc_core.c	Thu Mar 12 11:09:57 2009 +0000
     1.3 @@ -518,7 +518,17 @@ xc_domain_dumpcore_via_callback(int xc_h
     1.4      if ( sts != 0 )
     1.5          goto out;
     1.6  
     1.7 +    /*
     1.8 +     * Note: this is the *current* number of pages and may change under
     1.9 +     * a live dump-core.  We'll just take this value, and if more pages
    1.10 +     * exist, we'll skip them.  If there's less, then we'll just not use
    1.11 +     * all the array...
    1.12 +     *
    1.13 +     * We don't want to use the total potential size of the memory map
    1.14 +     * since that is usually much higher than info.nr_pages.
    1.15 +     */
    1.16      nr_pages = info.nr_pages;
    1.17 +
    1.18      if ( !auto_translated_physmap )
    1.19      {
    1.20          /* obtain p2m table */
     2.1 --- a/tools/libxc/xenctrl.h	Thu Mar 12 11:08:45 2009 +0000
     2.2 +++ b/tools/libxc/xenctrl.h	Thu Mar 12 11:09:57 2009 +0000
     2.3 @@ -158,7 +158,7 @@ typedef struct xc_dominfo {
     2.4                    paused:1, blocked:1, running:1,
     2.5                    hvm:1, debugged:1;
     2.6      unsigned int  shutdown_reason; /* only meaningful if shutdown==1 */
     2.7 -    unsigned long nr_pages;
     2.8 +    unsigned long nr_pages; /* current number, not maximum */
     2.9      unsigned long shared_info_frame;
    2.10      uint64_t      cpu_time;
    2.11      unsigned long max_memkb;
     3.1 --- a/tools/python/xen/xend/XendDomain.py	Thu Mar 12 11:08:45 2009 +0000
     3.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu Mar 12 11:09:57 2009 +0000
     3.3 @@ -1237,13 +1237,23 @@ class XendDomain:
     3.4                               POWER_STATE_NAMES[DOM_STATE_PAUSED],
     3.5                               POWER_STATE_NAMES[dominfo._stateGet()])
     3.6  
     3.7 +        dopause = (not live and dominfo._stateGet() == DOM_STATE_RUNNING)
     3.8 +        if dopause:
     3.9 +            dominfo.pause()
    3.10 +
    3.11          try:
    3.12 -            log.info("Domain core dump requested for domain %s (%d) "
    3.13 -                     "live=%d crash=%d.",
    3.14 -                     dominfo.getName(), dominfo.getDomid(), live, crash)
    3.15 -            return dominfo.dumpCore(filename)
    3.16 -        except Exception, ex:
    3.17 -            raise XendError(str(ex))
    3.18 +            try:
    3.19 +                log.info("Domain core dump requested for domain %s (%d) "
    3.20 +                         "live=%d crash=%d.",
    3.21 +                         dominfo.getName(), dominfo.getDomid(), live, crash)
    3.22 +                dominfo.dumpCore(filename)
    3.23 +                if crash:
    3.24 +                    self.domain_destroy(domid)
    3.25 +            except Exception, ex:
    3.26 +                raise XendError(str(ex))
    3.27 +        finally:
    3.28 +            if dopause and not crash:
    3.29 +                dominfo.unpause()
    3.30  
    3.31      def domain_destroy(self, domid):
    3.32          """Terminate domain immediately.
     4.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 12 11:08:45 2009 +0000
     4.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 12 11:09:57 2009 +0000
     4.3 @@ -2027,26 +2027,31 @@ class XendDomainInfo:
     4.4          @raise: XendError if core dumping failed.
     4.5          """
     4.6          
     4.7 -        try:
     4.8 -            if not corefile:
     4.9 -                this_time = time.strftime("%Y-%m%d-%H%M.%S", time.localtime())
    4.10 -                corefile = "/var/xen/dump/%s-%s.%s.core" % (this_time,
    4.11 -                                  self.info['name_label'], self.domid)
    4.12 +        if not corefile:
    4.13 +            this_time = time.strftime("%Y-%m%d-%H%M.%S", time.localtime())
    4.14 +            corefile = "/var/xen/dump/%s-%s.%s.core" % (this_time,
    4.15 +                              self.info['name_label'], self.domid)
    4.16                  
    4.17 -            if os.path.isdir(corefile):
    4.18 -                raise XendError("Cannot dump core in a directory: %s" %
    4.19 -                                corefile)
    4.20 -            
    4.21 -            self._writeVm(DUMPCORE_IN_PROGRESS, 'True')
    4.22 -            xc.domain_dumpcore(self.domid, corefile)
    4.23 +        if os.path.isdir(corefile):
    4.24 +            raise XendError("Cannot dump core in a directory: %s" %
    4.25 +                            corefile)
    4.26 +
    4.27 +        try:
    4.28 +            try:
    4.29 +                self._writeVm(DUMPCORE_IN_PROGRESS, 'True')
    4.30 +                xc.domain_dumpcore(self.domid, corefile)
    4.31 +            except RuntimeError, ex:
    4.32 +                corefile_incomp = corefile+'-incomplete'
    4.33 +                try:
    4.34 +                    os.rename(corefile, corefile_incomp)
    4.35 +                except:
    4.36 +                    pass
    4.37 +
    4.38 +                log.error("core dump failed: id = %s name = %s: %s",
    4.39 +                          self.domid, self.info['name_label'], str(ex))
    4.40 +                raise XendError("Failed to dump core: %s" %  str(ex))
    4.41 +        finally:
    4.42              self._removeVm(DUMPCORE_IN_PROGRESS)
    4.43 -        except RuntimeError, ex:
    4.44 -            corefile_incomp = corefile+'-incomplete'
    4.45 -            os.rename(corefile, corefile_incomp)
    4.46 -            self._removeVm(DUMPCORE_IN_PROGRESS)
    4.47 -            log.exception("XendDomainInfo.dumpCore failed: id = %s name = %s",
    4.48 -                          self.domid, self.info['name_label'])
    4.49 -            raise XendError("Failed to dump core: %s" %  str(ex))
    4.50  
    4.51      #
    4.52      # Device creation/deletion functions
     5.1 --- a/tools/python/xen/xm/main.py	Thu Mar 12 11:08:45 2009 +0000
     5.2 +++ b/tools/python/xen/xm/main.py	Thu Mar 12 11:09:57 2009 +0000
     5.3 @@ -1351,22 +1351,10 @@ def xm_dump_core(args):
     5.4      else:
     5.5          filename = None
     5.6  
     5.7 -    if not live:
     5.8 -        ds = server.xend.domain.pause(dom, True)
     5.9 -
    5.10 -    try:
    5.11 -        print "Dumping core of domain: %s ..." % str(dom)
    5.12 -        server.xend.domain.dump(dom, filename, live, crash)
    5.13 -
    5.14 -        if crash:
    5.15 -            print "Destroying domain: %s ..." % str(dom)
    5.16 -            server.xend.domain.destroy(dom)
    5.17 -        elif reset:
    5.18 -            print "Resetting domain: %s ..." % str(dom)
    5.19 -            server.xend.domain.reset(dom)
    5.20 -    finally:
    5.21 -        if not live and not crash and not reset and ds == DOM_STATE_RUNNING:
    5.22 -            server.xend.domain.unpause(dom)
    5.23 +    print "Dumping core of domain: %s ..." % str(dom)
    5.24 +    server.xend.domain.dump(dom, filename, live, crash)
    5.25 +    if reset:
    5.26 +        server.xend.domain.reset(dom)
    5.27  
    5.28  def xm_rename(args):
    5.29      arg_check(args, "rename", 2)