2323
2424#include " curvefs/src/client/curve_fuse_op.h"
2525
26+ #include < fmt/format.h>
27+
2628#include < cstring>
29+ #include < functional>
2730#include < memory>
2831#include < string>
2932#include < unordered_map>
@@ -66,6 +69,7 @@ using ::curvefs::client::common::WarmupStorageType;
6669using ::curvefs::client::filesystem::AttrOut;
6770using ::curvefs::client::filesystem::EntryOut;
6871using ::curvefs::client::filesystem::FileOut;
72+ using ::curvefs::client::filesystem::IsCheckXAttr;
6973using ::curvefs::client::filesystem::IsListWarmupXAttr;
7074using ::curvefs::client::filesystem::IsWarmupXAttr;
7175using ::curvefs::client::filesystem::StrAttr;
@@ -237,16 +241,18 @@ void UnInitFuseClient() {
237241int AddWarmupTask (curvefs::client::common::WarmupType type, fuse_ino_t key,
238242 const std::string& path,
239243 curvefs::client::common::WarmupStorageType storageType,
240- const std::string& mount_point, const std::string& root) {
244+ const std::string& mount_point, const std::string& root,
245+ bool check = false ) {
241246 int ret = 0 ;
242247 bool result = true ;
243248 switch (type) {
244249 case curvefs::client::common::WarmupType::kWarmupTypeList :
245- result = g_ClientInstance->PutWarmFilelistTask (key, storageType, path,
246- mount_point, root);
247- break ;
250+ result = g_ClientInstance->PutWarmFilelistTask (
251+ key, storageType, path, mount_point, root, check );
252+ break ;
248253 case curvefs::client::common::WarmupType::kWarmupTypeSingle :
249- result = g_ClientInstance->PutWarmFileTask (key, path, storageType);
254+ result =
255+ g_ClientInstance->PutWarmFileTask (key, path, storageType, check);
250256 break ;
251257 default :
252258 // not support add warmup type (warmup single file/dir or filelist)
@@ -291,6 +297,18 @@ void QueryWarmupTask(fuse_ino_t key, std::string *data) {
291297 VLOG (9 ) << " Warmup [" << key << " ]" << *data;
292298}
293299
300+ void QueryCheckCachedTask (fuse_ino_t key, std::string* data) {
301+ WarmupProgress progress;
302+ bool ret = g_ClientInstance->GetCheckCachedProgress (key, &progress);
303+ if (!ret) {
304+ *data = " no check task or not warmup yet" ;
305+ } else {
306+ *data =
307+ fmt::format (" {}/{}" , progress.GetFinished (), progress.GetTotal ());
308+ }
309+ VLOG (9 ) << " check cached [" << key << " ]" << *data;
310+ }
311+
294312void ListWarmupTasks (std::string* data) {
295313 WarmupProgress progress;
296314 std::unordered_map<std::string, WarmupProgress> filepath2progress;
@@ -344,9 +362,15 @@ int Warmup(fuse_ino_t key, const char* name, const std::string& values) {
344362 }
345363
346364 int ret = 0 ;
365+ bool check = false ;
366+ if (curvefs::client::common::GetWarmupOpType (warmupOpType) ==
367+ curvefs::client::common::WarmupOpType::kWarmupOpCheck ) {
368+ check = true ;
369+ }
347370
348371 switch (curvefs::client::common::GetWarmupOpType (warmupOpType)) {
349- case curvefs::client::common::WarmupOpType::kWarmupOpAdd : {
372+ case curvefs::client::common::WarmupOpType::kWarmupOpCheck :
373+ case curvefs::client::common::WarmupOpType::kWarmupOpAdd : {
350374 if (opTypePath.size () !=
351375 curvefs::client::common::kWarmupAddArgsNum ) {
352376 LOG (ERROR)
@@ -373,7 +397,7 @@ int Warmup(fuse_ino_t key, const char* name, const std::string& values) {
373397 ret = AddWarmupTask (
374398 curvefs::client::common::GetWarmupType (warmupDataType), key,
375399 entryFilePathInClient, storageType, mountPointInCurvefs,
376- rootPathInCurvefs);
400+ rootPathInCurvefs, check );
377401 break ;
378402 }
379403 case curvefs::client::common::WarmupOpType::kWarmupOpCancel : {
@@ -446,6 +470,17 @@ void QueryWarmup(fuse_req_t req, fuse_ino_t ino, size_t size) {
446470 return fs->ReplyBuffer (req, data.data (), data.length ());
447471}
448472
473+ void QueryCheckCached (fuse_req_t req, fuse_ino_t ino, size_t size) {
474+ auto fs = Client ()->GetFileSystem ();
475+
476+ std::string data;
477+ QueryCheckCachedTask (ino, &data);
478+ if (size == 0 ) {
479+ return fs->ReplyXattr (req, data.length ());
480+ }
481+ return fs->ReplyBuffer (req, data.data (), data.length ());
482+ }
483+
449484void ListWarmup (fuse_req_t req, size_t size) {
450485 auto fs = Client ()->GetFileSystem ();
451486
@@ -944,6 +979,8 @@ void FuseOpGetXattr(fuse_req_t req,
944979 return ListWarmup (req, size);
945980 } else if (IsWarmupXAttr (name)) {
946981 return QueryWarmup (req, ino, size);
982+ } else if (IsCheckXAttr (name)) {
983+ return QueryCheckCached (req, ino, size);
947984 }
948985
949986 rc = Client ()->FuseOpGetXattr (req, ino, name, &value, size);
0 commit comments