qmemman: update for py3k
This just make the code compatible with py3k, but nothing more. Converting to asyncio is probably the next step.
This commit is contained in:
parent
2c3e112951
commit
33416f2549
@ -26,6 +26,7 @@ import os
|
|||||||
import string
|
import string
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import functools
|
||||||
import xen.lowlevel.xc
|
import xen.lowlevel.xc
|
||||||
import xen.lowlevel.xs
|
import xen.lowlevel.xs
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ class SystemState(object):
|
|||||||
# at any time
|
# at any time
|
||||||
# assumption: self.refresh_memactual was called before
|
# assumption: self.refresh_memactual was called before
|
||||||
# (so domdict[id].memory_actual is up to date)
|
# (so domdict[id].memory_actual is up to date)
|
||||||
assigned_but_unused = reduce(
|
assigned_but_unused = functools.reduce(
|
||||||
lambda acc, dom: acc + max(0, dom.last_target-dom.memory_current),
|
lambda acc, dom: acc + max(0, dom.last_target-dom.memory_current),
|
||||||
self.domdict.values(),
|
self.domdict.values(),
|
||||||
0
|
0
|
||||||
@ -113,7 +114,7 @@ class SystemState(object):
|
|||||||
def refresh_memactual(self):
|
def refresh_memactual(self):
|
||||||
for domain in self.xc.domain_getinfo():
|
for domain in self.xc.domain_getinfo():
|
||||||
id = str(domain['domid'])
|
id = str(domain['domid'])
|
||||||
if self.domdict.has_key(id):
|
if id in self.domdict:
|
||||||
# real memory usage
|
# real memory usage
|
||||||
self.domdict[id].memory_current = domain['mem_kb']*1024
|
self.domdict[id].memory_current = domain['mem_kb']*1024
|
||||||
# what VM is using or can use
|
# what VM is using or can use
|
||||||
|
@ -32,9 +32,9 @@ class QMemmanClient:
|
|||||||
fcntl.fcntl(self.sock.fileno(), fcntl.F_SETFD, flags)
|
fcntl.fcntl(self.sock.fileno(), fcntl.F_SETFD, flags)
|
||||||
|
|
||||||
self.sock.connect("/var/run/qubes/qmemman.sock")
|
self.sock.connect("/var/run/qubes/qmemman.sock")
|
||||||
self.sock.send(str(amount)+"\n")
|
self.sock.send(str(int(amount)).encode('ascii')+b"\n")
|
||||||
self.received = self.sock.recv(1024).strip()
|
received = self.sock.recv(1024).strip()
|
||||||
if self.received == 'OK':
|
if received == b'OK':
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
@ -20,14 +20,14 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
import ConfigParser
|
import configparser
|
||||||
import SocketServer
|
import socketserver
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import thread
|
import threading
|
||||||
|
|
||||||
import xen.lowlevel.xs
|
import xen.lowlevel.xs
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ SOCK_PATH = '/var/run/qubes/qmemman.sock'
|
|||||||
LOG_PATH = '/var/log/qubes/qmemman.log'
|
LOG_PATH = '/var/log/qubes/qmemman.log'
|
||||||
|
|
||||||
system_state = qubes.qmemman.SystemState()
|
system_state = qubes.qmemman.SystemState()
|
||||||
global_lock = thread.allocate_lock()
|
global_lock = threading.Lock()
|
||||||
# If XS_Watcher will
|
# If XS_Watcher will
|
||||||
# handle meminfo event before @introduceDomain, it will use
|
# handle meminfo event before @introduceDomain, it will use
|
||||||
# incomplete domain list for that and may redistribute memory
|
# incomplete domain list for that and may redistribute memory
|
||||||
@ -161,7 +161,7 @@ class XS_Watcher(object):
|
|||||||
token.fn(self, token.param)
|
token.fn(self, token.param)
|
||||||
|
|
||||||
|
|
||||||
class QMemmanReqHandler(SocketServer.BaseRequestHandler):
|
class QMemmanReqHandler(socketserver.BaseRequestHandler):
|
||||||
"""
|
"""
|
||||||
The RequestHandler class for our server.
|
The RequestHandler class for our server.
|
||||||
|
|
||||||
@ -196,10 +196,10 @@ class QMemmanReqHandler(SocketServer.BaseRequestHandler):
|
|||||||
self.log.debug('global_lock acquired')
|
self.log.debug('global_lock acquired')
|
||||||
|
|
||||||
got_lock = True
|
got_lock = True
|
||||||
if system_state.do_balloon(int(self.data)):
|
if system_state.do_balloon(int(self.data.decode('ascii'))):
|
||||||
resp = "OK\n"
|
resp = b"OK\n"
|
||||||
else:
|
else:
|
||||||
resp = "FAIL\n"
|
resp = b"FAIL\n"
|
||||||
self.log.debug('resp={!r}'.format(resp))
|
self.log.debug('resp={!r}'.format(resp))
|
||||||
self.request.send(resp)
|
self.request.send(resp)
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
@ -253,7 +253,7 @@ def main():
|
|||||||
|
|
||||||
log = logging.getLogger('qmemman.daemon')
|
log = logging.getLogger('qmemman.daemon')
|
||||||
|
|
||||||
config = ConfigParser.SafeConfigParser({
|
config = configparser.SafeConfigParser({
|
||||||
'vm-min-mem': str(qubes.qmemman.algo.MIN_PREFMEM),
|
'vm-min-mem': str(qubes.qmemman.algo.MIN_PREFMEM),
|
||||||
'dom0-mem-boost': str(qubes.qmemman.algo.DOM0_MEM_BOOST),
|
'dom0-mem-boost': str(qubes.qmemman.algo.DOM0_MEM_BOOST),
|
||||||
'cache-margin-factor': str(qubes.qmemman.algo.CACHE_FACTOR)
|
'cache-margin-factor': str(qubes.qmemman.algo.CACHE_FACTOR)
|
||||||
@ -280,7 +280,7 @@ def main():
|
|||||||
|
|
||||||
log.debug('instantiating server')
|
log.debug('instantiating server')
|
||||||
os.umask(0)
|
os.umask(0)
|
||||||
server = SocketServer.UnixStreamServer(SOCK_PATH, QMemmanReqHandler)
|
server = socketserver.UnixStreamServer(SOCK_PATH, QMemmanReqHandler)
|
||||||
os.umask(0o077)
|
os.umask(0o077)
|
||||||
|
|
||||||
# notify systemd
|
# notify systemd
|
||||||
@ -294,5 +294,5 @@ def main():
|
|||||||
s.sendall("READY=1")
|
s.sendall("READY=1")
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
thread.start_new_thread(server.serve_forever, ())
|
threading.Thread(target=server.serve_forever).start()
|
||||||
XS_Watcher().watch_loop()
|
XS_Watcher().watch_loop()
|
||||||
|
Loading…
Reference in New Issue
Block a user