From: lixiaoy1 Date: Thu, 23 Apr 2020 10:38:09 +0000 (-0400) Subject: librbd: Return read request early X-Git-Tag: v16.1.0~2485^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F34700%2Fhead;p=ceph.git librbd: Return read request early Finish read requests if the total length is 0. Signed-off-by: Li, Xiaoyan --- diff --git a/src/librbd/io/ImageRequest.cc b/src/librbd/io/ImageRequest.cc index 0f93c95da4c0..7b7e7e4f1594 100644 --- a/src/librbd/io/ImageRequest.cc +++ b/src/librbd/io/ImageRequest.cc @@ -263,6 +263,15 @@ int ImageRequest::clip_request() { return 0; } +template +uint64_t ImageRequest::get_total_length() const { + uint64_t total_bytes = 0; + for (auto& image_extent : this->m_image_extents) { + total_bytes += image_extent.second; + } + return total_bytes; +} + template void ImageRequest::update_timestamp() { bool modify = (get_aio_type() != AIO_TYPE_READ); @@ -342,6 +351,17 @@ int ImageReadRequest::clip_request() { return 0; } +template +bool ImageReadRequest::finish_request_early() { + auto total_bytes = this->get_total_length(); + if (total_bytes == 0) { + auto *aio_comp = this->m_aio_comp; + aio_comp->set_request_count(0); + return true; + } + return false; +} + template void ImageReadRequest::send_request() { I &image_ctx = this->m_image_ctx; @@ -420,10 +440,7 @@ bool AbstractImageWriteRequest::finish_request_early() { return true; } } - uint64_t total_bytes = 0; - for (auto& image_extent : this->m_image_extents) { - total_bytes += image_extent.second; - } + auto total_bytes = this->get_total_length(); if (total_bytes == 0) { aio_comp->set_request_count(0); return true; diff --git a/src/librbd/io/ImageRequest.h b/src/librbd/io/ImageRequest.h index e5a04597d3e7..ca2a74e35ee2 100644 --- a/src/librbd/io/ImageRequest.h +++ b/src/librbd/io/ImageRequest.h @@ -83,6 +83,8 @@ protected: m_trace.event("start"); } + uint64_t get_total_length() const; + virtual bool finish_request_early() { return false; } @@ -106,6 +108,7 @@ public: protected: int clip_request() override; + bool finish_request_early() override; void send_request() override; void send_image_cache_request() override;