Skip to content

Commit 9f08c1f

Browse files
authored
Merge pull request ceph#64505 from abitdrag/tracker_71961
librbd: images aren't closed in group_snap_*_by_record() on error Reviewed-by: Ilya Dryomov <[email protected]>
2 parents e66ca20 + ac14330 commit 9f08c1f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/librbd/api/Group.cc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,30 @@ int group_snap_remove_by_record(librados::IoCtx& group_ioctx,
180180
const std::string& group_header_oid) {
181181

182182
CephContext *cct = (CephContext *)group_ioctx.cct();
183+
std::vector<librados::IoCtx> ioctxs;
184+
std::vector<librbd::ImageCtx*> ictxs;
183185
std::vector<C_SaferCond*> on_finishes;
184186
int r, ret_code;
185187

186-
std::vector<librbd::ImageCtx*> ictxs;
187-
188188
cls::rbd::GroupSnapshotNamespace ne{group_ioctx.get_id(), group_id,
189189
group_snap.id};
190190

191191
ldout(cct, 20) << "Removing snapshots" << dendl;
192192
int snap_count = group_snap.snaps.size();
193193

194194
for (int i = 0; i < snap_count; ++i) {
195-
librbd::IoCtx image_io_ctx;
195+
librados::IoCtx image_io_ctx;
196196
r = util::create_ioctx(group_ioctx, "image", group_snap.snaps[i].pool, {},
197197
&image_io_ctx);
198198
if (r < 0) {
199199
return r;
200200
}
201+
ioctxs.push_back(std::move(image_io_ctx));
202+
}
201203

204+
for (int i = 0; i < snap_count; ++i) {
202205
librbd::ImageCtx* image_ctx = new ImageCtx("", group_snap.snaps[i].image_id,
203-
nullptr, image_io_ctx, false);
206+
nullptr, ioctxs[i], false);
204207

205208
C_SaferCond* on_finish = new C_SaferCond;
206209

@@ -286,11 +289,11 @@ int group_snap_rollback_by_record(librados::IoCtx& group_ioctx,
286289
const std::string& group_id,
287290
ProgressContext& pctx) {
288291
CephContext *cct = (CephContext *)group_ioctx.cct();
292+
std::vector<librados::IoCtx> ioctxs;
293+
std::vector<librbd::ImageCtx*> ictxs;
289294
std::vector<C_SaferCond*> on_finishes;
290295
int r, ret_code;
291296

292-
std::vector<librbd::ImageCtx*> ictxs;
293-
294297
cls::rbd::GroupSnapshotNamespace ne{group_ioctx.get_id(), group_id,
295298
group_snap.id};
296299

@@ -304,9 +307,12 @@ int group_snap_rollback_by_record(librados::IoCtx& group_ioctx,
304307
if (r < 0) {
305308
return r;
306309
}
310+
ioctxs.push_back(std::move(image_io_ctx));
311+
}
307312

313+
for (int i = 0; i < snap_count; ++i) {
308314
librbd::ImageCtx* image_ctx = new ImageCtx("", group_snap.snaps[i].image_id,
309-
nullptr, image_io_ctx, false);
315+
nullptr, ioctxs[i], false);
310316

311317
C_SaferCond* on_finish = new C_SaferCond;
312318

@@ -460,7 +466,7 @@ int GroupSnapshot_to_group_snap_info2(
460466
image_snaps.reserve(cls_group_snap.snaps.size());
461467

462468
for (const auto& snap : cls_group_snap.snaps) {
463-
librbd::IoCtx image_ioctx;
469+
librados::IoCtx image_ioctx;
464470
int r = util::create_ioctx(group_ioctx, "image", snap.pool, {},
465471
&image_ioctx);
466472
if (r < 0) {
@@ -972,7 +978,7 @@ int Group<I>::snap_create(librados::IoCtx& group_ioctx,
972978
}
973979

974980
for (auto image: images) {
975-
librbd::IoCtx image_io_ctx;
981+
librados::IoCtx image_io_ctx;
976982
r = util::create_ioctx(group_ioctx, "image", image.spec.pool_id, {},
977983
&image_io_ctx);
978984
if (r < 0) {

0 commit comments

Comments
 (0)