Skip to content

Commit

Permalink
curve-fuse: fix misuse Locked & Unlocked calling contract
Browse files Browse the repository at this point in the history
Signed-off-by: Hanqing Wu <[email protected]>
  • Loading branch information
wu-hanqing committed Sep 6, 2022
1 parent f6a10ea commit 2ad2362
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 276 deletions.
6 changes: 3 additions & 3 deletions curvefs/src/client/client_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ CURVEFS_ERROR RenameOperator::LinkInode(uint64_t inodeId, uint64_t parent) {
return rc;
}

rc = inodeWrapper->LinkLocked(parent);
rc = inodeWrapper->Link(parent);
if (rc != CURVEFS_ERROR::OK) {
LOG_ERROR("Link", rc);
return rc;
Expand All @@ -297,7 +297,7 @@ CURVEFS_ERROR RenameOperator::UnLinkInode(uint64_t inodeId, uint64_t parent) {
return rc;
}

rc = inodeWrapper->UnLinkLocked(parent);
rc = inodeWrapper->UnLink(parent);
if (rc != CURVEFS_ERROR::OK) {
LOG_ERROR("UnLink", rc);
return rc;
Expand Down Expand Up @@ -385,7 +385,7 @@ CURVEFS_ERROR RenameOperator::UpdateInodeParent() {
return rc;
}

rc = inodeWrapper->UpdateParentLocked(parentId_, newParentId_);
rc = inodeWrapper->UpdateParent(parentId_, newParentId_);
if (rc != CURVEFS_ERROR::OK) {
LOG_ERROR("UpdateInodeParent", rc);
return rc;
Expand Down
14 changes: 7 additions & 7 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ CURVEFS_ERROR FuseClient::FuseOpOpen(fuse_req_t req, fuse_ino_t ino,
<< ", inodeid = " << ino;
return CURVEFS_ERROR::INTERNAL;
}
inodeWrapper->SetLength(0);
inodeWrapper->SetLengthLocked(0);
inodeWrapper->UpdateTimestampLocked(kChangeTime | kModifyTime);
if (length != 0) {
ret = inodeWrapper->Sync();
Expand Down Expand Up @@ -755,7 +755,7 @@ CURVEFS_ERROR FuseClient::RemoveNode(fuse_req_t req, fuse_ino_t parent,
return ret;
}

ret = inodeWrapper->UnLinkLocked(parent);
ret = inodeWrapper->UnLink(parent);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "UnLink failed, ret = " << ret << ", inodeid = " << ino
<< ", parent = " << parent << ", name = " << name;
Expand Down Expand Up @@ -1037,13 +1037,13 @@ CURVEFS_ERROR FuseClient::FuseOpSetAttr(fuse_req_t req, fuse_ino_t ino,
<< ", inodeid = " << ino;
return tRet;
}
inodeWrapper->SetLength(attr->st_size);
inodeWrapper->SetLengthLocked(attr->st_size);
ret = inodeWrapper->Sync();
if (ret != CURVEFS_ERROR::OK) {
return ret;
}
InodeAttr inodeAttr;
inodeWrapper->GetInodeAttrUnlocked(&inodeAttr);
inodeWrapper->GetInodeAttrLocked(&inodeAttr);
InodeAttr2ParamAttr(inodeAttr, attrOut);

if (enableSumInDir_ && changeSize != 0) {
Expand All @@ -1070,7 +1070,7 @@ CURVEFS_ERROR FuseClient::FuseOpSetAttr(fuse_req_t req, fuse_ino_t ino,
return ret;
}
InodeAttr inodeAttr;
inodeWrapper->GetInodeAttrUnlocked(&inodeAttr);
inodeWrapper->GetInodeAttrLocked(&inodeAttr);
InodeAttr2ParamAttr(inodeAttr, attrOut);
return ret;
}
Expand Down Expand Up @@ -1295,7 +1295,7 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req, fuse_ino_t ino,
<< ", inodeid = " << ino;
return ret;
}
ret = inodeWrapper->LinkLocked(newparent);
ret = inodeWrapper->Link(newparent);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "Link Inode fail, ret = " << ret << ", inodeid = " << ino
<< ", newparent = " << newparent
Expand All @@ -1313,7 +1313,7 @@ CURVEFS_ERROR FuseClient::FuseOpLink(fuse_req_t req, fuse_ino_t ino,
LOG(ERROR) << "dentryManager_ CreateDentry fail, ret = " << ret
<< ", parent = " << newparent << ", name = " << newname;

CURVEFS_ERROR ret2 = inodeWrapper->UnLinkLocked(newparent);
CURVEFS_ERROR ret2 = inodeWrapper->UnLink(newparent);
if (ret2 != CURVEFS_ERROR::OK) {
LOG(ERROR) << "Also unlink inode failed, ret = " << ret2
<< ", inodeid = " << inodeWrapper->GetInodeId();
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/fuse_s3_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ CURVEFS_ERROR FuseS3Client::FuseOpWrite(fuse_req_t req, fuse_ino_t ino,
// update file len
if (inodeWrapper->GetLengthLocked() < off + *wSize) {
changeSize = off + *wSize - inodeWrapper->GetLengthLocked();
inodeWrapper->SetLength(off + *wSize);
inodeWrapper->SetLengthLocked(off + *wSize);
}

inodeWrapper->UpdateTimestampLocked(kModifyTime | kChangeTime);
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/inode_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ InodeCacheManagerImpl::RefreshInode(uint64_t inodeId) {
if (!ok) {
PUT_INODE_CACHE(inodeId, out);
} else {
out->SetLength(inode.length());
out->SetLengthLocked(inode.length());
}

return CURVEFS_ERROR::OK;
Expand Down
6 changes: 3 additions & 3 deletions curvefs/src/client/inode_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ CURVEFS_ERROR InodeWrapper::RefreshS3ChunkInfo() {
return CURVEFS_ERROR::OK;
}

CURVEFS_ERROR InodeWrapper::LinkLocked(uint64_t parent) {
CURVEFS_ERROR InodeWrapper::Link(uint64_t parent) {
curve::common::UniqueLock lg(mtx_);
REFRESH_NLINK_IF_NEED;
uint32_t old = inode_.nlink();
Expand Down Expand Up @@ -292,7 +292,7 @@ CURVEFS_ERROR InodeWrapper::LinkLocked(uint64_t parent) {
return CURVEFS_ERROR::OK;
}

CURVEFS_ERROR InodeWrapper::UnLinkLocked(uint64_t parent) {
CURVEFS_ERROR InodeWrapper::UnLink(uint64_t parent) {
curve::common::UniqueLock lg(mtx_);
REFRESH_NLINK_IF_NEED;
uint32_t old = inode_.nlink();
Expand Down Expand Up @@ -363,7 +363,7 @@ CURVEFS_ERROR InodeWrapper::UnLinkLocked(uint64_t parent) {
return CURVEFS_ERROR::INTERNAL;
}

CURVEFS_ERROR InodeWrapper::UpdateParentLocked(
CURVEFS_ERROR InodeWrapper::UpdateParent(
uint64_t oldParent, uint64_t newParent) {
curve::common::UniqueLock lg(mtx_);
auto parents = inode_.mutable_parent();
Expand Down
17 changes: 6 additions & 11 deletions curvefs/src/client/inode_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <memory>
#include <string>


#include "curvefs/src/common/define.h"
#include "curvefs/proto/metaserver.pb.h"
#include "curvefs/src/client/error_code.h"
Expand Down Expand Up @@ -112,10 +111,6 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {
g_alive_inode_count << -1;
}

uint64_t inodeid() const {
return GetInodeId();
}

uint64_t GetInodeId() const {
return inode_.inodeid();
}
Expand Down Expand Up @@ -202,7 +197,7 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {
void MergeXAttrLocked(
const google::protobuf::Map<std::string, std::string>& xattrs);

CURVEFS_ERROR GetInodeAttrUnlocked(InodeAttr *attr) {
CURVEFS_ERROR GetInodeAttrLocked(InodeAttr *attr) {
REFRESH_NLINK_IF_NEED;

attr->set_inodeid(inode_.inodeid());
Expand Down Expand Up @@ -235,9 +230,9 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {
return CURVEFS_ERROR::OK;
}

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

XAttr GetXattr() const {
Expand All @@ -253,12 +248,12 @@ class InodeWrapper : public std::enable_shared_from_this<InodeWrapper> {
return curve::common::UniqueLock(mtx_);
}

CURVEFS_ERROR UpdateParentLocked(uint64_t oldParent, uint64_t newParent);
CURVEFS_ERROR UpdateParent(uint64_t oldParent, uint64_t newParent);

// dir will not update parent
CURVEFS_ERROR LinkLocked(uint64_t parent = 0);
CURVEFS_ERROR Link(uint64_t parent = 0);

CURVEFS_ERROR UnLinkLocked(uint64_t parent = 0);
CURVEFS_ERROR UnLink(uint64_t parent = 0);

// mark nlink invalid, need to refresh from metaserver
void InvalidateNlink() {
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/volume/default_volume_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ CURVEFS_ERROR DefaultVolumeStorage::Write(uint64_t ino,
{
auto lk = inodeWrapper->GetUniqueLock();
if (offset + len > inodeWrapper->GetLengthLocked()) {
inodeWrapper->SetLength(offset + len);
inodeWrapper->SetLengthLocked(offset + len);
}

inodeWrapper->UpdateTimestampLocked(kModifyTime | kChangeTime);
Expand Down
Loading

0 comments on commit 2ad2362

Please sign in to comment.