Skip to content

Commit ed14734

Browse files
mseriJon Ludlam
authored andcommitted
CA-283754: ppxified interfaces, do not discard internal errors (#204)
* CA-283754: memory_interface, do not discard internal errors Signed-off-by: Marcello Seri <[email protected]> * memory_interface: run ocp-indent Signed-off-by: Marcello Seri <[email protected]> * CA-283754: gpumon_interface, do not discard internal errors Signed-off-by: Marcello Seri <[email protected]> * gpumon_interface: run ocp-indent Signed-off-by: Marcello Seri <[email protected]> * CA-283754: v6_interface, do not discard internal errors Signed-off-by: Marcello Seri <[email protected]>
1 parent 9b44fc9 commit ed14734

File tree

3 files changed

+122
-110
lines changed

3 files changed

+122
-110
lines changed

gpumon/gpumon_interface.ml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ type gpu_errors =
6464
(** Exception raised when gpumon is unable to load the nvml nvidia library *)
6565
| NvmlFailure of string
6666
(** Exception raised by the c bindings to the nvml nvidia library*)
67+
| Internal_error of string
68+
(** Exception raised if an unexpected error is triggered by the library *)
6769
| Gpumon_failure
6870
(** Default exception raised upon daemon failure *)
6971
[@@default Gpumon_failure]
@@ -72,11 +74,13 @@ type gpu_errors =
7274
exception Gpumon_error of gpu_errors
7375

7476
(** Error handler *)
75-
module GpuErrors = Error.Make(struct
76-
type t = gpu_errors
77-
let t = gpu_errors
78-
end)
79-
let gpu_err = GpuErrors.error
77+
let gpu_err = Error.{
78+
def = gpu_errors;
79+
raiser = (fun e -> raise (Gpumon_error e));
80+
matcher = (function
81+
| Gpumon_error e -> Some e
82+
| e -> Some (Internal_error (Printexc.to_string e)))
83+
}
8084

8185
(** Functor to autogenerate API calls *)
8286
module RPC_API(R : RPC) = struct
@@ -151,9 +155,9 @@ module RPC_API(R : RPC) = struct
151155
declare "get_vgpu_metadata"
152156
[ "Obtains metadata for all vGPUs running in a domain." ]
153157
( debug_info_p
154-
@-> domid_p
155-
@-> pgpu_address_p
156-
@-> returning nvidia_vgpu_metadata_list_p gpu_err
158+
@-> domid_p
159+
@-> pgpu_address_p
160+
@-> returning nvidia_vgpu_metadata_list_p gpu_err
157161
)
158162

159163
let get_pgpu_vgpu_compatibility =

memory/memory_interface.ml

Lines changed: 105 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*)
1414
(**
1515
* @group Memory
16-
*)
16+
*)
1717
open Rpc
1818
open Idl
1919

@@ -24,57 +24,64 @@ let xml_path = "/var/xapi/memory"
2424

2525
type 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

3333
type 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

3939
type 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

7176
exception MemoryError of errors
7277

7378
let 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

7986
type 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

225232
end

v6/v6_interface.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ type errors =
8282
(** Thrown if connection port or address parameter not supplied to check_license *)
8383
| V6d_failure
8484
(** Daemon failed to enable features *)
85+
| Internal_error of string
86+
(** Exception raised if an unexpected error is triggered by the library *)
8587
[@@default V6d_failure]
8688
[@@deriving rpcty]
8789

@@ -92,11 +94,10 @@ exception V6_error of errors
9294
(** handle exception generation and raising *)
9395
let err = Error.{
9496
def = errors;
95-
raiser = (function
96-
| e -> raise (V6_error e));
97+
raiser = (fun e -> raise (V6_error e));
9798
matcher = (function
98-
| V6_error e -> Some e
99-
| _ -> None)
99+
| V6_error e -> Some e
100+
| e -> Some (Internal_error (Printexc.to_string e)))
100101
}
101102

102103

0 commit comments

Comments
 (0)