From 80ebceea58e5a066010e8c5cc7666f062c40ff2e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 5 Oct 2012 13:36:31 -0700 Subject: [PATCH] filer: uninline StripedReadResult Signed-off-by: Sage Weil --- src/osdc/Filer.cc | 98 +++++++++++++++++++++++++++++++++++++++++++++++ src/osdc/Filer.h | 91 ++----------------------------------------- 2 files changed, 101 insertions(+), 88 deletions(-) diff --git a/src/osdc/Filer.cc b/src/osdc/Filer.cc index ad9e5b5044fb0..ebb0c4bda6fd1 100644 --- a/src/osdc/Filer.cc +++ b/src/osdc/Filer.cc @@ -432,3 +432,101 @@ void Filer::extent_to_file(CephContext *cct, ceph_file_layout *layout, len -= extent_len; } } + + +// StripedReadResult + +void Filer::StripedReadResult::add_partial_result(bufferlist& bl, + const vector >& buffer_extents) +{ + for (vector >::const_iterator p = buffer_extents.begin(); + p != buffer_extents.end(); + ++p) { + pair& r = partial[p->first]; + size_t actual = MIN(bl.length(), p->second); + bl.splice(0, actual, &r.first); + r.second = p->second; + } +} + +void Filer::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 Filer::StripedReadResult::assemble_result(bufferlist& bl, bool zero_tail) +{ + // go backwards, so that we can efficiently discard zeros + map >::reverse_iterator p = partial.rbegin(); + if (p == partial.rend()) + return; + + uint64_t end = p->first + p->second.second; + while (p != partial.rend()) { + // sanity check + assert(p->first == end - p->second.second); + end = p->first; + + size_t len = p->second.first.length(); + if (len < p->second.second) { + if (zero_tail || bl.length()) { + bufferptr bp(p->second.second - p->second.first.length()); + bp.zero(); + bl.push_front(bp); + bl.claim_prepend(p->second.first); + } else { + bl.claim_prepend(p->second.first); + } + } else { + bl.claim_prepend(p->second.first); + } + p++; + } + partial.clear(); +} diff --git a/src/osdc/Filer.h b/src/osdc/Filer.h index 8f763751efd30..3dae59219f11b 100644 --- a/src/osdc/Filer.h +++ b/src/osdc/Filer.h @@ -132,17 +132,7 @@ class Filer { public: void add_partial_result(bufferlist& bl, - const vector >& buffer_extents) { - for (vector >::const_iterator p = buffer_extents.begin(); - p != buffer_extents.end(); - ++p) { - pair& r = partial[p->first]; - size_t actual = MIN(bl.length(), p->second); - bl.splice(0, actual, &r.first); - r.second = p->second; - } - } - + const vector >& buffer_extents); /** * add sparse read into results * @@ -153,86 +143,11 @@ class Filer { */ 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; - } - } + const vector >& buffer_extents); - void assemble_result(bufferlist& bl, bool zero_tail) { - // go backwards, so that we can efficiently discard zeros - map >::reverse_iterator p = partial.rbegin(); - if (p == partial.rend()) - return; - - uint64_t end = p->first + p->second.second; - while (p != partial.rend()) { - // sanity check - assert(p->first == end - p->second.second); - end = p->first; - - size_t len = p->second.first.length(); - if (len < p->second.second) { - if (zero_tail || bl.length()) { - bufferptr bp(p->second.second - p->second.first.length()); - bp.zero(); - bl.push_front(bp); - bl.claim_prepend(p->second.first); - } else { - bl.claim_prepend(p->second.first); - } - } else { - bl.claim_prepend(p->second.first); - } - p++; - } - partial.clear(); - } + void assemble_result(bufferlist& bl, bool zero_tail); }; - /*** async file interface. scatter/gather as needed. ***/ int read(inodeno_t ino, -- 2.39.5