Skip to content

Commit 6de9ffa

Browse files
authored
Merge pull request #3093 from gaborigloi/feature/CBT_merge
Merge first part of CBT feature branch into master
2 parents 84e8ca3 + 3d04c24 commit 6de9ffa

28 files changed

+328
-39
lines changed

ocaml/idl/datamodel.ml

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ open Datamodel_types
1818
(* IMPORTANT: Please bump schema vsn if you change/add/remove a _field_.
1919
You do not have to bump vsn if you change/add/remove a message *)
2020
let schema_major_vsn = 5
21-
let schema_minor_vsn = 120
21+
let schema_minor_vsn = 131
2222

2323
(* Historical schema versions just in case this is useful later *)
2424
let rio_schema_major_vsn = 5
@@ -88,7 +88,7 @@ let falcon_release_schema_major_vsn = 5
8888
let falcon_release_schema_minor_vsn = 120
8989

9090
let inverness_release_schema_major_vsn = 5
91-
let inverness_release_schema_minor_vsn = 130
91+
let inverness_release_schema_minor_vsn = 131
9292

9393
(* List of tech-preview releases. Fields in these releases are not guaranteed to be retained when
9494
* upgrading to a full release. *)
@@ -1105,10 +1105,12 @@ let _ =
11051105
~doc:"This operation cannot be performed because the system does not manage this VDI" ();
11061106
error Api_errors.vdi_not_in_map [ "vdi" ]
11071107
~doc:"This VDI was not mapped to a destination SR in VM.migrate_send operation" () ;
1108+
error Api_errors.vdi_cbt_enabled [ "vdi" ]
1109+
~doc:"The requested operation is not allowed for VDIs with CBT enabled or VMs having such VDIs, and CBT is enabled for the specified VDI." ();
11081110
error Api_errors.vdi_copy_failed []
11091111
~doc:"The VDI copy action has failed" ();
11101112
error Api_errors.vdi_on_boot_mode_incompatible_with_operation []
1111-
~doc:"This operation is not permitted on VMs containing VDIs in the 'on-boot=reset' mode" ();
1113+
~doc:"This operation is not permitted on VDIs in the 'on-boot=reset' mode, or on VMs having such VDIs." ();
11121114
error Api_errors.cannot_create_state_file []
11131115
~doc:"An HA statefile could not be created, perhaps because no SR with the appropriate capability was found." ();
11141116
error Api_errors.vif_not_in_map [ "vif" ]
@@ -5985,6 +5987,9 @@ let storage_operations =
59855987
"vdi_clone", "Cloneing a VDI";
59865988
"vdi_snapshot", "Snapshotting a VDI";
59875989
"vdi_mirror", "Mirroring a VDI";
5990+
"vdi_enable_cbt", "Enabling changed block tracking for a VDI";
5991+
"vdi_disable_cbt", "Disabling changed block tracking for a VDI";
5992+
"vdi_set_on_boot", "Setting the on_boot field of the VDI";
59885993
"pbd_create", "Creating a PBD for this SR";
59895994
"pbd_destroy", "Destroying one of this SR's PBDs"; ])
59905995

@@ -6199,6 +6204,7 @@ let vdi_type = Enum ("vdi_type", [ "system", "a disk that may be replaced on
61996204
"redo_log", "a disk used for a general metadata redo-log";
62006205
"rrd", "a disk that stores SR-level RRDs";
62016206
"pvs_cache", "a disk that stores PVS cache data";
6207+
"cbt_metadata", "Metadata about a snapshot VDI that has been deleted: the set of blocks that changed between some previous version of the disk and the version tracked by the snapshot.";
62026208
])
62036209

62046210
let vdi_introduce_params first_rel =
@@ -6230,7 +6236,10 @@ let vdi_pool_introduce = call
62306236
~name:"pool_introduce"
62316237
~in_oss_since:None
62326238
~in_product_since:rel_rio
6233-
~versioned_params:(vdi_introduce_params miami_release)
6239+
~versioned_params:(
6240+
(vdi_introduce_params miami_release) @
6241+
[{ param_type=Bool; param_name="cbt_enabled"; param_doc="True if changed blocks are tracked for this VDI"; param_release=inverness_release; param_default= Some(VBool false) }]
6242+
)
62346243
~doc:"Create a new VDI record in the database only"
62356244
~result:(Ref _vdi, "The ref of the newly created VDI record.")
62366245
~hide_from_docs:true
@@ -6303,6 +6312,9 @@ let vdi_operations =
63036312
"update", "Refreshing the fields of the VDI";
63046313
"force_unlock", "Forcibly unlocking the VDI";
63056314
"generate_config", "Generating static configuration";
6315+
"enable_cbt", "Enabling changed block tracking for a VDI";
6316+
"disable_cbt", "Disabling changed block tracking for a VDI";
6317+
"set_on_boot", "Setting the on_boot field of the VDI";
63066318
"blocked", "Operations on this VDI are temporarily blocked";
63076319
])
63086320

