From e3dabe22f8b0b9bd2eddeb94636b201f92e745d2 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 4 Aug 2017 13:58:17 -0400 Subject: [PATCH] common/LogClient: assign seq and queue atomically The _get_mon_log_message() assumes that log_last and log_queue are in sync, but it was previously possible to increment log_last setting e.seq in do_log(), and only later queue it. If a racing thread ran get_mon_log_message() in the meantime it would fail an assertion. Fix by assigning the seq and queueing it atomically. If the cluster log is not enabled, use the get_next_seq() helper so that graylog or syslog messages still have a seq assigned. Fixes: http://tracker.ceph.com/issues/18209 Signed-off-by: Sage Weil (cherry picked from commit 1f8f58becf1ec53c729b0befeb1f19c601588c4a) --- src/common/LogClient.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/common/LogClient.cc b/src/common/LogClient.cc index 07c53e80d9ff7..5e0715aac9ff1 100644 --- a/src/common/LogClient.cc +++ b/src/common/LogClient.cc @@ -224,11 +224,17 @@ void LogChannel::do_log(clog_type prio, const std::string& s) // seq and who should be set for syslog/graylog/log_to_mon e.who = parent->get_myinst(); e.name = parent->get_myname(); - e.seq = parent->get_next_seq(); e.prio = prio; e.msg = s; e.channel = get_log_channel(); + // log to monitor? + if (log_to_monitors) { + e.seq = parent->queue(e); + } else { + e.seq = parent->get_next_seq(); + } + // log to syslog? if (do_log_to_syslog()) { ldout(cct,0) << __func__ << " log to syslog" << dendl; @@ -240,11 +246,6 @@ void LogChannel::do_log(clog_type prio, const std::string& s) ldout(cct,0) << __func__ << " log to graylog" << dendl; graylog->log_log_entry(&e); } - - // log to monitor? - if (log_to_monitors) { - parent->queue(e); - } } Message *LogClient::get_mon_log_message(bool flush) @@ -324,6 +325,7 @@ void LogClient::_send_to_mon() version_t LogClient::queue(LogEntry &entry) { Mutex::Locker l(log_lock); + entry.seq = ++last_log; log_queue.push_back(entry); if (is_mon) { -- 2.39.5