Skip to content

Commit 7ff43a0

Browse files
committed
Merge pull request #43 from djs55/epoch-open
API changes for clone-on-boot
2 parents 0979190 + 2e6ebe9 commit 7ff43a0

File tree

5 files changed

+113
-15
lines changed

5 files changed

+113
-15
lines changed

generator/src/control.ml

+47-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ let api =
6060
"protocols, he list should be sorted into descending order of ";
6161
"desirability. Xapi will open the most desirable URI for which it has ";
6262
"an available datapath plugin.";
63-
]
63+
];
64+
"keys", Dict(String, Basic String), String.concat " " [
65+
"A lit of key=value pairs which have been stored in the Volume ";
66+
"metadata. These should not be interpreted by the Volume plugin.";
67+
];
6468
]
6569
)) in
6670
let volume = Type.Name "volume" in
@@ -210,6 +214,8 @@ let api =
210214
"[snapshot sr volume] creates a new volue which is a ";
211215
"snapshot of [volume] in [sr]. Snapshots should never be";
212216
"written to; they are intended for backup/restore only.";
217+
"Note the name and description are copied but any extra";
218+
"metadata associated by [set] is not copied.";
213219
];
214220
inputs = [
215221
sr;
@@ -225,7 +231,8 @@ let api =
225231
Method.name = "clone";
226232
description = String.concat " " [
227233
"[clone sr volume] creates a new volume which is a writable";
228-
"clone of [volume] in [sr].";
234+
"clone of [volume] in [sr]. Note the name and description are";
235+
"copied but any extra metadata associated by [set] is not copied.";
229236
];
230237
inputs = [
231238
sr;
@@ -276,6 +283,44 @@ let api =
276283
];
277284
outputs = [
278285
];
286+
}; {
287+
Method.name = "set";
288+
description = String.concat " " [
289+
"[set sr volume key value] associates [key] with [value] in the metadata of [volume]";
290+
"Note these keys and values are not interpreted by the plugin; they are intended for";
291+
"the higher-level software only.";
292+
];
293+
inputs = [
294+
sr;
295+
key;
296+
{ Arg.name = "k";
297+
ty = Basic String;
298+
description = "Key"
299+
}; {
300+
Arg.name = "v";
301+
ty = Basic String;
302+
description = "Value"
303+
}
304+
];
305+
outputs = [
306+
];
307+
}; {
308+
Method.name = "unset";
309+
description = String.concat " " [
310+
"[unset sr volume key] removes [key] and any value associated with it from the metadata of [volume]";
311+
"Note these keys and values are not interpreted by the plugin; they are intended for";
312+
"the higher-level software only.";
313+
];
314+
inputs = [
315+
sr;
316+
key;
317+
{ Arg.name = "k";
318+
ty = Basic String;
319+
description = "Key"
320+
}
321+
];
322+
outputs = [
323+
];
279324
}; {
280325
Method.name = "resize";
281326
description = String.concat " " [

generator/src/data.ml

+35
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ let backend = {
1818
description = "The Xen block backend configuration."
1919
}
2020

21+
let persistent = {
22+
Arg.name = "persistent";
23+
ty = Type.(Basic Boolean);
24+
description = String.concat "" [
25+
"True means the disk data is persistent and should be preserved when the datapath ";
26+
"is closed i.e. when a VM is shutdown or rebooted. False means the data should be ";
27+
"thrown away when the VM is shutdown or rebooted.";
28+
]
29+
}
30+
2131
let implementation = Type.Variant (
2232
("Blkback", Type.(Basic String), "use kernel blkback with the given 'params' key"), [
2333
"Tapdisk3", Type.(Basic String), "use userspace tapdisk3 with the given 'params' key";
@@ -95,6 +105,20 @@ let api =
95105
];
96106
methods = [
97107
{
108+
Method.name = "open";
109+
description = String.concat " "[
110+
"[open uri persistent] is called before a disk is attached to a VM. If";
111+
"persistent is true then care should be taken to persist all writes to the";
112+
"disk. If persistent is false then the implementation should configure";
113+
"a temporary location for writes so they can be thrown away on [close]."
114+
];
115+
inputs = [
116+
uri;
117+
persistent;
118+
];
119+
outputs = [
120+
];
121+
}; {
98122
Method.name = "attach";
99123
description = String.concat " "[
100124
"[attach uri domain] prepares a connection between the storage";
@@ -164,6 +188,17 @@ let api =
164188
];
165189
outputs = [
166190
];
191+
}; {
192+
Method.name = "close";
193+
description = String.concat " "[
194+
"[close uri] is called after a disk is detached and a VM shutdown.";
195+
"This is an opportunity to throw away writes if the disk is not persistent.";
196+
];
197+
inputs = [
198+
uri;
199+
];
200+
outputs = [
201+
];
167202
}
168203
]
169204
}

generator/src/ocaml.ml

+13-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ let rec lines_of_t t =
1414

1515
let string_of_ts ts = String.concat "\n" (List.concat (List.map lines_of_t ts))
1616

17+
let keywords = [
18+
"open";
19+
]
20+
21+
let escape_keywords x = if List.mem x keywords then "_" ^ x else x
22+
1723
open Printf
1824

1925
let rec typeof ?(expand_aliases=false) env t =
@@ -315,7 +321,7 @@ let skeleton_method unimplemented env i m =
315321
let unimplemented_error =
316322
sprintf "return (`Error (Unimplemented \"%s.%s\"))" i.Interface.name m.Method.name in
317323
[
318-
Line (sprintf "let %s x =" m.Method.name);
324+
Line (sprintf "let %s x =" (escape_keywords m.Method.name));
319325
Block [
320326
Line (sprintf "let open Types.%s.%s in" i.Interface.name (String.capitalize m.Method.name));
321327
Line "let open Types in";
@@ -365,7 +371,7 @@ let example_stub env is i m =
365371
];
366372
Line "end)";
367373
Line "";
368-
Line (sprintf "let result = Client.%s %s;;" m.Method.name (String.concat " " (List.map (fun a -> sprintf "~%s:%s" a.Arg.name (example_value_of env a.Arg.ty)) m.Method.inputs)));
374+
Line (sprintf "let result = Client.%s %s;;" (escape_keywords m.Method.name) (String.concat " " (List.map (fun a -> sprintf "~%s:%s" a.Arg.name (example_value_of env a.Arg.ty)) m.Method.inputs)));
369375
]
370376

371377
let skeleton_of_interface unimplemented suffix env i =
@@ -381,7 +387,7 @@ let skeleton_of_interface unimplemented suffix env i =
381387
let signature_of_interface env i =
382388
let signature_of_method m =
383389
Line (sprintf "val %s: Types.%s.%s.In.t -> (Types.%s.%s.Out.t, exn) Result.t t"
384-
m.Method.name
390+
(escape_keywords m.Method.name)
385391
i.Interface.name (String.capitalize m.Method.name)
386392
i.Interface.name (String.capitalize m.Method.name)
387393
) in
@@ -402,7 +408,7 @@ let server_of_interface env i =
402408
[
403409
Line (sprintf "| Types.%s.In.%s x ->" i.Interface.name (String.capitalize m.Method.name));
404410
Block [
405-
Line (sprintf "Impl.%s x" m.Method.name);
411+
Line (sprintf "Impl.%s x" (escape_keywords m.Method.name));
406412
Line ">>= fun result ->";
407413
Line "return (Result.(>>=) result (fun ok ->";
408414
Block [
@@ -441,17 +447,17 @@ let server_of_interface env i =
441447
let client_of_interfaces env is =
442448
let client_of_method env i m =
443449
[
444-
Line (sprintf "let %s_r x =" m.Method.name);
450+
Line (sprintf "let %s_r x =" (escape_keywords m.Method.name));
445451
Block [
446452
Line (sprintf "let call = Types.%s.In.call_of (Types.%s.In.%s x) in" i.Interface.name i.Interface.name (String.capitalize m.Method.name));
447453
Line "RPC.rpc call >>= fun response ->";
448454
Line (sprintf "let result = Result.(>>=) (result_of_response response) (fun x -> Result.return (Types.%s.%s.Out.t_of_rpc x)) in" i.Interface.name (String.capitalize m.Method.name));
449455
Line "return result";
450456
];
451-
Line (sprintf "let %s %s =" m.Method.name (String.concat " " (List.map (fun i -> sprintf "~%s" i.Arg.name) m.Method.inputs)));
457+
Line (sprintf "let %s %s =" (escape_keywords m.Method.name) (String.concat " " (List.map (fun i -> sprintf "~%s" i.Arg.name) m.Method.inputs)));
452458
Block [
453459
Line (sprintf "let r = Types.%s.%s.In.({ %s }) in" i.Interface.name (String.capitalize m.Method.name) (String.concat "; " (List.map (fun i -> sprintf "%s = %s" i.Arg.name i.Arg.name) m.Method.inputs)));
454-
Line (sprintf "%s_r r" m.Method.name);
460+
Line (sprintf "%s_r r" (escape_keywords m.Method.name));
455461
]
456462
] in
457463
let client_of_interface env i =

generator/src/python.ml

+15-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ let rec lines_of_t t =
1414

1515
let string_of_ts ts = String.concat "\n" (List.concat (List.map lines_of_t ts))
1616

17+
(* generate a fresh id *)
18+
let fresh_id =
19+
let counter = ref 0 in
20+
fun () ->
21+
incr counter;
22+
"tmp_" ^ (string_of_int !counter)
23+
1724
(** [typecheck ty v] returns a python fragment which checks
1825
[v] has type [ty] *)
1926
let rec typecheck env ty v =
@@ -47,20 +54,22 @@ let rec typecheck env ty v =
4754
] in
4855
(member true hd) @ (List.concat (List.map (member false) tl))
4956
| Array t ->
57+
let id = fresh_id () in
5058
[
5159
Line (sprintf "if type(%s) <> type([]):" v);
5260
Block [ raise_type_error ];
53-
Line (sprintf "for x in %s:" v);
54-
Block (typecheck env t "x")
61+
Line (sprintf "for %s in %s:" id v);
62+
Block (typecheck env t id)
5563
]
5664
| Dict (key, va) ->
65+
let id = fresh_id () in
5766
[
5867
Line (sprintf "if type(%s) <> type({}):" v);
5968
Block [ raise_type_error ];
60-
Line (sprintf "for x in %s.keys():" v);
61-
Block (typecheck env (Basic key) "x");
62-
Line (sprintf "for x in %s.values():" v);
63-
Block (typecheck env va "x")
69+
Line (sprintf "for %s in %s.keys():" id v);
70+
Block (typecheck env (Basic key) id);
71+
Line (sprintf "for %s in %s.values():" id v);
72+
Block (typecheck env va id)
6473
]
6574
| Name x ->
6675
let ident =

python/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ install: build
1616
.PHONY: uninstall
1717
uninstall:
1818
echo "I don't know how to uninstall python code"
19+
20+
.PHONY: reinstall
21+
reinstall: install

0 commit comments

Comments
 (0)