int CacheController::shutdown() {
ldout(m_cct, 20) << dendl;
- int r = m_cache_server->stop();
- if (r < 0) {
- lderr(m_cct) << "stop error\n" << dendl;
- return r;
+ int r;
+ if (m_cache_server != nullptr) {
+ r = m_cache_server->stop();
+ if (r < 0) {
+ lderr(m_cct) << "stop error\n" << dendl;
+ return r;
+ }
}
r = m_object_cache_store->shutdown();
shutdown();
}
-void CacheController::run() {
+int CacheController::run() {
try {
std::string controller_path =
m_cct->_conf.get_val<std::string>("immutable_object_cache_sock");
+ if (controller_path.empty()) {
+ lderr(m_cct) << "'immutable_object_cache_sock' path not set" << dendl;
+ return -EINVAL;
+ }
+
std::remove(controller_path.c_str());
m_cache_server = new CacheServer(m_cct, controller_path,
int ret = m_cache_server->run();
if (ret != 0) {
- throw std::runtime_error("io serivce run error");
+ return ret;
}
+
+ return 0;
} catch (std::exception& e) {
lderr(m_cct) << "Exception: " << e.what() << dendl;
+ return -EFAULT;
}
}
void handle_signal(int sinnum);
- void run();
+ int run();
void handle_request(CacheSession* session, ObjectCacheRequest* msg);
private:
- CacheServer *m_cache_server;
+ CacheServer *m_cache_server = nullptr;
std::vector<const char*> m_args;
CephContext *m_cct;
- ObjectCacheStore *m_object_cache_store;
+ ObjectCacheStore *m_object_cache_store = nullptr;
};
} // namespace immutable_obj_cache
boost::system::error_code ec;
m_acceptor.open(m_local_path.protocol(), ec);
if (ec) {
- ldout(cct, 1) << "m_acceptor open fails: " << ec.message() << dendl;
- return -1;
+ lderr(cct) << "failed to open domain socket: " << ec.message() << dendl;
+ return -ec.value();
}
m_acceptor.bind(m_local_path, ec);
if (ec) {
- ldout(cct, 1) << "m_acceptor bind fails: " << ec.message() << dendl;
- return -1;
+ lderr(cct) << "failed to bind to domain socket '"
+ << m_local_path << "': " << ec.message() << dendl;
+ return -ec.value();
}
m_acceptor.listen(boost::asio::socket_base::max_connections, ec);
if (ec) {
- ldout(cct, 1) << "m_acceptor listen fails: " << ec.message() << dendl;
- return -1;
+ lderr(cct) << "failed to listen on domain socket: " << ec.message()
+ << dendl;
+ return -ec.value();
}
accept();
// TODO(dehao): fsck and reuse existing cache objects
if (reset) {
- std::error_code ec;
- if (efs::exists(m_cache_root_dir)) {
- // remove all sub folders
- for (auto& p : efs::directory_iterator(m_cache_root_dir)) {
- efs::remove_all(p.path());
- }
- } else {
- if (!efs::create_directories(m_cache_root_dir, ec)) {
- lderr(m_cct) << "fail to create cache store dir: " << ec << dendl;
- return ec.value();
+ try {
+ if (efs::exists(m_cache_root_dir)) {
+ // remove all sub folders
+ for (auto& p : efs::directory_iterator(m_cache_root_dir)) {
+ efs::remove_all(p.path());
+ }
+ } else {
+ efs::create_directories(m_cache_root_dir);
}
+ } catch (const efs::filesystem_error& e) {
+ lderr(m_cct) << "failed to initialize cache store directory: "
+ << e.what() << dendl;
+ return -e.code().value();
}
}
return 0;
goto cleanup;
}
- cachectl->run();
+ r = cachectl->run();
+ if (r < 0) {
+ goto cleanup;
+ }
cleanup:
unregister_async_signal_handler(SIGHUP, sighup_handler);