shm: throw TransportError if could not lock region

This commit is contained in:
Alexey Rybalchenko 2021-06-10 11:16:56 +02:00
parent 37c059177f
commit a8bdb91165

View File

@ -16,8 +16,8 @@
#define FAIR_MQ_SHMEM_MANAGER_H_ #define FAIR_MQ_SHMEM_MANAGER_H_
#include "Common.h" #include "Common.h"
#include "Region.h"
#include "Monitor.h" #include "Monitor.h"
#include "Region.h"
#include <fairmq/ProgOptions.h> #include <fairmq/ProgOptions.h>
#include <fairmq/tools/Strings.h> #include <fairmq/tools/Strings.h>
@ -34,8 +34,8 @@
#include <boost/process.hpp> #include <boost/process.hpp>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <cstdlib> // getenv
#include <condition_variable> #include <condition_variable>
#include <cstdlib> // getenv
#include <memory> // make_unique #include <memory> // make_unique
#include <mutex> #include <mutex>
#include <set> #include <set>
@ -43,9 +43,9 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <thread> #include <thread>
#include <tuple>
#include <unordered_map> #include <unordered_map>
#include <utility> // pair #include <utility> // pair
#include <tuple>
#include <vector> #include <vector>
#include <unistd.h> // getuid #include <unistd.h> // getuid
@ -194,6 +194,7 @@ class Manager
LOG(debug) << "Locking the managed segment memory pages..."; LOG(debug) << "Locking the managed segment memory pages...";
if (mlock(boost::apply_visitor(SegmentAddress(), fSegments.at(fSegmentId)), boost::apply_visitor(SegmentSize(), fSegments.at(fSegmentId))) == -1) { if (mlock(boost::apply_visitor(SegmentAddress(), fSegments.at(fSegmentId)), boost::apply_visitor(SegmentSize(), fSegments.at(fSegmentId))) == -1) {
LOG(error) << "Could not lock the managed segment memory. Code: " << errno << ", reason: " << strerror(errno); LOG(error) << "Could not lock the managed segment memory. Code: " << errno << ", reason: " << strerror(errno);
throw TransportError(tools::ToString("Could not lock the managed segment memory: ", strerror(errno)));
} }
LOG(debug) << "Successfully locked the managed segment memory pages."; LOG(debug) << "Successfully locked the managed segment memory pages.";
} }
@ -323,6 +324,7 @@ class Manager
LOG(debug) << "Locking region " << id << "..."; LOG(debug) << "Locking region " << id << "...";
if (mlock(r.first->second->fRegion.get_address(), r.first->second->fRegion.get_size()) == -1) { if (mlock(r.first->second->fRegion.get_address(), r.first->second->fRegion.get_size()) == -1) {
LOG(error) << "Could not lock region " << id << ". Code: " << errno << ", reason: " << strerror(errno); LOG(error) << "Could not lock region " << id << ". Code: " << errno << ", reason: " << strerror(errno);
throw TransportError(tools::ToString("Could not lock region ", id, ": ", strerror(errno)));
} }
LOG(debug) << "Successfully locked region " << id << "."; LOG(debug) << "Successfully locked region " << id << ".";
} }