Skip to content

Commit e34b6ff

Browse files
authored
Merge pull request xapi-project#3428 from gaborigloi/complete_vdi_info
VDI.snapshot, clone: pass down complete vdi_info
2 parents 67eb53f + 5a8fea7 commit e34b6ff

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

ocaml/xapi/storage_access.ml

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,34 @@ let find_content ~__context ?sr name =
6565
|| (vdi_rec.API.vDI_location = name) (* PR-1255 *)
6666
) all
6767

68+
let vdi_info_of_vdi_rec __context vdi_rec =
69+
let content_id =
70+
try
71+
List.assoc "content_id" vdi_rec.API.vDI_other_config
72+
with Not_found -> vdi_rec.API.vDI_location (* PR-1255 *)
73+
in {
74+
vdi = vdi_rec.API.vDI_location;
75+
uuid = Some vdi_rec.API.vDI_uuid;
76+
content_id = content_id; (* PR-1255 *)
77+
name_label = vdi_rec.API.vDI_name_label;
78+
name_description = vdi_rec.API.vDI_name_description;
79+
ty = Storage_utils.string_of_vdi_type vdi_rec.API.vDI_type;
80+
metadata_of_pool = Ref.string_of vdi_rec.API.vDI_metadata_of_pool;
81+
is_a_snapshot = vdi_rec.API.vDI_is_a_snapshot;
82+
snapshot_time = Date.to_string vdi_rec.API.vDI_snapshot_time;
83+
snapshot_of =
84+
if Db.is_valid_ref __context vdi_rec.API.vDI_snapshot_of
85+
then Db.VDI.get_uuid ~__context ~self:vdi_rec.API.vDI_snapshot_of
86+
else "";
87+
read_only = vdi_rec.API.vDI_read_only;
88+
cbt_enabled = vdi_rec.API.vDI_cbt_enabled;
89+
virtual_size = vdi_rec.API.vDI_virtual_size;
90+
physical_utilisation = vdi_rec.API.vDI_physical_utilisation;
91+
persistent = vdi_rec.API.vDI_on_boot = `persist;
92+
sharable = vdi_rec.API.vDI_sharable;
93+
sm_config = vdi_rec.API.vDI_sm_config;
94+
}
95+
6896
let redirect sr =
6997
raise (Redirect (Some (Pool_role.get_master_address ())))
7098

@@ -82,34 +110,6 @@ module SMAPIv1 = struct
82110

83111
type context = Smint.request
84112

85-
let vdi_info_of_vdi_rec __context vdi_rec =
86-
let content_id =
87-
if List.mem_assoc "content_id" vdi_rec.API.vDI_other_config
88-
then List.assoc "content_id" vdi_rec.API.vDI_other_config
89-
else vdi_rec.API.vDI_location (* PR-1255 *)
90-
in {
91-
vdi = vdi_rec.API.vDI_location;
92-
uuid = Some vdi_rec.API.vDI_uuid;
93-
content_id = content_id; (* PR-1255 *)
94-
name_label = vdi_rec.API.vDI_name_label;
95-
name_description = vdi_rec.API.vDI_name_description;
96-
ty = Storage_utils.string_of_vdi_type vdi_rec.API.vDI_type;
97-
metadata_of_pool = Ref.string_of vdi_rec.API.vDI_metadata_of_pool;
98-
is_a_snapshot = vdi_rec.API.vDI_is_a_snapshot;
99-
snapshot_time = Date.to_string vdi_rec.API.vDI_snapshot_time;
100-
snapshot_of =
101-
if Db.is_valid_ref __context vdi_rec.API.vDI_snapshot_of
102-
then Db.VDI.get_uuid ~__context ~self:vdi_rec.API.vDI_snapshot_of
103-
else "";
104-
read_only = vdi_rec.API.vDI_read_only;
105-
cbt_enabled = vdi_rec.API.vDI_cbt_enabled;
106-
virtual_size = vdi_rec.API.vDI_virtual_size;
107-
physical_utilisation = vdi_rec.API.vDI_physical_utilisation;
108-
persistent = vdi_rec.API.vDI_on_boot = `persist;
109-
sharable = vdi_rec.API.vDI_sharable;
110-
sm_config = vdi_rec.API.vDI_sm_config;
111-
}
112-
113113
let vdi_info_from_db ~__context self =
114114
let vdi_rec = Db.VDI.get_record ~__context ~self in
115115
vdi_info_of_vdi_rec __context vdi_rec
@@ -569,9 +569,10 @@ module SMAPIv1 = struct
569569
with _ ->
570570
Uuid.string_of_uuid (Uuid.make_uuid ())
571571
in
572+
let snapshot_time = Date.of_float (Unix.gettimeofday ()) in
572573
Db.VDI.set_name_label ~__context ~self ~value:vdi_info.name_label;
573574
Db.VDI.set_name_description ~__context ~self ~value:vdi_info.name_description;
574-
Db.VDI.set_snapshot_time ~__context ~self ~value:(Date.of_string vdi_info.snapshot_time);
575+
Db.VDI.set_snapshot_time ~__context ~self ~value:snapshot_time;
575576
Db.VDI.set_is_a_snapshot ~__context ~self ~value:is_a_snapshot;
576577
Db.VDI.remove_from_other_config ~__context ~self ~key:"content_id";
577578
Db.VDI.add_to_other_config ~__context ~self ~key:"content_id" ~value:content_id;

