:param name: Name of LV to delete
"""
+
+ def run_udevadm_settle():
+ self._execute('udevadm', 'settle',
+ root_helper=self._root_helper, run_as_root=True,
+ check_exit_code=False)
+
try:
- self._execute('lvremove',
- '-f',
- '%s/%s' % (self.vg_name, name),
+ need_force_remove = False
+ # LV removal seems to be a race with udev in
+ # some cases (see LP #1270192), so we do it in several steps:
+
+ # - Deactivate the LV/Snapshot, which triggers udev events
+ # - Wait for udev to finish its job with udevadmn settle
+ # - Remove the LV
+
+ try:
+ self._execute('lvchange', '-y', '-an',
+ '%s/%s' % (self.vg_name, name),
+ root_helper=self._root_helper, run_as_root=True)
+ except putils.ProcessExecutionError as err:
+ mesg = (_('Error during lvchange -an: CMD: %(command)s, '
+ 'RESPONSE: %(response)s') %
+ {'command': err.cmd, 'response': err.stderr})
+ LOG.debug(mesg)
+ need_force_remove = True
+
+ run_udevadm_settle()
+
+ cmd = ['lvremove', ]
+
+ # if deactivation failed, use the --force, lvm!
+ if need_force_remove:
+ cmd.append('-f')
+ cmd.append('%s/%s' % (self.vg_name, name))
+ self._execute(*cmd,
root_helper=self._root_helper, run_as_root=True)
except putils.ProcessExecutionError as err:
mesg = (_('Error reported running lvremove: CMD: %(command)s, '
LOG.debug(mesg)
LOG.debug(_('Attempting udev settle and retry of lvremove...'))
- self._execute('udevadm', 'settle',
- root_helper=self._root_helper,
- run_as_root=True)
+ run_udevadm_settle()
self._execute('lvremove',
'-f',