]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
osdc/Striper: add get_file_offset function
authorOr Ozeri <oro@il.ibm.com>
Tue, 14 Jul 2020 11:28:12 +0000 (14:28 +0300)
committerOr Ozeri <oro@il.ibm.com>
Tue, 14 Jul 2020 11:28:12 +0000 (14:28 +0300)
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>
src/osdc/Striper.cc
src/osdc/Striper.h
src/test/test_striper.cc

index 7510ac946c3374653f02a5c2c6ac78226d24058c..2c7f0a960875ec1862b74b09e6211ad5d394aa5a 100644 (file)
@@ -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(
index ddfb2c570ed14aa2b000c48c4f09311a40cc01f1..2ebc29a1213a6a1049d674945ac979c050a9ee36 100644 (file)
@@ -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
      */
index 200c2279ded4e6573f01c6e27df408dd759fca6a..c294d646820464bbe7a68810403f20d6f6a38442 100644 (file)
@@ -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);
+}