@@ -44,52 +44,8 @@ let safe_unplug rpc session_id self =
4444 raise e
4545 )
4646
47- (* * For a VBD attached to a control domain, it may correspond to a running task
48- (if so the task will be linked via an other_config key) or it may be a qemu
49- frontend (if so it will be linked to another frontend) *)
50- let has_vbd_leaked __context vbd =
51- let other_config = Db.VBD. get_other_config ~__context ~self: vbd in
52- let vm = Db.VBD. get_VM ~__context ~self: vbd in
53- let can_leak = Db.VM. get_is_control_domain ~__context ~self: vm in
54- let device = Db.VBD. get_device ~__context ~self: vbd in
55- let has_task = List. mem_assoc Xapi_globs. vbd_task_key other_config in
56- let has_related = List. mem_assoc Xapi_globs. related_to_key other_config in
57- if (not can_leak) || ((not has_task) && not has_related) then (
58- info " Ignoring orphaned disk attached to control domain (device = %s)"
59- device ;
60- false
61- ) else
62- let has_valid_task =
63- has_task
64- &&
65- let task_id =
66- Ref. of_string (List. assoc Xapi_globs. vbd_task_key other_config)
67- in
68- (* check if the task record still exists and is pending *)
69- try
70- let status = Db.Task. get_status ~__context ~self: task_id in
71- List. mem status [`pending ; `cancelling ]
72- (* pending and cancelling => not leaked *)
73- with _ -> false
74- (* task record gone *)
75- in
76- let has_valid_related =
77- has_related
78- &&
79- let related =
80- Ref. of_string (List. assoc Xapi_globs. related_to_key other_config)
81- in
82- (* check if the VBD still exists and is currently_attached *)
83- try Db.VBD. get_currently_attached ~__context ~self: related
84- with _ -> false
85- (* VBD record gone *)
86- in
87- (* leaked if neither of the two keys are still valid *)
88- (not has_valid_task) && not has_valid_related
89-
9047(* * Execute a function with a list of VBDs after attaching a bunch of VDIs to an vm *)
9148let with_vbds rpc session_id __context vm vdis mode f =
92- let task_id = Context. get_task_id __context in
9349 let vbds = ref [] in
9450 finally
9551 (fun () ->
@@ -99,13 +55,8 @@ let with_vbds rpc session_id __context vm vdis mode f =
9955 Client.VBD. create ~rpc ~session_id ~v M:vm ~empty: false ~v DI:vdi
10056 ~userdevice: " autodetect" ~bootable: false ~mode ~_type:`Disk
10157 ~unpluggable: true ~qos_algorithm_type: " " ~qos_algorithm_params: []
102- ~other_config: [(Xapi_globs. vbd_task_key, Ref. string_of task_id)]
103- ~device: " " ~currently_attached: false
58+ ~other_config: [] ~device: " " ~currently_attached: false
10459 in
105- (* sanity-check *)
106- if has_vbd_leaked __context vbd then
107- error " Attach_helpers.with_vbds new VBD has leaked: %s"
108- (Ref. string_of vbd) ;
10960 let vbd_uuid = Client.VBD. get_uuid ~rpc ~session_id ~self: vbd in
11061 let uuid = Client.VM. get_uuid ~rpc ~session_id ~self: vm in
11162 debug " created VBD (uuid %s); attempting to hotplug to VM (uuid: %s)"
0 commit comments