From 5d54ac1271bf3f3d5a965d39490b33eb143c0a2c Mon Sep 17 00:00:00 2001 From: songyuhang Date: Tue, 15 Nov 2022 13:57:40 +0800 Subject: [PATCH 1/2] update libproxy and libosa data-11-15 --- src/ceph_proxy/CephExport.h | 7 -- src/ceph_proxy/CephProxy.cc | 9 +- src/ceph_proxy/CephProxyInterface.cc | 57 ++++----- src/ceph_proxy/Gcbufferlist.h | 4 +- src/ceph_proxy/RadosMonitor.cc | 109 +++++++++++++---- src/ceph_proxy/RadosWorker.cc | 4 +- src/ceph_proxy/RadosWorker.h | 3 +- src/ceph_proxy/RadosWrapper.cc | 107 +++++++--------- src/ceph_proxy/RbdWrapper.cc | 169 +++++++++----------------- src/server_adaptor/class_api.cc | 98 +++++++-------- src/server_adaptor/msg_module.cpp | 7 +- src/server_adaptor/network_module.cpp | 122 ++++++++++++++++--- src/server_adaptor/osa.cpp | 58 ++++++--- 13 files changed, 431 insertions(+), 323 deletions(-) diff --git a/src/ceph_proxy/CephExport.h b/src/ceph_proxy/CephExport.h index 1d03c92..79a8ded 100644 --- a/src/ceph_proxy/CephExport.h +++ b/src/ceph_proxy/CephExport.h @@ -21,13 +21,6 @@ PROXY_API_PUBLIC int CephLibrbdSnapRemove(int64_t pool_id, uint64_t snap_id, bool force); -int CephLibrbdGetPoolName(std::string& pool_name, int64_t pool_id, - const std::string& namespace_name); - -int CephLibrbdGetImageName(const std::string& pool_name, int64_t pool_id, - const std::string& image_id, std::string& image_name, - const std::string& namespace_name); - PROXY_API_PUBLIC int CephLibrbdGetImageInfo(int64_t pool_id, const char *_image_id, int32_t *num_objs); diff --git a/src/ceph_proxy/CephProxy.cc b/src/ceph_proxy/CephProxy.cc index bb1e6cf..5a78d25 100644 --- a/src/ceph_proxy/CephProxy.cc +++ b/src/ceph_proxy/CephProxy.cc @@ -80,7 +80,14 @@ int CephProxy::Init(const std::string &cephConf, char *savep; p = strtok_r(tmp.get(), delim, &savep); while (p) { - vecCoreId.push_back(atoi(p)); + errno = 0; + char *end = nullptr; + uint32_t id = (uint32_t)strtol(p, &end, 10); + if (errno == ERANGE || end == p) { + ProxyDbgLogErr("get core id failed."); + return -1; + } + vecCoreId.push_back(id); p = strtok_r(nullptr, delim, &savep); } RadosBindMsgrWorker(vecCoreId, pid); diff --git a/src/ceph_proxy/CephProxyInterface.cc b/src/ceph_proxy/CephProxyInterface.cc index 5276d27..72aa3c0 100644 --- a/src/ceph_proxy/CephProxyInterface.cc +++ b/src/ceph_proxy/CephProxyInterface.cc @@ -12,8 +12,7 @@ #include #include -int CephProxyInit(const char *conf, size_t wNum, const char *log, - ceph_proxy_t *proxy) +int CephProxyInit(const char *conf, size_t wNum, const char *log, ceph_proxy_t *proxy) { int ret = 0; if (conf == nullptr || log == nullptr || proxy == nullptr) { @@ -199,7 +198,8 @@ int CephProxyWriteOpInit2(ceph_proxy_op_t *op, const int64_t poolId, const char* return 0; } -void CephProxyWriteOpRelease(ceph_proxy_op_t op) { +void CephProxyWriteOpRelease(ceph_proxy_op_t op) +{ RadosWriteOpRelease(op); } @@ -218,26 +218,24 @@ void CephProxyWriteOpAssertVersion(ceph_proxy_op_t op, uint64_t ver) RadosWriteOpAssertVersion(op, ver); } -void CephProxyWriteOpCmpext(ceph_proxy_op_t op, const char *cmpBuf, - size_t cmpLen, uint64_t off, int *prval) +void CephProxyWriteOpCmpext(ceph_proxy_op_t op, const char *cmpBuf, size_t cmpLen, uint64_t off, int *prval) { RadosWriteOpCmpext(op, cmpBuf, cmpLen, off ,prval); } -void CephProxyWriteOpCmpXattr(ceph_proxy_op_t op, const char *name, - uint8_t compOperator, const char *value, size_t valLen) +void CephProxyWriteOpCmpXattr(ceph_proxy_op_t op, const char *name, uint8_t compOperator, const char *value, + size_t valLen) { RadosWriteOpCmpXattr(op, name ,compOperator, value, valLen); } -void CephProxyWriteOpOmapCmp(ceph_proxy_op_t op, const char *key, uint8_t compOperator, - const char *value, size_t valLen, int *prval) +void CephProxyWriteOpOmapCmp(ceph_proxy_op_t op, const char *key, uint8_t compOperator, const char *value, + size_t valLen, int *prval) { RadosWriteOpOmapCmp(op, key, compOperator, value, valLen, prval); } -void CephProxyWriteOpSetXattr(ceph_proxy_op_t op, const char *name, - const char *value, size_t valLen) +void CephProxyWriteOpSetXattr(ceph_proxy_op_t op, const char *name, const char *value, size_t valLen) { RadosWriteOpSetXattr(op, name, value, valLen); } @@ -257,7 +255,8 @@ void CephProxyWriteOpWrite(ceph_proxy_op_t op, const char *buffer, size_t len, u RadosWriteOpWrite(op, buffer, len, off); } -void CephProxyWriteOpWriteBl(ceph_proxy_op_t op, void *s, size_t len1, uint64_t off, AlignBuffer *alignBuffer, int isRelease) +void CephProxyWriteOpWriteBl(ceph_proxy_op_t op, void *s, size_t len1, uint64_t off, AlignBuffer *alignBuffer, + int isRelease) { RadosWriteOpWriteBl(op, static_cast(s), len1, off, alignBuffer, isRelease); } @@ -267,8 +266,8 @@ void CephProxyWriteOpRemove(ceph_proxy_op_t op) RadosWriteOpRemove(op); } -void CephProxyWriteOpOmapSet(ceph_proxy_op_t op, char const* const* keys, - char const* const* vals, const size_t *lens, size_t num) +void CephProxyWriteOpOmapSet(ceph_proxy_op_t op, char const* const* keys, char const* const* vals, + const size_t *lens, size_t num) { RadosWriteOpOmapSet(op, keys, vals, lens, num); } @@ -283,8 +282,8 @@ void CephProxyWriteOpOmapClear(ceph_proxy_op_t op) RadosWriteOpOmapClear(op); } -void CephProxyWriteOpSetAllocHint(ceph_proxy_op_t op, uint64_t expectedObjSize, - uint64_t expectedWriteSize, uint32_t flags) +void CephProxyWriteOpSetAllocHint(ceph_proxy_op_t op, uint64_t expectedObjSize, uint64_t expectedWriteSize, + uint32_t flags) { RadosWriteOpSetAllocHint(op, expectedObjSize, expectedWriteSize, flags); } @@ -324,14 +323,13 @@ void CephProxyReadOpAssertVersion(ceph_proxy_op_t op, uint64_t ver) RadosReadOpAssertVersion(op, ver); } -void CephProxyReadOpCmpext(ceph_proxy_op_t op, const char *cmpBuf, - size_t cmpLen, uint64_t off, int *prval) +void CephProxyReadOpCmpext(ceph_proxy_op_t op, const char *cmpBuf, size_t cmpLen, uint64_t off, int *prval) { RadosReadOpCmpext(op, cmpBuf, cmpLen, off, prval); } -void CephProxyReadOpCmpXattr(ceph_proxy_op_t op, const char *name, - uint8_t compOperator, const char *value, size_t valueLen) +void CephProxyReadOpCmpXattr(ceph_proxy_op_t op, const char *name, uint8_t compOperator, const char *value, + size_t valueLen) { RadosReadOpCmpXattr(op, name, compOperator, value, valueLen); } @@ -341,8 +339,8 @@ void CephProxyReadOpGetXattrs(ceph_proxy_op_t op, proxy_xattrs_iter_t *iter, int RadosReadOpGetXattrs(op, iter, prval); } -void CephProxyReadOpOmapCmp(ceph_proxy_op_t op, const char *key, - uint8_t compOperator, const char *val, size_t valLen, int *prval) +void CephProxyReadOpOmapCmp(ceph_proxy_op_t op, const char *key, uint8_t compOperator, const char *val, size_t valLen, + int *prval) { RadosReadOpOmapCmp(op, key, compOperator, val, valLen, prval); } @@ -352,8 +350,7 @@ void CephProxyReadOpStat(ceph_proxy_op_t op, uint64_t *psize, time_t *pmtime, in RadosReadOpStat(op, psize, pmtime, prval); } -void CephProxyReadOpRead(ceph_proxy_op_t op, uint64_t offset, size_t len, - char *buffer, size_t *bytesRead, int *prval) +void CephProxyReadOpRead(ceph_proxy_op_t op, uint64_t offset, size_t len, char *buffer, size_t *bytesRead, int *prval) { RadosReadOpRead(op, offset, len, buffer, bytesRead, prval); } @@ -363,19 +360,19 @@ void CephProxyReadOpReadBl(ceph_proxy_op_t op, uint64_t offset, size_t len, void RadosReadOpReadBl(op, offset, len , static_cast(s), prval, isRelease); } -void CephProxyReadOpCheckSum(ceph_proxy_op_t op, proxy_checksum_type_t type, - const char *initValue, size_t initValueLen, - uint64_t offset, size_t len, size_t chunkSize, char *pCheckSum, - size_t CheckSumLen, int *prval) +void CephProxyReadOpCheckSum(ceph_proxy_op_t op, proxy_checksum_type_t type, const char *initValue, size_t initValueLen, + uint64_t offset, size_t len, size_t chunkSize, char *pCheckSum, size_t CheckSumLen, int *prval) { RadosReadOpCheckSum(op ,type, initValue, initValueLen, offset, len, chunkSize, pCheckSum, CheckSumLen, prval); } -completion_t CephProxyCreateCompletion(CallBack_t fn, void *arg) { +completion_t CephProxyCreateCompletion(CallBack_t fn, void *arg) +{ return CompletionInit(fn, arg); } -void CephProxyCompletionDestroy(completion_t c) { +void CephProxyCompletionDestroy(completion_t c) +{ CompletionDestroy(c); } diff --git a/src/ceph_proxy/Gcbufferlist.h b/src/ceph_proxy/Gcbufferlist.h index 72e54d2..d7bc090 100644 --- a/src/ceph_proxy/Gcbufferlist.h +++ b/src/ceph_proxy/Gcbufferlist.h @@ -10,12 +10,12 @@ typedef struct ListEntryType uint32_t len; } ListEntry; -#define ENTRY_PER_BUFFERLIST 64 +#define ENTRY_PER_BUFFLIST 64 typedef struct GcBufferListType { struct GcBufferListType *nextBufferList; uint16_t entrySumList; - ListEntry entrys[ENTRY_PER_BUFFERLIST]; + ListEntry entrys[ENTRY_PER_BUFFLIST]; } GcBufferList; #endif \ No newline at end of file diff --git a/src/ceph_proxy/RadosMonitor.cc b/src/ceph_proxy/RadosMonitor.cc index 766357b..1322a40 100644 --- a/src/ceph_proxy/RadosMonitor.cc +++ b/src/ceph_proxy/RadosMonitor.cc @@ -50,7 +50,14 @@ void TransStrToNum(std::string strNum, uint64_t &num) std::smatch result; bool flag = std::regex_match(strNum, result, pattern); if (flag) { - uint32_t size = atoi(result[1].str().c_str()); + errno = 0; + char *end = nullptr; + const char *p = result[1].str().c_str(); + uint32_t size = (uint32_t)strtol(p, &end, 10); + if (errno == ERANGE || end == p) { + ProxyDbgLogErr("get size failed."); + return; + } uint64_t unit = TransStrUnitToNum(result[2].str().c_str()); num = size * unit; } else { @@ -123,7 +130,7 @@ int32_t PoolUsageStat::GetPoolInfo(uint32_t poolId, struct PoolInfo *info) int32_t PoolUsageStat::IsECPool(string poolName, string &ecProfile, bool &isEC) { - librados::Rados *rados = reinterpret_cast(proxy->radosClient); + librados::Rados *rados = static_cast(proxy->radosClient); std::string cmd("{\"var\": \"erasure_code_profile\", \"prefix\": \"osd pool get\", \"pool\": \""); std::string outs; bufferlist inbl; @@ -158,11 +165,12 @@ int32_t PoolUsageStat::IsECPool(string poolName, string &ecProfile, bool &isEC) int32_t PoolUsageStat::GetECProfileSize(std::string profileName, uint32_t &k, uint32_t &m, uint32_t &stripeUnit) { - librados::Rados *rados = reinterpret_cast(proxy->radosClient); + librados::Rados *rados = static_cast(proxy->radosClient); std::string cmd("{\"prefix\": \"osd erasure-code-profile get\", \"name\": \""); std::string outs; bufferlist inbl; bufferlist outbl; + char *strs = nullptr; cmd.append(profileName); cmd.append(string("\"}")); @@ -180,14 +188,18 @@ int32_t PoolUsageStat::GetECProfileSize(std::string profileName, uint32_t &k, ui } std::vector infoVector; - char *strs = new char[outbl.to_str().size() + 1]; + strs = new(std::nothrow) char[outbl.to_str().size() + 1]; + if (strs == nullptr) { + ProxyDbgLogErr("malloc failed"); + return -ENOMEM; + } strcpy(strs, outbl.c_str()); - - char *p = strtok(strs, "\n"); + char *savep; + char *p = strtok_r(strs, "\n", &savep); while (p) { string s = p; infoVector.push_back(s); - p = strtok(NULL, "\n"); + p = strtok_r(nullptr, "\n", &savep); } for (uint32_t i = 0; i < infoVector.size(); i++) { @@ -208,10 +220,20 @@ void PoolUsageStat::ParseECProfile(string &profile, uint32_t &k, uint32_t &m, ui if (!flag) { return; } + errno = 0; + char *end = nullptr; if (result[1].str().compare("k") == 0) { - k = atoi(result[2].str().c_str()); + const char *p = result[2].str().c_str(); + k = (uint32_t)strtol(p, &end, 10); + if (errno == ERANGE || end == p) { + return; + } } else if (result[1].str().compare("m") == 0) { - m = atoi(result[2].str().c_str()); + const char *p = result[2].str().c_str(); + m = (uint32_t)strtol(p, &end, 10); + if (errno == ERANGE || end == p) { + return; + } } else if (result[1].str().compare("stripe_unit") == 0) { uint64_t val = 0; TransStrToNum(result[2].str().c_str(), val); @@ -227,7 +249,7 @@ uint32_t PoolUsageStat::GetDefaultECStripeUnit() uint32_t stripeUnit = defaultStripeUnit; uint64_t num = 0; - librados::Rados *rados = reinterpret_cast(proxy->radosClient); + librados::Rados *rados = static_cast(proxy->radosClient); std::string cmd("{\"prefix\": \"config get\", \"who\": " \ "\"osd.-1\", \"key\": \"osd_pool_erasure_code_stripe_unit\"}"); std::string outs; @@ -273,6 +295,30 @@ int32_t PoolUsageStat::GetPoolReplicationSize(uint32_t poolId, double& rep) return 0; } +static int StrToDouble(const char *src, double &dest, const char *print) +{ + errno = 0; + char *end = nullptr; + dest = strtod(src, &end); + if (errno == ERANGE || end == src) { + ProxyDbgLogErr("get %s from str failed.", print); + return -1; + } + return 0; +} + +static int StrToInt(const char *src, int &dest, const char *print) +{ + errno = 0; + char *end = nullptr; + dest = (int)strtol(src, &end, 10); + if (errno == ERANGE || end == src) { + ProxyDbgLogErr("get %s from str failed.", print); + return -1; + } + return 0; +} + int32_t PoolUsageStat::ParseToRecordInfo(std::smatch& result, struct RecordInfo &info) { // @@ -281,17 +327,24 @@ int32_t PoolUsageStat::ParseToRecordInfo(std::smatch& result, struct RecordInfo info.poolName = result[i].str().c_str(); } if (i == 2) { - int id = atoi(result[i].str().c_str()); + int id; + if (StrToInt(result[i].str().c_str(), id, "poolId") != 0) { + return -1; + } if (id < 0) { return -1; } info.poolId = (uint32_t)id; } else if (i == 3) { - info.storedSize = atof(result[i].str().c_str()); + if (StrToDouble(result[i].str().c_str(), info.storedSize, "storedSize") != 0) { + return -1; + } } else if (i == 4) { info.storedSizeUnit = TransStrUnitToNum(result[i].str().c_str()); } else if (i == 5) { - info.objectsNum = atof(result[i].str().c_str()); + if (StrToDouble(result[i].str().c_str(), info.objectsNum, "objectsNum") != 0) { + return -1; + } } else if (i == 6) { if (result[i].length() == 0) { info.numUnit = 1; @@ -301,13 +354,19 @@ int32_t PoolUsageStat::ParseToRecordInfo(std::smatch& result, struct RecordInfo info.numUnit = 1024 * 1024; } } else if (i == 7) { - info.usedSize = atof(result[i].str().c_str()); + if (StrToDouble(result[i].str().c_str(), info.usedSize, "usedSize") != 0) { + return -1; + } } else if (i == 8) { info.usedSizeUnit = TransStrUnitToNum(result[i].str().c_str()); } else if (i == 9) { - info.useRatio = atof(result[i].str().c_str()); + if (StrToDouble(result[i].str().c_str(), info.useRatio, "useRatio") != 0) { + return -1; + } } else if (i == 10) { - info.maxAvail = atof(result[i].str().c_str()); + if (StrToDouble(result[i].str().c_str(), info.maxAvail, "maxAvail") != 0) { + return -1; + } } else if (i == 11) { info.maxAvailUnit = TransStrUnitToNum(result[i].str().c_str()); } @@ -426,16 +485,20 @@ static int GetPoolStorageUsage(PoolUsageStat *mgr, const char *input) { std::string pattern = poolNamePattern + poolIdPattern + storedPattern + objectsPattern + usedPattern + usedRatioPattern + availPattern; - + char *strs = nullptr; std::vector infoVector; - char *strs = new char[strlen(input) + 1]; + strs = new(std::nothrow) char[strlen(input) + 1]; + if (strs == nullptr) { + ProxyDbgLogErr("malloc failed"); + return -ENOMEM; + } strcpy(strs, input); - - char *p = strtok(strs, "\n"); + char *savep; + char *p = strtok_r(strs, "\n", &savep); while (p) { string s = p; - infoVector.push_back(s); - p = strtok(NULL, "\n"); + infoVector.push_back(s); + p = strtok_r(nullptr, "\n", &savep); } for (size_t i = 0; i < infoVector.size(); i++) { @@ -495,7 +558,7 @@ int32_t PoolUsageStat::UpdatePoolList(void) int PoolUsageStat::UpdatePoolUsage(void) { - librados::Rados *rados = reinterpret_cast(proxy->radosClient); + librados::Rados *rados = static_cast(proxy->radosClient); std::string cmd("{\"prefix\":\"df\"}"); std::string outs; bufferlist inbl; diff --git a/src/ceph_proxy/RadosWorker.cc b/src/ceph_proxy/RadosWorker.cc index 8c4ddca..8423072 100644 --- a/src/ceph_proxy/RadosWorker.cc +++ b/src/ceph_proxy/RadosWorker.cc @@ -58,7 +58,7 @@ int32_t RadosIOWorker::Queue(ceph_proxy_op_t op, completion_t c) reqCtx.op = op; reqCtx.comp = c; - RadosObjectOperation *operation = reinterpret_cast(op); + RadosObjectOperation *operation = static_cast(op); if (Ops.size() > IO_WORKER_QUEUE_MAX_COUNT) { ProxyDbgLogErr("Too many requests are stacked in the IOWorker Queue, ops.size = %d, poolId: %d.", Ops.size(), operation->poolId); @@ -88,7 +88,7 @@ void* RadosIOWorker::OpHandler() { for (auto opair : ls) { Completion *c = static_cast(opair.comp); - RadosObjectOperation *operation = reinterpret_cast(opair.op); + RadosObjectOperation *operation = static_cast(opair.op); rados_ioctx_t ioctx = proxy->GetIoCtx2(operation->poolId); if (ioctx == NULL) { ProxyDbgLogWarnLimit1("Get IOCtx(%u) Failed.", operation->poolId); diff --git a/src/ceph_proxy/RadosWorker.h b/src/ceph_proxy/RadosWorker.h index e06f6f8..ac207a2 100644 --- a/src/ceph_proxy/RadosWorker.h +++ b/src/ceph_proxy/RadosWorker.h @@ -313,9 +313,10 @@ public: } int32_t Queue(ceph_proxy_op_t op, completion_t c) { - RadosObjectOperation *operation = reinterpret_cast(op); + RadosObjectOperation *operation = static_cast(op); if (operation == nullptr || c == nullptr) { ProxyDbgLogErr("operation %p or c %p is invalid", operation, c); + return -1; } if (operation->poolId < 0) { ProxyDbgLogErr("invalid poolId: %ld", operation->poolId); diff --git a/src/ceph_proxy/RadosWrapper.cc b/src/ceph_proxy/RadosWrapper.cc index 0c9b420..85b9a5e 100644 --- a/src/ceph_proxy/RadosWrapper.cc +++ b/src/ceph_proxy/RadosWrapper.cc @@ -187,7 +187,7 @@ int RadosClientInit(rados_client_t *client,const std::string &cephConf) ProxyDbgLogErr("set conf failed: %d", ProxyGetCephKeyring(), ret); goto client_init_out; } - ProxyDbgLogInfo("set config success.", ProxyGetCephKeyring()); + ProxyDbgLogInfo("set config success.", ProxyGetCephKeyring()); } ret = rados->conf_set(ProxyGetMonTimeOutOption(), str.c_str()); @@ -530,8 +530,7 @@ void RadosWriteOpAssertVersion(rados_op_t op, uint64_t ver) writeOp->op.assert_version(ver); } -void RadosWriteOpCmpext(rados_op_t op, const char *cmpBuf, - size_t cmpLen, uint64_t off, int *prval) +void RadosWriteOpCmpext(rados_op_t op, const char *cmpBuf, size_t cmpLen, uint64_t off, int *prval) { RadosObjectWriteOp *writeOp = static_cast(op); bufferlist cmpBl; @@ -539,8 +538,7 @@ void RadosWriteOpCmpext(rados_op_t op, const char *cmpBuf, writeOp->op.cmpext(off, cmpBl, prval); } -void RadosWriteOpCmpXattr(rados_op_t op, const char *name, - uint8_t compOperator, const char *value, size_t valLen) +void RadosWriteOpCmpXattr(rados_op_t op, const char *name, uint8_t compOperator, const char *value, size_t valLen) { RadosObjectWriteOp *writeOp = static_cast(op); bufferlist valueBl; @@ -548,8 +546,8 @@ void RadosWriteOpCmpXattr(rados_op_t op, const char *name, writeOp->op.cmpxattr(name, compOperator, valueBl); } -void RadosWriteOpOmapCmp(rados_op_t op, const char *key, uint8_t compOperator, - const char *value, size_t valLen, int *prval) +void RadosWriteOpOmapCmp(rados_op_t op, const char *key, uint8_t compOperator, const char *value, size_t valLen, + int *prval) { RadosObjectWriteOp *writeOp = static_cast(op); bufferlist bl; @@ -595,7 +593,8 @@ void RadosWriteOpWrite(rados_op_t op, const char *buffer, size_t len, uint64_t o PROXY_FTDS_END_HIGH(PROXY_FTDS_OPS_OPINIT_WRITE, ts, ret); } -void RadosWriteOpWriteBl(rados_op_t op, GcBufferList *bl, size_t len1, uint64_t off, AlignBuffer *alignBuffer, int isRelease) +void RadosWriteOpWriteBl(rados_op_t op, GcBufferList *bl, size_t len1, uint64_t off, AlignBuffer *alignBuffer, + int isRelease) { uint64_t ts = 0; int32_t ret = 0; @@ -610,9 +609,7 @@ void RadosWriteOpWriteBl(rados_op_t op, GcBufferList *bl, size_t len1, uint64_t uint32_t curSrcEntryIndex = 0; // - if (alignBuffer != NULL && - alignBuffer->prevAlignBuffer != NULL && - alignBuffer->prevAlignLen != 0) { + if (alignBuffer != NULL && alignBuffer->prevAlignBuffer != NULL && alignBuffer->prevAlignLen != 0) { writeOp->bl.append(alignBuffer->prevAlignBuffer, alignBuffer->prevAlignLen); } @@ -634,9 +631,7 @@ void RadosWriteOpWriteBl(rados_op_t op, GcBufferList *bl, size_t len1, uint64_t } // - if (alignBuffer != NULL && - alignBuffer->backAlignBuffer != NULL && - alignBuffer->backAlignLen != 0) { + if (alignBuffer != NULL && alignBuffer->backAlignBuffer != NULL && alignBuffer->backAlignLen != 0) { writeOp->bl.append(alignBuffer->backAlignBuffer, alignBuffer->backAlignLen); } @@ -660,8 +655,8 @@ void RadosWriteOpRemove(rados_op_t op) PROXY_FTDS_END_HIGH(PROXY_FTDS_OPS_OPINIT_REMOVE, ts, ret); } -void RadosWriteOpOmapSet(rados_op_t op, const char *const *keys, - const char *const *vals, const size_t *lens, size_t num) +void RadosWriteOpOmapSet(rados_op_t op, const char *const *keys, const char *const *vals, const size_t *lens, + size_t num) { RadosObjectWriteOp *writeOp = static_cast(op); std::map entries; @@ -743,8 +738,7 @@ void RadosReadOpAssertVersion(rados_op_t op, uint64_t ver) readOp->op.assert_version(ver); } -void RadosReadOpCmpext(rados_op_t op, const char *cmpBuf, - size_t cmpLen, uint64_t off, int *prval) +void RadosReadOpCmpext(rados_op_t op, const char *cmpBuf, size_t cmpLen, uint64_t off, int *prval) { RadosObjectReadOp *readOp=static_cast(op); bufferlist bl; @@ -752,8 +746,7 @@ void RadosReadOpCmpext(rados_op_t op, const char *cmpBuf, readOp->op.cmpext(off, bl, prval); } -void RadosReadOpCmpXattr(rados_op_t op, const char *name, uint8_t compOperator, - const char *value, size_t valueLen) +void RadosReadOpCmpXattr(rados_op_t op, const char *name, uint8_t compOperator, const char *value, size_t valueLen) { RadosObjectReadOp *readOp=static_cast(op); bufferlist bl; @@ -823,8 +816,7 @@ void RadosGetXattrsEnd(proxy_xattrs_iter_t iter) delete it; } -void RadosReadOpOmapGetVals(rados_op_t op, const char *startAfter, - uint64_t maxReturn, rados_omap_iter_t *iter, +void RadosReadOpOmapGetVals(rados_op_t op, const char *startAfter, uint64_t maxReturn, rados_omap_iter_t *iter, unsigned char *pmore, int *prval) { RadosObjectReadOp *readOp = static_cast(op); @@ -839,8 +831,8 @@ void RadosReadOpOmapGetVals(rados_op_t op, const char *startAfter, *iter = oIter; } -void RadosReadOpOmapGetKeys(rados_op_t op, const char *startAfter, uint64_t maxReturn, - proxy_omap_iter_t *iter, unsigned char *pmore, int *prval) +void RadosReadOpOmapGetKeys(rados_op_t op, const char *startAfter, uint64_t maxReturn, proxy_omap_iter_t *iter, + unsigned char *pmore, int *prval) { RadosObjectReadOp *readOp = static_cast(op); RadosOmapIter *oIter = new(std::nothrow) RadosOmapIter(); @@ -897,7 +889,8 @@ int RadosOmapGetNext(proxy_omap_iter_t iter, char **key, char **val, size_t *key return 0; } -size_t RadosOmapIterSize(proxy_omap_iter_t iter) { +size_t RadosOmapIterSize(proxy_omap_iter_t iter) +{ RadosOmapIter *it = static_cast(iter); return it->values.size(); } @@ -908,8 +901,8 @@ void RadosOmapIterEnd(proxy_omap_iter_t iter) delete it; } -void RadosReadOpOmapCmp(rados_op_t op, const char *key, uint8_t compOperator, - const char *val, size_t valLen, int *prval) +void RadosReadOpOmapCmp(rados_op_t op, const char *key, uint8_t compOperator, const char *val, size_t valLen, + int *prval) { RadosObjectReadOp *readOp = static_cast(op); bufferlist bl; @@ -936,16 +929,15 @@ void RadosReadOpStat(rados_op_t op, uint64_t *psize, time_t *pmtime, int *prval) PROXY_FTDS_END_HIGH(PROXY_FTDS_OPS_OPINIT_READSTAT, ts, ret); } -void RadosReadOpRead(rados_op_t op, uint64_t offset, size_t len, char *buffer, - size_t *bytesRead, int *prval) +void RadosReadOpRead(rados_op_t op, uint64_t offset, size_t len, char *buffer, size_t *bytesRead, int *prval) { uint64_t ts = 0; int32_t ret = 0; PROXY_FTDS_START_HIGH(PROXY_FTDS_OPS_OPINIT_READ, ts); RadosObjectReadOp *readOp = static_cast(op); if (readOp == nullptr || buffer == nullptr || bytesRead == nullptr) { - ProxyDbgLogErr("readOp %p or buffer %p or bytesRead %p or prval %p is invalid", - readOp, buffer, bytesRead, prval); + ProxyDbgLogErr("readOp %p or buffer %p or bytesRead %p or prval %p is invalid", readOp, buffer, bytesRead, + prval); PROXY_FTDS_END_HIGH(PROXY_FTDS_OPS_OPINIT_READ, ts, ret); return; } @@ -975,10 +967,8 @@ void RadosReadOpReadBl(rados_op_t op, uint64_t offset,size_t len, GcBufferList * PROXY_FTDS_END_HIGH(PROXY_FTDS_OPS_OPINIT_READBL, ts, ret); } -void RadosReadOpCheckSum(rados_op_t op, proxy_checksum_type_t type, - const char *initValue, size_t initValueLen, - uint64_t offset, size_t len, size_t chunkSize, - char *pCheckSum, size_t checkSumLen, int *prval) +void RadosReadOpCheckSum(rados_op_t op, proxy_checksum_type_t type, const char *initValue, size_t initValueLen, + uint64_t offset, size_t len, size_t chunkSize, char *pCheckSum, size_t checkSumLen, int *prval) { rados_checksum_type_t rtype = (rados_checksum_type_t)type; RadosObjectReadOp *readOp = static_cast(op); @@ -989,9 +979,8 @@ void RadosReadOpCheckSum(rados_op_t op, proxy_checksum_type_t type, readOp->op.checksum(rtype, bl, offset, len, chunkSize, &(readOp->checksums), prval); } -void RadosReadOpExec(rados_op_t op, const char *cls, const char *method, - const char *inBuf, size_t inLen, char **outBuf, - size_t *outLen, int *prval) +void RadosReadOpExec(rados_op_t op, const char *cls, const char *method, const char *inBuf, size_t inLen, char **outBuf, + size_t *outLen, int *prval) { RadosObjectReadOp *readOp = static_cast(op); bufferlist inbl; @@ -1012,13 +1001,11 @@ int RadosOperationOperate(rados_op_t op, rados_ioctx_t io) RadosObjectReadOp *readOp = dynamic_cast(rop); bufferlist bl; ret = ctx->operate(readOp->objectId, &(readOp->op), &bl); - } - break; + } break; case BATCH_WRITE_OP: { RadosObjectWriteOp *writeOp = dynamic_cast(rop); ret = ctx->operate(writeOp->objectId, &(writeOp->op)); - } - break; + } break; default: break; } @@ -1068,7 +1055,7 @@ void ReadCallback(rados_completion_t c, void *arg) memcpy(bl->entrys[curEntryIndex].buf, cbl.c_str(), size); leftLen -= size; curEntryIndex++; - if (curEntryIndex >= ENTRY_PER_BUFFERLIST) { + if (curEntryIndex >= ENTRY_PER_BUFFLIST) { curEntryIndex = 0; bl = bl->nextBufferList; } @@ -1078,16 +1065,16 @@ void ReadCallback(rados_completion_t c, void *arg) } } else { if (ret == -2) { - ProxyDbgLogWarn("pool(%ld) or objects(%s) is not exists: %d", readOp->poolId, readOp->objectId.c_str(), ret); + ProxyDbgLogWarn("pool(%ld) or objects(%s) is not exists: %d", readOp->poolId, readOp->objectId.c_str(), + ret); } else { ProxyDbgLogErr("read pool(%ld) or objects(%s) failed: %d", readOp->poolId, readOp->objectId.c_str(), ret); } } if (ret == 0 && readOp->reqCtx.xattr.name != nullptr) { - memcpy(*(readOp->reqCtx.xattr.vals), - readOp->xattrs[readOp->reqCtx.xattr.name].c_str(), - readOp->xattrs[readOp->reqCtx.xattr.name].length()); + memcpy(*(readOp->reqCtx.xattr.vals), readOp->xattrs[readOp->reqCtx.xattr.name].c_str(), + readOp->xattrs[readOp->reqCtx.xattr.name].length()); } if (ret == 0 && readOp->reqCtx.xattrs.iter != nullptr) { @@ -1096,19 +1083,17 @@ void ReadCallback(rados_completion_t c, void *arg) } if (ret == 0 && readOp->reqCtx.omap.iter != nullptr) { - RadosOmapIter *iter = static_cast(readOp->reqCtx.omap.iter); - iter->i = iter->values.begin(); - if (!iter->keys.empty()) { - for (auto i : iter->keys) { - iter->values[i]; - } + RadosOmapIter *iter = static_cast(readOp->reqCtx.omap.iter); + iter->i = iter->values.begin(); + if (!iter->keys.empty()) { + for (auto i : iter->keys) { + iter->values[i]; + } } } if (ret == 0 && readOp->reqCtx.checksum.pCheckSum != nullptr) { - memcpy(readOp->reqCtx.checksum.pCheckSum, - readOp->checksums.c_str(), - readOp->reqCtx.checksum.chunkSumLen); + memcpy(readOp->reqCtx.checksum.pCheckSum, readOp->checksums.c_str(), readOp->reqCtx.checksum.chunkSumLen); } // TODO: other reqCtx; @@ -1162,10 +1147,9 @@ int RadosOperationAioOperate( rados_client_t client, rados_op_t op, rados_ioctx_ ret = ctx->aio_operate(readOp->objectId, readCompletion, &(readOp->op), NULL); if (ret !=0) { ProxyDbgLogErr("aio_operate failed: %d", ret); - } + } readCompletion->release(); - } - break; + } break; case BATCH_WRITE_OP: { RadosObjectWriteOp *writeOp = dynamic_cast(rop); writeOp->ts = 0; @@ -1177,10 +1161,9 @@ int RadosOperationAioOperate( rados_client_t client, rados_op_t op, rados_ioctx_ ret=ctx->aio_operate(writeOp->objectId, writeCompletion, &(writeOp->op)); if (ret !=0) { ProxyDbgLogErr("aio_operate failed: %d", ret); - } + } writeCompletion->release(); - } - break; + } break; default: ProxyDbgLogErr("unknown op: %u", rop->opType); ret = -EINVAL; diff --git a/src/ceph_proxy/RbdWrapper.cc b/src/ceph_proxy/RbdWrapper.cc index 69015c4..9f644d9 100644 --- a/src/ceph_proxy/RbdWrapper.cc +++ b/src/ceph_proxy/RbdWrapper.cc @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "rbd/librbd.h" #include "rados/librados.h" @@ -53,24 +52,6 @@ static struct ProxyCtx gProxyCtx; using shared_lock = std::shared_lock; using unique_lock = std::unique_lock; -static void GetPool(librados::IoCtx &io_ctx, int64_t &pool_id, std::string &pool_name) -{ - std::string poolName = io_ctx.get_pool_name(); - pool_id = io_ctx.get_id(); - pool_name.assign(poolName); -} - -static void GetImage(librbd::Image &rbd_image, std::string &image_name, std::string &image_id) -{ - - std::string imageName; - std::string imageId; - rbd_image.get_name(&imageName); - rbd_image.get_id(&imageId); - image_name.assign(imageName); - image_id.assign(imageId); -} - static void RadosShutdown() { unique_lock l(gProxyCtx.lock); @@ -83,7 +64,10 @@ static void RadosShutdown() static void FastInitRados(std::map& conf_map) { - assert(gProxyCtx.init_flag == true); + if (!gProxyCtx.init_flag) { + ProxyDbgCrit("proxy Ctx not init!"); + return; + } gProxyCtx.ref++; std::map::iterator iter; int ret; @@ -126,7 +110,7 @@ static int RadosInit(std::map& conf_map) { uint32_t retryCount = 0; { - shared_lock l(gProxyCtx.lock); + unique_lock l(gProxyCtx.lock); if (gProxyCtx.init_flag) { FastInitRados(conf_map); return 0; @@ -242,7 +226,10 @@ static int IoctxInit(librados::IoCtx* ioctx, const std::string& pool_name, int64_t pool_id, const std::string& namespace_name) { int ret; - assert(gProxyCtx.init_flag); + if (!gProxyCtx.init_flag) { + ProxyDbgCrit("proxy ctx not init"); + return -1; + } if (!pool_name.empty()) { ret = gProxyCtx.client.ioctx_create(pool_name.c_str(), *ioctx); if (ret < 0) { @@ -327,7 +314,7 @@ static int ImageRemoveSnap(librbd::Image& image, const std::string& snap_name, u } else { ret = image.snap_remove_by_id(snap_id); if (ret < 0) { - ProxyDbgLogErr("rbd snap remove failed. snap_id %lu ret %d", snap_id, ret); + ProxyDbgLogErr("rbd snap remove failed. snap_id %llu ret %d", snap_id, ret); return ret; } } @@ -368,6 +355,8 @@ int CephLibrbdSnapRemove(int64_t pool_id, return -EINVAL; } + ProxyDbgLogInfo("image remove snap start pool %lld:%s image %s:%s snap %llu:%s", + pool_id, pool_name.c_str(), image_id.c_str(), image_name.c_str(), snap_id, snap_name.c_str()); ret = RadosInit(confMap); if (ret < 0) { ProxyDbgLogErr("rados client Init failed: %d", ret); @@ -406,8 +395,8 @@ int CephLibrbdSnapRemove(int64_t pool_id, goto close_image; } - ProxyDbgLogDebug("image remove snap success pool %ld:%s image %s:%s snap %lu:%s", - pool_id, pool_name, image_id, image_name, snap_id, snap_name); + ProxyDbgLogInfo("image remove snap success pool %lld:%s image %s:%s snap %llu:%s", + pool_id, pool_name.c_str(), image_id.c_str(), image_name.c_str(), snap_id, snap_name.c_str()); close_image: IoctxCloseImage(image); @@ -420,78 +409,6 @@ shutdown: return ret; } -int CephLibrbdGetPoolName(std::string& pool_name, int64_t pool_id, - const std::string& namespace_name) -{ - int ret; - librados::IoCtx ioctx; - int64_t pid; - - std::map confMap; - - ret = RadosInit(confMap); - if (ret < 0) { - ProxyDbgLogErr("rados client Init failed: %d", ret); - return ret; - } - - ret = IoctxInit(&ioctx, "", pool_id, namespace_name); - if (ret < 0) { - ProxyDbgLogErr("ioctx Init failed: %d", ret); - goto shutdown; - } - - GetPool(ioctx, pid, pool_name); - assert(pid == pool_id); - - IoCtxDestroy(ioctx); - -shutdown: - RadosShutdown(); - return ret; -} - -int CephLibrbdGetImageName(const std::string& pool_name, int64_t pool_id, - const std::string& image_id, std::string& image_name, - const std::string& namespace_name) -{ - int ret; - librados::IoCtx ioctx; - librbd::Image image; - std::string iid; - - std::map confMap; - ret = RadosInit(confMap); - if (ret < 0) { - ProxyDbgLogErr("rados client Init failed: %d", ret); - return ret; - } - - ret = IoctxInit(&ioctx, "", pool_id, namespace_name); - if (ret < 0) { - ProxyDbgLogErr("ioctx Init failed: %d", ret); - goto shutdown; - } - - ret = IoctxOpenImage(ioctx, "", image_id, &image); - if (ret < 0) { - ProxyDbgLogErr("image open failed: %d", ret); - goto close_ioctx; - } - - GetImage(image, image_name, iid); - assert(iid == image_id); - - IoctxCloseImage(image); - -close_ioctx: - IoCtxDestroy(ioctx); - -shutdown: - RadosShutdown(); - return ret; -} - int CephLibrbdGetImageInfo(int64_t pool_id, const char *_image_id, int32_t *num_objs) @@ -515,7 +432,7 @@ int CephLibrbdGetImageInfo(int64_t pool_id, ret = IoctxInit(&ioctx, "", pool_id, ""); if (ret < 0) { - ProxyDbgLogErr("ioctx %ld Init failed: %d", pool_id, ret); + ProxyDbgLogErr("ioctx %lld Init failed: %d", pool_id, ret); goto shutdown; } @@ -547,7 +464,10 @@ shutdown: static int MonCommand(std::string cmd, std::string &_outs) { int ret; - assert(gProxyCtx.init_flag); + if (!gProxyCtx.init_flag) { + ProxyDbgCrit("proxy ctx not init"); + return -1; + } std::string outs; bufferlist inbl; bufferlist outbl; @@ -564,17 +484,18 @@ static int ParsePoolMap(std::string &outs, std::map { std::string pattern = "\\s*(\\d+)\\s+(\\S+)"; std::vector preVec; - char *strs = new char[outs.length() + 1]; + char *strs = new(std::nothrow) char[outs.length() + 1]; if (strs == nullptr) { ProxyDbgLogErr("alloc memory failed"); return -1; } strcpy(strs, outs.c_str()); - char *p = strtok(strs, "\n"); + char *savep; + char *p = strtok_r(strs, "\n", &savep); while (p) { std::string s = p; preVec.push_back(s); - p = strtok(NULL, "\n"); + p = strtok_r(nullptr, "\n", &savep); } for (size_t i = 0; i < preVec.size(); i++) { @@ -582,13 +503,20 @@ static int ParsePoolMap(std::string &outs, std::map std::smatch result; bool flag = std::regex_match(preVec[i], result, expression); if (flag) { - int64_t poolId = atoi(result[1].str().c_str()); + errno = 0; + char *end = nullptr; + const char* p = result[1].str().c_str(); + int64_t poolId = (int64_t)strtol(p, &end, 10); + if (errno == ERANGE || end == p) { + ProxyDbgLogErr("get poolId from str failed."); + break; + } struct SigPoolInfo info; info.poolId = poolId; info.poolName = result[2].str().c_str(); info.usage = 0; poolMap[poolId] = info; - ProxyDbgLogInfo("pool %s, id %ld", info.poolName.c_str(), info.poolId); + ProxyDbgLogInfo("pool %s, id %lld", info.poolName.c_str(), info.poolId); } } @@ -613,17 +541,18 @@ static int GetECPoolScale(struct SigPoolInfo &info) } std::vector preVec; - char *strs = new char[outs.length() + 1]; + char *strs = new(std::nothrow) char[outs.length() + 1]; if (strs == nullptr) { ProxyDbgLogErr("alloc memory failed"); return -1; } strcpy(strs, outs.c_str()); - char *p = strtok(strs, "\n"); + char *savep; + char *p = strtok_r(strs, "\n", &savep); while (p) { std::string s = p; preVec.push_back(s); - p = strtok(NULL, "\n"); + p = strtok_r(nullptr, "\n", &savep); } for (uint32_t i = 0; i < preVec.size(); i++) { @@ -633,10 +562,21 @@ static int GetECPoolScale(struct SigPoolInfo &info) if (!flag) { continue; } + errno = 0; + char *end = nullptr; + const char *p = result[2].str().c_str(); if (result[1].str().compare("k") == 0) { - info.k = atoi(result[2].str().c_str()); + info.k = (int)strtol(p, &end, 10); + if (errno == ERANGE || end == p) { + ProxyDbgLogErr("get k from str failed."); + break; + } } else if (result[1].str().compare("m") == 0) { - info.m = atoi(result[2].str().c_str()); + info.m = (int)strtol(p, &end, 10); + if (errno == ERANGE || end == p) { + ProxyDbgLogErr("get m from str failed."); + break; + } } } @@ -685,7 +625,10 @@ static int CalPoolProperty(std::map &poolMap) ProxyDbgLogErr("get EC pool size failed! ret=%d", ret); return ret; } - assert(info.k != 0 && info.m != 0); + if (info.k == 0 || info.m == 0) { + ProxyDbgCrit("unexpected EC result k %d m %d", info.k, info.m); + return -1; + } ProxyDbgLogInfo("EC pool %s, k=%d, m=%d", info.poolName.c_str(), info.k, info.m); } } @@ -694,7 +637,7 @@ static int CalPoolProperty(std::map &poolMap) static int DiffCallback(uint64_t offset, size_t len, int exists, void *arg) { - uint64_t *used = reinterpret_cast(arg); + uint64_t *used = static_cast(arg); if (exists) { (*used) += len; } @@ -756,7 +699,7 @@ static int CalImageUsage(librados::IoCtx &ioctx, struct SigPoolInfo& info, librb } info.usage += used; lastSnap = snap.name.c_str(); - ProxyDbgLogInfo("snap %s/%s@%s, used=%lu", + ProxyDbgLogInfo("snap %s/%s@%s, used=%llu", info.poolName.c_str(), imageSpec.name.c_str(), snap.name.c_str(), used); } @@ -771,7 +714,7 @@ static int CalImageUsage(librados::IoCtx &ioctx, struct SigPoolInfo& info, librb goto image_close; } info.usage += used; - ProxyDbgLogInfo("image %s/%s, used=%lu", info.poolName.c_str(), imageSpec.name.c_str(), used); + ProxyDbgLogInfo("image %s/%s, used=%llu", info.poolName.c_str(), imageSpec.name.c_str(), used); image_close: image.close(); return ret; diff --git a/src/server_adaptor/class_api.cc b/src/server_adaptor/class_api.cc index ed90c5d..1115831 100644 --- a/src/server_adaptor/class_api.cc +++ b/src/server_adaptor/class_api.cc @@ -96,10 +96,10 @@ int cls_unregister_method(cls_method_handle_t handle) int cls_getxattr(cls_method_context_t hctx, const char *name, char **outdata, int *outdatalen) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; @@ -127,10 +127,10 @@ int cls_getxattr(cls_method_context_t hctx, const char *name, char **outdata, in int cls_setxattr(cls_method_context_t hctx, const char *name, const char *value, int val_len) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; op.opSubType = CEPH_OSD_OP_SETXATTR; @@ -145,10 +145,10 @@ int cls_setxattr(cls_method_context_t hctx, const char *name, const char *value, int cls_get_request_origin(cls_method_context_t hctx, entity_inst_t *origin) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); *origin = ptr->get_orig_source_inst(); return 0; @@ -162,19 +162,19 @@ uint64_t cls_get_features(cls_method_context_t hctx) uint64_t cls_get_client_features(cls_method_context_t hctx) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); return ptr->get_connection()->get_features(); } int cls_cxx_create(cls_method_context_t hctx, bool exclusive) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); SaOpReq opreq = *pOpReq; OpRequestOps op; op.opSubType = CEPH_OSD_OP_CREATE; @@ -187,9 +187,9 @@ int cls_cxx_create(cls_method_context_t hctx, bool exclusive) int cls_cxx_remove(cls_method_context_t hctx) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); SaOpReq opreq = *pOpReq; OpRequestOps op; op.opSubType = CEPH_OSD_OP_DELETE; @@ -202,10 +202,10 @@ int cls_cxx_remove(cls_method_context_t hctx) int cls_cxx_stat(cls_method_context_t hctx, uint64_t *size, time_t *mtime) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; @@ -239,10 +239,10 @@ int cls_cxx_stat(cls_method_context_t hctx, uint64_t *size, time_t *mtime) int cls_cxx_stat2(cls_method_context_t hctx, uint64_t *size, ceph::real_time *mtime) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; @@ -254,6 +254,7 @@ int cls_cxx_stat2(cls_method_context_t hctx, uint64_t *size, ceph::real_time *mt op.rbdObjId.format = pOpReq->vecOps[pctx->opId].rbdObjId.format; op.rbdObjId.poolId = pOpReq->vecOps[pctx->opId].rbdObjId.poolId; op.objName = pOpReq->vecOps[pctx->opId].objName; // ptr->get_oid().name; + op.opFlags = 1; // assert exists vector ops(1); ops.swap(ptr->ops); @@ -288,10 +289,10 @@ int cls_cxx_read(cls_method_context_t hctx, int ofs, int len, bufferlist *outbl) int cls_cxx_read2(cls_method_context_t hctx, int ofs, int len, bufferlist *outbl, uint32_t op_flags) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; @@ -302,7 +303,6 @@ int cls_cxx_read2(cls_method_context_t hctx, int ofs, int len, op.objName = ptr->get_oid().name; op.objOffset = ofs; op.objLength = len; - op.outData = new char[len]; op.outDataLen = len; vector ops(1); @@ -325,7 +325,7 @@ int cls_cxx_write(cls_method_context_t hctx, int ofs, int len, bufferlist *inbl) int cls_cxx_write2(cls_method_context_t hctx, int ofs, int len, bufferlist *inbl, uint32_t op_flags) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; OpRequestOps op; @@ -350,10 +350,10 @@ int cls_cxx_write2(cls_method_context_t hctx, int ofs, int len, bufferlist *inbl int cls_cxx_write_full(cls_method_context_t hctx, bufferlist *inbl) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; op.opSubType = CEPH_OSD_OP_WRITEFULL; @@ -370,10 +370,10 @@ int cls_cxx_write_full(cls_method_context_t hctx, bufferlist *inbl) int cls_cxx_getxattr(cls_method_context_t hctx, const char *name, bufferlist *outbl) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; @@ -396,10 +396,10 @@ int cls_cxx_getxattr(cls_method_context_t hctx, const char *name, bufferlist *ou int cls_cxx_getxattrs(cls_method_context_t hctx, map *attrset) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; @@ -426,10 +426,10 @@ int cls_cxx_getxattrs(cls_method_context_t hctx, map *attrse int cls_cxx_setxattr(cls_method_context_t hctx, const char *name, bufferlist *inbl) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; op.opSubType = CEPH_OSD_OP_SETXATTR; @@ -447,10 +447,10 @@ int cls_cxx_setxattr(cls_method_context_t hctx, const char *name, bufferlist *in int cls_cxx_map_get_all_vals(cls_method_context_t hctx, map *vals, bool *more) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; uint64_t max_to_get = -1; @@ -487,10 +487,10 @@ int cls_cxx_map_get_all_vals(cls_method_context_t hctx, map int cls_cxx_map_get_keys(cls_method_context_t hctx, const string &start_obj, uint64_t max_to_get, set *keys, bool *more) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; op.opSubType = CEPH_OSD_OP_OMAPGETKEYS; @@ -523,10 +523,10 @@ int cls_cxx_map_get_keys(cls_method_context_t hctx, const string &start_obj, uin int cls_cxx_map_get_vals(cls_method_context_t hctx, const string &start_obj, const string &filter_prefix, uint64_t max_to_get, map *vals, bool *more) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; @@ -562,10 +562,10 @@ int cls_cxx_map_get_vals(cls_method_context_t hctx, const string &start_obj, con int cls_cxx_map_read_header(cls_method_context_t hctx, bufferlist *outbl) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; @@ -588,10 +588,10 @@ int cls_cxx_map_read_header(cls_method_context_t hctx, bufferlist *outbl) int cls_cxx_map_get_val(cls_method_context_t hctx, const string &key, bufferlist *outbl) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; int r; @@ -626,10 +626,10 @@ int cls_cxx_map_get_val(cls_method_context_t hctx, const string &key, bufferlist int cls_cxx_map_set_val(cls_method_context_t hctx, const string &key, bufferlist *inbl) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; op.opSubType = CEPH_OSD_OP_OMAPSETVALS; @@ -647,10 +647,10 @@ int cls_cxx_map_set_val(cls_method_context_t hctx, const string &key, bufferlist int cls_cxx_map_set_vals(cls_method_context_t hctx, const std::map *map) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; op.opSubType = CEPH_OSD_OP_OMAPSETVALS; @@ -671,10 +671,10 @@ int cls_cxx_map_set_vals(cls_method_context_t hctx, const std::map(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; op.opSubType = CEPH_OSD_OP_OMAPCLEAR; @@ -687,10 +687,10 @@ int cls_cxx_map_clear(cls_method_context_t hctx) int cls_cxx_map_write_header(cls_method_context_t hctx, bufferlist *inbl) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; op.opSubType = CEPH_OSD_OP_OMAPSETHEADER; @@ -705,10 +705,10 @@ int cls_cxx_map_write_header(cls_method_context_t hctx, bufferlist *inbl) int cls_cxx_map_remove_key(cls_method_context_t hctx, const string &key) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); SaOpReq *pOpReq = pctx->opReq; SaOpReq opreq = *pOpReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); OpRequestOps op; op.opSubType = CEPH_OSD_OP_OMAPRMKEYS; @@ -759,7 +759,7 @@ uint64_t cls_current_version(cls_method_context_t hctx) int cls_current_subop_num(cls_method_context_t hctx) { - SaOpContext *pctx = reinterpret_cast(hctx); + SaOpContext *pctx = static_cast(hctx); return pctx->opId; } diff --git a/src/server_adaptor/msg_module.cpp b/src/server_adaptor/msg_module.cpp index 63fa39a..8ac2918 100644 --- a/src/server_adaptor/msg_module.cpp +++ b/src/server_adaptor/msg_module.cpp @@ -120,7 +120,10 @@ int MsgModule::ConvertClientopToOpreq(OSDOp &clientop, OpRequestOps &oneOp, Opti } } break; case CEPH_OSD_OP_GETXATTRS: - case CEPH_OSD_OP_STAT: + case CEPH_OSD_OP_STAT: { + oneOp.opFlags = clientop.op.flags; + SaDatalog("Converting stat tid=%ld obj=%s flag=%u", tid, oneOp.objName.c_str(), oneOp.opFlags); + } break; case CEPH_OSD_OP_CALL: { string cname, mname; @@ -137,7 +140,7 @@ int MsgModule::ConvertClientopToOpreq(OSDOp &clientop, OpRequestOps &oneOp, Opti } } break; case CEPH_OSD_OP_LIST_SNAPS: { - SaDatalog("Converting COPYUP tid=%ld obj=%s", tid, oneOp.objName.c_str()); + SaDatalog("Converting list snaps tid=%ld obj=%s", tid, oneOp.objName.c_str()); } break; case CEPH_OSD_OP_CREATE: diff --git a/src/server_adaptor/network_module.cpp b/src/server_adaptor/network_module.cpp index 3e294a2..e88a653 100644 --- a/src/server_adaptor/network_module.cpp +++ b/src/server_adaptor/network_module.cpp @@ -81,7 +81,11 @@ int NetworkModule::InitNetworkModule(const std::string &rAddr, const std::vector Salog(LV_DEBUG, LOG_TYPE, "Init network module."); int ret; if (ptrMsgModule == nullptr) { - ptrMsgModule = new MsgModule(); + ptrMsgModule = new(std::nothrow) MsgModule(); + if (ptrMsgModule == nullptr) { + Salog(LV_ERROR, LOG_TYPE, "memory alloc failed"); + return -ENOMEM; + } } recvAddr = rAddr; vecPorts = rPort; @@ -96,7 +100,11 @@ int NetworkModule::InitNetworkModule(const std::string &rAddr, const std::vector } #ifdef SA_PERF if (msgPerf == nullptr) { - msgPerf = new MsgPerfRecord(); + msgPerf = new(std::nothrow) MsgPerfRecord(); + if (msgPerf == nullptr) { + Salog(LV_ERROR, LOG_TYPE, "memory alloc failed"); + return -ENOMEM; + } } if (g_msgPerf == nullptr) { g_msgPerf = msgPerf; @@ -194,8 +202,22 @@ int NetworkModule::ThreadFuncBodyServer() svrMessenger->set_auth_server(&dummy_auth); svrMessenger->set_magic(MSG_MAGIC_TRACE_CTR); - Throttle *clientByteThrottler = new Throttle(g_ceph_context,"osd_client_bytes",messageSize); - Throttle *clientMsgThrottler = new Throttle(g_ceph_context,"osd_client_messages",messageCap); + Throttle *clientByteThrottler = nullptr; + Throttle *clientMsgThrottler = nullptr; + clientByteThrottler = new(std::nothrow) Throttle(g_ceph_context,"osd_client_bytes",messageSize); + clientMsgThrottler = new(std::nothrow) Throttle(g_ceph_context,"osd_client_messages",messageCap); + if (clientByteThrottler == nullptr || clientMsgThrottler == nullptr) { + Salog(LV_ERROR, LOG_TYPE, "Throttle memory alloc failed"); + r = -ENOMEM; + *bindSuccess = 0; + if (clientByteThrottler) { + delete clientByteThrottler; + } + if (clientMsgThrottler) { + delete clientMsgThrottler; + } + goto out; + } svrMessenger->set_default_policy(Messenger::Policy::stateless_server(0)); if (qosParam.enableThrottle) { Salog(LV_WARNING, LOG_TYPE, "set messenger throttlers."); @@ -207,10 +229,20 @@ int NetworkModule::ThreadFuncBodyServer() if (r < 0) { Salog(LV_ERROR, LOG_TYPE, "bind error %s:%s", recvAddr.c_str(), strPort.c_str()); *bindSuccess = 0; - goto out; + delete clientByteThrottler; + delete clientMsgThrottler; + goto out; } - - SaServerDispatcher *svrDispatcher = new SaServerDispatcher(svrMessenger, ptrMsgModule, this); + SaServerDispatcher *svrDispatcher = nullptr; + svrDispatcher = new(std::nothrow) SaServerDispatcher(svrMessenger, ptrMsgModule, this); + if (svrDispatcher == nullptr) { + Salog(LV_ERROR, LOG_TYPE, "memory alloc failed"); + r = -ENOMEM; + *bindSuccess = 0; + delete clientByteThrottler; + delete clientMsgThrottler; + goto out; + } svrDispatcher->ms_set_require_authorizer(false); svrMessenger->add_dispatcher_head(svrDispatcher); svrMessenger->start(); @@ -357,7 +389,16 @@ void NetworkModule::CreateWorkThread(uint32_t qnum, uint32_t portAmout, uint32_t for (uint64_t i = 0; i < queueNum; i++) { finishThread.push_back(false); - opDispatcher.push_back(new ClientOpQueue()); + ClientOpQueue *cq = nullptr; + do { + cq = new(std::nothrow) ClientOpQueue(); + if (cq) { + break; + } + Salog(LV_ERROR, LOG_TYPE, "memory alloc failed"); + usleep(COMMON_SLEEP_TIME_MS * SA_THOUSAND_DEC); + } while (cq == nullptr); + opDispatcher.push_back(cq); } for (uint64_t i = 0; i < queueNum; i++) { int cpuNum = saCoreId[i % saCoreId.size()]; @@ -483,7 +524,7 @@ void NetworkModule::OpHandlerThread(int threadNum, int coreId) } // while (!dealQueue.empty()) { - SaOpReq *opreq = new SaOpReq; + SaOpReq *opreq = new(std::nothrow) SaOpReq; if (opreq == nullptr) { SalogLimit(LV_ERROR, LOG_TYPE, "new nullptr"); usleep(COMMON_SLEEP_TIME_MS * SA_THOUSAND_DEC); @@ -506,7 +547,7 @@ void NetworkModule::OpHandlerThread(int threadNum, int coreId) GetReadBWCas(opreq->optionLength); } while (copyupFlag.load() == 1) { - usleep(20 * SA_THOUSAND_DEC); + usleep(50); } if (unlikely(opreq->exitsCopyUp == 1)) { SaDatalog("exists copyup, set copyupFlag, tid=%ld", opreq->tid); @@ -536,7 +577,7 @@ void NetworkModule::OpHandlerThread(int threadNum, int coreId) sleep(1); ceph_assert("Lock queue mutex catch std::exception 2" == nullptr); } - sa->FtdsEndHigt(SA_FTDS_LOCK_ONE, "SA_FTDS_OP_LIFE", lockTsOne, 0); + sa->FtdsEndHigt(SA_FTDS_LOCK_ONE, "SA_FTDS_LOCK_ONE", lockTsOne, 0); continue; } try { @@ -1117,11 +1158,18 @@ void NetworkModule::PutReadBWCas(unsigned long int c) void FinishCacheOps(void *op, uint32_t optionType, uint64_t optionLength, int32_t r) { MOSDOp *ptr = (MOSDOp *)(op); + MOSDOpReply *reply = nullptr; if (ptr == nullptr) { Salog(LV_ERROR, LOG_TYPE, " finish. but mosdop is null"); return; } - MOSDOpReply *reply = new MOSDOpReply(ptr, 0, 0, 0, false); + do { + reply = new(std::nothrow) MOSDOpReply(ptr, 0, 0, 0, false); + if (reply) { + break; + } + SalogLimit(LV_ERROR, LOG_TYPE, " memory alloc failed"); + } while (reply == nullptr); reply->claim_op_out_data(ptr->ops); reply->set_result(r); reply->add_flags(CEPH_OSD_FLAG_ACK | CEPH_OSD_FLAG_ONDISK); @@ -1155,14 +1203,18 @@ void SetOpResult(int i, int32_t ret, MOSDOp *op) Salog(LV_ERROR, LOG_TYPE, " mosdop %p is null, skip", op); return; } + if ((uint32_t)i >= op->ops.size()) { + Salog(LV_ERROR, LOG_TYPE, " index %d >= %u overflow", i, op->ops.size()); + return; + } op->ops[i].rval = ret; } void ProcessBuf(const char *buf, uint32_t len, int cnt, void *p) { MOSDOp *ptr = (MOSDOp *)(p); - if (ptr == nullptr) { - Salog(LV_ERROR, LOG_TYPE, " mosdop %p is null, skip", ptr); + if (ptr == nullptr || buf == nullptr) { + Salog(LV_ERROR, LOG_TYPE, " mosdop %p or buf %p is null, skip", ptr, buf); return; } encode(std::string_view(buf, len), ptr->ops[cnt].outdata); @@ -1175,6 +1227,10 @@ void EncodeOmapGetkeys(const SaBatchKeys *batchKeys, int i, MOSDOp *mosdop) Salog(LV_ERROR, LOG_TYPE, " mosdop %p or batchKeys %p is null, skip", mosdop, batchKeys); return; } + if ((uint32_t)i >= mosdop->ops.size()) { + Salog(LV_ERROR, LOG_TYPE, " index %d >= %u overflow", i, mosdop->ops.size()); + return; + } for (uint32_t j = 0; j < batchKeys->nums; j++) { encode(std::string_view(batchKeys->keys[j].buf, batchKeys->keys[j].len), bl); } @@ -1191,6 +1247,10 @@ void EncodeOmapGetvals(const SaBatchKv *KVs, int i, MOSDOp *mosdop) Salog(LV_ERROR, LOG_TYPE, " mosdop %p or KVs %p is null, skip", mosdop, KVs); return; } + if ((uint32_t)i >= mosdop->ops.size()) { + Salog(LV_ERROR, LOG_TYPE, " index %d >= %u overflow", i, mosdop->ops.size()); + return; + } Salog(LV_DEBUG, LOG_TYPE, "CEPH_OSD_OP_OMAPGETVALS get key num=%d", KVs->kvNum); for (uint32_t j = 0; j < KVs->kvNum; j++) { if (KVs->keys[j].buf && KVs->keys[j].len) { @@ -1214,6 +1274,10 @@ void EncodeOmapGetvalsbykeys(const SaBatchKv *keyValue, int i, MOSDOp *mosdop) Salog(LV_ERROR, LOG_TYPE, " mosdop %p or keyValue %p is null, skip", mosdop, keyValue); return; } + if ((uint32_t)i >= mosdop->ops.size()) { + Salog(LV_ERROR, LOG_TYPE, " index %d >= %u overflow", i, mosdop->ops.size()); + return; + } for (uint32_t j = 0; j < keyValue->kvNum; j++) { bufferlist value; string keys(keyValue->keys[j].buf, keyValue->keys[j].len); @@ -1226,8 +1290,12 @@ void EncodeOmapGetvalsbykeys(const SaBatchKv *keyValue, int i, MOSDOp *mosdop) void EncodeRead(uint64_t opType, unsigned int offset, unsigned int len, const char *buf, unsigned int bufLen, int i, MOSDOp *mosdop) { - if (mosdop == nullptr) { - Salog(LV_ERROR, LOG_TYPE, " mosdop %p is null, skip", mosdop); + if (mosdop == nullptr || buf == nullptr) { + Salog(LV_ERROR, LOG_TYPE, " mosdop %p or buf %p is null, skip", mosdop, buf); + return; + } + if ((uint32_t)i >= mosdop->ops.size()) { + Salog(LV_ERROR, LOG_TYPE, " index %d >= %u overflow", i, mosdop->ops.size()); return; } if (unlikely(opType == CEPH_OSD_OP_SPARSE_READ)) { @@ -1246,6 +1314,10 @@ void EncodeXattrGetXattr(const SaBatchKv *keyValue, int i, MOSDOp *mosdop) Salog(LV_ERROR, LOG_TYPE, " mosdop %p or keyValue %p is null, skip", mosdop, keyValue); return; } + if ((uint32_t)i >= mosdop->ops.size()) { + Salog(LV_ERROR, LOG_TYPE, " index %d >= %u overflow", i, mosdop->ops.size()); + return; + } mosdop->ops[i].outdata.clear(); for (uint32_t j = 0; j < keyValue->kvNum; j++) { bufferptr ptr(keyValue->values[j].buf, keyValue->values[j].len); @@ -1259,6 +1331,10 @@ void EncodeXattrGetXattrs(const SaBatchKv *keyValue, int i, MOSDOp *mosdop) Salog(LV_ERROR, LOG_TYPE, " mosdop %p or keyValue %p is null, skip", mosdop, keyValue); return; } + if ((uint32_t)i >= mosdop->ops.size()) { + Salog(LV_ERROR, LOG_TYPE, " index %d >= %u overflow", i, mosdop->ops.size()); + return; + } map out; bufferlist bl; for (uint32_t j = 0; j < keyValue->kvNum; j++) { @@ -1277,6 +1353,10 @@ void EncodeGetOpstat(uint64_t psize, time_t ptime, int i, MOSDOp *mosdop) Salog(LV_ERROR, LOG_TYPE, " mosdop %p is null, skip", mosdop); return; } + if ((uint32_t)i >= mosdop->ops.size()) { + Salog(LV_ERROR, LOG_TYPE, " index %d >= %u overflow", i, mosdop->ops.size()); + return; + } encode(psize, mosdop->ops[i].outdata); encode(ptime, mosdop->ops[i].outdata); } @@ -1287,6 +1367,14 @@ void EncodeListSnaps(const ObjSnaps *objSnaps, int i, MOSDOp *mosdop) Salog(LV_ERROR, LOG_TYPE, " mosdop %p or objSnaps %p is null, skip", mosdop, objSnaps); return; } + if ((uint32_t)i >= mosdop->ops.size()) { + Salog(LV_ERROR, LOG_TYPE, " index %d >= %u overflow", i, mosdop->ops.size()); + return; + } + if (objSnaps->cloneInfoNum < 1) { + Salog(LV_ERROR, LOG_TYPE, " cloneInfoNum at lease 1"); + return; + } obj_list_snap_response_t resp; resp.seq = 0; if (objSnaps->cloneInfoNum >= 2) { @@ -1308,7 +1396,7 @@ void EncodeListSnaps(const ObjSnaps *objSnaps, int i, MOSDOp *mosdop) } resp.clones.push_back(ci); } - { + if (objSnaps->cloneInfoNum >= 1) { clone_info ci; CloneInfo &CI = objSnaps->cloneInfos[objSnaps->cloneInfoNum - 1]; ci.cloneid = snapid_t(-2); diff --git a/src/server_adaptor/osa.cpp b/src/server_adaptor/osa.cpp index 28298f4..6359161 100644 --- a/src/server_adaptor/osa.cpp +++ b/src/server_adaptor/osa.cpp @@ -91,6 +91,7 @@ bool CheckLocalIp(const string &ipaddr) 0, NI_NUMERICHOST); if (s != 0) { Salog(LV_ERROR, LOG_TYPE, "getnameinfo error %s", gai_strerror(s)); + freeifaddrs(ifaddr); return ret; } if (ipaddr == host) { @@ -163,7 +164,7 @@ int OSA_Init(SaExport &sa) pPort = strtok_r(nullptr, delimPort, &savePort); } if (vecPort.size() <= 0 || vecPort.size() > 8) { - Salog(LV_CRITICAL, LOG_TYPE, "error : port count is %d", vecPort.size()); + Salog(LV_CRITICAL, LOG_TYPE, "error : port count is %u", vecPort.size()); return ERROR_PORT; } @@ -177,7 +178,13 @@ int OSA_Init(SaExport &sa) char *savep; p = strtok_r(tmp.get(), delim, &savep); while (p) { - int coreId = atoi(p); + errno = 0; + char *end = nullptr; + int coreId = (int)strtol(p, &end, 10); + if (errno == ERANGE || end == p) { + Salog(LV_CRITICAL, LOG_TYPE, "error: get core id from str error"); + return ERROR_PORT; + } if (CheckCoreId(coreId) == false) { Salog(LV_CRITICAL, LOG_TYPE, "error coreNumber %s", coreNumber.c_str()); return ERROR_PORT; @@ -188,30 +195,30 @@ int OSA_Init(SaExport &sa) uint32_t queueAmount = readConfig.GetQueueAmount(); if (queueAmount > SA_QUEUE_MAX_NUM || queueAmount < SA_QUEUE_MIN_NUM) { - Salog(LV_CRITICAL, LOG_TYPE, "error : queueAmount number is %d should between %d~%d", queueAmount, + Salog(LV_CRITICAL, LOG_TYPE, "error : queueAmount number is %u should between %u~%u", queueAmount, SA_QUEUE_MIN_NUM, SA_QUEUE_MAX_NUM); return ERROR_PORT; } uint32_t queueMaxCapacity = readConfig.GetQueueMaxCapacity(); if (queueMaxCapacity > SA_QUEUE_MAX_CAPACITY || queueMaxCapacity < SA_QUEUE_MIN_CAPACITY) { - Salog(LV_CRITICAL, LOG_TYPE, "error : queueMaxCapacity number is %d should between %d~%d", queueMaxCapacity, + Salog(LV_CRITICAL, LOG_TYPE, "error : queueMaxCapacity number is %u should between %u~%u", queueMaxCapacity, SA_QUEUE_MIN_CAPACITY, SA_QUEUE_MAX_CAPACITY); return ERROR_PORT; } uint32_t msgrAmount = readConfig.GetMsgrAmount(); if (msgrAmount > SA_MSGR_MAX_NUM || msgrAmount < SA_MSGR_MIN_NUM) { - Salog(LV_CRITICAL, LOG_TYPE, "error : msgrAmount number is %d should between %d~%d", msgrAmount, + Salog(LV_CRITICAL, LOG_TYPE, "error : msgrAmount number is %u should between %u~%u", msgrAmount, SA_MSGR_MIN_NUM, SA_MSGR_MAX_NUM); return ERROR_PORT; } uint32_t bindCore = readConfig.GetBindCore(); uint32_t bindSaCore = readConfig.GetBindQueueCore(); - Salog(LV_WARNING, LOG_TYPE, "core binding is %d, %d", bindCore, bindSaCore); + Salog(LV_WARNING, LOG_TYPE, "core binding is %u, %u", bindCore, bindSaCore); if((msgrAmount + vecPort.size()) > vecCoreId.size() && bindCore) { - Salog(LV_CRITICAL, LOG_TYPE, "error : SA needs more than %d cores !", (msgrAmount+vecPort.size())); + Salog(LV_CRITICAL, LOG_TYPE, "error : SA needs more than %u cores !", (msgrAmount+vecPort.size())); return ERROR_PORT; } @@ -220,21 +227,21 @@ int OSA_Init(SaExport &sa) qos.getQuotaCycle = readConfig.GetQuotCyc(); qos.enableThrottle = readConfig.GetMessengerThrottle(); qos.saOpThrottle = readConfig.GetSaOpThrottle(); - Salog(LV_WARNING, LOG_TYPE, "SA QoS limitWrite=%d, time_cyc=%d ms, enableThrottle=%d, opThrottle=%lu", + Salog(LV_WARNING, LOG_TYPE, "SA QoS limitWrite=%u, time_cyc=%u ms, enableThrottle=%u, opThrottle=%llu", qos.limitWrite, qos.getQuotaCycle, qos.enableThrottle, qos.saOpThrottle); if (qos.getQuotaCycle < 1) { - Salog(LV_CRITICAL, LOG_TYPE, "error : get quota cycle is %d", qos.getQuotaCycle); + Salog(LV_CRITICAL, LOG_TYPE, "error : get quota cycle is %u", qos.getQuotaCycle); return ERROR_PORT; } if ((qos.saOpThrottle != 0) && (qos.saOpThrottle < 2000 || qos.saOpThrottle > 30000)) { - Salog(LV_CRITICAL, LOG_TYPE, "error : get quota cycle is %d, should in {0, [2000~30000]}", qos.saOpThrottle); + Salog(LV_CRITICAL, LOG_TYPE, "error : get quota cycle is %u, should in {0, [2000~30000]}", qos.saOpThrottle); return ERROR_PORT; } char szMsgrAmount[4] = {0}; sprintf(szMsgrAmount, "%d", msgrAmount); - Salog(LV_INFORMATION, LOG_TYPE, "Server adaptor init queueAmount=%d szMsgrAmount=%s bindCore=%d bindSaCore=%d", + Salog(LV_INFORMATION, LOG_TYPE, "Server adaptor init queueAmount=%u szMsgrAmount=%s bindCore=%u bindSaCore=%u", queueAmount, szMsgrAmount, bindCore, bindSaCore); vector args = { "--conf", "/opt/gcache/conf/gcache.conf" }; @@ -245,7 +252,18 @@ int OSA_Init(SaExport &sa) int ret = 0; if (g_ptrNetwork == nullptr) { - g_ptrNetwork = new NetworkModule(sa, vecCoreId, msgrAmount, bindCore, bindSaCore); + g_ptrNetwork = new(std::nothrow) NetworkModule(sa, vecCoreId, msgrAmount, bindCore, bindSaCore); + if (g_ptrNetwork == nullptr) { + Salog(LV_CRITICAL, LOG_TYPE, "error : memory alloc failed!"); + return 1; + } + rpc_handler = new(std::nothrow) ClassHandler(g_ceph_context); + if (rpc_handler == nullptr) { + Salog(LV_CRITICAL, LOG_TYPE, "error : memory alloc failed!"); + delete g_ptrNetwork; + g_ptrNetwork = nullptr; + return 1; + } g_ptrNetwork->CreateWorkThread(queueAmount, vecPort.size(),queueMaxCapacity); string sAddr = rAddr; string sPort = vecPort[0]; @@ -253,13 +271,24 @@ int OSA_Init(SaExport &sa) Salog(LV_INFORMATION, LOG_TYPE, "Server adaptor init Port=%s" , rPort.c_str()); if (rPort == "") { Salog(LV_CRITICAL, LOG_TYPE, "error : Server adaptor Listen ip:port is empty."); + delete g_ptrNetwork; + g_ptrNetwork = nullptr; + delete rpc_handler; + rpc_handler = nullptr; return 1; } g_ptrNetwork->SetQosParam(qos); int bindSuccess = -1; ret = g_ptrNetwork->InitNetworkModule(rAddr, vecPort, sAddr, sPort, &bindSuccess); + if (ret != 0) { + Salog(LV_CRITICAL, LOG_TYPE, "error : init network module error."); + delete g_ptrNetwork; + g_ptrNetwork = nullptr; + delete rpc_handler; + rpc_handler = nullptr; + return 1; + } - rpc_handler = new ClassHandler(g_ceph_context); cls_initialize(rpc_handler); rpc_init(); @@ -292,6 +321,7 @@ int OSA_Finish() g_ptrNetwork = nullptr; if (rpc_handler) { rpc_handler->shutdown(); + delete rpc_handler; rpc_handler = nullptr; } FinishSalog("sa"); @@ -371,7 +401,7 @@ int OSA_ExecClass(SaOpContext *pctx, PREFETCH_FUNC prefetch) return -EINVAL; } struct SaOpReq * pOpReq = pctx->opReq; - MOSDOp *ptr = reinterpret_cast(pOpReq->ptrMosdop); + MOSDOp *ptr = static_cast(pOpReq->ptrMosdop); if (ptr == nullptr) { Salog(LV_ERROR, LOG_TYPE, " mosdop %p is null, skip", ptr); return -EINVAL; -- Gitee From 4ec8d4c8135684d748f00ffdb537a2aab38fb0df Mon Sep 17 00:00:00 2001 From: songyuhang Date: Tue, 15 Nov 2022 15:50:11 +0800 Subject: [PATCH 2/2] update CA to date-11-15 --- patch/ceph-global-cache.patch | 295 +++++++++++++++++++--------------- 1 file changed, 165 insertions(+), 130 deletions(-) diff --git a/patch/ceph-global-cache.patch b/patch/ceph-global-cache.patch index 8cc38a4..70bebc5 100644 --- a/patch/ceph-global-cache.patch +++ b/patch/ceph-global-cache.patch @@ -1,5 +1,5 @@ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt -index 28ec9835..bf4aa6e8 100644 +index 28ec983..bf4aa6e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -103,6 +103,11 @@ if(HAVE_INTEL) @@ -40,7 +40,7 @@ index 28ec9835..bf4aa6e8 100644 if(WITH_TESTS) diff --git a/src/client_adaptor/CMakeLists.txt b/src/client_adaptor/CMakeLists.txt new file mode 100644 -index 00000000..aba70f7e +index 0000000..aba70f7 --- /dev/null +++ b/src/client_adaptor/CMakeLists.txt @@ -0,0 +1,17 @@ @@ -63,7 +63,7 @@ index 00000000..aba70f7e + diff --git a/src/client_adaptor/ClientAdaptorMgr.cc b/src/client_adaptor/ClientAdaptorMgr.cc new file mode 100644 -index 00000000..f9ca79b1 +index 0000000..900be66 --- /dev/null +++ b/src/client_adaptor/ClientAdaptorMgr.cc @@ -0,0 +1,256 @@ @@ -108,7 +108,7 @@ index 00000000..f9ca79b1 + return RET_OK; +} + -+int32_t CcmNodeChangeNotify(NodeInfo *nodeList, uint32_t nodeNum, void *ctx) { ++int32_t CcmNodeChangeNotify(int32_t clusterId, NodeInfo *nodeList, uint32_t nodeNum, void *ctx) { + if (nodeNum == 0) { + return RET_OK; + } @@ -122,7 +122,7 @@ index 00000000..f9ca79b1 + return RET_OK; + } + Objecter *obj = static_cast(ctx); -+ obj->nodeview_change_retry_op_submit(available_nodes); ++ obj->nodeview_change_retry_op_submit(clusterId, available_nodes); + return RET_OK; +} + @@ -325,7 +325,7 @@ index 00000000..f9ca79b1 +} diff --git a/src/client_adaptor/ClientAdaptorMgr.h b/src/client_adaptor/ClientAdaptorMgr.h new file mode 100644 -index 00000000..7ea053f0 +index 0000000..7ea053f --- /dev/null +++ b/src/client_adaptor/ClientAdaptorMgr.h @@ -0,0 +1,189 @@ @@ -520,7 +520,7 @@ index 00000000..7ea053f0 +#endif diff --git a/src/client_adaptor/ClientAdaptorMsg.cc b/src/client_adaptor/ClientAdaptorMsg.cc new file mode 100644 -index 00000000..ee19bbd5 +index 0000000..ee19bbd --- /dev/null +++ b/src/client_adaptor/ClientAdaptorMsg.cc @@ -0,0 +1,348 @@ @@ -874,7 +874,7 @@ index 00000000..ee19bbd5 +} diff --git a/src/client_adaptor/ClientAdaptorMsg.h b/src/client_adaptor/ClientAdaptorMsg.h new file mode 100644 -index 00000000..80afa785 +index 0000000..80afa78 --- /dev/null +++ b/src/client_adaptor/ClientAdaptorMsg.h @@ -0,0 +1,87 @@ @@ -967,7 +967,7 @@ index 00000000..80afa785 +#endif diff --git a/src/client_adaptor/ClientAdaptorPerf.cc b/src/client_adaptor/ClientAdaptorPerf.cc new file mode 100644 -index 00000000..cea78351 +index 0000000..cea7835 --- /dev/null +++ b/src/client_adaptor/ClientAdaptorPerf.cc @@ -0,0 +1,85 @@ @@ -1058,7 +1058,7 @@ index 00000000..cea78351 +} diff --git a/src/client_adaptor/ClientAdaptorPerf.h b/src/client_adaptor/ClientAdaptorPerf.h new file mode 100644 -index 00000000..f7ee5be5 +index 0000000..f7ee5be --- /dev/null +++ b/src/client_adaptor/ClientAdaptorPerf.h @@ -0,0 +1,55 @@ @@ -1119,7 +1119,7 @@ index 00000000..f7ee5be5 +#endif diff --git a/src/client_adaptor/ClientAdaptorPlugin.cc b/src/client_adaptor/ClientAdaptorPlugin.cc new file mode 100644 -index 00000000..c44e3480 +index 0000000..c44e348 --- /dev/null +++ b/src/client_adaptor/ClientAdaptorPlugin.cc @@ -0,0 +1,45 @@ @@ -1170,7 +1170,7 @@ index 00000000..c44e3480 +} diff --git a/src/client_adaptor/ClientAdaptorPlugin.h b/src/client_adaptor/ClientAdaptorPlugin.h new file mode 100644 -index 00000000..fa7d71d2 +index 0000000..fa7d71d --- /dev/null +++ b/src/client_adaptor/ClientAdaptorPlugin.h @@ -0,0 +1,39 @@ @@ -1215,10 +1215,10 @@ index 00000000..fa7d71d2 +#endif diff --git a/src/client_adaptor/open_ccm.h b/src/client_adaptor/open_ccm.h new file mode 100644 -index 00000000..50b8b372 +index 0000000..2fefc7e --- /dev/null +++ b/src/client_adaptor/open_ccm.h -@@ -0,0 +1,224 @@ +@@ -0,0 +1,209 @@ +/* + * Copyright (c) 2021 Huawei Technologies Co., Ltd All rights reserved. + @@ -1334,11 +1334,6 @@ index 00000000..50b8b372 + +typedef struct { + uint32_t nodeId; -+ uint32_t vnodeId; -+} PtSrcNodeInfo; -+ -+typedef struct { -+ uint32_t nodeId; + uint32_t diskId; + uint32_t vnodeId; +} PtNodeInfo; @@ -1368,7 +1363,7 @@ index 00000000..50b8b372 +/* NodeView callback */ +typedef struct { + void *ctx; -+ int32_t (*notifyNodeChange)(NodeInfo *nodeList, uint32_t nodeNum, void *ctx); ++ int32_t (*notifyNodeChange)(int32_t clusterId, NodeInfo *nodeList, uint32_t nodeNum, void *ctx); +} NodeViewChangeOpHandle; + +/* PTView callback */ @@ -1387,16 +1382,6 @@ index 00000000..50b8b372 + CCM_MODULE_BUTT, +} ModuleType; + -+typedef enum { -+ CACHENODE = 0, -+ CLIENTNODE = 1, -+} NodeType; -+ -+typedef enum { -+ IOTYPE_READ = 0, -+ IOTYPE_WRITE = 1, -+} IOType_E; -+ +typedef struct { + int64_t mdPoolId; + int64_t dataPoolId; @@ -1446,7 +1431,7 @@ index 00000000..50b8b372 \ No newline at end of file diff --git a/src/client_adaptor/open_das.h b/src/client_adaptor/open_das.h new file mode 100644 -index 00000000..6eac9f73 +index 0000000..6eac9f7 --- /dev/null +++ b/src/client_adaptor/open_das.h @@ -0,0 +1,67 @@ @@ -1519,7 +1504,7 @@ index 00000000..6eac9f73 +#endif // OPEN_DAS_H \ No newline at end of file diff --git a/src/common/options.cc b/src/common/options.cc -index 8135ea8f..9d3bb781 100644 +index 8135ea8..9d3bb78 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -1015,7 +1015,7 @@ std::vector