From: Rongze Zhu <rongze@unitedstack.com>
Date: Wed, 17 Jul 2013 10:15:04 +0000 (+0800)
Subject: Fixes race condition in LVMVolumeDriver create_cloned_volume method
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=201890c17e0f29d1ec8e5040206ecd1be09e22f7;p=openstack-build%2Fcinder-build.git

Fixes race condition in LVMVolumeDriver create_cloned_volume method

When we create a clone volume, LVMVolumeDriver will firstly create a temp
snapshot for copying, the temp snapshot name is
"clone-snap-%s" % source_volume['id']. When we create multiple clone volumes
of the same volume simultaneously, which would trigger the race issuse.

I changes the temp snapshot name template to "clone-snap-%s" % volume['id'],
so temp snapshot name will be unique.

Fixes bug #1202139

Change-Id: I3a4f2585ea9e6f70b6f6f9889e900f19559b8176
---

diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py
index a905a15db..33fef0f89 100644
--- a/cinder/volume/drivers/lvm.py
+++ b/cinder/volume/drivers/lvm.py
@@ -300,11 +300,11 @@ class LVMVolumeDriver(driver.VolumeDriver):
         """Creates a clone of the specified volume."""
         LOG.info(_('Creating clone of volume: %s') % src_vref['id'])
         volume_name = CONF.volume_name_template % src_vref['id']
-        temp_id = 'tmp-snap-%s' % src_vref['id']
+        temp_id = 'tmp-snap-%s' % volume['id']
         temp_snapshot = {'volume_name': volume_name,
                          'size': src_vref['size'],
                          'volume_size': src_vref['size'],
-                         'name': 'clone-snap-%s' % src_vref['id'],
+                         'name': 'clone-snap-%s' % volume['id'],
                          'id': temp_id}
         self.create_snapshot(temp_snapshot)
         self._create_volume(volume['name'], self._sizestr(volume['size']))