ocaml/xapi/storage_access.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ val find_vdi: __context:Context.t -> Storage_interface.sr -> Storage_interface.v
3333
with [content_id] *)
3434
val find_content: __context:Context.t -> ?sr:Storage_interface.sr -> Storage_interface.content_id -> API.ref_VDI * API.vDI_t
3535

36+
(** [vdi_info_of_vdi_rec __context vdi_rec] constructs a vdi_info record from information in the given VDI database record. *)
37+
val vdi_info_of_vdi_rec : Context.t -> API.vDI_t -> Storage_interface.vdi_info
38+
3639
(** [bind __context pbd] causes the storage_access module to choose the most
3740
appropriate driver implementation for the given [pbd] *)
3841
val bind: __context:Context.t -> pbd:API.ref_PBD -> Storage_interface.query_result

ocaml/xapi/xapi_vdi.ml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ let create ~__context ~name_label ~name_description
407407
name_description = name_description;
408408
ty = vdi_type;
409409
read_only = read_only;
410+
cbt_enabled = false;
410411
virtual_size = virtual_size;
411412
sharable = sharable;
412413
sm_config = sm_config;
@@ -530,20 +531,15 @@ let snapshot_and_clone call_f ~__context ~vdi ~driver_params =
530531
let sR = Db.VDI.get_SR ~__context ~self:vdi in
531532
Sm.assert_pbd_is_plugged ~__context ~sr:sR;
532533
Xapi_vdi_helpers.assert_managed ~__context ~vdi;
533-
let a = Db.VDI.get_record_internal ~__context ~self:vdi in
534+
let vdi_rec = Db.VDI.get_record ~__context ~self:vdi in
534535

535536
let call_snapshot () =
536537
let open Storage_access in
537538
let task = Context.get_task_id __context in
538539
let open Storage_interface in
539-
let vdi' = Db.VDI.get_location ~__context ~self:vdi in
540540
let vdi_info = {
541-
default_vdi_info with
542-
vdi = vdi';
543-
name_label = a.Db_actions.vDI_name_label;
544-
name_description = a.Db_actions.vDI_name_description;
541+
(Storage_access.vdi_info_of_vdi_rec __context vdi_rec) with
545542
sm_config = driver_params;
546-
snapshot_time = Date.to_string (Date.of_float (Unix.gettimeofday ()));
547543
} in
548544
let sr' = Db.SR.get_uuid ~__context ~self:sR in
549545
(* We don't use transform_storage_exn because of the clone/copy fallback below *)
@@ -556,14 +552,14 @@ let snapshot_and_clone call_f ~__context ~vdi ~driver_params =
556552
let newvdi = call_snapshot () in
557553

558554
(* Copy across the metadata which we control *)
559-
Db.VDI.set_name_label ~__context ~self:newvdi ~value:a.Db_actions.vDI_name_label;
560-
Db.VDI.set_name_description ~__context ~self:newvdi ~value:a.Db_actions.vDI_name_description;
561-
Db.VDI.set_type ~__context ~self:newvdi ~value:a.Db_actions.vDI_type;
562-
Db.VDI.set_sharable ~__context ~self:newvdi ~value:a.Db_actions.vDI_sharable;
563-
Db.VDI.set_other_config ~__context ~self:newvdi ~value:a.Db_actions.vDI_other_config;
564-
Db.VDI.set_xenstore_data ~__context ~self:newvdi ~value:a.Db_actions.vDI_xenstore_data;
565-
Db.VDI.set_on_boot ~__context ~self:newvdi ~value:a.Db_actions.vDI_on_boot;
566-
Db.VDI.set_allow_caching ~__context ~self:newvdi ~value:a.Db_actions.vDI_allow_caching;
555+
Db.VDI.set_name_label ~__context ~self:newvdi ~value:vdi_rec.API.vDI_name_label;
556+
Db.VDI.set_name_description ~__context ~self:newvdi ~value:vdi_rec.API.vDI_name_description;
557+
Db.VDI.set_type ~__context ~self:newvdi ~value:vdi_rec.API.vDI_type;
558+
Db.VDI.set_sharable ~__context ~self:newvdi ~value:vdi_rec.API.vDI_sharable;
559+
Db.VDI.set_other_config ~__context ~self:newvdi ~value:vdi_rec.API.vDI_other_config;
560+
Db.VDI.set_xenstore_data ~__context ~self:newvdi ~value:vdi_rec.API.vDI_xenstore_data;
561+
Db.VDI.set_on_boot ~__context ~self:newvdi ~value:vdi_rec.API.vDI_on_boot;
562+
Db.VDI.set_allow_caching ~__context ~self:newvdi ~value:vdi_rec.API.vDI_allow_caching;
567563
newvdi
568564

569565
let snapshot ~__context ~vdi ~driver_params =

0 commit comments

Comments
 (0)