diff options
author | Sage Weil <sage@inktank.com> | 2013-10-17 16:52:29 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-10-17 16:52:29 -0700 |
commit | 93f1befdd7e4acd12937ae61756061051b8a69d2 (patch) | |
tree | 9a4209eca40472ef7ad8d3c6201e1a6d06f0ead3 | |
parent | 1f291f5c891237516ee4bf15bcb39b80ded95ce1 (diff) | |
parent | 3cfe9f602b153f51fae4017c402e11ac37870e2c (diff) | |
download | ceph-93f1befdd7e4acd12937ae61756061051b8a69d2.tar.gz |
Merge pull request #738 from ceph/wip-cache-crc
fix cached crc, bug #6583
Reviewed-by: Samuel Just <sam.just@inktank.com>
-rw-r--r-- | src/common/buffer.cc | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 4aa03ae4131..49307055715 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -77,13 +77,11 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE atomic_t nref; Spinlock crc_lock; - map<pair<off_t, off_t>, pair<int64_t, int64_t> > crc_map; - int64_t crc_in; ///< cached crc base; -1 if invalid - int64_t crc_out; ///< cached crc value; -1 if invalid + map<pair<size_t, size_t>, pair<uint32_t, uint32_t> > crc_map; - raw(unsigned l) : data(NULL), len(l), nref(0), crc_in(-1), crc_out(-1) + raw(unsigned l) : data(NULL), len(l), nref(0) { } - raw(char *c, unsigned l) : data(c), len(l), nref(0), crc_in(-1), crc_out(-1) + raw(char *c, unsigned l) : data(c), len(l), nref(0) { } virtual ~raw() {}; @@ -108,21 +106,25 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE bool is_n_page_sized() { return (len & ~CEPH_PAGE_MASK) == 0; } - bool get_crc(const pair<off_t, off_t> &fromto, - pair<int64_t, int64_t> *crc) const { + bool get_crc(const pair<size_t, size_t> &fromto, + pair<uint32_t, uint32_t> *crc) const { Spinlock::Locker l(crc_lock); - map<pair<off_t, off_t>, pair<int64_t, int64_t> >::const_iterator i = + map<pair<size_t, size_t>, pair<uint32_t, uint32_t> >::const_iterator i = crc_map.find(fromto); if (i == crc_map.end()) return false; *crc = i->second; return true; } - void set_crc(const pair<off_t, off_t> &fromto, - const pair<uint64_t, uint64_t> &crc) { + void set_crc(const pair<size_t, size_t> &fromto, + const pair<uint32_t, uint32_t> &crc) { Spinlock::Locker l(crc_lock); crc_map[fromto] = crc; } + void invalidate_crc() { + Spinlock::Locker l(crc_lock); + crc_map.clear(); + } }; class buffer::raw_malloc : public buffer::raw { @@ -453,17 +455,20 @@ static uint32_t simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZE assert(_raw); assert(o <= _len); assert(o+l <= _len); + _raw->invalidate_crc(); memcpy(c_str()+o, src, l); } void buffer::ptr::zero() { + _raw->invalidate_crc(); memset(c_str(), 0, _len); } void buffer::ptr::zero(unsigned o, unsigned l) { assert(o+l <= _len); + _raw->invalidate_crc(); memset(c_str()+o, 0, l); } @@ -1317,8 +1322,8 @@ __u32 buffer::list::crc32c(__u32 crc) const ++it) { if (it->length()) { raw *r = it->get_raw(); - pair<off_t, off_t> ofs(it->offset(), it->offset() + it->length()); - pair<int64_t, int64_t> ccrc; + pair<size_t, size_t> ofs(it->offset(), it->offset() + it->length()); + pair<uint32_t, uint32_t> ccrc; if (r->get_crc(ofs, &ccrc)) { if (ccrc.first == crc) { // got it already |