Skip to content

Commit 1e31cd0

Browse files
psafontDavid Scottjohnelse
committed
storage: add VDI.revert
This operation allows storage backends to implement VDI revert natively, as well as advertise it. The operation is unused by xapi for the time being. Co-authored-by: David Scott <dave.scott@eu.citrix.com> Co-authored-by: John Else <john.else@citrix.com> Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech> (cherry picked from commit c368ca8)
1 parent f487aef commit 1e31cd0

10 files changed

Lines changed: 101 additions & 2 deletions

File tree

ocaml/xapi-idl/storage/storage_interface.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,15 @@ module StorageAPI (R : RPC) = struct
10261026
let result_p = Param.mk ~name:"changed_blocks" Types.string in
10271027
declare "VDI.list_changed_blocks" []
10281028
(dbg_p @-> sr_p @-> vdi_from_p @-> vdi_to_p @-> returning result_p err)
1029+
1030+
(** [revert dbg sr snapshot_info] creates a new VDI which is a clone of
1031+
[snapshot_info] in [sr]. The contents of the VDI in
1032+
[snapshot_info.snapshot_of] will be destroyed and replaced with the
1033+
contents of [snapshot] *)
1034+
let revert =
1035+
let snapshot_info_p = Param.mk ~name:"snapshot_info" vdi_info in
1036+
declare "VDI.revert" []
1037+
(dbg_p @-> sr_p @-> snapshot_info_p @-> returning unit_p err)
10291038
end
10301039

10311040
(** [get_by_name task name] returns a vdi with [name] (which may be in any SR) *)
@@ -1651,6 +1660,9 @@ module type Server_impl = sig
16511660

16521661
val list_changed_blocks :
16531662
context -> dbg:debug_info -> sr:sr -> vdi_from:vdi -> vdi_to:vdi -> string
1663+
1664+
val revert :
1665+
context -> dbg:debug_info -> sr:sr -> snapshot_info:vdi_info -> unit
16541666
end
16551667

16561668
val get_by_name : context -> dbg:debug_info -> name:string -> sr * vdi_info
@@ -1854,6 +1866,9 @@ module Server (Impl : Server_impl) () = struct
18541866
S.VDI.list_changed_blocks (fun dbg sr vdi_from vdi_to ->
18551867
Impl.VDI.list_changed_blocks () ~dbg ~sr ~vdi_from ~vdi_to
18561868
) ;
1869+
S.VDI.revert (fun dbg sr snapshot_info ->
1870+
Impl.VDI.revert () ~dbg ~sr ~snapshot_info
1871+
) ;
18571872
S.get_by_name (fun dbg name -> Impl.get_by_name () ~dbg ~name) ;
18581873
S.DATA.copy (fun dbg sr vdi vm url dest verify_dest ->
18591874
Impl.DATA.copy () ~dbg ~sr ~vdi ~vm ~url ~dest ~verify_dest

ocaml/xapi-idl/storage/storage_skeleton.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ module VDI = struct
175175

176176
let list_changed_blocks ctx ~dbg ~sr ~vdi_from ~vdi_to =
177177
Storage_interface.unimplemented __FUNCTION__
178+
179+
let revert ctx ~dbg ~sr ~snapshot_info =
180+
Storage_interface.unimplemented __FUNCTION__
178181
end
179182

180183
let get_by_name ctx ~dbg ~name = Storage_interface.unimplemented __FUNCTION__

ocaml/xapi-storage-script/main.ml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,8 @@ module VDIImpl (M : META) = struct
13551355
dbg sr vdi
13561356
)
13571357

1358+
let ( let* ) = Lwt_result.bind
1359+
13581360
let update_keys ~dbg ~sr ~key ~value response =
13591361
match value with
13601362
| None ->
@@ -1374,6 +1376,11 @@ module VDIImpl (M : META) = struct
13741376
Volume_client.destroy (volume_rpc ~dbg) dbg sr vdi
13751377
)
13761378

