Skip to content

Commit

Permalink
Merge pull request #43 from djs55/epoch-open
Browse files Browse the repository at this point in the history
API changes for clone-on-boot
  • Loading branch information
djs55 committed Jul 15, 2015
2 parents 0979190 + 2e6ebe9 commit 7ff43a0
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 15 deletions.
49 changes: 47 additions & 2 deletions generator/src/control.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ let api =
"protocols, he list should be sorted into descending order of ";
"desirability. Xapi will open the most desirable URI for which it has ";
"an available datapath plugin.";
]
];
"keys", Dict(String, Basic String), String.concat " " [
"A lit of key=value pairs which have been stored in the Volume ";
"metadata. These should not be interpreted by the Volume plugin.";
];
]
)) in
let volume = Type.Name "volume" in
Expand Down Expand Up @@ -210,6 +214,8 @@ let api =
"[snapshot sr volume] creates a new volue which is a ";
"snapshot of [volume] in [sr]. Snapshots should never be";
"written to; they are intended for backup/restore only.";
"Note the name and description are copied but any extra";
"metadata associated by [set] is not copied.";
];
inputs = [
sr;
Expand All @@ -225,7 +231,8 @@ let api =
Method.name = "clone";
description = String.concat " " [
"[clone sr volume] creates a new volume which is a writable";
"clone of [volume] in [sr].";
"clone of [volume] in [sr]. Note the name and description are";
"copied but any extra metadata associated by [set] is not copied.";
];
inputs = [
sr;
Expand Down Expand Up @@ -276,6 +283,44 @@ let api =
];
outputs = [
];
}; {
Method.name = "set";
description = String.concat " " [
"[set sr volume key value] associates [key] with [value] in the metadata of [volume]";
"Note these keys and values are not interpreted by the plugin; they are intended for";
"the higher-level software only.";
];
inputs = [
sr;
key;
{ Arg.name = "k";
ty = Basic String;
description = "Key"
}; {
Arg.name = "v";
ty = Basic String;
description = "Value"
}
];
outputs = [
];
}; {
Method.name = "unset";
description = String.concat " " [
"[unset sr volume key] removes [key] and any value associated with it from the metadata of [volume]";
"Note these keys and values are not interpreted by the plugin; they are intended for";
"the higher-level software only.";
];
inputs = [
sr;
key;
{ Arg.name = "k";
ty = Basic String;
description = "Key"
}
];
outputs = [
];
}; {
Method.name = "resize";
description = String.concat " " [
Expand Down
35 changes: 35 additions & 0 deletions generator/src/data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ let backend = {
description = "The Xen block backend configuration."
}

let persistent = {
Arg.name = "persistent";
ty = Type.(Basic Boolean);
description = String.concat "" [
"True means the disk data is persistent and should be preserved when the datapath ";
"is closed i.e. when a VM is shutdown or rebooted. False means the data should be ";
"thrown away when the VM is shutdown or rebooted.";
]
}

let implementation = Type.Variant (
("Blkback", Type.(Basic String), "use kernel blkback with the given 'params' key"), [
"Tapdisk3", Type.(Basic String), "use userspace tapdisk3 with the given 'params' key";
Expand Down Expand Up @@ -95,6 +105,20 @@ let api =
];
methods = [
{
Method.name = "open";
description = String.concat " "[
"[open uri persistent] is called before a disk is attached to a VM. If";
"persistent is true then care should be taken to persist all writes to the";
"disk. If persistent is false then the implementation should configure";
"a temporary location for writes so they can be thrown away on [close]."
];
inputs = [
uri;
persistent;
];
outputs = [
];
}; {
Method.name = "attach";
description = String.concat " "[
"[attach uri domain] prepares a connection between the storage";
Expand Down Expand Up @@ -164,6 +188,17 @@ let api =
];
outputs = [
];
}; {
Method.name = "close";
description = String.concat " "[
"[close uri] is called after a disk is detached and a VM shutdown.";
"This is an opportunity to throw away writes if the disk is not persistent.";
];
inputs = [
uri;
];
outputs = [
];
}
]
}
Expand Down
20 changes: 13 additions & 7 deletions generator/src/ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ let rec lines_of_t t =

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

let keywords = [
"open";
]

let escape_keywords x = if List.mem x keywords then "_" ^ x else x

open Printf

let rec typeof ?(expand_aliases=false) env t =
Expand Down Expand Up @@ -315,7 +321,7 @@ let skeleton_method unimplemented env i m =
let unimplemented_error =
sprintf "return (`Error (Unimplemented \"%s.%s\"))" i.Interface.name m.Method.name in
[
Line (sprintf "let %s x =" m.Method.name);
Line (sprintf "let %s x =" (escape_keywords m.Method.name));
Block [
Line (sprintf "let open Types.%s.%s in" i.Interface.name (String.capitalize m.Method.name));
Line "let open Types in";
Expand Down Expand Up @@ -365,7 +371,7 @@ let example_stub env is i m =
];
Line "end)";
Line "";
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)));
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)));
]