@@ -6508,6 +6520,42 @@ let vdi_read_database_pool_uuid = call
65086520
~allowed_roles:_R_READ_ONLY
65096521
()
65106522

6523+
let vdi_enable_cbt = call
6524+
~name:"enable_cbt"
6525+
~in_oss_since:None
6526+
~in_product_since:rel_inverness
6527+
~params:[Ref _vdi, "self", "The VDI for which CBT should be enabled"]
6528+
~errs:[
6529+
Api_errors.sr_operation_not_supported;
6530+
Api_errors.vdi_missing;
6531+
Api_errors.sr_not_attached;
6532+
Api_errors.sr_no_pbds;
6533+
Api_errors.operation_not_allowed;
6534+
Api_errors.vdi_incompatible_type;
6535+
Api_errors.vdi_on_boot_mode_incompatible_with_operation;
6536+
]
6537+
~doc:"Enable changed block tracking for the VDI. This call is idempotent - enabling CBT for a VDI for which CBT is already enabled results in a no-op, and no error will be thrown."
6538+
~allowed_roles:_R_VM_ADMIN
6539+
()
6540+
6541+
let vdi_disable_cbt = call
6542+
~name:"disable_cbt"
6543+
~in_oss_since:None
6544+
~in_product_since:rel_inverness
6545+
~params:[Ref _vdi, "self", "The VDI for which CBT should be disabled"]
6546+
~errs:[
6547+
Api_errors.sr_operation_not_supported;
6548+
Api_errors.vdi_missing;
6549+
Api_errors.sr_not_attached;
6550+
Api_errors.sr_no_pbds;
6551+
Api_errors.operation_not_allowed;
6552+
Api_errors.vdi_incompatible_type;
6553+
Api_errors.vdi_on_boot_mode_incompatible_with_operation;
6554+
]
6555+
~doc:"Disable changed block tracking for the VDI. This call is only allowed on VDIs that support enabling CBT. It is an idempotent operation - disabling CBT for a VDI for which CBT is not enabled results in a no-op, and no error will be thrown."
6556+
~allowed_roles:_R_VM_ADMIN
6557+
()
6558+
65116559
(** A virtual disk *)
65126560
let vdi =
65136561
create_obj ~in_db:true ~in_product_since:rel_rio ~in_oss_since:oss_since_303 ~internal_deprecated_since:None ~persist:PersistEverything ~gen_constructor_destructor:true ~name:_vdi ~descr:"A virtual disk image"
@@ -6540,6 +6588,8 @@ let vdi =
65406588
vdi_checksum;
65416589
vdi_read_database_pool_uuid;
65426590
vdi_pool_migrate;
6591+
vdi_enable_cbt;
6592+
vdi_disable_cbt;
65436593
]
65446594
~contents:
65456595
([ uid _vdi;
@@ -6573,6 +6623,7 @@ let vdi =
65736623
field ~in_product_since:rel_boston ~qualifier:DynamicRO ~ty:(Ref _pool) ~default_value:(Some (VRef null_ref)) "metadata_of_pool" "The pool whose metadata is contained in this VDI";
65746624
field ~in_product_since:rel_boston ~qualifier:DynamicRO ~ty:Bool ~default_value:(Some (VBool false)) "metadata_latest" "Whether this VDI contains the latest known accessible metadata for the pool";
65756625
field ~lifecycle:[Published, rel_dundee, ""] ~qualifier:DynamicRO ~ty:Bool ~default_value:(Some (VBool false)) "is_tools_iso" "Whether this VDI is a Tools ISO";
6626+
field ~lifecycle:[Published, rel_inverness, ""] ~qualifier:DynamicRO ~ty:Bool ~default_value:(Some (VBool false)) "cbt_enabled" "True if changed blocks are tracked for this VDI" ~doc_tags:[Snapshots];
65766627
])
65776628
()
65786629

