Skip to content

Commit

Permalink
pybind/mgr/volumes: use existing client provided recursive mkdir
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
  • Loading branch information
batrick committed Jul 16, 2019
1 parent 7cc4b72 commit e9c314a
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions src/pybind/mgr/volumes/fs/subvolume.py
Expand Up @@ -37,25 +37,6 @@ def __init__(self, mgr, fs_handle):
self.fs = fs_handle
self.rados = mgr.rados

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)
except cephfs.Error as e:
raise VolumeException(-e.args[0], e.args[1])

def _get_single_dir_entry(self, dir_path, exclude=[]):
"""
Return a directory entry in a given directory exclusing passed
Expand Down Expand Up @@ -96,7 +77,7 @@ def create_subvolume(self, spec, size=None, namespace_isolated=True, mode=0o755,
subvolpath = spec.subvolume_path
log.info("creating subvolume with path: {0}".format(subvolpath))

self._mkdir_p(subvolpath, mode)
self.fs.mkdirs(subvolpath, mode)

if size is not None:
self.fs.setxattr(subvolpath, 'ceph.quota.max_bytes', str(size).encode('utf-8'), 0)
Expand Down Expand Up @@ -134,7 +115,7 @@ def remove_subvolume(self, spec, force):

# Create the trash directory if it doesn't already exist
trashdir = spec.trash_dir
self._mkdir_p(trashdir)
self.fs.mkdirs(trashdir, 0o700)

# mangle the trash directroy entry to a random string so that subsequent
# subvolume create and delete with same name moves the subvolume directory
Expand Down Expand Up @@ -199,7 +180,7 @@ def get_subvolume_path(self, spec):

def create_group(self, spec, mode=0o755, pool=None):
path = spec.group_path
self._mkdir_p(path, mode)
self.fs.mkdirs(path, mode)
if not pool:
pool = self._get_ancestor_xattr(path, "ceph.dir.layout.pool")
self.fs.setxattr(path, 'ceph.dir.layout.pool', pool.encode('utf-8'), 0)
Expand Down

0 comments on commit e9c314a

Please sign in to comment.