Skip to content

Commit

Permalink
curvefs: fix refresh inode in getInodeAttr everytime when read
Browse files Browse the repository at this point in the history
Signed-off-by: wanghai01 <[email protected]>
  • Loading branch information
SeanHai authored and YunhuiChen committed Sep 5, 2022
1 parent 3b562da commit 1203c60
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
5 changes: 5 additions & 0 deletions curvefs/src/client/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ std::ostream &operator<<(std::ostream &os, MetaServerOpType optype);

const uint32_t MAXXATTRLENGTH = 256;

enum class FileHandle : uint64_t {
kDefaultValue = 0,
kKeepCache = 1,
};

} // namespace common
} // namespace client
} // namespace curvefs
Expand Down
3 changes: 3 additions & 0 deletions curvefs/src/client/curve_fuse_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ using ::curvefs::client::rpcclient::MDSBaseClient;
using ::curvefs::client::metric::ClientOpMetric;
using ::curvefs::common::LatencyUpdater;
using ::curvefs::client::metric::InflightGuard;
using ::curvefs::client::common::FileHandle;

using ::curvefs::common::FLAGS_vlog_level;

Expand Down Expand Up @@ -358,6 +359,8 @@ void FuseOpOpen(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) {
FuseReplyErrByErrCode(req, ret);
return;
}
// set fh to 1 to indicate needn't refresh inode when file is still opened
fi->fh = static_cast<uint64_t>(FileHandle::kKeepCache);
fuse_reply_open(req, fi);
}

Expand Down
16 changes: 11 additions & 5 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <utility>

#include "curvefs/proto/mds.pb.h"
#include "curvefs/src/client/common/common.h"
#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/xattr_manager.h"
Expand All @@ -47,6 +49,7 @@ using ::curvefs::common::Volume;
using ::curvefs::mds::topology::PartitionTxId;
using ::curvefs::mds::FSStatusCode_Name;
using ::curvefs::client::common::MAXXATTRLENGTH;
using ::curvefs::client::common::FileHandle;

#define RETURN_IF_UNSUCCESS(action) \
do { \
Expand Down Expand Up @@ -761,11 +764,14 @@ CURVEFS_ERROR FuseClient::FuseOpGetAttr(fuse_req_t req, fuse_ino_t ino,
struct stat *attr) {
VLOG(1) << "FuseOpGetAttr ino = " << ino;
if (FLAGS_enableCto) {
CURVEFS_ERROR ret = inodeManager_->RefreshInode(ino);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "inodeManager get inode fail, ret = " << ret
<< ", inodeid = " << ino;
return ret;
if (fi == nullptr ||
fi->fh != static_cast<uint64_t>(FileHandle::kKeepCache)) {
CURVEFS_ERROR ret = inodeManager_->RefreshInode(ino);
if (ret != CURVEFS_ERROR::OK) {
LOG(ERROR) << "inodeManager get inode fail, ret = " << ret
<< ", inodeid = " << ino;
return ret;
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions curvefs/test/client/test_fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <gtest/gtest.h>

#include "absl/memory/memory.h"
#include "curvefs/src/client/common/common.h"
#include "curvefs/src/client/error_code.h"
#include "curvefs/src/client/fuse_s3_client.h"
#include "curvefs/src/client/fuse_volume_client.h"
#include "curvefs/src/common/define.h"
Expand Down Expand Up @@ -66,6 +68,7 @@ using rpcclient::MockMetaServerClient;
using rpcclient::MetaServerClientDone;
using ::curvefs::volume::MockBlockDeviceClient;
using ::curvefs::volume::MockSpaceManager;
using ::curvefs::client::common::FileHandle;

#define EQUAL(a) (lhs.a() == rhs.a())

Expand Down Expand Up @@ -1301,6 +1304,13 @@ TEST_F(TestFuseVolumeClient, FuseOpGetAttrEnableCto) {

ASSERT_EQ(CURVEFS_ERROR::INTERNAL,
client_->FuseOpGetAttr(req, ino, &fi, &attr));

// need not refresh inode
fi.fh = static_cast<uint64_t>(FileHandle::kKeepCache);
EXPECT_CALL(*inodeManager_, GetInodeAttr(ino, _))
.WillOnce(DoAll(SetArgPointee<1>(inode), Return(CURVEFS_ERROR::OK)));

ASSERT_EQ(CURVEFS_ERROR::OK, client_->FuseOpGetAttr(req, ino, &fi, &attr));
}

TEST_F(TestFuseVolumeClient, FuseOpSetAttr) {
Expand Down

0 comments on commit 1203c60

Please sign in to comment.