Handling Invalid argument iflag=direct in dd

During volume/snapshot create/delete operations,
dd command is used to clear contents of disk.

Before invoking dd, it is checked if iflag=direct
supports dd or not by executing dd command with
iflag=direct and if=/dev/zero combination.
But this always results in invalid argument
error.

Handling for this argument is done to eliminate
unnecessary call to dd command when it is used
with iflag=direct and if=/dev/zero combination
to check if this argument supports dd or not.

Closes-Bug: #1270362

Change-Id: Ic6dd029ca1a339076e491c38ef3c69315497f189
This commit is contained in:
Sheel Rana 2016-01-12 01:36:46 +05:30
parent 81f7986c16
commit 5e363eb194
2 changed files with 30 additions and 3 deletions

View File

@ -445,6 +445,20 @@ class OdirectSupportTestCase(test.TestCase):
mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/abc',
'of=/dev/def', 'iflag=direct',
run_as_root=True)
mock_exec.reset_mock()
output = volume_utils.check_for_odirect_support('/dev/zero',
'/dev/def',
'iflag=direct')
self.assertFalse(output)
mock_exec.reset_mock()
output = volume_utils.check_for_odirect_support('/dev/zero',
'/dev/def')
self.assertTrue(output)
mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/zero',
'of=/dev/def', 'oflag=direct',
run_as_root=True)
@mock.patch('cinder.utils.execute',
side_effect=processutils.ProcessExecutionError)
@ -454,6 +468,13 @@ class OdirectSupportTestCase(test.TestCase):
mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/abc',
'of=/dev/def', 'oflag=direct',
run_as_root=True)
mock_exec.reset_mock()
output = volume_utils.check_for_odirect_support('/dev/zero',
'/dev/def')
self.assertFalse(output)
mock_exec.assert_called_once_with('dd', 'count=0', 'if=/dev/zero',
'of=/dev/def', 'oflag=direct',
run_as_root=True)
class ClearVolumeTestCase(test.TestCase):

View File

@ -299,9 +299,15 @@ def check_for_odirect_support(src, dest, flag='oflag=direct'):
# Check whether O_DIRECT is supported
try:
utils.execute('dd', 'count=0', 'if=%s' % src, 'of=%s' % dest,
flag, run_as_root=True)
return True
# iflag=direct and if=/dev/zero combination does not work
# error: dd: failed to open '/dev/zero': Invalid argument
if (src == '/dev/zero' and flag == 'iflag=direct'):
return False
else:
utils.execute('dd', 'count=0', 'if=%s' % src,
'of=%s' % dest,
flag, run_as_root=True)
return True
except processutils.ProcessExecutionError:
return False