]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: AioImageRequest base class is now templated
authorJason Dillaman <dillaman@redhat.com>
Thu, 17 Dec 2015 18:21:42 +0000 (13:21 -0500)
committerJason Dillaman <dillaman@redhat.com>
Fri, 15 Jan 2016 15:40:29 +0000 (10:40 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/AioImageRequest.cc
src/librbd/AioImageRequest.h
src/librbd/AioImageRequestWQ.cc
src/librbd/AioImageRequestWQ.h
src/librbd/AioObjectRequest.cc
src/librbd/CopyupRequest.cc
src/librbd/internal.cc
src/librbd/journal/Replay.cc

index ed93b34eb7501eb43fc8006639a5febc8d1168ca..cba7dde121972345cbbc7c62015dcade642169ad 100644 (file)
@@ -77,39 +77,46 @@ struct C_FlushJournalCommit : public Context {
 
 } // anonymous namespace
 
-void AioImageRequest::aio_read(
-    ImageCtx *ictx, AioCompletion *c,
+template <typename I>
+void AioImageRequest<I>::aio_read(
+    I *ictx, AioCompletion *c,
     const std::vector<std::pair<uint64_t,uint64_t> > &extents,
     char *buf, bufferlist *pbl, int op_flags) {
   AioImageRead req(*ictx, c, extents, buf, pbl, op_flags);
   req.send();
 }
 
-void AioImageRequest::aio_read(ImageCtx *ictx, AioCompletion *c, uint64_t off,
-                               size_t len, char *buf, bufferlist *pbl,
-                               int op_flags) {
+template <typename I>
+void AioImageRequest<I>::aio_read(I *ictx, AioCompletion *c,
+                                  uint64_t off, size_t len, char *buf,
+                                  bufferlist *pbl, int op_flags) {
   AioImageRead req(*ictx, c, off, len, buf, pbl, op_flags);
   req.send();
 }
 
-void AioImageRequest::aio_write(ImageCtx *ictx, AioCompletion *c, uint64_t off,
-                                size_t len, const char *buf, int op_flags) {
+template <typename I>
+void AioImageRequest<I>::aio_write(I *ictx, AioCompletion *c,
+                                   uint64_t off, size_t len, const char *buf,
+                                   int op_flags) {
   AioImageWrite req(*ictx, c, off, len, buf, op_flags);
   req.send();
 }
 
-void AioImageRequest::aio_discard(ImageCtx *ictx, AioCompletion *c,
-                                  uint64_t off, uint64_t len) {
+template <typename I>
+void AioImageRequest<I>::aio_discard(I *ictx, AioCompletion *c,
+                                     uint64_t off, uint64_t len) {
   AioImageDiscard req(*ictx, c, off, len);
   req.send();
 }
 
-void AioImageRequest::aio_flush(ImageCtx *ictx, AioCompletion *c) {
+template <typename I>
+void AioImageRequest<I>::aio_flush(I *ictx, AioCompletion *c) {
   AioImageFlush req(*ictx, c);
   req.send();
 }
 
-void AioImageRequest::send() {
+template <typename I>
+void AioImageRequest<I>::send() {
   assert(m_image_ctx.owner_lock.is_locked());
 
   CephContext *cct = m_image_ctx.cct;
@@ -120,7 +127,8 @@ void AioImageRequest::send() {
   send_request();
 }
 
-void AioImageRequest::fail(int r) {
+template <typename I>
+void AioImageRequest<I>::fail(int r) {
   m_aio_comp->get();
   m_aio_comp->fail(m_image_ctx.cct, r);
 }
@@ -466,3 +474,5 @@ void AioImageFlush::send_request() {
 }
 
 } // namespace librbd
+
+template class librbd::AioImageRequest<librbd::ImageCtx>;
index 6ee6d64322ba5d60eb0a3103f7a183451cfc0bda..e8a3fd5b106e9bf750d1aced506cc118b31e72cd 100644 (file)
@@ -18,22 +18,23 @@ namespace librbd {
 class AioObjectRequest;
 class ImageCtx;
 
+template <typename ImageCtxT = ImageCtx>
 class AioImageRequest {
 public:
   typedef std::vector<std::pair<uint64_t,uint64_t> > Extents;
 
   virtual ~AioImageRequest() {}
 
-  static void aio_read(ImageCtx *ictx, AioCompletion *c,
+  static void aio_read(ImageCtxT *ictx, AioCompletion *c,
                        const std::vector<std::pair<uint64_t,uint64_t> > &extents,
                        char *buf, bufferlist *pbl, int op_flags);
-  static void aio_read(ImageCtx *ictx, AioCompletion *c, uint64_t off,
+  static void aio_read(ImageCtxT *ictx, AioCompletion *c, uint64_t off,
                        size_t len, char *buf, bufferlist *pbl, int op_flags);
-  static void aio_write(ImageCtx *ictx, AioCompletion *c, uint64_t off,
+  static void aio_write(ImageCtxT *ictx, AioCompletion *c, uint64_t off,
                         size_t len, const char *buf, int op_flags);
-  static void aio_discard(ImageCtx *ictx, AioCompletion *c, uint64_t off,
+  static void aio_discard(ImageCtxT *ictx, AioCompletion *c, uint64_t off,
                           uint64_t len);
-  static void aio_flush(ImageCtx *ictx, AioCompletion *c);
+  static void aio_flush(ImageCtxT *ictx, AioCompletion *c);
 
   virtual bool is_write_op() const {
     return false;
@@ -45,17 +46,17 @@ public:
 protected:
   typedef std::list<AioObjectRequest *> AioObjectRequests;
 
-  ImageCtx &m_image_ctx;
+  ImageCtxT &m_image_ctx;
   AioCompletion *m_aio_comp;
 
-  AioImageRequest(ImageCtx &image_ctx, AioCompletion *aio_comp)
+  AioImageRequest(ImageCtxT &image_ctx, AioCompletion *aio_comp)
     : m_image_ctx(image_ctx), m_aio_comp(aio_comp) {}
 
   virtual void send_request() = 0;
   virtual const char *get_request_type() const = 0;
 };
 
-class AioImageRead : public AioImageRequest {
+class AioImageRead : public AioImageRequest<> {
 public:
   AioImageRead(ImageCtx &image_ctx, AioCompletion *aio_comp, uint64_t off,
                size_t len, char *buf, bufferlist *pbl, int op_flags)
@@ -83,7 +84,7 @@ private:
   int m_op_flags;
 };
 
-class AbstractAioImageWrite : public AioImageRequest {
+class AbstractAioImageWrite : public AioImageRequest<> {
 public:
   virtual bool is_write_op() const {
     return true;
@@ -194,7 +195,7 @@ protected:
   virtual void update_stats(size_t length);
 };
 
-class AioImageFlush : public AioImageRequest {
+class AioImageFlush : public AioImageRequest<> {
 public:
   AioImageFlush(ImageCtx &image_ctx, AioCompletion *aio_comp)
     : AioImageRequest(image_ctx, aio_comp) {
@@ -213,4 +214,6 @@ protected:
 
 } // namespace librbd
 
+extern template class librbd::AioImageRequest<librbd::ImageCtx>;
+
 #endif // CEPH_LIBRBD_AIO_IMAGE_REQUEST_H
index f6607e227139970a1740930a42a30d434747f0ca..2de18d35c50d13b27caac9e8368d80f1ff308753 100644 (file)
@@ -19,7 +19,7 @@ namespace librbd {
 
 AioImageRequestWQ::AioImageRequestWQ(ImageCtx *image_ctx, const string &name,
                                      time_t ti, ThreadPool *tp)
-  : ThreadPool::PointerWQ<AioImageRequest>(name, ti, 0, tp),
+  : ThreadPool::PointerWQ<AioImageRequest<> >(name, ti, 0, tp),
     m_image_ctx(*image_ctx),
     m_lock(util::unique_lock_name("AioImageRequestWQ::m_lock", this)),
     m_write_blockers(0), m_in_progress_writes(0), m_queued_writes(0),
@@ -115,7 +115,7 @@ void AioImageRequestWQ::aio_read(AioCompletion *c, uint64_t off, uint64_t len,
   if (m_image_ctx.non_blocking_aio || writes_blocked() || !writes_empty()) {
     queue(new AioImageRead(m_image_ctx, c, off, len, buf, pbl, op_flags));
   } else {
-    AioImageRequest::aio_read(&m_image_ctx, c, off, len, buf, pbl, op_flags);
+    AioImageRequest<>::aio_read(&m_image_ctx, c, off, len, buf, pbl, op_flags);
     finish_in_flight_op();
   }
 }
@@ -142,7 +142,7 @@ void AioImageRequestWQ::aio_write(AioCompletion *c, uint64_t off, uint64_t len,
       writes_blocked()) {
     queue(new AioImageWrite(m_image_ctx, c, off, len, buf, op_flags));
   } else {
-    AioImageRequest::aio_write(&m_image_ctx, c, off, len, buf, op_flags);
+    AioImageRequest<>::aio_write(&m_image_ctx, c, off, len, buf, op_flags);
     finish_in_flight_op();
   }
 }
@@ -168,7 +168,7 @@ void AioImageRequestWQ::aio_discard(AioCompletion *c, uint64_t off,
       writes_blocked()) {
     queue(new AioImageDiscard(m_image_ctx, c, off, len));
   } else {
-    AioImageRequest::aio_discard(&m_image_ctx, c, off, len);
+    AioImageRequest<>::aio_discard(&m_image_ctx, c, off, len);
     finish_in_flight_op();
   }
 }
@@ -192,7 +192,7 @@ void AioImageRequestWQ::aio_flush(AioCompletion *c, bool native_async) {
       writes_blocked() || !writes_empty()) {
     queue(new AioImageFlush(m_image_ctx, c));
   } else {
-    AioImageRequest::aio_flush(&m_image_ctx, c);
+    AioImageRequest<>::aio_flush(&m_image_ctx, c);
     finish_in_flight_op();
   }
 }
@@ -265,7 +265,7 @@ void AioImageRequestWQ::unblock_writes() {
 }
 
 void *AioImageRequestWQ::_void_dequeue() {
-  AioImageRequest *peek_item = front();
+  AioImageRequest<> *peek_item = front();
   if (peek_item == NULL || m_refresh_in_progress) {
     return NULL;
   }
@@ -278,8 +278,8 @@ void *AioImageRequestWQ::_void_dequeue() {
     m_in_progress_writes.inc();
   }
 
-  AioImageRequest *item = reinterpret_cast<AioImageRequest *>(
-    ThreadPool::PointerWQ<AioImageRequest>::_void_dequeue());
+  AioImageRequest<> *item = reinterpret_cast<AioImageRequest<> *>(
+    ThreadPool::PointerWQ<AioImageRequest<> >::_void_dequeue());
   assert(peek_item == item);
 
   if (m_image_ctx.state->is_refresh_required()) {
@@ -295,7 +295,7 @@ void *AioImageRequestWQ::_void_dequeue() {
   return item;
 }
 
-void AioImageRequestWQ::process(AioImageRequest *req) {
+void AioImageRequestWQ::process(AioImageRequest<> *req) {
   CephContext *cct = m_image_ctx.cct;
   ldout(cct, 20) << __func__ << ": ictx=" << &m_image_ctx << ", "
                  << "req=" << req << dendl;
@@ -376,7 +376,7 @@ bool AioImageRequestWQ::is_lock_required() const {
   return (!m_image_ctx.exclusive_lock->is_lock_owner());
 }
 
-void AioImageRequestWQ::queue(AioImageRequest *req) {
+void AioImageRequestWQ::queue(AioImageRequest<> *req) {
   CephContext *cct = m_image_ctx.cct;
   ldout(cct, 20) << __func__ << ": ictx=" << &m_image_ctx << ", "
                  << "req=" << req << dendl;
@@ -387,14 +387,14 @@ void AioImageRequestWQ::queue(AioImageRequest *req) {
     m_queued_writes.inc();
   }
 
-  ThreadPool::PointerWQ<AioImageRequest>::queue(req);
+  ThreadPool::PointerWQ<AioImageRequest<> >::queue(req);
 
   if (write_op && is_lock_required()) {
     m_image_ctx.exclusive_lock->request_lock(nullptr);
   }
 }
 
-void AioImageRequestWQ::handle_refreshed(int r, AioImageRequest *req) {
+void AioImageRequestWQ::handle_refreshed(int r, AioImageRequest<> *req) {
   CephContext *cct = m_image_ctx.cct;
   ldout(cct, 15) << "resuming IO after image refresh: r=" << r << ", "
                  << "req=" << req << dendl;
index c84548955a338106349f3fc16b90762a3402ca8f..1573e72658cde21fe1cd53c2f27ed822d43e8452 100644 (file)
 namespace librbd {
 
 class AioCompletion;
-class AioImageRequest;
+template <typename> class AioImageRequest;
 class ImageCtx;
 
-class AioImageRequestWQ : protected ThreadPool::PointerWQ<AioImageRequest> {
+class AioImageRequestWQ : protected ThreadPool::PointerWQ<AioImageRequest<ImageCtx> > {
 public:
   AioImageRequestWQ(ImageCtx *image_ctx, const string &name, time_t ti,
                     ThreadPool *tp);
@@ -30,11 +30,12 @@ public:
                 bufferlist *pbl, int op_flags, bool native_async=true);
   void aio_write(AioCompletion *c, uint64_t off, uint64_t len, const char *buf,
                  int op_flags, bool native_async=true);
-  void aio_discard(AioCompletion *c, uint64_t off, uint64_t len, bool native_async=true);
+  void aio_discard(AioCompletion *c, uint64_t off, uint64_t len,
+                   bool native_async=true);
   void aio_flush(AioCompletion *c, bool native_async=true);
 
-  using ThreadPool::PointerWQ<AioImageRequest>::drain;
-  using ThreadPool::PointerWQ<AioImageRequest>::empty;
+  using typename ThreadPool::PointerWQ<AioImageRequest<ImageCtx> >::drain;
+  using typename ThreadPool::PointerWQ<AioImageRequest<ImageCtx> >::empty;
 
   inline bool writes_empty() const {
     RWLock::RLocker locker(m_lock);
@@ -54,17 +55,17 @@ public:
 
 protected:
   virtual void *_void_dequeue();
-  virtual void process(AioImageRequest *req);
+  virtual void process(AioImageRequest<ImageCtx> *req);
 
 private:
   typedef std::list<Context *> Contexts;
 
   struct C_RefreshFinish : public Context {
     AioImageRequestWQ *aio_work_queue;
-    AioImageRequest *aio_image_request;
+    AioImageRequest<ImageCtx> *aio_image_request;
 
     C_RefreshFinish(AioImageRequestWQ *aio_work_queue,
-                    AioImageRequest *aio_image_request)
+                    AioImageRequest<ImageCtx> *aio_image_request)
       : aio_work_queue(aio_work_queue), aio_image_request(aio_image_request) {
     }
     virtual void finish(int r) override {
@@ -101,9 +102,9 @@ private:
 
   bool is_journal_required() const;
   bool is_lock_required() const;
-  void queue(AioImageRequest *req);
+  void queue(AioImageRequest<ImageCtx> *req);
 
-  void handle_refreshed(int r, AioImageRequest *req);
+  void handle_refreshed(int r, AioImageRequest<ImageCtx> *req);
   void handle_blocked_writes(int r);
 };
 
index 34a1c116999d45917c6020451b3406c80862bc49..96669eadbe472af456a872bc9585e98b9228a331 100644 (file)
@@ -281,8 +281,8 @@ namespace librbd {
                           << " extents " << parent_extents
                           << dendl;
     RWLock::RLocker owner_locker(m_ictx->parent->owner_lock);
-    AioImageRequest::aio_read(m_ictx->parent, m_parent_completion,
-                              parent_extents, NULL, &m_read_data, 0);
+    AioImageRequest<>::aio_read(m_ictx->parent, m_parent_completion,
+                                parent_extents, NULL, &m_read_data, 0);
   }
 
   /** write **/
index d7713ad166a099921caf6a7edeb445659a819d9b..29d8a4ac40fb5a9c1da30adbf21217c6f8fe4440 100644 (file)
@@ -191,8 +191,8 @@ private:
                            << ", extents " << m_image_extents
                            << dendl;
     RWLock::RLocker owner_locker(m_ictx->parent->owner_lock);
-    AioImageRequest::aio_read(m_ictx->parent, comp, m_image_extents, NULL,
-                              &m_copyup_data, 0);
+    AioImageRequest<>::aio_read(m_ictx->parent, comp, m_image_extents, NULL,
+                                &m_copyup_data, 0);
   }
 
   void CopyupRequest::complete(int r)
index a926e03731cf4d0c3f07a187ad70dbe8c01677bd..eb77456a7e8c4fbec7ebaf4182314977270a9a39 100644 (file)
@@ -1894,8 +1894,8 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
       bufferlist *bl = new bufferlist();
       Context *ctx = new C_CopyRead(&throttle, dest, offset, bl);
       AioCompletion *comp = AioCompletion::create(ctx);
-      AioImageRequest::aio_read(src, comp, offset, len, NULL, bl,
-                                fadvise_flags);
+      AioImageRequest<>::aio_read(src, comp, offset, len, NULL, bl,
+                                  fadvise_flags);
       prog_ctx.update_progress(offset, src_size);
     }
 
@@ -2119,7 +2119,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
 
       C_SaferCond ctx;
       AioCompletion *c = AioCompletion::create(&ctx);
-      AioImageRequest::aio_read(ictx, c, off, read_len, NULL, &bl, 0);
+      AioImageRequest<>::aio_read(ictx, c, off, read_len, NULL, &bl, 0);
 
       int ret = ctx.wait();
       if (ret < 0) {
index 23172179e18047c5a7d511e76f9f4ff9b4324876..b0bb1ce573cf9813819922d0812039ace783fa0d 100644 (file)
@@ -67,8 +67,8 @@ void Replay<I>::handle_event(const journal::AioDiscardEvent &event,
   ldout(cct, 20) << this << " " << __func__ << ": AIO discard event" << dendl;
 
   AioCompletion *aio_comp = create_aio_completion(on_safe);
-  AioImageRequest::aio_discard(&m_image_ctx, aio_comp, event.offset,
-                               event.length);
+  AioImageRequest<I>::aio_discard(&m_image_ctx, aio_comp, event.offset,
+                                  event.length);
 }
 
 template <typename I>
@@ -79,8 +79,8 @@ void Replay<I>::handle_event(const journal::AioWriteEvent &event,
 
   bufferlist data = event.data;
   AioCompletion *aio_comp = create_aio_completion(on_safe);
-  AioImageRequest::aio_write(&m_image_ctx, aio_comp, event.offset, event.length,
-                             data.c_str(), 0);
+  AioImageRequest<I>::aio_write(&m_image_ctx, aio_comp, event.offset,
+                                event.length, data.c_str(), 0);
 }
 
 template <typename I>
@@ -90,7 +90,7 @@ void Replay<I>::handle_event(const journal::AioFlushEvent &event,
   ldout(cct, 20) << this << " " << __func__ << ": AIO flush event" << dendl;
 
   AioCompletion *aio_comp = create_aio_completion(on_safe);
-  AioImageRequest::aio_flush(&m_image_ctx, aio_comp);
+  AioImageRequest<I>::aio_flush(&m_image_ctx, aio_comp);
 }
 
 template <typename I>