Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: MizukiCry <[email protected]>
  • Loading branch information
MizukiCry committed Apr 10, 2023
1 parent 2fd0cf9 commit 69b3273
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 65 deletions.
21 changes: 13 additions & 8 deletions curvefs/src/client/curve_fuse_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,30 @@ int InitGlog(const char *confPath, const char *argv0) {
return 0;
}

int InitFuseClient(const char *confPath, const char* fsName,
const char *fsType, const char *mdsAddr) {
int InitFuseClient(const struct MountOption *mountOption) {
g_clientOpMetric = new ClientOpMetric();

Configuration conf;
conf.SetConfigPath(confPath);
conf.SetConfigPath(mountOption->conf);
if (!conf.LoadConfig()) {
LOG(ERROR) << "LoadConfig failed, confPath = " << confPath;
LOG(ERROR) << "LoadConfig failed, confPath = " << mountOption->conf;
return -1;
}
if (mdsAddr)
conf.SetStringValue("mdsOpt.rpcRetryOpt.addrs", mdsAddr);
if (mountOption->mdsAddr)
conf.SetStringValue("mdsOpt.rpcRetryOpt.addrs", mountOption->mdsAddr);

conf.PrintConfig();

g_fuseClientOption = new FuseClientOption();
curvefs::client::common::InitFuseClientOption(&conf, g_fuseClientOption);

std::shared_ptr<FsInfo> fsInfo = std::make_shared<FsInfo>();
if (GetFsInfo(fsName, fsInfo.get()) != 0) {
if (GetFsInfo(mountOption->fsName, fsInfo.get()) != 0) {
return -1;
}

std::string fsTypeStr = (fsType == nullptr) ? "" : fsType;
std::string fsTypeStr =
(mountOption->fsType == nullptr) ? "" : mountOption->fsType;
std::string fsTypeMds;
if (fsInfo->fstype() == FSType::TYPE_S3) {
fsTypeMds = "s3";
Expand Down Expand Up @@ -187,6 +187,11 @@ int InitFuseClient(const char *confPath, const char* fsName,
return -1;
}

ret = g_ClientInstance->SetMountStatus(mountOption);
if (ret != CURVEFS_ERROR::OK) {
return -1;
}

return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions curvefs/src/client/curve_fuse_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ extern "C" {

int InitGlog(const char *confPath, const char *argv0);

int InitFuseClient(const char *confPath, const char *fsName,
const char* fsType, const char* mdsAddr);
int InitFuseClient(const struct MountOption *mountOption);

void UnInitFuseClient();

Expand Down
99 changes: 52 additions & 47 deletions curvefs/src/client/fuse_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,54 +174,8 @@ void FuseClient::Fini() {

CURVEFS_ERROR FuseClient::FuseOpInit(void *userdata,
struct fuse_conn_info *conn) {
(void)userdata;
(void)conn;
struct MountOption* mOpts = (struct MountOption*)userdata;
// set path
mountpoint_.set_path((mOpts->mountPoint == nullptr) ? ""
: mOpts->mountPoint);
std::string fsName = (mOpts->fsName == nullptr) ? "" : mOpts->fsName;

mountpoint_.set_cto(FLAGS_enableCto);

int retVal = SetHostPortInMountPoint(&mountpoint_);
if (retVal < 0) {
LOG(ERROR) << "Set Host and Port in MountPoint failed, ret = "
<< retVal;
return CURVEFS_ERROR::INTERNAL;
}

auto ret = mdsClient_->MountFs(fsName, mountpoint_, fsInfo_.get());
if (ret != FSStatusCode::OK && ret != FSStatusCode::MOUNT_POINT_EXIST) {
LOG(ERROR) << "MountFs failed, FSStatusCode = " << ret
<< ", FSStatusCode_Name = "
<< FSStatusCode_Name(ret)
<< ", fsName = " << fsName
<< ", mountPoint = " << mountpoint_.ShortDebugString();
return CURVEFS_ERROR::MOUNT_FAILED;
}
inodeManager_->SetFsId(fsInfo_->fsid());
dentryManager_->SetFsId(fsInfo_->fsid());
enableSumInDir_ = fsInfo_->enablesumindir() && !FLAGS_enableCto;
if (fsInfo_->has_recycletimehour()) {
enableSumInDir_ = enableSumInDir_ && (fsInfo_->recycletimehour() == 0);
}

LOG(INFO) << "Mount " << fsName << " on " << mountpoint_.ShortDebugString()
<< " success!" << " enableSumInDir = " << enableSumInDir_;

fsMetric_ = std::make_shared<FSMetric>(fsName);

// init fsname and mountpoint
leaseExecutor_->SetFsName(fsName);
leaseExecutor_->SetMountPoint(mountpoint_);
if (!leaseExecutor_->Start()) {
return CURVEFS_ERROR::INTERNAL;
}

init_ = true;
if (warmupManager_ != nullptr) {
warmupManager_->SetMounted(true);
}
return CURVEFS_ERROR::OK;
}

Expand Down Expand Up @@ -1468,5 +1422,56 @@ void FuseClient::FlushAll() {
FlushInodeAll();
}

CURVEFS_ERROR
FuseClient::SetMountStatus(const struct MountOption *mountOption) {
mountpoint_.set_path(
(mountOption->mountPoint == nullptr) ? "" : mountOption->mountPoint);
std::string fsName =
(mountOption->fsName == nullptr) ? "" : mountOption->fsName;

mountpoint_.set_cto(FLAGS_enableCto);

int retVal = SetHostPortInMountPoint(&mountpoint_);
if (retVal < 0) {
LOG(ERROR) << "Set Host and Port in MountPoint failed, ret = "
<< retVal;
return CURVEFS_ERROR::INTERNAL;
}

auto ret = mdsClient_->MountFs(fsName, mountpoint_, fsInfo_.get());
if (ret != FSStatusCode::OK && ret != FSStatusCode::MOUNT_POINT_EXIST) {
LOG(ERROR) << "MountFs failed, FSStatusCode = " << ret
<< ", FSStatusCode_Name = " << FSStatusCode_Name(ret)
<< ", fsName = " << fsName
<< ", mountPoint = " << mountpoint_.ShortDebugString();
return CURVEFS_ERROR::MOUNT_FAILED;
}
inodeManager_->SetFsId(fsInfo_->fsid());
dentryManager_->SetFsId(fsInfo_->fsid());
enableSumInDir_ = fsInfo_->enablesumindir() && !FLAGS_enableCto;
if (fsInfo_->has_recycletimehour()) {
enableSumInDir_ = enableSumInDir_ && (fsInfo_->recycletimehour() == 0);
}

LOG(INFO) << "Mount " << fsName << " on " << mountpoint_.ShortDebugString()
<< " success!"
<< " enableSumInDir = " << enableSumInDir_;

fsMetric_ = std::make_shared<FSMetric>(fsName);

// init fsname and mountpoint
leaseExecutor_->SetFsName(fsName);
leaseExecutor_->SetMountPoint(mountpoint_);
if (!leaseExecutor_->Start()) {
return CURVEFS_ERROR::INTERNAL;
}

init_ = true;
if (warmupManager_ != nullptr) {
warmupManager_->SetMounted(true);
}
return CURVEFS_ERROR::OK;
}

} // namespace client
} // namespace curvefs
2 changes: 2 additions & 0 deletions curvefs/src/client/fuse_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ class FuseClient {
return false;
}

CURVEFS_ERROR SetMountStatus(const struct MountOption *mountOption);

protected:
CURVEFS_ERROR MakeNode(fuse_req_t req, fuse_ino_t parent, const char* name,
mode_t mode, FsFileType type, dev_t rdev,
Expand Down
10 changes: 6 additions & 4 deletions curvefs/src/client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* Author: xuchaojie
*/

#include <glog/logging.h>

#include <string>
#include <unordered_map>

Expand Down Expand Up @@ -224,14 +226,14 @@ int main(int argc, char *argv[]) {
printf("Init glog failed, confpath = %s\n", mOpts.conf);
}

ret = InitFuseClient(mOpts.conf, mOpts.fsName, mOpts.fsType, mOpts.mdsAddr);
ret = InitFuseClient(&mOpts);
if (ret < 0) {
printf("init fuse client fail, conf =%s\n", mOpts.conf);
LOG(ERROR) << "init fuse client fail, conf = " << mOpts.conf;
goto err_out4;
}

printf("fuse start loop, singlethread = %d, max_idle_threads = %d\n",
opts.singlethread, opts.max_idle_threads);
LOG(INFO) << "fuse start loop, singlethread = " << opts.singlethread
<< ", max_idle_threads = " << opts.max_idle_threads;

/* Block until ctrl+c or fusermount -u */
if (opts.singlethread) {
Expand Down
7 changes: 6 additions & 1 deletion curvefs/src/client/s3/disk_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ bool DiskCacheManager::IsCacheClean() {

int DiskCacheManager::UmountDiskCache() {
LOG(INFO) << "umount disk cache.";
diskInitThread_.join();
if (diskInitThread_.joinable()) {
diskInitThread_.join();
}
TrimStop();
cacheWrite_->AsyncUploadStop();
LOG_IF(ERROR, !IsCacheClean()) << "umount disk cache error.";
Expand Down Expand Up @@ -360,6 +362,9 @@ void DiskCacheManager::TrimCache() {
waitIntervalSec_.Init(trimCheckIntervalSec_ * 1000);
// trim will start after get the disk size
while (!IsDiskUsedInited()) {
if (!isRunning_) {
return;
}
waitIntervalSec_.WaitForNextExcution();
}
// 1. check cache disk usage every sleepSec seconds.
Expand Down
4 changes: 2 additions & 2 deletions curvefs/test/client/test_fuse_s3_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ TEST_F(TestFuseS3Client, warmUp_FetchChildDentry_suc_ListDentry) {
ASSERT_FALSE(ret);
}

TEST_F(TestFuseS3Client, FuseOpInit_when_fs_exist) {
TEST_F(TestFuseS3Client, FuseInit_when_fs_exist) {
MountOption mOpts;
memset(&mOpts, 0, sizeof(mOpts));
mOpts.fsName = const_cast<char*>("s3fs");
Expand All @@ -850,7 +850,7 @@ TEST_F(TestFuseS3Client, FuseOpInit_when_fs_exist) {
fsInfoExp.set_fsname(fsName);
EXPECT_CALL(*mdsClient_, MountFs(fsName, _, _))
.WillOnce(DoAll(SetArgPointee<2>(fsInfoExp), Return(FSStatusCode::OK)));
CURVEFS_ERROR ret = client_->FuseOpInit(&mOpts, nullptr);
CURVEFS_ERROR ret = client_->SetMountStatus(&mOpts);
ASSERT_EQ(CURVEFS_ERROR::OK, ret);

auto fsInfo = client_->GetFsInfo();
Expand Down
4 changes: 3 additions & 1 deletion curvefs/test/client/test_fuse_volume_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ TEST_F(TestFuseVolumeClient, FuseOpInit_when_fs_exist) {

EXPECT_CALL(*blockDeviceClient_, Open(_, _))
.WillOnce(Return(true));
CURVEFS_ERROR ret = client_->FuseOpInit(&mOpts, nullptr);
CURVEFS_ERROR ret = client_->SetMountStatus(&mOpts);
ASSERT_EQ(CURVEFS_ERROR::OK, ret);
ret = client_->FuseOpInit(&mOpts, nullptr);
ASSERT_EQ(CURVEFS_ERROR::OK, ret);

auto fsInfo = client_->GetFsInfo();
Expand Down

0 comments on commit 69b3273

Please sign in to comment.