diff --git a/curvefs/conf/tools.conf b/curvefs/conf/tools.conf index ea5a76883e..ca3d0e750a 100644 --- a/curvefs/conf/tools.conf +++ b/curvefs/conf/tools.conf @@ -26,5 +26,5 @@ s3.endpoint=endpoint s3.bucket_name=bucket s3.blocksize=4194304 s3.chunksize=67108864 -# statistic info in xattr +# statistic info in xattr, hardlink will not be supported when enable enableSumInDir=false diff --git a/curvefs/src/client/curve_fuse_op.cpp b/curvefs/src/client/curve_fuse_op.cpp index f99dbdc339..c1cc55e8d8 100644 --- a/curvefs/src/client/curve_fuse_op.cpp +++ b/curvefs/src/client/curve_fuse_op.cpp @@ -209,7 +209,7 @@ void FuseReplyErrByErrCode(fuse_req_t req, CURVEFS_ERROR errcode) { fuse_reply_err(req, ENOTEMPTY); break; case CURVEFS_ERROR::NOTSUPPORT: - fuse_reply_err(req, ENOSYS); + fuse_reply_err(req, EOPNOTSUPP); break; case CURVEFS_ERROR::NAMETOOLONG: fuse_reply_err(req, ENAMETOOLONG); diff --git a/curvefs/src/client/fuse_client.cpp b/curvefs/src/client/fuse_client.cpp index b465c7cd92..b72e876491 100644 --- a/curvefs/src/client/fuse_client.cpp +++ b/curvefs/src/client/fuse_client.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "curvefs/proto/mds.pb.h" #include "curvefs/src/client/fuse_common.h" @@ -308,9 +309,9 @@ CURVEFS_ERROR FuseClient::FuseOpOpen(fuse_req_t req, fuse_ino_t ino, XAttr xattr; xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(length)}); - std::list parentIds; - if (inodeManager_->GetParent(inode->inodeid(), &parentIds)) { - ret = UpdateParentInodeXattr(parentIds, xattr, false); + uint64_t parentId; + if (inodeManager_->GetParent(inode->inodeid(), &parentId)) { + ret = UpdateParentInodeXattr(parentId, xattr, false); } else { LOG(ERROR) << "inodeManager getParent failed, inodeId = " << inode; @@ -417,8 +418,7 @@ CURVEFS_ERROR FuseClient::MakeNode(fuse_req_t req, fuse_ino_t parent, } xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(inodeWrapper->GetLength())}); - ret = UpdateParentInodeXattr( - std::list({parent}), xattr, true); + ret = UpdateParentInodeXattr(parent, xattr, true); } GetDentryParamFromInode(inodeWrapper, e); @@ -516,7 +516,7 @@ CURVEFS_ERROR FuseClient::RemoveNode(fuse_req_t req, fuse_ino_t parent, if (enableSumInDir_) { // remove parent relationshaip - inodeManager_->RemoveParent(ino, parent); + inodeManager_->ClearParent(ino); // update parent summary info XAttr xattr; @@ -528,8 +528,7 @@ CURVEFS_ERROR FuseClient::RemoveNode(fuse_req_t req, fuse_ino_t parent, } xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(inodeWrapper->GetLength())}); - ret = UpdateParentInodeXattr( - std::list({parent}), xattr, false); + ret = UpdateParentInodeXattr(parent, xattr, false); } inodeManager_->ClearInodeCache(ino); @@ -669,17 +668,15 @@ CURVEFS_ERROR FuseClient::FuseOpRename(fuse_req_t req, fuse_ino_t parent, xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(inodeWrapper->GetLength())}); - if (inodeManager_->UpdateParent(ino, parent, newparent)) { + if (inodeManager_->UpdateParent(ino, newparent)) { // TODO(wanghai): deal with failure - rc = UpdateParentInodeXattr( - std::list({parent}), xattr, false); + rc = UpdateParentInodeXattr(parent, xattr, false); if (rc != CURVEFS_ERROR::OK) { LOG(ERROR) << "UpdateParentInodeXattr failed, parentId = " << parent; return rc; } - rc = UpdateParentInodeXattr( - std::list({newparent}), xattr, true); + rc = UpdateParentInodeXattr(newparent, xattr, true); if (rc != CURVEFS_ERROR::OK) { LOG(ERROR) << "UpdateParentInodeXattr failed, parentId = " << newparent; @@ -782,10 +779,10 @@ CURVEFS_ERROR FuseClient::FuseOpSetAttr(fuse_req_t req, fuse_ino_t ino, XAttr xattr; xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(std::abs(changeSize))}); - std::list parentIds; - if (inodeManager_->GetParent(ino, &parentIds)) { + uint64_t parentId; + if (inodeManager_->GetParent(ino, &parentId)) { bool direction = changeSize > 0; - ret = UpdateParentInodeXattr(parentIds, xattr, direction); + ret = UpdateParentInodeXattr(parentId, xattr, direction); } else { LOG(ERROR) << "inodeManager getParent failed, inodeId = " << inode; @@ -858,7 +855,7 @@ CURVEFS_ERROR FuseClient::CalOneLayerSumInfo(Inode *inode) { for (const auto &it : dentryList) { inodeIds.emplace(it.inodeid()); } - ret = inodeManager_->BatchGetInodeAttr(inodeIds, &attrs); + ret = inodeManager_->BatchGetInodeAttr(&inodeIds, &attrs); if (ret == CURVEFS_ERROR::OK) { uint64_t files = 0; uint64_t subdirs = 0; @@ -893,7 +890,8 @@ CURVEFS_ERROR FuseClient::CalOneLayerSumInfo(Inode *inode) { CURVEFS_ERROR FuseClient::CalAllLayerSumInfo(Inode *inode) { std::stack iStack; - // use set can deal with hard link + // record hard link, + std::unordered_map hardLinkMap; std::set inodeIds; std::list attrs; auto ino = inode->inodeid(); @@ -925,7 +923,7 @@ CURVEFS_ERROR FuseClient::CalAllLayerSumInfo(Inode *inode) { } // check size if (inodeIds.size() >= attrsLimit || iStack.empty()) { - ret = inodeManager_->BatchGetInodeAttr(inodeIds, &attrs); + ret = inodeManager_->BatchGetInodeAttr(&inodeIds, &attrs); if (ret == CURVEFS_ERROR::OK) { for (const auto &it : attrs) { if (it.type() == FsFileType::TYPE_DIRECTORY) { @@ -935,6 +933,15 @@ CURVEFS_ERROR FuseClient::CalAllLayerSumInfo(Inode *inode) { } rentries++; rfbytes += it.length(); + // record hardlink + if (it.type() != FsFileType::TYPE_DIRECTORY && + it.nlink() > 1) { + if (hardLinkMap.count(it.inodeid())) { + hardLinkMap[it.inodeid()] += it.length(); + } else { + hardLinkMap.emplace(it.inodeid(), 0); + } + } } inodeIds.clear(); attrs.clear(); @@ -944,6 +951,11 @@ CURVEFS_ERROR FuseClient::CalAllLayerSumInfo(Inode *inode) { } } + // deal with hardlink + for (const auto &it : hardLinkMap) { + rfbytes -= it.second; + } + inode->mutable_xattr()->insert({XATTRRFILES, std::to_string(rfiles)}); inode->mutable_xattr()->insert({XATTRRSUBDIRS, @@ -996,7 +1008,7 @@ CURVEFS_ERROR FuseClient::FastCalAllLayerSumInfo(Inode *inode) { } // check size if (inodeIds.size() >= xattrsLimit || iStack.empty()) { - ret = inodeManager_->BatchGetXAttr(inodeIds, &xattrs); + ret = inodeManager_->BatchGetXAttr(&inodeIds, &xattrs); if (ret == CURVEFS_ERROR::OK) { for (const auto &it : xattrs) { if (it.xattrinfos().count(XATTRFILES)) { @@ -1180,8 +1192,7 @@ CURVEFS_ERROR FuseClient::FuseOpSymlink(fuse_req_t req, const char *link, xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); xattr.mutable_xattrinfos()->insert({XATTRFBYTES, std::to_string(inodeWrapper->GetLength())}); - ret = UpdateParentInodeXattr( - std::list({parent}), xattr, true); + ret = UpdateParentInodeXattr(parent, xattr, true); } GetDentryParamFromInode(inodeWrapper, e); @@ -1194,6 +1205,12 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req, fuse_ino_t ino, LOG(INFO) << "FuseOpLink, ino: " << ino << ", newparent: " << newparent << ", newname: " << newname; + if (enableSumInDir_) { + // don't support hardlink + LOG(ERROR) << "FuseOpLink doesn't support when enableSumInDir."; + return CURVEFS_ERROR::NOTSUPPORT; + } + if (strlen(newname) > option_.maxNameLength) { return CURVEFS_ERROR::NAMETOOLONG; } @@ -1244,19 +1261,6 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req, fuse_ino_t ino, return ret; } - if (enableSumInDir_) { - // recore parent inodeId - inodeManager_->AddParent(inodeWrapper->GetInodeId(), newparent); - // update parent summary info - XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"}); - xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, - std::to_string(inodeWrapper->GetLength())}); - ret = UpdateParentInodeXattr( - std::list({newparent}), xattr, true); - } - GetDentryParamFromInode(inodeWrapper, e); return ret; } @@ -1297,10 +1301,6 @@ CURVEFS_ERROR FuseClient::FuseOpRelease(fuse_req_t req, fuse_ino_t ino, return ret; } - if (enableSumInDir_) { - // update parent relationship - inodeManager_->ClearParent(ino); - } return ret; } @@ -1313,41 +1313,31 @@ void FuseClient::FlushAll() { FlushInodeAll(); } -CURVEFS_ERROR FuseClient::UpdateParentInodeXattr( - const std::list &parentIds, +CURVEFS_ERROR FuseClient::UpdateParentInodeXattr(uint64_t parentId, const XAttr &xattr, bool direction) { - for (const auto &parentId : parentIds) { - VLOG(1) << "UpdateParentInodeXattr inodeId = " << parentId - << ", \nxattr = " << xattr.DebugString(); - std::shared_ptr pInodeWrapper; - CURVEFS_ERROR ret = inodeManager_->GetInode(parentId, pInodeWrapper); - if (ret != CURVEFS_ERROR::OK) { - LOG(ERROR) << "UpdateParentInodeXattr get parent inode fail, ret = " - << ret << ", inodeid = " << parentId; - return ret; - } - // if dirty, flush attr first - if (pInodeWrapper->Dirty()) { - ret = pInodeWrapper->SyncAttr(); - if (ret != CURVEFS_ERROR::OK) { - LOG(ERROR) << "sync parent inode attr failed when" - << " UpdateParentInodeXattr, inodeId = " << parentId; - return ret; - } - } - ::curve::common::UniqueLock lgGuard = pInodeWrapper->GetUniqueLock(); - auto inode = pInodeWrapper->GetMutableInodeUnlocked(); - for (const auto &it : xattr.xattrinfos()) { - auto iter = inode->mutable_xattr()->find(it.first); - if (iter != inode->mutable_xattr()->end()) { - if (!AddUllStringToFirst(&(iter->second), it.second, - direction)) { - return CURVEFS_ERROR::INTERNAL; - } + VLOG(1) << "UpdateParentInodeXattr inodeId = " << parentId + << ", direction = " << direction + << ", \nxattr = " << xattr.DebugString(); + std::shared_ptr pInodeWrapper; + CURVEFS_ERROR ret = inodeManager_->GetInode(parentId, pInodeWrapper); + if (ret != CURVEFS_ERROR::OK) { + LOG(ERROR) << "UpdateParentInodeXattr get parent inode fail, ret = " + << ret << ", inodeid = " << parentId; + return ret; + } + + ::curve::common::UniqueLock lgGuard = pInodeWrapper->GetUniqueLock(); + auto inode = pInodeWrapper->GetMutableInodeUnlocked(); + for (const auto &it : xattr.xattrinfos()) { + auto iter = inode->mutable_xattr()->find(it.first); + if (iter != inode->mutable_xattr()->end()) { + if (!AddUllStringToFirst(&(iter->second), it.second, + direction)) { + return CURVEFS_ERROR::INTERNAL; } } - pInodeWrapper->FlushXattrAsync(); } + pInodeWrapper->FlushXattrAsync(); return CURVEFS_ERROR::OK; } diff --git a/curvefs/src/client/fuse_client.h b/curvefs/src/client/fuse_client.h index ccac1243cc..abeb24cbd2 100644 --- a/curvefs/src/client/fuse_client.h +++ b/curvefs/src/client/fuse_client.h @@ -240,7 +240,7 @@ class FuseClient { return 0; } - CURVEFS_ERROR UpdateParentInodeXattr(const std::list &parentIds, + CURVEFS_ERROR UpdateParentInodeXattr(uint64_t parentId, const XAttr &xattr, bool direction); private: diff --git a/curvefs/src/client/fuse_s3_client.cpp b/curvefs/src/client/fuse_s3_client.cpp index 4840ca4a83..5355d0d101 100644 --- a/curvefs/src/client/fuse_s3_client.cpp +++ b/curvefs/src/client/fuse_s3_client.cpp @@ -108,8 +108,10 @@ CURVEFS_ERROR FuseS3Client::FuseOpWrite(fuse_req_t req, fuse_ino_t ino, Inode *inode = inodeWrapper->GetMutableInodeUnlocked(); *wSize = wRet; + size_t changeSize = 0; // update file len if (inode->length() < off + *wSize) { + changeSize = off + *wSize - inode->length(); inode->set_length(off + *wSize); } struct timespec now; @@ -125,13 +127,13 @@ CURVEFS_ERROR FuseS3Client::FuseOpWrite(fuse_req_t req, fuse_ino_t ino, // Todo: do some cache flush later } - if (enableSumInDir_) { + if (enableSumInDir_ && changeSize != 0) { XAttr xattr; xattr.mutable_xattrinfos()->insert({XATTRFBYTES, - std::to_string(*wSize)}); - std::list parentIds; - if (inodeManager_->GetParent(ino, &parentIds)) { - ret = UpdateParentInodeXattr(parentIds, xattr, true); + std::to_string(changeSize)}); + uint64_t parentId; + if (inodeManager_->GetParent(ino, &parentId)) { + ret = UpdateParentInodeXattr(parentId, xattr, true); } else { LOG(ERROR) << "inodeManager getParent failed, inodeId = " << ino; return CURVEFS_ERROR::INTERNAL; diff --git a/curvefs/src/client/inode_cache_manager.cpp b/curvefs/src/client/inode_cache_manager.cpp index f73ad5a9d0..7708c9dfa8 100644 --- a/curvefs/src/client/inode_cache_manager.cpp +++ b/curvefs/src/client/inode_cache_manager.cpp @@ -82,8 +82,23 @@ CURVEFS_ERROR InodeCacheManagerImpl::GetInode(uint64_t inodeid, } CURVEFS_ERROR InodeCacheManagerImpl::BatchGetInodeAttr( - const std::set &inodeIds, + std::set *inodeIds, std::list *attr) { + // get some inode in icache + for (auto iter = inodeIds->begin(); iter != inodeIds->end();) { + std::shared_ptr inodeWrapper; + NameLockGuard lock(nameLock_, std::to_string(*iter)); + bool ok = iCache_->Get(*iter, &inodeWrapper); + if (ok) { + InodeAttr tmpAttr; + inodeWrapper->GetInodeAttrLocked(&tmpAttr); + attr->emplace_back(tmpAttr); + iter = inodeIds->erase(iter); + } else { + ++iter; + } + } + MetaStatusCode ret = metaClient_->BatchGetInodeAttr(fsId_, inodeIds, attr); if (MetaStatusCode::OK != ret) { LOG(ERROR) << "metaClient BatchGetInodeAttr failed, MetaStatusCode = " @@ -94,8 +109,23 @@ CURVEFS_ERROR InodeCacheManagerImpl::BatchGetInodeAttr( } CURVEFS_ERROR InodeCacheManagerImpl::BatchGetXAttr( - const std::set &inodeIds, + std::set *inodeIds, std::list *xattr) { + // get some inode in icache + for (auto iter = inodeIds->begin(); iter != inodeIds->end();) { + std::shared_ptr inodeWrapper; + NameLockGuard lock(nameLock_, std::to_string(*iter)); + bool ok = iCache_->Get(*iter, &inodeWrapper); + if (ok) { + XAttr tmpXattr; + inodeWrapper->GetXattrLocked(&tmpXattr); + xattr->emplace_back(tmpXattr); + iter = inodeIds->erase(iter); + } else { + ++iter; + } + } + MetaStatusCode ret = metaClient_->BatchGetXAttr(fsId_, inodeIds, xattr); if (MetaStatusCode::OK != ret) { LOG(ERROR) << "metaClient BatchGetXAttr failed, MetaStatusCode = " @@ -182,48 +212,37 @@ void InodeCacheManagerImpl::FlushInodeOnce() { void InodeCacheManagerImpl::AddParent(uint64_t inodeId, uint64_t parentId) { curve::common::LockGuard lg2(parentIdMapMutex_); - if (parentIdMap_.count(inodeId)) { - parentIdMap_[inodeId].emplace_back(parentId); - } else { - parentIdMap_.emplace(inodeId, std::list({parentId})); - } -} - -void InodeCacheManagerImpl::RemoveParent(uint64_t inodeId, uint64_t parentId) { - curve::common::LockGuard lg2(parentIdMapMutex_); - if (parentIdMap_.count(inodeId)) { - auto iter = std::find(parentIdMap_[inodeId].begin(), - parentIdMap_[inodeId].end(), parentId); - if (iter != parentIdMap_[inodeId].end()) { - parentIdMap_[inodeId].erase(iter); - } + if (parentIdMap_.count(inodeId) && parentIdMap_[inodeId] != parentId) { + LOG(WARNING) << "AddParent but exist, inodeId = " << inodeId + << ", parentId = " << parentIdMap_[inodeId] + << ", need2AddParentId = " << parentId; } + parentIdMap_[inodeId] = parentId; } void InodeCacheManagerImpl::ClearParent(uint64_t inodeId) { curve::common::LockGuard lg2(parentIdMapMutex_); parentIdMap_.erase(inodeId); + VLOG(1) << "ClearParent inodeId = " << inodeId + << ", after clear the parentmap size = " + << parentIdMap_.size(); } -bool InodeCacheManagerImpl::UpdateParent(uint64_t inodeId, uint64_t oldParentId, +bool InodeCacheManagerImpl::UpdateParent(uint64_t inodeId, uint64_t newParentId) { curve::common::LockGuard lg2(parentIdMapMutex_); if (parentIdMap_.count(inodeId)) { - auto iter = std::find(parentIdMap_[inodeId].begin(), - parentIdMap_[inodeId].end(), oldParentId); - if (iter != parentIdMap_[inodeId].end()) { - *iter = newParentId; - return true; - } + parentIdMap_[inodeId] = newParentId; + return true; } return false; } bool InodeCacheManagerImpl::GetParent(uint64_t inodeId, - std::list *parentIds) { + uint64_t *parentId) { curve::common::LockGuard lg2(parentIdMapMutex_); if (parentIdMap_.count(inodeId)) { - *parentIds = parentIdMap_[inodeId]; + *parentId = parentIdMap_[inodeId]; return true; } return false; diff --git a/curvefs/src/client/inode_cache_manager.h b/curvefs/src/client/inode_cache_manager.h index 194d6d101d..75e0a78a00 100644 --- a/curvefs/src/client/inode_cache_manager.h +++ b/curvefs/src/client/inode_cache_manager.h @@ -67,10 +67,10 @@ class InodeCacheManager { std::shared_ptr &out) = 0; // NOLINT virtual CURVEFS_ERROR BatchGetInodeAttr( - const std::set &inodeIds, + std::set *inodeIds, std::list *attrs) = 0; - virtual CURVEFS_ERROR BatchGetXAttr(const std::set &inodeIds, + virtual CURVEFS_ERROR BatchGetXAttr(std::set *inodeIds, std::list *xattrs) = 0; virtual CURVEFS_ERROR CreateInode(const InodeParam ¶m, @@ -89,15 +89,11 @@ class InodeCacheManager { virtual void AddParent(uint64_t inodeId, uint64_t parentId) = 0; - virtual void RemoveParent(uint64_t inodeId, uint64_t parentId) = 0; - virtual void ClearParent(uint64_t inodeId) = 0; - virtual bool GetParent(uint64_t inodeId, - std::list *parentIds) = 0; + virtual bool GetParent(uint64_t inodeId, uint64_t *parentId) = 0; - virtual bool UpdateParent(uint64_t inodeId, uint64_t oldParentId, - uint64_t newParentId) = 0; + virtual bool UpdateParent(uint64_t inodeId, uint64_t newParentId) = 0; protected: uint32_t fsId_; @@ -129,10 +125,10 @@ class InodeCacheManagerImpl : public InodeCacheManager { CURVEFS_ERROR GetInode(uint64_t inodeid, std::shared_ptr &out) override; // NOLINT - CURVEFS_ERROR BatchGetInodeAttr(const std::set &inodeIds, + CURVEFS_ERROR BatchGetInodeAttr(std::set *inodeIds, std::list *attrs) override; - CURVEFS_ERROR BatchGetXAttr(const std::set &inodeIds, + CURVEFS_ERROR BatchGetXAttr(std::set *inodeIds, std::list *xattrs) override; CURVEFS_ERROR CreateInode(const InodeParam ¶m, @@ -151,14 +147,11 @@ class InodeCacheManagerImpl : public InodeCacheManager { void AddParent(uint64_t inodeId, uint64_t parentId) override; - void RemoveParent(uint64_t inodeId, uint64_t parentId) override; - void ClearParent(uint64_t inodeId) override; - bool GetParent(uint64_t inodeId, std::list *parentIds) override; + bool GetParent(uint64_t inodeId, uint64_t *parentId) override; - bool UpdateParent(uint64_t inodeId, uint64_t oldParentId, - uint64_t newParentId) override; + bool UpdateParent(uint64_t inodeId, uint64_t newParentId) override; private: std::shared_ptr metaClient_; @@ -168,8 +161,8 @@ class InodeCacheManagerImpl : public InodeCacheManager { std::map> dirtyMap_; curve::common::Mutex dirtyMapMutex_; - // inodeid to parent inodeid, may have more parent at hard link - std::map> parentIdMap_; + // inodeid to parent inodeid + std::map parentIdMap_; curve::common::Mutex parentIdMapMutex_; curve::common::GenericNameLock nameLock_; diff --git a/curvefs/src/client/inode_wrapper.cpp b/curvefs/src/client/inode_wrapper.cpp index bb60e406e5..31e59eddc1 100644 --- a/curvefs/src/client/inode_wrapper.cpp +++ b/curvefs/src/client/inode_wrapper.cpp @@ -180,12 +180,9 @@ void InodeWrapper::FlushAttrAsync() { } void InodeWrapper::FlushXattrAsync() { - if (dirty_) { - LockSyncingXattr(); - auto *done = new UpdateXattrAsyncDone(shared_from_this()); - metaClient_->UpdateXattrAsync(inode_, done); - dirty_ = false; - } + LockSyncingXattr(); + auto *done = new UpdateXattrAsyncDone(shared_from_this()); + metaClient_->UpdateXattrAsync(inode_, done); } void InodeWrapper::FlushS3ChunkInfoAsync() { diff --git a/curvefs/src/client/inode_wrapper.h b/curvefs/src/client/inode_wrapper.h index af2c58d80d..fe21b541c6 100644 --- a/curvefs/src/client/inode_wrapper.h +++ b/curvefs/src/client/inode_wrapper.h @@ -176,6 +176,43 @@ class InodeWrapper : public std::enable_shared_from_this { return; } + void GetInodeAttrLocked(InodeAttr *attr) { + curve::common::UniqueLock lg(mtx_); + attr->set_inodeid(inode_.inodeid()); + attr->set_fsid(inode_.fsid()); + attr->set_length(inode_.length()); + attr->set_ctime(inode_.ctime()); + attr->set_ctime_ns(inode_.ctime_ns()); + attr->set_mtime(inode_.mtime()); + attr->set_mtime_ns(inode_.mtime_ns()); + attr->set_atime(inode_.atime()); + attr->set_atime_ns(inode_.atime_ns()); + attr->set_uid(inode_.uid()); + attr->set_gid(inode_.gid()); + attr->set_mode(inode_.mode()); + attr->set_nlink(inode_.nlink()); + attr->set_type(inode_.type()); + if (inode_.has_symlink()) { + attr->set_symlink(inode_.symlink()); + } + if (inode_.has_rdev()) { + attr->set_rdev(inode_.rdev()); + } + if (inode_.has_dtime()) { + attr->set_dtime(inode_.dtime()); + } + if (inode_.has_openmpcount()) { + attr->set_openmpcount(inode_.openmpcount()); + } + } + + void GetXattrLocked(XAttr *xattr) { + curve::common::UniqueLock lg(mtx_); + xattr->set_fsid(inode_.fsid()); + xattr->set_inodeid(inode_.inodeid()); + *(xattr->mutable_xattrinfos()) = inode_.xattr(); + } + bool GetXattrUnLocked(const char *name, std::string *value) { auto it = inode_.xattr().find(name); if (it != inode_.xattr().end()) { diff --git a/curvefs/src/client/rpcclient/metaserver_client.cpp b/curvefs/src/client/rpcclient/metaserver_client.cpp index ea3bfec284..c66ea81a5e 100644 --- a/curvefs/src/client/rpcclient/metaserver_client.cpp +++ b/curvefs/src/client/rpcclient/metaserver_client.cpp @@ -448,9 +448,9 @@ MetaStatusCode MetaServerClientImpl::GetInode(uint32_t fsId, uint64_t inodeid, bool GroupInodeIdByPartition( uint32_t fsId, std::shared_ptr metaCache, - const std::set &inodeIds, + std::set *inodeIds, std::unordered_map> *inodeGroups) { - for (const auto &it : inodeIds) { + for (const auto &it : *inodeIds) { uint32_t pId = 0; if (metaCache->GetPartitionIdByInodeId(fsId, it, &pId)) { auto iter = inodeGroups->find(pId); @@ -469,7 +469,7 @@ bool GroupInodeIdByPartition( } MetaStatusCode MetaServerClientImpl::BatchGetInodeAttr(uint32_t fsId, - const std::set &inodeIds, + std::set *inodeIds, std::list *attr) { uint32_t limit = opt_.batchLimit; // group inodeid by partition @@ -548,7 +548,7 @@ MetaStatusCode MetaServerClientImpl::BatchGetInodeAttr(uint32_t fsId, } MetaStatusCode MetaServerClientImpl::BatchGetXAttr(uint32_t fsId, - const std::set &inodeIds, + std::set *inodeIds, std::list *xattr) { uint32_t limit = opt_.batchLimit; // group inodeid by partition diff --git a/curvefs/src/client/rpcclient/metaserver_client.h b/curvefs/src/client/rpcclient/metaserver_client.h index f532f68154..8c550caf54 100644 --- a/curvefs/src/client/rpcclient/metaserver_client.h +++ b/curvefs/src/client/rpcclient/metaserver_client.h @@ -87,11 +87,11 @@ class MetaServerClient { Inode *out) = 0; virtual MetaStatusCode BatchGetInodeAttr(uint32_t fsId, - const std::set &inodeIds, + std::set *inodeIds, std::list *attr) = 0; virtual MetaStatusCode BatchGetXAttr(uint32_t fsId, - const std::set &inodeIds, + std::set *inodeIds, std::list *xattr) = 0; virtual MetaStatusCode UpdateInode(const Inode &inode, @@ -159,11 +159,11 @@ class MetaServerClientImpl : public MetaServerClient { Inode *out) override; MetaStatusCode BatchGetInodeAttr(uint32_t fsId, - const std::set &inodeIds, + std::set *inodeIds, std::list *attr) override; MetaStatusCode BatchGetXAttr(uint32_t fsId, - const std::set &inodeIds, + std::set *inodeIds, std::list *xattr) override; MetaStatusCode UpdateInode(const Inode &inode, diff --git a/curvefs/test/client/mock_inode_cache_manager.h b/curvefs/test/client/mock_inode_cache_manager.h index 8771135a63..97f4560b33 100644 --- a/curvefs/test/client/mock_inode_cache_manager.h +++ b/curvefs/test/client/mock_inode_cache_manager.h @@ -45,10 +45,10 @@ class MockInodeCacheManager : public InodeCacheManager { uint64_t inodeid, std::shared_ptr &out)); // NOLINT MOCK_METHOD2(BatchGetInodeAttr, CURVEFS_ERROR( - const std::set &inodeIds, std::list *attrs)); + std::set *inodeIds, std::list *attrs)); MOCK_METHOD2(BatchGetXAttr, CURVEFS_ERROR( - const std::set &inodeIds, std::list *xattrs)); + std::set *inodeIds, std::list *xattrs)); MOCK_METHOD2(CreateInode, CURVEFS_ERROR(const InodeParam ¶m, std::shared_ptr &out)); // NOLINT @@ -67,16 +67,13 @@ class MockInodeCacheManager : public InodeCacheManager { MOCK_METHOD2(AddParent, void(uint64_t inodeId, uint64_t parentId)); - MOCK_METHOD2(RemoveParent, void(uint64_t inodeId, - uint64_t parentId)); - MOCK_METHOD1(ClearParent, void(uint64_t inodeId)); MOCK_METHOD2(GetParent, bool(uint64_t inodeId, - std::list *parentId)); + uint64_t *parentId)); - MOCK_METHOD3(UpdateParent, bool(uint64_t inodeId, - uint64_t oldParentId, uint64_t newParentId)); + MOCK_METHOD2(UpdateParent, bool(uint64_t inodeId, + uint64_t newParentId)); }; } // namespace client diff --git a/curvefs/test/client/mock_metaserver_client.h b/curvefs/test/client/mock_metaserver_client.h index 2e7a008748..1cb7c48b51 100644 --- a/curvefs/test/client/mock_metaserver_client.h +++ b/curvefs/test/client/mock_metaserver_client.h @@ -76,11 +76,11 @@ class MockMetaServerClient : public MetaServerClient { uint32_t fsId, uint64_t inodeid, Inode *out)); MOCK_METHOD3(BatchGetInodeAttr, MetaStatusCode( - uint32_t fsId, const std::set &inodeIds, + uint32_t fsId, std::set *inodeIds, std::list *attr)); MOCK_METHOD3(BatchGetXAttr, MetaStatusCode( - uint32_t fsId, const std::set &inodeIds, + uint32_t fsId, std::set *inodeIds, std::list *xattr)); MOCK_METHOD2(UpdateInode, diff --git a/curvefs/test/client/rpcclient/metaserver_client_test.cpp b/curvefs/test/client/rpcclient/metaserver_client_test.cpp index 73a1af45b3..706093e6fa 100644 --- a/curvefs/test/client/rpcclient/metaserver_client_test.cpp +++ b/curvefs/test/client/rpcclient/metaserver_client_test.cpp @@ -1059,7 +1059,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetInodeAttr) { SetArgPointee<3>(applyIndex), Return(true))); MetaStatusCode status = metaserverCli_.BatchGetInodeAttr( - fsid, inodeIds, &attr); + fsid, &inodeIds, &attr); ASSERT_EQ(MetaStatusCode::RPC_ERROR, status); // test1: batchGetInodeAttr ok @@ -1081,7 +1081,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetInodeAttr) { BatchGetInodeAttrResponse>))); EXPECT_CALL(*mockMetacache_.get(), UpdateApplyIndex(_, _)); - status = metaserverCli_.BatchGetInodeAttr(fsid, inodeIds, &attr); + status = metaserverCli_.BatchGetInodeAttr(fsid, &inodeIds, &attr); ASSERT_EQ(MetaStatusCode::OK, status); ASSERT_EQ(attr.size(), 2); ASSERT_THAT(attr.begin()->inodeid(), AnyOf(inodeId1, inodeId2)); @@ -1097,7 +1097,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetInodeAttr) { DoAll(SetArgPointee<2>(response), Invoke(SetRpcService))); - status = metaserverCli_.BatchGetInodeAttr(fsid, inodeIds, &attr); + status = metaserverCli_.BatchGetInodeAttr(fsid, &inodeIds, &attr); ASSERT_EQ(MetaStatusCode::NOT_FOUND, status); // test3: test response do not have applyindex @@ -1113,7 +1113,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetInodeAttr) { Invoke(SetRpcService))); - status = metaserverCli_.BatchGetInodeAttr(fsid, inodeIds, &attr); + status = metaserverCli_.BatchGetInodeAttr(fsid, &inodeIds, &attr); ASSERT_EQ(MetaStatusCode::RPC_ERROR, status); } @@ -1161,7 +1161,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetXAttr) { SetArgPointee<3>(applyIndex), Return(true))); MetaStatusCode status = metaserverCli_.BatchGetXAttr( - fsid, inodeIds, &xattr); + fsid, &inodeIds, &xattr); ASSERT_EQ(MetaStatusCode::RPC_ERROR, status); // test1: batchGetXAttr ok @@ -1183,7 +1183,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetXAttr) { BatchGetXAttrResponse>))); EXPECT_CALL(*mockMetacache_.get(), UpdateApplyIndex(_, _)); - status = metaserverCli_.BatchGetXAttr(fsid, inodeIds, &xattr); + status = metaserverCli_.BatchGetXAttr(fsid, &inodeIds, &xattr); ASSERT_EQ(MetaStatusCode::OK, status); ASSERT_EQ(xattr.size(), 2); ASSERT_THAT(xattr.begin()->inodeid(), AnyOf(inodeId1, inodeId2)); @@ -1199,7 +1199,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetXAttr) { DoAll(SetArgPointee<2>(response), Invoke(SetRpcService))); - status = metaserverCli_.BatchGetXAttr(fsid, inodeIds, &xattr); + status = metaserverCli_.BatchGetXAttr(fsid, &inodeIds, &xattr); ASSERT_EQ(MetaStatusCode::NOT_FOUND, status); // test3: test response do not have applyindex @@ -1215,7 +1215,7 @@ TEST_F(MetaServerClientImplTest, test_BatchGetXAttr) { Invoke(SetRpcService))); - status = metaserverCli_.BatchGetXAttr(fsid, inodeIds, &xattr); + status = metaserverCli_.BatchGetXAttr(fsid, &inodeIds, &xattr); ASSERT_EQ(MetaStatusCode::RPC_ERROR, status); } diff --git a/curvefs/test/client/test_fuse_client.cpp b/curvefs/test/client/test_fuse_client.cpp index b901fdf7bc..fc2acf5f76 100644 --- a/curvefs/test/client/test_fuse_client.cpp +++ b/curvefs/test/client/test_fuse_client.cpp @@ -2577,8 +2577,7 @@ TEST_F(TestFuseS3Client, FuseOpWrite_EnableSummary) { parentInode.mutable_xattr()->insert({XATTRENTRIES, "1"}); parentInode.mutable_xattr()->insert({XATTRFBYTES, "0"}); - std::list parentIds; - parentIds.emplace_back(1); + uint64_t parentId = 1; auto parentInodeWrapper = std::make_shared( parentInode, metaClient_); @@ -2592,7 +2591,7 @@ TEST_F(TestFuseS3Client, FuseOpWrite_EnableSummary) { EXPECT_CALL(*s3ClientAdaptor_, Write(_, _, _, _)) .WillOnce(Return(size)); EXPECT_CALL(*inodeManager_, GetParent(_, _)) - .WillOnce(DoAll(SetArgPointee<1>(parentIds), Return(true))); + .WillOnce(DoAll(SetArgPointee<1>(parentId), Return(true))); EXPECT_CALL(*metaClient_, UpdateXattrAsync(_, _)) .WillOnce(Invoke([](const Inode &inode, MetaServerClientDone *done){ @@ -2621,61 +2620,9 @@ TEST_F(TestFuseS3Client, FuseOpLink_EnableSummary) { fuse_ino_t newparent = 2; const char* newname = "xxxx"; - uint32_t nlink = 100; - - Inode inode; - inode.set_inodeid(ino); - inode.set_length(0); - inode.set_nlink(nlink); - auto inodeWrapper = std::make_shared(inode, metaClient_); - - Inode parentInode; - parentInode.set_fsid(fsId); - parentInode.set_inodeid(newparent); - parentInode.set_type(FsFileType::TYPE_DIRECTORY); - parentInode.set_nlink(2); - parentInode.mutable_xattr()->insert({XATTRFILES, "1"}); - parentInode.mutable_xattr()->insert({XATTRSUBDIRS, "1"}); - parentInode.mutable_xattr()->insert({XATTRENTRIES, "2"}); - parentInode.mutable_xattr()->insert({XATTRFBYTES, "100"}); - auto parentInodeWrapper = std::make_shared( - parentInode, metaClient_); - - EXPECT_CALL(*inodeManager_, GetInode(_, _)) - .WillOnce( - DoAll(SetArgReferee<1>(inodeWrapper), Return(CURVEFS_ERROR::OK))) - .WillOnce( - DoAll(SetArgReferee<1>(parentInodeWrapper), - Return(CURVEFS_ERROR::OK))) - .WillOnce( - DoAll(SetArgReferee<1>(parentInodeWrapper), - Return(CURVEFS_ERROR::OK))); - - EXPECT_CALL(*dentryManager_, CreateDentry(_)) - .WillOnce(Return(CURVEFS_ERROR::OK)); - - EXPECT_CALL(*metaClient_, UpdateInode(_, _)) - .WillRepeatedly(Return(MetaStatusCode::OK)); - EXPECT_CALL(*inodeManager_, AddParent(_, _)) - .Times(1); - EXPECT_CALL(*metaClient_, UpdateXattrAsync(_, _)) - .WillOnce(Invoke([](const Inode &inode, - MetaServerClientDone *done){ - done->SetMetaStatusCode(MetaStatusCode::OK); - done->Run(); - })); - fuse_entry_param e; CURVEFS_ERROR ret = client_->FuseOpLink(req, ino, newparent, newname, &e); - ASSERT_EQ(CURVEFS_ERROR::OK, ret); - Inode inode2 = inodeWrapper->GetInodeUnlocked(); - ASSERT_EQ(nlink + 1, inode2.nlink()); - - auto p = parentInodeWrapper->GetInodeLocked(); - ASSERT_EQ(p.xattr().find(XATTRFILES)->second, "2"); - ASSERT_EQ(p.xattr().find(XATTRSUBDIRS)->second, "1"); - ASSERT_EQ(p.xattr().find(XATTRENTRIES)->second, "3"); - ASSERT_EQ(p.xattr().find(XATTRFBYTES)->second, "100"); + ASSERT_EQ(CURVEFS_ERROR::NOTSUPPORT, ret); } TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) { @@ -2733,7 +2680,7 @@ TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) { EXPECT_CALL(*metaClient_, UpdateInode(_, _)) .WillRepeatedly(Return(MetaStatusCode::OK)); - EXPECT_CALL(*inodeManager_, RemoveParent(_, _)) + EXPECT_CALL(*inodeManager_, ClearParent(_)) .Times(1); EXPECT_CALL(*metaClient_, UpdateXattrAsync(_, _)) .WillOnce(Invoke([](const Inode &inode, @@ -2786,8 +2733,7 @@ TEST_F(TestFuseS3Client, FuseOpOpen_Trunc_EnableSummary) { auto parentInodeWrapper = std::make_shared( parentInode, metaClient_); - std::list parentIds; - parentIds.emplace_back(1); + uint64_t parentId = 1; EXPECT_CALL(*inodeManager_, GetInode(ino, _)) .WillOnce( @@ -2800,7 +2746,7 @@ TEST_F(TestFuseS3Client, FuseOpOpen_Trunc_EnableSummary) { EXPECT_CALL(*metaClient_, UpdateInode(_, _)) .WillRepeatedly(Return(MetaStatusCode::OK)); EXPECT_CALL(*inodeManager_, GetParent(_, _)) - .WillOnce(DoAll(SetArgPointee<1>(parentIds), Return(true))); + .WillOnce(DoAll(SetArgPointee<1>(parentId), Return(true))); EXPECT_CALL(*metaClient_, UpdateXattrAsync(_, _)) .WillOnce(Invoke([](const Inode &inode, MetaServerClientDone *done){ diff --git a/curvefs/test/client/test_inode_cache_manager.cpp b/curvefs/test/client/test_inode_cache_manager.cpp index bf6383b32e..777431151a 100644 --- a/curvefs/test/client/test_inode_cache_manager.cpp +++ b/curvefs/test/client/test_inode_cache_manager.cpp @@ -234,16 +234,16 @@ TEST_F(TestInodeCacheManager, BatchGetInodeAttr) { attr.set_inodeid(inodeId2); attrs.emplace_back(attr); - EXPECT_CALL(*metaClient_, BatchGetInodeAttr(fsId_, inodeIds, _)) + EXPECT_CALL(*metaClient_, BatchGetInodeAttr(fsId_, &inodeIds, _)) .WillOnce(Return(MetaStatusCode::NOT_FOUND)) .WillOnce(DoAll(SetArgPointee<2>(attrs), Return(MetaStatusCode::OK))); std::list getAttrs; - CURVEFS_ERROR ret = iCacheManager_->BatchGetInodeAttr(inodeIds, &getAttrs); + CURVEFS_ERROR ret = iCacheManager_->BatchGetInodeAttr(&inodeIds, &getAttrs); ASSERT_EQ(CURVEFS_ERROR::NOTEXIST, ret); - ret = iCacheManager_->BatchGetInodeAttr(inodeIds, &getAttrs); + ret = iCacheManager_->BatchGetInodeAttr(&inodeIds, &getAttrs); ASSERT_EQ(CURVEFS_ERROR::OK, ret); ASSERT_EQ(getAttrs.size(), 2); ASSERT_THAT(getAttrs.begin()->inodeid(), AnyOf(inodeId1, inodeId2)); @@ -274,16 +274,16 @@ TEST_F(TestInodeCacheManager, BatchGetXAttr) { xattr.mutable_xattrinfos()->find(XATTRFBYTES)->second = "200"; xattrs.emplace_back(xattr); - EXPECT_CALL(*metaClient_, BatchGetXAttr(fsId_, inodeIds, _)) + EXPECT_CALL(*metaClient_, BatchGetXAttr(fsId_, &inodeIds, _)) .WillOnce(Return(MetaStatusCode::NOT_FOUND)) .WillOnce(DoAll(SetArgPointee<2>(xattrs), Return(MetaStatusCode::OK))); std::list getXAttrs; - CURVEFS_ERROR ret = iCacheManager_->BatchGetXAttr(inodeIds, &getXAttrs); + CURVEFS_ERROR ret = iCacheManager_->BatchGetXAttr(&inodeIds, &getXAttrs); ASSERT_EQ(CURVEFS_ERROR::NOTEXIST, ret); - ret = iCacheManager_->BatchGetXAttr(inodeIds, &getXAttrs); + ret = iCacheManager_->BatchGetXAttr(&inodeIds, &getXAttrs); ASSERT_EQ(CURVEFS_ERROR::OK, ret); ASSERT_EQ(getXAttrs.size(), 2); ASSERT_THAT(getXAttrs.begin()->inodeid(), AnyOf(inodeId1, inodeId2)); @@ -298,36 +298,23 @@ TEST_F(TestInodeCacheManager, ParentMap) { uint64_t p2 = 200; uint64_t p3 = 300; - std::list parents; - ASSERT_FALSE(iCacheManager_->GetParent(inodeId1, &parents)); + uint64_t parent; + ASSERT_FALSE(iCacheManager_->GetParent(inodeId1, &parent)); iCacheManager_->AddParent(inodeId1, p1); - ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parents)); - ASSERT_EQ(parents.size(), 1); - ASSERT_EQ(*(parents.begin()), p1); + ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parent)); + ASSERT_EQ(parent, p1); - parents.clear(); iCacheManager_->AddParent(inodeId1, p2); - ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parents)); - ASSERT_EQ(parents.size(), 2); - ASSERT_EQ(*(parents.begin()), p1); - ASSERT_EQ(*(++parents.begin()), p2); - - parents.clear(); - ASSERT_TRUE(iCacheManager_->UpdateParent(inodeId1, p1, p3)); - ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parents)); - ASSERT_EQ(parents.size(), 2); - ASSERT_EQ(*(parents.begin()), p3); - - parents.clear(); - iCacheManager_->RemoveParent(inodeId1, p3); - ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parents)); - ASSERT_EQ(parents.size(), 1); - ASSERT_EQ(*(parents.begin()), p2); - - parents.clear(); + ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parent)); + ASSERT_EQ(parent, p2); + + ASSERT_TRUE(iCacheManager_->UpdateParent(inodeId1, p3)); + ASSERT_TRUE(iCacheManager_->GetParent(inodeId1, &parent)); + ASSERT_EQ(parent, p3); + iCacheManager_->ClearParent(inodeId1); - ASSERT_FALSE(iCacheManager_->GetParent(inodeId1, &parents)); + ASSERT_FALSE(iCacheManager_->GetParent(inodeId1, &parent)); } } // namespace client diff --git a/curvefs/test/mds/mds_test.cpp b/curvefs/test/mds/mds_test.cpp index 81195a8100..8e5de6c913 100644 --- a/curvefs/test/mds/mds_test.cpp +++ b/curvefs/test/mds/mds_test.cpp @@ -91,7 +91,7 @@ class MdsTest : public ::testing::Test { EtcdConf conf{const_cast(kEtcdAddr), strlen(kEtcdAddr), 1000}; uint64_t now = curve::common::TimeUtility::GetTimeofDaySec(); bool initSucc = false; - while (curve::common::TimeUtility::GetTimeofDaySec() - now <= 5) { + while (curve::common::TimeUtility::GetTimeofDaySec() - now <= 50) { if (0 == client->Init(conf, 0, 3)) { initSucc = true; break;