]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix LVM thin pool creation race
authorDuncan Thomas <duncan.thomas@gmail.com>
Tue, 13 Jan 2015 16:41:13 +0000 (18:41 +0200)
committerDuncan Thomas <duncan.thomas@hp.com>
Fri, 13 Mar 2015 16:22:35 +0000 (18:22 +0200)
In the event that two copied of the LVM driver get init called at
the same time (e.g. cinder-volume and cinder-backup getting
started in parallel, on the same host), it is possible for the
thin pool check/create to race. Add a simple recheck if the create
fails, to cover this window.

Change-Id: I006970736ba0e62df383bacc79b5754dea2e9a3e
Closes-Bug: #1410341

cinder/brick/local_dev/lvm.py

index 9d2cdf7ff6eb1c95c8fe1d78c23f09bc339edcd7..9fe2f4de98ce770082488910df2cb5bd3eb81381 100644 (file)
@@ -89,10 +89,16 @@ class LVM(executor.Executor):
         if lvm_type == 'thin':
             pool_name = "%s-pool" % self.vg_name
             if self.get_volume(pool_name) is None:
-                self.create_thin_pool(pool_name)
-            else:
-                self.vg_thin_pool = pool_name
-
+                try:
+                    self.create_thin_pool(pool_name)
+                except putils.ProcessExecutionError:
+                    # Maybe we just lost the race against another copy of
+                    # this driver being in init in parallel - e.g.
+                    # cinder-volume and cinder-backup starting in parallel
+                    if self.get_volume(pool_name) is None:
+                        raise
+
+            self.vg_thin_pool = pool_name
             self.activate_lv(self.vg_thin_pool)
         self.pv_list = self.get_all_physical_volumes(root_helper, vg_name)
 
@@ -460,7 +466,7 @@ class LVM(executor.Executor):
             size_str = self._calculate_thin_pool_size()
 
         cmd = ['lvcreate', '-T', '-L', size_str, vg_pool_name]
-        LOG.debug('Created thin pool \'%(pool)s\' with size %(size)s of '
+        LOG.debug('Creating thin pool \'%(pool)s\' with size %(size)s of '
                   'total %(free)sg' % {'pool': vg_pool_name,
                                        'size': size_str,
                                        'free': self.vg_free_space})