Skip to content

Commit

Permalink
curvefs/client: fix update nlink error
Browse files Browse the repository at this point in the history
Signed-off-by: wanghai01 <seanhaizi@163.com>
  • Loading branch information
SeanHai committed Sep 7, 2022
1 parent 89b3fff commit 0a0a3c1
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 87 deletions.
23 changes: 11 additions & 12 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ CURVEFS_ERROR FuseClient::FuseOpOpen(fuse_req_t req, fuse_ino_t ino,
return ret;
}

CURVEFS_ERROR FuseClient::UpdateParentInodeMCTimeAndInvalidNlink(
fuse_ino_t parent, FsFileType type) {
CURVEFS_ERROR FuseClient::UpdateParentMCTimeAndNlink(
fuse_ino_t parent, FsFileType type, int32_t nlink) {
std::shared_ptr<InodeWrapper> parentInodeWrapper;
auto ret = inodeManager_->GetInode(parent, parentInodeWrapper);
if (ret != CURVEFS_ERROR::OK) {
Expand All @@ -580,7 +580,7 @@ CURVEFS_ERROR FuseClient::UpdateParentInodeMCTimeAndInvalidNlink(
parentInodeWrapper->UpdateTimestampLocked(kModifyTime | kChangeTime);

if (FsFileType::TYPE_DIRECTORY == type) {
parentInodeWrapper->InvalidateNlink();
parentInodeWrapper->UpdateNlinkLocked(nlink);
}
}
return CURVEFS_ERROR::OK;
Expand Down Expand Up @@ -647,9 +647,9 @@ CURVEFS_ERROR FuseClient::MakeNode(fuse_req_t req, fuse_ino_t parent,
return ret;
}

ret = UpdateParentInodeMCTimeAndInvalidNlink(parent, type);
ret = UpdateParentMCTimeAndNlink(parent, type, 1);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentInodeMCTimeAndInvalidNlink failed"
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
<< ", parent: " << parent
<< ", name: " << name
<< ", type: " << type;
Expand Down Expand Up @@ -738,9 +738,9 @@ CURVEFS_ERROR FuseClient::RemoveNode(fuse_req_t req, fuse_ino_t parent,
return ret;
}

ret = UpdateParentInodeMCTimeAndInvalidNlink(parent, type);
ret = UpdateParentMCTimeAndNlink(parent, type, -1);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentInodeMCTimeAndInvalidNlink failed"
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
<< ", parent: " << parent
<< ", name: " << name
<< ", type: " << type;
Expand Down Expand Up @@ -1249,10 +1249,9 @@ CURVEFS_ERROR FuseClient::FuseOpSymlink(fuse_req_t req, const char *link,
return ret;
}

ret = UpdateParentInodeMCTimeAndInvalidNlink(
parent, FsFileType::TYPE_SYM_LINK);
ret = UpdateParentMCTimeAndNlink(parent, FsFileType::TYPE_SYM_LINK, 1);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentInodeMCTimeAndInvalidNlink failed"
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
<< ", link:" << link
<< ", parent: " << parent
<< ", name: " << name
Expand Down Expand Up @@ -1321,9 +1320,9 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req, fuse_ino_t ino,
return ret;
}

ret = UpdateParentInodeMCTimeAndInvalidNlink(newparent, type);
ret = UpdateParentMCTimeAndNlink(newparent, type, 1);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UpdateParentInodeMCTimeAndInvalidNlink failed"
LOG(ERROR) << "UpdateParentMCTimeAndNlink failed"
<< ", parent: " << newparent
<< ", name: " << newname
<< ", type: " << type;
Expand Down
4 changes: 2 additions & 2 deletions curvefs/src/client/fuse_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ class FuseClient {

virtual void FlushData() = 0;

CURVEFS_ERROR UpdateParentInodeMCTimeAndInvalidNlink(
fuse_ino_t parent, FsFileType type);
CURVEFS_ERROR UpdateParentMCTimeAndNlink(
fuse_ino_t parent, FsFileType type, int32_t nlink);

void WarmUpTask();

Expand Down
41 changes: 38 additions & 3 deletions curvefs/src/client/inode_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,42 @@ class GetOrModifyS3ChunkInfoAsyncDone : public MetaServerClientDone {
std::shared_ptr<InodeWrapper> inodeWrapper_;
};

CURVEFS_ERROR InodeWrapper::GetInodeAttrLocked(InodeAttr *attr) {
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());
*(attr->mutable_parent()) = inode_.parent();
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_.xattr_size() > 0) {
*(attr->mutable_xattr()) = inode_.xattr();
}
return CURVEFS_ERROR::OK;
}

void InodeWrapper::GetInodeAttr(InodeAttr *attr) {
curve::common::UniqueLock lg(mtx_);
GetInodeAttrLocked(attr);
}

CURVEFS_ERROR InodeWrapper::SyncAttr(bool internal) {
curve::common::UniqueLock lock = GetSyncingInodeUniqueLock();
if (dirty_) {
Expand Down Expand Up @@ -263,7 +299,7 @@ CURVEFS_ERROR InodeWrapper::RefreshS3ChunkInfo() {

CURVEFS_ERROR InodeWrapper::Link(uint64_t parent) {
curve::common::UniqueLock lg(mtx_);
REFRESH_NLINK_IF_NEED;
REFRESH_NLINK;
uint32_t old = inode_.nlink();
inode_.set_nlink(old + 1);
dirtyAttr_.set_nlink(inode_.nlink());
Expand Down Expand Up @@ -294,7 +330,7 @@ CURVEFS_ERROR InodeWrapper::Link(uint64_t parent) {

CURVEFS_ERROR InodeWrapper::UnLink(uint64_t parent) {
curve::common::UniqueLock lg(mtx_);
REFRESH_NLINK_IF_NEED;
REFRESH_NLINK;
uint32_t old = inode_.nlink();
VLOG(1) << "Unlink inode = " << inode_.DebugString();
if (old > 0) {
Expand Down Expand Up @@ -567,7 +603,6 @@ CURVEFS_ERROR InodeWrapper::RefreshNlink() {
}
inode_.set_nlink(attr.nlink());
VLOG(3) << "RefreshNlink from metaserver, newnlink: " << attr.nlink();
ResetNlinkValid();
return CURVEFS_ERROR::OK;
}

Expand Down
72 changes: 14 additions & 58 deletions curvefs/src/client/inode_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ constexpr int kAccessTime = 1 << 0;
constexpr int kChangeTime = 1 << 1;
constexpr int kModifyTime = 1 << 2;

#define REFRESH_NLINK_IF_NEED \
#define REFRESH_NLINK \
do { \
if (!isNlinkValid_) { \
CURVEFS_ERROR ret = RefreshNlink(); \
if (ret != CURVEFS_ERROR::OK) { \
return ret; \
} \
CURVEFS_ERROR ret = RefreshNlink(); \
if (ret != CURVEFS_ERROR::OK) { \
return ret; \
} \
} while (0)

Expand Down Expand Up @@ -96,7 +94,6 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {
maxDataSize_(maxDataSize),
refreshDataInterval_(refreshDataInterval),
lastRefreshTime_(::curve::common::TimeUtility::GetTimeofDaySec()),
isNlinkValid_(true),
s3ChunkInfoAddSize_(0),
metaClient_(std::move(metaClient)),
s3ChunkInfoMetric_(std::move(s3ChunkInfoMetric)),
Expand Down Expand Up @@ -196,43 +193,9 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {
void MergeXAttrLocked(
const google::protobuf::Map<std::string, std::string>& xattrs);

CURVEFS_ERROR GetInodeAttrLocked(InodeAttr *attr) {
REFRESH_NLINK_IF_NEED;

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());
*(attr->mutable_parent()) = inode_.parent();
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_.xattr_size() > 0) {
*(attr->mutable_xattr()) = inode_.xattr();
}
return CURVEFS_ERROR::OK;
}
CURVEFS_ERROR GetInodeAttrLocked(InodeAttr *attr);

void GetInodeAttr(InodeAttr *attr) {
curve::common::UniqueLock lg(mtx_);
GetInodeAttrLocked(attr);
}
void GetInodeAttr(InodeAttr *attr);

XAttr GetXattr() const {
XAttr ret;
Expand All @@ -254,19 +217,6 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {

CURVEFS_ERROR UnLink(uint64_t parent = 0);

// mark nlink invalid, need to refresh from metaserver
void InvalidateNlink() {
isNlinkValid_ = false;
}

void ResetNlinkValid() {
isNlinkValid_ = true;
}

bool IsNlinkValid() {
return isNlinkValid_;
}

CURVEFS_ERROR RefreshNlink();

CURVEFS_ERROR Sync(bool internal = false);
Expand Down Expand Up @@ -312,6 +262,14 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {
return s3ChunkInfoAdd_.empty();
}

uint32_t GetNlinkLocked() {
return inode_.nlink();
}

void UpdateNlinkLocked(uint32_t nlink) {
inode_.set_nlink(inode_.nlink() + nlink);
}

void AppendS3ChunkInfo(uint64_t chunkIndex, const S3ChunkInfo &info) {
curve::common::UniqueLock lg(mtx_);
AppendS3ChunkInfoToMap(chunkIndex, info, &s3ChunkInfoAdd_);
Expand Down Expand Up @@ -438,8 +396,6 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {
uint32_t refreshDataInterval_;
uint64_t lastRefreshTime_;

bool isNlinkValid_;

google::protobuf::Map<uint64_t, S3ChunkInfoList> s3ChunkInfoAdd_;
int64_t s3ChunkInfoAddSize_;
int64_t s3ChunkInfoSize_;
Expand Down
Loading

0 comments on commit 0a0a3c1

Please sign in to comment.