File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4275,6 +4275,7 @@ module SR = struct
42754275 ; (" vdi_generate_config" , " Generating the configuration of the VDI" )
42764276 ; (" vdi_resize_online" , " Resizing the VDI online" )
42774277 ; (" vdi_update" , " Refreshing the fields on the VDI" )
4278+ ; (" vdi_revert" , " Reverting a VDI to the snapshot" )
42784279 ; (" pbd_create" , " Creating a PBD for this SR" )
42794280 ; (" pbd_destroy" , " Destroying one of this SR's PBDs" )
42804281 ]
@@ -5476,6 +5477,16 @@ module VDI = struct
54765477 different SR. The destination SR must be visible to the guest."
54775478 ~allowed_roles: _R_VM_POWER_ADMIN ()
54785479
5480+ let revert =
5481+ call ~name: " revert" ~in_oss_since: None ~lifecycle: []
5482+ ~params:
5483+ [(Ref _vdi, " snapshot" , " The snapshot to which we want to revert" )]
5484+ ~doc:
5485+ " Copy the contents of a snapshot to the VDI it's related to. The \
5486+ original contents of the VDI are lost."
5487+ ~errs: [Api_errors. unimplemented_in_sm_backend]
5488+ ~allowed_roles: _R_VM_POWER_ADMIN ~doc_tags: [Snapshots ] ()
5489+
54795490 let introduce_params first_rel =
54805491 [
54815492 {
@@ -6258,6 +6269,7 @@ module VDI = struct
62586269 ; data_destroy
62596270 ; list_changed_blocks
62606271 ; get_nbd_info
6272+ ; revert
62616273 ]
62626274 ~contents:
62636275 ([
Original file line number Diff line number Diff line change @@ -360,6 +360,8 @@ let sr_operation_to_string : API.storage_operations -> string = function
360360 " VDI.resize_online"
361361 | `vdi_update ->
362362 " VDI.update"
363+ | `vdi_revert ->
364+ " VDI.revert"
363365
364366let vbd_operation_to_string = function
365367 | `attach ->
Original file line number Diff line number Diff line change @@ -175,6 +175,8 @@ let sr_operation_to_string : API.storage_operations -> string = function
175175 " VDI.resize_online"
176176 | `vdi_update ->
177177 " VDI.update"
178+ | `vdi_revert ->
179+ " VDI.revert"
178180 | `pbd_create ->
179181 " PBD.create"
180182 | `pbd_destroy ->
Original file line number Diff line number Diff line change @@ -5563,6 +5563,23 @@ functor
55635563 forward_vdi_op ~local_fn ~__context ~self: vdi ~remote_fn
55645564 )
55655565
5566+ let revert ~__context ~snapshot =
5567+ let ( let@ ) f x = f x in
5568+ let doc = " VDI.revert" in
5569+ info " %s: snapshot = '%s'" doc (vdi_uuid ~__context snapshot) ;
5570+ let local_fn = Local.VDI. revert ~snapshot in
5571+ let remote_fn = Client.VDI. revert ~snapshot in
5572+ let sr = Db.VDI. get_SR ~__context ~self: snapshot in
5573+ let vdi = Db.VDI. get_snapshot_of ~__context ~self: snapshot in
5574+ let op () =
5575+ forward_vdi_op ~local_fn ~__context ~self: snapshot ~remote_fn
5576+ in
5577+ let @ () =
5578+ with_sr_andor_vdi ~__context ~sr: (sr, `vdi_revert )
5579+ ~vdi: (snapshot, `revert_to ) ~doc
5580+ in
5581+ with_sr_andor_vdi ~__context ~vdi: (vdi, `revert_from ) ~doc op
5582+
55665583 let copy ~__context ~vdi ~sr ~base_vdi ~into_vdi =
55675584 info " VDI.copy: VDI = '%s'; SR = '%s'; base_vdi = '%s'; into_vdi = '%s'"
55685585 (vdi_uuid ~__context vdi) (sr_uuid ~__context sr)
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ let all_ops : API.storage_operations_set =
4848 ; `vdi_list_changed_blocks
4949 ; `vdi_set_on_boot
5050 ; `vdi_introduce
51+ ; `vdi_revert
5152 ; `update
5253 ; `pbd_create
5354 ; `pbd_destroy
@@ -89,6 +90,7 @@ let sm_cap_table : (API.storage_operations * _) list =
8990 ; (`vdi_list_changed_blocks , Vdi_configure_cbt )
9091 ; (`vdi_set_on_boot , Vdi_reset_on_boot )
9192 ; (`update , Sr_update )
93+ ; (`vdi_revert , Vdi_revert )
9294 ; (* We fake clone ourselves *)
9395 (`vdi_snapshot , Vdi_snapshot )
9496 ]
Original file line number Diff line number Diff line change @@ -1118,6 +1118,32 @@ let clone ~__context ~vdi ~driver_params =
11181118 )
11191119 )
11201120
1121+ let revert' ~__context ~snapshot =
1122+ let module C = Storage_interface. StorageAPI (Idl.Exn. GenClient (struct
1123+ let rpc = Storage_access. rpc
1124+ end )) in
1125+ let sr = Db.VDI. get_SR ~__context ~self: snapshot in
1126+ Sm. assert_pbd_is_plugged ~__context ~sr ;
1127+ Xapi_vdi_helpers. assert_managed ~__context ~vdi: snapshot ;
1128+ let snapshot_rec = Db.VDI. get_record ~__context ~self: snapshot in
1129+
1130+ let task = Context. get_task_id __context in
1131+ let snapshot_info =
1132+ Storage_smapiv1. vdi_info_of_vdi_rec __context snapshot_rec
1133+ in
1134+ let sr' =
1135+ Db.SR. get_uuid ~__context ~self: sr |> Storage_interface.Sr. of_string
1136+ in
1137+ (* We don't use transform_storage_exn because of the fallback below *)
1138+ C.VDI. revert (Ref. string_of task) sr' snapshot_info
1139+
1140+ let revert ~__context ~snapshot =
1141+ Storage_utils. transform_storage_exn @@ fun () ->
1142+ try revert' ~__context ~snapshot
1143+ with Storage_interface. Storage_error (Unimplemented _ ) ->
1144+ let msg = [Ref. string_of (Db.VDI. get_SR ~__context ~self: snapshot)] in
1145+ raise Api_errors. (Server_error (unimplemented_in_sm_backend, msg))
1146+
11211147let copy ~__context ~vdi ~sr ~base_vdi ~into_vdi =
11221148 Xapi_vdi_helpers. assert_managed ~__context ~vdi ;
11231149 let task_id = Ref. string_of (Context. get_task_id __context) in
Original file line number Diff line number Diff line change @@ -258,3 +258,5 @@ val _get_nbd_info :
258258 [get_server_certificate] function can be provided to avoid querying the real
259259 certificate using the Client module, which is what {!get_nbd_info} does,
260260 which would cause the unit test to fail. *)
261+
262+ val revert : __context :Context .t -> snapshot :[`VDI ] Ref .t -> unit
You can’t perform that action at this time.
0 commit comments