diff --git a/curvefs/src/client/common/common.h b/curvefs/src/client/common/common.h index b8b6cf9d7d..08d983f8dd 100644 --- a/curvefs/src/client/common/common.h +++ b/curvefs/src/client/common/common.h @@ -71,7 +71,7 @@ const uint32_t MAX_XATTR_VALUE_LENGTH = 64 * 1024; const char kCurveFsWarmupXAttr[] = "curvefs.warmup.op"; -constexpr int kWarmupOpNum = 4; +constexpr int kWarmupOpNum = 6; enum class WarmupOpType { kWarmupOpUnknown = 0, diff --git a/curvefs/src/client/curve_fuse_op.cpp b/curvefs/src/client/curve_fuse_op.cpp index 47d54cc3b1..6753b53bf1 100644 --- a/curvefs/src/client/curve_fuse_op.cpp +++ b/curvefs/src/client/curve_fuse_op.cpp @@ -221,13 +221,15 @@ void UnInitFuseClient() { } int AddWarmupTask(curvefs::client::common::WarmupType type, fuse_ino_t key, - const std::string &path, - curvefs::client::common::WarmupStorageType storageType) { + const std::string& path, + curvefs::client::common::WarmupStorageType storageType, + const std::string& mount_point, const std::string& root) { int ret = 0; bool result = true; switch (type) { case curvefs::client::common::WarmupType::kWarmupTypeList: - result = g_ClientInstance->PutWarmFilelistTask(key, storageType); + result = g_ClientInstance->PutWarmFilelistTask(key, storageType, + mount_point, root); break; case curvefs::client::common::WarmupType::kWarmupTypeSingle: result = g_ClientInstance->PutWarmFileTask(key, path, storageType); @@ -256,6 +258,15 @@ void QueryWarmupTask(fuse_ino_t key, std::string *data) { } int Warmup(fuse_ino_t key, const std::string& name, const std::string& value) { + /* + * value[0]: WarmupOpType: add, single + * value[1]: WarmupType: single, list + * value[2]: CurvefsPath + * value[3]: StorageType + * value[4]: MountPoint + * value[5]: Root + */ + // warmup if (g_ClientInstance->GetFsInfo()->fstype() != FSType::TYPE_S3) { LOG(ERROR) << "warmup only support s3"; @@ -278,9 +289,9 @@ int Warmup(fuse_ino_t key, const std::string& name, const std::string& value) { int ret = 0; switch (curvefs::client::common::GetWarmupOpType(opTypePath[0])) { case curvefs::client::common::WarmupOpType::kWarmupOpAdd: - ret = - AddWarmupTask(curvefs::client::common::GetWarmupType(opTypePath[1]), - key, opTypePath[2], storageType); + ret = AddWarmupTask( + curvefs::client::common::GetWarmupType(opTypePath[1]), key, + opTypePath[2], storageType, opTypePath[4], opTypePath[5]); if (ret != 0) { LOG(ERROR) << name << " has invalid xattr value " << value; } diff --git a/curvefs/src/client/fuse_client.h b/curvefs/src/client/fuse_client.h index 3988b77866..65fd0a42e0 100644 --- a/curvefs/src/client/fuse_client.h +++ b/curvefs/src/client/fuse_client.h @@ -305,9 +305,11 @@ class FuseClient { enableSumInDir_ = enable; } - bool PutWarmFilelistTask(fuse_ino_t key, common::WarmupStorageType type) { + bool PutWarmFilelistTask(fuse_ino_t key, common::WarmupStorageType type, + std::string &mount_point, std::string &root) { if (fsInfo_->fstype() == FSType::TYPE_S3) { - return warmupManager_->AddWarmupFilelist(key, type); + return warmupManager_->AddWarmupFilelist(key, type, mount_point, + root); } // only support s3 return true; } diff --git a/curvefs/src/client/warmup/warmup_manager.cpp b/curvefs/src/client/warmup/warmup_manager.cpp index e135231ab0..2a7af9083a 100644 --- a/curvefs/src/client/warmup/warmup_manager.cpp +++ b/curvefs/src/client/warmup/warmup_manager.cpp @@ -50,7 +50,9 @@ using curve::common::WriteLockGuard; #define WARMUP_CHECKINTERVAL_US (1000 * 1000) bool WarmupManagerS3Impl::AddWarmupFilelist(fuse_ino_t key, - WarmupStorageType type) { + WarmupStorageType type, + const std::string& mount_point, + const std::string& root) { if (!mounted_.load(std::memory_order_acquire)) { LOG(ERROR) << "not mounted"; return false; @@ -69,7 +71,7 @@ bool WarmupManagerS3Impl::AddWarmupFilelist(fuse_ino_t key, return false; } uint64_t len = inodeWrapper->GetLength(); - warmupFilelistDeque_.emplace_back(key, len); + warmupFilelistDeque_.emplace_back(key, len, mount_point, root); } } // Skip already added return true; @@ -628,11 +630,20 @@ void WarmupManagerS3Impl::ScanWarmupFilelist() { if (!warmupFilelistDeque_.empty()) { WarmupFilelist warmupFilelist = warmupFilelistDeque_.front(); VLOG(9) << "warmup ino: " << warmupFilelist.GetKey() - << " len is: " << warmupFilelist.GetFileLen(); + << " len is: " << warmupFilelist.GetFileLen() + << " mount point is: " << warmupFilelist.GetMountPoint() + << " fs root is: " << warmupFilelist.GetRoot(); std::vector warmuplist; GetWarmupList(warmupFilelist, &warmuplist); + std::string filePathInFs; for (auto filePath : warmuplist) { + size_t found = filePath.find(warmupFilelist.GetMountPoint()); + + if (found != std::string::npos) { + filePath.replace(found, 1, warmupFilelist.GetRoot()); + } + FetchDentryEnqueue(warmupFilelist.GetKey(), filePath); } warmupFilelistDeque_.pop_front(); diff --git a/curvefs/src/client/warmup/warmup_manager.h b/curvefs/src/client/warmup/warmup_manager.h index afdd28b047..4e81fd94d2 100644 --- a/curvefs/src/client/warmup/warmup_manager.h +++ b/curvefs/src/client/warmup/warmup_manager.h @@ -66,11 +66,14 @@ using curvefs::client::common::WarmupStorageType; class WarmupFile { public: - explicit WarmupFile(fuse_ino_t key = 0, uint64_t fileLen = 0) - : key_(key), fileLen_(fileLen) {} + explicit WarmupFile(fuse_ino_t key = 0, uint64_t fileLen = 0, + const std::string& mountPoint, const std::string& root) + : key_(key), fileLen_(fileLen), mountPoint_(mountPoint), root_(root) {} fuse_ino_t GetKey() const { return key_; } uint64_t GetFileLen() const { return fileLen_; } + std::string GetMountPoint() const { return mountPoint_; } + std::string GetRoot() const { return root_; } bool operator==(const WarmupFile &other) const { return key_ == other.key_; } @@ -78,6 +81,8 @@ class WarmupFile { private: fuse_ino_t key_; uint64_t fileLen_; + std::string mountPoint_; + std::string root_; }; using WarmupFilelist = WarmupFile; @@ -183,12 +188,12 @@ class WarmupManager { fuseOpRead_(std::move(readFunc)), kvClientManager_(std::move(kvClientManager)) {} - virtual void Init(const FuseClientOption &option) { - option_ = option; - } + virtual void Init(const FuseClientOption &option) { option_ = option; } virtual void UnInit() { ClearWarmupProcess(); } - virtual bool AddWarmupFilelist(fuse_ino_t key, WarmupStorageType type) = 0; + virtual bool AddWarmupFilelist(fuse_ino_t key, WarmupStorageType type, + const std::string& mount_point, + const std::string& root) = 0; virtual bool AddWarmupFile(fuse_ino_t key, const std::string &path, WarmupStorageType type) = 0; @@ -298,7 +303,9 @@ class WarmupManagerS3Impl : public WarmupManager { std::move(readFunc), std::move(kvClientManager)), s3Adaptor_(std::move(s3Adaptor)) {} - bool AddWarmupFilelist(fuse_ino_t key, WarmupStorageType type) override; + bool AddWarmupFilelist(fuse_ino_t key, WarmupStorageType type, + const std::string& mount_point, + const std::string& root) override; bool AddWarmupFile(fuse_ino_t key, const std::string &path, WarmupStorageType type) override; diff --git a/curvefs/test/client/test_fuse_s3_client.cpp b/curvefs/test/client/test_fuse_s3_client.cpp index aeb641badb..a735708a39 100644 --- a/curvefs/test/client/test_fuse_s3_client.cpp +++ b/curvefs/test/client/test_fuse_s3_client.cpp @@ -266,7 +266,7 @@ TEST_F(TestFuseS3Client, warmUp_inodeBadFd) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); LOG(INFO) << "ret:" << ret << " Warmup progress: " << progress.ToString(); @@ -323,7 +323,7 @@ TEST_F(TestFuseS3Client, warmUp_Warmfile_error_GetDentry01) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); @@ -381,7 +381,7 @@ TEST_F(TestFuseS3Client, warmUp_Warmfile_error_GetDentry02) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); @@ -439,7 +439,7 @@ TEST_F(TestFuseS3Client, warmUp_fetchDataEnqueue__error_getinode) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); @@ -497,7 +497,7 @@ TEST_F(TestFuseS3Client, warmUp_fetchDataEnqueue_chunkempty) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); @@ -560,7 +560,7 @@ TEST_F(TestFuseS3Client, warmUp_FetchDentry_TYPE_SYM_LINK) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); @@ -625,7 +625,7 @@ TEST_F(TestFuseS3Client, warmUp_FetchDentry_error_TYPE_DIRECTORY) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); @@ -689,7 +689,7 @@ TEST_F(TestFuseS3Client, warmUp_lookpath_multilevel) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); @@ -740,7 +740,7 @@ TEST_F(TestFuseS3Client, warmUp_lookpath_unkown) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); @@ -797,7 +797,7 @@ TEST_F(TestFuseS3Client, warmUp_FetchChildDentry_error_ListDentry) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); @@ -885,7 +885,7 @@ TEST_F(TestFuseS3Client, warmUp_FetchChildDentry_suc_ListDentry) { client_->GetFsInfo()->set_fstype(FSType::TYPE_S3); client_->PutWarmFilelistTask( inodeid, - curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk); + curvefs::client::common::WarmupStorageType::kWarmupStorageTypeDisk, "", ""); warmup::WarmupProgress progress; bool ret = client_->GetWarmupProgress(inodeid, &progress); diff --git a/tools-v2/pkg/cli/command/curvefs/warmup/add/add.go b/tools-v2/pkg/cli/command/curvefs/warmup/add/add.go index 539d839a13..2701898d50 100644 --- a/tools-v2/pkg/cli/command/curvefs/warmup/add/add.go +++ b/tools-v2/pkg/cli/command/curvefs/warmup/add/add.go @@ -161,7 +161,7 @@ func (aCmd *AddCommand) Print(cmd *cobra.Command, args []string) error { return output.FinalCmdOutput(&aCmd.FinalCurveCmd, aCmd) } -func (aCmd *AddCommand) convertFilelist() *cmderror.CmdError { +func (aCmd *AddCommand) verifyFilelist() *cmderror.CmdError { data, err := ioutil.ReadFile(aCmd.Path) if err != nil { readErr := cmderror.ErrReadFile() @@ -170,36 +170,31 @@ func (aCmd *AddCommand) convertFilelist() *cmderror.CmdError { } lines := strings.Split(string(data), "\n") - validPath := "" + for _, line := range lines { rel, err := filepath.Rel(aCmd.Mountpoint.MountPoint, line) - if err == nil && !strings.HasPrefix(rel, "..") { - // convert to curvefs path - curvefsAbspath := cobrautil.Path2CurvefsPath(line, aCmd.Mountpoint) - validPath += (curvefsAbspath + "\n") - } else { - convertFail := fmt.Sprintf("[%s] is not saved in curvefs", line) - aCmd.ConvertFails = append(aCmd.ConvertFails, convertFail) + if err != nil || strings.HasPrefix(rel, "..") { + convertFailMsg := fmt.Sprintf("[%s:%s] is not saved in curvefs", aCmd.Path, line) + convertErr = cmderror.ErrConverResult() + convertErr.Format(convertFailMsg, err.Error()) + return ErrConverResult } } - if err = ioutil.WriteFile(aCmd.Path, []byte(validPath), 0644); err != nil { - writeErr := cmderror.ErrWriteFile() - writeErr.Format(aCmd.Path, err.Error()) - } + return cmderror.ErrSuccess() } func (aCmd *AddCommand) RunCommand(cmd *cobra.Command, args []string) error { xattr := CURVEFS_WARMUP_OP_ADD_SINGLE if !aCmd.Single { - convertErr := aCmd.convertFilelist() + convertErr := aCmd.verifyFilelist() if convertErr.TypeCode() != cmderror.CODE_SUCCESS { return convertErr.ToError() } xattr = CURVEFS_WARMUP_OP_ADD_LIST } - value := fmt.Sprintf(xattr, aCmd.CurvefsPath, aCmd.StorageType) - err := unix.Setxattr(aCmd.Path, CURVEFS_WARMUP_OP_XATTR, []byte(value), 0) + values := fmt.Sprintf(xattr, aCmd.CurvefsPath, aCmd.StorageType, aCmd.Mountpoint.MountPoint, aCmd.Mountpoint.Root) + err := unix.Setxattr(aCmd.Path, CURVEFS_WARMUP_OP_XATTR, []byte(values), 0) if err == unix.ENOTSUP || err == unix.EOPNOTSUPP { return fmt.Errorf("filesystem does not support extended attributes") } else if err != nil {