Skip to content

Commit 80052ae

Browse files
committed
CA-86883: Detach SR if SR.destroy fails
The storage backend can destroy an SR only if it is attached. Therefore when xapi wants to destroy an SR, first it attaches it. When the backend destroys the SR it is no longer attached. This change adds exception handling so that if the backend fails to destroy the SR, xapi will detach it.
1 parent 18e7e90 commit 80052ae

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ocaml/xapi/storage_access.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,15 @@ let destroy_sr ~__context ~sr =
11511151
Client.SR.attach dbg (Db.SR.get_uuid ~__context ~self:sr) pbd_t.API.pBD_device_config;
11521152
(* The current backends expect the PBD to be temporarily set to currently_attached = true *)
11531153
Db.PBD.set_currently_attached ~__context ~self:pbd ~value:true;
1154-
Pervasiveext.finally (fun () ->
1155-
Client.SR.destroy dbg (Db.SR.get_uuid ~__context ~self:sr))
1154+
Pervasiveext.finally
1155+
(fun () ->
1156+
try
1157+
Client.SR.destroy dbg (Db.SR.get_uuid ~__context ~self:sr)
1158+
with exn ->
1159+
(* Clean up: SR is left attached if destroy fails *)
1160+
Client.SR.detach dbg (Db.SR.get_uuid ~__context ~self:sr);
1161+
raise exn
1162+
)
11561163
(fun () ->
11571164
(* All PBDs are clearly currently_attached = false now *)
11581165
Db.PBD.set_currently_attached ~__context ~self:pbd ~value:false);

0 commit comments

Comments
 (0)