From 411e8b5323f139e75cbf51783ea62e7308a87350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 14 Jan 2016 04:34:53 +0100 Subject: [PATCH] qmemman: refresh domain list holding global_lock Retrieve a domain list only after obtaining global lock. Otherwise an outdated list may be used, when a domain was introduced in the meantime (starting a new domain is done with global lock held), leading to #1389. QubesOS/qubes-issues#1389 --- qmemman/qmemman_server.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/qmemman/qmemman_server.py b/qmemman/qmemman_server.py index 31aeb587..2af58956 100755 --- a/qmemman/qmemman_server.py +++ b/qmemman/qmemman_server.py @@ -73,36 +73,34 @@ class XS_Watcher: def domain_list_changed(self, param): self.log.debug('domain_list_changed(param={!r})'.format(param)) - curr = self.handle.ls('', '/local/domain') - - if curr == None: - return - - # check if domain is really there, it may happen that some empty - # directories are left in xenstore - curr = filter( - lambda x: - self.handle.read('', - '/local/domain/{}/domid'.format(x) - ) is not None, - curr - ) - - self.log.debug('curr={!r}'.format(curr)) - self.log.debug('acquiring global_lock') global_lock.acquire() self.log.debug('global_lock acquired') try: + curr = self.handle.ls('', '/local/domain') + if curr is None: + return + + # check if domain is really there, it may happen that some empty + # directories are left in xenstore + curr = filter( + lambda x: + self.handle.read('', + '/local/domain/{}/domid'.format(x) + ) is not None, + curr + ) + self.log.debug('curr={!r}'.format(curr)) + for i in only_in_first_list(curr, self.watch_token_dict.keys()): - #new domain has been created + # new domain has been created watch = WatchType(XS_Watcher.meminfo_changed, i) self.watch_token_dict[i] = watch self.handle.watch(get_domain_meminfo_key(i), watch) system_state.add_domain(i) for i in only_in_first_list(self.watch_token_dict.keys(), curr): - #domain destroyed + # domain destroyed self.handle.unwatch(get_domain_meminfo_key(i), self.watch_token_dict[i]) self.watch_token_dict.pop(i) system_state.del_domain(i)