Skip to content

Commit

Permalink
curvebs: support poolset
Browse files Browse the repository at this point in the history
Co-authored-by: jolly-sy <[email protected]>
Co-authored-by: Hanqing Wu <[email protected]>

Signed-off-by: jolly-sy <[email protected]>
Signed-off-by: Hanqing Wu <[email protected]>
  • Loading branch information
jolly-sy authored and wu-hanqing committed Jun 8, 2023
1 parent d9d74a0 commit ada6a18
Show file tree
Hide file tree
Showing 135 changed files with 4,644 additions and 1,114 deletions.
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
build --verbose_failures

build --define=with_glog=true --define=libunwind=true
build --copt -DHAVE_ZLIB=1 --copt -DGFLAGS_NS=google --copt -DUSE_BTHREAD_MUTEX
build --cxxopt -Wno-error=format-security
build:gcc7-later --cxxopt -faligned-new
build --incompatible_blacklisted_protos_requires_proto_info=false
build --copt=-fdiagnostics-color=always

run --copt=-fdiagnostics-color=always
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,12 @@ GPATH
GRTAGS
GTAGS
core.*

test/integration/*.conf
test/integration/client/config/client.conf*
test/integration/snapshotcloneserver/config/*.conf

.pre-commit-config.yaml

*.deb
*.whl
5 changes: 5 additions & 0 deletions curvefs_python/HOWTO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1. `curvefs.py` and `curvefs_wrap.cxx` are generated by command `swig -c++ -python curvefs.i`.
2. Revert `ListDir` and Delete `Opendir`/`Closedir` functions in `curvefs.py` if you don intend to make changes about these functions.
3. Revert `_wrap_Read`/`_wrap_Listdir`/`_wrap_GetClusterId`/`_wrap_CBDClient_Read`/`_wrap_CBDClient_Listdir` if you don intend to make changes about these functions.
4. :exclamation: C functions in `libcurvefs.h` are not recommended for use anymore.
5. :exclamation: Types in `curve_type.h` are different from `include/client/*.h` even they have the similar name.
24 changes: 19 additions & 5 deletions curvefs_python/cbd_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@

#include "src/client/libcurve_file.h"

inline curve::client::UserInfo ToCurveClientUserInfo(UserInfo_t* userInfo) {
namespace {
inline curve::client::UserInfo ToCurveClientUserInfo(
const UserInfo_t* userInfo) {
return curve::client::UserInfo(userInfo->owner, userInfo->password);
}
}

CBDClient::CBDClient() : client_(new curve::client::FileClient()) {}

Expand All @@ -54,10 +57,17 @@ int CBDClient::Create(const char* filename, UserInfo_t* userInfo, size_t size) {
return client_->Create(filename, ToCurveClientUserInfo(userInfo), size);
}

int CBDClient::Create2(const char* filename, UserInfo_t* userInfo, size_t size,
uint64_t stripeUnit, uint64_t stripeCount) {
return client_->Create2(filename, ToCurveClientUserInfo(userInfo),
size, stripeUnit, stripeCount);
int CBDClient::Create2(const CreateContext* context) {
curve::client::CreateFileContext internal;
internal.pagefile = true;
internal.name = context->name;
internal.user = ToCurveClientUserInfo(&context->user);
internal.length = context->length;
internal.poolset = context->poolset;
internal.stripeUnit = context->stripeUnit;
internal.stripeCount = context->stripeCount;

return client_->Create2(internal);
}

int CBDClient::Unlink(const char* filename, UserInfo_t* userInfo) {
Expand Down Expand Up @@ -166,3 +176,7 @@ int CBDClient::Rmdir(const char* dirpath, UserInfo_t* userInfo) {
std::string CBDClient::GetClusterId() {
return client_->GetClusterId();
}

std::vector<std::string> CBDClient::ListPoolset() {
return client_->ListPoolset();
}
6 changes: 4 additions & 2 deletions curvefs_python/cbd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <memory>
#include <string>
#include <vector>

#include "curvefs_python/curve_type.h"

Expand All @@ -48,8 +49,7 @@ class CBDClient {
int Close(int fd);

int Create(const char* filename, UserInfo_t* userInfo, size_t size);
int Create2(const char* filename, UserInfo_t* userInfo, size_t size,
uint64_t stripeUnit, uint64_t stripeCount);
int Create2(const CreateContext* context);
int Unlink(const char* filename, UserInfo_t* info);
int DeleteForce(const char* filename, UserInfo_t* info);
int Recover(const char* filename, UserInfo_t* info, uint64_t fileId);
Expand All @@ -76,6 +76,8 @@ class CBDClient {

std::string GetClusterId();

std::vector<std::string> ListPoolset();

private:
std::unique_ptr<curve::client::FileClient> client_;
};
Expand Down
11 changes: 11 additions & 0 deletions curvefs_python/curve_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <stdint.h>
#include <unistd.h>

#include <string>

#define CURVE_INODE_DIRECTORY 0
#define CURVE_INODE_PAGEFILE 1
#define CURVEINODE_APPENDFILE 2
Expand Down Expand Up @@ -134,4 +136,13 @@ typedef struct DirInfos {
FileInfo_t* fileinfo;
} DirInfos_t;

struct CreateContext {
std::string name;
size_t length;
UserInfo user;
std::string poolset;
uint64_t stripeUnit;
uint64_t stripeCount;
};

#endif // CURVEFS_PYTHON_CURVE_TYPE_H_
57 changes: 51 additions & 6 deletions curvefs_python/curvefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,48 @@ def __init__(self):
DirInfos_t_swigregister = _curvefs.DirInfos_t_swigregister
DirInfos_t_swigregister(DirInfos_t)

class CreateContext(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, CreateContext, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, CreateContext, name)
__repr__ = _swig_repr
__swig_setmethods__["name"] = _curvefs.CreateContext_name_set
__swig_getmethods__["name"] = _curvefs.CreateContext_name_get
if _newclass:
name = _swig_property(_curvefs.CreateContext_name_get, _curvefs.CreateContext_name_set)
__swig_setmethods__["length"] = _curvefs.CreateContext_length_set
__swig_getmethods__["length"] = _curvefs.CreateContext_length_get
if _newclass:
length = _swig_property(_curvefs.CreateContext_length_get, _curvefs.CreateContext_length_set)
__swig_setmethods__["user"] = _curvefs.CreateContext_user_set
__swig_getmethods__["user"] = _curvefs.CreateContext_user_get
if _newclass:
user = _swig_property(_curvefs.CreateContext_user_get, _curvefs.CreateContext_user_set)
__swig_setmethods__["poolset"] = _curvefs.CreateContext_poolset_set
__swig_getmethods__["poolset"] = _curvefs.CreateContext_poolset_get
if _newclass:
poolset = _swig_property(_curvefs.CreateContext_poolset_get, _curvefs.CreateContext_poolset_set)
__swig_setmethods__["stripeUnit"] = _curvefs.CreateContext_stripeUnit_set
__swig_getmethods__["stripeUnit"] = _curvefs.CreateContext_stripeUnit_get
if _newclass:
stripeUnit = _swig_property(_curvefs.CreateContext_stripeUnit_get, _curvefs.CreateContext_stripeUnit_set)
__swig_setmethods__["stripeCount"] = _curvefs.CreateContext_stripeCount_set
__swig_getmethods__["stripeCount"] = _curvefs.CreateContext_stripeCount_get
if _newclass:
stripeCount = _swig_property(_curvefs.CreateContext_stripeCount_get, _curvefs.CreateContext_stripeCount_set)

def __init__(self):
this = _curvefs.new_CreateContext()
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
__swig_destroy__ = _curvefs.delete_CreateContext
__del__ = lambda self: None
CreateContext_swigregister = _curvefs.CreateContext_swigregister
CreateContext_swigregister(CreateContext)


def Init(path):
return _curvefs.Init(path)
Expand Down Expand Up @@ -374,14 +416,14 @@ def Unlink(filename, info):
return _curvefs.Unlink(filename, info)
Unlink = _curvefs.Unlink

def DeleteForce(filename, info):
return _curvefs.DeleteForce(filename, info)
DeleteForce = _curvefs.DeleteForce

def Recover(filename, info, fileId):
return _curvefs.Recover(filename, info, fileId)
Recover = _curvefs.Recover

def DeleteForce(filename, info):
return _curvefs.DeleteForce(filename, info)
DeleteForce = _curvefs.DeleteForce

def Listdir(dirpath, info):
return _curvefs.Listdir(dirpath, info)
Listdir = _curvefs.Listdir
Expand Down Expand Up @@ -432,8 +474,8 @@ def Close(self, fd):
def Create(self, filename, userInfo, size):
return _curvefs.CBDClient_Create(self, filename, userInfo, size)

def Create2(self, filename, userInfo, size, stripeUnit, stripeCount):
return _curvefs.CBDClient_Create2(self, filename, userInfo, size, stripeUnit, stripeCount)
def Create2(self, context):
return _curvefs.CBDClient_Create2(self, context)

def Unlink(self, filename, info):
return _curvefs.CBDClient_Unlink(self, filename, info)
Expand Down Expand Up @@ -479,6 +521,9 @@ def Rmdir(self, dirpath, info):

def GetClusterId(self):
return _curvefs.CBDClient_GetClusterId(self)

def ListPoolset(self):
return _curvefs.CBDClient_ListPoolset(self)
CBDClient_swigregister = _curvefs.CBDClient_swigregister
CBDClient_swigregister(CBDClient)

Expand Down
Loading

0 comments on commit ada6a18

Please sign in to comment.