@@ -287,6 +287,15 @@ Transport *TransferEngine::installTransport(const std::string &proto,
287287 entry.addr , entry.length , entry.location , entry.remote_accessible );
288288 if (ret < 0 ) return nullptr ;
289289 }
290+
291+ if (transport->supportFileBuffer ()) {
292+ for (auto &file : local_files_) {
293+ int ret = transport->registerLocalFile (
294+ file.second .id , file.second .path , file.second .size );
295+ if (ret < 0 ) return nullptr ;
296+ }
297+ }
298+
290299 return transport;
291300}
292301
@@ -436,6 +445,77 @@ int TransferEngine::unregisterLocalMemoryBatch(
436445 return 0 ;
437446}
438447
448+ bool TransferEngine::supportFileBuffer () {
449+ bool supported = false ;
450+ for (auto &transport : multi_transports_->listTransports ()) {
451+ supported = supported || transport->supportFileBuffer ();
452+ }
453+ return supported;
454+ }
455+
456+ int TransferEngine::registerLocalFile (const std::string &path, size_t size,
457+ FileBufferID &id) {
458+ if (!supportFileBuffer ()) {
459+ LOG (ERROR) << " File buffers not suppotred" ;
460+ return ERR_NOT_IMPLEMENTED;
461+ }
462+
463+ std::unique_lock<std::shared_mutex> lock (mutex_);
464+ if (local_files_.count (path) > 0 ) {
465+ LOG (ERROR) << " Registering an already registered file: " << path;
466+ return ERR_ADDRESS_OVERLAPPED;
467+ }
468+
469+ const auto id_ = next_file_id_.fetch_add (1 );
470+
471+ for (auto &transport : multi_transports_->listTransports ()) {
472+ if (!transport->supportFileBuffer ()) {
473+ continue ;
474+ }
475+
476+ int ret = transport->registerLocalFile (id_, path, size);
477+ if (ret != 0 ) {
478+ LOG (ERROR) << " Failed to register file " << path << " to transport "
479+ << transport->getName () << " , ret=" << ret;
480+ return ret;
481+ }
482+ }
483+
484+ local_files_[path] = {id_, path, size};
485+ id = id_;
486+ return 0 ;
487+ }
488+
489+ int TransferEngine::unregisterLocalFile (const std::string &path) {
490+ if (!supportFileBuffer ()) {
491+ LOG (ERROR) << " File buffers not suppotred" ;
492+ return ERR_NOT_IMPLEMENTED;
493+ }
494+
495+ std::unique_lock<std::shared_mutex> lock (mutex_);
496+ auto it = local_files_.find (path);
497+ if (it == local_files_.end ()) {
498+ return ERR_ADDRESS_NOT_REGISTERED;
499+ }
500+
501+ for (auto &transport : multi_transports_->listTransports ()) {
502+ if (!transport->supportFileBuffer ()) {
503+ continue ;
504+ }
505+
506+ int ret = transport->unregisterLocalFile (it->second .id );
507+ if (ret != 0 && ret != ERR_ADDRESS_NOT_REGISTERED) {
508+ LOG (ERROR) << " Failed to unregister file " << path
509+ << " from transport " << transport->getName ()
510+ << " , ret=" << ret;
511+ return ret;
512+ }
513+ }
514+
515+ local_files_.erase (it);
516+ return 0 ;
517+ }
518+
439519#ifdef WITH_METRICS
440520// Helper function to convert string to lowercase for case-insensitive
441521// comparison
0 commit comments