Skip to content

curvefs: xattr summary info support hard link #1185

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

Merged
merged 1 commit into from
Apr 2, 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
2 changes: 1 addition & 1 deletion curvefs/conf/tools.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ s3.bucket_name=bucket
s3.blocksize=4194304
s3.chunksize=67108864
# statistic info in xattr, hardlink will not be supported when enable
enableSumInDir=false
enableSumInDir=true
7 changes: 5 additions & 2 deletions curvefs/proto/metaserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ message Inode {
optional uint32 dtime = 19;
optional uint32 openmpcount = 20; // openmpcount mount points had the file open
map<string, string> xattr = 21;
repeated uint64 parent = 22;
}

message GetInodeResponse {
Expand All @@ -217,8 +218,9 @@ message CreateInodeRequest {
required uint32 gid = 7;
required uint32 mode = 8;
required FsFileType type = 9;
optional uint64 rdev = 10;
optional string symlink = 11; // TYPE_SYM_LINK only
required uint64 parent = 10;
optional uint64 rdev = 11;
optional string symlink = 12; // TYPE_SYM_LINK only
}

message CreateInodeResponse {
Expand Down Expand Up @@ -269,6 +271,7 @@ message UpdateInodeRequest {
optional uint32 nlink = 18;
optional InodeOpenStatusChange inodeOpenstatusChange = 19;
map<string, string> xattr = 20;
repeated uint64 parent = 21;
}

message UpdateInodeResponse {
Expand Down
47 changes: 42 additions & 5 deletions curvefs/src/client/client_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ RenameOperator::RenameOperator(uint32_t fsId,
srcTxId_(0),
dstTxId_(0),
oldInodeId_(0),
oldInodeSize_(-1),
dentryManager_(dentryManager),
inodeManager_(inodeManager),
metaClient_(metaClient),
Expand Down Expand Up @@ -144,6 +145,23 @@ CURVEFS_ERROR RenameOperator::Precheck() {
return rc;
}

// record old inode info if overwrite
CURVEFS_ERROR RenameOperator::RecordOldInodeInfo() {
if (oldInodeId_ != 0) {
std::shared_ptr<InodeWrapper> inodeWrapper;
auto rc = inodeManager_->GetInode(oldInodeId_, inodeWrapper);
if (rc == CURVEFS_ERROR::OK) {
oldInodeSize_ = inodeWrapper->GetLength();
oldInodeType_ = inodeWrapper->GetType();
} else {
LOG_ERROR("GetInode", rc);
return CURVEFS_ERROR::NOTEXIST;
}
}

return CURVEFS_ERROR::OK;
}

CURVEFS_ERROR RenameOperator::PrepareRenameTx(
const std::vector<Dentry>& dentrys) {
auto rc = metaClient_->PrepareRenameTx(dentrys);
Expand Down Expand Up @@ -209,15 +227,15 @@ CURVEFS_ERROR RenameOperator::CommitTx() {
return CURVEFS_ERROR::OK;
}

CURVEFS_ERROR RenameOperator::LinkInode(uint64_t inodeId) {
CURVEFS_ERROR RenameOperator::LinkInode(uint64_t inodeId, uint64_t parent) {
std::shared_ptr<InodeWrapper> inodeWrapper;
auto rc = inodeManager_->GetInode(inodeId, inodeWrapper);
if (rc != CURVEFS_ERROR::OK) {
LOG_ERROR("GetInode", rc);
return rc;
}

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

CURVEFS_ERROR RenameOperator::UnLinkInode(uint64_t inodeId) {
CURVEFS_ERROR RenameOperator::UnLinkInode(uint64_t inodeId, uint64_t parent) {
std::shared_ptr<InodeWrapper> inodeWrapper;
auto rc = inodeManager_->GetInode(inodeId, inodeWrapper);
if (rc != CURVEFS_ERROR::OK) {
LOG_ERROR("GetInode", rc);
return rc;
}

rc = inodeWrapper->UnLinkLocked();
rc = inodeWrapper->UnLinkLocked(parent);
if (rc != CURVEFS_ERROR::OK) {
LOG_ERROR("UnLink", rc);
return rc;
Expand Down Expand Up @@ -271,10 +289,29 @@ void RenameOperator::UnlinkOldInode() {
return;
}

auto rc = UnLinkInode(oldInodeId_);
auto rc = UnLinkInode(oldInodeId_, newParentId_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why some unlinkinode only have one param, some have two params

Copy link
Contributor Author

@SeanHai SeanHai Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why some unlinkinode only have one param, some have two params

The UnLinkInode with one param(actual two params, with one default param) used in 'UnlinkSrcParentInode' only decrease nlink of srcParentInode and will not occured delete.
The UnLinkInode with two params used to decrease nlink of current inode maybe be deleted when nlink decreased to 0.

LOG(INFO) << "Unlink old inode, retCode = " << rc;
}

CURVEFS_ERROR RenameOperator::UpdateInodeParent() {
std::shared_ptr<InodeWrapper> inodeWrapper;
auto rc = inodeManager_->GetInode(srcDentry_.inodeid(), inodeWrapper);
if (rc != CURVEFS_ERROR::OK) {
LOG_ERROR("GetInode", rc);
return rc;
}

rc = inodeWrapper->UpdateParentLocked(parentId_, newParentId_);
if (rc != CURVEFS_ERROR::OK) {
LOG_ERROR("UpdateInodeParent", rc);
return rc;
}

LOG(INFO) << "UpdateInodeParent oldParent = " << parentId_
<< ", newParent = " << newParentId_;
return rc;
}

void RenameOperator::UpdateCache() {
dentryManager_->DeleteCache(parentId_, name_);
dentryManager_->InsertOrReplaceCache(newDentry_);
Expand Down
16 changes: 14 additions & 2 deletions curvefs/src/client/client_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,22 @@ class RenameOperator {

CURVEFS_ERROR GetTxId();
CURVEFS_ERROR Precheck();
CURVEFS_ERROR RecordOldInodeInfo();
CURVEFS_ERROR LinkDestParentInode();
CURVEFS_ERROR PrepareTx();
CURVEFS_ERROR CommitTx();
void UnlinkSrcParentInode();
void UnlinkOldInode();
CURVEFS_ERROR UpdateInodeParent();
void UpdateCache();

void GetOldInode(uint64_t *oldInodeId, int64_t *oldInodeSize,
FsFileType *oldInodeType) {
*oldInodeId = oldInodeId_;
*oldInodeSize = oldInodeSize_;
*oldInodeType = oldInodeType_;
}

private:
std::string DebugString();

Expand All @@ -71,9 +80,9 @@ class RenameOperator {

CURVEFS_ERROR PrepareRenameTx(const std::vector<Dentry>& dentrys);

CURVEFS_ERROR LinkInode(uint64_t inodeId);
CURVEFS_ERROR LinkInode(uint64_t inodeId, uint64_t parent = 0);

CURVEFS_ERROR UnLinkInode(uint64_t inodeId);
CURVEFS_ERROR UnLinkInode(uint64_t inodeId, uint64_t parent = 0);

private:
uint32_t fsId_;
Expand All @@ -87,6 +96,9 @@ class RenameOperator {
uint64_t srcTxId_;
uint64_t dstTxId_;
uint64_t oldInodeId_;
// if dest exist, record the size and type of file or empty dir
int64_t oldInodeSize_;
FsFileType oldInodeType_;
Dentry srcDentry_;
Dentry dstDentry_;
Dentry dentry_;
Expand Down
Loading