Skip to content

Commit

Permalink
curvefs/client: let curve specified xattr works even if disable xattr.
Browse files Browse the repository at this point in the history
Signed-off-by: Wine93 <[email protected]>
  • Loading branch information
Wine93 committed Aug 8, 2023
1 parent 4596aa9 commit 9f10872
Show file tree
Hide file tree
Showing 26 changed files with 425 additions and 265 deletions.
6 changes: 3 additions & 3 deletions curvefs/conf/client.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions curvefs/src/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand All @@ -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",
],
Expand Down
6 changes: 0 additions & 6 deletions curvefs/src/client/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ struct DeferSyncOption {

struct FileSystemOption {
bool cto;
bool disableXattr;
bool disableXAttr;
uint32_t maxNameLength;
uint32_t blockSize = 0x10000u;
KernelCacheOption kernelCacheOption;
Expand Down
15 changes: 7 additions & 8 deletions curvefs/src/client/curve_fuse_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
71 changes: 71 additions & 0 deletions curvefs/src/client/filesystem/xattr.h
Original file line number Diff line number Diff line change
@@ -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 <cstdint>
#include <string>
#include <map>

#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<std::string, bool> 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_
89 changes: 53 additions & 36 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 { \
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 9f10872

Please sign in to comment.