-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PPX memory interface #163
Merged
Merged
PPX memory interface #163
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(* Memory CLI *) | ||
|
||
open Memory_interface | ||
open Xcp_client | ||
open Memory_client | ||
|
||
module Cmds = API(Cmdlinergen.Gen ()) | ||
|
||
let version_str description = | ||
let maj,min,mic = description.Idl.Interface.version in | ||
Printf.sprintf "%d.%d.%d" maj min mic | ||
|
||
let default_cmd = | ||
let doc = String.concat "" [ | ||
"A CLI for the memory API. This allows scripting of the squeeze daemon "; | ||
"for testing and debugging. This tool is not intended to be used as an "; | ||
"end user tool"] in | ||
Cmdliner.Term.(ret (const (fun _ -> `Help (`Pager, None)) $ const ())), | ||
Cmdliner.Term.info "memory_cli" ~version:(version_str Cmds.description) ~doc | ||
|
||
let cli () = | ||
let rpc = Memory_client.rpc in | ||
Cmdliner.Term.eval_choice default_cmd (List.map (fun t -> t rpc) (Cmds.implementation ())) | ||
|
||
let _ = cli () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,47 +14,212 @@ | |
(** | ||
* @group Memory | ||
*) | ||
open Rpc | ||
open Idl | ||
|
||
let service_name = "memory" | ||
let queue_name = Xcp_service.common_prefix ^ service_name | ||
let json_path = "/var/xapi/memory.json" | ||
let xml_path = "/var/xapi/memory" | ||
|
||
type reservation_id = string | ||
type reservation_id = | ||
string [@@doc [ | ||
"The reservation_id is an opaque identifier associated with a block of "; | ||
"memory. It is used to reserve memory for a domain before the domain has "; | ||
"been created."; | ||
]] | ||
[@@deriving rpcty] | ||
|
||
exception Cannot_free_this_much_memory of (int64 * int64) | ||
exception Domains_refused_to_cooperate of (int list) | ||
exception Unknown_reservation of (reservation_id) | ||
exception No_reservation | ||
exception Invalid_memory_value of (int64) | ||
type domain_zero_policy = | ||
| Fixed_size of int64 [@doc ["Never balloon, use the specified fixed size"]] | ||
| Auto_balloon of int64 * int64 [@doc ["Balloon between the two sizes specified"]] | ||
[@@doc ["Domain zero can have a different policy to that used by guest domains."]] | ||
[@@deriving rpcty] | ||
|
||
type errors = | ||
| Cannot_free_this_much_memory of (int64 * int64) | ||
[@doc [ | ||
"[Cannot_free_this_much_memory (required, free)] is reported if it is not "; | ||
"possible to free [required] kib. [free] is the amount of memory currently free"]] | ||
| Domains_refused_to_cooperate of (int list) | ||
[@doc [ | ||
"[Domains_refused_to_cooperate (domid list)] is reported if a set of domains do "; | ||
"not respond in a timely manner to the request to balloon. The uncooperative "; | ||
"domain ids are returned."]] | ||
| Unknown_reservation of (reservation_id) | ||
[@doc [ | ||
"[Unknown_reservation (id)] is reported if a the specified reservation_id is "; | ||
"unknown." | ||
]] | ||
| No_reservation | ||
[@doc [ | ||
"[No_reservation] is reported by [query_reservation_of_domain] if the domain "; | ||
"does not have a reservation." | ||
]] | ||
| Invalid_memory_value of (int64) | ||
[@doc [ | ||
"[Invalid_memory_value (value)] is reported if a memory value passed is not "; | ||
"valid, e.g. negative." | ||
]] | ||
| Unknown_error | ||
[@doc [ | ||
"The default variant for forward compatibility." | ||
]] | ||
[@@default Unknown_error] | ||
[@@deriving rpcty] | ||
|
||
exception MemoryError of errors | ||
|
||
let err = Error.{ | ||
def = errors; | ||
raiser = (function | e -> raise (MemoryError e)); | ||
matcher = function | MemoryError e -> Some e | _ -> None | ||
} | ||
|
||
type debug_info = string | ||
[@@doc ["An uninterpreted string associated with the operation."]] | ||
[@@deriving rpcty] | ||
|
||
type session_id = string | ||
|
||
external get_diagnostics: debug_info -> string = "" | ||
|
||
external login: debug_info -> string -> session_id = "" | ||
|
||
external reserve_memory: debug_info -> session_id -> int64 -> reservation_id = "" | ||
|
||
external reserve_memory_range: debug_info -> session_id -> int64 -> int64 -> reservation_id * int64 = "" | ||
|
||
external delete_reservation: debug_info -> session_id -> reservation_id -> unit = "" | ||
|
||
external transfer_reservation_to_domain: debug_info -> session_id -> reservation_id -> int -> unit = "" | ||
|
||
external query_reservation_of_domain: debug_info -> session_id -> int -> reservation_id = "" | ||
|
||
external balance_memory: debug_info -> unit = "" | ||
|
||
external get_host_reserved_memory: debug_info -> int64 = "" | ||
|
||
external get_host_initial_free_memory: debug_info -> int64 = "" | ||
|
||
type domain_zero_policy = | ||
| Fixed_size of int64 (** it will never be ballooned *) | ||
| Auto_balloon of int64 * int64 (** it will auto-balloon over a range *) | ||
|
||
external get_domain_zero_policy: debug_info -> domain_zero_policy = "" | ||
|
||
[@@doc [ | ||
"An identifier to associate requests with a client. This is "; | ||
"obtained by a call to [login]." | ||
]] | ||
[@@deriving rpcty] | ||
|
||
type reserve_memory_range_result = reservation_id * int64 | ||
[@@deriving rpcty] | ||
|
||
module API(R : RPC) = struct | ||
open R | ||
|
||
let description = Interface.{ | ||
name = "Memory"; | ||
namespace = None; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would be the effect of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It just changes the wire-name of the API call |
||
description = [ | ||
"This interface is used by Xapi and Squeezed to manage the "; | ||
"dynamic memory usage of VMs on a host."; | ||
]; | ||
version=(1,0,0); | ||
} | ||
|
||
let implementation = implement description | ||
|
||
(* General parameters, used by more than one API call *) | ||
|
||
let debug_info_p = Param.mk ~description:[ | ||
"An uninterpreted string to associate with the operation." | ||
] Types.string | ||
|
||
let diagnostics_result_p = Param.mk ~description:[ | ||
"A string containing diagnostic information from the server." | ||
] Types.string | ||
|
||
let service_name_p = Param.mk ~description:[ | ||
"The name of the service attempting to interact with the squeeze daemon." | ||
] Types.string | ||
|
||
let session_id_p = Param.mk ~description:[ | ||
"An identifier to associate requests with a client. This is "; | ||
"obtained by a call to [login]."] | ||
Types.string | ||
|
||
let domid_p = Param.mk ~description:[ | ||
"Domain id of a VM." | ||
] Types.int | ||
|
||
let reservation_id_p = Param.mk ~description:[ | ||
"The reservation_id is the token used to identify a memory allocation." | ||
] reservation_id | ||
|
||
let size_p = Param.mk ~description:[ | ||
"The size in bytes to reserve"] | ||
Types.int64 | ||
|
||
let unit_p = Param.mk Types.unit | ||
|
||
(* Individual API calls *) | ||
|
||
let get_diagnostics = declare | ||
"get_diagnostics" | ||
["Gets diagnostic information from the server"] | ||
(debug_info_p @-> returning diagnostics_result_p err) | ||
|
||
let login = declare | ||
"login" | ||
["Logs into the squeeze daemon. Any reservations previously made with the "; | ||
"specified service name not yet associated with a domain will be removed."] | ||
(debug_info_p @-> service_name_p @-> returning session_id_p err) | ||
|
||
|
||
let reserve_memory = declare | ||
"reserve_memory" | ||
["[reserve_memory dbg session size] reserves memory for a domain. If necessary, "; | ||
"other domains will be ballooned down to ensure [size] is available. The call "; | ||
"returns a reservation_id that can later be transferred to a domain."] | ||
(debug_info_p @-> session_id_p @-> size_p @-> returning reservation_id_p err) | ||
|
||
let reserve_memory_range = | ||
let result = Param.mk | ||
~description:[ | ||
"A tuple containing the reservation_id and the amount of memory actually reserved." | ||
] | ||
reserve_memory_range_result | ||
in | ||
declare | ||
"reserve_memory_range" | ||
["[reserve_memory_range dbg session min max] reserves memory for a domain. If necessary, "; | ||
"other domains will be ballooned down to ensure enough memory is available. The amount "; | ||
"of memory will be between [min] and [max] according to the policy in operation. The call "; | ||
"returns a reservation_id and the actual memory amount that can later be transferred to a domain."] | ||
(debug_info_p @-> session_id_p @-> size_p @-> size_p @-> returning result err) | ||
|
||
|
||
let delete_reservation = | ||
declare | ||
"delete_reservation" | ||
["Deletes a reservation. Note that memory rebalancing is not done synchronously after the "; | ||
"operation has completed."] | ||
(debug_info_p @-> session_id_p @-> reservation_id_p @-> returning unit_p err) | ||
|
||
let transfer_reservation_to_domain = | ||
declare | ||
"transfer_reservation_to_domain" | ||
["Transfers a reservation to a domain. This is called when the domain has been created for "; | ||
"the VM for which the reservation was initially made."] | ||
(debug_info_p @-> session_id_p @-> reservation_id_p @-> domid_p @-> returning unit_p err) | ||
|
||
let query_reservation_of_domain = | ||
declare | ||
"query_reservation_of_domain" | ||
["Queries the reservation_id associated with a domain"] | ||
(debug_info_p @-> session_id_p @-> domid_p @-> returning reservation_id_p err) | ||
|
||
let balance_memory = | ||
declare | ||
"balance_memory" | ||
["Forces a rebalance of the hosts memory. Blocks until the system is in a stable "; | ||
"state."] | ||
(debug_info_p @-> returning unit_p err) | ||
|
||
let get_host_reserved_memory = | ||
declare | ||
"get_host_reserved_memory" | ||
["Gets the amount of reserved memory in a host. This is the lower limit of memory that "; | ||
"squeezed will ensure remains unused by any domain or reservation."] | ||
(debug_info_p @-> returning size_p err) | ||
|
||
let get_host_initial_free_memory = | ||
declare | ||
"get_host_initial_free_memory" | ||
["Gets the amount of initial free memory in a host"] | ||
(debug_info_p @-> returning size_p err) | ||
|
||
let get_domain_zero_policy = | ||
let result_p = Param.mk ~description:["The policy associated with domain 0"] domain_zero_policy in | ||
declare | ||
"get_domain_zero_policy" | ||
["Gets the ballooning policy for domain zero."] | ||
(debug_info_p @-> returning result_p err) | ||
|
||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With documentation generation? 🎉