Merge pull request from dillaman/wip-46875

librbd: flush all incomplete in-flight IOs upon image close

Reviewed-by: Mykola Golub <mgolub@suse.com>
This commit is contained in:
Mykola Golub 2020-08-31 08:59:06 +03:00 committed by GitHub
commit 912f6fab28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 43 deletions

View File

@ -90,6 +90,34 @@ void CloseRequest<I>::handle_shut_down_update_watchers(int r) {
<< dendl;
}
send_flush();
}
template <typename I>
void CloseRequest<I>::send_flush() {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 10) << this << " " << __func__ << dendl;
std::shared_lock owner_locker{m_image_ctx->owner_lock};
auto ctx = create_context_callback<
CloseRequest<I>, &CloseRequest<I>::handle_flush>(this);
auto aio_comp = io::AioCompletion::create_and_start(ctx, m_image_ctx,
io::AIO_TYPE_FLUSH);
auto req = io::ImageDispatchSpec<I>::create_flush(
*m_image_ctx, io::IMAGE_DISPATCH_LAYER_API_START, aio_comp,
io::FLUSH_SOURCE_INTERNAL, {});
req->send();
}
template <typename I>
void CloseRequest<I>::handle_flush(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 10) << this << " " << __func__ << ": r=" << r << dendl;
if (r < 0) {
lderr(cct) << "failed to flush IO: " << cpp_strerror(r) << dendl;
}
send_shut_down_exclusive_lock();
}
@ -108,7 +136,7 @@ void CloseRequest<I>::send_shut_down_exclusive_lock() {
}
if (m_exclusive_lock == nullptr) {
send_flush();
send_unregister_image_watcher();
return;
}
@ -148,33 +176,6 @@ void CloseRequest<I>::handle_shut_down_exclusive_lock(int r) {
send_unregister_image_watcher();
}
template <typename I>
void CloseRequest<I>::send_flush() {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 10) << this << " " << __func__ << dendl;
std::shared_lock owner_locker{m_image_ctx->owner_lock};
auto ctx = create_context_callback<
CloseRequest<I>, &CloseRequest<I>::handle_flush>(this);
auto aio_comp = io::AioCompletion::create_and_start(ctx, m_image_ctx,
io::AIO_TYPE_FLUSH);
auto req = io::ImageDispatchSpec<I>::create_flush(
*m_image_ctx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
io::FLUSH_SOURCE_INTERNAL, {});
req->send();
}
template <typename I>
void CloseRequest<I>::handle_flush(int r) {
CephContext *cct = m_image_ctx->cct;
ldout(cct, 10) << this << " " << __func__ << ": r=" << r << dendl;
if (r < 0) {
lderr(cct) << "failed to flush IO: " << cpp_strerror(r) << dendl;
}
send_unregister_image_watcher();
}
template <typename I>
void CloseRequest<I>::send_unregister_image_watcher() {
if (m_image_ctx->image_watcher == nullptr) {

View File

@ -33,14 +33,15 @@ private:
* BLOCK_IMAGE_WATCHER (skip if R/O)
* |
* v
* SHUT_DOWN_UPDATE_WATCHERS . .
* | . (exclusive lock disabled)
* v v
* SHUT_DOWN_EXCLUSIVE_LOCK FLUSH
* | .
* | . . . . . . . . . . .
* | .
* v v
* SHUT_DOWN_UPDATE_WATCHERS
* |
* v
* FLUSH
* |
* v (skip if disabled)
* SHUT_DOWN_EXCLUSIVE_LOCK
* |
* v
* UNREGISTER_IMAGE_WATCHER (skip if R/O)
* |
* v
@ -82,12 +83,12 @@ private:
void send_shut_down_update_watchers();
void handle_shut_down_update_watchers(int r);
void send_shut_down_exclusive_lock();
void handle_shut_down_exclusive_lock(int r);
void send_flush();
void handle_flush(int r);
void send_shut_down_exclusive_lock();
void handle_shut_down_exclusive_lock(int r);
void send_unregister_image_watcher();
void handle_unregister_image_watcher(int r);

View File

@ -107,10 +107,6 @@ bool QueueImageDispatch<I>::flush(
auto cct = m_image_ctx->cct;
ldout(cct, 20) << "tid=" << tid << dendl;
if (flush_source != FLUSH_SOURCE_USER) {
return false;
}
*dispatch_result = DISPATCH_RESULT_CONTINUE;
m_flush_tracker->flush(on_dispatched);
return true;