Skip to content

Commit 736eeb1

Browse files
authored
CA-419840 mark CD VBD as empty when its VDI is removed (#6840)
When a CDR is removed from an ISO SR the corresponding VDI is deleted. So far we relied on the DB GC to mark the VBD as empty. This creates a window for a race where the VDI/CD is reported as present when in fact it is not. So mark the VBD as empty as early as possible.
2 parents f05fa58 + be5420b commit 736eeb1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ocaml/xapi/xapi_vdi.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,18 @@ let db_forget ~__context ~vdi =
739739
debug "db_forget uuid=%s ref=%s"
740740
(Db.VDI.get_uuid ~__context ~self:vdi)
741741
(Ref.string_of vdi) ;
742+
(* CA-419840 mark VBD as empty when it is a CDR *)
743+
( Db.VDI.get_VBDs ~__context ~self:vdi |> function
744+
| [] ->
745+
debug "%s: no VBD for VDI %s" __FUNCTION__ (Ref.string_of vdi)
746+
| self :: _ when self = Ref.null ->
747+
warn "%s: NULL VBD for VDI %s" __FUNCTION__ (Ref.string_of vdi)
748+
| self :: _ when Db.VBD.get_type ~__context ~self = `CD ->
749+
Db.VBD.set_VDI ~__context ~self ~value:Ref.null ;
750+
Db.VBD.set_empty ~__context ~self ~value:true
751+
| _ ->
752+
() (* not a CDR *)
753+
) ;
742754
Db.VDI.destroy ~__context ~self:vdi
743755

744756
let introduce ~__context ~uuid ~name_label ~name_description ~sR ~_type

0 commit comments

Comments
 (0)