[libvirt] [PATCH 7/8] Perform a handshake during QEMU startup to sync with relabelling

Daniel P. Berrange berrange at redhat.com
Mon Nov 22 18:09:26 UTC 2010


Perform a handshake during QEMU startup to allow file relabelling
to be performed after QEMU has been forked, but before it has
been exec'd. This is to allow the lock manager to acquire locks
against the QEMU pid, before relabelling takes place

* src/qemu/qemu_driver.c: Handshake during QEMU startup
---
 src/qemu/qemu_driver.c |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 0b0b6fe..bf6cd0e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3683,9 +3683,6 @@ static int qemudSecurityHook(void *data) {
     if (virSecurityManagerSetProcessLabel(h->driver->securityManager, h->vm) < 0)
         goto cleanup;
 
-    /* XXX temp hack to let disk labelling complete */
-    sleep(10);
-
     ret = 0;
 
 cleanup:
@@ -4097,28 +4094,36 @@ static int qemudStartVMDaemon(virConnectPtr conn,
     virCommandSetErrorFD(cmd, &logfile);
     virCommandSetPidFile(cmd, pidfile);
     virCommandDaemonize(cmd);
+    virCommandRequireHandshake(cmd);
 
     ret = virCommandRun(cmd, NULL);
-    VIR_WARN("Executing done %s", vm->def->emulator);
     VIR_FREE(pidfile);
 
-    /* XXX this is bollocks. Need a sync point */
-    sleep(5);
+    VIR_WARN0("Waiting for handshake from child");
+    if (virCommandHandshakeWait(cmd) < 0) {
+        ret = -1;
+        goto cleanup;
+    }
+    VIR_WARN0("Got handshake start, doing locks");
 
-    VIR_WARN("Locking %s", vm->def->emulator);
     if (!(lock = virDomainLockForStartup(driver->contentLockManager,
                                          driver->metadataLockManager,
                                          NULL, /* XXX lock state */
                                          vm)))
         goto cleanup;
 
-    VIR_WARN("Labelling %s", vm->def->emulator);
+    VIR_WARN0("Got Locks, doing labelling");
     DEBUG0("Setting domain security labels");
     if (virSecurityManagerSetAllLabel(driver->securityManager,
                                       vm, stdin_path) < 0)
         goto cleanup;
-    VIR_WARN("All done %s", vm->def->emulator);
 
+    VIR_WARN0("Labelling done, completing hanshake to child");
+    if (virCommandHandshakeNotify(cmd) < 0) {
+        ret = -1;
+        goto cleanup;
+    }
+    VIR_WARN0("Handshake complete, child running");
 
     /* wait for qemu process to to show up */
     if (ret == 0) {
-- 
1.7.2.3




More information about the libvir-list mailing list