diff options
author | Or Ozeri <oro@il.ibm.com> | 2020-07-14 13:28:12 +0200 |
---|---|---|
committer | Or Ozeri <oro@il.ibm.com> | 2020-07-14 13:28:12 +0200 |
commit | 8dd3e83742302be169a484e76d02be781b2cbb6e (patch) | |
tree | 3b4bf846f268762397612f8bf14005db551d6105 | |
parent | Merge pull request #35894 from tchaikov/wip-crimson-os (diff) | |
download | ceph-8dd3e83742302be169a484e76d02be781b2cbb6e.tar.xz ceph-8dd3e83742302be169a484e76d02be781b2cbb6e.zip |
osdc/Striper: add get_file_offset function
This commit adds a get_file_offset translating (object_no, object_off) -> file_offset.
This is useful for encryption object dispatch layer in librbd
to comply with disk-encryption standards that require the file offset as input.
Signed-off-by: Or Ozeri <oro@il.ibm.com>
-rw-r--r-- | src/osdc/Striper.cc | 20 | ||||
-rw-r--r-- | src/osdc/Striper.h | 3 | ||||
-rw-r--r-- | src/test/test_striper.cc | 15 |
3 files changed, 38 insertions, 0 deletions
diff --git a/src/osdc/Striper.cc b/src/osdc/Striper.cc index 7510ac946c3..2c7f0a96087 100644 --- a/src/osdc/Striper.cc +++ b/src/osdc/Striper.cc @@ -296,6 +296,26 @@ uint64_t Striper::get_num_objects(const file_layout_t& layout, return num_periods * stripe_count - remainder_objs; } +uint64_t Striper::get_file_offset(CephContext *cct, + const file_layout_t *layout, uint64_t objectno, uint64_t off) { + ldout(cct, 10) << "get_file_offset " << objectno << " " << off << dendl; + + __u32 object_size = layout->object_size; + __u32 su = layout->stripe_unit; + __u32 stripe_count = layout->stripe_count; + ceph_assert(object_size >= su); + uint64_t stripes_per_object = object_size / su; + ldout(cct, 20) << " stripes_per_object " << stripes_per_object << dendl; + + uint64_t off_in_block = off % su; + + uint64_t stripepos = objectno % stripe_count; + uint64_t objectsetno = objectno / stripe_count; + uint64_t stripeno = off / su + objectsetno * stripes_per_object; + uint64_t blockno = stripeno * stripe_count + stripepos; + return blockno * su + off_in_block; +} + // StripedReadResult void Striper::StripedReadResult::add_partial_result( diff --git a/src/osdc/Striper.h b/src/osdc/Striper.h index ddfb2c570ed..2ebc29a1213 100644 --- a/src/osdc/Striper.h +++ b/src/osdc/Striper.h @@ -73,6 +73,9 @@ static uint64_t get_num_objects(const file_layout_t& layout, uint64_t size); + + static uint64_t get_file_offset(CephContext *cct, + const file_layout_t *layout, uint64_t objectno, uint64_t off); /* * helper to assemble a striped result */ diff --git a/src/test/test_striper.cc b/src/test/test_striper.cc index 200c2279ded..c294d646820 100644 --- a/src/test/test_striper.cc +++ b/src/test/test_striper.cc @@ -70,3 +70,18 @@ TEST(Striper, GetNumObj) numobjs = Striper::get_num_objects(l, size); ASSERT_EQ(6u, numobjs); } + +TEST(Striper, GetFileOffset) +{ + file_layout_t l; + + l.object_size = 262144; + l.stripe_unit = 4096; + l.stripe_count = 3; + + uint64_t object_no = 100; + uint64_t object_off = 200000; + uint64_t file_offset = Striper::get_file_offset( + g_ceph_context, &l, object_no, object_off); + ASSERT_EQ(26549568u, file_offset); +} |