@@ -3888,22 +3888,22 @@ module VBD = struct
3888
3888
)
3889
3889
(fun () -> cleanup_attached_vdis vm vbd.id)
3890
3890
3891
- let unplug task vm vbd force =
3891
+ let deactivate task vm vbd force =
3892
3892
with_xc_and_xs (fun xc xs ->
3893
3893
try
3894
3894
(* On destroying the datapath
3895
3895
3896
- 1. if the device has already been shutdown and deactivated (as in
3897
- suspend) we must call DP.destroy here to avoid leaks
3896
+ 1. if the device has already been shutdown and deactivated (as in
3897
+ suspend) we must call DP.destroy here to avoid leaks
3898
3898
3899
- 2. if the device is successfully shutdown here then we must call
3900
- DP.destroy because no-one else will
3899
+ 2. if the device is successfully shutdown here then we must call
3900
+ DP.destroy because no-one else will
3901
3901
3902
- 3. if the device shutdown is rejected then we should leave the DP
3903
- alone and rely on the event thread calling us again later. *)
3902
+ 3. if the device shutdown is rejected then we should leave the DP
3903
+ alone and rely on the event thread calling us again later. *)
3904
3904
let domid = domid_of_uuid ~xs (uuid_of_string vm) in
3905
3905
(* If the device is gone then we don't need to shut it down but we do
3906
- need to free any storage resources. *)
3906
+ need to free any storage resources. *)
3907
3907
let dev =
3908
3908
try
3909
3909
Some (device_by_id xc xs vm (device_kind_of ~xs vbd) (id_of vbd))
@@ -3941,7 +3941,7 @@ module VBD = struct
3941
3941
vm (id_of vbd) ;
3942
3942
(* this happens on normal shutdown too *)
3943
3943
(* Case (1): success; Case (2): success; Case (3): an exception is
3944
- thrown *)
3944
+ thrown *)
3945
3945
with_tracing ~task ~name: " VBD_device_shutdown" @@ fun () ->
3946
3946
Xenops_task. with_subtask task
3947
3947
(Printf. sprintf " Vbd.clean_shutdown %s" (id_of vbd))
@@ -3952,7 +3952,7 @@ module VBD = struct
3952
3952
)
3953
3953
dev ;
3954
3954
(* We now have a shutdown device but an active DP: we should destroy
3955
- the DP if the backend is of type VDI *)
3955
+ the DP if the backend is of type VDI *)
3956
3956
finally
3957
3957
(fun () ->
3958
3958
with_tracing ~task ~name: " VBD_device_release" (fun () ->
@@ -3996,11 +3996,14 @@ module VBD = struct
3996
3996
()
3997
3997
)
3998
3998
(fun () ->
3999
- with_tracing ~task ~name: " VBD_dp_destroy" @@ fun () ->
3999
+ with_tracing ~task ~name: " VBD_deactivate" @@ fun () ->
4000
+ let vmid = Storage. vm_of_domid domid in
4000
4001
match (domid, backend) with
4001
- | Some x , None | Some x , Some (VDI _ ) ->
4002
- Storage. dp_destroy task
4003
- (Storage. id_of (string_of_int x) vbd.Vbd. id)
4002
+ | Some x , Some (VDI path ) ->
4003
+ let sr, vdi = Storage. get_disk_by_name task path in
4004
+ let dp = Storage. id_of (string_of_int x) vbd.id in
4005
+ Storage. deactivate task dp sr vdi vmid
4006
+ (* We don't need to detach Local or CDROM *)
4004
4007
| _ ->
4005
4008
()
4006
4009
)
@@ -4009,6 +4012,46 @@ module VBD = struct
4009
4012
raise (Xenopsd_error (Device_detach_rejected (" VBD" , id_of vbd, s)))
4010
4013
)
4011
4014
4015
+ let detach task vm vbd =
4016
+ with_xc_and_xs (fun xc xs ->
4017
+ let domid = domid_of_uuid ~xs (uuid_of_string vm) in
4018
+ let dev =
4019
+ try
4020
+ Some (device_by_id xc xs vm (device_kind_of ~xs vbd) (id_of vbd))
4021
+ with
4022
+ | Xenopsd_error (Does_not_exist (_ , _ )) ->
4023
+ debug " VM = %s; VBD = %s; Ignoring missing domain" vm (id_of vbd) ;
4024
+ None
4025
+ | Xenopsd_error Device_not_connected ->
4026
+ debug " VM = %s; VBD = %s; Ignoring missing device" vm (id_of vbd) ;
4027
+ None
4028
+ in
4029
+ let backend =
4030
+ match dev with
4031
+ | None ->
4032
+ None
4033
+ | Some dv -> (
4034
+ match
4035
+ Rpcmarshal. unmarshal typ_of_backend
4036
+ (Device.Generic. get_private_key ~xs dv _vdi_id
4037
+ |> Jsonrpc. of_string
4038
+ )
4039
+ with
4040
+ | Ok x ->
4041
+ x
4042
+ | Error (`Msg m ) ->
4043
+ internal_error " Failed to unmarshal VBD backend: %s" m
4044
+ )
4045
+ in
4046
+ with_tracing ~task ~name: " VBD_dp_destroy" @@ fun () ->
4047
+ match (domid, backend) with
4048
+ | Some x , None | Some x , Some (VDI _ ) ->
4049
+ Storage. dp_destroy task (Storage. id_of (string_of_int x) vbd.Vbd. id)
4050
+ | _ ->
4051
+ ()
4052
+ ) ;
4053
+ cleanup_attached_vdis vm vbd.id
4054
+
4012
4055
let insert task vm vbd d =
4013
4056
on_frontend
4014
4057
(fun xc xs frontend_domid domain_type ->
0 commit comments