WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] if the domain creation fails, destroy the domain

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] if the domain creation fails, destroy the domain
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Thu, 6 May 2010 14:46:32 +0100
Delivery-date: Thu, 06 May 2010 06:45:09 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)
Hi all,
this patch makes sure that if the domain creation fails for any reason,
no zombie domains are left around.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>

---

diff -r ccae861f52f7 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Thu May 06 11:59:55 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Thu May 06 14:44:16 2010 +0100
@@ -937,14 +937,16 @@
     ret = libxl_domain_make(&ctx, &info1, &domid);
     if (ret) {
         fprintf(stderr, "cannot make domain: %d\n", ret);
-        return ERROR_FAIL;
+        ret = ERROR_FAIL;
+        goto error_out;
     }
 
     ret = libxl_userdata_store(&ctx, domid, "xl",
                                     config_data, config_len);
     if (ret) {
         perror("cannot save config file");
-        return ERROR_FAIL;
+        ret = ERROR_FAIL;
+        goto error_out;
     }
 
     if (!restore_file || !need_daemon) {
@@ -959,7 +961,8 @@
 
     if (ret) {
         fprintf(stderr, "cannot (re-)build domain: %d\n", ret);
-        return ERROR_FAIL;
+        ret = ERROR_FAIL;
+        goto error_out;
     }
 
     for (i = 0; i < num_disks; i++) {
@@ -967,7 +970,8 @@
         ret = libxl_device_disk_add(&ctx, domid, &disks[i]);
         if (ret) {
             fprintf(stderr, "cannot add disk %d to domain: %d\n", i, ret);
-            return ERROR_FAIL;
+            ret = ERROR_FAIL;
+            goto error_out;
         }
     }
     for (i = 0; i < num_vifs; i++) {
@@ -975,7 +979,8 @@
         ret = libxl_device_nic_add(&ctx, domid, &vifs[i]);
         if (ret) {
             fprintf(stderr, "cannot add nic %d to domain: %d\n", i, ret);
-            return ERROR_FAIL;
+            ret = ERROR_FAIL;
+            goto error_out;
         }
     }
     if (info1.hvm) {
@@ -1023,13 +1028,15 @@
                 assert(got_child == -1);
                 if (errno != EINTR) {
                     perror("failed to wait for daemonizing child");
-                    return ERROR_FAIL;
+                    ret = ERROR_FAIL;
+                    goto error_out;
                 }
             }
             if (status) {
                 libxl_report_child_exitstatus(&ctx, XL_LOG_ERROR,
                            "daemonizing child", child1, status);
-                return ERROR_FAIL;
+                ret = ERROR_FAIL;
+                goto error_out;
             }
             return domid; /* caller gets success in parent */
         }
@@ -1113,6 +1120,11 @@
 
     close(logfile);
     exit(0);
+
+error_out:
+    if (domid)
+        libxl_domain_destroy(&ctx, domid, 0);
+    return ret;
 }
 
 void help(char *command)

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] if the domain creation fails, destroy the domain, Stefano Stabellini <=