diff --git a/include/maxscale/bitmask.h b/include/maxscale/bitmask.h deleted file mode 100644 index 1a8a12f29..000000000 --- a/include/maxscale/bitmask.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once -/* - * Copyright (c) 2016 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl. - * - * Change Date: 2019-07-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ - -/** - * @file bitmask.h An implementation of an arbitrarily long bitmask - */ - -#include - -#include -#include - -MXS_BEGIN_DECLS - -/* This number MUST an be exact multiple of 8 */ -#define MXS_BITMASK_LENGTH (MXS_MAX_THREADS + 1) /**< Number of bits in the bitmask */ - -#define MXS_BITMASK_SIZE (MXS_BITMASK_LENGTH / 8) /**< Number of bytes in the bitmask */ - -/** - * The bitmask structure used to store a fixed size bitmask - */ -typedef struct -{ - SPINLOCK lock; /**< Lock to protect the bitmask */ - unsigned char bits[MXS_BITMASK_SIZE]; /**< The bits themselves */ -} MXS_BITMASK; - -#define MXS_BITMASK_INIT {SPINLOCK_INIT} - -void bitmask_init(MXS_BITMASK *); -void bitmask_free(MXS_BITMASK *); -int bitmask_set(MXS_BITMASK *, int); -int bitmask_clear(MXS_BITMASK *, int); -int bitmask_clear_without_spinlock(MXS_BITMASK *, int); -int bitmask_isset(MXS_BITMASK *, int); -int bitmask_isallclear(MXS_BITMASK *); -void bitmask_copy(MXS_BITMASK *, MXS_BITMASK *); -char *bitmask_render_readable(MXS_BITMASK *); - -MXS_END_DECLS diff --git a/include/maxscale/dcb.h b/include/maxscale/dcb.h index 49076d8be..76b415e25 100644 --- a/include/maxscale/dcb.h +++ b/include/maxscale/dcb.h @@ -52,7 +52,6 @@ #include #include #include -#include #include MXS_BEGIN_DECLS @@ -130,11 +129,10 @@ typedef struct dcbstats */ typedef struct { - MXS_BITMASK bitmask; /*< The bitmask of threads */ struct dcb *next; /*< Next pointer for the zombie list */ } DCBMM; -#define DCBMM_INIT {MXS_BITMASK_INIT} +#define DCBMM_INIT { NULL } /* DCB states */ typedef enum diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 98172e769..33d2b9a25 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(maxscale-common SHARED adminusers.c alloc.c authenticator.c atomic.c buffer.c config.c config_runtime.c dcb.c filter.c filter.cc externcmd.c bitmask.c paths.c hashtable.c hint.c housekeeper.c load_utils.c log_manager.cc maxscale_pcre2.c memlog.c misc.c mlist.c modutil.c monitor.c queuemanager.c query_classifier.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c ssl.c mysql_utils.c mysql_binlog.c modulecmd.c ) +add_library(maxscale-common SHARED adminusers.c alloc.c authenticator.c atomic.c buffer.c config.c config_runtime.c dcb.c filter.c filter.cc externcmd.c paths.c hashtable.c hint.c housekeeper.c load_utils.c log_manager.cc maxscale_pcre2.c memlog.c misc.c mlist.c modutil.c monitor.c queuemanager.c query_classifier.c poll.c random_jkiss.c resultset.c secrets.c server.c service.c session.c spinlock.c thread.c users.c utils.c skygw_utils.cc statistics.c listener.c ssl.c mysql_utils.c mysql_binlog.c modulecmd.c ) target_link_libraries(maxscale-common ${MARIADB_CONNECTOR_LIBRARIES} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${CURL_LIBRARIES} ssl pthread crypt dl crypto inih z rt m stdc++) diff --git a/server/core/bitmask.c b/server/core/bitmask.c deleted file mode 100644 index 16e5dd248..000000000 --- a/server/core/bitmask.c +++ /dev/null @@ -1,331 +0,0 @@ -/* - * Copyright (c) 2016 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl. - * - * Change Date: 2019-07-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ -#include -#include -#include -#include -#include - -/** - * @file bitmask.c Implementation of bitmask operations for the gateway - * - * MXS_BITMASK is a fixed size bitmask with space for 256 bits. - * - * @verbatim - * Revision History - * - * Date Who Description - * 28/06/13 Mark Riddoch Initial implementation - * 20/08/15 Martin Brampton Added caveats about limitations (above) - * 17/10/15 Martin Brampton Added display of bitmask - * 04/01/16 Martin Brampton Changed bitmask_clear to not lock and return - * whether bitmask is clear; added bitmask_clear_with_lock. - * - * @endverbatim - */ - -static int bitmask_isset_without_spinlock(MXS_BITMASK *bitmask, int bit); -static int bitmask_count_bits_set(MXS_BITMASK *bitmask); - -static const unsigned char bitmapclear[8] = -{ - 255 - 1, 255 - 2, 255 - 4, 255 - 8, 255 - 16, 255 - 32, 255 - 64, 255 - 128 -}; -static const unsigned char bitmapset[8] = -{ - 1, 2, 4, 8, 16, 32, 64, 128 -}; - -/** - * Initialise a bitmask - * - * @param bitmask Pointer the bitmask - */ -void -bitmask_init(MXS_BITMASK *bitmask) -{ - spinlock_init(&bitmask->lock); - memset(bitmask->bits, 0, MXS_BITMASK_SIZE); -} - -/** - * Free a bitmask that is no longer required - * - * @param bitmask - */ -void -bitmask_free(MXS_BITMASK *bitmask) -{ -} - -/** - * Set the bit at the specified bit position in the bitmask. - * - * @param bitmask Pointer the bitmask - * @param bit Bit to set - * @return 1 if the bit could be set, 0 otherwise. - * Setting a bit may fail only if the bit exceeds - * the maximum length of the bitmask. - */ -int -bitmask_set(MXS_BITMASK *bitmask, int bit) -{ - ss_dassert(bit >= 0); - - spinlock_acquire(&bitmask->lock); - - if (bit < MXS_BITMASK_LENGTH) - { - unsigned char *ptr = bitmask->bits; - - if (bit >= 8) - { - ptr += (bit / 8); - bit = bit % 8; - } - - *ptr |= bitmapset[bit]; - } - - spinlock_release(&bitmask->lock); - - return bit < MXS_BITMASK_LENGTH; -} - -/** - * Clear the bit at the specified bit position in the bitmask. - * Bits beyond the bitmask length are always assumed to be clear, so no - * action is needed if the bit parameter is beyond the length. - * Note that this function does not lock the bitmask, but assumes that - * it is under the exclusive control of the caller. If you want to use the - * bitmask spinlock to protect access while clearing the bit, then call - * the alternative bitmask_clear. - * - * @param bitmask Pointer the bitmask - * @param bit Bit to clear - * @return int 1 if the bitmask is all clear after the operation, else 0. - */ -int -bitmask_clear_without_spinlock(MXS_BITMASK *bitmask, int bit) -{ - ss_dassert(bit >= 0); - - unsigned char *ptr = bitmask->bits; - - if (bit < MXS_BITMASK_LENGTH) - { - if (bit >= 8) - { - ptr += (bit / 8); - bit = bit % 8; - } - *ptr &= bitmapclear[bit]; - } - ptr = bitmask->bits; - for (int i = 0; i < MXS_BITMASK_SIZE; i++) - { - if (*(ptr + i) != 0) - { - return 0; - } - } - return 1; -} - -/** - * Clear the bit at the specified bit position in the bitmask using a spinlock. - * See bitmask_clear_without_spinlock for more details - * - * @param bitmask Pointer the bitmask - * @param bit Bit to clear - * @return int 1 if the bitmask is all clear after the operation, else 0 - */ -int -bitmask_clear(MXS_BITMASK *bitmask, int bit) -{ - int result; - - spinlock_acquire(&bitmask->lock); - result = bitmask_clear_without_spinlock(bitmask, bit); - spinlock_release(&bitmask->lock); - return result; -} - -/** - * Return a non-zero value if the bit at the specified bit - * position in the bitmask is set. If the specified bit is outside the - * bitmask, it is assumed to be unset; the bitmask is not extended. - * This function wraps bitmask_isset_without_spinlock with a spinlock. - * - * @param bitmask Pointer the bitmask - * @param bit Bit to test - */ -int -bitmask_isset(MXS_BITMASK *bitmask, int bit) -{ - int result; - - spinlock_acquire(&bitmask->lock); - result = bitmask_isset_without_spinlock(bitmask, bit); - spinlock_release(&bitmask->lock); - return result; -} - -/** - * Return a non-zero value if the bit at the specified bit - * position in the bitmask is set. Should be called while holding a - * lock on the bitmask or having control of it in some other way. - * - * Bits beyond the current length are deemed unset. - * - * @param bitmask Pointer the bitmask - * @param bit Bit to test - */ -static int -bitmask_isset_without_spinlock(MXS_BITMASK *bitmask, int bit) -{ - ss_dassert(bit >= 0); - - if (bit >= MXS_BITMASK_LENGTH) - { - return 0; - } - - unsigned char *ptr = bitmask->bits; - - if (bit >= 8) - { - ptr += (bit / 8); - bit = bit % 8; - } - return *ptr & bitmapset[bit]; -} - -/** - * Return a non-zero value of the bitmask has no bits set - * in it. This logic could be defeated if the bitmask is a - * copy and there was insufficient memory when the copy was - * made. - * - * @param bitmask Pointer the bitmask - * @return Non-zero if the bitmask has no bits set - */ -int -bitmask_isallclear(MXS_BITMASK *bitmask) -{ - unsigned char *ptr = bitmask->bits; - int result = 1; - - spinlock_acquire(&bitmask->lock); - for (int i = 0; i < MXS_BITMASK_SIZE; i++) - { - if (*(ptr + i) != 0) - { - result = 0; - break; - } - } - spinlock_release(&bitmask->lock); - - return result; -} - -/** - * Copy the contents of one bitmap to another. - * - * @param dest Bitmap tp update - * @param src Bitmap to copy - */ -void -bitmask_copy(MXS_BITMASK *dest, MXS_BITMASK *src) -{ - spinlock_acquire(&src->lock); - spinlock_acquire(&dest->lock); - memcpy(dest->bits, src->bits, MXS_BITMASK_SIZE); - spinlock_release(&dest->lock); - spinlock_release(&src->lock); -} - -/** - * Return a comma separated list of the numbers of the bits that are set in - * a bitmask, numbering starting at zero. The returned string must be - * freed by the caller (unless it is null on account of memory allocation - * failure). - * - * @param bitmask Bitmap to make readable - * @return pointer to the newly allocated string, or null if no memory - */ -char * -bitmask_render_readable(MXS_BITMASK *bitmask) -{ - static const char empty[] = "No bits are set"; - char *result; - - spinlock_acquire(&bitmask->lock); - int count_set = bitmask_count_bits_set(bitmask); - if (count_set) - { - result = MXS_MALLOC(1 + (4 * count_set)); - if (result) - { - result[0] = 0; - for (int i = 0; i < MXS_BITMASK_LENGTH; i++) - { - if (bitmask_isset_without_spinlock(bitmask, i)) - { - char onebit[5]; - sprintf(onebit, "%d,", i); - strcat(result, onebit); - } - } - result[strlen(result) - 1] = 0; - } - } - else - { - result = MXS_MALLOC(sizeof(empty)); - if (result) - { - strcpy(result, empty); - } - } - spinlock_release(&bitmask->lock); - return result; -} - -/** - * Return a count of the number of bits set in a bitmask. Helpful for setting - * the size of string needed to show the set bits in readable form. - * - * @param bitmask Bitmap whose bits are to be counted - * @return int Number of set bits - */ -static int -bitmask_count_bits_set(MXS_BITMASK *bitmask) -{ - static const unsigned char oneBits[] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4}; - unsigned char partresults; - int result = 0; - unsigned char *ptr, *eptr; - - ptr = bitmask->bits; - eptr = ptr + MXS_BITMASK_SIZE; - while (ptr < eptr) - { - partresults = oneBits[*ptr & 0x0f]; - partresults += oneBits[*ptr >> 4]; - result += partresults; - ptr++; - } - return result; -} diff --git a/server/core/dcb.c b/server/core/dcb.c index a88b6d514..eb76b4b2b 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -79,6 +79,7 @@ #include #include #include +#include #include #include #include @@ -208,7 +209,6 @@ static void dcb_initialize(void *dcb) { *(DCB *)dcb = dcb_initialized; - bitmask_init(&((DCB *)dcb)->memdata.bitmask); } /** @@ -441,7 +441,6 @@ dcb_free_all_memory(DCB *dcb) { SSL_free(dcb->ssl); } - bitmask_free(&dcb->memdata.bitmask); /* We never free the actual DCB, it is available for reuse*/ MXS_FREE(dcb); @@ -1902,15 +1901,6 @@ dprintOneDCB(DCB *pdcb, DCB *dcb) dcb_printf(pdcb, "\tRole: %s\n", rolename); MXS_FREE(rolename); } - if (!bitmask_isallclear(&dcb->memdata.bitmask)) - { - char *bitmasktext = bitmask_render_readable(&dcb->memdata.bitmask); - if (bitmasktext) - { - dcb_printf(pdcb, "\tBitMask: %s\n", bitmasktext); - MXS_FREE(bitmasktext); - } - } dcb_printf(pdcb, "\tStatistics:\n"); dcb_printf(pdcb, "\t\tNo. of Reads: %d\n", dcb->stats.n_reads); dcb_printf(pdcb, "\t\tNo. of Writes: %d\n", dcb->stats.n_writes); diff --git a/server/core/maxscale/poll.h b/server/core/maxscale/poll.h index f5a0d9bcc..2257b4ce2 100644 --- a/server/core/maxscale/poll.h +++ b/server/core/maxscale/poll.h @@ -18,7 +18,6 @@ #include -#include #include MXS_BEGIN_DECLS @@ -58,7 +57,6 @@ void dShowThreads(DCB *dcb); void dShowEventQ(DCB *dcb); void dShowEventStats(DCB *dcb); -MXS_BITMASK *poll_bitmask(); int poll_get_stat(POLL_STAT stat); RESULTSET *eventTimesGetList(); diff --git a/server/core/poll.c b/server/core/poll.c index aae033648..a84ad8f6c 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -105,7 +104,6 @@ static int next_epoll_fd = 0; /*< Which thread handles the next DCB */ static fake_event_t **fake_events; /*< Thread-specific fake event queue */ static SPINLOCK *fake_event_lock; static int do_shutdown = 0; /*< Flag the shutdown of the poll subsystem */ -static MXS_BITMASK poll_mask; /** Poll cross-thread messaging variables */ static volatile int *poll_msg; @@ -273,7 +271,6 @@ poll_init() memset(&pollStats, 0, sizeof(pollStats)); memset(&queueStats, 0, sizeof(queueStats)); - bitmask_init(&poll_mask); thread_data = (THREAD_DATA *)MXS_MALLOC(n_threads * sizeof(THREAD_DATA)); if (thread_data) { @@ -676,8 +673,6 @@ poll_waitevents(void *arg) thread_id = (intptr_t)arg; int poll_spins = 0; - /** Add this thread to the bitmask of running polling threads */ - bitmask_set(&poll_mask, thread_id); if (thread_data) { thread_data[thread_id].state = THREAD_IDLE; @@ -849,7 +844,6 @@ poll_waitevents(void *arg) { thread_data[thread_id].state = THREAD_STOPPED; } - bitmask_clear(&poll_mask, thread_id); return; } if (thread_data) @@ -1190,17 +1184,6 @@ poll_shutdown() do_shutdown = 1; } -/** - * Return the bitmask of polling threads - * - * @return The bitmask of the running polling threads - */ -MXS_BITMASK * -poll_bitmask() -{ - return &poll_mask; -} - /** * Display an entry from the spinlock statistics data * diff --git a/server/core/test/CMakeLists.txt b/server/core/test/CMakeLists.txt index 79834d018..99be06bae 100644 --- a/server/core/test/CMakeLists.txt +++ b/server/core/test/CMakeLists.txt @@ -2,7 +2,6 @@ add_executable(test_adminusers testadminusers.c) add_executable(test_buffer testbuffer.c) add_executable(test_dcb testdcb.c) add_executable(test_filter testfilter.c) -add_executable(test_gwbitmask testgwbitmask.c) add_executable(test_hash testhash.c) add_executable(test_hint testhint.c) add_executable(test_log testlog.c) @@ -24,7 +23,6 @@ target_link_libraries(test_adminusers maxscale-common) target_link_libraries(test_buffer maxscale-common) target_link_libraries(test_dcb maxscale-common) target_link_libraries(test_filter maxscale-common) -target_link_libraries(test_gwbitmask maxscale-common) target_link_libraries(test_hash maxscale-common) target_link_libraries(test_hint maxscale-common) target_link_libraries(test_log maxscale-common) @@ -46,7 +44,6 @@ add_test(TestAdminUsers test_adminusers) add_test(TestBuffer test_buffer) add_test(TestDCB test_dcb) add_test(TestFilter test_filter) -add_test(TestBitmask test_gwbitmask) add_test(TestHash test_hash) add_test(TestHint test_hint) add_test(TestLog test_log) diff --git a/server/core/test/testgwbitmask.c b/server/core/test/testgwbitmask.c deleted file mode 100644 index c422e6a91..000000000 --- a/server/core/test/testgwbitmask.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2016 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl. - * - * Change Date: 2019-07-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ - -/** - * - * @verbatim - * Revision History - * - * Date Who Description - * 13-10-2014 Martin Brampton Initial implementation - * - * @endverbatim - */ - -// To ensure that ss_info_assert asserts also when builing in non-debug mode. -#if !defined(SS_DEBUG) -#define SS_DEBUG -#endif -#if defined(NDEBUG) -#undef NDEBUG -#endif -#include -#include -#include - -#include - -#include - -/** - * test1 Create a bitmap and mess around with it - * - */ -static int -test1() -{ - static MXS_BITMASK bitmask, another; - int i; - - /* Hint tests */ - ss_dfprintf(stderr, - "testgwbitmask : Initialise a bitmask"); - bitmask_init(&bitmask); - for (i = 0; i < MXS_BITMASK_LENGTH; i++) - { - ss_info_dassert(0 == bitmask_isset(&bitmask, i), "All bits should initially be zero"); - } - ss_info_dassert(0 != bitmask_isallclear(&bitmask), "Should be all clear"); - ss_dfprintf(stderr, "\t..done\nSet an arbitrary bit."); - bitmask_set(&bitmask, 17); - bitmask_copy(&another, &bitmask); - ss_info_dassert(0 != bitmask_isset(&another, 17), "Test bit should be set"); - ss_dfprintf(stderr, "\t..done\nClear the arbitrary bit."); - bitmask_clear(&bitmask, 17); - ss_info_dassert(0 != bitmask_isallclear(&bitmask), "Should be all clear"); - ss_info_dassert(0 == bitmask_isset(&bitmask, 17), "Test bit should be clear"); - - ss_dfprintf(stderr, "\t..done\nFree the bitmask."); - bitmask_free(&bitmask); - ss_dfprintf(stderr, "\t..done\n"); - - return 0; - -} - -int main(int argc, char **argv) -{ - int result = 0; - - result += test1(); - - exit(result); -} - diff --git a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c index 83500c052..46a68069d 100644 --- a/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c +++ b/server/modules/protocol/MySQL/MySQLBackend/mysql_backend.c @@ -14,6 +14,7 @@ #define MXS_MODULE_NAME "MySQLBackend" #include +#include #include #include #include