From 1d2989096eee89e1d06a1b42b9b9765bbf287e01 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 10 Mar 2015 11:17:49 -0400 Subject: [PATCH] librbd: use image size and parent overlap from active shrink op If a shrink operation is in progress, all operations should use the new size and new parent overlap for IO operations. Signed-off-by: Jason Dillaman --- src/librbd/AsyncResizeRequest.h | 12 ++++++++++++ src/librbd/ImageCtx.cc | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/librbd/AsyncResizeRequest.h b/src/librbd/AsyncResizeRequest.h index de6a49b0ee989..655b2135a9c66 100644 --- a/src/librbd/AsyncResizeRequest.h +++ b/src/librbd/AsyncResizeRequest.h @@ -22,6 +22,18 @@ public: virtual void send(); + inline bool shrinking() const { + return m_new_size < m_original_size; + } + + inline uint64_t get_image_size() const { + return m_new_size; + } + + inline uint64_t get_parent_overlap() const { + return m_new_parent_overlap; + } + private: /** * Resize goes through the following state machine to resize the image diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 0b8d3e6c37dd9..10b0231c0714b 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -9,6 +9,7 @@ #include "librbd/AsyncOperation.h" #include "librbd/AsyncRequest.h" +#include "librbd/AsyncResizeRequest.h" #include "librbd/internal.h" #include "librbd/ImageCtx.h" #include "librbd/ImageWatcher.h" @@ -433,6 +434,10 @@ namespace librbd { { assert(snap_lock.is_locked()); if (in_snap_id == CEPH_NOSNAP) { + if (!async_resize_reqs.empty() && + async_resize_reqs.front()->shrinking()) { + return async_resize_reqs.front()->get_image_size(); + } return size; } @@ -527,6 +532,13 @@ namespace librbd { int ImageCtx::get_parent_overlap(snap_t in_snap_id, uint64_t *overlap) const { + assert(snap_lock.is_locked()); + if (in_snap_id == CEPH_NOSNAP && !async_resize_reqs.empty() && + async_resize_reqs.front()->shrinking()) { + *overlap = async_resize_reqs.front()->get_parent_overlap(); + return 0; + } + const parent_info *info = get_parent_info(in_snap_id); if (info) { *overlap = info->overlap; -- 2.39.5