| 235 | #define dout_subsys ceph_subsys_ms |
| 236 | |
| 237 | void Message::encode(uint64_t features, int crcflags, bool skip_header_crc) |
| 238 | { |
| 239 | // encode and copy out of *m |
| 240 | if (empty_payload()) { |
| 241 | ceph_assert(middle.length() == 0); |
| 242 | encode_payload(features); |
| 243 | |
| 244 | if (byte_throttler) { |
| 245 | byte_throttler->take(payload.length() + middle.length()); |
| 246 | } |
| 247 | |
| 248 | // if the encoder didn't specify past compatibility, we assume it |
| 249 | // is incompatible. |
| 250 | if (header.compat_version == 0) |
| 251 | header.compat_version = header.version; |
| 252 | } |
| 253 | if (crcflags & MSG_CRC_HEADER) |
| 254 | calc_front_crc(); |
| 255 | |
| 256 | // update envelope |
| 257 | header.front_len = get_payload().length(); |
| 258 | header.middle_len = get_middle().length(); |
| 259 | header.data_len = get_data().length(); |
| 260 | if (!skip_header_crc && (crcflags & MSG_CRC_HEADER)) |
| 261 | calc_header_crc(); |
| 262 | |
| 263 | footer.flags = CEPH_MSG_FOOTER_COMPLETE; |
| 264 | |
| 265 | if (crcflags & MSG_CRC_DATA) { |
| 266 | calc_data_crc(); |
| 267 | |
| 268 | #ifdef ENCODE_DUMP |
| 269 | bufferlist bl; |
| 270 | encode(get_header(), bl); |
| 271 | |
| 272 | // dump the old footer format |
| 273 | ceph_msg_footer_old old_footer; |
| 274 | old_footer.front_crc = footer.front_crc; |
| 275 | old_footer.middle_crc = footer.middle_crc; |
| 276 | old_footer.data_crc = footer.data_crc; |
| 277 | old_footer.flags = footer.flags; |
| 278 | encode(old_footer, bl); |
| 279 | |
| 280 | encode(get_payload(), bl); |
| 281 | encode(get_middle(), bl); |
| 282 | encode(get_data(), bl); |
| 283 | |
| 284 | // this is almost an exponential backoff, except because we count |
| 285 | // bits we tend to sample things we encode later, which should be |
| 286 | // more representative. |
| 287 | static int i = 0; |
| 288 | i++; |
| 289 | int bits = 0; |
| 290 | for (unsigned t = i; t; bits++) |
| 291 | t &= t - 1; |
| 292 | if (bits <= 2) { |
| 293 | char fn[200]; |
| 294 | int status; |
no test coverage detected