1379+
let revert ~dbg ~sr ~snapshot ~vdi =
1380+
return_volume_rpc (fun () ->
1381+
Volume_client.revert (volume_rpc ~dbg) dbg sr snapshot vdi
1382+
)
1383+
13771384
let vdi_attach_common dbg sr vdi domain =
13781385
Attached_SRs.find sr >>>= fun sr ->
13791386
(* Discover the URIs using Volume.stat *)
@@ -1424,6 +1431,14 @@ module VDIImpl (M : META) = struct
14241431
)
14251432
|> wrap
14261433

1434+
let revert_impl dbg sr snapshot_info =
1435+
wrap
1436+
@@
1437+
let snapshot = Storage_interface.(Vdi.string_of snapshot_info.vdi) in
1438+
let vdi = Storage_interface.(Vdi.string_of snapshot_info.snapshot_of) in
1439+
let* sr = Attached_SRs.find sr in
1440+
revert ~dbg ~sr ~snapshot ~vdi
1441+
14271442
let vdi_snapshot_impl dbg sr vdi_info =
14281443
Attached_SRs.find sr
14291444
>>>= (fun sr ->
@@ -1662,8 +1677,6 @@ module VDIImpl (M : META) = struct
16621677

16631678
let vdi_set_persistent_impl _dbg _sr _vdi _persistent = return () |> wrap
16641679

1665-
let ( let* ) = Lwt_result.bind
1666-
16671680
let vdi_enable_cbt_impl dbg sr vdi =
16681681
wrap
16691682
@@
@@ -1953,6 +1966,7 @@ let bind ~volume_script_dir =
19531966
S.VDI.add_to_sm_config VDI.vdi_add_to_sm_config_impl ;
19541967
S.VDI.remove_from_sm_config VDI.vdi_remove_from_sm_config_impl ;
19551968
S.VDI.similar_content VDI.similar_content_impl ;
1969+
S.VDI.revert VDI.revert_impl ;
19561970

19571971
let module DP = DPImpl (RuntimeMeta) in
19581972
S.DP.destroy2 DP.dp_destroy2 ;

ocaml/xapi-storage/generator/lib/control.ml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,27 @@ module Volume (R : RPC) = struct
276276
["[destroy sr volume] removes [volume] from [sr]"]
277277
(dbg @-> sr @-> key @-> returning unit errors)
278278

279+
let revert =
280+
let snapshot_p =
281+
Param.
282+
{
283+
key with
284+
name= Some "snapshot"
285+
; description=
286+
[
287+
"Read-only volume with the contents that are to be present in \
288+
the resulting volume"
289+
]
290+
}
291+
in
292+
R.declare "revert"
293+
[
294+
"[revert sr snapshot volume] returns a reference to a volume. This "
295+
; "volume must contain the contents of the read-only [snapshot], and its "
296+
; "identity must remain the same as [volume]."
297+
]
298+
(dbg @-> sr @-> snapshot_p @-> key @-> returning unit errors)
299+
279300
let new_name =
280301
Param.mk ~name:"new_name" ~description:["New name"] Types.string
281302

ocaml/xapi-storage/generator/test/storage_test.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ let volume_server () =
189189
Volume.data_destroy unimplemented ;
190190
Volume.list_changed_blocks unimplemented ;
191191
Volume.compose unimplemented ;
192+
Volume.revert unimplemented ;
192193

193194
Idl.Exn.server Volume.implementation
194195

ocaml/xapi/sm.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,18 @@ let vdi_snapshot ~dbg dconf driver driver_params sr vdi =
269269
in
270270
Sm_exec.parse_vdi_info (Sm_exec.exec_xmlrpc ~dbg (driver_filename driver) call)
271271

272+
let vdi_revert ~dbg dconf driver sr vdi snapshot =
273+
debug "vdi_revert" driver
274+
(sprintf "sr=%s vdi=%s snapshot=%s" (Ref.string_of sr) (Ref.string_of vdi)
275+
(Ref.string_of snapshot)
276+
) ;
277+
(* NB the SM backends treat the snapshot as the 'target', hence first argument *)
278+
let call =
279+
Sm_exec.make_call ~sr_ref:sr ~vdi_ref:snapshot dconf "vdi_revert"
280+
[Ref.string_of vdi]
281+
in
282+
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc ~dbg (driver_filename driver) call)
283+
272284
let vdi_clone ~dbg dconf driver driver_params sr vdi =
273285
with_dbg ~dbg ~name:"vdi_clone" @@ fun di ->
274286
let dbg = Debug_info.to_string di in