ocaml/xapi-consts/api_errors.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ let vdi_not_managed = "VDI_NOT_MANAGED"
239239
let vdi_io_error = "VDI_IO_ERROR"
240240
let vdi_on_boot_mode_incompatible_with_operation = "VDI_ON_BOOT_MODE_INCOMPATIBLE_WITH_OPERATION"
241241
let vdi_not_in_map = "VDI_NOT_IN_MAP"
242+
let vdi_cbt_enabled = "VDI_CBT_ENABLED"
242243
let vif_not_in_map = "VIF_NOT_IN_MAP"
243244
let cannot_create_state_file = "CANNOT_CREATE_STATE_FILE"
244245

ocaml/xapi/cli_frontend.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,22 @@ let rec cmdtable_data : (string*cmd_spec) list =
19691969
implementation=No_fd Cli_operations.vdi_unlock;
19701970
flags=[];
19711971
};
1972+
"vdi-enable-cbt",
1973+
{
1974+
reqd=["uuid"];
1975+
optn=[];
1976+
help="Enable changed block tracking on a VDI.";
1977+
implementation=No_fd Cli_operations.vdi_enable_cbt;
1978+
flags=[];
1979+
};
1980+
"vdi-disable-cbt",
1981+
{
1982+
reqd=["uuid"];
1983+
optn=[];
1984+
help="Disable changed block tracking on a VDI.";
1985+
implementation=No_fd Cli_operations.vdi_disable_cbt;
1986+
flags=[];
1987+
};
19721988
"diagnostic-vdi-status",
19731989
{
19741990
reqd=["uuid"];

ocaml/xapi/cli_operations.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,14 @@ let vdi_unlock printer rpc session_id params =
12481248
then failwith "This operation is extremely dangerous and may cause data loss. This operation must be forced (use --force).";
12491249
Client.VDI.force_unlock rpc session_id vdi
12501250

1251+
let vdi_enable_cbt printer rpc session_id params =
1252+
let vdi = Client.VDI.get_by_uuid rpc session_id (List.assoc "uuid" params) in
1253+
Client.VDI.enable_cbt rpc session_id vdi
1254+
1255+
let vdi_disable_cbt printer rpc session_id params =
1256+
let vdi = Client.VDI.get_by_uuid rpc session_id (List.assoc "uuid" params) in
1257+
Client.VDI.disable_cbt rpc session_id vdi
1258+
12511259
let diagnostic_vdi_status printer rpc session_id params =
12521260
let vdi = Client.VDI.get_by_uuid rpc session_id (List.assoc "uuid" params) in
12531261
let vdi_r = vdi_record rpc session_id vdi in

ocaml/xapi/debug_populate.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ let rec make_vdis_and_vbds __context vmref i =
6767
let snapshot_time = Stdext.Date.never in
6868
let snapshot_of = Ref.null in
6969
let sharable = false in
70+
let cbt_enabled = false in
7071
let vdi = Xapi_vdi.pool_introduce
71-
~__context ~uuid ~name_label ~name_description ~sR ~_type ~sharable ~read_only ~other_config ~location ~xenstore_data ~sm_config ~managed ~virtual_size ~physical_utilisation ~metadata_of_pool ~is_a_snapshot ~snapshot_time ~snapshot_of in
72+
~__context ~uuid ~name_label ~name_description ~sR ~_type ~sharable ~read_only ~other_config ~location ~xenstore_data ~sm_config ~managed ~virtual_size ~physical_utilisation ~metadata_of_pool ~is_a_snapshot ~snapshot_time ~snapshot_of ~cbt_enabled in
7273

7374
let _ =
7475
Xapi_vbd.create ~__context ~vM:vmref ~vDI:vdi ~userdevice:(string_of_int i) ~bootable:true ~mode:`RW ~_type:`Disk ~empty:false

ocaml/xapi/message_forwarding.ml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,8 +3393,11 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
33933393
let set_on_boot ~__context ~self ~value =
33943394
ensure_vdi_not_on_running_vm ~__context ~self;
33953395
let local_fn = Local.VDI.set_on_boot ~self ~value in
3396-
forward_vdi_op ~local_fn ~__context ~self
3397-
(fun session_id rpc -> Client.VDI.set_on_boot rpc session_id self value)
3396+
let sr = Db.VDI.get_SR ~__context ~self in
3397+
with_sr_andor_vdi ~__context ~sr:(sr, `vdi_set_on_boot) ~vdi:(self, `set_on_boot) ~doc:"VDI.set_on_boot"
3398+
(fun () ->
3399+
forward_vdi_op ~local_fn ~__context ~self
3400+
(fun session_id rpc -> Client.VDI.set_on_boot rpc session_id self value))
33983401

33993402
let set_allow_caching ~__context ~self ~value =
34003403
ensure_vdi_not_on_running_vm ~__context ~self;
@@ -3416,13 +3419,12 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
34163419
(fun session_id rpc -> Client.VDI.create ~rpc ~session_id ~name_label ~name_description ~sR ~virtual_size ~_type ~sharable ~read_only ~other_config ~xenstore_data ~sm_config ~tags))
34173420

