Skip to contentSkip to conversation

Two stubdom patches

PATCH In review Wei Liu 2 participants 7 messages Jun 1, 2015 – Jun 3, 2015

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

cover Two stubdom patches

I discovered some problems as I played along with my OSSTest stubdom test case. Here are two patches to fix them.

Wei.

Wei Liu (2):
libxl: remove code in stubdom creation failure path and callback
libxl: clean up qemu-save and qemu-resume files

 tools/libxl/libxl.c    |  9 +++++++++
 tools/libxl/libxl_dm.c | 27 ---------------------------
 2 files changed, 9 insertions(+), 27 deletions(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/2 libxl: remove code in stubdom creation failure path and callback

The snippet to destroy stubdom and the callback were added in 1fc3aeb3 ("libxl: use new QEMU xenstore protocol"). The intention was to destroy stubdom when it is not responsive. That approach is problematic because rc is not propagate back to sdss->callback, hence the guest is leaked.

The solution is simple. The destruction of stubdom can be done later in sdss->callback. That code path already does the right thing to destroy both the guest and the stubdom that serves the guest.

---
 tools/libxl/libxl_dm.c | 27 ---------------------------
 1 file changed, 27 deletions(-)
tools/libxl/libxl_dm.c +0 -27
index 3dd7c04..33f9ce6 100644
@@ -1036,9 +1036,6 @@ static void stubdom_pvqemu_cb(libxl__egc *egc,
                               libxl__multidev *aodevs,
                               int rc);
 
-static void spawn_stubdom_pvqemu_destroy_cb(libxl__egc *egc,
-                                            libxl__destroy_domid_state *dis,
-                                            int rc);
 static void stubdom_xswait_cb(libxl__egc *egc, libxl__xswait_state *xswait,
                               int rc, const char *p);
 
@@ -1353,7 +1350,6 @@ static void stubdom_xswait_cb(libxl__egc *egc, libxl__xswait_state *xswait,
 {
     EGC_GC;
     libxl__stub_dm_spawn_state *sdss = CONTAINER_OF(xswait, *sdss, xswait);
-    uint32_t dm_domid = sdss->pvqemu.guest_domid;
 
     if (rc) {
         if (rc == ERROR_TIMEDOUT)
@@ -1367,29 +1363,6 @@ static void stubdom_xswait_cb(libxl__egc *egc, libxl__xswait_state *xswait,
         return;
  out:
     libxl__xswait_stop(gc, xswait);
-    if (rc) {
-        if (dm_domid) {
-            sdss->dis.ao = sdss->dm.spawn.ao;
-            sdss->dis.domid = dm_domid;
-            sdss->dis.callback = spawn_stubdom_pvqemu_destroy_cb;
-            libxl__destroy_domid(egc, &sdss->dis);
-            return;
-        }
-    }
-    sdss->callback(egc, &sdss->dm, rc);
-}
-
-static void spawn_stubdom_pvqemu_destroy_cb(libxl__egc *egc,
-                                            libxl__destroy_domid_state *dis,
-                                            int rc)
-{
-    libxl__stub_dm_spawn_state *sdss = CONTAINER_OF(dis, *sdss, dis);
-    STATE_AO_GC(sdss->dis.ao);
-
-    if (rc)
-        LOG(ERROR, "destruction of domain %u after failed creation failed",
-                   sdss->pvqemu.guest_domid);
-
     sdss->callback(egc, &sdss->dm, rc);
 }
 
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH 1/2] libxl: remove code in stubdom creation failure path and callback

Quoted 10 lines · Wei Liu

The snippet to destroy stubdom and the callback were added in 1fc3aeb3 ("libxl: use new QEMU xenstore protocol"). The intention was to destroy stubdom when it is not responsive. That approach is problematic because rc is not propagate back to sdss->callback, hence the guest is leaked.

The solution is simple. The destruction of stubdom can be done later in sdss->callback. That code path already does the right thing to destroy both the guest and the stubdom that serves the guest.

Acked + applied, thanks,

author
#3 lore raw

PATCH 2/2 libxl: clean up qemu-save and qemu-resume files

In reply to Wei Liu

These files are leaked when using qemu-trad stubdom. They are intermediate files created by libxc. Unfortunately they don't fit well in our userdata scheme. Clean them up after we destroy guest, we're sure they are not useful anymore at that point.

---
 tools/libxl/libxl.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/libxl/libxl.c +9 -0
index 9117b01..ad2290d 100644
@@ -1686,6 +1686,15 @@ static void devices_destroy_cb(libxl__egc *egc,
 
         rc = xc_domain_destroy(ctx->xch, domid);
         if (rc < 0) goto badchild;
+        /* Clean up qemu-save and qemu-resume files. They are
+         * intermediate files created by libxc. Unfortunately they
+         * don't fit in existing userdata scheme very well.
+         */
+        rc = libxl__remove_file(gc, libxl__device_model_savefile(gc, domid));
+        if (rc < 0) goto badchild;
+        rc = libxl__remove_file(gc,
+                 GCSPRINTF(XC_DEVICE_MODEL_RESTORE_FILE".%u", domid));
+        if (rc < 0) goto badchild;
         _exit(0);
 
     badchild:
Signature · 1 line
1.9.1
#4 lore raw

Re: [PATCH 2/2] libxl: clean up qemu-save and qemu-resume files

Quoted 4 lines · Wei Liu

These files are leaked when using qemu-trad stubdom. They are intermediate files created by libxc. Unfortunately they don't fit well in our userdata scheme. Clean them up after we destroy guest, we're sure they are not useful anymore at that point.

Could this be done in the parent process at some point following domain_destroy_domid_cb or domain_destroy_cb perhaps?

I think we don't want to do things in sub processes which don't need to be, just to keep things simpler, and I think the logging is more reliable too.

Quoted 26 lines
---
 tools/libxl/libxl.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/libxl/libxl.c +9 -0
index 9117b01..ad2290d 100644
@@ -1686,6 +1686,15 @@ static void devices_destroy_cb(libxl__egc *egc,
 
         rc = xc_domain_destroy(ctx->xch, domid);
         if (rc < 0) goto badchild;
+        /* Clean up qemu-save and qemu-resume files. They are
+         * intermediate files created by libxc. Unfortunately they
+         * don't fit in existing userdata scheme very well.
+         */
+        rc = libxl__remove_file(gc, libxl__device_model_savefile(gc, domid));
+        if (rc < 0) goto badchild;
+        rc = libxl__remove_file(gc,
+                 GCSPRINTF(XC_DEVICE_MODEL_RESTORE_FILE".%u", domid));
+        if (rc < 0) goto badchild;
         _exit(0);
 
     badchild:
author
#5 lore raw

Re: [PATCH 2/2] libxl: clean up qemu-save and qemu-resume files

Quoted 9 lines · Ian Campbell
Quoted 4 lines · Wei Liu

These files are leaked when using qemu-trad stubdom. They are intermediate files created by libxc. Unfortunately they don't fit well in our userdata scheme. Clean them up after we destroy guest, we're sure they are not useful anymore at that point.

Could this be done in the parent process at some point following domain_destroy_domid_cb or domain_destroy_cb perhaps?

Yes, of course.

Quoted 32 lines

I think we don't want to do things in sub processes which don't need to be, just to keep things simpler, and I think the logging is more reliable too.

Quoted 26 lines
---
 tools/libxl/libxl.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/libxl/libxl.c +9 -0
index 9117b01..ad2290d 100644
@@ -1686,6 +1686,15 @@ static void devices_destroy_cb(libxl__egc *egc,
 
         rc = xc_domain_destroy(ctx->xch, domid);
         if (rc < 0) goto badchild;
+        /* Clean up qemu-save and qemu-resume files. They are
+         * intermediate files created by libxc. Unfortunately they
+         * don't fit in existing userdata scheme very well.
+         */
+        rc = libxl__remove_file(gc, libxl__device_model_savefile(gc, domid));
+        if (rc < 0) goto badchild;
+        rc = libxl__remove_file(gc,
+                 GCSPRINTF(XC_DEVICE_MODEL_RESTORE_FILE".%u", domid));
+        if (rc < 0) goto badchild;
         _exit(0);
 
     badchild:
author
#6 lore raw

Re: [PATCH 2/2] libxl: clean up qemu-save and qemu-resume files

In reply to Ian Campbell
Quoted 9 lines · Ian Campbell
Quoted 4 lines · Wei Liu

These files are leaked when using qemu-trad stubdom. They are intermediate files created by libxc. Unfortunately they don't fit well in our userdata scheme. Clean them up after we destroy guest, we're sure they are not useful anymore at that point.

Could this be done in the parent process at some point following domain_destroy_domid_cb or domain_destroy_cb perhaps?

I just had a look. The deletion of qemu-* files can be moved a few lines up, just after we destroy all userdata files and before forking. No need to defer it in a callback.

Wei.

Quoted 32 lines

I think we don't want to do things in sub processes which don't need to be, just to keep things simpler, and I think the logging is more reliable too.

Quoted 26 lines
---
 tools/libxl/libxl.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/libxl/libxl.c +9 -0
index 9117b01..ad2290d 100644
@@ -1686,6 +1686,15 @@ static void devices_destroy_cb(libxl__egc *egc,
 
         rc = xc_domain_destroy(ctx->xch, domid);
         if (rc < 0) goto badchild;
+        /* Clean up qemu-save and qemu-resume files. They are
+         * intermediate files created by libxc. Unfortunately they
+         * don't fit in existing userdata scheme very well.
+         */
+        rc = libxl__remove_file(gc, libxl__device_model_savefile(gc, domid));
+        if (rc < 0) goto badchild;
+        rc = libxl__remove_file(gc,
+                 GCSPRINTF(XC_DEVICE_MODEL_RESTORE_FILE".%u", domid));
+        if (rc < 0) goto badchild;
         _exit(0);
 
     badchild: