From: Radosław Korzeniewski Date: Fri, 5 Nov 2021 15:12:34 +0000 (+0100) Subject: pluginlib: Add per plugin IO timeout for backend. X-Git-Tag: Beta-15.0.0~769 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba98dac9b9b793728e4f22fa042c19aa1f9c5e32;p=thirdparty%2Fbacula.git pluginlib: Add per plugin IO timeout for backend. Backend can define compile in timeout value with the following variable: `const uint32_t BACKEND_TIMEOUT = 0; // use default` The value set at this variable defines a timeout in seconds which will be applied to all recvbackend_data() and sendbackend_data() calls. The value of zero (0) setup a default timeout of 3600 seconds. Set it to zero if unsure. --- diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp index 713da99ce..1cb47a225 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin.cpp +++ b/bacula/src/plugins/fd/pluginlib/metaplugin.cpp @@ -469,6 +469,10 @@ bRC METAPLUGIN::run_backend(bpContext *ctx) /* setup communication channel */ backend.ctx->set_bpipe(bp); DMSG(ctx, DINFO, "Backend executed at PID=%i\n", bp->worker_pid); + + backend.ctx->set_timeout(BACKEND_TIMEOUT); + DMSG(ctx, DINFO, "setup backend timeout=%d\n", backend.ctx->get_timeout()); + return bRC_OK; } diff --git a/bacula/src/plugins/fd/pluginlib/metaplugin.h b/bacula/src/plugins/fd/pluginlib/metaplugin.h index e9889d187..3479e0465 100644 --- a/bacula/src/plugins/fd/pluginlib/metaplugin.h +++ b/bacula/src/plugins/fd/pluginlib/metaplugin.h @@ -71,6 +71,7 @@ extern const int32_t CUSTOMCANCELSLEEP; /// custom wait time for backend extern const bool ACCURATEPLUGINPARAMETER; /// accurate parameter for plugin parameter extern const int ADDINCLUDESTRIPOPTION; /// setup precompiled include path strip option extern const bool DONOTSAVE_FT_PLUGIN_CONFIG; /// when set to `true` then Metaplugin won't save FT_PLUGIN_CONFIG as a first file during Full backup +extern const uint32_t BACKEND_TIMEOUT; /// define a custom timeout value in seconds for data exchange (read from or write to backend) /// defines if metaplugin should handle local filesystem restore with Bacula Core functions /// `false` means metaplugin will redirect local restore to backend diff --git a/bacula/src/plugins/fd/pluginlib/ptcomm.cpp b/bacula/src/plugins/fd/pluginlib/ptcomm.cpp index 3979d139c..5a41c84c4 100644 --- a/bacula/src/plugins/fd/pluginlib/ptcomm.cpp +++ b/bacula/src/plugins/fd/pluginlib/ptcomm.cpp @@ -154,7 +154,7 @@ bool PTCOMM::recvbackend_data(bpContext *ctx, char *buf, int32_t nbytes) int rbytes = 0; struct timeval _timeout; - _timeout.tv_sec = PTCOMM_DEFAULT_TIMEOUT; + _timeout.tv_sec = m_timeout > 0 ? m_timeout : PTCOMM_DEFAULT_TIMEOUT; _timeout.tv_usec = 0; while (nbytes > 0) diff --git a/bacula/src/plugins/fd/pluginlib/ptcomm.h b/bacula/src/plugins/fd/pluginlib/ptcomm.h index 2f5f17a31..d8ae25fa3 100644 --- a/bacula/src/plugins/fd/pluginlib/ptcomm.h +++ b/bacula/src/plugins/fd/pluginlib/ptcomm.h @@ -297,7 +297,19 @@ public: */ inline bool is_abort_on_error() { return abort_on_error; } - inline void set_timeout(uint32_t timeout) { m_timeout = timeout; } + /** + * @brief Set the timeout value in seconds + * + * @param timeout a value in seconds + */ + inline void set_timeout(uint32_t timeout) { m_timeout = timeout > 0 ? timeout : PTCOMM_DEFAULT_TIMEOUT; } + + /** + * @brief Get the timeout object + * + * @return uint32_t a current value of the PTCOMM Timeout + */ + inline uint32_t get_timeout() { return m_timeout; } }; #endif /* _PTCOMM_H_ */