Skip to content

Commit cb9cd26

Browse files
lindigChristian Lindig
authored andcommitted
CP-308455 VM.sysprep CA-414158 wait for "action" key to disappear (xapi-project#6604)
Eject CD once sysprep is no longer running. This moves it to an earlier point to avoid we try to eject the CD when the VM is rebooting and is not cooperating. Signed-off-by: Christian Lindig <christian.lindig@cloud.com>
1 parent a3471c6 commit cb9cd26

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

ocaml/xapi/vm_sysprep.ml

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,18 @@ let find_vdi ~__context ~label =
206206
warn "%s: more than one VDI with label %s" __FUNCTION__ label ;
207207
vdi
208208

209+
(* Ejecting the CD/VDI/ISO may fail with a timeout *)
210+
let eject ~rpc ~session_id ~vbd ~iso =
211+
try
212+
Client.VBD.eject ~rpc ~session_id ~vbd ;
213+
Sys.remove iso
214+
with exn ->
215+
debug "%s: ejecting CD failed: %s" __FUNCTION__ (Printexc.to_string exn) ;
216+
fail VM_CDR_eject
217+
209218
(** notify the VM with [domid] to run sysprep and where to find the
210219
file. *)
211-
let trigger ~domid ~uuid ~timeout =
220+
let trigger ~rpc ~session_id ~domid ~uuid ~timeout ~vbd ~iso =
212221
let open Ezxenstore_core.Xenstore in
213222
let control = Printf.sprintf "/local/domain/%Ld/control/sysprep" domid in
214223
let domain = Printf.sprintf "/local/domain/%Ld" domid in
@@ -228,19 +237,15 @@ let trigger ~domid ~uuid ~timeout =
228237
Ezxenstore_core.Watch.(
229238
wait_for ~xs ~timeout (key_to_disappear (control // "action"))
230239
) ;
231-
debug "%s sysprep is finished" __FUNCTION__ ;
240+
debug "%s sysprep is finished; ejecting CD" __FUNCTION__ ;
241+
eject ~rpc ~session_id ~vbd ~iso ;
232242
Ezxenstore_core.Watch.(wait_for ~xs ~timeout (key_to_disappear domain)) ;
233243
true
234244
with Ezxenstore_core.Watch.Timeout _ ->
235245
debug "%s: sysprep timeout" __FUNCTION__ ;
236246
false
237247
)
238248

239-
(* Ejecting the CD/VDI/ISO may fail with a timeout *)
240-
let eject ~rpc ~session_id iso vbd =
241-
Client.VBD.eject ~rpc ~session_id ~vbd ;
242-
Sys.remove iso
243-
244249
(* This function is executed on the host where [vm] is running *)
245250
let sysprep ~__context ~vm ~unattend ~timeout =
246251
debug "%s (timeout %f)" __FUNCTION__ timeout ;
@@ -275,19 +280,8 @@ let sysprep ~__context ~vm ~unattend ~timeout =
275280
call ~__context @@ fun rpc session_id ->
276281
Client.VBD.insert ~rpc ~session_id ~vdi ~vbd ;
277282
Thread.delay !Xapi_globs.vm_sysprep_wait ;
278-
match trigger ~domid ~uuid ~timeout with
279-
| true -> (
280-
debug "%s: sysprep running, ejecting CD" __FUNCTION__ ;
281-
try eject ~rpc ~session_id iso vbd
282-
with exn ->
283-
debug "%s: ejecting CD failed: %s" __FUNCTION__ (Printexc.to_string exn) ;
284-
fail VM_CDR_eject
285-
)
283+
match trigger ~rpc ~session_id ~domid ~uuid ~timeout ~vbd ~iso with
284+
| true ->
285+
()
286286
| false ->
287-
debug "%s: sysprep timeout, ejecting CD" __FUNCTION__ ;
288-
( try eject ~rpc ~session_id iso vbd
289-
with exn ->
290-
debug "%s: ejecting CD failed: %s" __FUNCTION__
291-
(Printexc.to_string exn)
292-
) ;
293287
fail VM_sysprep_timeout

0 commit comments

Comments
 (0)