Skip to content

Commit 196b5f4

Browse files
committed
CA-411477: Fix SM API version check failure
When shutdown a VM, xapi will check SM API version to decide if to call `post_deactivate_hook`. But if the SR has already been unplugged, the checking will fail. Solution: Check if the plugin of the SR still exists. If not, skip the SM API checking. Signed-off-by: Bengang Yuan <[email protected]>
1 parent f7ee5aa commit 196b5f4

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

ocaml/xapi/storage_mux.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,14 @@ module Mux = struct
652652
the SMAPI version of the SR, but as xapi-storage-script cannot call code
653653
xapi, and smapiv1_wrapper has state tracking logic, the hook has to be placed
654654
here for now. *)
655-
if smapi_version_of_sr sr = SMAPIv3 then
656-
Storage_migrate.post_deactivate_hook ~sr ~vdi ~dp
655+
match find_plugin sr with
656+
| Some _ when smapi_version_of_sr sr = SMAPIv3 ->
657+
Storage_migrate.post_deactivate_hook ~sr ~vdi ~dp
658+
| None ->
659+
debug
660+
"%s No plugin found for SR %s, the SR may be already destroyed, \
661+
skip post_deactivate_hook"
662+
__FUNCTION__ (s_of_sr sr)
657663

658664
let detach () ~dbg ~dp ~sr ~vdi ~vm =
659665
with_dbg ~name:"VDI.detach" ~dbg @@ fun di ->

ocaml/xapi/storage_mux_reg.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ let unregister sr =
6969
)
7070
)
7171

72+
let find_plugin sr = with_lock m (fun () -> Hashtbl.find_opt plugins sr)
73+
7274
let sr_has_capability sr capability =
7375
with_lock m (fun () ->
7476
match Hashtbl.find_opt plugins sr with

ocaml/xapi/storage_mux_reg.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ val register :
3636

3737
val unregister : Storage_interface.sr -> unit
3838

39+
val find_plugin : Storage_interface.sr -> plugin option
40+
3941
val sr_has_capability : Storage_interface.sr -> Smint.Feature.capability -> bool
4042

4143
val of_sr : Storage_interface.sr -> processor

0 commit comments

Comments
 (0)