From: Ilya Dryomov Date: Fri, 26 Jul 2024 10:13:08 +0000 (+0200) Subject: librbd/migration: close source image in OpenSourceImageRequest X-Git-Tag: testing/wip-vshankar-testing-20240802.091913-debug~5^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=63159d6b431470f5edc4b110cebf46865c550689;p=ceph-ci.git librbd/migration: close source image in OpenSourceImageRequest Currently, on errors in FormatInterface::open(), RawFormat disposes of src_image_ctx, but QCOWFormat doesn't, which is a leak. Rather than having each format do it internally, do it in OpenSourceImageRequest. Signed-off-by: Ilya Dryomov --- diff --git a/src/librbd/migration/OpenSourceImageRequest.cc b/src/librbd/migration/OpenSourceImageRequest.cc index 4bd9241ec29..b22900795b9 100644 --- a/src/librbd/migration/OpenSourceImageRequest.cc +++ b/src/librbd/migration/OpenSourceImageRequest.cc @@ -143,8 +143,7 @@ void OpenSourceImageRequest::open_format( if (r < 0) { lderr(m_cct) << "failed to build migration format handler: " << cpp_strerror(r) << dendl; - (*m_src_image_ctx)->state->close(); - finish(r); + close_image(r); return; } @@ -161,7 +160,7 @@ void OpenSourceImageRequest::handle_open_format(int r) { if (r < 0) { lderr(m_cct) << "failed to open migration format: " << cpp_strerror(r) << dendl; - finish(r); + close_image(r); return; } diff --git a/src/librbd/migration/RawFormat.cc b/src/librbd/migration/RawFormat.cc index 0b655d36882..4d1f7158a03 100644 --- a/src/librbd/migration/RawFormat.cc +++ b/src/librbd/migration/RawFormat.cc @@ -108,8 +108,8 @@ void RawFormat::handle_open(int r, Context* on_finish) { snapshot->close(gather_ctx->new_sub()); } - m_image_ctx->state->close(new LambdaContext( - [r, on_finish=gather_ctx->new_sub()](int _) { on_finish->complete(r); })); + auto ctx = gather_ctx->new_sub(); + ctx->complete(r); gather_ctx->activate(); return; diff --git a/src/test/librbd/migration/test_mock_RawFormat.cc b/src/test/librbd/migration/test_mock_RawFormat.cc index 6b69bf20c4b..16627628b55 100644 --- a/src/test/librbd/migration/test_mock_RawFormat.cc +++ b/src/test/librbd/migration/test_mock_RawFormat.cc @@ -125,13 +125,6 @@ public: }))); } - void expect_close(MockTestImageCtx &mock_image_ctx, int r) { - EXPECT_CALL(*mock_image_ctx.state, close(_)) - .WillOnce(Invoke([r](Context* ctx) { - ctx->complete(r); - })); - } - json_spirit::mObject json_object; }; @@ -174,7 +167,6 @@ TEST_F(TestMockMigrationRawFormat, OpenError) { expect_snapshot_open(*mock_snapshot_interface, -ENOENT); expect_snapshot_close(*mock_snapshot_interface, 0); - expect_close(mock_image_ctx, 0); MockRawFormat mock_raw_format(&mock_image_ctx, json_object, &mock_source_spec_builder); @@ -203,7 +195,6 @@ TEST_F(TestMockMigrationRawFormat, OpenSnapshotError) { expect_snapshot_close(*mock_snapshot_interface_1, 0); expect_snapshot_close(*mock_snapshot_interface_head, 0); - expect_close(mock_image_ctx, 0); json_spirit::mArray snapshots; snapshots.push_back(json_spirit::mObject{});