From ca04fc18293af34e0b92cad176804bb967bd19ae Mon Sep 17 00:00:00 2001 From: John Griffith Date: Tue, 18 Jun 2013 14:45:50 -0600 Subject: [PATCH] Don't perform retry_execute in certain cases. Certain cases like "LVM not found" and "Insufficient space" in LVM create/delete shouldn't be retried. Change-Id: I1a0891f769d37dc858c70b07c838f9fc4111a76c --- cinder/volume/driver.py | 20 ++++++++++++++++++-- cinder/volume/drivers/lvm.py | 6 +++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index 90b0e6d9e..5033a56a7 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -78,19 +78,32 @@ class VolumeDriver(object): def set_execute(self, execute): self._execute = execute + def _is_non_recoverable(self, err, non_recoverable_list): + for item in non_recoverable_list: + if item in err: + return True + + return False + def _try_execute(self, *command, **kwargs): # NOTE(vish): Volume commands can partially fail due to timing, but # running them a second time on failure will usually # recover nicely. + + non_recoverable = kwargs.pop('no_retry_list', []) + tries = 0 while True: try: self._execute(*command, **kwargs) return True - except exception.ProcessExecutionError: + except exception.ProcessExecutionError as ex: tries = tries + 1 - if tries >= self.configuration.num_shell_tries: + + if tries >= self.configuration.num_shell_tries or\ + self._is_non_recoverable(ex.stderr, non_recoverable): raise + LOG.exception(_("Recovering from a failed execute. " "Try number %s"), tries) time.sleep(tries ** 2) @@ -555,6 +568,9 @@ class FakeISCSIDriver(ISCSIDriver): super(FakeISCSIDriver, self).__init__(execute=self.fake_execute, *args, **kwargs) + def create_volume(self, volume): + pass + def check_for_setup_error(self): """No setup necessary in fake mode.""" pass diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 3c214cc5f..fbb3f2bbe 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -84,6 +84,10 @@ class LVMVolumeDriver(driver.VolumeDriver): raise exception.VolumeBackendAPIException(data=exception_message) def _create_volume(self, volume_name, sizestr): + + no_retry_list = ['Insufficient free extents', + 'One or more specified logical volume(s) not found'] + cmd = ['lvcreate', '-L', sizestr, '-n', volume_name, self.configuration.volume_group] if self.configuration.lvm_mirrors: @@ -95,7 +99,7 @@ class LVMVolumeDriver(driver.VolumeDriver): # http://red.ht/U2BPOD cmd += ['-R', str(rsize)] - self._try_execute(*cmd, run_as_root=True) + self._try_execute(*cmd, run_as_root=True, no_retry_list=no_retry_list) def _copy_volume(self, srcstr, deststr, size_in_g, clearing=False): # Use O_DIRECT to avoid thrashing the system buffer cache -- 2.45.2