core: hold the lock after QubesVmCollection.save()
The statement that unlock_db() is always called directly after save() is no longer true - tests holds the lock all the time, doing multiple saves in the middle.
This commit is contained in:
parent
c37390e33f
commit
e65842322a
@ -651,8 +651,12 @@ class QubesVmCollection(dict):
|
|||||||
try:
|
try:
|
||||||
|
|
||||||
new_store_file = tempfile.NamedTemporaryFile(prefix=self.qubes_store_filename, delete=False)
|
new_store_file = tempfile.NamedTemporaryFile(prefix=self.qubes_store_filename, delete=False)
|
||||||
# XXX: do not get lock on the new file, as in all use cases
|
if os.name == 'posix':
|
||||||
# unlock_db() is the next operation after save()
|
fcntl.lockf (new_store_file, fcntl.LOCK_EX)
|
||||||
|
elif os.name == 'nt':
|
||||||
|
overlapped = pywintypes.OVERLAPPED()
|
||||||
|
win32file.LockFileEx(win32file._get_osfhandle(new_store_file.fileno()),
|
||||||
|
win32con.LOCKFILE_EXCLUSIVE_LOCK, 0, -0x10000, overlapped)
|
||||||
tree.write(new_store_file, encoding="UTF-8", pretty_print=True)
|
tree.write(new_store_file, encoding="UTF-8", pretty_print=True)
|
||||||
new_store_file.flush()
|
new_store_file.flush()
|
||||||
os.chmod(new_store_file.name, 0660)
|
os.chmod(new_store_file.name, 0660)
|
||||||
@ -738,6 +742,7 @@ class QubesVmCollection(dict):
|
|||||||
self.clear()
|
self.clear()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
self.qubes_store_file.seek(0)
|
||||||
tree = lxml.etree.parse(self.qubes_store_file)
|
tree = lxml.etree.parse(self.qubes_store_file)
|
||||||
except (EnvironmentError,
|
except (EnvironmentError,
|
||||||
xml.parsers.expat.ExpatError) as err:
|
xml.parsers.expat.ExpatError) as err:
|
||||||
|
@ -401,7 +401,7 @@ class BackupTestsMixin(SystemTestsMixin):
|
|||||||
self.fill_image(testvm2.root_img, 1024*1024*1024, True)
|
self.fill_image(testvm2.root_img, 1024*1024*1024, True)
|
||||||
vms.append(testvm2)
|
vms.append(testvm2)
|
||||||
|
|
||||||
self.save_and_reload_db()
|
self.qc.save()
|
||||||
|
|
||||||
return vms
|
return vms
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user