Skip to content

Commit

Permalink
buffer: restored pre-infernalis API compatibility
Browse files Browse the repository at this point in the history
Fixes: ceph#13429
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
  • Loading branch information
Jason Dillaman committed Oct 9, 2015
1 parent 010836d commit cac1d6f
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 7 deletions.
89 changes: 88 additions & 1 deletion src/common/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,12 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
_len += l;
return _len + _off;
}


void buffer::ptr::copy_in(unsigned o, unsigned l, const char *src)
{
copy_in(o, l, src, true);
}

void buffer::ptr::copy_in(unsigned o, unsigned l, const char *src, bool crc_reset)
{
assert(_raw);
Expand All @@ -855,13 +860,23 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
maybe_inline_memcpy(dest, src, l, 64);
}

void buffer::ptr::zero()
{
zero(true);
}

void buffer::ptr::zero(bool crc_reset)
{
if (crc_reset)
_raw->invalidate_crc();
memset(c_str(), 0, _len);
}

void buffer::ptr::zero(unsigned o, unsigned l)
{
zero(o, l, true);
}

void buffer::ptr::zero(unsigned o, unsigned l, bool crc_reset)
{
assert(o+l <= _len);
Expand Down Expand Up @@ -1063,6 +1078,68 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
template class buffer::list::iterator_impl<true>;
template class buffer::list::iterator_impl<false>;

void buffer::list::iterator::advance(int o)
{
buffer::list::iterator_impl<false>::advance(o);
}

void buffer::list::iterator::seek(unsigned o)
{
buffer::list::iterator_impl<false>::seek(o);
}

char buffer::list::iterator::operator*()
{
if (p == ls->end()) {
throw end_of_buffer();
}
return (*p)[p_off];
}

buffer::list::iterator& buffer::list::iterator::operator++()
{
buffer::list::iterator_impl<false>::operator++();
return *this;
}

buffer::ptr buffer::list::iterator::get_current_ptr()
{
if (p == ls->end()) {
throw end_of_buffer();
}
return ptr(*p, p_off, p->length() - p_off);
}

void buffer::list::iterator::copy(unsigned len, char *dest)
{
return buffer::list::iterator_impl<false>::copy(len, dest);
}

void buffer::list::iterator::copy(unsigned len, ptr &dest)
{
buffer::list::iterator_impl<false>::copy(len, dest);
}

void buffer::list::iterator::copy(unsigned len, list &dest)
{
buffer::list::iterator_impl<false>::copy(len, dest);
}

void buffer::list::iterator::copy(unsigned len, std::string &dest)
{
buffer::list::iterator_impl<false>::copy(len, dest);
}

void buffer::list::iterator::copy_all(list &dest)
{
buffer::list::iterator_impl<false>::copy_all(dest);
}

void buffer::list::iterator::copy_in(unsigned len, const char *src)
{
copy_in(len, src, true);
}

// copy data in
void buffer::list::iterator::copy_in(unsigned len, const char *src, bool crc_reset)
{
Expand Down Expand Up @@ -1125,6 +1202,11 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
other.last_p = other.begin();
}

bool buffer::list::contents_equal(buffer::list& other)
{
return static_cast<const buffer::list*>(this)->contents_equal(other);
}

bool buffer::list::contents_equal(const ceph::buffer::list& other) const
{
if (length() != other.length())
Expand Down Expand Up @@ -1403,6 +1485,11 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
return last_p.copy(len, dest);
}

void buffer::list::copy_in(unsigned off, unsigned len, const char *src)
{
copy_in(off, len, src, true);
}

void buffer::list::copy_in(unsigned off, unsigned len, const char *src, bool crc_reset)
{
if (off + len > length())
Expand Down
33 changes: 27 additions & 6 deletions src/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,12 @@ class CEPH_BUFFER_API buffer {

unsigned append(char c);
unsigned append(const char *p, unsigned l);
void copy_in(unsigned o, unsigned l, const char *src, bool crc_reset = true);
void zero(bool crc_reset = true);
void zero(unsigned o, unsigned l, bool crc_reset = true);
void copy_in(unsigned o, unsigned l, const char *src);
void copy_in(unsigned o, unsigned l, const char *src, bool crc_reset);
void zero();
void zero(bool crc_reset);
void zero(unsigned o, unsigned l);
void zero(unsigned o, unsigned l, bool crc_reset);

};

Expand All @@ -258,7 +261,7 @@ class CEPH_BUFFER_API buffer {
ptr append_buffer; // where i put small appends.

template <bool is_const>
class iterator_impl: public std::iterator<std::forward_iterator_tag, char> {
class iterator_impl: public std::iterator<std::forward_iterator_tag, char> {
protected:
typedef typename std::conditional<is_const,
const list,
Expand Down Expand Up @@ -326,8 +329,23 @@ class CEPH_BUFFER_API buffer {
iterator_impl(l, o) {}
iterator(bl_t *l, unsigned o, list_iter_t ip, unsigned po) :
iterator_impl(l, o, ip, po) {}

void advance(int o);
void seek(unsigned o);
char operator*();
iterator& operator++();
ptr get_current_ptr();

// copy data out
void copy(unsigned len, char *dest);
void copy(unsigned len, ptr &dest);
void copy(unsigned len, list &dest);
void copy(unsigned len, std::string &dest);
void copy_all(list &dest);

// copy data in
void copy_in(unsigned len, const char *src, bool crc_reset = true);
void copy_in(unsigned len, const char *src);
void copy_in(unsigned len, const char *src, bool crc_reset);
void copy_in(unsigned len, const list& otherl);
};

Expand Down Expand Up @@ -373,6 +391,8 @@ class CEPH_BUFFER_API buffer {
#endif
return _len;
}

bool contents_equal(buffer::list& other);
bool contents_equal(const buffer::list& other) const;

bool can_zero_copy() const;
Expand Down Expand Up @@ -469,7 +489,8 @@ class CEPH_BUFFER_API buffer {
void copy(unsigned off, unsigned len, char *dest) const;
void copy(unsigned off, unsigned len, list &dest) const;
void copy(unsigned off, unsigned len, std::string& dest) const;
void copy_in(unsigned off, unsigned len, const char *src, bool crc_reset = true);
void copy_in(unsigned off, unsigned len, const char *src);
void copy_in(unsigned off, unsigned len, const char *src, bool crc_reset);
void copy_in(unsigned off, unsigned len, const list& src);

void append(char c);
Expand Down

0 comments on commit cac1d6f

Please sign in to comment.