@@ -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 ~s R: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 )
0 commit comments