let skeleton_of_interface unimplemented suffix env i =
Expand All @@ -381,7 +387,7 @@ let skeleton_of_interface unimplemented suffix env i =
let signature_of_interface env i =
let signature_of_method m =
Line (sprintf "val %s: Types.%s.%s.In.t -> (Types.%s.%s.Out.t, exn) Result.t t"
m.Method.name
(escape_keywords m.Method.name)
i.Interface.name (String.capitalize m.Method.name)
i.Interface.name (String.capitalize m.Method.name)
) in
Expand All @@ -402,7 +408,7 @@ let server_of_interface env i =
[
Line (sprintf "| Types.%s.In.%s x ->" i.Interface.name (String.capitalize m.Method.name));
Block [
Line (sprintf "Impl.%s x" m.Method.name);
Line (sprintf "Impl.%s x" (escape_keywords m.Method.name));
Line ">>= fun result ->";
Line "return (Result.(>>=) result (fun ok ->";
Block [
Expand Down Expand Up @@ -441,17 +447,17 @@ let server_of_interface env i =
let client_of_interfaces env is =
let client_of_method env i m =
[
Line (sprintf "let %s_r x =" m.Method.name);
Line (sprintf "let %s_r x =" (escape_keywords m.Method.name));
Block [
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));
Line "RPC.rpc call >>= fun response ->";
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));
Line "return result";
];
Line (sprintf "let %s %s =" m.Method.name (String.concat " " (List.map (fun i -> sprintf "~%s" i.Arg.name) m.Method.inputs)));
Line (sprintf "let %s %s =" (escape_keywords m.Method.name) (String.concat " " (List.map (fun i -> sprintf "~%s" i.Arg.name) m.Method.inputs)));
Block [
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)));
Line (sprintf "%s_r r" m.Method.name);
Line (sprintf "%s_r r" (escape_keywords m.Method.name));
]
] in
let client_of_interface env i =
Expand Down
21 changes: 15 additions & 6 deletions generator/src/python.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ let rec lines_of_t t =

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

(* generate a fresh id *)
let fresh_id =
let counter = ref 0 in
fun () ->
incr counter;
"tmp_" ^ (string_of_int !counter)

(** [typecheck ty v] returns a python fragment which checks
[v] has type [ty] *)
let rec typecheck env ty v =
Expand Down Expand Up @@ -47,20 +54,22 @@ let rec typecheck env ty v =
] in
(member true hd) @ (List.concat (List.map (member false) tl))
| Array t ->
let id = fresh_id () in
[
Line (sprintf "if type(%s) <> type([]):" v);
Block [ raise_type_error ];
Line (sprintf "for x in %s:" v);
Block (typecheck env t "x")
Line (sprintf "for %s in %s:" id v);
Block (typecheck env t id)
]
| Dict (key, va) ->
let id = fresh_id () in
[
Line (sprintf "if type(%s) <> type({}):" v);
Block [ raise_type_error ];
Line (sprintf "for x in %s.keys():" v);
Block (typecheck env (Basic key) "x");
Line (sprintf "for x in %s.values():" v);
Block (typecheck env va "x")
Line (sprintf "for %s in %s.keys():" id v);
Block (typecheck env (Basic key) id);
Line (sprintf "for %s in %s.values():" id v);
Block (typecheck env va id)
]
| Name x ->
let ident =
Expand Down
3 changes: 3 additions & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ install: build
.PHONY: uninstall
uninstall:
echo "I don't know how to uninstall python code"

.PHONY: reinstall
reinstall: install

0 comments on commit 7ff43a0

Please sign in to comment.