Merge "Limit RBD discard to 32 bit chunks"

This commit is contained in:
Zuul 2019-02-19 16:50:34 +00:00 committed by Gerrit Code Review
commit 0162efc6fb
2 changed files with 24 additions and 1 deletions

View File

@ -337,7 +337,15 @@ class CephBackupDriver(driver.BackupDriver):
LOG.debug("Discarding %(length)s bytes from offset %(offset)s",
{'length': length, 'offset': offset})
if self._file_is_rbd(volume):
eventlet.tpool.Proxy(volume.rbd_image).discard(offset, length)
limit = 2 * units.Gi - 1
chunks = int(length / limit)
for chunk in range(0, chunks):
eventlet.tpool.Proxy(volume.rbd_image).discard(
offset + chunk * limit, limit)
rem = int(length % limit)
if rem:
eventlet.tpool.Proxy(volume.rbd_image).discard(
offset + chunks * limit, rem)
else:
zeroes = '\0' * self.chunk_size
chunks = int(length / self.chunk_size)

View File

@ -899,9 +899,24 @@ class BackupCephTestCase(test.TestCase):
self.service._discard_bytes(wrapped_rbd, 0, 0)
self.assertEqual(0, image.discard.call_count)
image.discard.reset_mock()
self.service._discard_bytes(wrapped_rbd, 0, 1234)
self.assertEqual(1, image.discard.call_count)
image.discard.assert_has_calls([mock.call(0, 1234)])
image.discard.reset_mock()
limit = 2 * units.Gi - 1
self.service._discard_bytes(wrapped_rbd, 0, limit)
self.assertEqual(1, image.discard.call_count)
image.discard.assert_has_calls([mock.call(0, 2147483647)])
image.discard.reset_mock()
self.service._discard_bytes(wrapped_rbd, 0, limit * 2 + 1234)
self.assertEqual(3, image.discard.call_count)
image.discard.assert_has_calls([mock.call(0, 2147483647),
mock.call(2147483647, 2147483647),
mock.call(4294967294, 1234)])
image.reset_mock()
# Test discard with no remainder