Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curve-fuse: only update dirty inode metadata #1853

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions curvefs/src/client/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ cc_library(
"@com_google_absl//absl/strings",
"@com_google_absl//absl/meta:type_traits",
"@com_google_absl//absl/types:optional",
"@com_google_googletest//:gtest_prod",
],
)
11 changes: 4 additions & 7 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 All @@ -316,10 +316,7 @@ CURVEFS_ERROR RenameOperator::UpdateMCTime(uint64_t inodeId) {
}

curve::common::UniqueLock lk = inodeWrapper->GetUniqueLock();
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
inodeWrapper->SetMTime(now.tv_sec, now.tv_nsec);
inodeWrapper->SetCTime(now.tv_sec, now.tv_nsec);
inodeWrapper->UpdateTimestampLocked(kModifyTime | kChangeTime);

rc = inodeWrapper->SyncAttr();
if (rc != CURVEFS_ERROR::OK) {
Expand Down Expand Up @@ -388,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
78 changes: 36 additions & 42 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "curvefs/src/client/error_code.h"
#include "curvefs/src/client/fuse_common.h"
#include "curvefs/src/client/client_operator.h"
#include "curvefs/src/client/inode_wrapper.h"
#include "curvefs/src/client/xattr_manager.h"
#include "curvefs/src/common/define.h"
#include "src/common/net_common.h"
Expand Down Expand Up @@ -522,21 +523,15 @@ CURVEFS_ERROR FuseClient::FuseOpOpen(fuse_req_t req, fuse_ino_t ino,
::curve::common::UniqueLock lgGuard = inodeWrapper->GetUniqueLock();
if (fi->flags & O_TRUNC) {
if (fi->flags & O_WRONLY || fi->flags & O_RDWR) {
Inode *inode = inodeWrapper->GetMutableInodeUnlocked();
uint64_t length = inode->length();
CURVEFS_ERROR tRet = Truncate(inode, 0);
uint64_t length = inodeWrapper->GetLengthLocked();
CURVEFS_ERROR tRet = Truncate(inodeWrapper.get(), 0);
if (tRet != CURVEFS_ERROR::OK) {
LOG(ERROR) << "truncate file fail, ret = " << ret
<< ", inodeid = " << ino;
return CURVEFS_ERROR::INTERNAL;
}
inode->set_length(0);
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
inode->set_ctime(now.tv_sec);
inode->set_ctime_ns(now.tv_nsec);
inode->set_mtime(now.tv_sec);
inode->set_mtime_ns(now.tv_nsec);
inodeWrapper->SetLengthLocked(0);
inodeWrapper->UpdateTimestampLocked(kChangeTime | kModifyTime);
if (length != 0) {
ret = inodeWrapper->Sync();
if (ret != CURVEFS_ERROR::OK) {
Expand All @@ -548,6 +543,7 @@ CURVEFS_ERROR FuseClient::FuseOpOpen(fuse_req_t req, fuse_ino_t ino,

if (enableSumInDir_ && length != 0) {
// update parent summary info
const Inode *inode = inodeWrapper->GetInodeLocked();
XAttr xattr;
xattr.mutable_xattrinfos()->insert({XATTRFBYTES,
std::to_string(length)});
Expand Down Expand Up @@ -581,10 +577,7 @@ CURVEFS_ERROR FuseClient::UpdateParentInodeMCTimeAndInvalidNlink(

{
curve::common::UniqueLock lk = parentInodeWrapper->GetUniqueLock();
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
parentInodeWrapper->SetMTime(now.tv_sec, now.tv_nsec);
parentInodeWrapper->SetCTime(now.tv_sec, now.tv_nsec);
parentInodeWrapper->UpdateTimestampLocked(kModifyTime | kChangeTime);

if (FsFileType::TYPE_DIRECTORY == type) {
parentInodeWrapper->InvalidateNlink();
Expand Down Expand Up @@ -762,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 @@ -1003,62 +996,59 @@ CURVEFS_ERROR FuseClient::FuseOpSetAttr(fuse_req_t req, fuse_ino_t ino,
return ret;
}
::curve::common::UniqueLock lgGuard = inodeWrapper->GetUniqueLock();
Inode *inode = inodeWrapper->GetMutableInodeUnlocked();

struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);

if (to_set & FUSE_SET_ATTR_MODE) {
inode->set_mode(attr->st_mode);
inodeWrapper->SetMode(attr->st_mode);
}
if (to_set & FUSE_SET_ATTR_UID) {
inode->set_uid(attr->st_uid);
inodeWrapper->SetUid(attr->st_uid);
}
if (to_set & FUSE_SET_ATTR_GID) {
inode->set_gid(attr->st_gid);
inodeWrapper->SetGid(attr->st_gid);
}

struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);

if (to_set & FUSE_SET_ATTR_ATIME) {
inode->set_atime(attr->st_atim.tv_sec);
inode->set_atime_ns(attr->st_atim.tv_nsec);
inodeWrapper->UpdateTimestampLocked(attr->st_atim, kAccessTime);
}
if (to_set & FUSE_SET_ATTR_ATIME_NOW) {
inode->set_atime(now.tv_sec);
inode->set_atime_ns(now.tv_nsec);
inodeWrapper->UpdateTimestampLocked(now, kAccessTime);
}
if (to_set & FUSE_SET_ATTR_MTIME) {
inode->set_mtime(attr->st_mtim.tv_sec);
inode->set_mtime_ns(attr->st_mtim.tv_nsec);
inodeWrapper->UpdateTimestampLocked(attr->st_mtim, kModifyTime);
}
if (to_set & FUSE_SET_ATTR_MTIME_NOW) {
inode->set_mtime(now.tv_sec);
inode->set_mtime_ns(now.tv_nsec);
inodeWrapper->UpdateTimestampLocked(now, kModifyTime);
}
if (to_set & FUSE_SET_ATTR_CTIME) {
inode->set_ctime(attr->st_ctim.tv_sec);
inode->set_ctime_ns(attr->st_ctim.tv_nsec);
inodeWrapper->UpdateTimestampLocked(attr->st_ctim, kChangeTime);
} else {
inode->set_ctime(now.tv_sec);
inode->set_ctime_ns(now.tv_nsec);
inodeWrapper->UpdateTimestampLocked(now, kChangeTime);
}

if (to_set & FUSE_SET_ATTR_SIZE) {
int64_t changeSize = attr->st_size - inode->length();
CURVEFS_ERROR tRet = Truncate(inode, attr->st_size);
int64_t changeSize =
attr->st_size -
static_cast<int64_t>(inodeWrapper->GetLengthLocked());
CURVEFS_ERROR tRet = Truncate(inodeWrapper.get(), attr->st_size);
if (tRet != CURVEFS_ERROR::OK) {
LOG(ERROR) << "truncate file fail, ret = " << ret
<< ", inodeid = " << ino;
return tRet;
}
inode->set_length(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) {
// update parent summary info
const Inode* inode = inodeWrapper->GetInodeLocked();
XAttr xattr;
xattr.mutable_xattrinfos()->insert({XATTRFBYTES,
std::to_string(std::abs(changeSize))});
Expand All @@ -1080,11 +1070,13 @@ 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;
}

namespace {

bool IsSummaryInfo(const char *name) {
return std::strstr(name, SUMMARYPREFIX);
}
Expand All @@ -1099,6 +1091,8 @@ bool IsOneLayer(const char *name) {
return false;
}

} // namespace

CURVEFS_ERROR FuseClient::FuseOpGetXattr(fuse_req_t req, fuse_ino_t ino,
const char* name, void* value,
size_t size) {
Expand Down Expand Up @@ -1301,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 @@ -1319,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_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class FuseClient {
}

private:
virtual CURVEFS_ERROR Truncate(Inode* inode, uint64_t length) = 0;
virtual CURVEFS_ERROR Truncate(InodeWrapper* inode, uint64_t length) = 0;

virtual void FlushData() = 0;

Expand Down
26 changes: 8 additions & 18 deletions curvefs/src/client/fuse_s3_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,21 +375,16 @@ CURVEFS_ERROR FuseS3Client::FuseOpWrite(fuse_req_t req, fuse_ino_t ino,
}

::curve::common::UniqueLock lgGuard = inodeWrapper->GetUniqueLock();
Inode *inode = inodeWrapper->GetMutableInodeUnlocked();

*wSize = wRet;
size_t changeSize = 0;
// update file len
if (inode->length() < off + *wSize) {
changeSize = off + *wSize - inode->length();
inode->set_length(off + *wSize);
if (inodeWrapper->GetLengthLocked() < off + *wSize) {
changeSize = off + *wSize - inodeWrapper->GetLengthLocked();
inodeWrapper->SetLengthLocked(off + *wSize);
}
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
inode->set_mtime(now.tv_sec);
inode->set_mtime_ns(now.tv_nsec);
inode->set_ctime(now.tv_sec);
inode->set_ctime_ns(now.tv_nsec);

inodeWrapper->UpdateTimestampLocked(kModifyTime | kChangeTime);

inodeManager_->ShipToFlush(inodeWrapper);

Expand All @@ -398,6 +393,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,
std::to_string(changeSize)});
Expand Down Expand Up @@ -461,13 +457,7 @@ CURVEFS_ERROR FuseS3Client::FuseOpRead(fuse_req_t req, fuse_ino_t ino,
}

::curve::common::UniqueLock lgGuard = inodeWrapper->GetUniqueLock();
Inode *newInode = inodeWrapper->GetMutableInodeUnlocked();

struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
newInode->set_atime(now.tv_sec);
newInode->set_atime_ns(now.tv_nsec);

inodeWrapper->UpdateTimestampLocked(kAccessTime);
inodeManager_->ShipToFlush(inodeWrapper);

VLOG(9) << "read end, read size = " << *rSize;
Expand Down Expand Up @@ -536,7 +526,7 @@ CURVEFS_ERROR FuseS3Client::FuseOpFsync(fuse_req_t req, fuse_ino_t ino,
return inodeWrapper->Sync();
}

CURVEFS_ERROR FuseS3Client::Truncate(Inode *inode, uint64_t length) {
CURVEFS_ERROR FuseS3Client::Truncate(InodeWrapper *inode, uint64_t length) {
return s3Adaptor_->Truncate(inode, length);
}

Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/fuse_s3_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class FuseS3Client : public FuseClient {
struct fuse_file_info *fi) override;

private:
CURVEFS_ERROR Truncate(Inode *inode, uint64_t length) override;
CURVEFS_ERROR Truncate(InodeWrapper *inode, uint64_t length) override;

void FlushData() override;
// get the warmUp filelist
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/fuse_volume_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ CURVEFS_ERROR FuseVolumeClient::FuseOpFsync(fuse_req_t req, fuse_ino_t ino,
return inodeWrapper->Sync();
}

CURVEFS_ERROR FuseVolumeClient::Truncate(Inode *inode, uint64_t length) {
CURVEFS_ERROR FuseVolumeClient::Truncate(InodeWrapper *inode, uint64_t length) {
// Todo: call volume truncate
return CURVEFS_ERROR::OK;
}
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/fuse_volume_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class FuseVolumeClient : public FuseClient {
void SetVolumeStorageForTesting(VolumeStorage *storage);

private:
CURVEFS_ERROR Truncate(Inode *inode, uint64_t length) override;
CURVEFS_ERROR Truncate(InodeWrapper *inode, uint64_t length) override;

void FlushData() override;

Expand Down
6 changes: 2 additions & 4 deletions 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 Expand Up @@ -290,9 +290,7 @@ CURVEFS_ERROR InodeCacheManagerImpl::BatchGetXAttr(
NameLockGuard lock(nameLock_, std::to_string(*iter));
bool ok = iCache_->Get(*iter, &inodeWrapper);
if (ok) {
XAttr tmpXattr;
inodeWrapper->GetXattrLocked(&tmpXattr);
xattr->emplace_back(tmpXattr);
xattr->emplace_back(inodeWrapper->GetXattr());
iter = inodeIds->erase(iter);
} else {
++iter;
Expand Down
Loading