if (err) {
lderr(s_service->cct) << "Failed to start service. Error code: "
<< err << dendl;
- s_service->set_status(SERVICE_STOPPED);
+ s_service->shutdown(true);
} else {
ldout(s_service->cct, 5) << "Successfully started service." << dendl;
s_service->set_status(SERVICE_RUNNING);
}
}
-void ServiceBase::shutdown()
+void ServiceBase::shutdown(bool ignore_errors)
{
DWORD original_state = status.dwCurrentState;
set_status(SERVICE_STOP_PENDING);
int err = shutdown_hook();
if (err) {
derr << "Shutdown service hook failed. Error code: " << err << dendl;
- set_status(original_state);
+ if (ignore_errors) {
+ derr << "Ignoring shutdown hook failure, marking the service as stopped."
+ << dendl;
+ set_status(SERVICE_STOPPED);
+ } else {
+ derr << "Reverting to original service state." << dendl;
+ set_status(original_state);
+ }
} else {
dout(5) << "Shutdown hook completed." << dendl;
set_status(SERVICE_STOPPED);
dout(5) << "Removing mapping: " << cfg.devpath
<< ". Timeout: " << cfg.soft_disconnect_timeout
- << "ms. Hard disconnect: " << cfg.hard_disconnect
+ << "s. Hard disconnect: " << cfg.hard_disconnect
<< dendl;
r = do_unmap(&cfg, unregister);
int thread_count;
int service_start_timeout;
int image_map_timeout;
+ bool remap_failure_fatal;
public:
RBDService(bool _hard_disconnect,
int _soft_disconnect_timeout,
int _thread_count,
int _service_start_timeout,
- int _image_map_timeout)
+ int _image_map_timeout,
+ bool _remap_failure_fatal)
: ServiceBase(g_ceph_context)
, hard_disconnect(_hard_disconnect)
, soft_disconnect_timeout(_soft_disconnect_timeout)
, thread_count(_thread_count)
, service_start_timeout(_service_start_timeout)
, image_map_timeout(_image_map_timeout)
+ , remap_failure_fatal(_remap_failure_fatal)
{
}
// Restart registered mappings before accepting new ones.
int r = restart_registered_mappings(
thread_count, service_start_timeout, image_map_timeout);
- if (r)
- return r;
+ if (r) {
+ if (remap_failure_fatal) {
+ derr << "Couldn't remap all images. Cleaning up." << dendl;
+ return r;
+ } else {
+ dout(0) << "Ignoring image remap failure." << dendl;
+ }
+ }
return create_pipe_server();
}
unmapping images. Default: 8
--start-timeout The service start timeout in seconds. Default: 120
--map-timeout Individual image map timeout in seconds. Default: 20
+ --remap-failure-fatal If set, the service will stop when failing to remap
+ an image at start time, unmapping images that have
+ been mapped so far.
Show|List options:
--format plain|json|xml Output format (default: plain)
cfg->persistent = false;
} else if (ceph_argparse_flag(args, i, "--pretty-format", (char *)NULL)) {
cfg->pretty_format = true;
+ } else if (ceph_argparse_flag(args, i, "--remap-failure-fatal", (char *)NULL)) {
+ cfg->remap_failure_fatal = true;
} else if (ceph_argparse_witharg(args, i, &cfg->parent_pipe, err,
"--pipe-name", (char *)NULL)) {
if (!err.str().empty()) {
RBDService service(cfg.hard_disconnect, cfg.soft_disconnect_timeout,
cfg.service_thread_count,
cfg.service_start_timeout,
- cfg.image_map_timeout);
+ cfg.image_map_timeout,
+ cfg.remap_failure_fatal);
// This call will block until the service stops.
r = RBDService::initialize(&service);
if (r < 0)