34183421
(* Hidden call used in pool join only *)
3419-
let pool_introduce ~__context ~uuid ~name_label ~name_description ~sR ~_type ~sharable ~read_only ~other_config ~location =
3420-
Local.VDI.pool_introduce ~__context ~uuid ~name_label ~name_description ~sR ~_type ~sharable ~read_only ~other_config ~location
3422+
let pool_introduce = Local.VDI.pool_introduce
34213423

34223424
(* Called from the SM backend *)
3423-
let db_introduce ~__context ~uuid ~name_label ~name_description ~sR ~_type ~sharable ~read_only ~other_config ~location =
3425+
let db_introduce ~__context ~uuid ~name_label ~name_description ~sR ~_type ~sharable ~read_only ~other_config ~location ~xenstore_data ~sm_config ~managed ~virtual_size ~physical_utilisation ~metadata_of_pool ~is_a_snapshot ~snapshot_time ~snapshot_of ~cbt_enabled =
34243426
Sm.assert_session_has_internal_sr_access ~__context ~sr:sR;
3425-
Local.VDI.db_introduce ~__context ~uuid ~name_label ~name_description ~sR ~_type ~sharable ~read_only ~other_config ~location
3427+
Local.VDI.db_introduce ~__context ~uuid ~name_label ~name_description ~sR ~_type ~sharable ~read_only ~other_config ~location ~xenstore_data ~sm_config ~managed ~virtual_size ~physical_utilisation ~metadata_of_pool ~is_a_snapshot ~snapshot_time ~snapshot_of ~cbt_enabled
34263428

34273429
(* Called from the SM backend *)
34283430
let db_forget ~__context ~vdi =
@@ -3576,6 +3578,24 @@ module Forward = functor(Local: Custom_actions.CUSTOM_ACTIONS) -> struct
35763578
~extra_sr:(Db.VDI.get_SR ~__context ~self)
35773579
(fun session_id rpc -> Client.VDI.checksum rpc session_id self)
35783580

3581+
let enable_cbt ~__context ~self =
3582+
info "VDI.enable_cbt: VDI = '%s'" (vdi_uuid ~__context self);
3583+
let local_fn = Local.VDI.enable_cbt ~self in
3584+
let sR = Db.VDI.get_SR ~__context ~self in
3585+
with_sr_andor_vdi ~__context ~sr:(sR, `vdi_enable_cbt) ~vdi:(self, `enable_cbt) ~doc:"VDI.enable_cbt"
3586+
(fun () ->
3587+
forward_vdi_op ~local_fn ~__context ~self
3588+
(fun session_id rpc -> Client.VDI.enable_cbt rpc session_id self))
3589+
3590+
let disable_cbt ~__context ~self =
3591+
info "VDI.disable_cbt: VDI = '%s'" (vdi_uuid ~__context self);
3592+
let local_fn = Local.VDI.disable_cbt ~self in
3593+
let sR = Db.VDI.get_SR ~__context ~self in
3594+
with_sr_andor_vdi ~__context ~sr:(sR, `vdi_disable_cbt) ~vdi:(self, `disable_cbt) ~doc:"VDI.disable_cbt"
3595+
(fun () ->
3596+
forward_vdi_op ~local_fn ~__context ~self
3597+
(fun session_id rpc -> Client.VDI.disable_cbt rpc session_id self))
3598+
35793599
end
35803600
module VBD = struct
35813601

