]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: switch remaining uses of ExtentMap to Extents
authorJason Dillaman <dillaman@redhat.com>
Tue, 29 Sep 2020 00:04:48 +0000 (20:04 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 13 Oct 2020 12:40:29 +0000 (08:40 -0400)
The neorados API already requires the vector-based approach vs
the map-based approach. Now the remaining sparse-read functionality
has been switched to use the consistent approach.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/cls/rbd/cls_rbd_client.cc
src/cls/rbd/cls_rbd_client.h
src/librbd/deep_copy/ObjectCopyRequest.h
src/librbd/io/CopyupRequest.cc
src/librbd/io/CopyupRequest.h
src/librbd/io/ReadResult.cc
src/librbd/io/ReadResult.h
src/test/librbd/test_internal.cc

index 28f1600a8553da5bd7c03525f33322c3427a8ad1..cefa1fed79391c3fbbc0196a976ba8a6d04760e9 100644 (file)
@@ -872,7 +872,7 @@ void sparse_copyup(O* op, const E& extent_map, ceph::buffer::list data) {
 }
 
 void sparse_copyup(neorados::WriteOp* op,
-                   const std::map<uint64_t, uint64_t> &extent_map,
+                   const std::vector<std::pair<uint64_t, uint64_t>>& extent_map,
                    ceph::buffer::list data) {
   sparse_copyup<neorados::WriteOp>(op, extent_map, data);
 }
index 5bc43fca8836bf864cb6705f5969579bc4f977aa..12b34c48327087e9d2531d6c4227a349ad93c862 100644 (file)
@@ -643,7 +643,7 @@ int copyup(librados::IoCtx *ioctx, const std::string &oid,
            ceph::buffer::list data);
 
 void sparse_copyup(neorados::WriteOp* op,
-                   const std::map<uint64_t, uint64_t> &extent_map,
+                   const std::vector<std::pair<uint64_t, uint64_t>>& extent_map,
                    ceph::buffer::list data);
 void sparse_copyup(librados::ObjectWriteOperation *op,
                    const std::map<uint64_t, uint64_t> &extent_map,
index e12648132602783fa3e7c0831ffd8b1427693a62..7f41979cd40f1a9e03091c766957360178b28b06 100644 (file)
@@ -95,11 +95,9 @@ private:
     WRITE_OP_TYPE_REMOVE_TRUNC,
   };
 
-  typedef std::map<uint64_t, uint64_t> ExtentMap;
-
   struct ReadOp {
     interval_set<uint64_t> image_interval;
-    ExtentMap image_extent_map;
+    io::Extents image_extent_map;
     bufferlist out_bl;
   };
 
index 3f864322bc230cc32c15b04d01e9337d8f56509d..ae14cbf649aa59d6fb984457e4530ec64b8ebcf7 100644 (file)
@@ -222,15 +222,18 @@ void CopyupRequest<I>::handle_read_from_parent(int r) {
   }
 
   // convert the image-extent extent map to object-extents
-  ExtentMap image_extent_map;
+  Extents image_extent_map;
   image_extent_map.swap(m_copyup_extent_map);
+  m_copyup_extent_map.reserve(m_copyup_extent_map.size());
+
   for (auto [image_offset, image_length] : image_extent_map) {
     striper::LightweightObjectExtents object_extents;
     Striper::file_to_extents(
       cct, &m_image_ctx->layout, image_offset, image_length, 0, 0,
       &object_extents);
     for (auto& object_extent : object_extents) {
-      m_copyup_extent_map[object_extent.offset] = object_extent.length;
+      m_copyup_extent_map.emplace_back(
+        object_extent.offset, object_extent.length);
     }
   }
 
index 7875a6dc9dc0e8308b0efb56c5b1de32de7ae224..9724184fa38c2debe9f0ae8fbf7a3435ac2c3926 100644 (file)
@@ -90,7 +90,7 @@ private:
   bool m_copyup_is_zero = true;
   bool m_deep_copied = false;
 
-  std::map<uint64_t, uint64_t> m_copyup_extent_map;
+  Extents m_copyup_extent_map;
   ceph::bufferlist m_copyup_data;
 
   AsyncOperation m_async_op;
index 26e27943d2c372d6376bdd762d7c917a6782f232..963d4c685accf4faaffabe05b01f5fe70305ed4f 100644 (file)
@@ -95,17 +95,19 @@ struct ReadResult::AssembleResultVisitor : public boost::static_visitor<void> {
   }
 
   void operator()(SparseBufferlist &sparse_bufferlist) const {
-    sparse_bufferlist.extent_map->clear();
     sparse_bufferlist.bl->clear();
-    auto buffer_extents_length = destriper.assemble_result(
-      cct, sparse_bufferlist.extent_map, sparse_bufferlist.bl);
 
     ExtentMap buffer_extent_map;
-    buffer_extent_map.swap(*sparse_bufferlist.extent_map);
+    auto buffer_extents_length = destriper.assemble_result(
+      cct, &buffer_extent_map, sparse_bufferlist.bl);
+
     ldout(cct, 20) << "image_extents="
                    << sparse_bufferlist.image_extents << ", "
                    << "buffer_extent_map=" << buffer_extent_map << dendl;
 
+    sparse_bufferlist.extent_map->clear();
+    sparse_bufferlist.extent_map->reserve(buffer_extent_map.size());
+
     // The extent-map is logically addressed by buffer-extents not image- or
     // object-extents. Translate this address mapping to image-extent
     // logical addressing since it's tied to an image-extent read
@@ -130,8 +132,8 @@ struct ReadResult::AssembleResultVisitor : public boost::static_visitor<void> {
                        << "~" << buffer_extent_length << " to image extent "
                        << image_extent_offset << "~" << buffer_extent_length
                        << dendl;
-        (*sparse_bufferlist.extent_map)[image_extent_offset] =
-          buffer_extent_length;
+        sparse_bufferlist.extent_map->emplace_back(
+          image_extent_offset, buffer_extent_length);
         ++bem_it;
       }
 
@@ -247,8 +249,7 @@ ReadResult::ReadResult(ceph::bufferlist *bl)
   : m_buffer(Bufferlist(bl)) {
 }
 
-ReadResult::ReadResult(std::map<uint64_t, uint64_t> *extent_map,
-                       ceph::bufferlist *bl)
+ReadResult::ReadResult(Extents* extent_map, ceph::bufferlist* bl)
   : m_buffer(SparseBufferlist(extent_map, bl)) {
 }
 
index 365d79f83ca735769557215467f3e99c63f95af9..3a5b0d7bb37b60833e1ad0d815d3abf9999da2ba 100644 (file)
@@ -61,7 +61,7 @@ public:
   ReadResult(char *buf, size_t buf_len);
   ReadResult(const struct iovec *iov, int iov_count);
   ReadResult(ceph::bufferlist *bl);
-  ReadResult(std::map<uint64_t, uint64_t> *extent_map, ceph::bufferlist *bl);
+  ReadResult(Extents* extent_map, ceph::bufferlist* bl);
 
   void set_clip_length(size_t length);
   void set_image_extents(const Extents& image_extents);
@@ -97,13 +97,12 @@ private:
   };
 
   struct SparseBufferlist {
-    std::map<uint64_t, uint64_t> *extent_map;
+    Extents *extent_map;
     ceph::bufferlist *bl;
 
     Extents image_extents;
 
-    SparseBufferlist(std::map<uint64_t, uint64_t> *extent_map,
-                     ceph::bufferlist *bl)
+    SparseBufferlist(Extents* extent_map, ceph::bufferlist* bl)
       : extent_map(extent_map), bl(bl) {
     }
   };
index 222bca832ea529288386263515d1c5c9ac6abc0c..4a793a021b6024356951bb1cc3d50186af78ccce 100644 (file)
@@ -679,7 +679,7 @@ TEST_F(TestInternal, SnapshotCopyup)
       BOOST_SCOPE_EXIT(ictx3) {
         ictx3->state->close();
       } BOOST_SCOPE_EXIT_END;
-      std::map<uint64_t, uint64_t> expected_m;
+      std::vector<std::pair<uint64_t, uint64_t>> expected_m;
       bufferlist expected_bl;
       if (ictx3->enable_sparse_copyup && sparse_read_supported) {
         if (snap_name == NULL) {
@@ -701,7 +701,7 @@ TEST_F(TestInternal, SnapshotCopyup)
           expected_bl.append(std::string(256 * 1, '1'));
         }
       }
-      std::map<uint64_t, uint64_t> read_m;
+      std::vector<std::pair<uint64_t, uint64_t>> read_m;
       librbd::io::ReadResult sparse_read_result{&read_m, &read_bl};
       EXPECT_EQ(1024 + 256,
                 api::Io<>::read(*ictx3, 0, 1024 + 256,