From: Josh Durgin Date: Wed, 16 Oct 2013 23:23:36 +0000 (-0700) Subject: buffer: abstract raw data related methods X-Git-Tag: v0.74~65^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ebb261f9780669aba1963f7216ebc653204f659a;p=ceph.git buffer: abstract raw data related methods Create a virtual function that returns the raw data instead of accessing it directly, so raw buffers backed by pipes can be used as buffer::ptrs. Make raw::is_page_aligned() virtual so it will not need to look at the raw data for a pipe-based buffer. Signed-off-by: Josh Durgin --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 493070557159..9dd98310d97e 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -89,6 +89,9 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE raw(const raw &other); const raw& operator=(const raw &other); + virtual char *get_data() { + return data; + } virtual raw* clone_empty() = 0; raw *clone() { raw *c = clone_empty(); @@ -100,7 +103,7 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE return len; } - bool is_page_aligned() { + virtual bool is_page_aligned() { return ((long)data & ~CEPH_PAGE_MASK) == 0; } bool is_n_page_sized() { @@ -375,8 +378,14 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE bool buffer::ptr::at_buffer_tail() const { return _off + _len == _raw->len; } - const char *buffer::ptr::c_str() const { assert(_raw); return _raw->data + _off; } - char *buffer::ptr::c_str() { assert(_raw); return _raw->data + _off; } + const char *buffer::ptr::c_str() const { + assert(_raw); + return _raw->get_data() + _off; + } + char *buffer::ptr::c_str() { + assert(_raw); + return _raw->get_data() + _off; + } unsigned buffer::ptr::unused_tail_length() const { @@ -389,13 +398,13 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE { assert(_raw); assert(n < _len); - return _raw->data[_off + n]; + return _raw->get_data()[_off + n]; } char& buffer::ptr::operator[](unsigned n) { assert(_raw); assert(n < _len); - return _raw->data[_off + n]; + return _raw->get_data()[_off + n]; } const char *buffer::ptr::raw_c_str() const { assert(_raw); return _raw->data; }