Shorten snapshots names in CephFS drivers

The name set to snapshots in the CephFS drivers
is generated appending the snapshot id with the
snapshot instance id.

This is a problem because Ceph has a limitation
in the name of the subvolumes (shares) being created.

What happens then is, when trying to create a snapshot,
the snapshot gets created with a truncated name and it cannot
be accessed later.

This change drops the snapshot instance id from the
assigned name in order to avoid this limitation.

Closes-Bug: #1967760

Change-Id: Ifab3ec9de2abeb1af8e6499feca0236e1ee22fcf
This commit is contained in:
Victoria Martinez de la Cruz 2022-09-19 08:31:13 +00:00
parent 031fab2c8f
commit c86523d590
3 changed files with 41 additions and 14 deletions

View File

@ -595,7 +595,7 @@ class CephFSDriver(driver.ExecuteMixin, driver.GaneshaMixin,
argdict = {
"vol_name": self.volname,
"sub_name": snapshot["share_id"],
"snap_name": "_".join([snapshot["snapshot_id"], snapshot["id"]]),
"snap_name": snapshot["snapshot_id"],
}
rados_command(
@ -605,13 +605,24 @@ class CephFSDriver(driver.ExecuteMixin, driver.GaneshaMixin,
# delete a FS snapshot
LOG.debug("[%(be)s]: delete_snapshot: snapshot=%(id)s.",
{"be": self.backend_name, "id": snapshot['id']})
argdict = {
# FIXME(vkmc) remove this in CC (next tick) release.
legacy_snap_name = "_".join([snapshot["snapshot_id"], snapshot["id"]])
argdict_legacy = {
"vol_name": self.volname,
"sub_name": snapshot["share_id"],
"snap_name": '_'.join([snapshot['snapshot_id'], snapshot['id']]),
"snap_name": legacy_snap_name,
"force": True,
}
# try removing snapshot using legacy naming
rados_command(
self.rados_client, "fs subvolume snapshot rm", argdict_legacy)
# in case it's a snapshot with new naming, retry remove with new name
argdict = argdict_legacy.copy()
argdict.update({"snap_name": snapshot["snapshot_id"]})
rados_command(self.rados_client, "fs subvolume snapshot rm", argdict)
def create_share_group(self, context, sg_dict, share_server=None):
@ -734,7 +745,7 @@ class CephFSDriver(driver.ExecuteMixin, driver.GaneshaMixin,
argdict = {
"vol_name": self.volname,
"sub_name": parent_share["id"],
"snap_name": '_'.join([snapshot["snapshot_id"], snapshot["id"]]),
"snap_name": snapshot["snapshot_id"],
"target_sub_name": share["id"]
}
if share['share_group_id'] is not None:

View File

@ -364,8 +364,7 @@ class CephFSDriverTestCase(test.TestCase):
snapshot_create_dict = {
"vol_name": self._driver.volname,
"sub_name": self._snapshot["share_id"],
"snap_name": "_".join([
self._snapshot["snapshot_id"], self._snapshot["id"]]),
"snap_name": self._snapshot["snapshot_id"]
}
self._driver.create_snapshot(self._context, self._snapshot, None)
@ -375,23 +374,35 @@ class CephFSDriverTestCase(test.TestCase):
snapshot_create_prefix, snapshot_create_dict)
def test_delete_snapshot(self):
legacy_snap_name = "_".join(
[self._snapshot["snapshot_id"], self._snapshot["id"]])
snapshot_remove_prefix = "fs subvolume snapshot rm"
snapshot_remove_dict = {
"vol_name": self._driver.volname,
"sub_name": self._snapshot["share_id"],
"snap_name": "_".join([
self._snapshot["snapshot_id"], self._snapshot["id"]]),
"force": True,
"snap_name": legacy_snap_name,
"force": True
}
snapshot_remove_dict_2 = snapshot_remove_dict.copy()
snapshot_remove_dict_2.update(
{"snap_name": self._snapshot["snapshot_id"]})
self._driver.delete_snapshot(self._context,
self._snapshot,
None)
driver.rados_command.assert_called_once_with(
self._driver.rados_client,
snapshot_remove_prefix, snapshot_remove_dict)
driver.rados_command.assert_has_calls([
mock.call(self._driver.rados_client,
snapshot_remove_prefix,
snapshot_remove_dict),
mock.call(self._driver.rados_client,
snapshot_remove_prefix,
snapshot_remove_dict_2)])
self.assertEqual(2, driver.rados_command.call_count)
def test_create_share_group(self):
group_create_prefix = "fs subvolumegroup create"
@ -465,8 +476,7 @@ class CephFSDriverTestCase(test.TestCase):
create_share_from_snapshot_dict = {
"vol_name": self._driver.volname,
"sub_name": parent_share["id"],
"snap_name": "_".join([
self._snapshot["snapshot_id"], self._snapshot["id"]]),
"snap_name": self._snapshot["snapshot_id"],
"target_sub_name": self._share["id"]
}

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Make snapshot names in CephFS drivers shorter to
avoid limitation in Ceph clusters which truncates
the subvolume name and makes the snapshots inaccesible.