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 Oct 18, 2023
1 parent 9c3fb27 commit 112cd41
Show file tree
Hide file tree
Showing 27 changed files with 446 additions and 298 deletions.
6 changes: 3 additions & 3 deletions curvefs/conf/client.conf
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,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 @@ -65,12 +65,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";
const char kCurveFsWarmupXAttrList[] = "curvefs.warmup.op.list";

constexpr size_t kMinWarmupOpArgsNum = 1;
constexpr size_t kWarmupAddArgsNum = 6;
constexpr size_t kWarmupCancelArgsNum = 2;
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 @@ -304,7 +304,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
24 changes: 6 additions & 18 deletions curvefs/src/client/curve_fuse_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "curvefs/src/common/metric_utils.h"
#include "src/common/configuration.h"
#include "src/common/gflags_helper.h"
#include "curvefs/src/client/filesystem/xattr.h"

using ::curve::common::Configuration;
using ::curvefs::client::CURVEFS_ERROR;
Expand Down Expand Up @@ -77,6 +78,8 @@ using ::curvefs::client::rpcclient::MDSBaseClient;
using ::curvefs::client::rpcclient::MdsClientImpl;
using ::curvefs::client::warmup::WarmupProgress;
using ::curvefs::common::LatencyUpdater;
using ::curvefs::client::filesystem::IsWarmupXAttr;
using ::curvefs::client::filesystem::IsListWarmupXAttr;

using ::curvefs::common::FLAGS_vlog_level;

Expand Down Expand Up @@ -901,21 +904,6 @@ void FuseOpStatFs(fuse_req_t req, fuse_ino_t ino) {
return fs->ReplyStatfs(req, &stbuf);
}

const char* warmupXAttr = ::curvefs::client::common::kCurveFsWarmupXAttr;
const char* warmupListXAttr =
::curvefs::client::common::kCurveFsWarmupXAttrList;

bool IsWamupReq(const char* name) {
if (strlen(name) < strlen(warmupXAttr)) {
return false;
}
return strncmp(name, warmupXAttr, strlen(warmupXAttr)) == 0;
}

bool IsWarmupListReq(const char* name) {
return IsWamupReq(name) && strcmp(name, warmupListXAttr) == 0;
}

void FuseOpSetXattr(fuse_req_t req,
fuse_ino_t ino,
const char* name,
Expand All @@ -930,7 +918,7 @@ void FuseOpSetXattr(fuse_req_t req,
ino, name, size, flags, StrErr(rc));
});

if (IsWamupReq(name)) {
if (IsWarmupXAttr(name)) {
return TriggerWarmup(req, ino, name, value, size);
}
rc = client->FuseOpSetXattr(req, ino, name, value, size, flags);
Expand All @@ -951,9 +939,9 @@ void FuseOpGetXattr(fuse_req_t req,
ino, name, size, StrErr(rc), value.size());
});

if (IsWarmupListReq(name)) {
if (IsListWarmupXAttr(name)) {
return ListWarmup(req, size);
} else if (IsWamupReq(name)) {
} else if (IsWarmupXAttr(name)) {
return QueryWarmup(req, ino, size);
}

Expand Down
76 changes: 76 additions & 0 deletions curvefs/src/client/filesystem/xattr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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";
const char XATTR_WARMUP_OP_LIST[] = "curvefs.warmup.op.list";

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;
}

inline bool IsListWarmupXAttr(const std::string& key) {
return key == XATTR_WARMUP_OP_LIST;
}

} // namespace filesystem
} // namespace client
} // namespace curvefs

#endif // CURVEFS_SRC_CLIENT_FILESYSTEM_XATTR_H_
Loading

0 comments on commit 112cd41

Please sign in to comment.