Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client/mds: merge stripe feature and unit test #211

Merged
merged 1 commit into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions curvefs_python/cbd_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit message的形式:模块名:***
client/mds:stripe feature

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

uint64_t stripeUnit, uint64_t stripeCount) {
return client_->Create2(filename, ToCurveClientUserInfo(userInfo),
size, stripeUnit, stripeCount);
}

int CBDClient::Unlink(const char* filename, UserInfo_t* userInfo) {
return client_->Unlink(filename, ToCurveClientUserInfo(userInfo));
}
Expand Down
2 changes: 2 additions & 0 deletions curvefs_python/cbd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ 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 Unlink(const char* filename, UserInfo_t* info);
int DeleteForce(const char* filename, UserInfo_t* info);
int Rename(UserInfo_t* info, const char* oldpath, const char* newpath);
Expand Down
2 changes: 2 additions & 0 deletions curvefs_python/curve_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ typedef struct FileInfo {
char filename[256];
char owner[256];
int fileStatus;
uint64_t stripeUnit;
uint64_t stripeCount;
} FileInfo_t;

typedef struct DirInfos {
Expand Down
11 changes: 11 additions & 0 deletions curvefs_python/curvefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ class FileInfo_t(_object):
__swig_getmethods__["fileStatus"] = _curvefs.FileInfo_t_fileStatus_get
if _newclass:
fileStatus = _swig_property(_curvefs.FileInfo_t_fileStatus_get, _curvefs.FileInfo_t_fileStatus_set)
__swig_setmethods__["stripeUnit"] = _curvefs.FileInfo_t_stripeUnit_set
__swig_getmethods__["stripeUnit"] = _curvefs.FileInfo_t_stripeUnit_get
if _newclass:
stripeUnit = _swig_property(_curvefs.FileInfo_t_stripeUnit_get, _curvefs.FileInfo_t_stripeUnit_set)
__swig_setmethods__["stripeCount"] = _curvefs.FileInfo_t_stripeCount_set
__swig_getmethods__["stripeCount"] = _curvefs.FileInfo_t_stripeCount_get
if _newclass:
stripeCount = _swig_property(_curvefs.FileInfo_t_stripeCount_get, _curvefs.FileInfo_t_stripeCount_set)

def __init__(self):
this = _curvefs.new_FileInfo_t()
Expand Down Expand Up @@ -420,6 +428,9 @@ 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 Unlink(self, filename, info):
return _curvefs.CBDClient_Unlink(self, filename, info)

Expand Down
7 changes: 6 additions & 1 deletion curvefs_python/curvefs_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def getRetCodeMsg(ret):
user.password = args.password

if args.optype == "create":
ret = cbd.Create(args.filename, user, args.length * kGB)
if args.stripeUnit and args.stripeCount:
ret = cbd.Create2(args.filename, user, args.length * kGB, args.stripeUnit, args.stripeCount)
else:
ret = cbd.Create(args.filename, user, args.length * kGB)
elif args.optype == "delete":
ret = cbd.Unlink(args.filename, user)
elif args.optype == "extend":
Expand All @@ -98,6 +101,8 @@ def getRetCodeMsg(ret):
print "user: " + finfo.owner
print "filename: " + finfo.filename
print "fileStatus: " + fileStatus[finfo.fileStatus]
print "stripeUnit: " + str(finfo.stripeUnit)
print "stripeCount: " + str(finfo.stripeCount)
elif args.optype == "rename":
ret = cbd.Rename(user, args.filename, args.newname)
elif args.optype == "mkdir":
Expand Down
212 changes: 207 additions & 5 deletions curvefs_python/curvefs_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3615,6 +3615,29 @@ SWIG_From_unsigned_SS_long_SS_long (unsigned long long value)
#endif


SWIGINTERN int
SWIG_AsVal_unsigned_SS_int (PyObject * obj, unsigned int *val)
{
unsigned long v;
int res = SWIG_AsVal_unsigned_SS_long (obj, &v);
if (SWIG_IsOK(res)) {
if ((v > UINT_MAX)) {
return SWIG_OverflowError;
} else {
if (val) *val = static_cast< unsigned int >(v);
}
}
return res;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一段是做什么的

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是swig -c++ -python curvefs.i自动生成的

}


SWIGINTERNINLINE PyObject*
SWIG_From_unsigned_SS_int (unsigned int value)
{
return PyInt_FromSize_t((size_t) value);
}





Expand Down Expand Up @@ -4579,11 +4602,11 @@ SWIGINTERN PyObject *_wrap_FileInfo_t_fileStatus_get(PyObject *SWIGUNUSEDPARM(se
int res1 = 0 ;
PyObject * obj0 = 0 ;
int result;

if (!PyArg_ParseTuple(args,(char *)"O:FileInfo_t_fileStatus_get",&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_FileInfo, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FileInfo_t_fileStatus_get" "', argument " "1"" of type '" "FileInfo *""'");
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FileInfo_t_fileStatus_get" "', argument " "1"" of type '" "FileInfo *""'");
}
arg1 = reinterpret_cast< FileInfo * >(argp1);
result = (int) ((arg1)->fileStatus);
Expand All @@ -4594,6 +4617,110 @@ SWIGINTERN PyObject *_wrap_FileInfo_t_fileStatus_get(PyObject *SWIGUNUSEDPARM(se
}


SWIGINTERN PyObject *_wrap_FileInfo_t_stripeUnit_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
FileInfo *arg1 = (FileInfo *) 0 ;
uint32_t arg2 ;
void *argp1 = 0 ;
int res1 = 0 ;
unsigned int val2 ;
int ecode2 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;

if (!PyArg_ParseTuple(args,(char *)"OO:FileInfo_t_stripeUnit_set",&obj0,&obj1)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_FileInfo, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FileInfo_t_stripeUnit_set" "', argument " "1"" of type '" "FileInfo *""'");
}
arg1 = reinterpret_cast< FileInfo * >(argp1);
ecode2 = SWIG_AsVal_unsigned_SS_int(obj1, &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "FileInfo_t_stripeUnit_set" "', argument " "2"" of type '" "uint32_t""'");
}
arg2 = static_cast< uint32_t >(val2);
if (arg1) (arg1)->stripeUnit = arg2;
resultobj = SWIG_Py_Void();
return resultobj;
fail:
return NULL;
}


SWIGINTERN PyObject *_wrap_FileInfo_t_stripeUnit_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
FileInfo *arg1 = (FileInfo *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
uint32_t result;

if (!PyArg_ParseTuple(args,(char *)"O:FileInfo_t_stripeUnit_get",&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_FileInfo, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FileInfo_t_stripeUnit_get" "', argument " "1"" of type '" "FileInfo *""'");
}
arg1 = reinterpret_cast< FileInfo * >(argp1);
result = (uint64_t) ((arg1)->stripeUnit);
resultobj = SWIG_From_unsigned_SS_int(static_cast< unsigned int >(result));
return resultobj;
fail:
return NULL;
}


SWIGINTERN PyObject *_wrap_FileInfo_t_stripeCount_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
FileInfo *arg1 = (FileInfo *) 0 ;
uint32_t arg2 ;
void *argp1 = 0 ;
int res1 = 0 ;
unsigned int val2 ;
int ecode2 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;

if (!PyArg_ParseTuple(args,(char *)"OO:FileInfo_t_stripeCount_set",&obj0,&obj1)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_FileInfo, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FileInfo_t_stripeCount_set" "', argument " "1"" of type '" "FileInfo *""'");
}
arg1 = reinterpret_cast< FileInfo * >(argp1);
ecode2 = SWIG_AsVal_unsigned_SS_int(obj1, &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "FileInfo_t_stripeCount_set" "', argument " "2"" of type '" "uint32_t""'");
}
arg2 = static_cast< uint32_t >(val2);
if (arg1) (arg1)->stripeCount = arg2;
resultobj = SWIG_Py_Void();
return resultobj;
fail:
return NULL;
}


SWIGINTERN PyObject *_wrap_FileInfo_t_stripeCount_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
FileInfo *arg1 = (FileInfo *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
uint32_t result;

if (!PyArg_ParseTuple(args,(char *)"O:FileInfo_t_stripeCount_get",&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_FileInfo, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FileInfo_t_stripeCount_get" "', argument " "1"" of type '" "FileInfo *""'");
}
arg1 = reinterpret_cast< FileInfo * >(argp1);
result = (uint64_t) ((arg1)->stripeCount);
resultobj = SWIG_From_unsigned_SS_int(static_cast< unsigned int >(result));
return resultobj;
fail:
return NULL;
}


SWIGINTERN PyObject *_wrap_new_FileInfo_t(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
FileInfo *result = 0 ;
Expand Down Expand Up @@ -5696,7 +5823,7 @@ SWIGINTERN PyObject *_wrap_GetClusterId(PyObject *SWIGUNUSEDPARM(self), PyObject
PyObject * obj1 = 0 ;
int result;
int retlen;

if (!PyArg_ParseTuple(args,(char *)"|OO:GetClusterId",&obj0,&obj1)) SWIG_fail;
if (obj0) {
res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1);
Expand Down Expand Up @@ -5840,7 +5967,7 @@ SWIGINTERN PyObject *_wrap_CBDClient_Open(PyObject *SWIGUNUSEDPARM(self), PyObje
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
int result;

if (!PyArg_ParseTuple(args,(char *)"OOO:CBDClient_Open",&obj0,&obj1,&obj2)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CBDClient, 0 | 0 );
if (!SWIG_IsOK(res1)) {
Expand Down Expand Up @@ -5938,7 +6065,7 @@ SWIGINTERN PyObject *_wrap_CBDClient_Create(PyObject *SWIGUNUSEDPARM(self), PyOb
ecode4 = SWIG_AsVal_size_t(obj3, &val4);
if (!SWIG_IsOK(ecode4)) {
SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "CBDClient_Create" "', argument " "4"" of type '" "size_t""'");
}
}
arg4 = static_cast< size_t >(val4);
result = (int)(arg1)->Create((char const *)arg2,arg3,arg4);
resultobj = SWIG_From_int(static_cast< int >(result));
Expand All @@ -5950,6 +6077,76 @@ SWIGINTERN PyObject *_wrap_CBDClient_Create(PyObject *SWIGUNUSEDPARM(self), PyOb
}


SWIGINTERN PyObject *_wrap_CBDClient_Create2(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
CBDClient *arg1 = (CBDClient *) 0 ;
char *arg2 = (char *) 0 ;
UserInfo_t *arg3 = (UserInfo_t *) 0 ;
size_t arg4 ;
uint32_t arg5 ;
uint32_t arg6 ;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
void *argp3 = 0 ;
int res3 = 0 ;
size_t val4 ;
int ecode4 = 0 ;
unsigned int val5 ;
int ecode5 = 0 ;
unsigned int val6 ;
int ecode6 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
PyObject * obj3 = 0 ;
PyObject * obj4 = 0 ;
PyObject * obj5 = 0 ;
int result;

if (!PyArg_ParseTuple(args,(char *)"OOOOOO:CBDClient_Create2",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CBDClient, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CBDClient_Create2" "', argument " "1"" of type '" "CBDClient *""'");
}
arg1 = reinterpret_cast< CBDClient * >(argp1);
res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CBDClient_Create2" "', argument " "2"" of type '" "char const *""'");
}
arg2 = reinterpret_cast< char * >(buf2);
res3 = SWIG_ConvertPtr(obj2, &argp3,SWIGTYPE_p_UserInfo, 0 | 0 );
if (!SWIG_IsOK(res3)) {
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "CBDClient_Create2" "', argument " "3"" of type '" "UserInfo_t *""'");
}
arg3 = reinterpret_cast< UserInfo_t * >(argp3);
ecode4 = SWIG_AsVal_size_t(obj3, &val4);
if (!SWIG_IsOK(ecode4)) {
SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "CBDClient_Create2" "', argument " "4"" of type '" "size_t""'");
}
arg4 = static_cast< size_t >(val4);
ecode5 = SWIG_AsVal_unsigned_SS_int(obj4, &val5);
if (!SWIG_IsOK(ecode5)) {
SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "CBDClient_Create2" "', argument " "5"" of type '" "uint32_t""'");
}
arg5 = static_cast< uint32_t >(val5);
ecode6 = SWIG_AsVal_unsigned_SS_int(obj5, &val6);
if (!SWIG_IsOK(ecode6)) {
SWIG_exception_fail(SWIG_ArgError(ecode6), "in method '" "CBDClient_Create2" "', argument " "6"" of type '" "uint32_t""'");
}
arg6 = static_cast< uint32_t >(val6);
result = (int)(arg1)->Create2((char const *)arg2,arg3,arg4,arg5,arg6);
resultobj = SWIG_From_int(static_cast< int >(result));
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
return resultobj;
fail:
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
return NULL;
}


SWIGINTERN PyObject *_wrap_CBDClient_Unlink(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
CBDClient *arg1 = (CBDClient *) 0 ;
Expand Down Expand Up @@ -6748,6 +6945,10 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"FileInfo_t_owner_get", _wrap_FileInfo_t_owner_get, METH_VARARGS, NULL},
{ (char *)"FileInfo_t_fileStatus_set", _wrap_FileInfo_t_fileStatus_set, METH_VARARGS, NULL},
{ (char *)"FileInfo_t_fileStatus_get", _wrap_FileInfo_t_fileStatus_get, METH_VARARGS, NULL},
{ (char *)"FileInfo_t_stripeUnit_set", _wrap_FileInfo_t_stripeUnit_set, METH_VARARGS, NULL},
{ (char *)"FileInfo_t_stripeUnit_get", _wrap_FileInfo_t_stripeUnit_get, METH_VARARGS, NULL},
{ (char *)"FileInfo_t_stripeCount_set", _wrap_FileInfo_t_stripeCount_set, METH_VARARGS, NULL},
{ (char *)"FileInfo_t_stripeCount_get", _wrap_FileInfo_t_stripeCount_get, METH_VARARGS, NULL},
{ (char *)"new_FileInfo_t", _wrap_new_FileInfo_t, METH_VARARGS, NULL},
{ (char *)"delete_FileInfo_t", _wrap_delete_FileInfo_t, METH_VARARGS, NULL},
{ (char *)"FileInfo_t_swigregister", FileInfo_t_swigregister, METH_VARARGS, NULL},
Expand Down Expand Up @@ -6792,6 +6993,7 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"CBDClient_Open", _wrap_CBDClient_Open, METH_VARARGS, NULL},
{ (char *)"CBDClient_Close", _wrap_CBDClient_Close, METH_VARARGS, NULL},
{ (char *)"CBDClient_Create", _wrap_CBDClient_Create, METH_VARARGS, NULL},
{ (char *)"CBDClient_Create2", _wrap_CBDClient_Create2, METH_VARARGS, NULL},
{ (char *)"CBDClient_Unlink", _wrap_CBDClient_Unlink, METH_VARARGS, NULL},
{ (char *)"CBDClient_DeleteForce", _wrap_CBDClient_DeleteForce, METH_VARARGS, NULL},
{ (char *)"CBDClient_Rename", _wrap_CBDClient_Rename, METH_VARARGS, NULL},
Expand Down
2 changes: 2 additions & 0 deletions curvefs_python/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def get_parser():
subparser.add_argument("--length", help='length of file(GB)', type=long, required=True)
subparser.add_argument("--user", help='user of file', type=str, required=True)
subparser.add_argument("--password", help='password of user', type=str)
subparser.add_argument("--stripeUnit", help='stripe unit size', type=long)
subparser.add_argument("--stripeCount", help='stripe width', type=long)

# delete option
subparser = subparsers.add_parser("delete", help="delete file")
Expand Down
16 changes: 16 additions & 0 deletions include/client/libcurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ typedef struct FileStatInfo {
char filename[NAME_MAX_SIZE];
char owner[NAME_MAX_SIZE];
int fileStatus;
uint64_t stripeUnit;
uint64_t stripeCount;
} FileStatInfo_t;

// 存储用户信息
Expand Down Expand Up @@ -195,6 +197,20 @@ int Create(const char* filename,
const C_UserInfo_t* userinfo,
size_t size);

/**
* create file with stripe
* @param: filename file name
* @param: userinfo user info
* @param: size file size
* @param: stripeUnit block in stripe size
* @param: stripeCount stripe count in one stripe
*
* @return: success return 0, fail return less than 0
*/
int Create2(const char* filename,
const C_UserInfo_t* userinfo,
size_t size, uint64_t stripeUnit, uint64_t stripeCount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个用uint32_t就行了吧

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑扩展性,可不改


/**
* 同步模式读
* @param: fd为当前open返回的文件描述符
Expand Down
Loading