]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Allow the lvm backed drivers to use mirrrors
authorVishvananda Ishaya <vishvananda@gmail.com>
Mon, 17 Dec 2012 22:38:53 +0000 (14:38 -0800)
committerVishvananda Ishaya <vishvananda@gmail.com>
Tue, 18 Dec 2012 00:11:20 +0000 (16:11 -0800)
Adds a new configuration option called lvm_mirrors. If this is
set to a value > 0, it will create the specified number of mirrors
when creating volumes. Note that lvm_mirrors + 2 pvs are required
in the volume group for lvm mirroring to work properly.

Change-Id: I7e28d11c48cdbb99e17b0930b720fbd805bf9931

cinder/volume/driver.py
etc/cinder/cinder.conf.sample

index 71481eda95b4db17b242121d5fc02e5f4f1bc9ad..2dac38f59f0312b84f702a36312e02cdc2861bc1 100644 (file)
@@ -20,6 +20,7 @@ Drivers for volumes.
 
 """
 
+import math
 import os
 import re
 import time
@@ -39,6 +40,10 @@ volume_opts = [
     cfg.StrOpt('volume_group',
                default='cinder-volumes',
                help='Name for the VG that will contain exported volumes'),
+    cfg.IntOpt('lvm_mirrors',
+               default=0,
+               help='If set, create lvms with multiple mirrors. Note that '
+                    'this requires lvm_mirrors + 2 pvs with available space'),
     cfg.IntOpt('num_shell_tries',
                default=3,
                help='number of times to attempt to run flakey shell commands'),
@@ -100,8 +105,18 @@ class VolumeDriver(object):
             raise exception.VolumeBackendAPIException(data=exception_message)
 
     def _create_volume(self, volume_name, sizestr):
-        self._try_execute('lvcreate', '-L', sizestr, '-n',
-                          volume_name, FLAGS.volume_group, run_as_root=True)
+        cmd = ['lvcreate', '-L', sizestr, '-n', volume_name,
+               FLAGS.volume_group]
+        if FLAGS.lvm_mirrors:
+            cmd += ['-m', FLAGS.lvm_mirrors, '--nosync']
+            terras = int(sizestr[:-1]) / 1024.0
+            if terras >= 1.5:
+                rsize = int(2 ** math.ceil(math.log(terras) / math.log(2)))
+                # NOTE(vish): Next power of two for region size. See:
+                #             http://red.ht/U2BPOD
+                cmd += ['-R', str(rsize)]
+
+        self._try_execute(*cmd, run_as_root=True)
 
     def _copy_volume(self, srcstr, deststr, size_in_g):
         # Use O_DIRECT to avoid thrashing the system buffer cache
index 2f87758c2342ad352788ff8fdb7cb48681a11674..f3d3e3c984f90eb0cb5877265cf56d586b8b00da 100644 (file)
 # volume_group=cinder-volumes
 #### (StrOpt) Name for the VG that will contain exported volumes
 
+# lvm_mirrors=0
+#### (IntOpt) If set, create lvms with multiple mirrors. Note that
+####          this requires lvm_mirrors + 2 pvs with available space
+
 # num_shell_tries=3
 #### (IntOpt) number of times to attempt to run flakey shell commands