CONF.volume_clear = 'zero'
CONF.volume_clear_size = 0
CONF.volume_dd_blocksize = '1M'
+ CONF.volume_clear_ionice = None
self.mox.StubOutWithMock(volume_utils, 'copy_volume')
volume_utils.copy_volume("/dev/zero", "volume_path", 1024,
CONF.volume_dd_blocksize, sync=True,
- execute=utils.execute)
+ ionice=None, execute=utils.execute)
self.mox.ReplayAll()
volume_utils.clear_volume(1024, "volume_path")
def test_clear_volume_zero(self):
CONF.volume_clear = 'zero'
CONF.volume_clear_size = 1
+ CONF.volume_clear_ionice = None
+ self.mox.StubOutWithMock(volume_utils, 'copy_volume')
+ volume_utils.copy_volume("/dev/zero", "volume_path", 1,
+ CONF.volume_dd_blocksize, sync=True,
+ ionice=None, execute=utils.execute)
+ self.mox.ReplayAll()
+ volume_utils.clear_volume(1024, "volume_path")
+
+ def test_clear_volume_ionice(self):
+ CONF.volume_clear = 'zero'
+ CONF.volume_clear_size = 0
+ CONF.volume_dd_blocksize = '1M'
+ CONF.volume_clear_ionice = '-c3'
+ self.mox.StubOutWithMock(volume_utils, 'copy_volume')
+ volume_utils.copy_volume("/dev/zero", "volume_path", 1024,
+ CONF.volume_dd_blocksize, sync=True,
+ ionice=CONF.volume_clear_ionice,
+ execute=utils.execute)
+ self.mox.ReplayAll()
+ volume_utils.clear_volume(1024, "volume_path")
+
+ def test_clear_volume_zero_ionice(self):
+ CONF.volume_clear = 'zero'
+ CONF.volume_clear_size = 1
+ CONF.volume_clear_ionice = '-c3'
self.mox.StubOutWithMock(volume_utils, 'copy_volume')
volume_utils.copy_volume("/dev/zero", "volume_path", 1,
CONF.volume_dd_blocksize, sync=True,
+ ionice=CONF.volume_clear_ionice,
execute=utils.execute)
self.mox.ReplayAll()
volume_utils.clear_volume(1024, "volume_path")
cfg.IntOpt('volume_clear_size',
default=0,
help='Size in MiB to wipe at start of old volumes. 0 => all'),
+ cfg.StrOpt('volume_clear_ionice',
+ default=None,
+ help='The flag to pass to ionice to alter the i/o priority '
+ 'of the process used to zero a volume after deletion, '
+ 'for example "-c3" for idle only priority.'),
cfg.StrOpt('iscsi_helper',
default='tgtadm',
help='iscsi target user-land tool to use'),
def copy_volume(srcstr, deststr, size_in_m, blocksize, sync=False,
- execute=utils.execute):
+ execute=utils.execute, ionice=None):
# Use O_DIRECT to avoid thrashing the system buffer cache
extra_flags = ['iflag=direct', 'oflag=direct']
blocksize, count = _calculate_count(size_in_m, blocksize)
+ cmd = ['dd', 'if=%s' % srcstr, 'of=%s' % deststr,
+ 'count=%d' % count, 'bs=%s' % blocksize]
+ cmd.extend(extra_flags)
+
+ if ionice is not None:
+ cmd = ['ionice', ionice] + cmd
+
# Perform the copy
- execute('dd', 'if=%s' % srcstr, 'of=%s' % deststr,
- 'count=%d' % count,
- 'bs=%s' % blocksize,
- *extra_flags, run_as_root=True)
+ execute(*cmd, run_as_root=True)
def clear_volume(volume_size, volume_path, volume_clear=None,
- volume_clear_size=None):
+ volume_clear_size=None, volume_clear_ionice=None):
"""Unprovision old volumes to prevent data leaking between users."""
if volume_clear is None:
volume_clear = CONF.volume_clear
if volume_clear_size == 0:
volume_clear_size = volume_size
+ if volume_clear_ionice is None:
+ volume_clear_ionice = CONF.volume_clear_ionice
+
LOG.info(_("Performing secure delete on volume: %s") % volume_path)
if volume_clear == 'zero':
return copy_volume('/dev/zero', volume_path, volume_clear_size,
CONF.volume_dd_blocksize,
- sync=True, execute=utils.execute)
+ sync=True, execute=utils.execute,
+ ionice=volume_clear_ionice)
elif volume_clear == 'shred':
clear_cmd = ['shred', '-n3']
if volume_clear_size:
# (integer value)
#volume_clear_size=0
+# The flag to pass to ionice to alter the i/o priority of the
+# process used to zero a volume after deletion, for example
+# "-c3" for idle only priority. (string value)
+#volume_clear_ionice=<None>
+
# iscsi target user-land tool to use (string value)
#iscsi_helper=tgtadm