From: Igor Fedotov Date: Thu, 20 Feb 2020 13:25:06 +0000 (+0300) Subject: os/bluestore: extend bluestore_blob_t::map interface. X-Git-Tag: v16.1.0~2618^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c6d97c2d23be211e64e0a592aa52182aa8959c60;p=ceph.git os/bluestore: extend bluestore_blob_t::map interface. This allow different callback function signatures. Signed-off-by: Igor Fedotov --- diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index 32750ffb2d1a..3964e19b0a51 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -683,10 +683,49 @@ public: } } + // map_f_invoke templates intended to mask parameters which are not expected + // by the provided callback + template>::type* = nullptr> + int map_f_invoke(uint64_t lo, + const bluestore_pextent_t& p, + uint64_t o, + uint64_t l, F&& f) const{ + return f(o, l); + } + + template>::type * = nullptr> + int map_f_invoke(uint64_t lo, + const bluestore_pextent_t& p, + uint64_t o, + uint64_t l, F&& f) const { + return f(lo, o, l); + } + + template>::type * = nullptr> + int map_f_invoke(uint64_t lo, + const bluestore_pextent_t& p, + uint64_t o, + uint64_t l, F&& f) const { + return f(p, o, l); + } + template int map(uint64_t x_off, uint64_t x_len, F&& f) const { - static_assert(std::is_invocable_r_v); - + auto x_off0 = x_off; auto p = extents.begin(); ceph_assert(p != extents.end()); while (x_off >= p->length) { @@ -694,18 +733,19 @@ public: ++p; ceph_assert(p != extents.end()); } - while (x_len > 0) { - ceph_assert(p != extents.end()); + while (x_len > 0 && p != extents.end()) { uint64_t l = std::min(p->length - x_off, x_len); - int r = f(p->offset + x_off, l); + int r = map_f_invoke(x_off0, *p, p->offset + x_off, l, f); if (r < 0) return r; x_off = 0; x_len -= l; + x_off0 += l; ++p; } return 0; } + template void map_bl(uint64_t x_off, ceph::buffer::list& bl,