From 5d050f881b8d62f8c8bd5cd0ed94839e44634a59 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Thu, 7 Nov 2019 01:38:38 +0100 Subject: [PATCH] [947-mt-compatibility-for-hooks] Did a first pass on core hooks --- src/hooks/dhcp/flex_option/flex_option.dox | 4 +++ .../dhcp/flex_option/flex_option_callouts.cc | 7 +++++ src/hooks/dhcp/high_availability/ha.dox | 8 +++++- .../dhcp/high_availability/ha_callouts.cc | 11 +++++++- src/hooks/dhcp/lease_cmds/lease_cmds.cc | 27 +++++++++++++------ src/hooks/dhcp/lease_cmds/lease_cmds.dox | 8 +++++- .../dhcp/lease_cmds/lease_cmds_callouts.cc | 7 +++++ src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc | 9 +++++++ src/hooks/dhcp/stat_cmds/stat_cmds.dox | 6 +++++ .../dhcp/stat_cmds/stat_cmds_callouts.cc | 12 ++++++++- src/hooks/dhcp/user_chk/libdhcp_user_chk.dox | 6 ++++- 11 files changed, 92 insertions(+), 13 deletions(-) diff --git a/src/hooks/dhcp/flex_option/flex_option.dox b/src/hooks/dhcp/flex_option/flex_option.dox index 59e8beccc7..826f7e5498 100644 --- a/src/hooks/dhcp/flex_option/flex_option.dox +++ b/src/hooks/dhcp/flex_option/flex_option.dox @@ -112,4 +112,8 @@ applied by the template @ref process located in flex_option.h. When required the expression is evaluated on the query packet and the result is used by the action for instance to add a new option. +@section libdhcp_flex_optionMTCompatibility Multi-Threading Compaibility + +The libdhcp_flex_option hooks library is compatible with multi-threading. + */ diff --git a/src/hooks/dhcp/flex_option/flex_option_callouts.cc b/src/hooks/dhcp/flex_option/flex_option_callouts.cc index 2122de6a72..2f3f88dd94 100644 --- a/src/hooks/dhcp/flex_option/flex_option_callouts.cc +++ b/src/hooks/dhcp/flex_option/flex_option_callouts.cc @@ -122,4 +122,11 @@ int unload() { return (0); } +/// @brief This function is called to know the multi-threading compatibility. +/// +/// @return 1 which means compatible with multi-threading. +int multi_threading_compatible() { + return (1); +} + } // end extern "C" diff --git a/src/hooks/dhcp/high_availability/ha.dox b/src/hooks/dhcp/high_availability/ha.dox index 6cffa2743d..f905c135c4 100644 --- a/src/hooks/dhcp/high_availability/ha.dox +++ b/src/hooks/dhcp/high_availability/ha.dox @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -407,4 +407,10 @@ Addressing this issue requires two enhancements: points via which the server removing the lease from the database could notify the partner about such removal. +@section haMTCompatibility Multi-Threading Compatibility + +The High Availability hooks library currently reports it is not +compatible with multi-threading. This will be revisited as there is +no essential reason for such uncompatibility. + */ diff --git a/src/hooks/dhcp/high_availability/ha_callouts.cc b/src/hooks/dhcp/high_availability/ha_callouts.cc index 6dcdeac3eb..9a451aa838 100644 --- a/src/hooks/dhcp/high_availability/ha_callouts.cc +++ b/src/hooks/dhcp/high_availability/ha_callouts.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -241,5 +241,14 @@ int unload() { return (0); } +/// @brief This function is called to know the multi-threading compatibility. +/// +/// @note: this should be revisited as the library is not essentially +/// uncompatible. +/// +/// @return 0 which means not compatible with multi-threading. +int multi_threading_compatible() { + return (0); +} } // end extern "C" diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds.cc b/src/hooks/dhcp/lease_cmds/lease_cmds.cc index 240c68ee6c..35b83dd03a 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds.cc +++ b/src/hooks/dhcp/lease_cmds/lease_cmds.cc @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1564,19 +1565,23 @@ LeaseCmdsImpl::createFailedLeaseMap(const Lease::Type& lease_type, return (failed_lease_map); } +// Do lease changes in a critical section. + int LeaseCmds::leaseAddHandler(CalloutHandle& handle) { - return(impl_->leaseAddHandler(handle)); + MultiThreadingCriticalSection cs; + return (impl_->leaseAddHandler(handle)); } int LeaseCmds::lease6BulkApplyHandler(CalloutHandle& handle) { + MultiThreadingCriticalSection cs; return (impl_->lease6BulkApplyHandler(handle)); } int LeaseCmds::leaseGetHandler(CalloutHandle& handle) { - return(impl_->leaseGetHandler(handle)); + return (impl_->leaseGetHandler(handle)); } int @@ -1611,32 +1616,38 @@ LeaseCmds::leaseGetByHostnameHandler(hooks::CalloutHandle& handle) { int LeaseCmds::lease4DelHandler(CalloutHandle& handle) { - return(impl_->lease4DelHandler(handle)); + MultiThreadingCriticalSection cs; + return (impl_->lease4DelHandler(handle)); } int LeaseCmds::lease6DelHandler(CalloutHandle& handle) { - return(impl_->lease6DelHandler(handle)); + MultiThreadingCriticalSection cs; + return (impl_->lease6DelHandler(handle)); } int LeaseCmds::lease4UpdateHandler(CalloutHandle& handle) { - return(impl_->lease4UpdateHandler(handle)); + MultiThreadingCriticalSection cs; + return (impl_->lease4UpdateHandler(handle)); } int LeaseCmds::lease6UpdateHandler(CalloutHandle& handle) { - return(impl_->lease6UpdateHandler(handle)); + MultiThreadingCriticalSection cs; + return (impl_->lease6UpdateHandler(handle)); } int LeaseCmds::lease4WipeHandler(CalloutHandle& handle) { - return(impl_->lease4WipeHandler(handle)); + MultiThreadingCriticalSection cs; + return (impl_->lease4WipeHandler(handle)); } int LeaseCmds::lease6WipeHandler(CalloutHandle& handle) { - return(impl_->lease6WipeHandler(handle)); + MultiThreadingCriticalSection cs; + return (impl_->lease6WipeHandler(handle)); } LeaseCmds::LeaseCmds() diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds.dox b/src/hooks/dhcp/lease_cmds/lease_cmds.dox index 8afbc1107c..b12f71dcc2 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds.dox +++ b/src/hooks/dhcp/lease_cmds/lease_cmds.dox @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -95,4 +95,10 @@ commands that remove all leases from specific subnet. As there were no queries that could retrieve or otherwise enumerate leases for a specific subnet, a new query type and a new index had to be added. +@section lease_cmdsTCompatibility Multi-Threading Compatibility + +The Lease Commands Hook library is compatible with multi-threading. +All commands modifying leases are performed inside a critical section +i.e. with the DHCP server stopped. + */ diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds_callouts.cc b/src/hooks/dhcp/lease_cmds/lease_cmds_callouts.cc index 1b28e4615e..02c1ec35fc 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds_callouts.cc +++ b/src/hooks/dhcp/lease_cmds/lease_cmds_callouts.cc @@ -284,4 +284,11 @@ int unload() { return (0); } +/// @brief This function is called to know the multi-threading compatibility. +/// +/// @return 1 which means compatible with multi-threading. +int multi_threading_compatible() { + return (1); +} + } // end extern "C" diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc index 11b11df726..7140621b6b 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc @@ -45,5 +45,14 @@ int unload() { return (0); } +/// @brief This function is called to know the multi-threading compatibility. +/// +/// @note: the compatibility is based on the assumption this hook library +/// is always called from the main thread. +/// +/// @return 1 which means compatible with multi-threading. +int multi_threading_compatible() { + return (1); +} } // end extern "C" diff --git a/src/hooks/dhcp/stat_cmds/stat_cmds.dox b/src/hooks/dhcp/stat_cmds/stat_cmds.dox index 8480cff276..e267e3c350 100644 --- a/src/hooks/dhcp/stat_cmds/stat_cmds.dox +++ b/src/hooks/dhcp/stat_cmds/stat_cmds.dox @@ -196,4 +196,10 @@ and DHCPv6 response might look like this: } @endcode +@section stat_cmdsMTCompatibility Multi-Threading Compatibility + +The Stat Commands Hook library currently reports it is not +compatible with multi-threading. This will be revisited as there is +no essential reason for such uncompatibility. + */ diff --git a/src/hooks/dhcp/stat_cmds/stat_cmds_callouts.cc b/src/hooks/dhcp/stat_cmds/stat_cmds_callouts.cc index be210486e5..c4afeaeab9 100644 --- a/src/hooks/dhcp/stat_cmds/stat_cmds_callouts.cc +++ b/src/hooks/dhcp/stat_cmds/stat_cmds_callouts.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2018-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the End User License // Agreement. See COPYING file in the premium/ directory. @@ -61,4 +61,14 @@ int unload() { return (0); } +/// @brief This function is called to know the multi-threading compatibility. +/// +/// @note: this should be revisited as the library is not essentially +/// uncompatible. +/// +/// @return 0 which means not compatible with multi-threading. +int multi_threading_compatible() { + return (0); +} + } // end extern "C" diff --git a/src/hooks/dhcp/user_chk/libdhcp_user_chk.dox b/src/hooks/dhcp/user_chk/libdhcp_user_chk.dox index 4cf6a42383..4b3534252a 100644 --- a/src/hooks/dhcp/user_chk/libdhcp_user_chk.dox +++ b/src/hooks/dhcp/user_chk/libdhcp_user_chk.dox @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2019 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -212,6 +212,10 @@ registered=yes Note the library always opens this file in append mode and does not limit its size. +@section libdhcp_user_chkMTCompatibility Multi-Threading Compaibility +The user_chk hooks library does not define a multi_threading_compatible() +C function so is considered as not compatible with multi-threading +(and the current code should be in fact really not compatible). */ -- 2.47.2