This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.11
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.11 by this push:
     new 425ad49  kvm: fix qemu hook race condition (#3405)
425ad49 is described below

commit 425ad495b1d0675c00b85a34d7a060c145eced57
Author: Rohit Yadav <[email protected]>
AuthorDate: Fri Jun 14 12:55:04 2019 +0530

    kvm: fix qemu hook race condition (#3405)
    
    This fixes the qemu hooks `mkdir` race condition which can happen when
    too many VMs may launch on a KVM host executing the hooks script that
    tries to `mkdir` for the custom directory. On exception (multiple scripts
    trying to mkdir), the VM stops.
    
    The custom directory need not be created if it does not exist, instead
    the custom hooks should only execute when there is a custom directory.
    
    Feature documentation:
    
http://docs.cloudstack.apache.org/en/4.11.2.0/adminguide/hosts.html#kvm-libvirt-hook-script-include
    
    Signed-off-by: Rohit Yadav <[email protected]>
---
 agent/bindir/libvirtqemuhook.in | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/agent/bindir/libvirtqemuhook.in b/agent/bindir/libvirtqemuhook.in
index 598968b..27e0711 100755
--- a/agent/bindir/libvirtqemuhook.in
+++ b/agent/bindir/libvirtqemuhook.in
@@ -78,7 +78,9 @@ def handleMigrateBegin():
 
 
 def executeCustomScripts(sysArgs):
-    createDirectoryIfNotExists(customDir, customDirPermissions)
+    if not os.path.exists(customDir) or not os.path.isdir(customDir):
+        return
+
     scripts = getCustomScriptsFromDirectory()
 
     for scriptName in scripts:
@@ -127,12 +129,6 @@ def getCustomScriptsFromDirectory():
                          os.listdir(customDir)), key=lambda fileName: 
substringAfter(fileName, '_'))
 
 
-def createDirectoryIfNotExists(dir, permissions):
-    if not os.path.exists(dir):
-        logger.info('Directory %s does not exist; creating it.' % dir)
-        os.makedirs(dir, permissions)
-
-
 def substringAfter(s, delimiter):
     return s.partition(delimiter)[2]
 

Reply via email to