]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/librbd/io/ObjectRequest.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / librbd / io / ObjectRequest.h
index f59ec2e2a1a7d4c2a571addbb01efcc8d84be9de..9452ec43acd8cec2a7466361f04928793167ba0d 100644 (file)
@@ -14,6 +14,7 @@
 #include <map>
 
 class Context;
+class ObjectExtent;
 
 namespace librbd {
 
@@ -24,74 +25,47 @@ namespace io {
 struct AioCompletion;
 template <typename> class CopyupRequest;
 
-struct ObjectRequestHandle {
-  virtual ~ObjectRequestHandle() {
-  }
-
-  virtual void fail(int r) = 0;
-  virtual void send() = 0;
-};
-
 /**
  * This class represents an I/O operation to a single RBD data object.
  * Its subclasses encapsulate logic for dealing with special cases
  * for I/O due to layering.
  */
 template <typename ImageCtxT = ImageCtx>
-class ObjectRequest : public ObjectRequestHandle {
+class ObjectRequest {
 public:
-  static ObjectRequest* create_write(ImageCtxT *ictx, const std::string &oid,
-                                     uint64_t object_no,
-                                     uint64_t object_off,
-                                     const ceph::bufferlist &data,
-                                     const ::SnapContext &snapc, int op_flags,
-                                    const ZTracer::Trace &parent_trace,
-                                     Context *completion);
-  static ObjectRequest* create_discard(ImageCtxT *ictx, const std::string &oid,
-                                       uint64_t object_no, uint64_t object_off,
-                                       uint64_t object_len,
-                                       const ::SnapContext &snapc,
-                                       bool disable_clone_remove,
-                                       bool update_object_map,
-                                       const ZTracer::Trace &parent_trace,
-                                       Context *completion);
-  static ObjectRequest* create_writesame(ImageCtxT *ictx,
-                                         const std::string &oid,
-                                         uint64_t object_no,
-                                         uint64_t object_off,
-                                         uint64_t object_len,
-                                         const ceph::bufferlist &data,
-                                         const ::SnapContext &snapc,
-                                        int op_flags,
-                                        const ZTracer::Trace &parent_trace,
-                                         Context *completion);
-  static ObjectRequest* create_compare_and_write(ImageCtxT *ictx,
-                                                 const std::string &oid,
-                                                 uint64_t object_no,
-                                                 uint64_t object_off,
-                                                 const ceph::bufferlist &cmp_data,
-                                                 const ceph::bufferlist &write_data,
-                                                 const ::SnapContext &snapc,
-                                                 uint64_t *mismatch_offset, int op_flags,
-                                                 const ZTracer::Trace &parent_trace,
-                                                 Context *completion);
+  static ObjectRequest* create_write(
+      ImageCtxT *ictx, const std::string &oid, uint64_t object_no,
+      uint64_t object_off, ceph::bufferlist&& data, const ::SnapContext &snapc,
+      int op_flags, const ZTracer::Trace &parent_trace, Context *completion);
+  static ObjectRequest* create_discard(
+      ImageCtxT *ictx, const std::string &oid, uint64_t object_no,
+      uint64_t object_off, uint64_t object_len, const ::SnapContext &snapc,
+      int discard_flags, const ZTracer::Trace &parent_trace,
+      Context *completion);
+  static ObjectRequest* create_write_same(
+      ImageCtxT *ictx, const std::string &oid, uint64_t object_no,
+      uint64_t object_off, uint64_t object_len, ceph::bufferlist&& data,
+      const ::SnapContext &snapc, int op_flags,
+      const ZTracer::Trace &parent_trace, Context *completion);
+  static ObjectRequest* create_compare_and_write(
+      ImageCtxT *ictx, const std::string &oid, uint64_t object_no,
+      uint64_t object_off, ceph::bufferlist&& cmp_data,
+      ceph::bufferlist&& write_data, const ::SnapContext &snapc,
+      uint64_t *mismatch_offset, int op_flags,
+      const ZTracer::Trace &parent_trace, Context *completion);
 
   ObjectRequest(ImageCtxT *ictx, const std::string &oid,
                 uint64_t objectno, uint64_t off, uint64_t len,
                 librados::snap_t snap_id, const char *trace_name,
                 const ZTracer::Trace &parent_trace, Context *completion);
-  ~ObjectRequest() override {
+  virtual ~ObjectRequest() {
     m_trace.event("finish");
   }
 
   static void add_write_hint(ImageCtxT& image_ctx,
                              librados::ObjectWriteOperation *wr);
 
-  void fail(int r) {
-    finish(r);
-  }
-
-  void send() override = 0;
+  virtual void send() = 0;
 
   bool has_parent() const {
     return m_has_parent;
@@ -100,7 +74,7 @@ public:
   virtual const char *get_op_type() const = 0;
 
 protected:
-  bool compute_parent_extents(Extents *parent_extents);
+  bool compute_parent_extents(Extents *parent_extents, bool read_request);
 
   ImageCtxT *m_ictx;
   std::string m_oid;
@@ -124,35 +98,24 @@ public:
   static ObjectReadRequest* create(ImageCtxT *ictx, const std::string &oid,
                                    uint64_t objectno, uint64_t offset,
                                    uint64_t len, librados::snap_t snap_id,
-                                   int op_flags, bool cache_initiated,
+                                   int op_flags,
                                    const ZTracer::Trace &parent_trace,
-                                   Context *completion) {
+                                   ceph::bufferlist* read_data,
+                                   ExtentMap* extent_map, Context *completion) {
     return new ObjectReadRequest(ictx, oid, objectno, offset, len,
-                                 snap_id, op_flags, cache_initiated,
-                                 parent_trace, completion);
+                                 snap_id, op_flags, parent_trace, read_data,
+                                 extent_map, completion);
   }
 
   ObjectReadRequest(ImageCtxT *ictx, const std::string &oid,
                     uint64_t objectno, uint64_t offset, uint64_t len,
                     librados::snap_t snap_id, int op_flags,
-                    bool cache_initiated, const ZTracer::Trace &parent_trace,
+                    const ZTracer::Trace &parent_trace,
+                    ceph::bufferlist* read_data, ExtentMap* extent_map,
                     Context *completion);
 
   void send() override;
 
-  inline uint64_t get_offset() const {
-    return this->m_object_off;
-  }
-  inline uint64_t get_length() const {
-    return this->m_object_len;
-  }
-  ceph::bufferlist &data() {
-    return m_read_data;
-  }
-  ExtentMap &get_extent_map() {
-    return m_ext_map;
-  }
-
   const char *get_op_type() const override {
     return "read";
   }
@@ -161,16 +124,11 @@ private:
   /**
    * @verbatim
    *
-   *           <start>
-   *              |
-   *              |
-   *    /--------/ \--------\
-   *    |                   |
-   *    | (cache            | (cache
-   *    v  disabled)        v  enabled)
-   * READ_OBJECT      READ_CACHE
-   *    |                   |
-   *    |/------------------/
+   * <start>
+   *    |
+   *    |
+   *    v
+   * READ_OBJECT
    *    |
    *    v (skip if not needed)
    * READ_PARENT
@@ -185,13 +143,9 @@ private:
    */
 
   int m_op_flags;
-  bool m_cache_initiated;
-
-  ceph::bufferlist m_read_data;
-  ExtentMap m_ext_map;
 
-  void read_cache();
-  void handle_read_cache(int r);
+  ceph::bufferlist* m_read_data;
+  ExtentMap* m_extent_map;
 
   void read_object();
   void handle_read_object(int r);
@@ -230,6 +184,7 @@ public:
 
 protected:
   bool m_full_object = false;
+  bool m_copyup_enabled = true;
 
   virtual bool is_no_op_for_nonexistent_object() const {
     return false;
@@ -288,8 +243,10 @@ private:
 
   Extents m_parent_extents;
   bool m_object_may_exist = false;
-  bool m_copyup_enabled = true;
   bool m_copyup_in_progress = false;
+  bool m_guarding_migration_write = false;
+
+  void compute_parent_info();
 
   void pre_write_object_map_update();
   void handle_pre_write_object_map_update(int r);
@@ -309,13 +266,13 @@ class ObjectWriteRequest : public AbstractObjectWriteRequest<ImageCtxT> {
 public:
   ObjectWriteRequest(ImageCtxT *ictx, const std::string &oid,
                      uint64_t object_no, uint64_t object_off,
-                     const ceph::bufferlist &data, const ::SnapContext &snapc,
+                     ceph::bufferlist&& data, const ::SnapContext &snapc,
                      int op_flags, const ZTracer::Trace &parent_trace,
                      Context *completion)
     : AbstractObjectWriteRequest<ImageCtxT>(ictx, oid, object_no, object_off,
                                             data.length(), snapc, "write",
                                             parent_trace, completion),
-      m_write_data(data), m_op_flags(op_flags) {
+      m_write_data(std::move(data)), m_op_flags(op_flags) {
   }
 
   bool is_empty_write_op() const override {
@@ -340,16 +297,21 @@ public:
   ObjectDiscardRequest(ImageCtxT *ictx, const std::string &oid,
                        uint64_t object_no, uint64_t object_off,
                        uint64_t object_len, const ::SnapContext &snapc,
-                       bool disable_clone_remove, bool update_object_map,
-                       const ZTracer::Trace &parent_trace, Context *completion)
+                       int discard_flags, const ZTracer::Trace &parent_trace,
+                       Context *completion)
     : AbstractObjectWriteRequest<ImageCtxT>(ictx, oid, object_no, object_off,
                                             object_len, snapc, "discard",
                                             parent_trace, completion),
-      m_update_object_map(update_object_map) {
+      m_discard_flags(discard_flags) {
     if (this->m_full_object) {
-      if (disable_clone_remove && this->has_parent()) {
-        // need to hide the parent object instead of child object
-        m_discard_action = DISCARD_ACTION_REMOVE_TRUNCATE;
+      if ((m_discard_flags & OBJECT_DISCARD_FLAG_DISABLE_CLONE_REMOVE) != 0 &&
+          this->has_parent()) {
+        if (!this->m_copyup_enabled) {
+          // need to hide the parent object instead of child object
+          m_discard_action = DISCARD_ACTION_REMOVE_TRUNCATE;
+        } else {
+          m_discard_action = DISCARD_ACTION_TRUNCATE;
+        }
         this->m_object_len = 0;
       } else {
         m_discard_action = DISCARD_ACTION_REMOVE;
@@ -372,7 +334,7 @@ public:
     case DISCARD_ACTION_ZERO:
       return "zero";
     }
-    assert(false);
+    ceph_abort();
     return nullptr;
   }
 
@@ -388,7 +350,8 @@ protected:
     return (!this->has_parent());
   }
   bool is_object_map_update_enabled() const override {
-    return m_update_object_map;
+    return (
+      (m_discard_flags & OBJECT_DISCARD_FLAG_DISABLE_OBJECT_MAP_UPDATE) == 0);
   }
   bool is_non_existent_post_write_object_map_state() const override {
     return (m_discard_action == DISCARD_ACTION_REMOVE);
@@ -413,7 +376,7 @@ protected:
       wr->zero(this->m_object_off, this->m_object_len);
       break;
     default:
-      assert(false);
+      ceph_abort();
       break;
     }
   }
@@ -427,7 +390,7 @@ private:
   };
 
   DiscardAction m_discard_action;
-  bool m_update_object_map;
+  int m_discard_flags;
 
 };
 
@@ -436,14 +399,14 @@ class ObjectWriteSameRequest : public AbstractObjectWriteRequest<ImageCtxT> {
 public:
   ObjectWriteSameRequest(ImageCtxT *ictx, const std::string &oid,
                         uint64_t object_no, uint64_t object_off,
-                        uint64_t object_len, const ceph::bufferlist &data,
+                        uint64_t object_len, ceph::bufferlist&& data,
                          const ::SnapContext &snapc, int op_flags,
                         const ZTracer::Trace &parent_trace,
                         Context *completion)
     : AbstractObjectWriteRequest<ImageCtxT>(ictx, oid, object_no, object_off,
                                             object_len, snapc, "writesame",
                                             parent_trace, completion),
-      m_write_data(data), m_op_flags(op_flags) {
+      m_write_data(std::move(data)), m_op_flags(op_flags) {
   }
 
   const char *get_op_type() const override {
@@ -463,8 +426,8 @@ class ObjectCompareAndWriteRequest : public AbstractObjectWriteRequest<ImageCtxT
 public:
   ObjectCompareAndWriteRequest(ImageCtxT *ictx, const std::string &oid,
                                uint64_t object_no, uint64_t object_off,
-                               const ceph::bufferlist &cmp_bl,
-                               const ceph::bufferlist &write_bl,
+                               ceph::bufferlist&& cmp_bl,
+                               ceph::bufferlist&& write_bl,
                                const ::SnapContext &snapc,
                                uint64_t *mismatch_offset, int op_flags,
                                const ZTracer::Trace &parent_trace,
@@ -473,7 +436,7 @@ public:
                                            cmp_bl.length(), snapc,
                                            "compare_and_write", parent_trace,
                                            completion),
-    m_cmp_bl(cmp_bl), m_write_bl(write_bl),
+    m_cmp_bl(std::move(cmp_bl)), m_write_bl(std::move(write_bl)),
     m_mismatch_offset(mismatch_offset), m_op_flags(op_flags) {
   }