diff --git a/include/client/BUILD b/include/client/BUILD index 0a0856ae01..30f4037f8b 100644 --- a/include/client/BUILD +++ b/include/client/BUILD @@ -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"], ) diff --git a/src/client/libcbd.h b/include/client/libcbd.h similarity index 96% rename from src/client/libcbd.h rename to include/client/libcbd.h index 196534e2fd..19670e92b1 100644 --- a/src/client/libcbd.h +++ b/include/client/libcbd.h @@ -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" { @@ -50,7 +52,6 @@ extern "C" { typedef int CurveFd; -struct CurveAioContext; typedef struct CurveOptions { bool inited; char* conf; @@ -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_ diff --git a/include/client/libcurve.h b/include/client/libcurve.h index cd16f55eb4..3b50ee97d0 100644 --- a/include/client/libcurve.h +++ b/include/client/libcurve.h @@ -29,6 +29,8 @@ #include #include +#include "libcurve_define.h" // NOLINT + #define IO_ALIGNED_BLOCK_SIZE 4096 #define PATH_MAX_SIZE 4096 #define NAME_MAX_SIZE 256 @@ -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; diff --git a/include/client/libcurve_define.h b/include/client/libcurve_define.h new file mode 100644 index 0000000000..70e3a1c29d --- /dev/null +++ b/include/client/libcurve_define.h @@ -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 +#include + +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_ diff --git a/mk-deb.sh b/mk-deb.sh index 0d4500687a..3ade848c79 100644 --- a/mk-deb.sh +++ b/mk-deb.sh @@ -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}'` @@ -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 diff --git a/mk-tar.sh b/mk-tar.sh index 3bd23c3e09..7fe26508a1 100644 --- a/mk-tar.sh +++ b/mk-tar.sh @@ -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 diff --git a/src/client/BUILD b/src/client/BUILD index b4812a3dd1..440e533c5b 100644 --- a/src/client/BUILD +++ b/src/client/BUILD @@ -74,6 +74,7 @@ cc_library( "//proto:chunkserver-cc-protos", "//src/client:curve_client", "//src/common:curve_common", + "//include/client:include_client", ], ) diff --git a/src/client/libcbd_ext4.cpp b/src/client/libcbd_ext4.cpp index 185d5e79b3..a997a9a460 100644 --- a/src/client/libcbd_ext4.cpp +++ b/src/client/libcbd_ext4.cpp @@ -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" { diff --git a/src/client/libcbd_libcurve.cpp b/src/client/libcbd_libcurve.cpp index 7515e55371..d1aa2ef0ac 100644 --- a/src/client/libcbd_libcurve.cpp +++ b/src/client/libcbd_libcurve.cpp @@ -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" diff --git a/test/client/libcbd_ext4_test.cpp b/test/client/libcbd_ext4_test.cpp index 5e1657f368..30470b2a35 100644 --- a/test/client/libcbd_ext4_test.cpp +++ b/test/client/libcbd_ext4_test.cpp @@ -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) { diff --git a/test/client/libcbd_libcurve_test.cpp b/test/client/libcbd_libcurve_test.cpp index dcbe6d4d57..e7a5150df1 100644 --- a/test/client/libcbd_libcurve_test.cpp +++ b/test/client/libcbd_libcurve_test.cpp @@ -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"