Skip to content

Commit 93d6bce

Browse files
committed
CA-78221: use sm-config instead of other-config
Also remove the ~params field of create/clone/snapshot calls are now we can pass the parameters using sm-config
1 parent 1c84645 commit 93d6bce

File tree

10 files changed

+117
-86
lines changed

10 files changed

+117
-86
lines changed

ocaml/sm-cli/main.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ let _ =
103103
if Array.length Sys.argv < 3 then usage_and_exit ();
104104
let kvpairs = kvpairs args in
105105
let find key = if List.mem_assoc key kvpairs then Some (List.assoc key kvpairs) else None in
106+
let params = List.filter_map
107+
(fun (k, v) ->
108+
let prefix = "params:" in
109+
let l = String.length prefix in
110+
if String.startswith prefix k
111+
then Some (String.sub k l (String.length k - l), v)
112+
else None) kvpairs in
106113
let vdi_info = {
107114
vdi = "";
108115
sr = sr;
@@ -118,17 +125,10 @@ let _ =
118125
virtual_size = Opt.default 1L (Opt.map Int64.of_string (find "virtual_size"));
119126
physical_utilisation = 0L;
120127
persistent = true;
121-
base_mirror = find "base_mirror";
128+
sm_config = params;
122129
} in
123-
let params = List.filter_map
124-
(fun (k, v) ->
125-
let prefix = "params:" in
126-
let l = String.length prefix in
127-
if String.startswith prefix k
128-
then Some (String.sub k l (String.length k - l), v)
129-
else None) kvpairs in
130130

131-
let v = Client.VDI.create ~dbg ~sr ~vdi_info ~params in
131+
let v = Client.VDI.create ~dbg ~sr ~vdi_info in
132132
Printf.printf "%s\n" (string_of_vdi_info v)
133133
| [ "vdi-destroy"; sr; vdi ] ->
134134
Client.VDI.destroy ~dbg ~sr ~vdi

ocaml/sm-cli/test.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ let example_vdi_info =
170170
let read_only = false in
171171
let virtual_size = Int64.mul 8L mib in
172172
let physical_utilisation = 0L in
173-
let base_mirror = None in
173+
let sm_config = [] in
174174
{
175175
vdi = "";
176176
sr = "";
@@ -186,13 +186,13 @@ let example_vdi_info =
186186
virtual_size = virtual_size;
187187
physical_utilisation = physical_utilisation;
188188
persistent = true;
189-
base_mirror = base_mirror;
189+
sm_config = sm_config;
190190
}
191191

192192
let test_create_destroy sr _ =
193193
let vdi_info = example_vdi_info in
194194
let vdi_info' =
195-
let vdi_info' = SMClient.VDI.create ~dbg ~sr ~vdi_info ~params:[] in
195+
let vdi_info' = SMClient.VDI.create ~dbg ~sr ~vdi_info in
196196
vdi_info_assert_equal vdi_info vdi_info';
197197
vdi_info'
198198
in
@@ -207,7 +207,7 @@ let test_create_destroy sr _ =
207207
end
208208

209209
let test_attach_activate url sr _ =
210-
let vdi_info = SMClient.VDI.create ~dbg ~sr ~vdi_info:example_vdi_info ~params:[] in
210+
let vdi_info = SMClient.VDI.create ~dbg ~sr ~vdi_info:example_vdi_info in
211211
let dp = "test_attach_activate" in
212212
let _ = SMClient.VDI.attach ~dbg ~sr ~dp ~vdi:vdi_info.vdi ~read_write:true in
213213
SMClient.VDI.activate ~dbg ~sr ~dp ~vdi:vdi_info.vdi;
@@ -230,7 +230,7 @@ let test_attach_activate url sr _ =
230230
SMClient.VDI.destroy ~dbg ~sr ~vdi:vdi_info.vdi
231231

232232
let test_mirror_1 url sr rurl rsr _ =
233-
let vdi_info = SMClient.VDI.create ~dbg ~sr ~vdi_info:example_vdi_info ~params:[] in
233+
let vdi_info = SMClient.VDI.create ~dbg ~sr ~vdi_info:example_vdi_info in
234234
let dp = "test_attach_activate" in
235235
ignore(SMClient.VDI.attach ~dbg ~sr ~dp ~vdi:vdi_info.vdi ~read_write:true);
236236
SMClient.VDI.activate ~dbg ~sr ~dp ~vdi:vdi_info.vdi;

