Skip to content

Commit 63159d6

Browse files
committed
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 <[email protected]>
1 parent cacf7ca commit 63159d6

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

src/librbd/migration/OpenSourceImageRequest.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ void OpenSourceImageRequest<I>::open_format(
143143
if (r < 0) {
144144
lderr(m_cct) << "failed to build migration format handler: "
145145
<< cpp_strerror(r) << dendl;
146-
(*m_src_image_ctx)->state->close();
147-
finish(r);
146+
close_image(r);
148147
return;
149148
}
150149

@@ -161,7 +160,7 @@ void OpenSourceImageRequest<I>::handle_open_format(int r) {
161160
if (r < 0) {
162161
lderr(m_cct) << "failed to open migration format: " << cpp_strerror(r)
163162
<< dendl;
164-
finish(r);
163+
close_image(r);
165164
return;
166165
}
167166

src/librbd/migration/RawFormat.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ void RawFormat<I>::handle_open(int r, Context* on_finish) {
108108
snapshot->close(gather_ctx->new_sub());
109109
}
110110

111-
m_image_ctx->state->close(new LambdaContext(
112-
[r, on_finish=gather_ctx->new_sub()](int _) { on_finish->complete(r); }));
111+
auto ctx = gather_ctx->new_sub();
112+
ctx->complete(r);
113113

114114
gather_ctx->activate();
115115
return;

src/test/librbd/migration/test_mock_RawFormat.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ class TestMockMigrationRawFormat : public TestMockFixture {
125125
})));
126126
}
127127

128-
void expect_close(MockTestImageCtx &mock_image_ctx, int r) {
129-
EXPECT_CALL(*mock_image_ctx.state, close(_))
130-
.WillOnce(Invoke([r](Context* ctx) {
131-
ctx->complete(r);
132-
}));
133-
}
134-
135128
json_spirit::mObject json_object;
136129
};
137130

@@ -174,7 +167,6 @@ TEST_F(TestMockMigrationRawFormat, OpenError) {
174167
expect_snapshot_open(*mock_snapshot_interface, -ENOENT);
175168

176169
expect_snapshot_close(*mock_snapshot_interface, 0);
177-
expect_close(mock_image_ctx, 0);
178170

179171
MockRawFormat mock_raw_format(&mock_image_ctx, json_object,
180172
&mock_source_spec_builder);
@@ -203,7 +195,6 @@ TEST_F(TestMockMigrationRawFormat, OpenSnapshotError) {
203195

204196
expect_snapshot_close(*mock_snapshot_interface_1, 0);
205197
expect_snapshot_close(*mock_snapshot_interface_head, 0);
206-
expect_close(mock_image_ctx, 0);
207198

208199
json_spirit::mArray snapshots;
209200
snapshots.push_back(json_spirit::mObject{});

0 commit comments

Comments
 (0)