From: Vishvananda Ishaya Date: Mon, 17 Dec 2012 22:38:53 +0000 (-0800) Subject: Allow the lvm backed drivers to use mirrrors X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f61e854460c5ad8129b2230686465884eb6b8852;p=openstack-build%2Fcinder-build.git Allow the lvm backed drivers to use mirrrors 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 --- diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index 71481eda9..2dac38f59 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -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 diff --git a/etc/cinder/cinder.conf.sample b/etc/cinder/cinder.conf.sample index 2f87758c2..f3d3e3c98 100644 --- a/etc/cinder/cinder.conf.sample +++ b/etc/cinder/cinder.conf.sample @@ -517,6 +517,10 @@ # 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