Skip to content

Commit

Permalink
ceph_volume_client: version on-disk metadata
Browse files Browse the repository at this point in the history
Version on-disk metadata with two attributes,
'compat version', the minimum CephFSVolume Client
version that can decode the metadata, and
'version', the version that encoded the metadata.

Signed-off-by: Ramana Raja <rraja@redhat.com>
(cherry picked from commit 1c1d65a)
  • Loading branch information
ajarr committed Jul 27, 2016
1 parent 7c32932 commit fa2e94d
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions src/pybind/ceph_volume_client.py
Expand Up @@ -754,6 +754,15 @@ def _get_ancestor_xattr(self, path, attr):
else:
return self._get_ancestor_xattr(os.path.split(path)[0], attr)

def _check_compat_version(self, compat_version):
if self.version < compat_version:
msg = ("The current version of CephFSVolumeClient, version {0} "
"does not support the required feature. Need version {1} "
"or greater".format(self.version, compat_version)
)
log.error(msg)
raise CephFSVolumeClientError(msg)

def _metadata_get(self, path):
"""
Return a deserialized JSON object, or None
Expand Down Expand Up @@ -813,9 +822,35 @@ def _auth_lock(self, auth_id):
return self._lock(self._auth_metadata_path(auth_id))

def _auth_metadata_get(self, auth_id):
return self._metadata_get(self._auth_metadata_path(auth_id))
"""
Call me with the metadata locked!
Check whether a auth metadata structure can be decoded by the current
version of CephFSVolumeClient.
Return auth metadata that the current version of CephFSVolumeClient
can decode.
"""
auth_metadata = self._metadata_get(self._auth_metadata_path(auth_id))

if auth_metadata:
self._check_compat_version(auth_metadata['compat_version'])

return auth_metadata

def _auth_metadata_set(self, auth_id, data):
"""
Call me with the metadata locked!
Fsync the auth metadata.
Add two version attributes to the auth metadata,
'compat_version', the minimum CephFSVolumeClient version that can
decode the metadata, and 'version', the CephFSVolumeClient version
that encoded the metadata.
"""
data['compat_version'] = 1
data['version'] = 1
return self._metadata_set(self._auth_metadata_path(auth_id), data)

def _volume_metadata_path(self, volume_path):
Expand Down Expand Up @@ -844,13 +879,31 @@ def _volume_lock(self, volume_path):
def _volume_metadata_get(self, volume_path):
"""
Call me with the metadata locked!
Check whether a volume metadata structure can be decoded by the current
version of CephFSVolumeClient.
Return a volume_metadata structure that the current version of
CephFSVolumeClient can decode.
"""
return self._metadata_get(self._volume_metadata_path(volume_path))
volume_metadata = self._metadata_get(self._volume_metadata_path(volume_path))

if volume_metadata:
self._check_compat_version(volume_metadata['compat_version'])

return volume_metadata

def _volume_metadata_set(self, volume_path, data):
"""
Call me with the metadata locked!
Add two version attributes to the volume metadata,
'compat_version', the minimum CephFSVolumeClient version that can
decode the metadata and 'version', the CephFSVolumeClient version
that encoded the metadata.
"""
data['compat_version'] = 1
data['version'] = 1
return self._metadata_set(self._volume_metadata_path(volume_path), data)

def authorize(self, volume_path, auth_id, readonly=False, tenant_id=None):
Expand Down

0 comments on commit fa2e94d

Please sign in to comment.