ocaml/xapi/storage_access.ml

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ module SMAPIv1 = struct
8484
let stat_vdi context ~dbg ~sr ~vdi = assert false
8585
end
8686

87-
let base_mirror vdi_rec = (* CA-78221 *)
88-
if List.mem_assoc "base_mirror" vdi_rec.API.vDI_other_config then
89-
let id = List.assoc "base_mirror" vdi_rec.API.vDI_other_config in
90-
Some id
91-
else
92-
None
93-
9487
module SR = struct
9588
let create context ~dbg ~sr ~device_config ~physical_size =
9689
Server_helpers.exec_with_new_task "SR.create" ~subtask_of:(Ref.of_string dbg)
@@ -197,7 +190,7 @@ module SMAPIv1 = struct
197190
virtual_size = vdi_rec.API.vDI_virtual_size;
198191
physical_utilisation = vdi_rec.API.vDI_physical_utilisation;
199192
persistent = vdi_rec.API.vDI_on_boot = `persist;
200-
base_mirror = base_mirror vdi_rec;
193+
sm_config = vdi_rec.API.vDI_sm_config;
201194
}
202195

203196
let scan context ~dbg ~sr:sr' =
@@ -336,24 +329,29 @@ module SMAPIv1 = struct
336329
read_only = r.API.vDI_read_only;
337330
virtual_size = r.API.vDI_virtual_size;
338331
physical_utilisation = r.API.vDI_physical_utilisation;
332+
<<<<<<< HEAD
339333
persistent = r.API.vDI_on_boot = `persist;
340334
base_mirror = base_mirror r;
335+
=======
336+
sm_config = r.API.vDI_sm_config;
337+
>>>>>>> CA-78221: use sm-config instead of other-config
341338
}
342339

343340
let newvdi ~__context vi =
344341
(* The current backends stash data directly in the db *)
345342
let uuid = require_uuid vi in
346343
vdi_info_from_db ~__context (Db.VDI.get_by_uuid ~__context ~uuid)
347344

