From: Radoslaw Zarzynski Date: Wed, 22 Jul 2020 18:57:51 +0000 (+0000) Subject: common/bl: don't access raw::data directly. Use the getter instead. X-Git-Tag: v16.1.0~1617^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=053e6fa97c70b47912bc9ab9b37de16018da8410;p=ceph.git common/bl: don't access raw::data directly. Use the getter instead. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 6ac87306c932..7e07667b3f6a 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -279,7 +279,7 @@ static ceph::spinlock debug_lock; ceph::unique_leakable_ptr buffer::copy(const char *c, unsigned len) { auto r = buffer::create_aligned(len, sizeof(size_t)); - memcpy(r->data, c, len); + memcpy(r->get_data(), c, len); return r; } @@ -288,7 +288,7 @@ static ceph::spinlock debug_lock; } ceph::unique_leakable_ptr buffer::create(unsigned len, char c) { auto ret = buffer::create_aligned(len, sizeof(size_t)); - memset(ret->data, c, len); + memset(ret->get_data(), c, len); return ret; } ceph::unique_leakable_ptr @@ -539,7 +539,7 @@ static ceph::spinlock debug_lock; return _raw->get_data()[_off + n]; } - const char *buffer::ptr::raw_c_str() const { ceph_assert(_raw); return _raw->data; } + 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; } int buffer::ptr::raw_nref() const { ceph_assert(_raw); return _raw->nref; } @@ -547,7 +547,7 @@ static ceph::spinlock debug_lock; ceph_assert(_raw); if (o+l > _len) throw end_of_buffer(); - char* src = _raw->data + _off + o; + char* src = _raw->get_data() + _off + o; maybe_inline_memcpy(dest, src, l, 8); } @@ -580,7 +580,7 @@ static ceph::spinlock debug_lock; { ceph_assert(_raw); ceph_assert(1 <= unused_tail_length()); - char* ptr = _raw->data + _off + _len; + char* ptr = _raw->get_data() + _off + _len; *ptr = c; _len++; return _len + _off; @@ -590,7 +590,7 @@ static ceph::spinlock debug_lock; { ceph_assert(_raw); ceph_assert(l <= unused_tail_length()); - char* c = _raw->data + _off + _len; + char* c = _raw->get_data() + _off + _len; maybe_inline_memcpy(c, p, l, 32); _len += l; return _len + _off; @@ -600,7 +600,7 @@ static ceph::spinlock debug_lock; { ceph_assert(_raw); ceph_assert(l <= unused_tail_length()); - char* c = _raw->data + _off + _len; + char* c = _raw->get_data() + _off + _len; // FIPS zeroization audit 20191115: this memset is not security related. memset(c, 0, l); _len += l; @@ -612,7 +612,7 @@ static ceph::spinlock debug_lock; ceph_assert(_raw); ceph_assert(o <= _len); ceph_assert(o+l <= _len); - char* dest = _raw->data + _off + o; + char* dest = _raw->get_data() + _off + o; if (crc_reset) _raw->invalidate_crc(); maybe_inline_memcpy(dest, src, l, 64); @@ -2179,7 +2179,7 @@ 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.data << " len " << r.len << " nref " << r.nref.load() << ")"; + return out << "buffer::raw(" << (void*)r.get_data() << " len " << r.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 6483edd73f96..fe59860d5e9c 100644 --- a/src/include/buffer_raw.h +++ b/src/include/buffer_raw.h @@ -32,7 +32,9 @@ inline namespace v15_2_0 { // embedded slots. This would allow to avoid the "if" in dtor of ptr_node. std::aligned_storage::type bptr_storage; + protected: char *data; + public: unsigned len; ceph::atomic nref { 0 }; int mempool; @@ -84,7 +86,7 @@ private: raw(const raw &other) = delete; const raw& operator=(const raw &other) = delete; public: - char *get_data() { + char *get_data() const { return data; } virtual raw* clone_empty() = 0;