diff --git a/node-daemon/pvcd/fencing.py b/node-daemon/pvcd/fencing.py index 27483493..32996335 100644 --- a/node-daemon/pvcd/fencing.py +++ b/node-daemon/pvcd/fencing.py @@ -80,9 +80,28 @@ def migrateFromFencedNode(zk_conn, node_name, logger): target_node = findTargetHypervisor(zk_conn, 'mem', dom_uuid) logger.out('Flushing RBD locks for VM "{}"'.format(dom_uuid), state='i') - # TO BE IMPLEMENTED once RBD pools are integrated properly + # Get the list of RBD images + rbd_list = zkhandler.readdata(zk_conn, '/domains/{}/rbdlist'.format(dom_uuid)).split(',') + for rbd in rbd_list: + # Check if a lock exists + retcode, stdout, stderr = common.run_os_command('rbd lock list --format json {}'.format(rbd)) + if not retcode: + logger.out('Failed to obtain lock list for volume "{}"'.format(rbd), state='e') + continue + lock_list = stdout + # If there's at least one lock + if lock_list: + # Loop through the locks + for lock, detail in lock_list.items(): + # Free the lock + retcode, stdout, stderr = common.run_os_command('rbd lock remove {} "{}" "{}"'.format(rbd, lock, detail['locker'])) + if not retcode: + logger.out('Failed to free RBD lock "{}" on volume "{}"'.format(lock, rbd), state='e') + continue + logger.out('Freed RBD lock "{}" on volume "{}"'.format(lock, rbd), state='o') + - logger.out('Moving VM "{}" to node "{}"'.format(dom_uuid, target_node), state='i') + logger.out('Migrating VM "{}" to node "{}"'.format(dom_uuid, target_node), state='i') zkhandler.writedata(zk_conn, { '/domains/{}/state'.format(dom_uuid): 'start', '/domains/{}/node'.format(dom_uuid): target_node,