From 5d2031d99e462c44ab513a3bb0b367185eb670df Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Thu, 4 Jun 2020 10:26:47 -0400 Subject: [PATCH] Prevent a VM migrating to the same node Prevents a rare edge case where a node can end up "migrating" to itself. Quick hack to fix this, though like most of the VM management should probably be rethought/rewritten later. Fixes #92 --- node-daemon/pvcnoded/VMInstance.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/node-daemon/pvcnoded/VMInstance.py b/node-daemon/pvcnoded/VMInstance.py index 11c47977..e5758220 100644 --- a/node-daemon/pvcnoded/VMInstance.py +++ b/node-daemon/pvcnoded/VMInstance.py @@ -108,6 +108,7 @@ class VMInstance(object): self.domname = zkhandler.readdata(zk_conn, '/domains/{}'.format(domuuid)) self.state = zkhandler.readdata(self.zk_conn, '/domains/{}/state'.format(self.domuuid)) self.node = zkhandler.readdata(self.zk_conn, '/domains/{}/node'.format(self.domuuid)) + self.lastnode = zkhandler.readdata(self.zkconn, '/domains/{}/lastnode'.format(self.domuuid)) try: self.pinpolicy = zkhandler.readdata(self.zk_conn, '/domains/{}/pinpolicy'.format(self.domuuid)) except: @@ -147,6 +148,9 @@ class VMInstance(object): def getnode(self): return self.node + def getlastnode(self): + return self.lastnode + def getdom(self): return self.dom @@ -368,6 +372,11 @@ class VMInstance(object): # Migrate the VM to a target host def migrate_vm(self): + # Don't try to migrate a node to itself, set back to start + if self.node == self.lastnode: + zkhandler.writedata(self.zk_conn, { '/domains/{}/state'.format(self.domuuid): 'start' }) + return + self.inmigrate = True self.logger.out('Migrating VM to node "{}"'.format(self.node), state='i', prefix='Domain {}:'.format(self.domuuid)) @@ -469,6 +478,7 @@ class VMInstance(object): # Update the current values from zookeeper self.state = zkhandler.readdata(self.zk_conn, '/domains/{}/state'.format(self.domuuid)) self.node = zkhandler.readdata(self.zk_conn, '/domains/{}/node'.format(self.domuuid)) + self.lastnode = zkhandler.readdata(self.zk_conn, '/domains/{}/lastnode'.format(self.domuuid)) # Check the current state of the VM try: