Skip to content

Commit

Permalink
cephfs: implementation of mkdirs
Browse files Browse the repository at this point in the history
  • Loading branch information
maitredede committed Feb 14, 2023
1 parent 45e9a80 commit bbcb8f2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cephfs/makedirs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build ceph_preview
// +build ceph_preview

package cephfs

/*
#cgo LDFLAGS: -lcephfs
#cgo CPPFLAGS: -D_FILE_OFFSET_BITS=64
#include <stdlib.h>
#include <cephfs/libcephfs.h>
*/
import "C"

import (
"unsafe"
)

// MakeDirs creates multiple directories at once.
//
// Implements:
//
// int ceph_mkdirs(struct ceph_mount_info *cmount, const char *path, mode_t mode);
func (mount *MountInfo) MakeDirs(path string, mode uint32) error {
if err := mount.validate(); err != nil {
return err
}
cPath := C.CString(path)
defer C.free(unsafe.Pointer(cPath))

ret := C.ceph_mkdirs(mount.mount, cPath, C.mode_t(mode))
return getError(ret)
}
30 changes: 30 additions & 0 deletions cephfs/makedirs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build ceph_preview
// +build ceph_preview

package cephfs

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestMakeDirs(t *testing.T) {
mount := fsConnect(t)
defer fsDisconnect(t, mount)

dir1 := "/base/sub/way"
err := mount.MakeDirs(dir1, 0755)
assert.NoError(t, err)
defer func() {
assert.NoError(t, mount.RemoveDir("/base/sub/way"))
assert.NoError(t, mount.RemoveDir("/base/sub"))
assert.NoError(t, mount.RemoveDir("/base"))
}()

dir, err := mount.OpenDir(dir1)
assert.NoError(t, err)
assert.NotNil(t, dir)
err = dir.Close()
assert.NoError(t, err)
}
6 changes: 6 additions & 0 deletions docs/api-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@
"comment": "SelectFilesystem selects a file system to be mounted. If the ceph cluster\nsupports more than one cephfs this optional function selects which one to\nuse. Can only be called prior to calling Mount. The name of the file system\nis not validated by this call - if the supplied file system name is not\nvalid then only the subsequent mount call will fail.\n\nImplements:\n int ceph_select_filesystem(struct ceph_mount_info *cmount, const char *fs_name);\n",
"added_in_version": "v0.20.0",
"expected_stable_version": "v0.22.0"
},
{
"name": "MountInfo.MakeDirs",
"comment": "MakeDirs creates multiple directories at once.\n\nImplements:\n\n\tint ceph_mkdirs(struct ceph_mount_info *cmount, const char *path, mode_t mode);\n",
"added_in_version": "$NEXT_RELEASE",
"expected_stable_version": "$NEXT_RELEASE_STABLE"
}
]
},
Expand Down
1 change: 1 addition & 0 deletions docs/api-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Name | Added in Version | Expected Stable Version |
---- | ---------------- | ----------------------- |
MountInfo.SelectFilesystem | v0.20.0 | v0.22.0 |
MountInfo.MakeDirs | $NEXT_RELEASE | $NEXT_RELEASE_STABLE |

## Package: cephfs/admin

Expand Down

0 comments on commit bbcb8f2

Please sign in to comment.