Skip to content

Commit d78f943

Browse files
committed
xapi/attach_helpers: remove useless check for leaked vbds
Looks like this mechanism was used in the past, and only one vestigial check on VBD creation was used. It does not make sense to create a VBD associated with a task and immediately check whether it has leaked. Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent 87ddfe6 commit d78f943

2 files changed

Lines changed: 1 addition & 55 deletions

File tree

ocaml/xapi/attach_helpers.ml

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -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 *)
9148
let 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 ~vM:vm ~empty:false ~vDI: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)"

ocaml/xapi/xapi_globs.ml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,6 @@ let default_template_key = "default_template"
274274

275275
let base_template_name_key = "base_template_name"
276276

277-
(* Keys to explain the presence of dom0 block-attached VBDs: *)
278-
let vbd_task_key = "task_id"
279-
280-
let related_to_key = "related_to"
281-
282277
let get_nbd_extents = "/opt/xensource/libexec/get_nbd_extents.py"
283278

284279
(* other-config keys to sync over when mirroring/remapping/importing a VDI *)

0 commit comments

Comments
 (0)