Blob Blame History Raw
From 80b635be63902048622e6a6093cac5ae8a324643 Mon Sep 17 00:00:00 2001
From: Patrick Donnelly <pdonnell@redhat.com>
Date: Fri, 2 Jul 2021 09:07:34 -0700
Subject: [PATCH] pybind/ceph_volume_client: use cephfs mkdirs api

This _mkdir_p should never have worked as the first directory it tries
to stat/mkdir is "", the empty string. This causes an assertion in the
client. I'm not sure how this code ever functioned without causing
faults. They look like:

    2021-07-01 02:15:04.449 7f7612b5ab80  3 client.178735 statx enter (relpath  want 2047)

The assertion is caused by a C++ exception:

	/usr/include/c++/8/string_view:172: constexpr const _CharT& std::basic_string_view<_CharT, _Traits>::operator[](std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char$_Traits = std::char_traits<char>; std::basic_string_view<_CharT, _Traits>::size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.
        Aborted (core dumped)

Where relpath is just the path passed to Client::stat.

This commit only applies to Pacific and older because master no longer
has this library.

Fixes: https://tracker.ceph.com/issues/51492
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
(cherry picked from commit 0fb05aea8a6e12c37a9b54641715a9a94ae1366f)
---
 src/pybind/ceph_volume_client.py | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/src/pybind/ceph_volume_client.py b/src/pybind/ceph_volume_client.py
index b37d48ca260..1e5e192d80d 100644
--- a/src/pybind/ceph_volume_client.py
+++ b/src/pybind/ceph_volume_client.py
@@ -629,7 +629,7 @@ class CephFSVolumeClient(object):
             raise ValueError("group ID cannot end with '{0}'.".format(
                 META_FILE_EXT))
         path = self._get_group_path(group_id)
-        self._mkdir_p(path, mode)
+        self.fs.mkdirs(path, mode)
 
     def destroy_group(self, group_id):
         path = self._get_group_path(group_id)
@@ -640,23 +640,6 @@ class CephFSVolumeClient(object):
         else:
             self.fs.rmdir(path)
 
-    def _mkdir_p(self, path, mode=0o755):
-        try:
-            self.fs.stat(path)
-        except cephfs.ObjectNotFound:
-            pass
-        else:
-            return
-
-        parts = path.split(os.path.sep)
-
-        for i in range(1, len(parts) + 1):
-            subpath = os.path.join(*parts[0:i])
-            try:
-                self.fs.stat(subpath)
-            except cephfs.ObjectNotFound:
-                self.fs.mkdir(subpath, mode)
-
     def create_volume(self, volume_path, size=None, data_isolated=False, namespace_isolated=True,
                       mode=0o755):
         """
@@ -674,7 +657,7 @@ class CephFSVolumeClient(object):
         path = self._get_path(volume_path)
         log.info("create_volume: {0}".format(path))
 
-        self._mkdir_p(path, mode)
+        self.fs.mkdirs(path, mode)
 
         if size is not None:
             self.fs.setxattr(path, 'ceph.quota.max_bytes', to_bytes(size), 0)
@@ -732,7 +715,7 @@ class CephFSVolumeClient(object):
 
         # Create the trash folder if it doesn't already exist
         trash = os.path.join(self.volume_prefix, "_deleting")
-        self._mkdir_p(trash)
+        self.fs.mkdirs(trash, 0o755)
 
         # We'll move it to here
         trashed_volume = os.path.join(trash, volume_path.volume_id)
-- 
2.31.1