From: Ken Hironaka Subject: [PATCH][XEN]xm dump command add on (TAKE 2) Date: Wed, 16 Aug 2006 17:24:40 +0900 Message-ID: <1155716680.4637.21.camel@pingi.sky.yk.fujitsu.co.jp> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-RT2aQxYxYBFIGA0GJDN8" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --=-RT2aQxYxYBFIGA0GJDN8 Content-Type: text/plain Content-Transfer-Encoding: 7bit This is a TAKE 2 to the xm dump-core command to xend. Changes: -the command name is now xm dump-core instead of xm dump -the command takes long options --live, and --crash. -with pause dump, the message that the domain will be paused has been taken out -when an interrupt is received during execution, the command will automatically unpause the domain in question. The below is basically the same info as before. ----------------------------------------------------------------- The command outputs the memory contents of the specified domU to a coredump file. This will fail if tried on dom0. The specification is as follows: xm dump-core [-L|--live][-C| --crash] [output path] -L| --live Live dump:By default, xm dump does an xm pause, unpause before and after taking the dump, respectively. This option disables the pause/unpause and simply takes the dump. -C :| --crash crash dump: This executes an xm destroy after the dump file is complete. The output path is optional, and if it is not specified, the path will be /var/xen/dump/..core This command uses the existant dumpCore(), which has been used for coredump when a domU crashed. In this patch, the xc_domain_dumpcore_via_callback() in xc_core.c of libxc is also modified. Previously, the xc_domain_dumpcore_via_callback() did not respond to error when copy_from_domain_page() failed. In other words, the dump core remained silent even if mapping the domain memory failed and its page could not be copied. When this happened, erroneous data had been dumped to the file without the user realizing it. Now, it has been modified so that if copy_from_domain_page fails, this fact is recorded in the logfile. However even in such cases, the dumping will continue as before. Signed-off-by: Ken Hironaka Reference http://lists.xensource.com/archives/html/xen-devel/2006-08/msg00181.html http://lists.xensource.com/archives/html/xen-devel/2006-08/msg00259.html http://lists.xensource.com/archives/html/xen-devel/2006-08/msg00483.html http://lists.xensource.com/archives/html/xen-devel/2006-08/msg00742.html http://lists.xensource.com/archives/html/xen-devel/2006-08/msg00831.html --=-RT2aQxYxYBFIGA0GJDN8 Content-Disposition: attachment; filename=xmdump.v2.patch Content-Type: text/x-patch; name=xmdump.v2.patch; charset=us-ascii Content-Transfer-Encoding: 7bit diff -r ec03b24a2d83 tools/libxc/xc_core.c --- a/tools/libxc/xc_core.c Tue Aug 15 19:53:55 2006 +0100 +++ b/tools/libxc/xc_core.c Wed Aug 16 16:31:33 2006 +0900 @@ -37,6 +37,7 @@ xc_domain_dumpcore_via_callback(int xc_h char dummy[PAGE_SIZE]; int dummy_len; int sts; + unsigned int cpy_err_cnt = 0; if ( (dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL ) { @@ -103,7 +104,11 @@ xc_domain_dumpcore_via_callback(int xc_h for ( dump_mem = dump_mem_start, i = 0; i < nr_pages; i++ ) { - copy_from_domain_page(xc_handle, domid, page_array[i], dump_mem); + sts = copy_from_domain_page(xc_handle, domid, page_array[i], dump_mem); + + if( sts != 0 ) + cpy_err_cnt++; + dump_mem += PAGE_SIZE; if ( ((i + 1) % DUMP_INCREMENT == 0) || ((i + 1) == nr_pages) ) { @@ -112,6 +117,10 @@ xc_domain_dumpcore_via_callback(int xc_h goto error_out; dump_mem = dump_mem_start; } + } + if( cpy_err_cnt != 0 ){ + IPRINTF("Could not copy from domid=%d (%d)pages\n", domid, cpy_err_cnt); + goto error_out; } free(dump_mem_start); diff -r ec03b24a2d83 tools/python/xen/xend/XendDomain.py --- a/tools/python/xen/xend/XendDomain.py Tue Aug 15 19:53:55 2006 +0100 +++ b/tools/python/xen/xend/XendDomain.py Wed Aug 16 16:31:33 2006 +0900 @@ -390,6 +390,22 @@ class XendDomain: except Exception, ex: raise XendError(str(ex)) + def domain_dump(self, domid, filename): + """Dump domain core.""" + + dominfo = self.domain_lookup_by_name_or_id_nr(domid) + if not dominfo: + raise XendInvalidDomain(str(domid)) + + if dominfo.getDomid() == PRIV_DOMAIN: + raise XendError("Cannot dump core for privileged domain %s" % domid) + + try: + log.info("Domain core dump requested for domain %s (%d).", dominfo.getName(), + dominfo.getDomid()) + return dominfo.dumpCore(filename) + except Exception, ex: + raise XendError(str(ex)) def domain_destroy(self, domid): """Terminate domain immediately.""" diff -r ec03b24a2d83 tools/python/xen/xend/XendDomainInfo.py --- a/tools/python/xen/xend/XendDomainInfo.py Tue Aug 15 19:53:55 2006 +0100 +++ b/tools/python/xen/xend/XendDomainInfo.py Wed Aug 16 16:31:33 2006 +0900 @@ -967,11 +967,12 @@ class XendDomainInfo: self.restart(True) - def dumpCore(self): + def dumpCore(self,corefile=None): """Create a core dump for this domain. Nothrow guarantee.""" try: - corefile = "/var/xen/dump/%s.%s.core" % (self.info['name'], + if not corefile: + corefile = "/var/xen/dump/%s.%s.core" % (self.info['name'], self.domid) xc.domain_dumpcore(self.domid, corefile) diff -r ec03b24a2d83 tools/python/xen/xm/main.py --- a/tools/python/xen/xm/main.py Tue Aug 15 19:53:55 2006 +0100 +++ b/tools/python/xen/xm/main.py Wed Aug 16 16:31:33 2006 +0900 @@ -57,6 +57,9 @@ create_help = """create [-c] [Name=Value].. Create a domain based on Config File""" destroy_help = "destroy Terminate a domain immediately" +dump_core_help = """dump-core [-L|--live][-C|--crash] + [FileName] Dump core of the specified domain""" + help_help = "help Display this message" list_help = "list [--long] [DomId, ...] List information about domains" list_label_help = "list [--label] [DomId, ...] List information about domains including their labels" @@ -140,6 +143,7 @@ short_command_list = [ "console", "create", "destroy", + "dump-core", "help", "list", "mem-set", @@ -161,6 +165,7 @@ domain_commands = [ "destroy", "domid", "domname", + "dump-core", "list", "list_label", "mem-max", @@ -593,6 +598,42 @@ def xm_unpause(args): server.xend.domain.unpause(dom) +def xm_dump_core(args): + arg_check(args, "dump-core",1,3) + live = False + crash = False + import getopt + (options, params) = getopt.gnu_getopt(args, 'LC', ['live','crash']) + + for (k, v) in options: + if k in ['-L', '--live']: + live = True + if k in ['-C', '--crash']: + crash = True + + if len(params) == 0 or len(params) > 2: + err("invalid number of parameters") + usage("dump-core") + + dom = params[0] + if len(params) == 2: + filename = os.path.abspath(params[1]) + else: + filename = None + + if not live: + server.xend.domain.pause(dom) + + try: + print "dumping core of domain:%s ..." % str(dom) + server.xend.domain.dump(dom, filename) + finally: + if not live: + server.xend.domain.unpause(dom) + + if crash: + print "destroying domain:%s ..." % str(dom) + server.xend.domain.destroy(dom) def xm_rename(args): arg_check(args, "rename", 2) @@ -1170,6 +1211,7 @@ commands = { "destroy": xm_destroy, "domid": xm_domid, "domname": xm_domname, + "dump-core": xm_dump_core, "rename": xm_rename, "restore": xm_restore, "save": xm_save, --=-RT2aQxYxYBFIGA0GJDN8 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=-RT2aQxYxYBFIGA0GJDN8--