From: Stefan Berger Subject: [PATCH] [Xend] [ACM] Serialize the execution of external scripts Date: Thu, 13 Dec 2007 09:58:05 -0500 Message-ID: <1197557885.22411.2.camel@941e-2.watson.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-EGp0IZaqGIhKGXM2A+Tb" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel List-Id: xen-devel@lists.xenproject.org --=-EGp0IZaqGIhKGXM2A+Tb Content-Type: text/plain Content-Transfer-Encoding: 7bit Instead of starting a thread per script, run a single thread and send orders to it. This serializes the execution of the scripts. Signed-off-by: Stefan Berger --=-EGp0IZaqGIhKGXM2A+Tb Content-Disposition: attachment; filename=resource_label_script_serialize.diff Content-Type: text/x-vhdl; name=resource_label_script_serialize.diff; charset=UTF-8 Content-Transfer-Encoding: 7bit --- xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py | 24 +++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) Index: root/xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py =================================================================== --- root.orig/xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py +++ root/xen-unstable.hg/tools/python/xen/util/xsm/acm/acm.py @@ -1545,21 +1545,44 @@ def get_security_label(self, xspol=None) label = self.info.get('security_label', label) return label + +__cond = threading.Condition() +__script_runner = None +__orders = [] + def run_resource_label_change_script(resource, label, command): - def __run_resource_label_change_script(label, command): + global __cond, __orders, __script_runner + + def __run_resource_label_change_script(): + global __cond, __orders script = XendOptions.instance().get_resource_label_change_script() if script: - parms = { - 'resource' : resource, - 'label' : label, - 'command' : command, - } - log.info("Running resource label change script %s: %s" % - (script, parms)) - parms.update(os.environ) - os.spawnve(os.P_WAIT, script[0], script, parms) + parms = {} + while True: + __cond.acquire() + if len(__orders) == 0: + __cond.wait() + + parms['label'], \ + parms['command'], \ + parms['resource'] = __orders[0] + + __orders = __orders[1:] + __cond.release() + + log.info("Running resource label change script %s: %s" % + (script, parms)) + parms.update(os.environ) + os.spawnve(os.P_WAIT, script[0], script, parms) else: log.info("No script given for relabeling of resources.") - thread = threading.Thread(target=__run_resource_label_change_script, - args=(label,command)) - thread.start() + if not __script_runner: + __script_runner = \ + threading.Thread(target=__run_resource_label_change_script, + args=()) + __script_runner.start() + + __cond.acquire() + __orders.append((label,command,resource)) + __cond.notify() + __cond.release() --=-EGp0IZaqGIhKGXM2A+Tb Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=-EGp0IZaqGIhKGXM2A+Tb--