@@ -206,9 +206,18 @@ let find_vdi ~__context ~label =
206
206
warn " %s: more than one VDI with label %s" __FUNCTION__ label ;
207
207
vdi
208
208
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
+
209
218
(* * notify the VM with [domid] to run sysprep and where to find the
210
219
file. *)
211
- let trigger ~domid ~uuid ~timeout =
220
+ let trigger ~rpc ~ session_id ~ domid ~uuid ~timeout ~ vbd ~ iso =
212
221
let open Ezxenstore_core.Xenstore in
213
222
let control = Printf. sprintf " /local/domain/%Ld/control/sysprep" domid in
214
223
let domain = Printf. sprintf " /local/domain/%Ld" domid in
@@ -228,19 +237,15 @@ let trigger ~domid ~uuid ~timeout =
228
237
Ezxenstore_core.Watch. (
229
238
wait_for ~xs ~timeout (key_to_disappear (control // " action" ))
230
239
) ;
231
- debug " %s sysprep is finished" __FUNCTION__ ;
240
+ debug " %s sysprep is finished; ejecting CD" __FUNCTION__ ;
241
+ eject ~rpc ~session_id ~vbd ~iso ;
232
242
Ezxenstore_core.Watch. (wait_for ~xs ~timeout (key_to_disappear domain)) ;
233
243
true
234
244
with Ezxenstore_core.Watch. Timeout _ ->
235
245
debug " %s: sysprep timeout" __FUNCTION__ ;
236
246
false
237
247
)
238
248
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
-
244
249
(* This function is executed on the host where [vm] is running *)
245
250
let sysprep ~__context ~vm ~unattend ~timeout =
246
251
debug " %s (timeout %f)" __FUNCTION__ timeout ;
@@ -275,19 +280,8 @@ let sysprep ~__context ~vm ~unattend ~timeout =
275
280
call ~__context @@ fun rpc session_id ->
276
281
Client.VBD. insert ~rpc ~session_id ~vdi ~vbd ;
277
282
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
+ ()
286
286
| 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
- ) ;
293
287
fail VM_sysprep_timeout
0 commit comments