diff --git a/curvefs/conf/client.conf b/curvefs/conf/client.conf index 3e44aab314..96561d0ff6 100644 --- a/curvefs/conf/client.conf +++ b/curvefs/conf/client.conf @@ -134,15 +134,15 @@ fuseClient.throttle.burstReadIopsSecs=180 #### filesystem metadata # { -# fs.disableXattr: +# fs.disableXAttr: # if you want to get better metadata performance, -# you can mount fs with |fs.disableXattr| is true +# you can mount fs with |fs.disableXAttr| is true # # fs.lookupCache.negativeTimeoutSec: # entry which not found will be cached if |timeout| > 0 fs.cto=true fs.maxNameLength=255 -fs.disableXattr=false +fs.disableXAttr=true fs.accessLogging=true fs.kernelCache.attrTimeoutSec=3600 fs.kernelCache.dirAttrTimeoutSec=3600 diff --git a/curvefs/src/client/BUILD b/curvefs/src/client/BUILD index b296af86f8..677e32b0b6 100644 --- a/curvefs/src/client/BUILD +++ b/curvefs/src/client/BUILD @@ -32,6 +32,16 @@ cc_binary( ], ) +cc_library( + name = "filesystem_xattr", + hdrs = ["filesystem/xattr.h"], + copts = CURVE_DEFAULT_COPTS, + visibility = ["//visibility:public"], + deps = [ + "//external:bvar", + ], +) + cc_library( name = "fuse_client_lib", srcs = glob( @@ -64,6 +74,7 @@ cc_library( "//curvefs/src/common:curvefs_common", "//curvefs/src/client/lease:curvefs_lease", "//curvefs/src/client/kvclient:memcached_client_lib", + ":filesystem_xattr", "//external:brpc", "//external:gflags", "//external:glog", @@ -80,6 +91,7 @@ cc_library( "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/meta:type_traits", "@com_google_absl//absl/types:optional", + "@com_google_absl//absl/container:btree", "@com_google_googletest//:gtest_prod", "@spdlog//:spdlog", ], diff --git a/curvefs/src/client/common/common.h b/curvefs/src/client/common/common.h index a1a1d704c2..88e4c4500f 100644 --- a/curvefs/src/client/common/common.h +++ b/curvefs/src/client/common/common.h @@ -64,12 +64,6 @@ enum class MetaServerOpType { std::ostream &operator<<(std::ostream &os, MetaServerOpType optype); -const uint32_t MAX_XATTR_NAME_LENGTH = 255; -const uint32_t MAX_XATTR_VALUE_LENGTH = 64 * 1024; - -const char kCurveFsWarmupXAttr[] = "curvefs.warmup.op"; - - constexpr int kWarmupOpNum = 4; enum class WarmupOpType { diff --git a/curvefs/src/client/common/config.cpp b/curvefs/src/client/common/config.cpp index c353b643f7..04248618d5 100644 --- a/curvefs/src/client/common/config.cpp +++ b/curvefs/src/client/common/config.cpp @@ -298,7 +298,7 @@ void InitKVClientManagerOpt(Configuration *conf, void InitFileSystemOption(Configuration* c, FileSystemOption* option) { c->GetValueFatalIfFail("fs.cto", &option->cto); c->GetValueFatalIfFail("fs.cto", &FLAGS_enableCto); - c->GetValueFatalIfFail("fs.disableXattr", &option->disableXattr); + c->GetValueFatalIfFail("fs.disableXAttr", &option->disableXAttr); c->GetValueFatalIfFail("fs.maxNameLength", &option->maxNameLength); c->GetValueFatalIfFail("fs.accessLogging", &FLAGS_access_logging); { // kernel cache option diff --git a/curvefs/src/client/common/config.h b/curvefs/src/client/common/config.h index ff0b399e93..a787f63616 100644 --- a/curvefs/src/client/common/config.h +++ b/curvefs/src/client/common/config.h @@ -214,7 +214,7 @@ struct DeferSyncOption { struct FileSystemOption { bool cto; - bool disableXattr; + bool disableXAttr; uint32_t maxNameLength; uint32_t blockSize = 0x10000u; KernelCacheOption kernelCacheOption; diff --git a/curvefs/src/client/curve_fuse_op.cpp b/curvefs/src/client/curve_fuse_op.cpp index 47d54cc3b1..969aef1d60 100644 --- a/curvefs/src/client/curve_fuse_op.cpp +++ b/curvefs/src/client/curve_fuse_op.cpp @@ -45,6 +45,8 @@ #include "curvefs/src/client/warmup/warmup_manager.h" #include "curvefs/src/client/filesystem/meta.h" #include "curvefs/src/client/filesystem/access_log.h" +#include "curvefs/src/client/filesystem/metric.h" +#include "curvefs/src/client/filesystem/xattr.h" using ::curve::common::Configuration; using ::curvefs::client::CURVEFS_ERROR; @@ -67,6 +69,7 @@ using ::curvefs::client::filesystem::Logger; using ::curvefs::client::filesystem::StrEntry; using ::curvefs::client::filesystem::StrAttr; using ::curvefs::client::filesystem::StrMode; +using ::curvefs::client::filesystem::IsWarmupXAttr; using ::curvefs::common::FLAGS_vlog_level; @@ -312,12 +315,6 @@ FuseClient* Client() { return g_ClientInstance; } -const char* warmupXAttr = ::curvefs::client::common::kCurveFsWarmupXAttr; - -bool IsWamupReq(const char* name) { - return strcmp(name, warmupXAttr) == 0; -} - void TriggerWarmup(fuse_req_t req, fuse_ino_t ino, const char* name, @@ -803,7 +800,8 @@ void FuseOpSetXattr(fuse_req_t req, ino, name, size, flags, StrErr(rc)); }); - if (IsWamupReq(name)) { + // FIXME(Wine93): please handle it in FuseClient. + if (IsWarmupXAttr(name)) { return TriggerWarmup(req, ino, name, value, size); } rc = client->FuseOpSetXattr(req, ino, name, value, size, flags); @@ -824,7 +822,8 @@ void FuseOpGetXattr(fuse_req_t req, ino, name, size, StrErr(rc), value.size()); }); - if (IsWamupReq(name)) { + // FIXME(Wine93): please handle it in FuseClient. + if (IsWarmupXAttr(name)) { return QueryWarmup(req, ino, size); } diff --git a/curvefs/src/client/filesystem/xattr.h b/curvefs/src/client/filesystem/xattr.h new file mode 100644 index 0000000000..e8c7dabf3d --- /dev/null +++ b/curvefs/src/client/filesystem/xattr.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 NetEase Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Project: Curve + * Created Date: 2023-07-19 + * Author: Jingli Chen (Wine93) + */ + +#include +#include +#include + +#ifndef CURVEFS_SRC_CLIENT_FILESYSTEM_XATTR_H_ +#define CURVEFS_SRC_CLIENT_FILESYSTEM_XATTR_H_ + +namespace curvefs { +namespace client { +namespace filesystem { + +const uint32_t MAX_XATTR_NAME_LENGTH = 255; +const uint32_t MAX_XATTR_VALUE_LENGTH = 64 * 1024; + +const char XATTR_DIR_FILES[] = "curve.dir.files"; +const char XATTR_DIR_SUBDIRS[] = "curve.dir.subdirs"; +const char XATTR_DIR_ENTRIES[] = "curve.dir.entries"; +const char XATTR_DIR_FBYTES[] = "curve.dir.fbytes"; +const char XATTR_DIR_RFILES[] = "curve.dir.rfiles"; +const char XATTR_DIR_RSUBDIRS[] = "curve.dir.rsubdirs"; +const char XATTR_DIR_RENTRIES[] = "curve.dir.rentries"; +const char XATTR_DIR_RFBYTES[] = "curve.dir.rfbytes"; +const char XATTR_DIR_PREFIX[] = "curve.dir"; +const char XATTR_WARMUP_OP[] = "curvefs.warmup.op"; + +inline bool IsSpecialXAttr(const std::string& key) { + static std::map xattrs { + { XATTR_DIR_FILES, true }, + { XATTR_DIR_SUBDIRS, true }, + { XATTR_DIR_ENTRIES, true }, + { XATTR_DIR_FBYTES, true }, + { XATTR_DIR_RFILES, true }, + { XATTR_DIR_RSUBDIRS, true }, + { XATTR_DIR_RENTRIES, true }, + { XATTR_DIR_RFBYTES, true }, + { XATTR_DIR_PREFIX, true }, + }; + return xattrs.find(key) != xattrs.end(); +} + +inline bool IsWarmupXAttr(const std::string& key) { + return key == XATTR_WARMUP_OP; +} + +} // namespace filesystem +} // namespace client +} // namespace curvefs + +#endif // CURVEFS_SRC_CLIENT_FILESYSTEM_XATTR_H_ diff --git a/curvefs/src/client/fuse_client.cpp b/curvefs/src/client/fuse_client.cpp index 2baa7834da..62599b6bcc 100644 --- a/curvefs/src/client/fuse_client.cpp +++ b/curvefs/src/client/fuse_client.cpp @@ -36,6 +36,7 @@ #include "curvefs/proto/mds.pb.h" #include "curvefs/src/client/common/common.h" #include "curvefs/src/client/filesystem/error.h" +#include "curvefs/src/client/filesystem/xattr.h" #include "curvefs/src/client/fuse_common.h" #include "curvefs/src/client/client_operator.h" #include "curvefs/src/client/inode_wrapper.h" @@ -53,12 +54,22 @@ using ::curvefs::common::S3Info; using ::curvefs::common::Volume; using ::curvefs::mds::topology::PartitionTxId; using ::curvefs::mds::FSStatusCode_Name; -using ::curvefs::client::common::MAX_XATTR_NAME_LENGTH; -using ::curvefs::client::common::MAX_XATTR_VALUE_LENGTH; using ::curvefs::client::filesystem::ExternalMember; using ::curvefs::client::filesystem::DirEntry; using ::curvefs::client::filesystem::DirEntryList; using ::curvefs::client::filesystem::FileOut; +using ::curvefs::client::filesystem::MAX_XATTR_NAME_LENGTH; +using ::curvefs::client::filesystem::MAX_XATTR_VALUE_LENGTH; +using ::curvefs::client::filesystem::XATTR_DIR_FILES; +using ::curvefs::client::filesystem::XATTR_DIR_SUBDIRS; +using ::curvefs::client::filesystem::XATTR_DIR_ENTRIES; +using ::curvefs::client::filesystem::XATTR_DIR_FBYTES; +using ::curvefs::client::filesystem::XATTR_DIR_RFILES; +using ::curvefs::client::filesystem::XATTR_DIR_RFBYTES; +using ::curvefs::client::filesystem::XATTR_DIR_RSUBDIRS; +using ::curvefs::client::filesystem::XATTR_DIR_RENTRIES; +using ::curvefs::client::filesystem::XATTR_DIR_PREFIX; +using ::curvefs::client::filesystem::IsSpecialXAttr; #define RETURN_IF_UNSUCCESS(action) \ do { \ @@ -315,7 +326,7 @@ CURVEFS_ERROR FuseClient::HandleOpenFlags(fuse_req_t req, // update parent summary info const Inode *inode = inodeWrapper->GetInodeLocked(); XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, std::to_string(length)}); for (const auto &it : inode->parent()) { auto tret = xattrManager_->UpdateParentInodeXattr( @@ -470,13 +481,13 @@ CURVEFS_ERROR FuseClient::MakeNode( if (enableSumInDir_.load()) { // update parent summary info XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "1"}); if (type == FsFileType::TYPE_DIRECTORY) { - xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_SUBDIRS, "1"}); } else { - xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "1"}); } - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, std::to_string(inodeWrapper->GetLength())}); auto tret = xattrManager_->UpdateParentInodeXattr(parent, xattr, true); if (tret != CURVEFS_ERROR::OK) { @@ -549,13 +560,13 @@ CURVEFS_ERROR FuseClient::DeleteNode(uint64_t ino, fuse_ino_t parent, if (enableSumInDir_.load()) { // update parent summary info XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "1"}); if (FsFileType::TYPE_DIRECTORY == type) { - xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_SUBDIRS, "1"}); } else { - xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "1"}); } - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, std::to_string(inodeWrapper->GetLength())}); auto tret = xattrManager_->UpdateParentInodeXattr(parent, xattr, false); if (tret != CURVEFS_ERROR::OK) { @@ -650,13 +661,13 @@ CURVEFS_ERROR FuseClient::CreateManageNode(fuse_req_t req, if (enableSumInDir_.load()) { // update parent summary info XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "1"}); if (type == FsFileType::TYPE_DIRECTORY) { - xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_SUBDIRS, "1"}); } else { - xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "1"}); } - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, std::to_string(inodeWrapper->GetLength())}); auto tret = xattrManager_->UpdateParentInodeXattr(parent, xattr, true); if (tret != CURVEFS_ERROR::OK) { @@ -1032,7 +1043,7 @@ CURVEFS_ERROR FuseClient::FuseOpSetAttr(fuse_req_t req, // update parent summary info const Inode* inode = inodeWrapper->GetInodeLocked(); XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, std::to_string(std::abs(changeSize))}); bool direction = changeSize > 0; for (const auto &it : inode->parent()) { @@ -1061,8 +1072,9 @@ CURVEFS_ERROR FuseClient::FuseOpGetXattr(fuse_req_t req, fuse_ino_t ino, (void)req; VLOG(9) << "FuseOpGetXattr, ino: " << ino << ", name: " << name << ", size = " << size; - if (option_.fileSystemOption.disableXattr) { - return CURVEFS_ERROR::NOSYS; + + if (option_.fileSystemOption.disableXAttr && !IsSpecialXAttr(name)) { + return CURVEFS_ERROR::NODATA; } InodeAttr inodeAttr; @@ -1104,6 +1116,11 @@ CURVEFS_ERROR FuseClient::FuseOpSetXattr(fuse_req_t req, fuse_ino_t ino, VLOG(1) << "FuseOpSetXattr ino: " << ino << ", name: " << name << ", size = " << size << ", strvalue: " << strvalue; + + if (option_.fileSystemOption.disableXAttr && !IsSpecialXAttr(name)) { + return CURVEFS_ERROR::NODATA; + } + if (strname.length() > MAX_XATTR_NAME_LENGTH || size > MAX_XATTR_VALUE_LENGTH) { LOG(ERROR) << "xattr length is too long, name = " << name @@ -1152,10 +1169,10 @@ CURVEFS_ERROR FuseClient::FuseOpListXattr(fuse_req_t req, fuse_ino_t ino, // add summary xattr key if (inodeAttr.type() == FsFileType::TYPE_DIRECTORY) { - *realSize += strlen(XATTRRFILES) + 1; - *realSize += strlen(XATTRRSUBDIRS) + 1; - *realSize += strlen(XATTRRENTRIES) + 1; - *realSize += strlen(XATTRRFBYTES) + 1; + *realSize += strlen(XATTR_DIR_RFILES) + 1; + *realSize += strlen(XATTR_DIR_RSUBDIRS) + 1; + *realSize += strlen(XATTR_DIR_RENTRIES) + 1; + *realSize += strlen(XATTR_DIR_RFBYTES) + 1; } if (size == 0) { @@ -1167,14 +1184,14 @@ CURVEFS_ERROR FuseClient::FuseOpListXattr(fuse_req_t req, fuse_ino_t ino, value += tsize; } if (inodeAttr.type() == FsFileType::TYPE_DIRECTORY) { - memcpy(value, XATTRRFILES, strlen(XATTRRFILES) + 1); - value += strlen(XATTRRFILES) + 1; - memcpy(value, XATTRRSUBDIRS, strlen(XATTRRSUBDIRS) + 1); - value += strlen(XATTRRSUBDIRS) + 1; - memcpy(value, XATTRRENTRIES, strlen(XATTRRENTRIES) + 1); - value += strlen(XATTRRENTRIES) + 1; - memcpy(value, XATTRRFBYTES, strlen(XATTRRFBYTES) + 1); - value += strlen(XATTRRFBYTES) + 1; + memcpy(value, XATTR_DIR_RFILES, strlen(XATTR_DIR_RFILES) + 1); + value += strlen(XATTR_DIR_RFILES) + 1; + memcpy(value, XATTR_DIR_RSUBDIRS, strlen(XATTR_DIR_RSUBDIRS) + 1); + value += strlen(XATTR_DIR_RSUBDIRS) + 1; + memcpy(value, XATTR_DIR_RENTRIES, strlen(XATTR_DIR_RENTRIES) + 1); + value += strlen(XATTR_DIR_RENTRIES) + 1; + memcpy(value, XATTR_DIR_RFBYTES, strlen(XATTR_DIR_RFBYTES) + 1); + value += strlen(XATTR_DIR_RFBYTES) + 1; } return CURVEFS_ERROR::OK; } @@ -1243,9 +1260,9 @@ CURVEFS_ERROR FuseClient::FuseOpSymlink(fuse_req_t req, if (enableSumInDir_.load()) { // update parent summary info XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"}); - xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, + xattr.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, std::to_string(inodeWrapper->GetLength())}); auto tret = xattrManager_->UpdateParentInodeXattr(parent, xattr, true); if (tret != CURVEFS_ERROR::OK) { @@ -1313,9 +1330,9 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req, if (enableSumInDir_.load()) { // update parent summary info XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"}); - xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, + xattr.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, std::to_string(inodeWrapper->GetLength())}); auto tret = xattrManager_->UpdateParentInodeXattr( newparent, xattr, true); diff --git a/curvefs/src/client/fuse_common.h b/curvefs/src/client/fuse_common.h index 280d96aa16..816bc7b5fb 100644 --- a/curvefs/src/client/fuse_common.h +++ b/curvefs/src/client/fuse_common.h @@ -28,6 +28,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/curvefs/src/client/fuse_s3_client.cpp b/curvefs/src/client/fuse_s3_client.cpp index e94fe31e2c..869b7d9c06 100644 --- a/curvefs/src/client/fuse_s3_client.cpp +++ b/curvefs/src/client/fuse_s3_client.cpp @@ -26,6 +26,7 @@ #include "curvefs/src/client/fuse_s3_client.h" #include "curvefs/src/client/kvclient/memcache_client.h" +#include "curvefs/src/client/filesystem/xattr.h" namespace curvefs { namespace client { @@ -45,6 +46,7 @@ using curvefs::client::common::FLAGS_supportKVcache; using curvefs::client::common::FLAGS_enableCto; using curvefs::mds::topology::MemcacheClusterInfo; using curvefs::mds::topology::MemcacheServerInfo; +using ::curvefs::client::filesystem::XATTR_DIR_FBYTES; CURVEFS_ERROR FuseS3Client::Init(const FuseClientOption &option) { FuseClientOption opt(option); @@ -207,7 +209,7 @@ CURVEFS_ERROR FuseS3Client::FuseOpWrite(fuse_req_t req, fuse_ino_t ino, if (enableSumInDir_ && changeSize != 0) { const Inode* inode = inodeWrapper->GetInodeLocked(); XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, std::to_string(changeSize)}); for (const auto &it : inode->parent()) { auto tret = xattrManager_->UpdateParentInodeXattr(it, xattr, true); diff --git a/curvefs/src/client/xattr_manager.cpp b/curvefs/src/client/xattr_manager.cpp index 4f9c3bf928..1195756f20 100644 --- a/curvefs/src/client/xattr_manager.cpp +++ b/curvefs/src/client/xattr_manager.cpp @@ -23,6 +23,7 @@ #include "curvefs/src/client/xattr_manager.h" #include "curvefs/src/client/common/common.h" +#include "curvefs/src/client/filesystem/xattr.h" #include "src/common/string_util.h" namespace curvefs { @@ -31,16 +32,25 @@ namespace client { using ::curve::common::StringToUll; using ::curve::common::Thread; using ::curvefs::client::common::AddUllStringToFirst; +using ::curvefs::client::filesystem::XATTR_DIR_FILES; +using ::curvefs::client::filesystem::XATTR_DIR_SUBDIRS; +using ::curvefs::client::filesystem::XATTR_DIR_ENTRIES; +using ::curvefs::client::filesystem::XATTR_DIR_FBYTES; +using ::curvefs::client::filesystem::XATTR_DIR_RFILES; +using ::curvefs::client::filesystem::XATTR_DIR_RSUBDIRS; +using ::curvefs::client::filesystem::XATTR_DIR_RENTRIES; +using ::curvefs::client::filesystem::XATTR_DIR_RFBYTES; +using ::curvefs::client::filesystem::XATTR_DIR_PREFIX; bool IsSummaryInfo(const char *name) { - return std::strstr(name, SUMMARYPREFIX); + return std::strstr(name, XATTR_DIR_PREFIX); } bool IsOneLayer(const char *name) { - if (std::strcmp(name, XATTRFILES) == 0 || - std::strcmp(name, XATTRSUBDIRS) == 0 || - std::strcmp(name, XATTRENTRIES) == 0 || - std::strcmp(name, XATTRFBYTES) == 0) { + if (std::strcmp(name, XATTR_DIR_FILES) == 0 || + std::strcmp(name, XATTR_DIR_SUBDIRS) == 0 || + std::strcmp(name, XATTR_DIR_ENTRIES) == 0 || + std::strcmp(name, XATTR_DIR_FBYTES) == 0) { return true; } return false; @@ -78,13 +88,13 @@ CURVEFS_ERROR XattrManager::CalOneLayerSumInfo(InodeAttr *attr) { summaryInfo.entries++; summaryInfo.fbytes += it.length(); } - (*attr->mutable_xattr())[XATTRFILES] = + (*attr->mutable_xattr())[XATTR_DIR_FILES] = std::to_string(summaryInfo.files); - (*attr->mutable_xattr())[XATTRSUBDIRS] = + (*attr->mutable_xattr())[XATTR_DIR_SUBDIRS] = std::to_string(summaryInfo.subdirs); - (*attr->mutable_xattr())[XATTRENTRIES] = + (*attr->mutable_xattr())[XATTR_DIR_ENTRIES] = std::to_string(summaryInfo.entries); - (*attr->mutable_xattr())[XATTRFBYTES] = + (*attr->mutable_xattr())[XATTR_DIR_FBYTES] = std::to_string(summaryInfo.fbytes + attr->length()); } return ret; @@ -92,7 +102,7 @@ CURVEFS_ERROR XattrManager::CalOneLayerSumInfo(InodeAttr *attr) { CURVEFS_ERROR XattrManager::FastCalOneLayerSumInfo(InodeAttr *attr) { if (!AddUllStringToFirst( - &(attr->mutable_xattr()->find(XATTRFBYTES)->second), + &(attr->mutable_xattr()->find(XATTR_DIR_FBYTES)->second), attr->length(), true)) { return CURVEFS_ERROR::INTERNAL; } @@ -266,13 +276,13 @@ CURVEFS_ERROR XattrManager::CalAllLayerSumInfo(InodeAttr *attr) { summaryInfo.fbytes -= it.second; } - attr->mutable_xattr()->insert({XATTRRFILES, + attr->mutable_xattr()->insert({XATTR_DIR_RFILES, std::to_string(summaryInfo.files)}); - attr->mutable_xattr()->insert({XATTRRSUBDIRS, + attr->mutable_xattr()->insert({XATTR_DIR_RSUBDIRS, std::to_string(summaryInfo.subdirs)}); - attr->mutable_xattr()->insert({XATTRRENTRIES, + attr->mutable_xattr()->insert({XATTR_DIR_RENTRIES, std::to_string(summaryInfo.entries)}); - attr->mutable_xattr()->insert({XATTRRFBYTES, + attr->mutable_xattr()->insert({XATTR_DIR_RFBYTES, std::to_string(summaryInfo.fbytes + attr->length())}); return CURVEFS_ERROR::OK; } @@ -306,30 +316,30 @@ void XattrManager::ConcurrentGetInodeXattr( if (tret == CURVEFS_ERROR::OK) { SummaryInfo summaryInfo; for (const auto &it : xattrs) { - if (it.xattrinfos().count(XATTRFILES)) { + if (it.xattrinfos().count(XATTR_DIR_FILES)) { if (!AddUllStringToFirst(&summaryInfo.files, - it.xattrinfos().find(XATTRFILES)->second)) { + it.xattrinfos().find(XATTR_DIR_FILES)->second)) { ret->store(false); return; } } - if (it.xattrinfos().count(XATTRSUBDIRS)) { + if (it.xattrinfos().count(XATTR_DIR_SUBDIRS)) { if (!AddUllStringToFirst(&summaryInfo.subdirs, - it.xattrinfos().find(XATTRSUBDIRS)->second)) { + it.xattrinfos().find(XATTR_DIR_SUBDIRS)->second)) { ret->store(false); return; } } - if (it.xattrinfos().count(XATTRENTRIES)) { + if (it.xattrinfos().count(XATTR_DIR_ENTRIES)) { if (!AddUllStringToFirst(&summaryInfo.entries, - it.xattrinfos().find(XATTRENTRIES)->second)) { + it.xattrinfos().find(XATTR_DIR_ENTRIES)->second)) { ret->store(false); return; } } - if (it.xattrinfos().count(XATTRFBYTES)) { + if (it.xattrinfos().count(XATTR_DIR_FBYTES)) { if (!AddUllStringToFirst(&summaryInfo.fbytes, - it.xattrinfos().find(XATTRFBYTES)->second)) { + it.xattrinfos().find(XATTR_DIR_FBYTES)->second)) { ret->store(false); return; } @@ -338,16 +348,16 @@ void XattrManager::ConcurrentGetInodeXattr( // record summary info to target inode std::lock_guard guard(*inodeMutex); if (!(AddUllStringToFirst( - &(attr->mutable_xattr()->find(XATTRRFILES)->second), + &(attr->mutable_xattr()->find(XATTR_DIR_RFILES)->second), summaryInfo.files, true) && AddUllStringToFirst( - &(attr->mutable_xattr()->find(XATTRRSUBDIRS)->second), + &(attr->mutable_xattr()->find(XATTR_DIR_RSUBDIRS)->second), summaryInfo.subdirs, true) && AddUllStringToFirst( - &(attr->mutable_xattr()->find(XATTRRENTRIES)->second), + &(attr->mutable_xattr()->find(XATTR_DIR_RENTRIES)->second), summaryInfo.entries, true) && AddUllStringToFirst( - &(attr->mutable_xattr()->find(XATTRRFBYTES)->second), + &(attr->mutable_xattr()->find(XATTR_DIR_RFBYTES)->second), summaryInfo.fbytes, true))) { ret->store(false); return; @@ -369,20 +379,20 @@ CURVEFS_ERROR XattrManager::FastCalAllLayerSumInfo(InodeAttr *attr) { iStack.emplace(ino); // add the size of itself first if (!AddUllStringToFirst( - &(attr->mutable_xattr()->find(XATTRFBYTES)->second), + &(attr->mutable_xattr()->find(XATTR_DIR_FBYTES)->second), attr->length(), true)) { return CURVEFS_ERROR::INTERNAL; } // add first layer summary to all layer summary info - attr->mutable_xattr()->insert({XATTRRFILES, - attr->xattr().find(XATTRFILES)->second}); - attr->mutable_xattr()->insert({XATTRRSUBDIRS, - attr->xattr().find(XATTRSUBDIRS)->second}); - attr->mutable_xattr()->insert({XATTRRENTRIES, - attr->xattr().find(XATTRENTRIES)->second}); - attr->mutable_xattr()->insert({XATTRRFBYTES, - attr->xattr().find(XATTRFBYTES)->second}); + attr->mutable_xattr()->insert({XATTR_DIR_RFILES, + attr->xattr().find(XATTR_DIR_FILES)->second}); + attr->mutable_xattr()->insert({XATTR_DIR_RSUBDIRS, + attr->xattr().find(XATTR_DIR_SUBDIRS)->second}); + attr->mutable_xattr()->insert({XATTR_DIR_RENTRIES, + attr->xattr().find(XATTR_DIR_ENTRIES)->second}); + attr->mutable_xattr()->insert({XATTR_DIR_RFBYTES, + attr->xattr().find(XATTR_DIR_FBYTES)->second}); std::vector threadpool; Atomic inflightNum(0); @@ -513,13 +523,13 @@ CURVEFS_ERROR XattrManager::UpdateParentXattrAfterRename(uint64_t parent, return rc; } XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "1"}); if (dentry.type() == FsFileType::TYPE_DIRECTORY) { - xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_SUBDIRS, "1"}); } else { - xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "1"}); } - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, std::to_string(inodeWrapper->GetLength())}); // update src parent @@ -548,13 +558,13 @@ CURVEFS_ERROR XattrManager::UpdateParentXattrAfterRename(uint64_t parent, renameOp->GetOldInode(&oldInode, &oldInodeSize, &oldInodeType); if (oldInode != 0 && oldInodeSize >= 0) { XAttr xattr; - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "1"}); if (oldInodeType == FsFileType::TYPE_DIRECTORY) { - xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_SUBDIRS, "1"}); } else { - xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "1"}); } - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, std::to_string(oldInodeSize)}); rc = UpdateParentInodeXattr(newparent, xattr, false); diff --git a/curvefs/src/common/define.h b/curvefs/src/common/define.h index eb9a23be2d..a014a03f2c 100644 --- a/curvefs/src/common/define.h +++ b/curvefs/src/common/define.h @@ -24,19 +24,23 @@ #define CURVEFS_SRC_COMMON_DEFINE_H_ #include +#include "curvefs/src/client/filesystem/xattr.h" + namespace curvefs { const uint64_t ROOTINODEID = 1; const uint64_t RECYCLEINODEID = 2; const char RECYCLENAME[] = ".recycle"; -const char XATTRFILES[] = "curve.dir.files"; -const char XATTRSUBDIRS[] = "curve.dir.subdirs"; -const char XATTRENTRIES[] = "curve.dir.entries"; -const char XATTRFBYTES[] = "curve.dir.fbytes"; -const char XATTRRFILES[] = "curve.dir.rfiles"; -const char XATTRRSUBDIRS[] = "curve.dir.rsubdirs"; -const char XATTRRENTRIES[] = "curve.dir.rentries"; -const char XATTRRFBYTES[] = "curve.dir.rfbytes"; -const char SUMMARYPREFIX[] = "curve.dir"; +using ::curvefs::client::filesystem::XATTR_DIR_FILES; +using ::curvefs::client::filesystem::XATTR_DIR_SUBDIRS; +using ::curvefs::client::filesystem::XATTR_DIR_ENTRIES; +using ::curvefs::client::filesystem::XATTR_DIR_FBYTES; +using ::curvefs::client::filesystem::XATTR_DIR_RFILES; +using ::curvefs::client::filesystem::XATTR_DIR_RSUBDIRS; +using ::curvefs::client::filesystem::XATTR_DIR_RENTRIES; +using ::curvefs::client::filesystem::XATTR_DIR_RFBYTES; +using ::curvefs::client::filesystem::XATTR_DIR_PREFIX; +using ::curvefs::client::filesystem::XATTR_WARMUP_OP; + } // namespace curvefs #endif // CURVEFS_SRC_COMMON_DEFINE_H_ diff --git a/curvefs/src/mds/BUILD b/curvefs/src/mds/BUILD index c6d003f470..bf46e8d63c 100644 --- a/curvefs/src/mds/BUILD +++ b/curvefs/src/mds/BUILD @@ -68,6 +68,7 @@ cc_library( "//curvefs/src/mds/schedule/scheduleService:curvefs_schedule_service", "//curvefs/src/mds/space:curvefs_mds_space", "//curvefs/src/mds/topology:curvefs_topology", + "//curvefs/src/client:filesystem_xattr", "//external:brpc", "//external:gflags", "//external:glog", diff --git a/curvefs/src/metaserver/BUILD b/curvefs/src/metaserver/BUILD index e390509a44..b1c92f5bd9 100644 --- a/curvefs/src/metaserver/BUILD +++ b/curvefs/src/metaserver/BUILD @@ -51,6 +51,7 @@ cc_library( "//curvefs/proto:mds_cc_proto", "//curvefs/src/common:curvefs_common", "//curvefs/src/metaserver/common:fs_metaserver_common", + "//curvefs/src/client:filesystem_xattr", "//external:braft", "//src/common:curve_common", "//src/fs:lfs", diff --git a/curvefs/src/metaserver/inode_manager.cpp b/curvefs/src/metaserver/inode_manager.cpp index 096fcd857c..fe8076d3f7 100644 --- a/curvefs/src/metaserver/inode_manager.cpp +++ b/curvefs/src/metaserver/inode_manager.cpp @@ -33,10 +33,15 @@ #include "curvefs/src/common/define.h" #include "src/common/concurrent/name_lock.h" #include "src/common/timeutility.h" +#include "curvefs/src/client/filesystem/xattr.h" using ::curve::common::TimeUtility; using ::curve::common::NameLockGuard; using ::google::protobuf::util::MessageDifferencer; +using ::curvefs::client::filesystem::XATTR_DIR_FILES; +using ::curvefs::client::filesystem::XATTR_DIR_SUBDIRS; +using ::curvefs::client::filesystem::XATTR_DIR_ENTRIES; +using ::curvefs::client::filesystem::XATTR_DIR_FBYTES; namespace curvefs { namespace metaserver { @@ -173,10 +178,10 @@ void InodeManager::GenerateInodeInternal(uint64_t inodeId, if (FsFileType::TYPE_DIRECTORY == param.type) { inode->set_nlink(2); // set summary xattr - inode->mutable_xattr()->insert({XATTRFILES, "0"}); - inode->mutable_xattr()->insert({XATTRSUBDIRS, "0"}); - inode->mutable_xattr()->insert({XATTRENTRIES, "0"}); - inode->mutable_xattr()->insert({XATTRFBYTES, "0"}); + inode->mutable_xattr()->insert({XATTR_DIR_FILES, "0"}); + inode->mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "0"}); + inode->mutable_xattr()->insert({XATTR_DIR_ENTRIES, "0"}); + inode->mutable_xattr()->insert({XATTR_DIR_FBYTES, "0"}); } else { inode->set_nlink(1); } diff --git a/curvefs/test/client/filesystem/filesystem_test.cpp b/curvefs/test/client/filesystem/filesystem_test.cpp index e8087818fe..940f9d9f16 100644 --- a/curvefs/test/client/filesystem/filesystem_test.cpp +++ b/curvefs/test/client/filesystem/filesystem_test.cpp @@ -248,14 +248,34 @@ TEST_F(FileSystemTest, ReadDir_Basic) { fi.fh = handler->fh; // CASE 1: readdir success - EXPECT_CALL_RETURN_ListDentry(*builder.GetDentryManager(), - CURVEFS_ERROR::OK); - EXPECT_CALL_RETURN_BatchGetInodeAttrAsync(*builder.GetInodeManager(), - CURVEFS_ERROR::OK); + EXPECT_CALL_INVOKE_ListDentry(*builder.GetDentryManager(), + [&](uint64_t parent, + std::list* dentries, + uint32_t limit, + bool only, + uint32_t nlink) -> CURVEFS_ERROR { + dentries->push_back(MkDentry(1, "test")); + return CURVEFS_ERROR::OK; + }); + EXPECT_CALL_INVOKE_BatchGetInodeAttrAsync(*builder.GetInodeManager(), + [&](uint64_t parentId, + std::set* inos, + std::map* attrs) -> CURVEFS_ERROR { + for (const auto& ino : *inos) { + auto attr = MkAttr(ino, AttrOption().mtime(123, ino)); + attrs->emplace(ino, attr); + } + return CURVEFS_ERROR::OK; + }); + DirEntry dirEntry; auto entries = std::make_shared(); auto rc = fs->ReadDir(Request(), 1, &fi, &entries); ASSERT_EQ(rc, CURVEFS_ERROR::OK); + ASSERT_EQ(entries->Size(), 1); + ASSERT_TRUE(entries->Get(1, &dirEntry)); + ASSERT_EQ(dirEntry.ino, 1); + ASSERT_EQ(dirEntry.name, "test"); } TEST_F(FileSystemTest, ReadDir_CheckEntries) { diff --git a/curvefs/test/client/filesystem/helper/builder.h b/curvefs/test/client/filesystem/helper/builder.h index dc7c196adb..5c7a4dbcb6 100644 --- a/curvefs/test/client/filesystem/helper/builder.h +++ b/curvefs/test/client/filesystem/helper/builder.h @@ -197,7 +197,7 @@ class FileSystemBuilder { }; option.cto = true; - option.disableXattr = true; + option.disableXAttr = true; option.maxNameLength = 255; option.blockSize = 0x10000u; option.kernelCacheOption = kernelCacheOption; diff --git a/curvefs/test/client/filesystem/rpc_client_test.cpp b/curvefs/test/client/filesystem/rpc_client_test.cpp index 9419af8579..9763e15787 100644 --- a/curvefs/test/client/filesystem/rpc_client_test.cpp +++ b/curvefs/test/client/filesystem/rpc_client_test.cpp @@ -106,14 +106,34 @@ TEST_F(RPCClientTest, ReadDir_Basic) { // CASE 1: ok { - EXPECT_CALL_RETURN_ListDentry(*builder.GetDentryManager(), - CURVEFS_ERROR::OK); - EXPECT_CALL_RETURN_BatchGetInodeAttrAsync(*builder.GetInodeManager(), - CURVEFS_ERROR::OK); - + EXPECT_CALL_INVOKE_ListDentry(*builder.GetDentryManager(), + [&](uint64_t parent, + std::list* dentries, + uint32_t limit, + bool only, + uint32_t nlink) -> CURVEFS_ERROR { + dentries->push_back(MkDentry(1, "test")); + return CURVEFS_ERROR::OK; + }); + EXPECT_CALL_INVOKE_BatchGetInodeAttrAsync(*builder.GetInodeManager(), + [&](uint64_t parentId, + std::set* inos, + std::map* attrs) -> CURVEFS_ERROR { + for (const auto& ino : *inos) { + auto attr = MkAttr(ino, AttrOption().mtime(123, ino)); + attrs->emplace(ino, attr); + } + return CURVEFS_ERROR::OK; + }); + + DirEntry dirEntry; auto entries = std::make_shared(); auto rc = rpc->ReadDir(100, &entries); ASSERT_EQ(rc, CURVEFS_ERROR::OK); + ASSERT_EQ(entries->Size(), 1); + ASSERT_TRUE(entries->Get(1, &dirEntry)); + ASSERT_EQ(dirEntry.ino, 1); + ASSERT_EQ(dirEntry.name, "test"); } // CASE 2: inode not exist diff --git a/curvefs/test/client/rpcclient/BUILD b/curvefs/test/client/rpcclient/BUILD index fa2a3d4649..0503eac796 100644 --- a/curvefs/test/client/rpcclient/BUILD +++ b/curvefs/test/client/rpcclient/BUILD @@ -27,6 +27,7 @@ cc_test( "//external:gtest", "@com_google_googletest//:gtest_main", "//curvefs/src/client/rpcclient:rpcclient", + "//curvefs/src/client:filesystem_xattr", "//curvefs/proto:curvefs_topology_cc_proto", "//curvefs/src/common:curvefs_common", "//curvefs/test/utils:curvefs_test_utils", diff --git a/curvefs/test/client/rpcclient/metaserver_client_test.cpp b/curvefs/test/client/rpcclient/metaserver_client_test.cpp index aaff7bd1b7..bd56517dda 100644 --- a/curvefs/test/client/rpcclient/metaserver_client_test.cpp +++ b/curvefs/test/client/rpcclient/metaserver_client_test.cpp @@ -1204,10 +1204,10 @@ TEST_F(MetaServerClientImplTest, test_BatchGetXAttr) { curvefs::metaserver::XAttr out; out.set_fsid(fsid); out.set_inodeid(inodeId1); - out.mutable_xattrinfos()->insert({XATTRFILES, "1"}); - out.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"}); - out.mutable_xattrinfos()->insert({XATTRENTRIES, "2"}); - out.mutable_xattrinfos()->insert({XATTRFBYTES, "100"}); + out.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "1"}); + out.mutable_xattrinfos()->insert({XATTR_DIR_SUBDIRS, "1"}); + out.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "2"}); + out.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, "100"}); curvefs::metaserver::XAttr out1 = out; out1.set_inodeid(inodeId2); xattr.emplace_back(out); diff --git a/curvefs/test/client/test_fuse_s3_client.cpp b/curvefs/test/client/test_fuse_s3_client.cpp index f4b933f736..9ef7d70c56 100644 --- a/curvefs/test/client/test_fuse_s3_client.cpp +++ b/curvefs/test/client/test_fuse_s3_client.cpp @@ -1184,7 +1184,7 @@ TEST_F(TestFuseS3Client, FuseOpGetXattr_NotEnableSumInDir) { attr.set_length(100); attr.set_type(FsFileType::TYPE_DIRECTORY); attrs.emplace_back(attr); - attr.set_inodeid(inodeId2); +attr.set_inodeid(inodeId2); attr.set_length(200); attr.set_type(FsFileType::TYPE_FILE); attrs.emplace_back(attr); @@ -1200,10 +1200,10 @@ TEST_F(TestFuseS3Client, FuseOpGetXattr_NotEnableSumInDir) { inode.set_inodeid(ino); inode.set_length(4096); inode.set_type(FsFileType::TYPE_DIRECTORY); - inode.mutable_xattr()->insert({XATTRFILES, "0"}); - inode.mutable_xattr()->insert({XATTRSUBDIRS, "0"}); - inode.mutable_xattr()->insert({XATTRENTRIES, "0"}); - inode.mutable_xattr()->insert({XATTRFBYTES, "0"}); + inode.mutable_xattr()->insert({XATTR_DIR_FILES, "0"}); + inode.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "0"}); + inode.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "0"}); + inode.mutable_xattr()->insert({XATTR_DIR_FBYTES, "0"}); EXPECT_CALL(*inodeManager_, GetInodeAttr(ino, _)) .WillOnce( @@ -1273,10 +1273,10 @@ TEST_F(TestFuseS3Client, FuseOpGetXattr_NotEnableSumInDir_Failed) { InodeAttr inode; inode.set_inodeid(ino); - inode.mutable_xattr()->insert({XATTRFILES, "aaa"}); - inode.mutable_xattr()->insert({XATTRSUBDIRS, "1"}); - inode.mutable_xattr()->insert({XATTRENTRIES, "2"}); - inode.mutable_xattr()->insert({XATTRFBYTES, "100"}); + inode.mutable_xattr()->insert({XATTR_DIR_FILES, "aaa"}); + inode.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "1"}); + inode.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "2"}); + inode.mutable_xattr()->insert({XATTR_DIR_FBYTES, "100"}); // get inode failed EXPECT_CALL(*inodeManager_, GetInodeAttr(ino, _)) @@ -1336,19 +1336,19 @@ TEST_F(TestFuseS3Client, FuseOpGetXattr_EnableSumInDir) { XAttr xattr; xattr.set_fsid(fsId); xattr.set_inodeid(ino); - xattr.mutable_xattrinfos()->insert({XATTRFILES, "2"}); - xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "2"}); - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "4"}); - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, "200"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "2"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_SUBDIRS, "2"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "4"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, "200"}); xattrs.emplace_back(xattr); InodeAttr inode; inode.set_inodeid(ino); inode.set_nlink(3); - inode.mutable_xattr()->insert({XATTRFILES, "1"}); - inode.mutable_xattr()->insert({XATTRSUBDIRS, "1"}); - inode.mutable_xattr()->insert({XATTRENTRIES, "2"}); - inode.mutable_xattr()->insert({XATTRFBYTES, "100"}); + inode.mutable_xattr()->insert({XATTR_DIR_FILES, "1"}); + inode.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "1"}); + inode.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "2"}); + inode.mutable_xattr()->insert({XATTR_DIR_FBYTES, "100"}); InodeAttr attr = inode; attr.set_nlink(2); @@ -1406,10 +1406,10 @@ TEST_F(TestFuseS3Client, FuseOpGetXattr_EnableSumInDir_Failed) { XAttr xattr; xattr.set_fsid(fsId); xattr.set_inodeid(inodeId); - xattr.mutable_xattrinfos()->insert({XATTRFILES, "2"}); - xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "2"}); - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "4"}); - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, "200"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "2"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_SUBDIRS, "2"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "4"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, "200"}); xattrs.emplace_back(xattr); InodeAttr inode; @@ -1417,10 +1417,10 @@ TEST_F(TestFuseS3Client, FuseOpGetXattr_EnableSumInDir_Failed) { inode.set_nlink(3); inode.set_length(4096); inode.set_type(FsFileType::TYPE_DIRECTORY); - inode.mutable_xattr()->insert({XATTRFILES, "1"}); - inode.mutable_xattr()->insert({XATTRSUBDIRS, "1"}); - inode.mutable_xattr()->insert({XATTRENTRIES, "2"}); - inode.mutable_xattr()->insert({XATTRFBYTES, "aaa"}); + inode.mutable_xattr()->insert({XATTR_DIR_FILES, "1"}); + inode.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "1"}); + inode.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "2"}); + inode.mutable_xattr()->insert({XATTR_DIR_FBYTES, "aaa"}); // get inode failed EXPECT_CALL(*inodeManager_, GetInodeAttr(ino, _)) @@ -1434,7 +1434,7 @@ TEST_F(TestFuseS3Client, FuseOpGetXattr_EnableSumInDir_Failed) { Return(CURVEFS_ERROR::OK))); ret = client_->FuseOpGetXattr(req, ino, name, &value, size); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); - inode.mutable_xattr()->find(XATTRFBYTES)->second = "100"; + inode.mutable_xattr()->find(XATTR_DIR_FBYTES)->second = "100"; // list dentry failed EXPECT_CALL(*inodeManager_, GetInodeAttr(ino, _)) @@ -1461,8 +1461,8 @@ TEST_F(TestFuseS3Client, FuseOpGetXattr_EnableSumInDir_Failed) { ret = client_->FuseOpGetXattr(req, ino, rname, &value, size); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); - // AddUllStringToFirst XATTRFILES failed - inode.mutable_xattr()->find(XATTRFILES)->second = "aaa"; + // AddUllStringToFirst XATTR_DIR_FILES failed + inode.mutable_xattr()->find(XATTR_DIR_FILES)->second = "aaa"; EXPECT_CALL(*inodeManager_, GetInodeAttr(_, _)) .Times(AtLeast(2)) .WillRepeatedly( @@ -1478,9 +1478,9 @@ TEST_F(TestFuseS3Client, FuseOpGetXattr_EnableSumInDir_Failed) { ret = client_->FuseOpGetXattr(req, ino, rname, &value, size); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); - // AddUllStringToFirst XATTRSUBDIRS failed - inode.mutable_xattr()->find(XATTRFILES)->second = "0"; - inode.mutable_xattr()->find(XATTRSUBDIRS)->second = "aaa"; + // AddUllStringToFirst XATTR_DIR_SUBDIRS failed + inode.mutable_xattr()->find(XATTR_DIR_FILES)->second = "0"; + inode.mutable_xattr()->find(XATTR_DIR_SUBDIRS)->second = "aaa"; EXPECT_CALL(*inodeManager_, GetInodeAttr(_, _)) .Times(AtLeast(2)) .WillRepeatedly( @@ -1496,9 +1496,9 @@ TEST_F(TestFuseS3Client, FuseOpGetXattr_EnableSumInDir_Failed) { ret = client_->FuseOpGetXattr(req, ino, rname, &value, size); ASSERT_EQ(CURVEFS_ERROR::INTERNAL, ret); - // AddUllStringToFirst XATTRENTRIES failed - inode.mutable_xattr()->find(XATTRSUBDIRS)->second = "0"; - inode.mutable_xattr()->find(XATTRENTRIES)->second = "aaa"; + // AddUllStringToFirst XATTR_DIR_ENTRIES failed + inode.mutable_xattr()->find(XATTR_DIR_SUBDIRS)->second = "0"; + inode.mutable_xattr()->find(XATTR_DIR_ENTRIES)->second = "aaa"; EXPECT_CALL(*inodeManager_, GetInodeAttr(_, _)) .Times(AtLeast(2)) .WillRepeatedly( @@ -1549,10 +1549,10 @@ TEST_F(TestFuseS3Client, FuseOpCreate_EnableSummary) { parentInode.set_inodeid(parent); 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"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_FILES, "1"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "1"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "2"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_FBYTES, "100"}); auto parentInodeWrapper = std::make_shared( parentInode, metaClient_); @@ -1576,10 +1576,10 @@ TEST_F(TestFuseS3Client, FuseOpCreate_EnableSummary) { ASSERT_EQ(CURVEFS_ERROR::OK, ret); 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, "4196"); + ASSERT_EQ(p->xattr().find(XATTR_DIR_FILES)->second, "2"); + ASSERT_EQ(p->xattr().find(XATTR_DIR_SUBDIRS)->second, "1"); + ASSERT_EQ(p->xattr().find(XATTR_DIR_ENTRIES)->second, "3"); + ASSERT_EQ(p->xattr().find(XATTR_DIR_FBYTES)->second, "4196"); } TEST_F(TestFuseS3Client, FuseOpWrite_EnableSummary) { @@ -1605,10 +1605,10 @@ TEST_F(TestFuseS3Client, FuseOpWrite_EnableSummary) { parentInode.set_inodeid(0); parentInode.set_type(FsFileType::TYPE_DIRECTORY); parentInode.set_nlink(2); - parentInode.mutable_xattr()->insert({XATTRFILES, "1"}); - parentInode.mutable_xattr()->insert({XATTRSUBDIRS, "0"}); - parentInode.mutable_xattr()->insert({XATTRENTRIES, "1"}); - parentInode.mutable_xattr()->insert({XATTRFBYTES, "0"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_FILES, "1"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "0"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "1"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_FBYTES, "0"}); auto parentInodeWrapper = std::make_shared( parentInode, metaClient_); @@ -1631,10 +1631,10 @@ TEST_F(TestFuseS3Client, FuseOpWrite_EnableSummary) { ASSERT_EQ(size, fileOut.nwritten); auto p = parentInodeWrapper->GetInodeLocked(); - ASSERT_EQ(p->xattr().find(XATTRFILES)->second, "1"); - ASSERT_EQ(p->xattr().find(XATTRSUBDIRS)->second, "0"); - ASSERT_EQ(p->xattr().find(XATTRENTRIES)->second, "1"); - ASSERT_EQ(p->xattr().find(XATTRFBYTES)->second, std::to_string(size)); + ASSERT_EQ(p->xattr().find(XATTR_DIR_FILES)->second, "1"); + ASSERT_EQ(p->xattr().find(XATTR_DIR_SUBDIRS)->second, "0"); + ASSERT_EQ(p->xattr().find(XATTR_DIR_ENTRIES)->second, "1"); + ASSERT_EQ(p->xattr().find(XATTR_DIR_FBYTES)->second, std::to_string(size)); } TEST_F(TestFuseS3Client, FuseOpLink_EnableSummary) { @@ -1655,10 +1655,10 @@ TEST_F(TestFuseS3Client, FuseOpLink_EnableSummary) { Inode pinode; pinode.set_inodeid(0); pinode.set_length(0); - pinode.mutable_xattr()->insert({XATTRFILES, "0"}); - pinode.mutable_xattr()->insert({XATTRSUBDIRS, "0"}); - pinode.mutable_xattr()->insert({XATTRENTRIES, "0"}); - pinode.mutable_xattr()->insert({XATTRFBYTES, "0"}); + pinode.mutable_xattr()->insert({XATTR_DIR_FILES, "0"}); + pinode.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "0"}); + pinode.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "0"}); + pinode.mutable_xattr()->insert({XATTR_DIR_FBYTES, "0"}); auto pinodeWrapper = std::make_shared(pinode, metaClient_); EXPECT_CALL(*inodeManager_, GetInode(_, _)) @@ -1677,10 +1677,10 @@ TEST_F(TestFuseS3Client, FuseOpLink_EnableSummary) { &entryOut); ASSERT_EQ(CURVEFS_ERROR::OK, ret); auto p = pinodeWrapper->GetInode(); - ASSERT_EQ(p.xattr().find(XATTRFILES)->second, "1"); - ASSERT_EQ(p.xattr().find(XATTRSUBDIRS)->second, "0"); - ASSERT_EQ(p.xattr().find(XATTRENTRIES)->second, "1"); - ASSERT_EQ(p.xattr().find(XATTRFBYTES)->second, "100"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_FILES)->second, "1"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_SUBDIRS)->second, "0"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_ENTRIES)->second, "1"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_FBYTES)->second, "100"); } TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) { @@ -1720,10 +1720,10 @@ TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) { parentInode.set_inodeid(parent); parentInode.set_type(FsFileType::TYPE_DIRECTORY); parentInode.set_nlink(3); - parentInode.mutable_xattr()->insert({XATTRFILES, "1"}); - parentInode.mutable_xattr()->insert({XATTRSUBDIRS, "1"}); - parentInode.mutable_xattr()->insert({XATTRENTRIES, "2"}); - parentInode.mutable_xattr()->insert({XATTRFBYTES, "4196"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_FILES, "1"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "1"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "2"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_FBYTES, "4196"}); InodeAttr attr; attr.set_fsid(fsId); @@ -1757,10 +1757,10 @@ TEST_F(TestFuseS3Client, FuseOpUnlink_EnableSummary) { auto p = parentInodeWrapper->GetInode(); ASSERT_EQ(3, p.nlink()); - ASSERT_EQ(p.xattr().find(XATTRFILES)->second, "0"); - ASSERT_EQ(p.xattr().find(XATTRSUBDIRS)->second, "1"); - ASSERT_EQ(p.xattr().find(XATTRENTRIES)->second, "1"); - ASSERT_EQ(p.xattr().find(XATTRFBYTES)->second, "100"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_FILES)->second, "0"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_SUBDIRS)->second, "1"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_ENTRIES)->second, "1"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_FBYTES)->second, "100"); } TEST_F(TestFuseS3Client, FuseOpOpen_Trunc_EnableSummary) { @@ -1788,10 +1788,10 @@ TEST_F(TestFuseS3Client, FuseOpOpen_Trunc_EnableSummary) { parentInode.set_inodeid(0); parentInode.set_type(FsFileType::TYPE_DIRECTORY); parentInode.set_nlink(3); - parentInode.mutable_xattr()->insert({XATTRFILES, "1"}); - parentInode.mutable_xattr()->insert({XATTRSUBDIRS, "1"}); - parentInode.mutable_xattr()->insert({XATTRENTRIES, "2"}); - parentInode.mutable_xattr()->insert({XATTRFBYTES, "4196"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_FILES, "1"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "1"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "2"}); + parentInode.mutable_xattr()->insert({XATTR_DIR_FBYTES, "4196"}); auto parentInodeWrapper = std::make_shared( parentInode, metaClient_); @@ -1826,11 +1826,11 @@ TEST_F(TestFuseS3Client, FuseOpOpen_Trunc_EnableSummary) { ASSERT_EQ(CURVEFS_ERROR::OK, ret); auto p = parentInodeWrapper->GetInode(); - ASSERT_EQ(p.xattr().find(XATTRFILES)->second, "1"); - ASSERT_EQ(p.xattr().find(XATTRSUBDIRS)->second, "1"); - ASSERT_EQ(p.xattr().find(XATTRENTRIES)->second, "2"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_FILES)->second, "1"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_SUBDIRS)->second, "1"); + ASSERT_EQ(p.xattr().find(XATTR_DIR_ENTRIES)->second, "2"); // FIXME: (Wine93) - // ASSERT_EQ(p.xattr().find(XATTRFBYTES)->second, "100"); + // ASSERT_EQ(p.xattr().find(XATTR_DIR_FBYTES)->second, "100"); } TEST_F(TestFuseS3Client, FuseOpListXattr) { @@ -1874,9 +1874,11 @@ TEST_F(TestFuseS3Client, FuseOpListXattr) { ret = client_->FuseOpListXattr( req, ino, buf, size, &realSize); ASSERT_EQ(CURVEFS_ERROR::OK, ret); - auto expected = key.length() + 1 + strlen(XATTRRFILES) + 1 + - strlen(XATTRRSUBDIRS) + 1 + strlen(XATTRRENTRIES) + 1 + - strlen(XATTRRFBYTES) + 1; + auto expected = key.length() + 1 + + strlen(XATTR_DIR_RFILES) + 1 + + strlen(XATTR_DIR_RSUBDIRS) + 1 + + strlen(XATTR_DIR_RENTRIES) + 1 + + strlen(XATTR_DIR_RFBYTES) + 1; ASSERT_EQ(realSize, expected); realSize = 0; diff --git a/curvefs/test/client/test_inode_cache_manager.cpp b/curvefs/test/client/test_inode_cache_manager.cpp index 02b6133ebb..6b266118f0 100644 --- a/curvefs/test/client/test_inode_cache_manager.cpp +++ b/curvefs/test/client/test_inode_cache_manager.cpp @@ -392,13 +392,13 @@ TEST_F(TestInodeCacheManager, BatchGetXAttr) { XAttr xattr; xattr.set_fsid(fsId_); xattr.set_inodeid(inodeId1); - xattr.mutable_xattrinfos()->insert({XATTRFILES, "1"}); - xattr.mutable_xattrinfos()->insert({XATTRSUBDIRS, "1"}); - xattr.mutable_xattrinfos()->insert({XATTRENTRIES, "2"}); - xattr.mutable_xattrinfos()->insert({XATTRFBYTES, "100"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FILES, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_SUBDIRS, "1"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_ENTRIES, "2"}); + xattr.mutable_xattrinfos()->insert({XATTR_DIR_FBYTES, "100"}); xattrs.emplace_back(xattr); xattr.set_inodeid(inodeId2); - xattr.mutable_xattrinfos()->find(XATTRFBYTES)->second = "200"; + xattr.mutable_xattrinfos()->find(XATTR_DIR_FBYTES)->second = "200"; xattrs.emplace_back(xattr); EXPECT_CALL(*metaClient_, BatchGetXAttr(fsId_, inodeIds, _)) @@ -415,7 +415,7 @@ TEST_F(TestInodeCacheManager, BatchGetXAttr) { ASSERT_EQ(getXAttrs.size(), 2); ASSERT_THAT(getXAttrs.begin()->inodeid(), AnyOf(inodeId1, inodeId2)); ASSERT_EQ(getXAttrs.begin()->fsid(), fsId_); - ASSERT_THAT(getXAttrs.begin()->xattrinfos().find(XATTRFBYTES)->second, + ASSERT_THAT(getXAttrs.begin()->xattrinfos().find(XATTR_DIR_FBYTES)->second, AnyOf("100", "200")); } diff --git a/curvefs/test/metaserver/inode_manager_test.cpp b/curvefs/test/metaserver/inode_manager_test.cpp index e1808c45bd..248a6fedc4 100644 --- a/curvefs/test/metaserver/inode_manager_test.cpp +++ b/curvefs/test/metaserver/inode_manager_test.cpp @@ -466,10 +466,10 @@ TEST_F(InodeManagerTest, testGetXAttr) { ASSERT_EQ(manager->CreateInode(3, param_, &inode2), MetaStatusCode::OK); ASSERT_FALSE(inode2.xattr().empty()); - ASSERT_EQ(inode2.xattr().find(XATTRFILES)->second, "0"); - ASSERT_EQ(inode2.xattr().find(XATTRSUBDIRS)->second, "0"); - ASSERT_EQ(inode2.xattr().find(XATTRENTRIES)->second, "0"); - ASSERT_EQ(inode2.xattr().find(XATTRFBYTES)->second, "0"); + ASSERT_EQ(inode2.xattr().find(XATTR_DIR_FILES)->second, "0"); + ASSERT_EQ(inode2.xattr().find(XATTR_DIR_SUBDIRS)->second, "0"); + ASSERT_EQ(inode2.xattr().find(XATTR_DIR_ENTRIES)->second, "0"); + ASSERT_EQ(inode2.xattr().find(XATTR_DIR_FBYTES)->second, "0"); // GET XAttr xattr; @@ -478,16 +478,16 @@ TEST_F(InodeManagerTest, testGetXAttr) { ASSERT_EQ(xattr.fsid(), fsId); ASSERT_EQ(xattr.inodeid(), inode2.inodeid()); ASSERT_EQ(xattr.xattrinfos_size(), 4); - ASSERT_EQ(xattr.xattrinfos().find(XATTRFILES)->second, "0"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRSUBDIRS)->second, "0"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRENTRIES)->second, "0"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRFBYTES)->second, "0"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_FILES)->second, "0"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_SUBDIRS)->second, "0"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_ENTRIES)->second, "0"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_FBYTES)->second, "0"); // UPDATE - inode2.mutable_xattr()->find(XATTRFILES)->second = "1"; - inode2.mutable_xattr()->find(XATTRSUBDIRS)->second = "1"; - inode2.mutable_xattr()->find(XATTRENTRIES)->second = "2"; - inode2.mutable_xattr()->find(XATTRFBYTES)->second = "100"; + inode2.mutable_xattr()->find(XATTR_DIR_FILES)->second = "1"; + inode2.mutable_xattr()->find(XATTR_DIR_SUBDIRS)->second = "1"; + inode2.mutable_xattr()->find(XATTR_DIR_ENTRIES)->second = "2"; + inode2.mutable_xattr()->find(XATTR_DIR_FBYTES)->second = "100"; UpdateInodeRequest request = MakeUpdateInodeRequestFromInode(inode2); ASSERT_EQ(manager->UpdateInode(request), MetaStatusCode::OK); @@ -496,10 +496,10 @@ TEST_F(InodeManagerTest, testGetXAttr) { ASSERT_EQ(manager->GetXAttr(fsId, inode2.inodeid(), &xattr1), MetaStatusCode::OK); ASSERT_EQ(xattr1.xattrinfos_size(), 4); - ASSERT_EQ(xattr1.xattrinfos().find(XATTRFILES)->second, "1"); - ASSERT_EQ(xattr1.xattrinfos().find(XATTRSUBDIRS)->second, "1"); - ASSERT_EQ(xattr1.xattrinfos().find(XATTRENTRIES)->second, "2"); - ASSERT_EQ(xattr1.xattrinfos().find(XATTRFBYTES)->second, "100"); + ASSERT_EQ(xattr1.xattrinfos().find(XATTR_DIR_FILES)->second, "1"); + ASSERT_EQ(xattr1.xattrinfos().find(XATTR_DIR_SUBDIRS)->second, "1"); + ASSERT_EQ(xattr1.xattrinfos().find(XATTR_DIR_ENTRIES)->second, "2"); + ASSERT_EQ(xattr1.xattrinfos().find(XATTR_DIR_FBYTES)->second, "100"); } TEST_F(InodeManagerTest, testCreateManageInode) { diff --git a/curvefs/test/metaserver/inode_storage_test.cpp b/curvefs/test/metaserver/inode_storage_test.cpp index bd0de52901..ffac1c2069 100644 --- a/curvefs/test/metaserver/inode_storage_test.cpp +++ b/curvefs/test/metaserver/inode_storage_test.cpp @@ -308,30 +308,30 @@ TEST_F(InodeStorageTest, testGetXAttr) { inode.set_mode(777); inode.set_nlink(2); inode.set_type(FsFileType::TYPE_DIRECTORY); - inode.mutable_xattr()->insert({XATTRFILES, "1"}); - inode.mutable_xattr()->insert({XATTRSUBDIRS, "1"}); - inode.mutable_xattr()->insert({XATTRENTRIES, "2"}); - inode.mutable_xattr()->insert({XATTRFBYTES, "100"}); + inode.mutable_xattr()->insert({XATTR_DIR_FILES, "1"}); + inode.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "1"}); + inode.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "2"}); + inode.mutable_xattr()->insert({XATTR_DIR_FBYTES, "100"}); - inode.mutable_xattr()->insert({XATTRRFILES, "100"}); - inode.mutable_xattr()->insert({XATTRRSUBDIRS, "100"}); - inode.mutable_xattr()->insert({XATTRRENTRIES, "200"}); - inode.mutable_xattr()->insert({XATTRRFBYTES, "1000"}); + inode.mutable_xattr()->insert({XATTR_DIR_RFILES, "100"}); + inode.mutable_xattr()->insert({XATTR_DIR_RSUBDIRS, "100"}); + inode.mutable_xattr()->insert({XATTR_DIR_RENTRIES, "200"}); + inode.mutable_xattr()->insert({XATTR_DIR_RFBYTES, "1000"}); ASSERT_EQ(storage.Insert(inode), MetaStatusCode::OK); XAttr xattr; ASSERT_EQ(storage.GetXAttr(Key4Inode(1, 1), &xattr), MetaStatusCode::OK); ASSERT_FALSE(xattr.xattrinfos().empty()); - ASSERT_EQ(xattr.xattrinfos().find(XATTRFILES)->second, "1"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRSUBDIRS)->second, "1"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRENTRIES)->second, "2"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRFBYTES)->second, "100"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_FILES)->second, "1"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_SUBDIRS)->second, "1"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_ENTRIES)->second, "2"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_FBYTES)->second, "100"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRRFILES)->second, "100"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRRSUBDIRS)->second, "100"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRRENTRIES)->second, "200"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRRFBYTES)->second, "1000"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_RFILES)->second, "100"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_RSUBDIRS)->second, "100"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_RENTRIES)->second, "200"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_RFBYTES)->second, "1000"); } TEST_F(InodeStorageTest, ModifyInodeS3ChunkInfoList) { diff --git a/curvefs/test/metaserver/metastore_test.cpp b/curvefs/test/metaserver/metastore_test.cpp index fbb41016b6..3fdabac9cd 100644 --- a/curvefs/test/metaserver/metastore_test.cpp +++ b/curvefs/test/metaserver/metastore_test.cpp @@ -1412,10 +1412,10 @@ TEST_F(MetastoreTest, testBatchGetXAttr) { updateRequest.set_partitionid(partitionId); updateRequest.set_fsid(fsId); updateRequest.set_inodeid(inodeId1); - updateRequest.mutable_xattr()->insert({XATTRFILES, "1"}); - updateRequest.mutable_xattr()->insert({XATTRSUBDIRS, "2"}); - updateRequest.mutable_xattr()->insert({XATTRENTRIES, "3"}); - updateRequest.mutable_xattr()->insert({XATTRFBYTES, "100"}); + updateRequest.mutable_xattr()->insert({XATTR_DIR_FILES, "1"}); + updateRequest.mutable_xattr()->insert({XATTR_DIR_SUBDIRS, "2"}); + updateRequest.mutable_xattr()->insert({XATTR_DIR_ENTRIES, "3"}); + updateRequest.mutable_xattr()->insert({XATTR_DIR_FBYTES, "100"}); ret = metastore.UpdateInode(&updateRequest, &updateResponse); ASSERT_EQ(updateResponse.statuscode(), MetaStatusCode::OK); @@ -1433,39 +1433,39 @@ TEST_F(MetastoreTest, testBatchGetXAttr) { ASSERT_EQ(batchResponse.xattr_size(), 2); if (batchResponse.xattr(0).inodeid() == inodeId1) { ASSERT_EQ(batchResponse.xattr(0).xattrinfos() - .find(XATTRFILES)->second, "1"); + .find(XATTR_DIR_FILES)->second, "1"); ASSERT_EQ(batchResponse.xattr(0).xattrinfos() - .find(XATTRSUBDIRS)->second, "2"); + .find(XATTR_DIR_SUBDIRS)->second, "2"); ASSERT_EQ(batchResponse.xattr(0).xattrinfos() - .find(XATTRENTRIES)->second, "3"); + .find(XATTR_DIR_ENTRIES)->second, "3"); ASSERT_EQ(batchResponse.xattr(0).xattrinfos() - .find(XATTRFBYTES)->second, "100"); + .find(XATTR_DIR_FBYTES)->second, "100"); ASSERT_EQ(batchResponse.xattr(1).xattrinfos() - .find(XATTRFILES)->second, "0"); + .find(XATTR_DIR_FILES)->second, "0"); ASSERT_EQ(batchResponse.xattr(1).xattrinfos() - .find(XATTRSUBDIRS)->second, "0"); + .find(XATTR_DIR_SUBDIRS)->second, "0"); ASSERT_EQ(batchResponse.xattr(1).xattrinfos() - .find(XATTRENTRIES)->second, "0"); + .find(XATTR_DIR_ENTRIES)->second, "0"); ASSERT_EQ(batchResponse.xattr(1).xattrinfos() - .find(XATTRFBYTES)->second, "0"); + .find(XATTR_DIR_FBYTES)->second, "0"); } else { ASSERT_EQ(batchResponse.xattr(1).xattrinfos() - .find(XATTRFILES)->second, "1"); + .find(XATTR_DIR_FILES)->second, "1"); ASSERT_EQ(batchResponse.xattr(1).xattrinfos() - .find(XATTRSUBDIRS)->second, "2"); + .find(XATTR_DIR_SUBDIRS)->second, "2"); ASSERT_EQ(batchResponse.xattr(1).xattrinfos() - .find(XATTRENTRIES)->second, "3"); + .find(XATTR_DIR_ENTRIES)->second, "3"); ASSERT_EQ(batchResponse.xattr(1).xattrinfos() - .find(XATTRFBYTES)->second, "100"); + .find(XATTR_DIR_FBYTES)->second, "100"); ASSERT_EQ(batchResponse.xattr(0).xattrinfos() - .find(XATTRFILES)->second, "0"); + .find(XATTR_DIR_FILES)->second, "0"); ASSERT_EQ(batchResponse.xattr(0).xattrinfos() - .find(XATTRSUBDIRS)->second, "0"); + .find(XATTR_DIR_SUBDIRS)->second, "0"); ASSERT_EQ(batchResponse.xattr(0).xattrinfos() - .find(XATTRENTRIES)->second, "0"); + .find(XATTR_DIR_ENTRIES)->second, "0"); ASSERT_EQ(batchResponse.xattr(0).xattrinfos() - .find(XATTRFBYTES)->second, "0"); + .find(XATTR_DIR_FBYTES)->second, "0"); } } diff --git a/curvefs/test/metaserver/partition_test.cpp b/curvefs/test/metaserver/partition_test.cpp index 9f1f15e480..cc56c20e56 100644 --- a/curvefs/test/metaserver/partition_test.cpp +++ b/curvefs/test/metaserver/partition_test.cpp @@ -430,10 +430,10 @@ TEST_F(PartitionTest, testGetXAttr) { ASSERT_EQ(partition1.GetXAttr(1, 100, &xattr), MetaStatusCode::OK); ASSERT_EQ(xattr.inodeid(), 100); ASSERT_EQ(xattr.fsid(), 1); - ASSERT_EQ(xattr.xattrinfos().find(XATTRFILES)->second, "0"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRSUBDIRS)->second, "0"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRENTRIES)->second, "0"); - ASSERT_EQ(xattr.xattrinfos().find(XATTRFBYTES)->second, "0"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_FILES)->second, "0"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_SUBDIRS)->second, "0"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_ENTRIES)->second, "0"); + ASSERT_EQ(xattr.xattrinfos().find(XATTR_DIR_FBYTES)->second, "0"); } } // namespace metaserver