Never remove job queue lock in node daemon
authorMichael Hanselmann <hansmi@google.com>
Tue, 9 Sep 2008 12:47:16 +0000 (12:47 +0000)
committerMichael Hanselmann <hansmi@google.com>
Tue, 9 Sep 2008 12:47:16 +0000 (12:47 +0000)
Otherwise, corruption could occur in some corner cases. E.g. when
LeaveNode is running in a child and is in the process of removing
queue files, the main process gets killed, started again and gets
a request to update the queue. This is rather extreme corner case,
but we should opt for safety.

Reviewed-by: iustinp

lib/backend.py

index ca86245..cb8de54 100644 (file)
@@ -69,16 +69,11 @@ def _CleanDirectory(path, exclude=[]):
       utils.RemoveFile(full_name)
 
 
-def _JobQueuePurge(keep_lock):
+def JobQueuePurge():
   """Removes job queue files and archived jobs
 
   """
-  if keep_lock:
-    exclude = [constants.JOB_QUEUE_LOCK_FILE]
-  else:
-    exclude = []
-
-  _CleanDirectory(constants.QUEUE_DIR, exclude=exclude)
+  _CleanDirectory(constants.QUEUE_DIR, exclude=[constants.JOB_QUEUE_LOCK_FILE])
   _CleanDirectory(constants.JOB_QUEUE_ARCHIVE_DIR)
 
 
@@ -211,9 +206,7 @@ def LeaveCluster():
 
   """
   _CleanDirectory(constants.DATA_DIR)
-
-  # The lock can be removed because we're going to quit anyway.
-  _JobQueuePurge(keep_lock=False)
+  JobQueuePurge()
 
   try:
     priv_key, pub_key, auth_keys = ssh.GetUserFiles(constants.GANETI_RUNAS)
@@ -1717,15 +1710,6 @@ def JobQueueUpdate(file_name, content):
   return True
 
 
-def JobQueuePurge():
-  """Removes job queue files and archived jobs
-
-  """
-  # The lock must not be removed, otherwise another process could create
-  # it again.
-  return _JobQueuePurge(keep_lock=True)
-
-
 def JobQueueRename(old, new):
   """Renames a job queue file.