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>
@@ -65,6 +68,7 @@ using ::curvefs::client::common::WarmupStorageType;
6568using ::curvefs::client::filesystem::AttrOut;
6669using ::curvefs::client::filesystem::EntryOut;
6770using ::curvefs::client::filesystem::FileOut;
71+ using ::curvefs::client::filesystem::IsCheckXAttr;
6872using ::curvefs::client::filesystem::IsListWarmupXAttr;
6973using ::curvefs::client::filesystem::IsWarmupXAttr;
7074using ::curvefs::client::filesystem::StrAttr;
@@ -235,16 +239,18 @@ void UnInitFuseClient() {
235239int AddWarmupTask (curvefs::client::common::WarmupType type, fuse_ino_t key,
236240 const std::string& path,
237241 curvefs::client::common::WarmupStorageType storageType,
238- const std::string& mount_point, const std::string& root) {
242+ const std::string& mount_point, const std::string& root,
243+ bool check = false ) {
239244 int ret = 0 ;
240245 bool result = true ;
241246 switch (type) {
242247 case curvefs::client::common::WarmupType::kWarmupTypeList :
243- result = g_ClientInstance->PutWarmFilelistTask (key, storageType, path,
244- mount_point, root);
245- break ;
248+ result = g_ClientInstance->PutWarmFilelistTask (
249+ key, storageType, path, mount_point, root, check );
250+ break ;
246251 case curvefs::client::common::WarmupType::kWarmupTypeSingle :
247- result = g_ClientInstance->PutWarmFileTask (key, path, storageType);
252+ result =
253+ g_ClientInstance->PutWarmFileTask (key, path, storageType, check);
248254 break ;
249255 default :
250256 // not support add warmup type (warmup single file/dir or filelist)
@@ -289,6 +295,18 @@ void QueryWarmupTask(fuse_ino_t key, std::string *data) {
289295 VLOG (9 ) << " Warmup [" << key << " ]" << *data;
290296}
291297
298+ void QueryCheckCachedTask (fuse_ino_t key, std::string* data) {
299+ WarmupProgress progress;
300+ bool ret = g_ClientInstance->GetCheckCachedProgress (key, &progress);
301+ if (!ret) {
302+ *data = " no check task or not warmup yet" ;
303+ } else {
304+ *data =
305+ fmt::format (" {}/{}" , progress.GetFinished (), progress.GetTotal ());
306+ }
307+ VLOG (9 ) << " check cached [" << key << " ]" << *data;
308+ }
309+
292310void ListWarmupTasks (std::string* data) {
293311 WarmupProgress progress;
294312 std::unordered_map<std::string, WarmupProgress> filepath2progress;
@@ -342,9 +360,15 @@ int Warmup(fuse_ino_t key, const char* name, const std::string& values) {
342360 }
343361
344362 int ret = 0 ;
363+ bool check = false ;
364+ if (curvefs::client::common::GetWarmupOpType (warmupOpType) ==
365+ curvefs::client::common::WarmupOpType::kWarmupOpCheck ) {
366+ check = true ;
367+ }
345368
346369 switch (curvefs::client::common::GetWarmupOpType (warmupOpType)) {
347- case curvefs::client::common::WarmupOpType::kWarmupOpAdd : {
370+ case curvefs::client::common::WarmupOpType::kWarmupOpCheck :
371+ case curvefs::client::common::WarmupOpType::kWarmupOpAdd : {
348372 if (opTypePath.size () !=
349373 curvefs::client::common::kWarmupAddArgsNum ) {
350374 LOG (ERROR)
@@ -371,7 +395,7 @@ int Warmup(fuse_ino_t key, const char* name, const std::string& values) {
371395 ret = AddWarmupTask (
372396 curvefs::client::common::GetWarmupType (warmupDataType), key,
373397 entryFilePathInClient, storageType, mountPointInCurvefs,
374- rootPathInCurvefs);
398+ rootPathInCurvefs, check );
375399 break ;
376400 }
377401 case curvefs::client::common::WarmupOpType::kWarmupOpCancel : {
@@ -444,6 +468,17 @@ void QueryWarmup(fuse_req_t req, fuse_ino_t ino, size_t size) {
444468 return fs->ReplyBuffer (req, data.data (), data.length ());
445469}
446470
471+ void QueryCheckCached (fuse_req_t req, fuse_ino_t ino, size_t size) {
472+ auto fs = Client ()->GetFileSystem ();
473+
474+ std::string data;
475+ QueryCheckCachedTask (ino, &data);
476+ if (size == 0 ) {
477+ return fs->ReplyXattr (req, data.length ());
478+ }
479+ return fs->ReplyBuffer (req, data.data (), data.length ());
480+ }
481+
447482void ListWarmup (fuse_req_t req, size_t size) {
448483 auto fs = Client ()->GetFileSystem ();
449484
@@ -942,6 +977,8 @@ void FuseOpGetXattr(fuse_req_t req,
942977 return ListWarmup (req, size);
943978 } else if (IsWarmupXAttr (name)) {
944979 return QueryWarmup (req, ino, size);
980+ } else if (IsCheckXAttr (name)) {
981+ return QueryCheckCached (req, ino, size);
945982 }
946983
947984 rc = Client ()->FuseOpGetXattr (req, ino, name, &value, size);
0 commit comments