Skip to content

Commit ea2a845

Browse files
authored
CA-424844 Revert PR #6915 (#6952)
Revert PR #6915. There is a regression fail when the cross-pool SXM for a VM with snapshot. The VDI snapshot_of data is missing.
2 parents b22e637 + be04c2b commit ea2a845

1 file changed

Lines changed: 31 additions & 52 deletions

File tree

ocaml/xapi/import.ml

Lines changed: 31 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,57 +2076,37 @@ let handlers =
20762076
; (Datamodel_common._vtpm, VTPMHandler.handle)
20772077
]
20782078

2079-
(* If snapshot_of(x) = y, and both x and y are freshly imported VDIs,
2080-
the field must be rewritten to a real database reference. The same
2081-
relationship formed by parental links must be preserved as well.
2082-
2083-
We can't do this on-the-fly during an import because we can't
2084-
guarantee that the VDIs will be imported in reverse topological
2085-
order of the relation induced by snapshot_of. *)
2086-
let update_vdi_links ~__context state =
2087-
(* Map an exported reference to a (freshly) imported reference, or
2088-
null if it's not present in the import. *)
2089-
let resolve_import =
2090-
let tbl = Hashtbl.create 16 in
2091-
let go (_, a, b) = Hashtbl.replace tbl a (Ref.of_string b) in
2092-
List.iter go state.table ;
2093-
fun r ->
2094-
Hashtbl.find_opt tbl (Ref.string_of r) |> Option.value ~default:Ref.null
2095-
in
2096-
let update x =
2097-
let x_r = Db.VDI.get_record ~__context ~self:x in
2098-
let parent = resolve_import x_r.API.vDI_parent in
2099-
let snapshot_of = resolve_import x_r.API.vDI_snapshot_of in
2100-
Db.VDI.set_parent ~__context ~self:x ~value:parent ;
2101-
Db.VDI.set_snapshot_of ~__context ~self:x ~value:snapshot_of ;
2102-
Db.VDI.set_is_a_snapshot ~__context ~self:x ~value:(snapshot_of <> Ref.null)
2103-
in
2104-
let go (cls, _, r) =
2105-
if cls = Datamodel_common._vdi then update (Ref.of_string r)
2106-
in
2107-
List.iter go state.table
2108-
2109-
(* Same as [update_vdi_links] but over VMs instead. *)
2110-
let update_vm_links ~__context state =
2111-
let resolve_import =
2112-
let tbl = Hashtbl.create 16 in
2113-
let go (_, a, b) = Hashtbl.replace tbl a (Ref.of_string b) in
2114-
List.iter go state.table ;
2115-
fun r ->
2116-
Hashtbl.find_opt tbl (Ref.string_of r) |> Option.value ~default:Ref.null
2117-
in
2118-
let update x =
2119-
let x_r = Db.VM.get_record ~__context ~self:x in
2120-
let parent = resolve_import x_r.API.vM_parent in
2121-
let snapshot_of = resolve_import x_r.API.vM_snapshot_of in
2122-
Db.VM.set_parent ~__context ~self:x ~value:parent ;
2123-
Db.VM.set_snapshot_of ~__context ~self:x ~value:snapshot_of ;
2124-
Db.VM.set_is_a_snapshot ~__context ~self:x ~value:(snapshot_of <> Ref.null)
2125-
in
2126-
let go (cls, _, r) =
2127-
if cls = Datamodel_common._vm then update (Ref.of_string r)
2079+
let update_snapshot_and_parent_links ~__context state =
2080+
let aux (cls, _, ref) =
2081+
let ref = Ref.of_string ref in
2082+
( if
2083+
cls = Datamodel_common._vm
2084+
&& Db.VM.get_is_a_snapshot ~__context ~self:ref
2085+
then
2086+
let snapshot_of = Db.VM.get_snapshot_of ~__context ~self:ref in
2087+
if snapshot_of <> Ref.null then (
2088+
debug "lookup for snapshot_of = '%s'" (Ref.string_of snapshot_of) ;
2089+
log_reraise
2090+
("Failed to find the VM which is snapshot of "
2091+
^ Db.VM.get_name_label ~__context ~self:ref
2092+
)
2093+
(fun table ->
2094+
let snapshot_of = (lookup snapshot_of) table in
2095+
Db.VM.set_snapshot_of ~__context ~self:ref ~value:snapshot_of
2096+
)
2097+
state.table
2098+
)
2099+
) ;
2100+
if cls = Datamodel_common._vm then (
2101+
let parent = Db.VM.get_parent ~__context ~self:ref in
2102+
debug "lookup for parent = '%s'" (Ref.string_of parent) ;
2103+
try
2104+
let parent = lookup parent state.table in
2105+
Db.VM.set_parent ~__context ~self:ref ~value:parent
2106+
with _ -> debug "no parent found"
2107+
)
21282108
in
2129-
List.iter go state.table
2109+
List.iter aux state.table
21302110

21312111
let check_references ~__context (table : table) =
21322112
let is_export_reference r =
@@ -2174,8 +2154,7 @@ let handle_all __context config rpc session_id (xs : obj list) =
21742154
false
21752155
in
21762156
if not dry_run then (
2177-
update_vm_links ~__context state ;
2178-
update_vdi_links ~__context state ;
2157+
update_snapshot_and_parent_links ~__context state ;
21792158
check_references ~__context state.table
21802159
) ;
21812160
state

0 commit comments

Comments
 (0)