Skip to content

Commit

Permalink
add c-styled header file to curve-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-chaojie committed May 9, 2022
1 parent 5c985ff commit 160f916
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 94 deletions.
2 changes: 1 addition & 1 deletion include/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ load("//:copts.bzl", "CURVE_DEFAULT_COPTS")

cc_library(
name = "include_client",
srcs = ["libcurve.h"],
srcs = glob(["*.h"]),
copts = CURVE_DEFAULT_COPTS,
visibility = ["//visibility:public"],
)
9 changes: 5 additions & 4 deletions src/client/libcbd.h → include/client/libcbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
* 2018/10/10 Wenyu Zhou Initial version
*/

#ifndef SRC_CLIENT_LIBCBD_H_
#define SRC_CLIENT_LIBCBD_H_
#ifndef INCLUDE_CLIENT_LIBCBD_H_
#define INCLUDE_CLIENT_LIBCBD_H_

#include "libcurve_define.h" // NOLINT

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -50,7 +52,6 @@ extern "C" {

typedef int CurveFd;

struct CurveAioContext;
typedef struct CurveOptions {
bool inited;
char* conf;
Expand Down Expand Up @@ -119,4 +120,4 @@ int cbd_libcurve_resize(const char* filename, int64_t size);
} // extern "C"
#endif

#endif // SRC_CLIENT_LIBCBD_H_
#endif // INCLUDE_CLIENT_LIBCBD_H_
87 changes: 2 additions & 85 deletions include/client/libcurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <map>
#include <string>

#include "libcurve_define.h" // NOLINT

#define IO_ALIGNED_BLOCK_SIZE 4096
#define PATH_MAX_SIZE 4096
#define NAME_MAX_SIZE 256
Expand All @@ -41,93 +43,8 @@ enum FileType {
INODE_SNAPSHOT_PAGEFILE = 4
};

enum LIBCURVE_ERROR {
// 操作成功
OK = 0,
// 文件或者目录已存在
EXISTS = 1,
// 操作失败
FAILED = 2,
// 禁止IO
DISABLEIO = 3,
// 认证失败
AUTHFAIL = 4,
// 正在删除
DELETING = 5,
// 文件不存在
NOTEXIST = 6,
// 快照中
UNDER_SNAPSHOT = 7,
// 非快照期间
NOT_UNDERSNAPSHOT = 8,
// 删除错误
DELETE_ERROR = 9,
// segment未分配
NOT_ALLOCATE = 10,
// 操作不支持
NOT_SUPPORT = 11,
// 目录非空
NOT_EMPTY = 12,
// 禁止缩容
NO_SHRINK_BIGGER_FILE = 13,
// session不存在
SESSION_NOTEXISTS = 14,
// 文件被占用
FILE_OCCUPIED = 15,
// 参数错误
PARAM_ERROR = 16,
// MDS一侧存储错误
INTERNAL_ERROR = 17,
// crc检查错误
CRC_ERROR = 18,
// request参数存在问题
INVALID_REQUEST = 19,
// 磁盘存在问题
DISK_FAIL = 20,
// 空间不足
NO_SPACE = 21,
// IO未对齐
NOT_ALIGNED = 22,
// 文件正在被关闭,fd不可用
BAD_FD = 23,
// 文件长度不满足要求
LENGTH_NOT_SUPPORT = 24,
// session不存在
SESSION_NOT_EXIST = 25,
// 状态异常
STATUS_NOT_MATCH = 26,
// 删除文件正常被克隆
DELETE_BEING_CLONED = 27,
// client版本不支持快照
CLIENT_NOT_SUPPORT_SNAPSHOT = 28,
// snapshot功能禁用中
SNAPSTHO_FROZEN = 29,
// You must retry it until success
RETRY_UNTIL_SUCCESS = 30,
// 未知错误
UNKNOWN = 100
};

const char* ErrorNum2ErrorName(LIBCURVE_ERROR err);

typedef enum LIBCURVE_OP {
LIBCURVE_OP_READ,
LIBCURVE_OP_WRITE,
LIBCURVE_OP_DISCARD,
LIBCURVE_OP_MAX,
} LIBCURVE_OP;

typedef void (*LibCurveAioCallBack)(struct CurveAioContext* context);

typedef struct CurveAioContext {
off_t offset;
size_t length;
int ret;
LIBCURVE_OP op;
LibCurveAioCallBack cb;
void* buf;
} CurveAioContext;

typedef struct FileStatInfo {
uint64_t id;
uint64_t parentid;
Expand Down
116 changes: 116 additions & 0 deletions include/client/libcurve_define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (c) 2022 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: Curve
*
* History:
* 2022/05/05 xuchaojie Initial version
*/

#ifndef INCLUDE_CLIENT_LIBCURVE_DEFINE_H_
#define INCLUDE_CLIENT_LIBCURVE_DEFINE_H_

#include <unistd.h>
#include <stdint.h>

enum LIBCURVE_ERROR {
// success
OK = 0,
// volume or dir exists
EXISTS = 1,
// failed
FAILED = 2,
// disable IO
DISABLEIO = 3,
// authentication failed
AUTHFAIL = 4,
// volume is deleting state
DELETING = 5,
// volume not exist
NOTEXIST = 6,
// under snapshot
UNDER_SNAPSHOT = 7,
// not under snapshot
NOT_UNDERSNAPSHOT = 8,
// delete error
DELETE_ERROR = 9,
// segment not allocated
NOT_ALLOCATE = 10,
// operation not supported
NOT_SUPPORT = 11,
// directory not empty
NOT_EMPTY = 12,
// no shrinkage
NO_SHRINK_BIGGER_FILE = 13,
// session not exist
SESSION_NOTEXISTS = 14,
// volume occupied
FILE_OCCUPIED = 15,
// parameter error
PARAM_ERROR = 16,
// internal error
INTERNAL_ERROR = 17,
// CRC error
CRC_ERROR = 18,
// parameter invalid
INVALID_REQUEST = 19,
// disk fail
DISK_FAIL = 20,
// not enough space
NO_SPACE = 21,
// io not aligned
NOT_ALIGNED = 22,
// volume file is being closed, fd unavailable
BAD_FD = 23,
// volume file length is not supported
LENGTH_NOT_SUPPORT = 24,
// session not exist
SESSION_NOT_EXIST = 25,
// status error
STATUS_NOT_MATCH = 26,
// delete the file being cloned
DELETE_BEING_CLONED = 27,
// this version of client not support snapshot
CLIENT_NOT_SUPPORT_SNAPSHOT = 28,
// snapshot is forbid now
SNAPSTHO_FROZEN = 29,
// You must retry it until success
RETRY_UNTIL_SUCCESS = 30,
// unknown error
UNKNOWN = 100
};

typedef enum LIBCURVE_OP {
LIBCURVE_OP_READ,
LIBCURVE_OP_WRITE,
LIBCURVE_OP_DISCARD,
LIBCURVE_OP_MAX,
} LIBCURVE_OP;


typedef void (*LibCurveAioCallBack)(struct CurveAioContext* context);

typedef struct CurveAioContext {
off_t offset;
size_t length;
int ret;
LIBCURVE_OP op;
LibCurveAioCallBack cb;
void* buf;
} CurveAioContext;

#endif // INCLUDE_CLIENT_LIBCURVE_DEFINE_H_
3 changes: 3 additions & 0 deletions mk-deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ then
fi
echo "bazel version : ${bazel_version}"


# check gcc version, gcc version must >= 4.8.5
gcc_version_major=`gcc -dumpversion | awk -F'.' '{print $1}'`
gcc_version_minor=`gcc -dumpversion | awk -F'.' '{print $2}'`
Expand Down Expand Up @@ -448,6 +449,8 @@ then
fi
cp ./bazel-bin/src/client/libcurve.so build/curve-sdk/usr/lib
cp include/client/libcurve.h build/curve-sdk/usr/include
cp include/client/libcbd.h build/curve-sdk/usr/include
cp include/client/libcurve_define.h build/curve-sdk/usr/include
if [ $? -ne 0 ]
then
exit
Expand Down
2 changes: 2 additions & 0 deletions mk-tar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ then
fi
cp ./bazel-bin/src/client/libcurve.so build/curve/curve-sdk/lib/
cp include/client/libcurve.h build/curve/curve-sdk/include
cp include/client/libcbd.h build/curve/curve-sdk/include
cp include/client/libcurve_define.h build/curve/curve-sdk/include
if [ $? -ne 0 ]
then
exit
Expand Down
1 change: 1 addition & 0 deletions src/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ cc_library(
"//proto:chunkserver-cc-protos",
"//src/client:curve_client",
"//src/common:curve_common",
"//include/client:include_client",
],
)

Expand Down
2 changes: 1 addition & 1 deletion src/client/libcbd_ext4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* 2018/10/10 Wenyu Zhou Initial version
*/

#include "src/client/libcbd.h"
#include "include/client/libcbd.h"
#include "include/client/libcurve.h"

extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/client/libcbd_libcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* 2018/10/10 Wenyu Zhou Initial version
*/

#include "src/client/libcbd.h"
#include "include/client/libcbd.h"
#include "src/client/config_info.h"
#include "include/client/libcurve.h"

Expand Down
2 changes: 1 addition & 1 deletion test/client/libcbd_ext4_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#define CBD_BACKEND_FAKE

#include "src/client/libcbd.h"
#include "include/client/libcbd.h"
#include "include/client/libcurve.h"

void LibcbdExt4TestCallback(CurveAioContext* context) {
Expand Down
2 changes: 1 addition & 1 deletion test/client/libcbd_libcurve_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

// #define CBD_BACKEND_FAKE

#include "src/client/libcbd.h"
#include "include/client/libcbd.h"

#include "src/client/libcurve_file.h"
#include "include/client/libcurve.h"
Expand Down

0 comments on commit 160f916

Please sign in to comment.