From 9e109e187c5efe4e19d52826f61a6a5c211b27e1 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 2 Oct 2012 16:00:29 -0700 Subject: [PATCH] filer: add sparse result into a striped read result Add a helper to assimilate a sparse read result into the destriper helper class. Signed-off-by: Sage Weil --- src/osdc/Filer.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/osdc/Filer.h b/src/osdc/Filer.h index bd09a8eaecd88..8f763751efd30 100644 --- a/src/osdc/Filer.h +++ b/src/osdc/Filer.h @@ -143,6 +143,64 @@ class Filer { } } + /** + * add sparse read into results + * + * @param bl buffer + * @param bl_map map of which logical source extents this covers + * @param bl_off logical buffer offset (e.g., first bl_map key if the buffer is not sparse) + * @param buffer_extents output buffer extents the data maps to + */ + void add_partial_sparse_result(bufferlist& bl, const map& bl_map, + uint64_t bl_off, + const vector >& buffer_extents) { + map::const_iterator s = bl_map.begin(); + for (vector >::const_iterator p = buffer_extents.begin(); + p != buffer_extents.end(); + ++p) { + uint64_t tofs = p->first; + uint64_t tlen = p->second; + while (tlen > 0) { + if (s == bl_map.end()) { + pair& r = partial[tofs]; + r.second = tlen; + break; + } + + // skip zero-length extent + if (s->second == 0) { + s++; + continue; + } + + if (s->first > bl_off) { + // gap in sparse read result + pair& r = partial[tofs]; + size_t gap = s->first - bl_off; + r.second = gap; + bl_off += gap; + tofs += gap; + tlen -= gap; + } + + assert(s->first <= bl_off); + size_t left = (s->first + s->second) - bl_off; + size_t actual = MIN(left, tlen); + + pair& r = partial[tofs]; + bl.splice(0, actual, &r.first); + r.second = actual; + bl_off += actual; + tofs += actual; + tlen -= actual; + + if (actual == left) + s++; + } + bl_off += p->second; + } + } + void assemble_result(bufferlist& bl, bool zero_tail) { // go backwards, so that we can efficiently discard zeros map >::reverse_iterator p = partial.rbegin(); -- 2.39.5