From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gianni Tedesco Subject: [PATCH]: xl: Check a domain exists before destroying it Date: Mon, 24 Jan 2011 17:43:51 +0000 Message-ID: <1295891031.28333.25.camel@qabil.uk.xensource.com> References: <1295888759.28333.14.camel@qabil.uk.xensource.com> <201101241827.46797.Christoph.Egger@amd.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <201101241827.46797.Christoph.Egger@amd.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Christoph Egger Cc: Ian, "xen-devel@lists.xensource.com" , Jackson , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org On Mon, 2011-01-24 at 17:27 +0000, Christoph Egger wrote: > > > 7. Too many error information showed when destroy an inexistent guest > > > (Community) http://bugzilla.xensource.com/bugzilla/show_bug.cgi?id=1714 > > > > A three line fix? > > Already posted to this list: > http://lists.xensource.com/archives/html/xen-devel/2011-01/msg01452.html This is quite a clever fix but I think Ian Jacksons comments are correct. We should do a libxl_domain_info() and bail early in the destroy path if that fails. --- xl: Check a domain exists before destroying it Also fix a mis-formatted error message in xl destroy command. Signed-off-by: Gianni Tedesco diff -r b59f04eb8978 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Fri Jan 21 18:06:23 2011 +0000 +++ b/tools/libxl/libxl.c Mon Jan 24 17:39:33 2011 +0000 @@ -654,10 +654,21 @@ int libxl_event_get_disk_eject_info(libx int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, int force) { libxl__gc gc = LIBXL_INIT_GC(ctx); + libxl_dominfo dominfo; char *dom_path; char *vm_path; int rc, dm_present; + rc = libxl_domain_info(ctx, &dominfo, domid); + switch(rc) { + case 0: + break; + case ERROR_INVAL: + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "non-existant domain %d", domid); + default: + return rc; + } + if (libxl__domain_is_hvm(ctx, domid)) { dm_present = 1; } else { diff -r b59f04eb8978 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Fri Jan 21 18:06:23 2011 +0000 +++ b/tools/libxl/xl_cmdimpl.c Mon Jan 24 17:39:33 2011 +0000 @@ -2176,7 +2176,7 @@ static void destroy_domain(const char *p exit(-1); } rc = libxl_domain_destroy(&ctx, domid, 0); - if (rc) { fprintf(stderr,"destroy failed (rc=%d)\n.",rc); exit(-1); } + if (rc) { fprintf(stderr,"destroy failed (rc=%d).\n",rc); exit(-1); } } static void shutdown_domain(const char *p, int wait)