From tashi-commits-return-231-apmail-incubator-tashi-commits-archive=incubator.apache.org@incubator.apache.org Tue May 17 22:22:29 2011 Return-Path: X-Original-To: apmail-incubator-tashi-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-tashi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 062D84B62 for ; Tue, 17 May 2011 22:22:29 +0000 (UTC) Received: (qmail 91698 invoked by uid 500); 17 May 2011 22:22:29 -0000 Delivered-To: apmail-incubator-tashi-commits-archive@incubator.apache.org Received: (qmail 91659 invoked by uid 500); 17 May 2011 22:22:28 -0000 Mailing-List: contact tashi-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: tashi-dev@incubator.apache.org Delivered-To: mailing list tashi-commits@incubator.apache.org Received: (qmail 91631 invoked by uid 99); 17 May 2011 22:22:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 May 2011 22:22:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FRT_STOCK2 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 May 2011 22:22:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C08E82388A29; Tue, 17 May 2011 22:22:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1104602 - /incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py Date: Tue, 17 May 2011 22:22:07 -0000 To: tashi-commits@incubator.apache.org From: stroucki@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110517222207.C08E82388A29@eris.apache.org> Author: stroucki Date: Tue May 17 22:22:07 2011 New Revision: 1104602 URL: http://svn.apache.org/viewvc?rev=1104602&view=rev Log: qemu.py: Clean up scratch space in separate thread to allow quicker creation times, especially when creating many VMs Modified: incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py Modified: incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py?rev=1104602&r1=1104601&r2=1104602&view=diff ============================================================================== --- incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py (original) +++ incubator/tashi/trunk/src/tashi/nodemanager/vmcontrol/qemu.py Tue May 17 22:22:07 2011 @@ -121,6 +121,10 @@ class Qemu(VmControlInterface): class anonClass: def __init__(self, **attrs): self.__dict__.update(attrs) + + def __cleanScratchSpace(self, file): + time.sleep(5) + os.unlink(file) def getSystemPids(self): """Utility function to get a list of system PIDs that match the QEMU_BIN specified (/proc/nnn/exe)""" @@ -366,6 +370,7 @@ class Qemu(VmControlInterface): # scratch disk (should be integrated better) scratchSize = instance.hints.get("scratchSpace", "0") scratchSize = int(scratchSize) + scratch_file = None try: if scratchSize > 0: @@ -375,13 +380,9 @@ class Qemu(VmControlInterface): scratch_file = os.path.join(self.scratchDir, instance.name + ".scratch") print 'scratch file name is ', scratch_file tempfd = open(scratch_file, "w") - print 'opened' tempfd.seek( (scratchSize * 2 ** 30) - 1 ) - print 'seeked' tempfd.write('x') - print 'written' tempfd.close() - print 'closed' index += 1 thisDiskList = [ "file=%s" % scratch_file ] @@ -457,10 +458,10 @@ class Qemu(VmControlInterface): log.info("Adding vmId %d" % (child.pid)) # clean up scratch file - if scratchSize > 0: - scratch_file = os.path.join(self.scratchDir, instance.name + ".scratch") - time.sleep(5) - os.unlink(scratch_file) + if scratchSize > 0 and scratch_file is not None: + # do this in the background + threading.Thread(target=self.__cleanScratchSpace,args=[scratch_file]).start() + return (child.pid, cmd)