Skip to content

Commit 9ee6a57

Browse files
committed
Refactor Storage_smapiv1.find_vdi
Move this to storage_utils.ml since it is used by storage_smapiv1.ml and storage_mux.ml Signed-off-by: Vincent Liu <[email protected]>
1 parent f0d21ae commit 9ee6a57

File tree

6 files changed

+37
-47
lines changed

6 files changed

+37
-47
lines changed

ocaml/xapi/storage_mux.ml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module D = Debug.Make (struct let name = "mux" end)
1919
open D
2020
open Storage_interface
2121
open Storage_mux_reg
22+
open Storage_utils
2223

2324
let s_of_sr = Storage_interface.Sr.string_of
2425

@@ -330,27 +331,6 @@ module Mux = struct
330331
Storage_migrate.update_snapshot_info_src ~dbg:(Debug_info.to_string di)
331332
~sr ~vdi ~url ~dest ~dest_vdi ~snapshot_pairs
332333

333-
exception No_VDI
334-
335-
(* Find a VDI given a storage-layer SR and VDI *)
336-
let find_vdi ~__context sr vdi =
337-
let sr = s_of_sr sr in
338-
let vdi = s_of_vdi vdi in
339-
let open Xapi_database.Db_filter_types in
340-
let sr = Db.SR.get_by_uuid ~__context ~uuid:sr in
341-
match
342-
Db.VDI.get_records_where ~__context
343-
~expr:
344-
(And
345-
( Eq (Field "location", Literal vdi)
346-
, Eq (Field "SR", Literal (Ref.string_of sr))
347-
)
348-
)
349-
with
350-
| x :: _ ->
351-
x
352-
| _ ->
353-
raise No_VDI
354334

355335
let set_is_a_snapshot _context ~dbg ~sr ~vdi ~is_a_snapshot =
356336
Server_helpers.exec_with_new_task "VDI.set_is_a_snapshot"

ocaml/xapi/storage_smapiv1.ml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ open D
1818
module Date = Clock.Date
1919
module XenAPI = Client.Client
2020
open Storage_interface
21-
22-
exception No_VDI
21+
open Storage_utils
2322

2423
let s_of_vdi = Vdi.string_of
2524

@@ -30,26 +29,6 @@ let with_lock = Xapi_stdext_threads.Threadext.Mutex.execute
3029
let with_dbg ~name ~dbg f =
3130
Debug_info.with_dbg ~module_name:"SMAPIv1" ~name ~dbg f
3231

33-
(* Find a VDI given a storage-layer SR and VDI *)
34-
let find_vdi ~__context sr vdi =
35-
let sr = s_of_sr sr in
36-
let vdi = s_of_vdi vdi in
37-
let open Xapi_database.Db_filter_types in
38-
let sr = Db.SR.get_by_uuid ~__context ~uuid:sr in
39-
match
40-
Db.VDI.get_records_where ~__context
41-
~expr:
42-
(And
43-
( Eq (Field "location", Literal vdi)
44-
, Eq (Field "SR", Literal (Ref.string_of sr))
45-
)
46-
)
47-
with
48-
| x :: _ ->
49-
x
50-
| _ ->
51-
raise No_VDI
52-
5332
(* Find a VDI reference given a name *)
5433
let find_content ~__context ?sr name =
5534
(* PR-1255: the backend should do this for us *)

ocaml/xapi/storage_smapiv1.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@ val vdi_read_write : (Sr.t * Vdi.t, bool) Hashtbl.t
2020

2121
val vdi_info_of_vdi_rec : Context.t -> API.vDI_t -> Storage_interface.vdi_info
2222

23-
val find_vdi : __context:Context.t -> Sr.t -> Vdi.t -> [`VDI] Ref.t * API.vDI_t
24-
(** Find a VDI given a storage-layer SR and VDI *)
25-
2623
module SMAPIv1 : Server_impl

ocaml/xapi/storage_utils.ml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
open Storage_interface
1616

17+
let s_of_sr = Storage_interface.Sr.string_of
18+
19+
let s_of_vdi = Storage_interface.Vdi.string_of
20+
1721
let string_of_vdi_type vdi_type =
1822
Rpc.string_of_rpc (API.rpc_of_vdi_type vdi_type)
1923

@@ -173,3 +177,24 @@ let transform_storage_exn f =
173177
(Api_errors.Server_error
174178
(Api_errors.internal_error, [Printexc.to_string e])
175179
)
180+
181+
exception No_VDI
182+
183+
let find_vdi ~__context sr vdi =
184+
let sr = s_of_sr sr in
185+
let vdi = s_of_vdi vdi in
186+
let open Xapi_database.Db_filter_types in
187+
let sr = Db.SR.get_by_uuid ~__context ~uuid:sr in
188+
match
189+
Db.VDI.get_records_where ~__context
190+
~expr:
191+
(And
192+
( Eq (Field "location", Literal vdi)
193+
, Eq (Field "SR", Literal (Ref.string_of sr))
194+
)
195+
)
196+
with
197+
| x :: _ ->
198+
x
199+
| _ ->
200+
raise No_VDI

ocaml/xapi/storage_utils.mli

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,12 @@ val rpc :
6464

6565
val transform_storage_exn : (unit -> 'a) -> 'a
6666
(** [transform_storage_exn f] runs [f], rethrowing any storage error as a nice XenAPI error *)
67+
68+
exception No_VDI
69+
70+
val find_vdi :
71+
__context:Context.t
72+
-> Storage_interface.sr
73+
-> Storage_interface.vdi
74+
-> [`VDI] Ref.t * API.vDI_t
75+
(** Find a VDI given a storage-layer SR and VDI *)

ocaml/xapi/xapi_services.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ let put_handler (req : Http.Request.t) s _ =
196196
http_proxy_to_plugin req s name
197197
| [""; services; "SM"; "data"; sr; vdi] when services = _services ->
198198
let vdi, _ =
199-
Storage_smapiv1.find_vdi ~__context
199+
Storage_utils.find_vdi ~__context
200200
(Storage_interface.Sr.of_string sr)
201201
(Storage_interface.Vdi.of_string vdi)
202202
in

0 commit comments

Comments
 (0)