348-
let create context ~dbg ~sr ~vdi_info ~params =
345+
let create context ~dbg ~sr ~vdi_info =
349346
try
350347
Server_helpers.exec_with_new_task "VDI.create" ~subtask_of:(Ref.of_string dbg)
351348
(fun __context ->
349+
let sm_config = vdi_info.sm_config in
352350
let sr = Db.SR.get_by_uuid ~__context ~uuid:sr in
353351
let vi =
354352
Sm.call_sm_functions ~__context ~sR:sr
355353
(fun device_config _type ->
356-
Sm.vdi_create device_config _type sr params vdi_info.ty
354+
Sm.vdi_create device_config _type sr sm_config vdi_info.ty
357355
vdi_info.virtual_size vdi_info.name_label vdi_info.name_description
358356
vdi_info.metadata_of_pool vdi_info.is_a_snapshot
359357
vdi_info.snapshot_time vdi_info.snapshot_of vdi_info.read_only
@@ -364,13 +362,18 @@ module SMAPIv1 = struct
364362
| Api_errors.Server_error(code, params) -> raise (Backend_error(code, params))
365363
| Sm.MasterOnly -> redirect sr
366364

367-
let snapshot_and_clone call_name call_f context ~dbg ~sr ~vdi ~vdi_info ~params =
365+
(* A list of keys in sm-config that will be preserved on clone/snapshot *)
366+
let sm_config_keys_to_preserve_on_clone = [
367+
"base_mirror"
368+
]
369+
370+
let snapshot_and_clone call_name call_f context ~dbg ~sr ~vdi ~vdi_info =
368371
try
369372
Server_helpers.exec_with_new_task call_name ~subtask_of:(Ref.of_string dbg)
370373
(fun __context ->
371374
let vi = for_vdi ~dbg ~sr ~vdi call_name
372375
(fun device_config _type sr self ->
373-
call_f device_config _type params sr self
376+
call_f device_config _type vdi_info.sm_config sr self
374377
) in
375378
(* PR-1255: modify clone, snapshot to take the same parameters as create? *)
376379
let self, _ = find_vdi ~__context sr vi.Smint.vdi_info_location in
@@ -386,10 +389,12 @@ module SMAPIv1 = struct
386389
Db.VDI.set_name_description ~__context ~self ~value:vdi_info.name_description;
387390
Db.VDI.remove_from_other_config ~__context ~self ~key:"content_id";
388391
Db.VDI.add_to_other_config ~__context ~self ~key:"content_id" ~value:content_id;
389-
Opt.iter (fun id ->
390-
Db.VDI.remove_from_other_config ~__context ~self ~key:"base_mirror";
391-
Db.VDI.add_to_other_config ~__context ~self ~key:"base_mirror" ~value:id;
392-
) vdi_info.base_mirror;
392+
List.iter (fun (key, value) ->
393+
if List.mem key sm_config_keys_to_preserve_on_clone then (
394+
Db.VDI.remove_from_sm_config ~__context ~self ~key;
395+
Db.VDI.add_to_sm_config ~__context ~self ~key ~value;
396+
)
397+
) vdi_info.sm_config;
393398
for_vdi ~dbg ~sr ~vdi:vi.Smint.vdi_info_location "VDI.update"
394399
(fun device_config _type sr self ->
395400
Sm.vdi_update device_config _type sr self
@@ -553,9 +558,16 @@ module SMAPIv1 = struct
553558
raise (Vdi_does_not_exist vdi1)
554559
| Sm.MasterOnly -> redirect sr
555560

556-
let remove_from_other_config context ~dbg ~sr ~vdi ~key =
557-
info "VDI.update_record dbg:%s sr:%s vdi:%s" dbg sr vdi;
558-
Server_helpers.exec_with_new_task "VDI.update_record" ~subtask_of:(Ref.of_string dbg)
561+
let add_to_sm_config context ~dbg ~sr ~vdi ~key ~value =
562+
info "VDI.add_to_sm_config dbg:%s sr:%s vdi:%s key:%s value:%s" dbg sr vdi key value;
563+
Server_helpers.exec_with_new_task "VDI.add_to_sm_config" ~subtask_of:(Ref.of_string dbg)
564+
(fun __context ->
565+
let self = find_vdi ~__context sr vdi |> fst in
566+
Db.VDI.add_to_sm_config ~__context ~self ~key ~value)
567+
568+
let remove_from_sm_config context ~dbg ~sr ~vdi ~key =
569+
info "VDI.remove_from_sm_config dbg:%s sr:%s vdi:%s key:%s" dbg sr vdi key;
570+
Server_helpers.exec_with_new_task "VDI.remove_from_sm_config" ~subtask_of:(Ref.of_string dbg)
559571
(fun __context ->
560572
let self = find_vdi ~__context sr vdi |> fst in
561573
Db.VDI.remove_from_other_config ~__context ~self ~key)

ocaml/xapi/storage_impl.ml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -458,20 +458,20 @@ module Wrapper = functor(Impl: Server_impl) -> struct
458458
Impl.VDI.epoch_end context ~dbg ~sr ~vdi
459459
))
460460

461-
let create context ~dbg ~sr ~vdi_info ~params =
462-
info "VDI.create dbg:%s sr:%s vdi_info:%s params:%s" dbg sr (string_of_vdi_info vdi_info) (String.concat "; " (List.map (fun (k, v) -> k ^ ":" ^ v) params));
463-
let result = Impl.VDI.create context ~dbg ~sr ~vdi_info ~params in
461+
let create context ~dbg ~sr ~vdi_info =
462+
info "VDI.create dbg:%s sr:%s vdi_info:%s" dbg sr (string_of_vdi_info vdi_info);
463+
let result = Impl.VDI.create context ~dbg ~sr ~vdi_info in
464464
match result with
465465
| { virtual_size = virtual_size' } when virtual_size' < vdi_info.virtual_size ->
466466
error "VDI.create dbg:%s created a smaller VDI (%Ld)" dbg virtual_size';
467467
raise (Backend_error("SR_BACKEND_FAILURE", ["Disk too small"; Int64.to_string vdi_info.virtual_size; Int64.to_string virtual_size']))
468468
| result -> result
469469

470-
let snapshot_and_clone call_name call_f context ~dbg ~sr ~vdi ~vdi_info ~params =
471-
info "%s dbg:%s sr:%s vdi:%s vdi_info:%s params:%s" call_name dbg sr vdi (string_of_vdi_info vdi_info) (String.concat ";" (List.map (fun (k, v) -> k ^ ":" ^ v) params));
470+
let snapshot_and_clone call_name call_f context ~dbg ~sr ~vdi ~vdi_info =
471+
info "%s dbg:%s sr:%s vdi:%s vdi_info:%s" call_name dbg sr vdi (string_of_vdi_info vdi_info);
472472
with_vdi sr vdi
473473
(fun () ->
474-
call_f context ~dbg ~sr ~vdi ~vdi_info ~params
474+
call_f context ~dbg ~sr ~vdi ~vdi_info
475475
)
476476

477477
let snapshot = snapshot_and_clone "VDI.snapshot" Impl.VDI.snapshot
@@ -515,9 +515,13 @@ module Wrapper = functor(Impl: Server_impl) -> struct
515515
info "VDI.compose dbg:%s sr:%s vdi1:%s vdi2:%s" dbg sr vdi1 vdi2;
516516
Impl.VDI.compose context ~dbg ~sr ~vdi1 ~vdi2
517517

518-
let remove_from_other_config context ~dbg ~sr ~vdi ~key =
518+
let add_to_sm_config context ~dbg ~sr ~vdi ~key ~value =
519+
info "VDI.add_to_other_config dbg:%s sr:%s vdi:%s key:%s valu:%s" dbg sr vdi key value;
520+
Impl.VDI.add_to_sm_config context ~dbg ~sr ~vdi ~key ~value
521+
522+
let remove_from_sm_config context ~dbg ~sr ~vdi ~key =
519523
info "VDI.remove_from_other_config dbg:%s sr:%s vdi:%s key:%s" dbg sr vdi key;
520-
Impl.VDI.remove_from_other_config context ~dbg ~sr ~vdi ~key
524+
Impl.VDI.remove_from_sm_config context ~dbg ~sr ~vdi ~key
521525

522526
let get_url context ~dbg ~sr ~vdi =
523527
info "VDI.get_url dbg:%s sr:%s vdi:%s" dbg sr vdi;

ocaml/xapi/storage_impl_test.ml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ module Debug_print_impl = struct
5454
let created = Hashtbl.create 10
5555
let key_of sr vdi = Printf.sprintf "%s/%s" sr vdi
5656

57-
let create context ~dbg ~sr ~vdi_info ~params =
57+
let create context ~dbg ~sr ~vdi_info =
5858
let vdi = "newvdi" in
5959
let info =
60-
if List.mem_assoc "toosmall" params
60+
if List.mem_assoc "toosmall" vdi_info.sm_config
6161
then { vdi_info with virtual_size = Int64.sub vdi_info.virtual_size 1L }
6262
else vdi_info in
6363
Mutex.execute m
@@ -67,8 +67,8 @@ module Debug_print_impl = struct
6767
);
6868
info
6969

70-
let snapshot context ~dbg ~sr ~vdi ~vdi_info ~params =
71-
create context ~dbg ~sr ~vdi_info ~params
70+
let snapshot context ~dbg ~sr ~vdi ~vdi_info =
71+
create context ~dbg ~sr ~vdi_info
7272
let clone = snapshot
7373

7474
let destroy context ~dbg ~sr ~vdi =
@@ -153,7 +153,8 @@ module Debug_print_impl = struct
153153

154154
let get_url context ~dbg ~sr ~vdi = assert false
155155
let compose context ~dbg ~sr ~vdi1 ~vdi2 = assert false
156-
let remove_from_other_config context ~dbg ~sr ~vdi ~key = assert false
156+
let add_to_sm_config context ~dbg ~sr ~vdi ~key ~value = assert false
157+
let remove_from_sm_config context ~dbg ~sr ~vdi ~key = assert false
157158
let set_content_id context ~dbg ~sr ~vdi ~content_id = assert false
158159
let get_by_name context ~dbg ~sr ~name = assert false
159160
let similar_content context ~dbg ~sr ~vdi = assert false
@@ -469,11 +470,13 @@ let create_vdi_test sr =
469470
physical_utilisation = 10L;
470471
metadata_of_pool = "";
471472
persistent = true;
472-
base_mirror = None;
473+
sm_config = [];
473474
} in
474475
expect "too_small_backend_error" too_small_backend_error
475-
(fun () -> Client.VDI.create ~dbg ~sr ~vdi_info ~params:["toosmall", ""]);
476-
let vdi = Client.VDI.create ~dbg ~sr ~vdi_info ~params:[] in
476+
(fun () ->
477+
let vdi_info = { vdi_info with sm_config = ["toosmall", ""] } in
478+
Client.VDI.create ~dbg ~sr ~vdi_info);
479+
let vdi = Client.VDI.create ~dbg ~sr ~vdi_info in
477480
expect "attach_info" (fun _ -> true)
478481
(Client.VDI.attach ~dbg ~dp ~sr ~vdi:vdi.vdi ~read_write:false);
479482
debug "Detaching and cleaning up";

ocaml/xapi/storage_interface.ml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type vdi_info = {
5858
physical_utilisation: int64;
5959
(* xenstore_data: workaround via XenAPI *)
6060
persistent: bool;
61-
base_mirror: string option;
61+
sm_config: (string * string) list;
6262
}
6363

6464
let string_of_vdi_info (x: vdi_info) = Jsonrpc.to_string (rpc_of_vdi_info x)
@@ -237,16 +237,16 @@ module VDI = struct
237237
(** Functions which operate on particular VDIs.
238238
These functions are all idempotent from the point of view of a given [dp]. *)
239239

240-
(** [create task sr vdi_info params] creates a new VDI in [sr] using [vdi_info]. Some
240+
(** [create task sr vdi_info] creates a new VDI in [sr] using [vdi_info]. Some
241241
fields in the [vdi_info] may be modified (e.g. rounded up), so the function
242242
returns the vdi_info which was used. *)
243-
external create : dbg:debug_info -> sr:sr -> vdi_info:vdi_info -> params:(string*string) list -> vdi_info = ""
243+
external create : dbg:debug_info -> sr:sr -> vdi_info:vdi_info -> vdi_info = ""
244244

245-
(** [snapshot task sr vdi vdi_info params] creates a new VDI which is a snapshot of [vdi] in [sr] *)
246-
external snapshot : dbg:debug_info -> sr:sr -> vdi:vdi -> vdi_info:vdi_info -> params:(string*string) list -> vdi_info = ""
245+
(** [snapshot task sr vdi vdi_info] creates a new VDI which is a snapshot of [vdi] in [sr] *)
246+
external snapshot : dbg:debug_info -> sr:sr -> vdi:vdi -> vdi_info:vdi_info -> vdi_info = ""
247247

248-
(** [clone task sr vdi vdi_info params] creates a new VDI which is a clone of [vdi] in [sr] *)
249-
external clone : dbg:debug_info -> sr:sr -> vdi:vdi -> vdi_info:vdi_info -> params:(string*string) list -> vdi_info = ""
248+
(** [clone task sr vdi vdi_info] creates a new VDI which is a clone of [vdi] in [sr] *)
249+
external clone : dbg:debug_info -> sr:sr -> vdi:vdi -> vdi_info:vdi_info -> vdi_info = ""
250250

251251
(** [destroy task sr vdi] removes [vdi] from [sr] *)
252252
external destroy : dbg:debug_info -> sr:sr -> vdi:vdi -> unit = ""
@@ -297,8 +297,12 @@ module VDI = struct
297297
(** [compose task sr vdi1 vdi2] layers the updates from [vdi2] onto [vdi1], modifying [vdi2] *)
298298
external compose : dbg:debug_info -> sr:sr -> vdi1:vdi -> vdi2:vdi -> unit = ""
299299

300-
(** [remove_other_config dbg sr vdi key] remove [key] from [vdi] other config *)
301-
external remove_from_other_config: dbg:debug_info -> sr:sr -> vdi:vdi -> key:string -> unit = ""
300+
(** [add_to_sm_config dbg sr vdi key value] associates [value] to the [key] in [vdi] sm-config *)
301+
external add_to_sm_config: dbg:debug_info -> sr:sr -> vdi:vdi -> key:string -> value:string -> unit = ""
302+
303+
(** [remove_from_sm_config dbg sr vdi key] remove [key] from [vdi] sm-config *)
304+
external remove_from_sm_config: dbg:debug_info -> sr:sr -> vdi:vdi -> key:string -> unit = ""
305+
302306
end
303307

304308
(** [get_by_name task name] returns a vdi with [name] (which may be in any SR) *)

0 commit comments

Comments
 (0)