]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: add iterator crc32c method
authorSage Weil <sage@redhat.com>
Tue, 31 May 2016 18:43:49 +0000 (14:43 -0400)
committerIgor Fedotov <ifedotov@mirantis.com>
Thu, 2 Jun 2016 09:10:22 +0000 (12:10 +0300)
Calculate crc from an iterator position.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/buffer.cc
src/include/buffer.h

index b809d92621f327e2ed952593a4e8001570260474..191b57869594036e3ebb049b00042e3582d2798f 100644 (file)
@@ -1218,6 +1218,19 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
     return l;
   }
 
+  template<bool is_const>
+  uint32_t buffer::list::iterator_impl<is_const>::crc32c(
+    size_t length, uint32_t crc)
+  {
+    while (length > 0) {
+      const char *p;
+      size_t l = get_ptr_and_advance(length, &p);
+      crc = ceph_crc32c(crc, (unsigned char*)p, l);
+      length -= l;
+    }
+    return crc;
+  }
+
   // explicitly instantiate only the iterator types we need, so we can hide the
   // details in this compilation unit without introducing unnecessary link time
   // dependencies.
index a4e89005a5c466167443725046b8792fea543d45..9998573237861bbe86b2b33a1174b8f8de129640 100644 (file)
@@ -329,6 +329,9 @@ namespace buffer CEPH_BUFFER_API {
       // and advance the iterator by that amount.
       size_t get_ptr_and_advance(size_t want, const char **p);
 
+      /// calculate crc from iterator position
+      uint32_t crc32c(size_t length, uint32_t crc);
+
       friend bool operator==(const iterator_impl& lhs,
                             const iterator_impl& rhs) {
        return &lhs.get_bl() == &rhs.get_bl() && lhs.get_off() == rhs.get_off();