Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012-2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Mark Salyzyn | b338b95 | 2016-10-24 16:22:17 -0700 | [diff] [blame] | 16 | // for manual checking of stale entries during LogBuffer::erase() |
| 17 | //#define DEBUG_CHECK_FOR_STALE_ENTRIES |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 18 | |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 19 | #include <ctype.h> |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 20 | #include <endian.h> |
Mark Salyzyn | 88fe7cc | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 21 | #include <errno.h> |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 22 | #include <stdio.h> |
| 23 | #include <string.h> |
Mark Salyzyn | ab94771 | 2016-10-24 08:20:26 -0700 | [diff] [blame] | 24 | #include <sys/cdefs.h> |
Mark Salyzyn | 7b85c59 | 2014-05-09 17:44:18 -0700 | [diff] [blame] | 25 | #include <sys/user.h> |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 26 | #include <time.h> |
| 27 | #include <unistd.h> |
| 28 | |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 29 | #include <unordered_map> |
Tom Cherry | ac228f1 | 2019-08-21 14:16:34 -0700 | [diff] [blame] | 30 | #include <utility> |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 31 | |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 32 | #include <cutils/properties.h> |
Mark Salyzyn | b004083 | 2016-09-27 13:08:23 -0700 | [diff] [blame] | 33 | #include <private/android_logger.h> |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 34 | |
| 35 | #include "LogBuffer.h" |
Mark Salyzyn | 0e2fe42 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 36 | #include "LogKlog.h" |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 37 | #include "LogReader.h" |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 38 | #include "LogUtils.h" |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 39 | |
Mark Salyzyn | ab94771 | 2016-10-24 08:20:26 -0700 | [diff] [blame] | 40 | #ifndef __predict_false |
| 41 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0) |
| 42 | #endif |
| 43 | |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 44 | // Default |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 45 | #define log_buffer_size(id) mMaxSize[id] |
Mark Salyzyn | 4e756fb | 2014-05-06 07:34:59 -0700 | [diff] [blame] | 46 | |
Mark Salyzyn | 3fe2593 | 2015-03-10 16:45:17 -0700 | [diff] [blame] | 47 | void LogBuffer::init() { |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 48 | log_id_for_each(i) { |
Mark Salyzyn | b004083 | 2016-09-27 13:08:23 -0700 | [diff] [blame] | 49 | if (setSize(i, __android_logger_get_buffer_size(i))) { |
Mark Salyzyn | 7b85c59 | 2014-05-09 17:44:18 -0700 | [diff] [blame] | 50 | setSize(i, LOG_BUFFER_MIN_SIZE); |
| 51 | } |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 52 | } |
Tom Cherry | 9876719 | 2020-05-01 16:45:25 -0700 | [diff] [blame] | 53 | // Release any sleeping reader threads to dump their current content. |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 54 | auto reader_threads_lock = std::lock_guard{reader_list_->reader_threads_lock()}; |
| 55 | for (const auto& reader_thread : reader_list_->reader_threads()) { |
| 56 | reader_thread->triggerReader_Locked(); |
Mark Salyzyn | 0e2fe42 | 2015-09-08 08:56:32 -0700 | [diff] [blame] | 57 | } |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 60 | LogBuffer::LogBuffer(LogReaderList* reader_list, LogTags* tags, PruneList* prune, |
| 61 | LogStatistics* stats) |
| 62 | : reader_list_(reader_list), tags_(tags), prune_(prune), stats_(stats) { |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 63 | pthread_rwlock_init(&mLogElementsLock, nullptr); |
Mark Salyzyn | 3fe2593 | 2015-03-10 16:45:17 -0700 | [diff] [blame] | 64 | |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 65 | log_id_for_each(i) { |
Mark Salyzyn | bec7b2d | 2017-03-31 10:48:39 -0700 | [diff] [blame] | 66 | lastLoggedElements[i] = nullptr; |
| 67 | droppedElements[i] = nullptr; |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Mark Salyzyn | 3fe2593 | 2015-03-10 16:45:17 -0700 | [diff] [blame] | 70 | init(); |
| 71 | } |
| 72 | |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 73 | LogBuffer::~LogBuffer() { |
| 74 | log_id_for_each(i) { |
| 75 | delete lastLoggedElements[i]; |
| 76 | delete droppedElements[i]; |
| 77 | } |
| 78 | } |
| 79 | |
Tom Cherry | 402364e | 2020-04-29 17:58:18 -0700 | [diff] [blame] | 80 | LogBufferElementCollection::iterator LogBuffer::GetOldest(log_id_t log_id) { |
| 81 | auto it = mLogElements.begin(); |
Tom Cherry | 02017d7 | 2020-05-04 10:17:42 -0700 | [diff] [blame] | 82 | if (oldest_[log_id]) { |
| 83 | it = *oldest_[log_id]; |
Tom Cherry | 402364e | 2020-04-29 17:58:18 -0700 | [diff] [blame] | 84 | } |
| 85 | while (it != mLogElements.end() && (*it)->getLogId() != log_id) { |
| 86 | it++; |
| 87 | } |
| 88 | if (it != mLogElements.end()) { |
Tom Cherry | 02017d7 | 2020-05-04 10:17:42 -0700 | [diff] [blame] | 89 | oldest_[log_id] = it; |
Tom Cherry | 402364e | 2020-04-29 17:58:18 -0700 | [diff] [blame] | 90 | } |
| 91 | return it; |
| 92 | } |
| 93 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 94 | enum match_type { DIFFERENT, SAME, SAME_LIBLOG }; |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 95 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 96 | static enum match_type identical(LogBufferElement* elem, |
| 97 | LogBufferElement* last) { |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 98 | // is it mostly identical? |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 99 | // if (!elem) return DIFFERENT; |
Mark Salyzyn | 530bd6c | 2016-08-11 08:02:06 -0700 | [diff] [blame] | 100 | ssize_t lenl = elem->getMsgLen(); |
| 101 | if (lenl <= 0) return DIFFERENT; // value if this represents a chatty elem |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 102 | // if (!last) return DIFFERENT; |
Mark Salyzyn | 530bd6c | 2016-08-11 08:02:06 -0700 | [diff] [blame] | 103 | ssize_t lenr = last->getMsgLen(); |
| 104 | if (lenr <= 0) return DIFFERENT; // value if this represents a chatty elem |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 105 | // if (elem->getLogId() != last->getLogId()) return DIFFERENT; |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 106 | if (elem->getUid() != last->getUid()) return DIFFERENT; |
| 107 | if (elem->getPid() != last->getPid()) return DIFFERENT; |
| 108 | if (elem->getTid() != last->getTid()) return DIFFERENT; |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 109 | |
| 110 | // last is more than a minute old, stop squashing identical messages |
| 111 | if (elem->getRealTime().nsec() > |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 112 | (last->getRealTime().nsec() + 60 * NS_PER_SEC)) |
| 113 | return DIFFERENT; |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 114 | |
| 115 | // Identical message |
| 116 | const char* msgl = elem->getMsg(); |
| 117 | const char* msgr = last->getMsg(); |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 118 | if (lenl == lenr) { |
| 119 | if (!fastcmp<memcmp>(msgl, msgr, lenl)) return SAME; |
| 120 | // liblog tagged messages (content gets summed) |
| 121 | if ((elem->getLogId() == LOG_ID_EVENTS) && |
| 122 | (lenl == sizeof(android_log_event_int_t)) && |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 123 | !fastcmp<memcmp>(msgl, msgr, sizeof(android_log_event_int_t) - |
| 124 | sizeof(int32_t)) && |
Mark Salyzyn | 6b344a8 | 2017-03-13 15:41:59 -0700 | [diff] [blame] | 125 | (elem->getTag() == LIBLOG_LOG_TAG)) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 126 | return SAME_LIBLOG; |
Mark Salyzyn | 6b344a8 | 2017-03-13 15:41:59 -0700 | [diff] [blame] | 127 | } |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 128 | } |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 129 | |
| 130 | // audit message (except sequence number) identical? |
Mark Salyzyn | 34aad62 | 2018-03-13 11:06:38 -0700 | [diff] [blame] | 131 | if (last->isBinary() && |
| 132 | (lenl > static_cast<ssize_t>(sizeof(android_log_event_string_t))) && |
| 133 | (lenr > static_cast<ssize_t>(sizeof(android_log_event_string_t)))) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 134 | if (fastcmp<memcmp>(msgl, msgr, sizeof(android_log_event_string_t) - |
Mark Salyzyn | 6b344a8 | 2017-03-13 15:41:59 -0700 | [diff] [blame] | 135 | sizeof(int32_t))) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 136 | return DIFFERENT; |
Mark Salyzyn | 6b344a8 | 2017-03-13 15:41:59 -0700 | [diff] [blame] | 137 | } |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 138 | msgl += sizeof(android_log_event_string_t); |
| 139 | lenl -= sizeof(android_log_event_string_t); |
| 140 | msgr += sizeof(android_log_event_string_t); |
| 141 | lenr -= sizeof(android_log_event_string_t); |
| 142 | } |
Mark Salyzyn | 530bd6c | 2016-08-11 08:02:06 -0700 | [diff] [blame] | 143 | static const char avc[] = "): avc: "; |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 144 | const char* avcl = android::strnstr(msgl, lenl, avc); |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 145 | if (!avcl) return DIFFERENT; |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 146 | lenl -= avcl - msgl; |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 147 | const char* avcr = android::strnstr(msgr, lenr, avc); |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 148 | if (!avcr) return DIFFERENT; |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 149 | lenr -= avcr - msgr; |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 150 | if (lenl != lenr) return DIFFERENT; |
Mark Salyzyn | 530bd6c | 2016-08-11 08:02:06 -0700 | [diff] [blame] | 151 | if (fastcmp<memcmp>(avcl + strlen(avc), avcr + strlen(avc), |
Mark Salyzyn | 6b344a8 | 2017-03-13 15:41:59 -0700 | [diff] [blame] | 152 | lenl - strlen(avc))) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 153 | return DIFFERENT; |
Mark Salyzyn | 6b344a8 | 2017-03-13 15:41:59 -0700 | [diff] [blame] | 154 | } |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 155 | return SAME; |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 158 | int LogBuffer::log(log_id_t log_id, log_time realtime, uid_t uid, pid_t pid, |
Chih-Hung Hsieh | 9ff8155 | 2018-08-13 14:22:56 -0700 | [diff] [blame] | 159 | pid_t tid, const char* msg, uint16_t len) { |
Yi Kong | 90bcc18 | 2018-03-01 17:48:53 -0500 | [diff] [blame] | 160 | if (log_id >= LOG_ID_MAX) { |
Mark Salyzyn | 88fe7cc | 2015-02-09 08:21:05 -0800 | [diff] [blame] | 161 | return -EINVAL; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 162 | } |
Mark Salyzyn | 0dcfae6 | 2014-10-02 13:07:05 -0700 | [diff] [blame] | 163 | |
Mark Salyzyn | cb722de | 2017-05-18 10:06:00 -0700 | [diff] [blame] | 164 | // Slip the time by 1 nsec if the incoming lands on xxxxxx000 ns. |
| 165 | // This prevents any chance that an outside source can request an |
| 166 | // exact entry with time specified in ms or us precision. |
| 167 | if ((realtime.tv_nsec % 1000) == 0) ++realtime.tv_nsec; |
| 168 | |
Tom Cherry | 6955f8b | 2020-02-20 13:21:51 -0800 | [diff] [blame] | 169 | LogBufferElement* elem = new LogBufferElement(log_id, realtime, uid, pid, tid, msg, len); |
| 170 | |
| 171 | // b/137093665: don't coalesce security messages. |
| 172 | if (log_id == LOG_ID_SECURITY) { |
| 173 | wrlock(); |
| 174 | log(elem); |
| 175 | unlock(); |
| 176 | |
| 177 | return len; |
| 178 | } |
| 179 | |
| 180 | int prio = ANDROID_LOG_INFO; |
| 181 | const char* tag = nullptr; |
| 182 | size_t tag_len = 0; |
| 183 | if (log_id == LOG_ID_EVENTS || log_id == LOG_ID_STATS) { |
Tom Cherry | 04ad458 | 2020-05-01 16:13:18 -0700 | [diff] [blame] | 184 | tag = tags_->tagToName(elem->getTag()); |
Tom Cherry | 6955f8b | 2020-02-20 13:21:51 -0800 | [diff] [blame] | 185 | if (tag) { |
| 186 | tag_len = strlen(tag); |
Mark Salyzyn | c969086 | 2015-12-04 10:59:45 -0800 | [diff] [blame] | 187 | } |
Tom Cherry | 6955f8b | 2020-02-20 13:21:51 -0800 | [diff] [blame] | 188 | } else { |
| 189 | prio = *msg; |
| 190 | tag = msg + 1; |
| 191 | tag_len = strnlen(tag, len - 1); |
| 192 | } |
| 193 | if (!__android_log_is_loggable_len(prio, tag, tag_len, ANDROID_LOG_VERBOSE)) { |
| 194 | // Log traffic received to total |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 195 | stats_->AddTotal(elem); |
Tom Cherry | 6955f8b | 2020-02-20 13:21:51 -0800 | [diff] [blame] | 196 | delete elem; |
| 197 | return -EACCES; |
Mark Salyzyn | 0dcfae6 | 2014-10-02 13:07:05 -0700 | [diff] [blame] | 198 | } |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 199 | |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 200 | wrlock(); |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 201 | LogBufferElement* currentLast = lastLoggedElements[log_id]; |
| 202 | if (currentLast) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 203 | LogBufferElement* dropped = droppedElements[log_id]; |
Chih-Hung Hsieh | 9ff8155 | 2018-08-13 14:22:56 -0700 | [diff] [blame] | 204 | uint16_t count = dropped ? dropped->getDropped() : 0; |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 205 | // |
| 206 | // State Init |
| 207 | // incoming: |
Mark Salyzyn | bec7b2d | 2017-03-31 10:48:39 -0700 | [diff] [blame] | 208 | // dropped = nullptr |
| 209 | // currentLast = nullptr; |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 210 | // elem = incoming message |
| 211 | // outgoing: |
Mark Salyzyn | bec7b2d | 2017-03-31 10:48:39 -0700 | [diff] [blame] | 212 | // dropped = nullptr -> State 0 |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 213 | // currentLast = copy of elem |
| 214 | // log elem |
| 215 | // State 0 |
| 216 | // incoming: |
| 217 | // count = 0 |
Mark Salyzyn | bec7b2d | 2017-03-31 10:48:39 -0700 | [diff] [blame] | 218 | // dropped = nullptr |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 219 | // currentLast = copy of last message |
| 220 | // elem = incoming message |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 221 | // outgoing: if match != DIFFERENT |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 222 | // dropped = copy of first identical message -> State 1 |
| 223 | // currentLast = reference to elem |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 224 | // break: if match == DIFFERENT |
Mark Salyzyn | bec7b2d | 2017-03-31 10:48:39 -0700 | [diff] [blame] | 225 | // dropped = nullptr -> State 0 |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 226 | // delete copy of last message (incoming currentLast) |
| 227 | // currentLast = copy of elem |
| 228 | // log elem |
| 229 | // State 1 |
| 230 | // incoming: |
| 231 | // count = 0 |
| 232 | // dropped = copy of first identical message |
| 233 | // currentLast = reference to last held-back incoming |
| 234 | // message |
| 235 | // elem = incoming message |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 236 | // outgoing: if match == SAME |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 237 | // delete copy of first identical message (dropped) |
| 238 | // dropped = reference to last held-back incoming |
| 239 | // message set to chatty count of 1 -> State 2 |
| 240 | // currentLast = reference to elem |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 241 | // outgoing: if match == SAME_LIBLOG |
| 242 | // dropped = copy of first identical message -> State 1 |
| 243 | // take sum of currentLast and elem |
| 244 | // if sum overflows: |
| 245 | // log currentLast |
| 246 | // currentLast = reference to elem |
| 247 | // else |
| 248 | // delete currentLast |
| 249 | // currentLast = reference to elem, sum liblog. |
| 250 | // break: if match == DIFFERENT |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 251 | // delete dropped |
Mark Salyzyn | bec7b2d | 2017-03-31 10:48:39 -0700 | [diff] [blame] | 252 | // dropped = nullptr -> State 0 |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 253 | // log reference to last held-back (currentLast) |
| 254 | // currentLast = copy of elem |
| 255 | // log elem |
| 256 | // State 2 |
| 257 | // incoming: |
| 258 | // count = chatty count |
| 259 | // dropped = chatty message holding count |
| 260 | // currentLast = reference to last held-back incoming |
| 261 | // message. |
| 262 | // dropped = chatty message holding count |
| 263 | // elem = incoming message |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 264 | // outgoing: if match != DIFFERENT |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 265 | // delete chatty message holding count |
| 266 | // dropped = reference to last held-back incoming |
| 267 | // message, set to chatty count + 1 |
| 268 | // currentLast = reference to elem |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 269 | // break: if match == DIFFERENT |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 270 | // log dropped (chatty message) |
Mark Salyzyn | bec7b2d | 2017-03-31 10:48:39 -0700 | [diff] [blame] | 271 | // dropped = nullptr -> State 0 |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 272 | // log reference to last held-back (currentLast) |
| 273 | // currentLast = copy of elem |
| 274 | // log elem |
| 275 | // |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 276 | enum match_type match = identical(elem, currentLast); |
| 277 | if (match != DIFFERENT) { |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 278 | if (dropped) { |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 279 | // Sum up liblog tag messages? |
| 280 | if ((count == 0) /* at Pass 1 */ && (match == SAME_LIBLOG)) { |
| 281 | android_log_event_int_t* event = |
| 282 | reinterpret_cast<android_log_event_int_t*>( |
| 283 | const_cast<char*>(currentLast->getMsg())); |
| 284 | // |
| 285 | // To unit test, differentiate with something like: |
| 286 | // event->header.tag = htole32(CHATTY_LOG_TAG); |
| 287 | // here, then instead of delete currentLast below, |
| 288 | // log(currentLast) to see the incremental sums form. |
| 289 | // |
| 290 | uint32_t swab = event->payload.data; |
| 291 | unsigned long long total = htole32(swab); |
| 292 | event = reinterpret_cast<android_log_event_int_t*>( |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 293 | const_cast<char*>(elem->getMsg())); |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 294 | swab = event->payload.data; |
| 295 | |
| 296 | lastLoggedElements[LOG_ID_EVENTS] = elem; |
| 297 | total += htole32(swab); |
| 298 | // check for overflow |
| 299 | if (total >= UINT32_MAX) { |
| 300 | log(currentLast); |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 301 | unlock(); |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 302 | return len; |
| 303 | } |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 304 | stats_->AddTotal(currentLast); |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 305 | delete currentLast; |
| 306 | swab = total; |
| 307 | event->payload.data = htole32(swab); |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 308 | unlock(); |
Mark Salyzyn | 60b9992 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 309 | return len; |
| 310 | } |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 311 | if (count == USHRT_MAX) { |
| 312 | log(dropped); |
| 313 | count = 1; |
| 314 | } else { |
| 315 | delete dropped; |
| 316 | ++count; |
| 317 | } |
| 318 | } |
| 319 | if (count) { |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 320 | stats_->AddTotal(currentLast); |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 321 | currentLast->setDropped(count); |
| 322 | } |
| 323 | droppedElements[log_id] = currentLast; |
| 324 | lastLoggedElements[log_id] = elem; |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 325 | unlock(); |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 326 | return len; |
| 327 | } |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 328 | if (dropped) { // State 1 or 2 |
| 329 | if (count) { // State 2 |
| 330 | log(dropped); // report chatty |
| 331 | } else { // State 1 |
| 332 | delete dropped; |
Mark Salyzyn | 52ee5f5 | 2016-12-16 16:09:15 -0800 | [diff] [blame] | 333 | } |
Mark Salyzyn | bec7b2d | 2017-03-31 10:48:39 -0700 | [diff] [blame] | 334 | droppedElements[log_id] = nullptr; |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 335 | log(currentLast); // report last message in the series |
| 336 | } else { // State 0 |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 337 | delete currentLast; |
| 338 | } |
| 339 | } |
| 340 | lastLoggedElements[log_id] = new LogBufferElement(*elem); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 341 | |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 342 | log(elem); |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 343 | unlock(); |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 344 | |
| 345 | return len; |
| 346 | } |
| 347 | |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 348 | // assumes LogBuffer::wrlock() held, owns elem, look after garbage collection |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 349 | void LogBuffer::log(LogBufferElement* elem) { |
Tom Cherry | 16935b4 | 2019-08-21 13:17:12 -0700 | [diff] [blame] | 350 | mLogElements.push_back(elem); |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 351 | stats_->Add(elem); |
Mark Salyzyn | 24a57dc | 2016-12-13 10:31:29 -0800 | [diff] [blame] | 352 | maybePrune(elem->getLogId()); |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 353 | reader_list_->NotifyNewLog(1 << elem->getLogId()); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 354 | } |
| 355 | |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 356 | // LogBuffer::wrlock() must be held when this function is called. |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 357 | void LogBuffer::maybePrune(log_id_t id) { |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 358 | unsigned long prune_rows; |
| 359 | if (stats_->ShouldPrune(id, log_buffer_size(id), &prune_rows)) { |
| 360 | prune(id, prune_rows); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
Mark Salyzyn | 1fdf71f | 2015-09-03 16:08:50 -0700 | [diff] [blame] | 364 | LogBufferElementCollection::iterator LogBuffer::erase( |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 365 | LogBufferElementCollection::iterator it, bool coalesce) { |
| 366 | LogBufferElement* element = *it; |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 367 | log_id_t id = element->getLogId(); |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 368 | |
Mark Salyzyn | 1117818 | 2016-10-21 09:46:42 -0700 | [diff] [blame] | 369 | // Remove iterator references in the various lists that will become stale |
| 370 | // after the element is erased from the main logging list. |
| 371 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 372 | { // start of scope for found iterator |
| 373 | int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY)) |
| 374 | ? element->getTag() |
| 375 | : element->getUid(); |
Mark Salyzyn | 6fa0d03 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 376 | LogBufferIteratorMap::iterator found = mLastWorst[id].find(key); |
| 377 | if ((found != mLastWorst[id].end()) && (it == found->second)) { |
| 378 | mLastWorst[id].erase(found); |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 379 | } |
Mark Salyzyn | 5af07be | 2015-08-19 17:06:11 -0700 | [diff] [blame] | 380 | } |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 381 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 382 | { // start of scope for pid found iterator |
Mark Salyzyn | 1117818 | 2016-10-21 09:46:42 -0700 | [diff] [blame] | 383 | // element->getUid() may not be AID_SYSTEM for next-best-watermark. |
Mark Salyzyn | ab94771 | 2016-10-24 08:20:26 -0700 | [diff] [blame] | 384 | // will not assume id != LOG_ID_EVENTS or LOG_ID_SECURITY for KISS and |
| 385 | // long term code stability, find() check should be fast for those ids. |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 386 | LogBufferPidIteratorMap::iterator found = |
| 387 | mLastWorstPidOfSystem[id].find(element->getPid()); |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 388 | if ((found != mLastWorstPidOfSystem[id].end()) && |
| 389 | (it == found->second)) { |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 390 | mLastWorstPidOfSystem[id].erase(found); |
| 391 | } |
| 392 | } |
| 393 | |
Mark Salyzyn | 75d5cf0 | 2016-01-19 16:04:41 -0800 | [diff] [blame] | 394 | bool setLast[LOG_ID_MAX]; |
| 395 | bool doSetLast = false; |
Tom Cherry | 02017d7 | 2020-05-04 10:17:42 -0700 | [diff] [blame] | 396 | log_id_for_each(i) { doSetLast |= setLast[i] = oldest_[i] && it == *oldest_[i]; } |
Mark Salyzyn | b338b95 | 2016-10-24 16:22:17 -0700 | [diff] [blame] | 397 | #ifdef DEBUG_CHECK_FOR_STALE_ENTRIES |
| 398 | LogBufferElementCollection::iterator bad = it; |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 399 | int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY)) |
| 400 | ? element->getTag() |
| 401 | : element->getUid(); |
Mark Salyzyn | b338b95 | 2016-10-24 16:22:17 -0700 | [diff] [blame] | 402 | #endif |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 403 | it = mLogElements.erase(it); |
Mark Salyzyn | 75d5cf0 | 2016-01-19 16:04:41 -0800 | [diff] [blame] | 404 | if (doSetLast) { |
| 405 | log_id_for_each(i) { |
| 406 | if (setLast[i]) { |
Tom Cherry | 402364e | 2020-04-29 17:58:18 -0700 | [diff] [blame] | 407 | if (__predict_false(it == mLogElements.end())) { |
Tom Cherry | 02017d7 | 2020-05-04 10:17:42 -0700 | [diff] [blame] | 408 | oldest_[i] = std::nullopt; |
Mark Salyzyn | 75d5cf0 | 2016-01-19 16:04:41 -0800 | [diff] [blame] | 409 | } else { |
Tom Cherry | 02017d7 | 2020-05-04 10:17:42 -0700 | [diff] [blame] | 410 | oldest_[i] = it; // Store the next iterator even if it does not correspond to |
Tom Cherry | 402364e | 2020-04-29 17:58:18 -0700 | [diff] [blame] | 411 | // the same log_id, as a starting point for GetOldest(). |
Mark Salyzyn | 75d5cf0 | 2016-01-19 16:04:41 -0800 | [diff] [blame] | 412 | } |
| 413 | } |
Mark Salyzyn | b7dd96e | 2016-01-11 10:58:09 -0800 | [diff] [blame] | 414 | } |
| 415 | } |
Mark Salyzyn | b338b95 | 2016-10-24 16:22:17 -0700 | [diff] [blame] | 416 | #ifdef DEBUG_CHECK_FOR_STALE_ENTRIES |
| 417 | log_id_for_each(i) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 418 | for (auto b : mLastWorst[i]) { |
Mark Salyzyn | b338b95 | 2016-10-24 16:22:17 -0700 | [diff] [blame] | 419 | if (bad == b.second) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 420 | android::prdebug("stale mLastWorst[%d] key=%d mykey=%d\n", i, |
| 421 | b.first, key); |
Mark Salyzyn | b338b95 | 2016-10-24 16:22:17 -0700 | [diff] [blame] | 422 | } |
| 423 | } |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 424 | for (auto b : mLastWorstPidOfSystem[i]) { |
Mark Salyzyn | b338b95 | 2016-10-24 16:22:17 -0700 | [diff] [blame] | 425 | if (bad == b.second) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 426 | android::prdebug("stale mLastWorstPidOfSystem[%d] pid=%d\n", i, |
| 427 | b.first); |
Mark Salyzyn | b338b95 | 2016-10-24 16:22:17 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
Mark Salyzyn | b338b95 | 2016-10-24 16:22:17 -0700 | [diff] [blame] | 430 | } |
| 431 | #endif |
Mark Salyzyn | 5c5189a | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 432 | if (coalesce) { |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 433 | stats_->Erase(element); |
Mark Salyzyn | 5c5189a | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 434 | } else { |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 435 | stats_->Subtract(element); |
Mark Salyzyn | 1fdf71f | 2015-09-03 16:08:50 -0700 | [diff] [blame] | 436 | } |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 437 | delete element; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 438 | |
| 439 | return it; |
| 440 | } |
| 441 | |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 442 | // Define a temporary mechanism to report the last LogBufferElement pointer |
| 443 | // for the specified uid, pid and tid. Used below to help merge-sort when |
| 444 | // pruning for worst UID. |
| 445 | class LogBufferElementKey { |
| 446 | const union { |
| 447 | struct { |
Mark Salyzyn | 16aacd3 | 2016-12-13 12:44:20 -0800 | [diff] [blame] | 448 | uint32_t uid; |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 449 | uint16_t pid; |
| 450 | uint16_t tid; |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 451 | } __packed; |
| 452 | uint64_t value; |
| 453 | } __packed; |
| 454 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 455 | public: |
| 456 | LogBufferElementKey(uid_t uid, pid_t pid, pid_t tid) |
| 457 | : uid(uid), pid(pid), tid(tid) { |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 458 | } |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 459 | explicit LogBufferElementKey(uint64_t key) : value(key) { |
| 460 | } |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 461 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 462 | uint64_t getKey() { |
| 463 | return value; |
| 464 | } |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 465 | }; |
| 466 | |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 467 | class LogBufferElementLast { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 468 | typedef std::unordered_map<uint64_t, LogBufferElement*> LogBufferElementMap; |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 469 | LogBufferElementMap map; |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 470 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 471 | public: |
Chih-Hung Hsieh | 9ff8155 | 2018-08-13 14:22:56 -0700 | [diff] [blame] | 472 | bool coalesce(LogBufferElement* element, uint16_t dropped) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 473 | LogBufferElementKey key(element->getUid(), element->getPid(), |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 474 | element->getTid()); |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 475 | LogBufferElementMap::iterator it = map.find(key.getKey()); |
| 476 | if (it != map.end()) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 477 | LogBufferElement* found = it->second; |
Chih-Hung Hsieh | 9ff8155 | 2018-08-13 14:22:56 -0700 | [diff] [blame] | 478 | uint16_t moreDropped = found->getDropped(); |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 479 | if ((dropped + moreDropped) > USHRT_MAX) { |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 480 | map.erase(it); |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 481 | } else { |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 482 | found->setDropped(dropped + moreDropped); |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 483 | return true; |
| 484 | } |
| 485 | } |
| 486 | return false; |
| 487 | } |
| 488 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 489 | void add(LogBufferElement* element) { |
| 490 | LogBufferElementKey key(element->getUid(), element->getPid(), |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 491 | element->getTid()); |
| 492 | map[key.getKey()] = element; |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Mark Salyzyn | be1a30c | 2015-04-20 14:08:56 -0700 | [diff] [blame] | 495 | inline void clear() { |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 496 | map.clear(); |
Mark Salyzyn | be1a30c | 2015-04-20 14:08:56 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 499 | void clear(LogBufferElement* element) { |
Tom Cherry | ac228f1 | 2019-08-21 14:16:34 -0700 | [diff] [blame] | 500 | uint64_t current = element->getRealTime().nsec() - (EXPIRE_RATELIMIT * NS_PER_SEC); |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 501 | for (LogBufferElementMap::iterator it = map.begin(); it != map.end();) { |
| 502 | LogBufferElement* mapElement = it->second; |
Tom Cherry | ac228f1 | 2019-08-21 14:16:34 -0700 | [diff] [blame] | 503 | if (mapElement->getDropped() >= EXPIRE_THRESHOLD && |
| 504 | current > mapElement->getRealTime().nsec()) { |
Mark Salyzyn | 6a40419 | 2015-05-19 09:12:30 -0700 | [diff] [blame] | 505 | it = map.erase(it); |
| 506 | } else { |
| 507 | ++it; |
Mark Salyzyn | be1a30c | 2015-04-20 14:08:56 -0700 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | } |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 511 | }; |
| 512 | |
Mark Salyzyn | 434f374 | 2017-05-11 13:28:33 -0700 | [diff] [blame] | 513 | // If the selected reader is blocking our pruning progress, decide on |
| 514 | // what kind of mitigation is necessary to unblock the situation. |
Tom Cherry | 1647cd4 | 2020-05-04 12:53:36 -0700 | [diff] [blame] | 515 | void LogBuffer::kickMe(LogReaderThread* me, log_id_t id, unsigned long pruneRows) { |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 516 | if (stats_->Sizes(id) > (2 * log_buffer_size(id))) { // +100% |
Mark Salyzyn | 434f374 | 2017-05-11 13:28:33 -0700 | [diff] [blame] | 517 | // A misbehaving or slow reader has its connection |
| 518 | // dropped if we hit too much memory pressure. |
Tom Cherry | 59fc119 | 2019-11-15 17:37:03 -0800 | [diff] [blame] | 519 | android::prdebug("Kicking blocked reader, pid %d, from LogBuffer::kickMe()\n", |
Tom Cherry | 7e3bc96 | 2020-05-04 17:10:16 -0700 | [diff] [blame] | 520 | me->client()->getPid()); |
Mark Salyzyn | 434f374 | 2017-05-11 13:28:33 -0700 | [diff] [blame] | 521 | me->release_Locked(); |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 522 | } else if (me->deadline().time_since_epoch().count() != 0) { |
| 523 | // Allow a blocked WRAP deadline reader to trigger and start reporting the log data. |
Mark Salyzyn | 434f374 | 2017-05-11 13:28:33 -0700 | [diff] [blame] | 524 | me->triggerReader_Locked(); |
| 525 | } else { |
| 526 | // tell slow reader to skip entries to catch up |
Tom Cherry | 59fc119 | 2019-11-15 17:37:03 -0800 | [diff] [blame] | 527 | android::prdebug( |
| 528 | "Skipping %lu entries from slow reader, pid %d, from LogBuffer::kickMe()\n", |
Tom Cherry | 7e3bc96 | 2020-05-04 17:10:16 -0700 | [diff] [blame] | 529 | pruneRows, me->client()->getPid()); |
Mark Salyzyn | 434f374 | 2017-05-11 13:28:33 -0700 | [diff] [blame] | 530 | me->triggerSkip_Locked(id, pruneRows); |
| 531 | } |
| 532 | } |
| 533 | |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 534 | // prune "pruneRows" of type "id" from the buffer. |
| 535 | // |
Mark Salyzyn | e2827d5 | 2015-09-08 09:12:51 -0700 | [diff] [blame] | 536 | // This garbage collection task is used to expire log entries. It is called to |
| 537 | // remove all logs (clear), all UID logs (unprivileged clear), or every |
| 538 | // 256 or 10% of the total logs (whichever is less) to prune the logs. |
| 539 | // |
| 540 | // First there is a prep phase where we discover the reader region lock that |
| 541 | // acts as a backstop to any pruning activity to stop there and go no further. |
| 542 | // |
| 543 | // There are three major pruning loops that follow. All expire from the oldest |
| 544 | // entries. Since there are multiple log buffers, the Android logging facility |
| 545 | // will appear to drop entries 'in the middle' when looking at multiple log |
| 546 | // sources and buffers. This effect is slightly more prominent when we prune |
| 547 | // the worst offender by logging source. Thus the logs slowly loose content |
| 548 | // and value as you move back in time. This is preferred since chatty sources |
| 549 | // invariably move the logs value down faster as less chatty sources would be |
| 550 | // expired in the noise. |
| 551 | // |
| 552 | // The first loop performs blacklisting and worst offender pruning. Falling |
| 553 | // through when there are no notable worst offenders and have not hit the |
| 554 | // region lock preventing further worst offender pruning. This loop also looks |
| 555 | // after managing the chatty log entries and merging to help provide |
| 556 | // statistical basis for blame. The chatty entries are not a notification of |
| 557 | // how much logs you may have, but instead represent how much logs you would |
| 558 | // have had in a virtual log buffer that is extended to cover all the in-memory |
| 559 | // logs without loss. They last much longer than the represented pruned logs |
| 560 | // since they get multiplied by the gains in the non-chatty log sources. |
| 561 | // |
| 562 | // The second loop get complicated because an algorithm of watermarks and |
| 563 | // history is maintained to reduce the order and keep processing time |
| 564 | // down to a minimum at scale. These algorithms can be costly in the face |
| 565 | // of larger log buffers, or severly limited processing time granted to a |
| 566 | // background task at lowest priority. |
| 567 | // |
| 568 | // This second loop does straight-up expiration from the end of the logs |
| 569 | // (again, remember for the specified log buffer id) but does some whitelist |
| 570 | // preservation. Thus whitelist is a Hail Mary low priority, blacklists and |
| 571 | // spam filtration all take priority. This second loop also checks if a region |
| 572 | // lock is causing us to buffer too much in the logs to help the reader(s), |
| 573 | // and will tell the slowest reader thread to skip log entries, and if |
| 574 | // persistent and hits a further threshold, kill the reader thread. |
| 575 | // |
| 576 | // The third thread is optional, and only gets hit if there was a whitelist |
| 577 | // and more needs to be pruned against the backstop of the region lock. |
| 578 | // |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 579 | // LogBuffer::wrlock() must be held when this function is called. |
Mark Salyzyn | e2827d5 | 2015-09-08 09:12:51 -0700 | [diff] [blame] | 580 | // |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 581 | bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { |
Tom Cherry | 1647cd4 | 2020-05-04 12:53:36 -0700 | [diff] [blame] | 582 | LogReaderThread* oldest = nullptr; |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 583 | bool busy = false; |
Mark Salyzyn | 71541f3 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 584 | bool clearAll = pruneRows == ULONG_MAX; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 585 | |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 586 | auto reader_threads_lock = std::lock_guard{reader_list_->reader_threads_lock()}; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 587 | |
| 588 | // Region locked? |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 589 | for (const auto& reader_thread : reader_list_->reader_threads()) { |
| 590 | if (!reader_thread->IsWatching(id)) { |
| 591 | continue; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 592 | } |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 593 | if (!oldest || oldest->start() > reader_thread->start() || |
| 594 | (oldest->start() == reader_thread->start() && |
| 595 | reader_thread->deadline().time_since_epoch().count() != 0)) { |
| 596 | oldest = reader_thread.get(); |
| 597 | } |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 598 | } |
| 599 | |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 600 | LogBufferElementCollection::iterator it; |
| 601 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 602 | if (__predict_false(caller_uid != AID_ROOT)) { // unlikely |
Mark Salyzyn | 9e0c78e | 2016-09-01 15:48:36 -0700 | [diff] [blame] | 603 | // Only here if clear all request from non system source, so chatty |
| 604 | // filter logistics is not required. |
Tom Cherry | 402364e | 2020-04-29 17:58:18 -0700 | [diff] [blame] | 605 | it = GetOldest(id); |
Mark Salyzyn | b7dd96e | 2016-01-11 10:58:09 -0800 | [diff] [blame] | 606 | while (it != mLogElements.end()) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 607 | LogBufferElement* element = *it; |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 608 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 609 | if ((element->getLogId() != id) || |
| 610 | (element->getUid() != caller_uid)) { |
Mark Salyzyn | 71541f3 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 611 | ++it; |
| 612 | continue; |
| 613 | } |
| 614 | |
Tom Cherry | 7e3bc96 | 2020-05-04 17:10:16 -0700 | [diff] [blame] | 615 | if (oldest && oldest->start() <= element->getSequence()) { |
Tom Cherry | bc02eff | 2020-04-08 10:47:26 -0700 | [diff] [blame] | 616 | busy = true; |
| 617 | kickMe(oldest, id, pruneRows); |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 618 | break; |
| 619 | } |
| 620 | |
Mark Salyzyn | 71541f3 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 621 | it = erase(it); |
Mark Salyzyn | 9e0c78e | 2016-09-01 15:48:36 -0700 | [diff] [blame] | 622 | if (--pruneRows == 0) { |
| 623 | break; |
| 624 | } |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 625 | } |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 626 | return busy; |
Mark Salyzyn | 276d535 | 2014-06-12 11:16:16 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 629 | // prune by worst offenders; by blacklist, UID, and by PID of system UID |
Tom Cherry | 4bd63ef | 2020-05-01 17:03:20 -0700 | [diff] [blame] | 630 | bool hasBlacklist = (id != LOG_ID_SECURITY) && prune_->naughty(); |
Mark Salyzyn | 71541f3 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 631 | while (!clearAll && (pruneRows > 0)) { |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 632 | // recalculate the worst offender on every batched pass |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 633 | int worst = -1; // not valid for getUid() or getKey() |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 634 | size_t worst_sizes = 0; |
| 635 | size_t second_worst_sizes = 0; |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 636 | pid_t worstPid = 0; // POSIX guarantees PID != 0 |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 637 | |
Tom Cherry | 4bd63ef | 2020-05-01 17:03:20 -0700 | [diff] [blame] | 638 | if (worstUidEnabledForLogid(id) && prune_->worstUidEnabled()) { |
Mark Salyzyn | 6fa0d03 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 639 | // Calculate threshold as 12.5% of available storage |
| 640 | size_t threshold = log_buffer_size(id) / 8; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 641 | |
Tom Cherry | 4011d5a | 2020-05-07 09:13:12 -0700 | [diff] [blame] | 642 | if (id == LOG_ID_EVENTS || id == LOG_ID_SECURITY) { |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 643 | stats_->WorstTwoTags(threshold, &worst, &worst_sizes, &second_worst_sizes); |
Mark Salyzyn | ab94771 | 2016-10-24 08:20:26 -0700 | [diff] [blame] | 644 | // per-pid filter for AID_SYSTEM sources is too complex |
Mark Salyzyn | 6fa0d03 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 645 | } else { |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 646 | stats_->WorstTwoUids(id, threshold, &worst, &worst_sizes, &second_worst_sizes); |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 647 | |
Tom Cherry | 4011d5a | 2020-05-07 09:13:12 -0700 | [diff] [blame] | 648 | if (worst == AID_SYSTEM && prune_->worstPidOfSystemEnabled()) { |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 649 | stats_->WorstTwoSystemPids(id, worst_sizes, &worstPid, &second_worst_sizes); |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 650 | } |
| 651 | } |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 652 | } |
| 653 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 654 | // skip if we have neither worst nor naughty filters |
Mark Salyzyn | 6fa0d03 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 655 | if ((worst == -1) && !hasBlacklist) { |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 656 | break; |
| 657 | } |
| 658 | |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 659 | bool kick = false; |
Tom Cherry | 402364e | 2020-04-29 17:58:18 -0700 | [diff] [blame] | 660 | bool leading = true; // true if starting from the oldest log entry, false if starting from |
| 661 | // a specific chatty entry. |
Mark Salyzyn | e2827d5 | 2015-09-08 09:12:51 -0700 | [diff] [blame] | 662 | // Perform at least one mandatory garbage collection cycle in following |
| 663 | // - clear leading chatty tags |
Mark Salyzyn | 5c5189a | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 664 | // - coalesce chatty tags |
Mark Salyzyn | e2827d5 | 2015-09-08 09:12:51 -0700 | [diff] [blame] | 665 | // - check age-out of preserved logs |
| 666 | bool gc = pruneRows <= 1; |
Mark Salyzyn | 6fa0d03 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 667 | if (!gc && (worst != -1)) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 668 | { // begin scope for worst found iterator |
| 669 | LogBufferIteratorMap::iterator found = |
| 670 | mLastWorst[id].find(worst); |
| 671 | if ((found != mLastWorst[id].end()) && |
| 672 | (found->second != mLogElements.end())) { |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 673 | leading = false; |
| 674 | it = found->second; |
| 675 | } |
| 676 | } |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 677 | if (worstPid) { // begin scope for pid worst found iterator |
Mark Salyzyn | ab94771 | 2016-10-24 08:20:26 -0700 | [diff] [blame] | 678 | // FYI: worstPid only set if !LOG_ID_EVENTS and |
| 679 | // !LOG_ID_SECURITY, not going to make that assumption ... |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 680 | LogBufferPidIteratorMap::iterator found = |
| 681 | mLastWorstPidOfSystem[id].find(worstPid); |
| 682 | if ((found != mLastWorstPidOfSystem[id].end()) && |
| 683 | (found->second != mLogElements.end())) { |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 684 | leading = false; |
| 685 | it = found->second; |
| 686 | } |
Mark Salyzyn | 5af07be | 2015-08-19 17:06:11 -0700 | [diff] [blame] | 687 | } |
| 688 | } |
Tom Cherry | 402364e | 2020-04-29 17:58:18 -0700 | [diff] [blame] | 689 | if (leading) { |
| 690 | it = GetOldest(id); |
| 691 | } |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 692 | static const timespec too_old = { EXPIRE_HOUR_THRESHOLD * 60 * 60, 0 }; |
Mark Salyzyn | 7f62d6b | 2015-08-24 13:43:27 -0700 | [diff] [blame] | 693 | LogBufferElementCollection::iterator lastt; |
| 694 | lastt = mLogElements.end(); |
| 695 | --lastt; |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 696 | LogBufferElementLast last; |
Mark Salyzyn | 5af07be | 2015-08-19 17:06:11 -0700 | [diff] [blame] | 697 | while (it != mLogElements.end()) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 698 | LogBufferElement* element = *it; |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 699 | |
Tom Cherry | 7e3bc96 | 2020-05-04 17:10:16 -0700 | [diff] [blame] | 700 | if (oldest && oldest->start() <= element->getSequence()) { |
Tom Cherry | bc02eff | 2020-04-08 10:47:26 -0700 | [diff] [blame] | 701 | busy = true; |
Mark Salyzyn | 434f374 | 2017-05-11 13:28:33 -0700 | [diff] [blame] | 702 | // Do not let chatty eliding trigger any reader mitigation |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 703 | break; |
| 704 | } |
| 705 | |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 706 | if (element->getLogId() != id) { |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 707 | ++it; |
| 708 | continue; |
| 709 | } |
Mark Salyzyn | 1117818 | 2016-10-21 09:46:42 -0700 | [diff] [blame] | 710 | // below this point element->getLogId() == id |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 711 | |
Chih-Hung Hsieh | 9ff8155 | 2018-08-13 14:22:56 -0700 | [diff] [blame] | 712 | uint16_t dropped = element->getDropped(); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 713 | |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 714 | // remove any leading drops |
| 715 | if (leading && dropped) { |
| 716 | it = erase(it); |
| 717 | continue; |
| 718 | } |
| 719 | |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 720 | if (dropped && last.coalesce(element, dropped)) { |
Mark Salyzyn | 5c5189a | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 721 | it = erase(it, true); |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 722 | continue; |
| 723 | } |
| 724 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 725 | int key = ((id == LOG_ID_EVENTS) || (id == LOG_ID_SECURITY)) |
| 726 | ? element->getTag() |
| 727 | : element->getUid(); |
Mark Salyzyn | 6fa0d03 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 728 | |
Tom Cherry | 4bd63ef | 2020-05-01 17:03:20 -0700 | [diff] [blame] | 729 | if (hasBlacklist && prune_->naughty(element)) { |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 730 | last.clear(element); |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 731 | it = erase(it); |
| 732 | if (dropped) { |
| 733 | continue; |
| 734 | } |
| 735 | |
| 736 | pruneRows--; |
| 737 | if (pruneRows == 0) { |
| 738 | break; |
| 739 | } |
| 740 | |
Mark Salyzyn | 6fa0d03 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 741 | if (key == worst) { |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 742 | kick = true; |
| 743 | if (worst_sizes < second_worst_sizes) { |
| 744 | break; |
| 745 | } |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 746 | worst_sizes -= element->getMsgLen(); |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 747 | } |
| 748 | continue; |
| 749 | } |
| 750 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 751 | if ((element->getRealTime() < ((*lastt)->getRealTime() - too_old)) || |
| 752 | (element->getRealTime() > (*lastt)->getRealTime())) { |
Mark Salyzyn | 7f62d6b | 2015-08-24 13:43:27 -0700 | [diff] [blame] | 753 | break; |
| 754 | } |
| 755 | |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 756 | if (dropped) { |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 757 | last.add(element); |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 758 | if (worstPid && |
| 759 | ((!gc && (element->getPid() == worstPid)) || |
| 760 | (mLastWorstPidOfSystem[id].find(element->getPid()) == |
| 761 | mLastWorstPidOfSystem[id].end()))) { |
Mark Salyzyn | 1117818 | 2016-10-21 09:46:42 -0700 | [diff] [blame] | 762 | // element->getUid() may not be AID_SYSTEM, next best |
Mark Salyzyn | ab94771 | 2016-10-24 08:20:26 -0700 | [diff] [blame] | 763 | // watermark if current one empty. id is not LOG_ID_EVENTS |
| 764 | // or LOG_ID_SECURITY because of worstPid check. |
Mark Salyzyn | ce50dec | 2016-09-01 07:28:44 -0700 | [diff] [blame] | 765 | mLastWorstPidOfSystem[id][element->getPid()] = it; |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 766 | } |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 767 | if ((!gc && !worstPid && (key == worst)) || |
| 768 | (mLastWorst[id].find(key) == mLastWorst[id].end())) { |
Mark Salyzyn | 6fa0d03 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 769 | mLastWorst[id][key] = it; |
Mark Salyzyn | 76aab49 | 2015-08-24 13:43:27 -0700 | [diff] [blame] | 770 | } |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 771 | ++it; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 772 | continue; |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 773 | } |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 774 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 775 | if ((key != worst) || |
| 776 | (worstPid && (element->getPid() != worstPid))) { |
Mark Salyzyn | fd318a8 | 2015-06-01 09:41:19 -0700 | [diff] [blame] | 777 | leading = false; |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 778 | last.clear(element); |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 779 | ++it; |
| 780 | continue; |
| 781 | } |
Mark Salyzyn | 1117818 | 2016-10-21 09:46:42 -0700 | [diff] [blame] | 782 | // key == worst below here |
| 783 | // If worstPid set, then element->getPid() == worstPid below here |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 784 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 785 | pruneRows--; |
| 786 | if (pruneRows == 0) { |
| 787 | break; |
| 788 | } |
| 789 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 790 | kick = true; |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 791 | |
Chih-Hung Hsieh | 9ff8155 | 2018-08-13 14:22:56 -0700 | [diff] [blame] | 792 | uint16_t len = element->getMsgLen(); |
Mark Salyzyn | 65ec860 | 2015-05-22 10:03:31 -0700 | [diff] [blame] | 793 | |
| 794 | // do not create any leading drops |
| 795 | if (leading) { |
| 796 | it = erase(it); |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 797 | } else { |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 798 | stats_->Drop(element); |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 799 | element->setDropped(1); |
| 800 | if (last.coalesce(element, 1)) { |
Mark Salyzyn | 5c5189a | 2015-09-30 07:40:09 -0700 | [diff] [blame] | 801 | it = erase(it, true); |
Mark Salyzyn | 65ec860 | 2015-05-22 10:03:31 -0700 | [diff] [blame] | 802 | } else { |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 803 | last.add(element); |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 804 | if (worstPid && |
| 805 | (!gc || (mLastWorstPidOfSystem[id].find(worstPid) == |
| 806 | mLastWorstPidOfSystem[id].end()))) { |
Mark Salyzyn | 1117818 | 2016-10-21 09:46:42 -0700 | [diff] [blame] | 807 | // element->getUid() may not be AID_SYSTEM, next best |
Mark Salyzyn | ab94771 | 2016-10-24 08:20:26 -0700 | [diff] [blame] | 808 | // watermark if current one empty. id is not |
| 809 | // LOG_ID_EVENTS or LOG_ID_SECURITY because of worstPid. |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 810 | mLastWorstPidOfSystem[id][worstPid] = it; |
| 811 | } |
Mark Salyzyn | 6fa0d03 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 812 | if ((!gc && !worstPid) || |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 813 | (mLastWorst[id].find(worst) == mLastWorst[id].end())) { |
Mark Salyzyn | 6fa0d03 | 2016-07-14 15:34:30 -0700 | [diff] [blame] | 814 | mLastWorst[id][worst] = it; |
Mark Salyzyn | e2827d5 | 2015-09-08 09:12:51 -0700 | [diff] [blame] | 815 | } |
Mark Salyzyn | 65ec860 | 2015-05-22 10:03:31 -0700 | [diff] [blame] | 816 | ++it; |
| 817 | } |
Mark Salyzyn | a69d5a4 | 2015-03-16 12:04:09 -0700 | [diff] [blame] | 818 | } |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 819 | if (worst_sizes < second_worst_sizes) { |
| 820 | break; |
| 821 | } |
| 822 | worst_sizes -= len; |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 823 | } |
Mark Salyzyn | d84b27e | 2015-04-17 15:38:04 -0700 | [diff] [blame] | 824 | last.clear(); |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 825 | |
Tom Cherry | 4bd63ef | 2020-05-01 17:03:20 -0700 | [diff] [blame] | 826 | if (!kick || !prune_->worstUidEnabled()) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 827 | break; // the following loop will ask bad clients to skip/drop |
Mark Salyzyn | 5c06ca4 | 2014-02-06 18:11:13 -0800 | [diff] [blame] | 828 | } |
| 829 | } |
| 830 | |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 831 | bool whitelist = false; |
Tom Cherry | 4bd63ef | 2020-05-01 17:03:20 -0700 | [diff] [blame] | 832 | bool hasWhitelist = (id != LOG_ID_SECURITY) && prune_->nice() && !clearAll; |
Tom Cherry | 402364e | 2020-04-29 17:58:18 -0700 | [diff] [blame] | 833 | it = GetOldest(id); |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 834 | while ((pruneRows > 0) && (it != mLogElements.end())) { |
| 835 | LogBufferElement* element = *it; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 836 | |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 837 | if (element->getLogId() != id) { |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 838 | it++; |
| 839 | continue; |
| 840 | } |
| 841 | |
Tom Cherry | 7e3bc96 | 2020-05-04 17:10:16 -0700 | [diff] [blame] | 842 | if (oldest && oldest->start() <= element->getSequence()) { |
Tom Cherry | bc02eff | 2020-04-08 10:47:26 -0700 | [diff] [blame] | 843 | busy = true; |
| 844 | if (!whitelist) kickMe(oldest, id, pruneRows); |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 845 | break; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 846 | } |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 847 | |
Tom Cherry | 4bd63ef | 2020-05-01 17:03:20 -0700 | [diff] [blame] | 848 | if (hasWhitelist && !element->getDropped() && prune_->nice(element)) { |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 849 | // WhiteListed |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 850 | whitelist = true; |
| 851 | it++; |
| 852 | continue; |
| 853 | } |
| 854 | |
| 855 | it = erase(it); |
| 856 | pruneRows--; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 857 | } |
| 858 | |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 859 | // Do not save the whitelist if we are reader range limited |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 860 | if (whitelist && (pruneRows > 0)) { |
Tom Cherry | 402364e | 2020-04-29 17:58:18 -0700 | [diff] [blame] | 861 | it = GetOldest(id); |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 862 | while ((it != mLogElements.end()) && (pruneRows > 0)) { |
| 863 | LogBufferElement* element = *it; |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 864 | |
Mark Salyzyn | edcbdfa | 2015-08-28 08:02:59 -0700 | [diff] [blame] | 865 | if (element->getLogId() != id) { |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 866 | ++it; |
| 867 | continue; |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 868 | } |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 869 | |
Tom Cherry | 7e3bc96 | 2020-05-04 17:10:16 -0700 | [diff] [blame] | 870 | if (oldest && oldest->start() <= element->getSequence()) { |
Tom Cherry | bc02eff | 2020-04-08 10:47:26 -0700 | [diff] [blame] | 871 | busy = true; |
| 872 | kickMe(oldest, id, pruneRows); |
Mark Salyzyn | 9cf5d40 | 2015-03-10 13:51:35 -0700 | [diff] [blame] | 873 | break; |
| 874 | } |
| 875 | |
| 876 | it = erase(it); |
| 877 | pruneRows--; |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 878 | } |
| 879 | } |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 880 | |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 881 | return (pruneRows > 0) && busy; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | // clear all rows of type "id" from the buffer. |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 885 | bool LogBuffer::clear(log_id_t id, uid_t uid) { |
| 886 | bool busy = true; |
| 887 | // If it takes more than 4 tries (seconds) to clear, then kill reader(s) |
| 888 | for (int retry = 4;;) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 889 | if (retry == 1) { // last pass |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 890 | // Check if it is still busy after the sleep, we say prune |
| 891 | // one entry, not another clear run, so we are looking for |
| 892 | // the quick side effect of the return value to tell us if |
| 893 | // we have a _blocked_ reader. |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 894 | wrlock(); |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 895 | busy = prune(id, 1, uid); |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 896 | unlock(); |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 897 | // It is still busy, blocked reader(s), lets kill them all! |
| 898 | // otherwise, lets be a good citizen and preserve the slow |
| 899 | // readers and let the clear run (below) deal with determining |
| 900 | // if we are still blocked and return an error code to caller. |
| 901 | if (busy) { |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 902 | auto reader_threads_lock = std::lock_guard{reader_list_->reader_threads_lock()}; |
| 903 | for (const auto& reader_thread : reader_list_->reader_threads()) { |
| 904 | if (reader_thread->IsWatching(id)) { |
Tom Cherry | 59fc119 | 2019-11-15 17:37:03 -0800 | [diff] [blame] | 905 | android::prdebug( |
| 906 | "Kicking blocked reader, pid %d, from LogBuffer::clear()\n", |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 907 | reader_thread->client()->getPid()); |
| 908 | reader_thread->release_Locked(); |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 909 | } |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 910 | } |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 911 | } |
| 912 | } |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 913 | wrlock(); |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 914 | busy = prune(id, ULONG_MAX, uid); |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 915 | unlock(); |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 916 | if (!busy || !--retry) { |
| 917 | break; |
| 918 | } |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 919 | sleep(1); // Let reader(s) catch up after notification |
Mark Salyzyn | 8cf0d03 | 2015-09-16 15:34:00 -0700 | [diff] [blame] | 920 | } |
| 921 | return busy; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 922 | } |
| 923 | |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 924 | // set the total space allocated to "id" |
| 925 | int LogBuffer::setSize(log_id_t id, unsigned long size) { |
| 926 | // Reasonable limits ... |
Mark Salyzyn | b004083 | 2016-09-27 13:08:23 -0700 | [diff] [blame] | 927 | if (!__android_logger_valid_buffer_size(size)) { |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 928 | return -1; |
| 929 | } |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 930 | wrlock(); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 931 | log_buffer_size(id) = size; |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 932 | unlock(); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | // get the total space allocated to "id" |
| 937 | unsigned long LogBuffer::getSize(log_id_t id) { |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 938 | rdlock(); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 939 | size_t retval = log_buffer_size(id); |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 940 | unlock(); |
Mark Salyzyn | c89839a | 2014-02-11 12:29:31 -0800 | [diff] [blame] | 941 | return retval; |
| 942 | } |
| 943 | |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 944 | uint64_t LogBuffer::flushTo( |
| 945 | SocketClient* reader, uint64_t start, pid_t* lastTid, bool privileged, bool security, |
| 946 | const std::function<FlushToResult(const LogBufferElement* element)>& filter) { |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 947 | LogBufferElementCollection::iterator it; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 948 | uid_t uid = reader->getUid(); |
| 949 | |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 950 | rdlock(); |
Dragoslav Mitrinovic | 81624f2 | 2015-01-15 09:29:43 -0600 | [diff] [blame] | 951 | |
Tom Cherry | ac228f1 | 2019-08-21 14:16:34 -0700 | [diff] [blame] | 952 | if (start <= 1) { |
Dragoslav Mitrinovic | 81624f2 | 2015-01-15 09:29:43 -0600 | [diff] [blame] | 953 | // client wants to start from the beginning |
| 954 | it = mLogElements.begin(); |
| 955 | } else { |
| 956 | // Client wants to start from some specified time. Chances are |
| 957 | // we are better off starting from the end of the time sorted list. |
Tom Cherry | ac228f1 | 2019-08-21 14:16:34 -0700 | [diff] [blame] | 958 | for (it = mLogElements.end(); it != mLogElements.begin(); |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 959 | /* do nothing */) { |
Dragoslav Mitrinovic | 81624f2 | 2015-01-15 09:29:43 -0600 | [diff] [blame] | 960 | --it; |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 961 | LogBufferElement* element = *it; |
Tom Cherry | ac228f1 | 2019-08-21 14:16:34 -0700 | [diff] [blame] | 962 | if (element->getSequence() <= start) { |
| 963 | it++; |
Dragoslav Mitrinovic | 81624f2 | 2015-01-15 09:29:43 -0600 | [diff] [blame] | 964 | break; |
| 965 | } |
| 966 | } |
| 967 | } |
| 968 | |
Tom Cherry | ac228f1 | 2019-08-21 14:16:34 -0700 | [diff] [blame] | 969 | uint64_t curr = start; |
Mark Salyzyn | 1d7b071 | 2017-01-23 14:20:31 -0800 | [diff] [blame] | 970 | |
Dragoslav Mitrinovic | 81624f2 | 2015-01-15 09:29:43 -0600 | [diff] [blame] | 971 | for (; it != mLogElements.end(); ++it) { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 972 | LogBufferElement* element = *it; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 973 | |
| 974 | if (!privileged && (element->getUid() != uid)) { |
| 975 | continue; |
| 976 | } |
| 977 | |
Mark Salyzyn | b10f737 | 2016-01-26 14:32:35 -0800 | [diff] [blame] | 978 | if (!security && (element->getLogId() == LOG_ID_SECURITY)) { |
| 979 | continue; |
| 980 | } |
| 981 | |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 982 | // NB: calling out to another object with wrlock() held (safe) |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 983 | if (filter) { |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 984 | FlushToResult ret = filter(element); |
| 985 | if (ret == FlushToResult::kSkip) { |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 986 | continue; |
| 987 | } |
Tom Cherry | 5ecfbf0 | 2020-05-11 16:29:29 -0700 | [diff] [blame^] | 988 | if (ret == FlushToResult::kStop) { |
Mark Salyzyn | 0aaf6cd | 2015-03-03 13:39:37 -0800 | [diff] [blame] | 989 | break; |
| 990 | } |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 991 | } |
| 992 | |
Mark Salyzyn | bec7b2d | 2017-03-31 10:48:39 -0700 | [diff] [blame] | 993 | bool sameTid = false; |
| 994 | if (lastTid) { |
| 995 | sameTid = lastTid[element->getLogId()] == element->getTid(); |
| 996 | // Dropped (chatty) immediately following a valid log from the |
| 997 | // same source in the same log buffer indicates we have a |
| 998 | // multiple identical squash. chatty that differs source |
| 999 | // is due to spam filter. chatty to chatty of different |
| 1000 | // source is also due to spam filter. |
| 1001 | lastTid[element->getLogId()] = |
| 1002 | (element->getDropped() && !sameTid) ? 0 : element->getTid(); |
| 1003 | } |
Mark Salyzyn | 1d7b071 | 2017-01-23 14:20:31 -0800 | [diff] [blame] | 1004 | |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 1005 | unlock(); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1006 | |
| 1007 | // range locking in LastLogTimes looks after us |
Tom Cherry | 479b503 | 2020-05-07 14:44:43 -0700 | [diff] [blame] | 1008 | curr = element->flushTo(reader, stats_, sameTid); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1009 | |
Mark Salyzyn | cb722de | 2017-05-18 10:06:00 -0700 | [diff] [blame] | 1010 | if (curr == element->FLUSH_ERROR) { |
| 1011 | return curr; |
Mark Salyzyn | e2c1ea4 | 2017-05-17 19:55:12 +0000 | [diff] [blame] | 1012 | } |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1013 | |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 1014 | rdlock(); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1015 | } |
Mark Salyzyn | d2712b1 | 2017-04-18 14:09:45 -0700 | [diff] [blame] | 1016 | unlock(); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1017 | |
Mark Salyzyn | cb722de | 2017-05-18 10:06:00 -0700 | [diff] [blame] | 1018 | return curr; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 1019 | } |