ocaml/xapi/record_util.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ let host_operation_to_string = function
9797
| `vm_resume -> "VM.resume"
9898
| `vm_migrate -> "VM.migrate"
9999

100-
let vdi_operation_to_string = function
100+
let vdi_operation_to_string: API.vdi_operations -> string = function
101101
| `scan -> "scan"
102102
| `clone -> "clone"
103103
| `copy -> "copy"
@@ -110,9 +110,12 @@ let vdi_operation_to_string = function
110110
| `forget -> "forget"
111111
| `update -> "update"
112112
| `generate_config -> "generate_config"
113+
| `enable_cbt -> "enable_cbt"
114+
| `disable_cbt -> "disable_cbt"
115+
| `set_on_boot -> "set_on_boot"
113116
| `blocked -> "blocked"
114117

115-
let sr_operation_to_string = function
118+
let sr_operation_to_string: API.storage_operations -> string = function
116119
| `scan -> "scan"
117120
| `destroy -> "destroy"
118121
| `forget -> "forget"
@@ -126,6 +129,9 @@ let sr_operation_to_string = function
126129
| `vdi_clone -> "VDI.clone"
127130
| `vdi_snapshot -> "VDI.snapshot"
128131
| `vdi_mirror -> "VDI.mirror"
132+
| `vdi_enable_cbt -> "VDI.enable_cbt"
133+
| `vdi_disable_cbt -> "VDI.disable_cbt"
134+
| `vdi_set_on_boot -> "VDI.set_on_boot"
129135
| `pbd_create -> "PBD.create"
130136
| `pbd_destroy -> "PBD.destroy"
131137

@@ -387,6 +393,7 @@ let vdi_type_to_string t =
387393
| `redo_log -> "Redo log"
388394
| `rrd -> "rrd"
389395
| `pvs_cache -> "PVS cache"
396+
| `cbt_metadata -> "CBT metadata"
390397

391398
let ip_configuration_mode_to_string = function
392399
| `None -> "None"

ocaml/xapi/records.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,7 @@ let vdi_record rpc session_id vdi =
13081308
~get_set:(fun () -> (x ()).API.vDI_tags)
13091309
~add_to_set:(fun tag -> Client.VDI.add_tags rpc session_id vdi tag)
13101310
~remove_from_set:(fun tag -> Client.VDI.remove_tags rpc session_id vdi tag) ();
1311+
make_field ~name:"cbt-enabled" ~get:(fun () -> string_of_bool (x ()).API.vDI_cbt_enabled) ();
13111312
]}
13121313

13131314
let vbd_record rpc session_id vbd =

ocaml/xapi/sm.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ let vdi_epoch_end dconf driver sr vdi =
222222
let call = Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_epoch_end" [] in
223223
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)
224224

225+
let vdi_enable_cbt dconf driver sr vdi =
226+
debug "vdi_enable_cbt" driver (sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi));
227+
srmaster_only dconf;
228+
let call = Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_enable_cbt" [] in
229+
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)
230+
231+
let vdi_disable_cbt dconf driver sr vdi =
232+
debug "vdi_disable_cbt" driver (sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi));
233+
srmaster_only dconf;
234+
let call = Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_disable_cbt" [] in
235+
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)
236+
225237
let session_has_internal_sr_access ~__context ~sr =
226238
let session_id = Context.get_session_id __context in
227239
(* XXX: need to move this somewhere else eventually *)

ocaml/xapi/smint.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type capability =
4242
| Vdi_generate_config
4343
| Vdi_attach_offline
4444
| Vdi_reset_on_boot
45+
| Vdi_configure_cbt
4546

4647
type feature = capability * int64
4748

@@ -67,6 +68,7 @@ let string_to_capability_table = [
6768
"VDI_GENERATE_CONFIG", Vdi_generate_config;
6869
"VDI_ATTACH_OFFLINE", Vdi_attach_offline;
6970
"VDI_RESET_ON_BOOT", Vdi_reset_on_boot;
71+
"VDI_CONFIG_CBT", Vdi_configure_cbt;
7072
"SR_STATS", Sr_stats;
7173
]
7274
let capability_to_string_table = List.map (fun (k, v) -> v, k) string_to_capability_table

0 commit comments

Comments
 (0)