ocaml/xapi/smint.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ module Feature = struct
6060
| Large_vdi (** Supports >2TB VDIs *)
6161
| Thin_provisioning
6262
| Vdi_read_caching
63+
| Vdi_revert
6364

6465
type t = capability * int64
6566

@@ -101,6 +102,7 @@ module Feature = struct
101102
; ("LARGE_VDI", Large_vdi)
102103
; ("THIN_PROVISIONING", Thin_provisioning)
103104
; ("VDI_READ_CACHING", Vdi_read_caching)
105+
; ("VDI_REVERT", Vdi_revert)
104106
]
105107

106108
let capability_to_string_table =

ocaml/xapi/storage_mux.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,15 @@ module Mux = struct
782782
let rpc = of_sr sr
783783
end)) in
784784
C.VDI.list_changed_blocks (Debug_info.to_string di) sr vdi_from vdi_to
785+
786+
let revert () ~dbg ~sr ~snapshot_info =
787+
with_dbg ~name:"VDI.revert" ~dbg @@ fun di ->
788+
info "VDI.revert dbg:%s sr:%s snapshot:%s" dbg (s_of_sr sr)
789+
(string_of_vdi_info snapshot_info) ;
790+
let module C = StorageAPI (Idl.Exn.GenClient (struct
791+
let rpc = of_sr sr
792+
end)) in
793+
C.VDI.revert (Debug_info.to_string di) sr snapshot_info
785794
end
786795

787796
let get_by_name () ~dbg ~name =

ocaml/xapi/storage_smapiv1.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,21 @@ module SMAPIv1 : Server_impl = struct
11251125
raise (Storage_error (Backend_error (code, params)))
11261126
| Sm.MasterOnly ->
11271127
redirect sr
1128+
1129+
let call_revert ~__context ~dbg ~sr ~snapshot_info =
1130+
let snap = find_vdi ~__context sr snapshot_info.vdi |> fst in
1131+
for_vdi ~dbg ~sr ~vdi:snapshot_info.snapshot_of "VDI.revert"
1132+
(fun device_config _type sr self ->
1133+
Sm.vdi_revert ~dbg device_config _type sr self snap
1134+
)
1135+
1136+
let revert _context ~dbg ~sr ~snapshot_info =
1137+
with_dbg ~name:"VDI.revert" ~dbg @@ fun di ->
1138+
let dbg = Debug_info.to_string di in
1139+
Server_helpers.exec_with_new_task "VDI.revert"
1140+
~subtask_of:(Ref.of_string dbg) (fun __context ->
1141+
call_revert ~__context ~dbg ~sr ~snapshot_info
1142+
)
11281143
end
11291144

11301145
let get_by_name _context ~dbg:_ ~name:_ = assert false

ocaml/xapi/storage_smapiv1_wrapper.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,13 @@ functor
843843
let data_destroy =
844844
destroy_and_data_destroy "VDI.data_destroy" Impl.VDI.data_destroy
845845

846+
let revert context ~dbg ~sr ~snapshot_info =
847+
with_dbg ~name:"VDI.revert" ~dbg @@ fun di ->
848+
info "VDI.revert dbg:%s sr:%s snapshot:%s" di.log (s_of_sr sr)
849+
(string_of_vdi_info snapshot_info) ;
850+
let dbg = Debug_info.to_string di in
851+
Impl.VDI.revert context ~dbg ~sr ~snapshot_info
852+
846853
let stat context ~dbg ~sr ~vdi =
847854
with_dbg ~name:"VDI.stat" ~dbg @@ fun di ->
848855
info "VDI.stat dbg:%s sr:%s vdi:%s" di.log (s_of_sr sr) (s_of_vdi vdi) ;

0 commit comments

Comments
 (0)