[qpid-dispatch] 01/03: Revert "DISPATCH-1956: log.c rewrite to reduce locking scope"
This is an automated email from the ASF dual-hosted git repository. gmurthy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git commit b9bdfa2aa47b41c9d348d289d317900d31a9cd49 Author: Ganesh Murthy AuthorDate: Thu Oct 21 15:33:17 2021 -0400 Revert "DISPATCH-1956: log.c rewrite to reduce locking scope" This reverts commit 94164788cebf38d28b4213f5977cac1d62933ad4. --- include/qpid/dispatch/log.h | 17 - src/log.c | 31 ++- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/include/qpid/dispatch/log.h b/include/qpid/dispatch/log.h index 5a65f68..6265029 100644 --- a/include/qpid/dispatch/log.h +++ b/include/qpid/dispatch/log.h @@ -27,15 +27,14 @@ /** Logging levels */ typedef enum { -QD_LOG_NONE =0x00, ///< No logging -QD_LOG_TRACE =0x01, ///< High volume messages, o(n) or more for n message transfers. -QD_LOG_DEBUG =0x02, ///< Debugging messages useful to developers. -QD_LOG_INFO =0x04, ///< Information messages useful to users -QD_LOG_NOTICE=0x08, ///< Notice of important but non-error events. -QD_LOG_WARNING =0x10, ///< Warning of event that may be a problem. -QD_LOG_ERROR =0x20, ///< Error, definitely a problem -QD_LOG_CRITICAL =0x40, ///< Critical error, data loss or process shut-down. -QD_LOG_UNDEFINED =0x7FFF, ///< No log level defined, so none will be masked out. +QD_LOG_NONE =0x00, ///< No logging +QD_LOG_TRACE=0x01, ///< High volume messages, o(n) or more for n message transfers. +QD_LOG_DEBUG=0x02, ///< Debugging messages useful to developers. +QD_LOG_INFO =0x04, ///< Information messages useful to users +QD_LOG_NOTICE =0x08, ///< Notice of important but non-error events. +QD_LOG_WARNING =0x10, ///< Warning of event that may be a problem. +QD_LOG_ERROR=0x20, ///< Error, definitely a problem +QD_LOG_CRITICAL =0x40, ///< Critical error, data loss or process shut-down. } qd_log_level_t; typedef struct qd_log_source_t qd_log_source_t; diff --git a/src/log.c b/src/log.c index 3262bdb..5599483 100644 --- a/src/log.c +++ b/src/log.c @@ -43,7 +43,6 @@ #define LOG_MAX (QD_LOG_TEXT_MAX+128) #define LIST_MAX 1000 - // log.c lock strategy // // log sources -- @@ -215,7 +214,7 @@ typedef enum {DEFAULT, NONE, TRACE, DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICA struct qd_log_source_t { DEQ_LINKS(qd_log_source_t); char *module; -sys_atomic_t mask; +int mask; int includeTimestamp; /* boolean or -1 means not set */ int includeSource; /* boolean or -1 means not set */ bool syslog; @@ -238,7 +237,7 @@ typedef struct level_t { #define LEVEL(name, QD_LOG, SYSLOG) { name, QD_LOG, ALL_BITS & ~(QD_LOG-1), SYSLOG } static level_t levels[] = { -{"default", QD_LOG_UNDEFINED, QD_LOG_UNDEFINED, 0}, +{"default", -1, -1, 0}, {"none", 0, 0, 0}, LEVEL("trace",QD_LOG_TRACE, LOG_DEBUG), /* syslog has no trace level */ LEVEL("debug",QD_LOG_DEBUG, LOG_DEBUG), @@ -274,7 +273,7 @@ static const level_t *level_for_name(const char *name, int len) { } /* - Return undefined and set qd_error if not a valid bit. + Return -1 and set qd_error if not a valid bit. Translate so that the min valid level index is 0. */ static int level_index_for_bit(int bit) { @@ -286,7 +285,7 @@ static int level_index_for_bit(int bit) { } qd_error(QD_ERROR_CONFIG, "'%d' is not a valid log level bit.", bit); -return QD_LOG_UNDEFINED; +return -1; } /// Return the name of log level or 0 if not found. @@ -384,7 +383,7 @@ static void write_log(qd_log_source_t *log_source, qd_log_entry_t *entry) /// Reset the log source to the default state static void qd_log_source_defaults(qd_log_source_t *src) { -sys_atomic_set(&src->mask, (uint32_t) QD_LOG_UNDEFINED); +src->mask = -1; src->includeTimestamp = -1; src->includeSource = -1; log_sink_decref(src->sink); @@ -420,11 +419,8 @@ static void qd_log_source_free(qd_log_source_t *src) { bool qd_log_enabled(qd_log_source_t *source, qd_log_level_t level) { if (!source) return false; -uint32_t mask = sys_atomic_get(&source->mask); -if (mask == QD_LOG_UNDEFINED) { -mask = sys_atomic_get(&default_log_source->mask); -} -return !!(level & mask); +int mask = source->mask == -1 ? default_log_source->mask : source->mask; +return level & mask; } void qd_vlog_impl(qd_log_source_t *source, qd_log_level_t level, bool check_level, const char *file, int line, const char *fmt, va_list ap) @@ -434,7 +430,7 @@ void qd_vlog_impl(qd_log_source_t *source, qd_log_level_t level, bool check_leve // We can always decide not to look at it later, // based on its used/unus
[qpid-dispatch] 02/03: Revert "log.c rewrite part two"
This is an automated email from the ASF dual-hosted git repository. gmurthy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git commit c0b50a1a8d0dd3a5430c39bbe28a34ca8d19d0cf Author: Ganesh Murthy AuthorDate: Thu Oct 21 15:33:29 2021 -0400 Revert "log.c rewrite part two" This reverts commit 5be2067c1dc28378e56acd5806f25159cf3a14a5. --- src/log.c | 259 +--- tests/tsan.supp | 2 +- 2 files changed, 115 insertions(+), 146 deletions(-) diff --git a/src/log.c b/src/log.c index 5599483..e032bf6 100644 --- a/src/log.c +++ b/src/log.c @@ -26,7 +26,6 @@ #include "entity_cache.h" #include "log_private.h" #include "server_private.h" -#include "schema_enum.h" #include "qpid/dispatch/alloc.h" #include "qpid/dispatch/atomic.h" @@ -43,35 +42,6 @@ #define LOG_MAX (QD_LOG_TEXT_MAX+128) #define LIST_MAX 1000 -// log.c lock strategy -// -// log sources -- -// 1. Log sources are created only at initialize time, -//and are freed only during finalize time, so the -//list itself does not need to be protected by a -//lock. -// -// 2. Individual log sources do need protection, though, -//because a management command may call qd_log_entity() -//at any time, which may replace the log sink. So each -//log source has its own lock, to prevent collisions -//between write_log() and qd_log_entity(). -// -// log sinks --- -// 1. There is a global list of log sinks, which may be -//added to and deleted from at any time by qd_log_entity(). -//So there is a lock to protect the sinks list from -//simultaneous additions and deletions. -// -// log entries - -// 1. There is a global list of the most recent log entries -//that may be added to at any time by any log source. -//The list is bounded, so after some point additions -//cause deletions. -//So there is another lock to protect this entries lis -//from simultaneous access. -// -//= const char *QD_LOG_STATS_TYPE = "logStats"; static qd_log_source_t *default_log_source=0; @@ -79,6 +49,7 @@ static qd_log_source_t *default_log_source=0; int qd_log_max_len() { return TEXT_MAX; } typedef struct qd_log_entry_t qd_log_entry_t; + struct qd_log_entry_t { DEQ_LINKS(qd_log_entry_t); char *module; @@ -88,13 +59,14 @@ struct qd_log_entry_t { struct timeval time; chartext[TEXT_MAX]; }; + ALLOC_DECLARE(qd_log_entry_t); ALLOC_DEFINE(qd_log_entry_t); + DEQ_DECLARE(qd_log_entry_t, qd_log_list_t); static qd_log_list_t entries = {0}; -sys_mutex_t *entries_lock = 0; -static void qd_log_entry_free_lh(qd_log_entry_t *entry) { +static void qd_log_entry_free_lh(qd_log_entry_t* entry) { DEQ_REMOVE(entries, entry); free(entry->file); free(entry->module); @@ -109,9 +81,11 @@ typedef struct log_sink_t { FILE *file; DEQ_LINKS(struct log_sink_t); } log_sink_t; -DEQ_DECLARE(log_sink_t, log_sinks_t); -static sys_mutex_t *log_sinks_lock = 0; -static log_sinks_t sink_list = {0}; + +DEQ_DECLARE(log_sink_t, log_sink_list_t); + +static sys_mutex_t *log_sink_list_lock = 0; +static log_sink_list_t sink_list = {0}; const char *format = "%Y-%m-%d %H:%M:%S.%%06lu %z"; bool utc = false; @@ -137,11 +111,9 @@ static const char* SINK_STDERR = "stderr"; static const char* SINK_SYSLOG = "syslog"; static const char* SOURCE_DEFAULT = "DEFAULT"; -// Hold the log_sinks_lock to prevent collision -// with log_sink(). static void log_sink_decref(const log_sink_t *sink) { if (!sink) return; -sys_mutex_lock(log_sinks_lock); +sys_mutex_lock(log_sink_list_lock); assert(sink->ref_count); log_sink_t *mutable_sink = (log_sink_t *)sink; @@ -155,14 +127,12 @@ static void log_sink_decref(const log_sink_t *sink) { closelog(); free(mutable_sink); } -sys_mutex_unlock(log_sinks_lock); +sys_mutex_unlock(log_sink_list_lock); } -// Hold the log_sinks_lock to prevent collision -// with log_sink_decref(). -static const log_sink_t *log_sink(const char *name) { -sys_mutex_lock(log_sinks_lock); -log_sink_t *sink = DEQ_HEAD(sink_list); +static const log_sink_t* log_sink(const char* name) { +sys_mutex_lock(log_sink_list_lock); +log_sink_t* sink = DEQ_HEAD(sink_list); DEQ_FIND(sink, strcmp(sink->name, name) == 0); if (sink) { @@ -186,8 +156,11 @@ static const log_sink_t *log_sink(const char *name) { file = fopen(name, "a"); } +//If file is not there, return 0. +// We are not logging an error here since we are already holding the log_source_lock +// Writing a log message will try to re-obtain th
[qpid-dispatch] 03/03: Revert "DISPATCH-1956: Changes to sink-side only"
This is an automated email from the ASF dual-hosted git repository. gmurthy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git commit 60a12434e3f4b9f876b3b765178e0ffdf5580bfc Author: Ganesh Murthy AuthorDate: Thu Oct 21 15:33:33 2021 -0400 Revert "DISPATCH-1956: Changes to sink-side only" This reverts commit 25360c6cf6655e85cfb521e0c475b8a6a12bc592. --- src/log.c | 66 --- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/src/log.c b/src/log.c index e032bf6..cac7fbd 100644 --- a/src/log.c +++ b/src/log.c @@ -84,7 +84,6 @@ typedef struct log_sink_t { DEQ_DECLARE(log_sink_t, log_sink_list_t); -static sys_mutex_t *log_sink_list_lock = 0; static log_sink_list_t sink_list = {0}; const char *format = "%Y-%m-%d %H:%M:%S.%%06lu %z"; @@ -111,30 +110,30 @@ static const char* SINK_STDERR = "stderr"; static const char* SINK_SYSLOG = "syslog"; static const char* SOURCE_DEFAULT = "DEFAULT"; -static void log_sink_decref(const log_sink_t *sink) { +static log_sink_t* find_log_sink_lh(const char* name) { +log_sink_t* sink = DEQ_HEAD(sink_list); +DEQ_FIND(sink, strcmp(sink->name, name) == 0); +return sink; +} + +// Must hold the log_source_lock +static void log_sink_free_lh(log_sink_t* sink) { if (!sink) return; -sys_mutex_lock(log_sink_list_lock); assert(sink->ref_count); -log_sink_t *mutable_sink = (log_sink_t *)sink; - -if (sys_atomic_dec(&mutable_sink->ref_count) == 1) { -DEQ_REMOVE(sink_list, mutable_sink); -free(mutable_sink->name); -if (mutable_sink->file && mutable_sink->file != stderr) -fclose(mutable_sink->file); -if (mutable_sink->syslog) +if (sys_atomic_dec(&sink->ref_count) == 1) { +DEQ_REMOVE(sink_list, sink); +free(sink->name); +if (sink->file && sink->file != stderr) +fclose(sink->file); +if (sink->syslog) closelog(); -free(mutable_sink); +free(sink); } -sys_mutex_unlock(log_sink_list_lock); } -static const log_sink_t* log_sink(const char* name) { -sys_mutex_lock(log_sink_list_lock); -log_sink_t* sink = DEQ_HEAD(sink_list); -DEQ_FIND(sink, strcmp(sink->name, name) == 0); - +static log_sink_t* log_sink_lh(const char* name) { +log_sink_t* sink = find_log_sink_lh(name); if (sink) { sys_atomic_inc(&sink->ref_count); } @@ -156,11 +155,12 @@ static const log_sink_t* log_sink(const char* name) { file = fopen(name, "a"); } + + //If file is not there, return 0. // We are not logging an error here since we are already holding the log_source_lock // Writing a log message will try to re-obtain the log_source_lock lock and cause a deadlock. if (!file && !syslog) { -sys_mutex_unlock(log_sink_list_lock); return 0; } @@ -173,8 +173,7 @@ static const log_sink_t* log_sink(const char* name) { DEQ_INSERT_TAIL(sink_list, sink); } -sys_mutex_unlock(log_sink_list_lock); -return (const log_sink_t *)sink; +return sink; } @@ -191,7 +190,7 @@ struct qd_log_source_t { int includeTimestamp; /* boolean or -1 means not set */ int includeSource; /* boolean or -1 means not set */ bool syslog; -const log_sink_t *sink; +log_sink_t *sink; uint64_t severity_histogram[N_LEVEL_INDICES]; }; @@ -306,13 +305,8 @@ static bool default_bool(int value, int default_value) { static void write_log(qd_log_source_t *log_source, qd_log_entry_t *entry) { -// Don't let the sink list change while we are writing to one of them. -sys_mutex_lock(log_sink_list_lock); -const log_sink_t* sink = log_source->sink ? log_source->sink : default_log_source->sink; -if (!sink) { -sys_mutex_unlock(log_sink_list_lock); -return; -} +log_sink_t* sink = log_source->sink ? log_source->sink : default_log_source->sink; +if (!sink) return; char log_str[LOG_MAX]; char *begin = log_str; @@ -345,6 +339,7 @@ static void write_log(qd_log_source_t *log_source, qd_log_entry_t *entry) char msg[TEXT_MAX]; snprintf(msg, sizeof(msg), "Cannot write log output to '%s'", sink->name); perror(msg); +exit(1); }; fflush(sink->file); } @@ -353,7 +348,6 @@ static void write_log(qd_log_source_t *log_source, qd_log_entry_t *entry) if (syslog_level != -1) syslog(syslog_level, "%s", log_str); } -sys_mutex_unlock(log_sink_list_lock); } /// Reset the log source to the default state @@ -401,7 +395,7 @@ qd_log_source_t *qd_log_source_reset(const char *module) static void qd_log_source_free_lh(qd_log_source_t* src) { DEQ_REMOVE(source_list, src); -log_sink_decref(src->sink); +log_sink_free_lh(src->sink);
[qpid-dispatch] branch main updated (fe30749 -> 60a1243)
This is an automated email from the ASF dual-hosted git repository. gmurthy pushed a change to branch main in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git. from fe30749 DISPATCH-2257: test address and disable ipv6 if it is an ipv4 address new b9bdfa2 Revert "DISPATCH-1956: log.c rewrite to reduce locking scope" new c0b50a1 Revert "log.c rewrite part two" new 60a1243 Revert "DISPATCH-1956: Changes to sink-side only" The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: include/qpid/dispatch/log.h | 17 ++- src/log.c | 318 +++- tests/tsan.supp | 2 +- 3 files changed, 147 insertions(+), 190 deletions(-) - To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org
svn commit: r50612 - /release/qpid/protonj2/1.0.0-M3/
Author: tabish Date: Mon Oct 25 15:41:26 2021 New Revision: 50612 Log: Add files for Qpid ProtonJ2 1.0.0-M3 Added: release/qpid/protonj2/1.0.0-M3/ - copied from r50611, dev/qpid/protonj2/1.0.0-M3-rc1/ - To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org