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

curvefs/client: rm create fs in init #905

Merged
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
11 changes: 2 additions & 9 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,8 @@ CURVEFS_ERROR FuseClient::FuseOpInit(void *userdata,
FSStatusCode ret = mdsClient_->GetFsInfo(fsName, &fsInfo);
if (ret != FSStatusCode::OK) {
if (FSStatusCode::NOT_FOUND == ret) {
LOG(INFO) << "The fsName not exist, try to CreateFs"
<< ", fsName = " << fsName;

CURVEFS_ERROR ret2 = CreateFs(userdata, &fsInfo);
if (ret2 != CURVEFS_ERROR::OK) {
LOG(ERROR) << "CreateFs failed, ret = " << ret2
<< ", fsName = " << fsName;
return ret2;
}
LOG(ERROR) << "The fsName not exist, fsName = " << fsName;
return CURVEFS_ERROR::NOTEXIST;
} else {
LOG(ERROR) << "GetFsInfo failed, FSStatusCode = " << ret
<< ", FSStatusCode_Name = "
Expand Down
7 changes: 7 additions & 0 deletions curvefs/src/tools/create/curvefs_create_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,16 @@ int CreateFsTool::Init() {
}

AddRequest(request);

SetController();

return ret;
}

void CreateFsTool::SetController() {
controller_->set_timeout_ms(FLAGS_rpcTimeoutMs);
}

bool CreateFsTool::AfterSendRequestToHost(const std::string& host) {
bool ret = true;
if (controller_->Failed()) {
Expand Down
1 change: 1 addition & 0 deletions curvefs/src/tools/create/curvefs_create_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class CreateFsTool : public CurvefsToolRpc<curvefs::mds::CreateFsRequest,
protected:
void AddUpdateFlags() override;
bool AfterSendRequestToHost(const std::string& host) override;
void SetController() override;
};

} // namespace create
Expand Down
1 change: 1 addition & 0 deletions curvefs/src/tools/curvefs_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class CurvefsToolRpc : public CurvefsTool {
return true;
}
controller_->Reset();
SetController();
}
// send request to all host failed
return false;
Expand Down
32 changes: 2 additions & 30 deletions curvefs/test/client/test_fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,29 +188,12 @@ TEST_F(TestFuseVolumeClient, FuseOpInit_when_fs_not_exist) {
EXPECT_CALL(*mdsClient_, GetFsInfo(fsName, _))
.WillOnce(Return(FSStatusCode::NOT_FOUND));

EXPECT_CALL(*blockDeviceClient_, Stat(volName, user, _))
.WillOnce(Return(CURVEFS_ERROR::OK));

EXPECT_CALL(*mdsClient_, CreateFs(_, _, _))
.WillOnce(Return(FSStatusCode::OK));

FsInfo fsInfoExp;
fsInfoExp.set_fsid(100);
fsInfoExp.set_fsname(fsName);
EXPECT_CALL(*mdsClient_, MountFs(fsName, _, _))
.WillOnce(DoAll(SetArgPointee<2>(fsInfoExp), Return(FSStatusCode::OK)));

EXPECT_CALL(*blockDeviceClient_, Open(volName, user))
.WillOnce(Return(CURVEFS_ERROR::OK));

CURVEFS_ERROR ret = client_->FuseOpInit(&mOpts, nullptr);
ASSERT_EQ(CURVEFS_ERROR::OK, ret);

auto fsInfo = client_->GetFsInfo();
ASSERT_NE(fsInfo, nullptr);

ASSERT_EQ(fsInfo->fsid(), fsInfoExp.fsid());
ASSERT_EQ(fsInfo->fsname(), fsInfoExp.fsname());
ASSERT_EQ(CURVEFS_ERROR::NOTEXIST, ret);
}

TEST_F(TestFuseVolumeClient, FuseOpDestroy) {
Expand Down Expand Up @@ -1768,23 +1751,12 @@ TEST_F(TestFuseS3Client, FuseOpInit_when_fs_not_exist) {
EXPECT_CALL(*mdsClient_, GetFsInfo(fsName, _))
.WillOnce(Return(FSStatusCode::NOT_FOUND));

EXPECT_CALL(*mdsClient_, CreateFsS3(_, _, _))
.WillOnce(Return(FSStatusCode::OK));

FsInfo fsInfoExp;
fsInfoExp.set_fsid(100);
fsInfoExp.set_fsname(fsName);
EXPECT_CALL(*mdsClient_, MountFs(fsName, _, _))
.WillOnce(DoAll(SetArgPointee<2>(fsInfoExp), Return(FSStatusCode::OK)));

CURVEFS_ERROR ret = client_->FuseOpInit(&mOpts, nullptr);
ASSERT_EQ(CURVEFS_ERROR::OK, ret);

auto fsInfo = client_->GetFsInfo();
ASSERT_NE(fsInfo, nullptr);

ASSERT_EQ(fsInfo->fsid(), fsInfoExp.fsid());
ASSERT_EQ(fsInfo->fsname(), fsInfoExp.fsname());
ASSERT_EQ(CURVEFS_ERROR::NOTEXIST, ret);
}

TEST_F(TestFuseS3Client, FuseOpDestroy) {
Expand Down