From 43756fc62b97083f36ae2db7bc4aeeb98297ea95 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Wed, 7 Aug 2019 13:38:49 -0400 Subject: [PATCH] Implement lock flush function for clients Uses a similar command pathway as the Ceph commands do, but in a different location (pending move of the Ceph commands to a similar location). --- client-common/vm.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/client-common/vm.py b/client-common/vm.py index 36c81138..42e59e3d 100644 --- a/client-common/vm.py +++ b/client-common/vm.py @@ -120,6 +120,46 @@ def is_migrated(zk_conn, domain): else: return False +def flush_locks(zk_conn, domain): + # Validate that VM exists in cluster + dom_uuid = getDomainUUID(zk_conn, domain) + if not dom_uuid: + common.stopZKConnection(zk_conn) + return False, 'ERROR: Could not find VM "{}" in the cluster!'.format(domain) + + # Verify that the VM is in a stopped state; freeing locks is not safe otherwise + state = zkhandler.readdata(zk_conn, '/domains/{}/state'.format(dom_uuid)) + if state != 'stop': + return False, 'ERROR: VM "{}" is not in stopped state; flushing RBD locks on a running VM is dangerous.'.format(domain) + + # Tell the cluster to create a new OSD for the host + flush_locks_string = 'flush_locks {}'.format(dom_uuid) + zkhandler.writedata(zk_conn, {'/cmd/domains': flush_locks_string}) + # Wait 1/2 second for the cluster to get the message and start working + time.sleep(0.5) + # Acquire a read lock, so we get the return exclusively + lock = zkhandler.readlock(zk_conn, '/cmd/domains') + with lock: + try: + result = zkhandler.readdata(zk_conn, '/cmd/domains').split()[0] + if result == 'success-flush_locks': + message = 'Flushed locks on VM "{}"'.format(domain) + success = True + else: + message = 'ERROR: Failed to flush locks on VM "{}"; check node logs for details.'.format(domain) + success = False + except: + message = 'ERROR: Command ignored by node.' + success = False + + # Acquire a write lock to ensure things go smoothly + lock = zkhandler.writelock(zk_conn, '/cmd/domains') + with lock: + time.sleep(0.5) + zkhandler.writedata(zk_conn, {'/cmd/domains': ''}) + + return success, message + def define_vm(zk_conn, config_data, target_node, selector): # Parse the XML data try: