Permalink
Browse files

Merge commit 'a5ee04d2072a3d30a8a13766641aa84ca5140694'

  • Loading branch information...
2 parents 22aebf9 + a5ee04d commit 3228fa0202b22acf9fc541c4ac0f7392db6a4c53 xen-git committed Jun 19, 2012
View
@@ -103,9 +103,15 @@ let _ =
if Array.length Sys.argv < 3 then usage_and_exit ();
let kvpairs = kvpairs args in
let find key = if List.mem_assoc key kvpairs then Some (List.assoc key kvpairs) else None in
+ let params = List.filter_map
+ (fun (k, v) ->
+ let prefix = "params:" in
+ let l = String.length prefix in
+ if String.startswith prefix k
+ then Some (String.sub k l (String.length k - l), v)
+ else None) kvpairs in
let vdi_info = {
vdi = "";
- sr = sr;
content_id = ""; (* PR-1255 *)
name_label = Opt.default "default name_label" (find "name_label");
name_description = Opt.default "default name_description" (find "name_description");
@@ -118,16 +124,10 @@ let _ =
virtual_size = Opt.default 1L (Opt.map Int64.of_string (find "virtual_size"));
physical_utilisation = 0L;
persistent = true;
+ sm_config = params;
} in
- let params = List.filter_map
- (fun (k, v) ->
- let prefix = "params:" in
- let l = String.length prefix in
- if String.startswith prefix k
- then Some (String.sub k l (String.length k - l), v)
- else None) kvpairs in
- let v = Client.VDI.create ~dbg ~sr ~vdi_info ~params in
+ let v = Client.VDI.create ~dbg ~sr ~vdi_info in
Printf.printf "%s\n" (string_of_vdi_info v)
| [ "vdi-destroy"; sr; vdi ] ->
Client.VDI.destroy ~dbg ~sr ~vdi
@@ -144,8 +144,8 @@ let _ =
let v = Client.VDI.get_by_name ~dbg ~sr ~name in
Printf.printf "%s\n" (string_of_vdi_info v)
| [ "vdi-get-by-name"; name ] ->
- let v = Client.get_by_name ~dbg ~name in
- Printf.printf "%s\n" (string_of_vdi_info v)
+ let sr, v = Client.get_by_name ~dbg ~name in
+ Printf.printf "sr=%s; %s\n" sr (string_of_vdi_info v)
| [ "vdi-set-content-id"; sr; vdi; content_id ] ->
Client.VDI.set_content_id ~dbg ~sr ~vdi~content_id
| [ "vdi-similar-content"; sr; vdi ] ->
View
@@ -170,9 +170,9 @@ let example_vdi_info =
let read_only = false in
let virtual_size = Int64.mul 8L mib in
let physical_utilisation = 0L in
+ let sm_config = [] in
{
vdi = "";
- sr = "";
content_id = "";
name_label = name_label;
name_description = name_description;
@@ -185,12 +185,13 @@ let example_vdi_info =
virtual_size = virtual_size;
physical_utilisation = physical_utilisation;
persistent = true;
+ sm_config = sm_config;
}
let test_create_destroy sr _ =
let vdi_info = example_vdi_info in
let vdi_info' =
- let vdi_info' = SMClient.VDI.create ~dbg ~sr ~vdi_info ~params:[] in
+ let vdi_info' = SMClient.VDI.create ~dbg ~sr ~vdi_info in
vdi_info_assert_equal vdi_info vdi_info';
vdi_info'
in
@@ -205,7 +206,7 @@ let test_create_destroy sr _ =
end
let test_attach_activate url sr _ =
- let vdi_info = SMClient.VDI.create ~dbg ~sr ~vdi_info:example_vdi_info ~params:[] in
+ let vdi_info = SMClient.VDI.create ~dbg ~sr ~vdi_info:example_vdi_info in
let dp = "test_attach_activate" in
let _ = SMClient.VDI.attach ~dbg ~sr ~dp ~vdi:vdi_info.vdi ~read_write:true in
SMClient.VDI.activate ~dbg ~sr ~dp ~vdi:vdi_info.vdi;
@@ -228,7 +229,7 @@ let test_attach_activate url sr _ =
SMClient.VDI.destroy ~dbg ~sr ~vdi:vdi_info.vdi
let test_mirror_1 url sr rurl rsr _ =
- let vdi_info = SMClient.VDI.create ~dbg ~sr ~vdi_info:example_vdi_info ~params:[] in
+ let vdi_info = SMClient.VDI.create ~dbg ~sr ~vdi_info:example_vdi_info in
let dp = "test_attach_activate" in
ignore(SMClient.VDI.attach ~dbg ~sr ~dp ~vdi:vdi_info.vdi ~read_write:true);
SMClient.VDI.activate ~dbg ~sr ~dp ~vdi:vdi_info.vdi;
@@ -172,14 +172,13 @@ module SMAPIv1 = struct
)
)
- let vdi_info_of_vdi_rec __context sr vdi_rec =
+ let vdi_info_of_vdi_rec __context vdi_rec =
let content_id =
if List.mem_assoc "content_id" vdi_rec.API.vDI_other_config
then List.assoc "content_id" vdi_rec.API.vDI_other_config
else vdi_rec.API.vDI_location (* PR-1255 *)
in {
vdi = vdi_rec.API.vDI_location;
- sr = sr;
content_id = content_id; (* PR-1255 *)
name_label = vdi_rec.API.vDI_name_label;
name_description = vdi_rec.API.vDI_name_description;
@@ -192,6 +191,7 @@ module SMAPIv1 = struct
virtual_size = vdi_rec.API.vDI_virtual_size;
physical_utilisation = vdi_rec.API.vDI_physical_utilisation;
persistent = vdi_rec.API.vDI_on_boot = `persist;
+ sm_config = vdi_rec.API.vDI_sm_config;
}
let scan context ~dbg ~sr:sr' =
@@ -204,7 +204,7 @@ module SMAPIv1 = struct
Sm.sr_scan device_config _type sr;
let open Db_filter_types in
let vdis = Db.VDI.get_records_where ~__context ~expr:(Eq(Field "SR", Literal (Ref.string_of sr))) |> List.map snd in
- List.map (vdi_info_of_vdi_rec __context sr') vdis
+ List.map (vdi_info_of_vdi_rec __context) vdis
with
| Smint.Not_implemented_in_backend ->
raise (Storage_interface.Backend_error(Api_errors.sr_operation_not_supported, [ Ref.string_of sr ]))
@@ -318,7 +318,6 @@ module SMAPIv1 = struct
let r = Db.VDI.get_record ~__context ~self in
{
vdi = r.API.vDI_location;
- sr = Db.SR.get_uuid ~__context ~self:r.API.vDI_SR;
content_id = r.API.vDI_location; (* PR-1255 *)
name_label = r.API.vDI_name_label;
name_description = r.API.vDI_name_description;
@@ -331,22 +330,23 @@ module SMAPIv1 = struct
virtual_size = r.API.vDI_virtual_size;
physical_utilisation = r.API.vDI_physical_utilisation;
persistent = r.API.vDI_on_boot = `persist;
+ sm_config = r.API.vDI_sm_config;
}
let newvdi ~__context vi =
(* The current backends stash data directly in the db *)
let uuid = require_uuid vi in
vdi_info_from_db ~__context (Db.VDI.get_by_uuid ~__context ~uuid)
- let create context ~dbg ~sr ~vdi_info ~params =
+ let create context ~dbg ~sr ~vdi_info =
try
Server_helpers.exec_with_new_task "VDI.create" ~subtask_of:(Ref.of_string dbg)
(fun __context ->
let sr = Db.SR.get_by_uuid ~__context ~uuid:sr in
let vi =
Sm.call_sm_functions ~__context ~sR:sr
(fun device_config _type ->
- Sm.vdi_create device_config _type sr params vdi_info.ty
+ Sm.vdi_create device_config _type sr vdi_info.sm_config vdi_info.ty
vdi_info.virtual_size vdi_info.name_label vdi_info.name_description
vdi_info.metadata_of_pool vdi_info.is_a_snapshot
vdi_info.snapshot_time vdi_info.snapshot_of vdi_info.read_only
@@ -357,17 +357,22 @@ module SMAPIv1 = struct
| Api_errors.Server_error(code, params) -> raise (Backend_error(code, params))
| Sm.MasterOnly -> redirect sr
- let snapshot_and_clone call_name call_f context ~dbg ~sr ~vdi ~vdi_info ~params =
+ (* A list of keys in sm-config that will be preserved on clone/snapshot *)
+ let sm_config_keys_to_preserve_on_clone = [
+ "base_mirror"
+ ]
+
+ let snapshot_and_clone call_name call_f context ~dbg ~sr ~vdi_info =
try
Server_helpers.exec_with_new_task call_name ~subtask_of:(Ref.of_string dbg)
(fun __context ->
- let vi = for_vdi ~dbg ~sr ~vdi call_name
+ let vi = for_vdi ~dbg ~sr ~vdi:vdi_info.vdi call_name
(fun device_config _type sr self ->
- call_f device_config _type params sr self
+ call_f device_config _type vdi_info.sm_config sr self
) in
(* PR-1255: modify clone, snapshot to take the same parameters as create? *)
let self, _ = find_vdi ~__context sr vi.Smint.vdi_info_location in
- let clonee, _ = find_vdi ~__context sr vdi in
+ let clonee, _ = find_vdi ~__context sr vdi_info.vdi in
let content_id =
try
List.assoc "content_id"
@@ -379,11 +384,21 @@ module SMAPIv1 = struct
Db.VDI.set_name_description ~__context ~self ~value:vdi_info.name_description;
Db.VDI.remove_from_other_config ~__context ~self ~key:"content_id";
Db.VDI.add_to_other_config ~__context ~self ~key:"content_id" ~value:content_id;
+ debug "copying sm-config";
+ List.iter (fun (key, value) ->
+ let preserve = List.mem key sm_config_keys_to_preserve_on_clone in
+ if preserve then (
+ Db.VDI.remove_from_sm_config ~__context ~self ~key;
+ Db.VDI.add_to_sm_config ~__context ~self ~key ~value;
+ )
+ ) vdi_info.sm_config;
for_vdi ~dbg ~sr ~vdi:vi.Smint.vdi_info_location "VDI.update"
(fun device_config _type sr self ->
Sm.vdi_update device_config _type sr self
);
- vdi_info_from_db ~__context self
+ let vdi = vdi_info_from_db ~__context self in
+ debug "vdi = %s" (string_of_vdi_info vdi);
+ vdi
)
with
| Api_errors.Server_error(code, params) ->
@@ -417,7 +432,7 @@ module SMAPIv1 = struct
(fun __context ->
for_vdi ~dbg ~sr ~vdi "VDI.stat"
(fun device_config _type _ self ->
- SR.vdi_info_of_vdi_rec __context sr (Db.VDI.get_record ~__context ~self)
+ SR.vdi_info_of_vdi_rec __context (Db.VDI.get_record ~__context ~self)
)
)
with e ->
@@ -453,7 +468,7 @@ module SMAPIv1 = struct
(* PR-1255: the backend should do this for us *)
try
let _, vdi = find_content ~__context ~sr name in
- let vi = SR.vdi_info_of_vdi_rec __context sr vdi in
+ let vi = SR.vdi_info_of_vdi_rec __context vdi in
debug "VDI.get_by_name returning successfully";
vi
with e ->
@@ -518,7 +533,7 @@ module SMAPIv1 = struct
let _, vdi_rec = find_vdi ~__context sr vdi in
let vdis = explore 0 StringMap.empty vdi_rec.API.vDI_location |> invert |> IntMap.bindings |> List.map snd |> List.concat in
let vdi_recs = List.map (fun l -> StringMap.find l locations) vdis in
- List.map (fun x -> SR.vdi_info_of_vdi_rec __context sr x) vdi_recs
+ List.map (fun x -> SR.vdi_info_of_vdi_rec __context x) vdi_recs
)
let compose context ~dbg ~sr ~vdi1 ~vdi2 =
@@ -542,6 +557,20 @@ module SMAPIv1 = struct
raise (Vdi_does_not_exist vdi1)
| Sm.MasterOnly -> redirect sr
+ let add_to_sm_config context ~dbg ~sr ~vdi ~key ~value =
+ info "VDI.add_to_sm_config dbg:%s sr:%s vdi:%s key:%s value:%s" dbg sr vdi key value;
+ Server_helpers.exec_with_new_task "VDI.add_to_sm_config" ~subtask_of:(Ref.of_string dbg)
+ (fun __context ->
+ let self = find_vdi ~__context sr vdi |> fst in
+ Db.VDI.add_to_sm_config ~__context ~self ~key ~value)
+
+ let remove_from_sm_config context ~dbg ~sr ~vdi ~key =
+ info "VDI.remove_from_sm_config dbg:%s sr:%s vdi:%s key:%s" dbg sr vdi key;
+ Server_helpers.exec_with_new_task "VDI.remove_from_sm_config" ~subtask_of:(Ref.of_string dbg)
+ (fun __context ->
+ let self = find_vdi ~__context sr vdi |> fst in
+ Db.VDI.remove_from_other_config ~__context ~self ~key)
+
let get_url context ~dbg ~sr ~vdi =
info "VDI.get_url dbg:%s sr:%s vdi:%s" dbg sr vdi;
(* XXX: PR-1255: tapdisk shouldn't hardcode xapi urls *)
View
@@ -458,20 +458,20 @@ module Wrapper = functor(Impl: Server_impl) -> struct
Impl.VDI.epoch_end context ~dbg ~sr ~vdi
))
- let create context ~dbg ~sr ~vdi_info ~params =
- 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));
- let result = Impl.VDI.create context ~dbg ~sr ~vdi_info ~params in
+ let create context ~dbg ~sr ~vdi_info =
+ info "VDI.create dbg:%s sr:%s vdi_info:%s" dbg sr (string_of_vdi_info vdi_info);
+ let result = Impl.VDI.create context ~dbg ~sr ~vdi_info in
match result with
| { virtual_size = virtual_size' } when virtual_size' < vdi_info.virtual_size ->
error "VDI.create dbg:%s created a smaller VDI (%Ld)" dbg virtual_size';
raise (Backend_error("SR_BACKEND_FAILURE", ["Disk too small"; Int64.to_string vdi_info.virtual_size; Int64.to_string virtual_size']))
| result -> result
- let snapshot_and_clone call_name call_f context ~dbg ~sr ~vdi ~vdi_info ~params =
- 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));
- with_vdi sr vdi
+ let snapshot_and_clone call_name call_f context ~dbg ~sr ~vdi_info =
+ info "%s dbg:%s sr:%s vdi_info:%s" call_name dbg sr (string_of_vdi_info vdi_info);
+ with_vdi sr vdi_info.vdi
(fun () ->
- call_f context ~dbg ~sr ~vdi ~vdi_info ~params
+ call_f context ~dbg ~sr ~vdi_info
)
let snapshot = snapshot_and_clone "VDI.snapshot" Impl.VDI.snapshot
@@ -515,6 +515,14 @@ module Wrapper = functor(Impl: Server_impl) -> struct
info "VDI.compose dbg:%s sr:%s vdi1:%s vdi2:%s" dbg sr vdi1 vdi2;
Impl.VDI.compose context ~dbg ~sr ~vdi1 ~vdi2
+ let add_to_sm_config context ~dbg ~sr ~vdi ~key ~value =
+ info "VDI.add_to_other_config dbg:%s sr:%s vdi:%s key:%s valu:%s" dbg sr vdi key value;
+ Impl.VDI.add_to_sm_config context ~dbg ~sr ~vdi ~key ~value
+
+ let remove_from_sm_config context ~dbg ~sr ~vdi ~key =
+ info "VDI.remove_from_other_config dbg:%s sr:%s vdi:%s key:%s" dbg sr vdi key;
+ Impl.VDI.remove_from_sm_config context ~dbg ~sr ~vdi ~key
+
let get_url context ~dbg ~sr ~vdi =
info "VDI.get_url dbg:%s sr:%s vdi:%s" dbg sr vdi;
Impl.VDI.get_url context ~dbg ~sr ~vdi
@@ -54,10 +54,10 @@ module Debug_print_impl = struct
let created = Hashtbl.create 10
let key_of sr vdi = Printf.sprintf "%s/%s" sr vdi
- let create context ~dbg ~sr ~vdi_info ~params =
+ let create context ~dbg ~sr ~vdi_info =
let vdi = "newvdi" in
let info =
- if List.mem_assoc "toosmall" params
+ if List.mem_assoc "toosmall" vdi_info.sm_config
then { vdi_info with virtual_size = Int64.sub vdi_info.virtual_size 1L }
else vdi_info in
Mutex.execute m
@@ -67,8 +67,8 @@ module Debug_print_impl = struct
);
info
- let snapshot context ~dbg ~sr ~vdi ~vdi_info ~params =
- create context ~dbg ~sr ~vdi_info ~params
+ let snapshot context ~dbg ~sr ~vdi_info =
+ create context ~dbg ~sr ~vdi_info
let clone = snapshot
let destroy context ~dbg ~sr ~vdi =
@@ -153,6 +153,8 @@ module Debug_print_impl = struct
let get_url context ~dbg ~sr ~vdi = assert false
let compose context ~dbg ~sr ~vdi1 ~vdi2 = assert false
+ let add_to_sm_config context ~dbg ~sr ~vdi ~key ~value = assert false
+ let remove_from_sm_config context ~dbg ~sr ~vdi ~key = assert false
let set_content_id context ~dbg ~sr ~vdi ~content_id = assert false
let get_by_name context ~dbg ~sr ~name = assert false
let similar_content context ~dbg ~sr ~vdi = assert false
@@ -455,7 +457,6 @@ let create_vdi_test sr =
(Client.SR.attach ~dbg ~sr ~device_config:[]);
let vdi_info = {
vdi = "";
- sr = "";
content_id = "";
name_label = "name_label";
name_description = "name_description";
@@ -468,10 +469,13 @@ let create_vdi_test sr =
physical_utilisation = 10L;
metadata_of_pool = "";
persistent = true;
+ sm_config = [];
} in
expect "too_small_backend_error" too_small_backend_error
- (fun () -> Client.VDI.create ~dbg ~sr ~vdi_info ~params:["toosmall", ""]);
- let vdi = Client.VDI.create ~dbg ~sr ~vdi_info ~params:[] in
+ (fun () ->
+ let vdi_info = { vdi_info with sm_config = ["toosmall", ""] } in
+ Client.VDI.create ~dbg ~sr ~vdi_info);
+ let vdi = Client.VDI.create ~dbg ~sr ~vdi_info in
expect "attach_info" (fun _ -> true)
(Client.VDI.attach ~dbg ~dp ~sr ~vdi:vdi.vdi ~read_write:false);
debug "Detaching and cleaning up";
Oops, something went wrong.

0 comments on commit 3228fa0

Please sign in to comment.