1313 *)
1414(* *
1515 * @group Memory
16- *)
16+ *)
1717open Rpc
1818open Idl
1919
@@ -24,57 +24,64 @@ let xml_path = "/var/xapi/memory"
2424
2525type reservation_id =
2626 string [@@ doc [
27- "The reservation_id is an opaque identifier associated with a block of " ;
28- "memory. It is used to reserve memory for a domain before the domain has " ;
29- "been created." ;
30- ]]
31- [@@ deriving rpcty ]
27+ "The reservation_id is an opaque identifier associated with a block of " ;
28+ "memory. It is used to reserve memory for a domain before the domain has " ;
29+ "been created." ;
30+ ]]
31+ [@@ deriving rpcty ]
3232
3333type domain_zero_policy =
34- | Fixed_size of int64 [@ doc ["Never balloon, use the specified fixed size" ]]
35- | Auto_balloon of int64 * int64 [@ doc ["Balloon between the two sizes specified" ]]
36- [@@ doc ["Domain zero can have a different policy to that used by guest domains." ]]
37- [@@ deriving rpcty ]
34+ | Fixed_size of int64 [@ doc ["Never balloon, use the specified fixed size" ]]
35+ | Auto_balloon of int64 * int64 [@ doc ["Balloon between the two sizes specified" ]]
36+ [@@ doc ["Domain zero can have a different policy to that used by guest domains." ]]
37+ [@@ deriving rpcty ]
3838
3939type errors =
40- | Cannot_free_this_much_memory of (int64 * int64 )
41- [@ doc [
42- "[Cannot_free_this_much_memory (required, free)] is reported if it is not " ;
43- "possible to free [required] kib. [free] is the amount of memory currently free" ]]
44- | Domains_refused_to_cooperate of (int list )
45- [@ doc [
46- "[Domains_refused_to_cooperate (domid list)] is reported if a set of domains do " ;
47- "not respond in a timely manner to the request to balloon. The uncooperative " ;
48- "domain ids are returned." ]]
49- | Unknown_reservation of (reservation_id )
50- [@ doc [
51- "[Unknown_reservation (id)] is reported if a the specified reservation_id is " ;
52- "unknown."
53- ]]
54- | No_reservation
55- [@ doc [
56- "[No_reservation] is reported by [query_reservation_of_domain] if the domain " ;
57- "does not have a reservation."
58- ]]
59- | Invalid_memory_value of (int64 )
60- [@ doc [
61- "[Invalid_memory_value (value)] is reported if a memory value passed is not " ;
62- "valid, e.g. negative."
63- ]]
64- | Unknown_error
65- [@ doc [
66- "The default variant for forward compatibility."
67- ]]
40+ | Cannot_free_this_much_memory of (int64 * int64 )
41+ [@ doc [
42+ "[Cannot_free_this_much_memory (required, free)] is reported if it is not " ;
43+ "possible to free [required] kib. [free] is the amount of memory currently free" ]]
44+ | Domains_refused_to_cooperate of (int list )
45+ [@ doc [
46+ "[Domains_refused_to_cooperate (domid list)] is reported if a set of domains do " ;
47+ "not respond in a timely manner to the request to balloon. The uncooperative " ;
48+ "domain ids are returned." ]]
49+ | Unknown_reservation of (reservation_id )
50+ [@ doc [
51+ "[Unknown_reservation (id)] is reported if a the specified reservation_id is " ;
52+ "unknown."
53+ ]]
54+ | No_reservation
55+ [@ doc [
56+ "[No_reservation] is reported by [query_reservation_of_domain] if the domain " ;
57+ "does not have a reservation."
58+ ]]
59+ | Invalid_memory_value of (int64 )
60+ [@ doc [
61+ "[Invalid_memory_value (value)] is reported if a memory value passed is not " ;
62+ "valid, e.g. negative."
63+ ]]
64+ | Internal_error of (string )
65+ [@ doc [
66+ "[Internal_error (value)] is reported if an unexpected error is triggered " ;
67+ "by the library."
68+ ]]
69+ | Unknown_error
70+ [@ doc [
71+ "The default variant for forward compatibility."
72+ ]]
6873[@@ default Unknown_error ]
6974[@@ deriving rpcty ]
7075
7176exception MemoryError of errors
7277
7378let err = Error. {
74- def = errors;
75- raiser = (function | e -> raise (MemoryError e));
76- matcher = function | MemoryError e -> Some e | _ -> None
77- }
79+ def = errors;
80+ raiser = (fun e -> raise (MemoryError e));
81+ matcher = (function
82+ | MemoryError e -> Some e
83+ | e -> Some (Internal_error (Printexc. to_string e)))
84+ }
7885
7986type debug_info = string
8087[@@ doc ["An uninterpreted string associated with the operation." ]]
@@ -108,118 +115,118 @@ module API(R : RPC) = struct
108115 (* General parameters, used by more than one API call *)
109116
110117 let debug_info_p = Param. mk ~description: [
111- " An uninterpreted string to associate with the operation."
118+ " An uninterpreted string to associate with the operation."
112119 ] Types. string
113120
114121 let diagnostics_result_p = Param. mk ~description: [
115- " A string containing diagnostic information from the server."
122+ " A string containing diagnostic information from the server."
116123 ] Types. string
117124
118125 let service_name_p = Param. mk ~description: [
119- " The name of the service attempting to interact with the squeeze daemon."
126+ " The name of the service attempting to interact with the squeeze daemon."
120127 ] Types. string
121128
122129 let session_id_p = Param. mk ~description: [
123- " An identifier to associate requests with a client. This is " ;
124- " obtained by a call to [login]." ]
125- Types. string
130+ " An identifier to associate requests with a client. This is " ;
131+ " obtained by a call to [login]." ]
132+ Types. string
126133
127134 let domid_p = Param. mk ~description: [
128- " Domain id of a VM."
135+ " Domain id of a VM."
129136 ] Types. int
130137
131138 let reservation_id_p = Param. mk ~description: [
132- " The reservation_id is the token used to identify a memory allocation."
139+ " The reservation_id is the token used to identify a memory allocation."
133140 ] reservation_id
134141
135142 let size_p = Param. mk ~description: [
136- " The size in bytes to reserve" ]
137- Types. int64
143+ " The size in bytes to reserve" ]
144+ Types. int64
138145
139146 let unit_p = Param. mk Types. unit
140147
141148 (* Individual API calls *)
142149
143150 let get_diagnostics = declare
144- " get_diagnostics"
145- [" Gets diagnostic information from the server" ]
146- (debug_info_p @-> returning diagnostics_result_p err)
151+ " get_diagnostics"
152+ [" Gets diagnostic information from the server" ]
153+ (debug_info_p @-> returning diagnostics_result_p err)
147154
148155 let login = declare
149- " login"
150- [" Logs into the squeeze daemon. Any reservations previously made with the " ;
151- " specified service name not yet associated with a domain will be removed." ]
152- (debug_info_p @-> service_name_p @-> returning session_id_p err)
156+ " login"
157+ [" Logs into the squeeze daemon. Any reservations previously made with the " ;
158+ " specified service name not yet associated with a domain will be removed." ]
159+ (debug_info_p @-> service_name_p @-> returning session_id_p err)
153160
154161
155162 let reserve_memory = declare
156- " reserve_memory"
157- [" [reserve_memory dbg session size] reserves memory for a domain. If necessary, " ;
158- " other domains will be ballooned down to ensure [size] is available. The call " ;
159- " returns a reservation_id that can later be transferred to a domain." ]
160- (debug_info_p @-> session_id_p @-> size_p @-> returning reservation_id_p err)
163+ " reserve_memory"
164+ [" [reserve_memory dbg session size] reserves memory for a domain. If necessary, " ;
165+ " other domains will be ballooned down to ensure [size] is available. The call " ;
166+ " returns a reservation_id that can later be transferred to a domain." ]
167+ (debug_info_p @-> session_id_p @-> size_p @-> returning reservation_id_p err)
161168
162169 let reserve_memory_range =
163170 let result = Param. mk
164- ~description: [
165- " A tuple containing the reservation_id and the amount of memory actually reserved."
166- ]
167- reserve_memory_range_result
171+ ~description: [
172+ " A tuple containing the reservation_id and the amount of memory actually reserved."
173+ ]
174+ reserve_memory_range_result
168175 in
169176 declare
170177 " reserve_memory_range"
171- [" [reserve_memory_range dbg session min max] reserves memory for a domain. If necessary, " ;
172- " other domains will be ballooned down to ensure enough memory is available. The amount " ;
173- " of memory will be between [min] and [max] according to the policy in operation. The call " ;
174- " returns a reservation_id and the actual memory amount that can later be transferred to a domain." ]
175- (debug_info_p @-> session_id_p @-> size_p @-> size_p @-> returning result err)
178+ [" [reserve_memory_range dbg session min max] reserves memory for a domain. If necessary, " ;
179+ " other domains will be ballooned down to ensure enough memory is available. The amount " ;
180+ " of memory will be between [min] and [max] according to the policy in operation. The call " ;
181+ " returns a reservation_id and the actual memory amount that can later be transferred to a domain." ]
182+ (debug_info_p @-> session_id_p @-> size_p @-> size_p @-> returning result err)
176183
177184
178185 let delete_reservation =
179186 declare
180- " delete_reservation"
181- [" Deletes a reservation. Note that memory rebalancing is not done synchronously after the " ;
182- " operation has completed." ]
183- (debug_info_p @-> session_id_p @-> reservation_id_p @-> returning unit_p err)
187+ " delete_reservation"
188+ [" Deletes a reservation. Note that memory rebalancing is not done synchronously after the " ;
189+ " operation has completed." ]
190+ (debug_info_p @-> session_id_p @-> reservation_id_p @-> returning unit_p err)
184191
185192 let transfer_reservation_to_domain =
186193 declare
187- " transfer_reservation_to_domain"
188- [" Transfers a reservation to a domain. This is called when the domain has been created for " ;
189- " the VM for which the reservation was initially made." ]
190- (debug_info_p @-> session_id_p @-> reservation_id_p @-> domid_p @-> returning unit_p err)
194+ " transfer_reservation_to_domain"
195+ [" Transfers a reservation to a domain. This is called when the domain has been created for " ;
196+ " the VM for which the reservation was initially made." ]
197+ (debug_info_p @-> session_id_p @-> reservation_id_p @-> domid_p @-> returning unit_p err)
191198
192199 let query_reservation_of_domain =
193200 declare
194- " query_reservation_of_domain"
195- [" Queries the reservation_id associated with a domain" ]
196- (debug_info_p @-> session_id_p @-> domid_p @-> returning reservation_id_p err)
201+ " query_reservation_of_domain"
202+ [" Queries the reservation_id associated with a domain" ]
203+ (debug_info_p @-> session_id_p @-> domid_p @-> returning reservation_id_p err)
197204
198205 let balance_memory =
199206 declare
200- " balance_memory"
201- [" Forces a rebalance of the hosts memory. Blocks until the system is in a stable " ;
202- " state." ]
203- (debug_info_p @-> returning unit_p err)
207+ " balance_memory"
208+ [" Forces a rebalance of the hosts memory. Blocks until the system is in a stable " ;
209+ " state." ]
210+ (debug_info_p @-> returning unit_p err)
204211
205212 let get_host_reserved_memory =
206213 declare
207- " get_host_reserved_memory"
208- [" Gets the amount of reserved memory in a host. This is the lower limit of memory that " ;
209- " squeezed will ensure remains unused by any domain or reservation." ]
210- (debug_info_p @-> returning size_p err)
214+ " get_host_reserved_memory"
215+ [" Gets the amount of reserved memory in a host. This is the lower limit of memory that " ;
216+ " squeezed will ensure remains unused by any domain or reservation." ]
217+ (debug_info_p @-> returning size_p err)
211218
212219 let get_host_initial_free_memory =
213220 declare
214- " get_host_initial_free_memory"
215- [" Gets the amount of initial free memory in a host" ]
216- (debug_info_p @-> returning size_p err)
221+ " get_host_initial_free_memory"
222+ [" Gets the amount of initial free memory in a host" ]
223+ (debug_info_p @-> returning size_p err)
217224
218225 let get_domain_zero_policy =
219226 let result_p = Param. mk ~description: [" The policy associated with domain 0" ] domain_zero_policy in
220227 declare
221- " get_domain_zero_policy"
222- [" Gets the ballooning policy for domain zero." ]
223- (debug_info_p @-> returning result_p err)
228+ " get_domain_zero_policy"
229+ [" Gets the ballooning policy for domain zero." ]
230+ (debug_info_p @-> returning result_p err)
224231
225232end
0 commit comments