Skip to content

Commit

Permalink
Fix backing file cp/resize race condition.
Browse files Browse the repository at this point in the history
 * Fixes bug 953831

Change-Id: I39950b16c9b76159b16203f7b8b504cae5475516
  • Loading branch information
sleepsonthefloor committed Mar 13, 2012
1 parent dec0e49 commit aa204ea
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions nova/virt/libvirt/connection.py
Expand Up @@ -46,6 +46,7 @@
import os
import shutil
import sys
import time
import uuid

from eventlet import greenthread
Expand Down Expand Up @@ -1012,22 +1013,26 @@ def call_if_not_exists(base, fn, *args, **kwargs):
# For raw it's quicker to just generate outside the cache
call_if_not_exists(target, fn, *args, **kwargs)

if cow:
cow_base = base
if size:
size_gb = size / (1024 * 1024 * 1024)
cow_base += "_%d" % size_gb
if not os.path.exists(cow_base):
libvirt_utils.copy_image(base, cow_base)
disk.extend(cow_base, size)
libvirt_utils.create_cow_image(cow_base, target)
elif not generating:
libvirt_utils.copy_image(base, target)
# Resize after the copy, as it's usually much faster
# to make sparse updates, rather than potentially
# naively copying the whole image file.
if size:
disk.extend(target, size)
@utils.synchronized(base)
def copy_and_extend(cow, generating, base, target, size):
if cow:
cow_base = base
if size:
size_gb = size / (1024 * 1024 * 1024)
cow_base += "_%d" % size_gb
if not os.path.exists(cow_base):
libvirt_utils.copy_image(base, cow_base)
disk.extend(cow_base, size)
libvirt_utils.create_cow_image(cow_base, target)
elif not generating:
libvirt_utils.copy_image(base, target)
# Resize after the copy, as it's usually much faster
# to make sparse updates, rather than potentially
# naively copying the whole image file.
if size:
disk.extend(target, size)

copy_and_extend(cow, generating, base, target, size)

@staticmethod
def _create_local(target, local_size, unit='G',
Expand Down

0 comments on commit aa204ea

Please sign in to comment.