From 7f828a27a5384e61a3b654ffd837d0726ea9b1f9 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 9 Jul 2019 10:53:46 -0400 Subject: [PATCH] Free RBD locks when fencing node --- node-daemon/pvcd/fencing.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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,