Skip to content

Commit 8ccb08f

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 8ccb08f

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

ocaml/xapi/storage_mux.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,15 @@ 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+
| None ->
657+
debug
658+
"%s No plugin found for SR %s, the SR may be already destroyed, \
659+
skip post_deactivate_hook"
660+
__FUNCTION__ (s_of_sr sr)
661+
| _ ->
662+
if smapi_version_of_sr sr = SMAPIv3 then
663+
Storage_migrate.post_deactivate_hook ~sr ~vdi ~dp
657664

658665
let detach () ~dbg ~dp ~sr ~vdi ~vm =
659666
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)