Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ocaml/xapi/vm_sysprep.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type error =
| Other of string
| VM_CDR_not_found
| VM_CDR_eject
| VM_CDR_insert
| VM_misses_feature
| VM_not_running
| VM_sysprep_timeout
Expand Down Expand Up @@ -212,6 +213,8 @@ let eject ~rpc ~session_id ~vbd ~iso =
Client.VBD.eject ~rpc ~session_id ~vbd ;
Sys.remove iso
with exn ->
Sys.remove iso ;
(* still remove ISO to protect it *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour is a little uncommon. Can you describe in detail?
What's the relation between vbd and iso? If vbd eject fail, will it still exist? Then if we remove iso, will it be inconsistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ISO may contain secrets so we would like to not keeping it around. This is an ISO SR where we can add and remove ISOs and the SM layer will update xapi. I am not sure what happens from the VMs perspective, though.

warn "%s: ejecting CD failed: %s" __FUNCTION__ (Printexc.to_string exn) ;
fail VM_CDR_eject

Expand Down Expand Up @@ -281,7 +284,13 @@ let sysprep ~__context ~vm ~unattend ~timeout =
let uuid = Db.VDI.get_uuid ~__context ~self:vdi in
debug "%s: inserting Sysprep VDI for VM %s" __FUNCTION__ vm_uuid ;
call ~__context @@ fun rpc session_id ->
Client.VBD.insert ~rpc ~session_id ~vdi ~vbd ;
( try Client.VBD.insert ~rpc ~session_id ~vdi ~vbd
with e ->
debug "%s: failed to insert CD, removing ISO %s: %s" __FUNCTION__ iso
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be warn or error?

(Printexc.to_string e) ;
Sys.remove iso ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can Sys.remove fail? What happen if it fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can fail if the file does not exist, which should not happen. I could wrap this.

fail VM_CDR_insert
) ;
Thread.delay !Xapi_globs.vm_sysprep_wait ;
match trigger ~rpc ~session_id ~domid ~uuid ~timeout ~vbd ~iso with
| true ->
Expand Down
1 change: 1 addition & 0 deletions ocaml/xapi/vm_sysprep.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type error =
| Other of string
| VM_CDR_not_found
| VM_CDR_eject
| VM_CDR_insert
| VM_misses_feature
| VM_not_running
| VM_sysprep_timeout
Expand Down
5 changes: 4 additions & 1 deletion ocaml/xapi/xapi_vm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1727,10 +1727,13 @@ let sysprep ~__context ~self ~unattend ~timeout =
raise Api_errors.(Server_error (sysprep, [uuid; "VM is not running"]))
| exception Vm_sysprep.Sysprep VM_CDR_eject ->
raise Api_errors.(Server_error (sysprep, [uuid; "VM failed to eject CD"]))
| exception Vm_sysprep.Sysprep VM_CDR_insert ->
raise Api_errors.(Server_error (sysprep, [uuid; "VM failed to insert CD"]))
| exception Vm_sysprep.Sysprep VM_sysprep_timeout ->
raise
Api_errors.(
Server_error (sysprep, [uuid; "sysprep not found running - timeout"])
Server_error
(sysprep, [uuid; "No response from sysprep within allocated time"])
)
| exception Vm_sysprep.Sysprep XML_too_large ->
raise
Expand Down
Loading