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 committed Sep 2, 2022
1 parent 72a5b19 commit 7932de7
Show file tree
Hide file tree
Showing 4 changed files with 27 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 @@ -82,6 +82,11 @@ enum class WarmupType {

WarmupType GetWarmupType(const std::string& type);

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 @@ -55,6 +55,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 @@ -417,6 +418,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
15 changes: 10 additions & 5 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#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"
Expand All @@ -50,6 +51,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 @@ -964,11 +966,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
9 changes: 9 additions & 0 deletions curvefs/test/client/test_fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.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"
Expand Down Expand Up @@ -68,6 +69,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 @@ -1325,6 +1327,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 7932de7

Please sign in to comment.