From d7dee1639a68d17a5bca9c88dcd7deded73f4870 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Fri, 24 Jul 2020 10:14:25 +0000 Subject: [PATCH] common/bl: don't access raw::len directly. Use the getter instead. Signed-off-by: Radoslaw Zarzynski --- src/common/buffer.cc | 19 +++++++++---------- src/include/buffer_raw.h | 5 ++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 7e07667b3f6a..ee2bdc1e9e28 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -359,7 +359,7 @@ static ceph::spinlock debug_lock; buffer::ptr::ptr(ceph::unique_leakable_ptr r) : _raw(r.release()), _off(0), - _len(_raw->len) + _len(_raw->get_len()) { _raw->nref.store(1, std::memory_order_release); bdout << "ptr " << this << " get " << _raw << bendl; @@ -474,7 +474,7 @@ static ceph::spinlock debug_lock; (1 == cached_raw->nref.load(std::memory_order_acquire)); if (likely(last_one) || --cached_raw->nref == 0) { bdout << "deleting raw " << static_cast(cached_raw) - << " len " << cached_raw->len << bendl; + << " len " << cached_raw->get_len() << bendl; ANNOTATE_HAPPENS_AFTER(&cached_raw->nref); ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(&cached_raw->nref); delete cached_raw; // dealloc old (if any) @@ -521,10 +521,7 @@ static ceph::spinlock debug_lock; unsigned buffer::ptr::unused_tail_length() const { - if (_raw) - return _raw->len - (_off+_len); - else - return 0; + return _raw ? _raw->get_len() - (_off + _len) : 0; } const char& buffer::ptr::operator[](unsigned n) const { @@ -540,7 +537,7 @@ static ceph::spinlock debug_lock; } const char *buffer::ptr::raw_c_str() const { ceph_assert(_raw); return _raw->get_data(); } - unsigned buffer::ptr::raw_length() const { ceph_assert(_raw); return _raw->len; } + unsigned buffer::ptr::raw_length() const { ceph_assert(_raw); return _raw->get_len(); } int buffer::ptr::raw_nref() const { ceph_assert(_raw); return _raw->nref; } void buffer::ptr::copy_out(unsigned o, unsigned l, char *dest) const { @@ -553,7 +550,7 @@ static ceph::spinlock debug_lock; unsigned buffer::ptr::wasted() const { - return _raw->len - _len; + return _raw->get_len() - _len; } int buffer::ptr::cmp(const ptr& o) const @@ -1156,7 +1153,7 @@ static ceph::spinlock debug_lock; if (r == last) continue; last = r; - total += r->len; + total += r->get_len(); } // If multiple buffers are sharing the same raw buffer and they overlap // with each other, the wasted space will be underestimated. @@ -2179,7 +2176,9 @@ buffer::ptr_node* buffer::ptr_node::cloner::operator()( } std::ostream& buffer::operator<<(std::ostream& out, const buffer::raw &r) { - return out << "buffer::raw(" << (void*)r.get_data() << " len " << r.len << " nref " << r.nref.load() << ")"; + return out << "buffer::raw(" + << (void*)r.get_data() << " len " << r.get_len() + << " nref " << r.nref.load() << ")"; } std::ostream& buffer::operator<<(std::ostream& out, const buffer::ptr& bp) { diff --git a/src/include/buffer_raw.h b/src/include/buffer_raw.h index fe59860d5e9c..890fb04d5b2f 100644 --- a/src/include/buffer_raw.h +++ b/src/include/buffer_raw.h @@ -34,8 +34,8 @@ inline namespace v15_2_0 { alignof(ptr_node)>::type bptr_storage; protected: char *data; - public: unsigned len; + public: ceph::atomic nref { 0 }; int mempool; @@ -89,6 +89,9 @@ public: char *get_data() const { return data; } + unsigned get_len() const { + return len; + } virtual raw* clone_empty() = 0; ceph::unique_leakable_ptr clone() { raw* const c = clone_empty(); -- 2.47.3