From b3412920f0c1cce6d92134b998aac3f3eb8d7c4b Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Fri, 29 Apr 2016 14:53:03 +0100 Subject: [PATCH 01/16] CP-17113 First steps toward richer control language (JSON based) The reaction of the kernel can now be controlled by a JSON object that describes how the kernel reacts to messages and how it acknowledges them. Parsing the JSON object is now in place but reactions are not yet implemented. Signed-off-by: Christian Lindig --- src/Makefile | 3 +- src/_tags | 1 + src/commands.mli | 28 +++++++++--------- src/commands.mll | 57 ------------------------------------- src/mirage_vm.ml | 74 ++++++++++++++++++++++++++++++++---------------- 5 files changed, 67 insertions(+), 96 deletions(-) delete mode 100644 src/commands.mll diff --git a/src/Makefile b/src/Makefile index 6a7ec3f..b417346 100644 --- a/src/Makefile +++ b/src/Makefile @@ -14,12 +14,13 @@ OCB = ocamlbuild -use-ocamlfind $(OCBOPTS) all: $(OCB) main.native.o ld -d -static -nostdlib $(LIBS) -o $(VM) - gzip $(VM) + gzip -f $(VM) LIBS += _build/main.native.o LIBS += -L$(OPAMLIB) LIBS += -L$(OPAMLIB)/minios-xen LIBS += -L$(OPAMLIB)/io-page +LIBS += -L$(OPAMLIB)/yojson LIBS += $(OPAMLIB)/mirage-xen/libxencamlbindings.a LIBS += $(OPAMLIB)/mirage-xen-ocaml/libxenasmrun.a LIBS += $(OPAMLIB)/mirage-xen-ocaml/libxenotherlibs.a diff --git a/src/_tags b/src/_tags index 9011e88..df6ced2 100644 --- a/src/_tags +++ b/src/_tags @@ -1,6 +1,7 @@ true: package(functoria.runtime) true: package(mirage-bootvar) true: package(mirage-console.xen) +true: package(yojson) # true: package(mirage-types.lwt) # true: package(mirage-xen) diff --git a/src/commands.mli b/src/commands.mli index e27945b..18954ad 100644 --- a/src/commands.mli +++ b/src/commands.mli @@ -1,7 +1,8 @@ exception Error of string -type shutdown = +(** actions a guest can take *) +type action = | Suspend | PowerOff | Reboot @@ -9,21 +10,22 @@ type shutdown = | Crash | Ignore -type testing = - | Now of shutdown - | Next of shutdown +(** how is a control message from the host acknowledged by the guest *) +type ack = + | AckOK (* ack by putting empty string *) + | AckWrite of string (* ack by putting string *) + | AckNone (* don't ack *) + | AckDelete (* delete key /control/shutdown *) + +(** message to a guest *) +type message = + | Now of action + | OnShutdown of ack * action module Scan : sig - val shutdown: string -> shutdown - val testing: string -> testing + val shutdown: string -> action (* control/shutdown *) + val message: string -> message (* control/testing - in JSON *) end -(** module [String] provides functions to turn commands back into - * strings - *) - module String : sig - val shutdown: shutdown -> string - val testing: testing -> string -end diff --git a/src/commands.mll b/src/commands.mll deleted file mode 100644 index 2b1296f..0000000 --- a/src/commands.mll +++ /dev/null @@ -1,57 +0,0 @@ -(** This module implements recognizers for commands and maps them from - * strings to a more abstract data type - *) - -{ - module L = Lexing - exception Error of string - - type shutdown = - | Suspend - | PowerOff - | Reboot - | Halt - | Crash - | Ignore - - type testing = - | Now of shutdown - | Next of shutdown -} - - rule shutdown = parse - | "suspend" { Suspend } - | "poweroff" { PowerOff } - | "reboot" { Reboot } - | "halt" { Halt } - | "crash" { Crash } - | "ignore" { Ignore } - | _ { raise (Error "unknown shutdown command") } - - and testing = parse - | "now:" { Now(shutdown lexbuf) } - | "next:" { Next(shutdown lexbuf) } - | _ { raise (Error "unknown side channel command") } - -{ - - module Scan = struct - let shutdown str = shutdown (L.from_string str) - let testing str = testing (L.from_string str) - end - - module String = struct - let shutdown = function - | Suspend -> "suspend" - | PowerOff -> "poweroff" - | Reboot -> "reboot" - | Halt -> "halt" - | Crash -> "crash" - | Ignore -> "ignore" - - let testing = function - | Now(msg) -> Printf.sprintf "now:%s" (shutdown msg) - | Next(msg) -> Printf.sprintf "next:%s" (shutdown msg) - end -} - diff --git a/src/mirage_vm.ml b/src/mirage_vm.ml index 4a8a884..6654778 100644 --- a/src/mirage_vm.ml +++ b/src/mirage_vm.ml @@ -27,9 +27,18 @@ module Main (C: V1_LWT.CONSOLE) = struct * formatting instructions. *) let log c fmt = Printf.kprintf (fun msg -> C.log_s c msg) fmt - + let ack' client path = XS.(immediate client @@ fun h -> write h path "") let read client path = XS.(immediate client @@ fun h -> read h path) - let ack client path = XS.(immediate client @@ fun h -> write h path "") + + (* [ack] acknowledges a message and offers to violate the proper + * protocol (AckOK) by doing something else *) + + let ack client path = function + | CMD.AckOK -> XS.(immediate client @@ fun h -> write h path "") + | CMD.AckWrite(x) -> XS.(immediate client @@ fun h -> write h path x ) + | CMD.AckNone -> return () (* do nothing *) + | CMD.AckDelete -> XS.(immediate client @@ fun h -> rm h path) + (* [read_opt client path] reads [path] from the Xen Store and * returns it as an option value on success, and [None] otherwise. @@ -46,6 +55,22 @@ module Main (C: V1_LWT.CONSOLE) = struct | ex -> Lwt.fail ex ) + type cmd = + | Cmd of Commands.message + | CmdError of string + | CmdNone + + let read_cmd client path = + read_opt client path >>= function + | None -> return CmdNone + | Some "" -> return CmdNone + | Some msg -> + Lwt.catch + (fun () -> return @@ Cmd (Commands.Scan.message msg)) + (function + | CMD.Error msg -> return @@ CmdError(msg) + | x -> return @@ CmdError("what happened?") + ) let sleep secs = OS.Time.sleep secs @@ -71,39 +96,38 @@ module Main (C: V1_LWT.CONSOLE) = struct let rec loop tick override = (* read control messages, honor override if present *) read_opt client control_shutdown >>= fun msg -> + ack' client control_shutdown >>= fun () -> ( match msg, override with - | Some "" , _ -> return false - | Some _ , Some override -> - ack client control_shutdown >>= fun () -> - dispatch override >>= fun _ -> - loop (tick+1) None (* clear override *) - | Some msg, None -> - ack client control_shutdown >>= fun () -> - dispatch (CMD.Scan.shutdown msg) - | None , _ -> + | Some "" , _ -> return false + | None , _ -> return false + | Some "suspend", _ -> suspend () + | Some "poweroff", _-> poweroff () + | Some "reboot", _ -> reboot () + | Some "halt",_ -> halt () + | Some "crash",_ -> crash () + | Some x,_ -> + log c "unknown shutdown reason %s" x >>= fun () -> return false ) >>= fun x -> - (* read out-of band test messages like now:reboot or - * next:reboot and register it as an override + (* read command and store in override *) - read_opt client control_testing >>= - ( function - | Some "" -> return x - | Some msg -> - ack client control_testing >>= fun () -> - ( match CMD.Scan.testing msg with - | CMD.Now(shutdown) -> dispatch shutdown - | CMD.Next(override) -> loop (tick+1) (Some override) - ) - | None -> return x + read_cmd client control_testing >>= fun msg -> + ack' client control_testing >>= fun () -> + ( match msg with + | CmdNone -> return x + | Cmd cmd -> + log c "received testing command" >>= fun () -> + loop (tick+1) (Some cmd) + | CmdError msg -> + log c "received bogus command: %s" msg >>= fun () -> + return x ) >>= fun _ -> (* just some reporting *) sleep 1.0 >>= fun x -> read client "domid" >>= fun domid -> log c "domain %s tick %d" domid tick >>= fun () -> ( match override with - | Some cmd -> log c "override %s is active" - (CMD.String.shutdown cmd) >>= fun _ -> return x + | Some cmd -> log c "override is active" >>= fun _ -> return x | None -> return x ) >>= fun _ -> loop (tick+1) override From bd364ebf076f6ef5cfbbb60d3f5bedc34b1f90eb Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Fri, 29 Apr 2016 15:34:04 +0100 Subject: [PATCH 02/16] CP-17113 Added dependency to Dockerfile: yojson Signed-off-by: Christian Lindig --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index b51a2aa..50d61c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ RUN opam install -q -y mirage-xen RUN opam install -q -y mirage-console RUN opam install -q -y mirage-bootvar-xen RUN opam install -q -y mirage +RUN opam install -q -y yojson ENTRYPOINT [ "opam", "config", "exec", "--" ] CMD [ "bash" ] From 319569d4ad2f56d06f504832f42c55927f4b5558 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Fri, 29 Apr 2016 17:07:47 +0100 Subject: [PATCH 03/16] CP-17113 JSON messages are now interpreted Not all behaviour is fully tested yet. The kernel receives a JSON message that tells it to * either do something immediately * do something when the next control message arrives and how to acknowledge that message Currently the message is passed to the kernel via Xen Store. Signed-off-by: Christian Lindig --- setup.sh | 1 + src/commands.mli | 9 ++-- src/mirage_vm.ml | 108 ++++++++++++++++++++++++++--------------------- 3 files changed, 65 insertions(+), 53 deletions(-) diff --git a/setup.sh b/setup.sh index ed2713c..e732f06 100755 --- a/setup.sh +++ b/setup.sh @@ -11,3 +11,4 @@ opam install -q -y mirage-xen opam install -q -y mirage-console opam install -q -y mirage-bootvar-xen opam install -q -y mirage +opam install -q -y yojson diff --git a/src/commands.mli b/src/commands.mli index 18954ad..f6b5337 100644 --- a/src/commands.mli +++ b/src/commands.mli @@ -18,14 +18,13 @@ type ack = | AckDelete (* delete key /control/shutdown *) (** message to a guest *) -type message = +type t = | Now of action | OnShutdown of ack * action -module Scan : sig - val shutdown: string -> action (* control/shutdown *) - val message: string -> message (* control/testing - in JSON *) -end +(** [from_string str] reads a JSON object [str] and returns a [t] + * value that represens it *) +val from_string: string -> t (* Error *) diff --git a/src/mirage_vm.ml b/src/mirage_vm.ml index 6654778..40ddceb 100644 --- a/src/mirage_vm.ml +++ b/src/mirage_vm.ml @@ -42,43 +42,46 @@ module Main (C: V1_LWT.CONSOLE) = struct (* [read_opt client path] reads [path] from the Xen Store and * returns it as an option value on success, and [None] otherwise. - * Unexpected errors still raise an exception. + * A empty string is returned as [None] (and thus conflates + * no string and the empty string). Unexpected errors still raise an + * exception. *) let read_opt client path = Lwt.catch ( fun () -> - read client path >>= fun msg -> - return (Some msg) + read client path >>= + ( function + | "" -> return None (* XXX right design choice? *) + | msg -> return (Some msg) + ) ) ( function | Xs_protocol.Enoent _ -> return None | ex -> Lwt.fail ex ) - type cmd = - | Cmd of Commands.message - | CmdError of string - | CmdNone - - let read_cmd client path = + (** [read_cmd] reads a command in JSON format from [path] and + * returns it, or [None] when nothing is there *) + let read_cmd c client path = read_opt client path >>= function - | None -> return CmdNone - | Some "" -> return CmdNone + | None -> return None | Some msg -> + ack' client path >>= fun () -> Lwt.catch - (fun () -> return @@ Cmd (Commands.Scan.message msg)) + (fun () -> return @@ Some (Commands.from_string msg)) (function - | CMD.Error msg -> return @@ CmdError(msg) - | x -> return @@ CmdError("what happened?") + | CMD.Error msg -> + log c "bogus command %s" msg >>= fun () -> return None + | x -> Lwt.fail x ) let sleep secs = OS.Time.sleep secs let suspend () = OS.Sched.suspend () >>= fun _ -> return true - let poweroff () = OS.Sched.(shutdown Poweroff); return false - let reboot () = OS.Sched.(shutdown Reboot); return false - let halt () = OS.Sched.(shutdown Poweroff); return false - let crash () = OS.Sched.(shutdown Crash); return false + let poweroff () = OS.Sched.(shutdown Poweroff); return true + let reboot () = OS.Sched.(shutdown Reboot); return true + let halt () = OS.Sched.(shutdown Poweroff); return true + let crash () = OS.Sched.(shutdown Crash); return true (** [dispatch] implements the reaction to control messages *) let dispatch = function @@ -93,44 +96,53 @@ module Main (C: V1_LWT.CONSOLE) = struct (* event loop *) let start c = OS.Xs.make () >>= fun client -> - let rec loop tick override = - (* read control messages, honor override if present *) + let rec loop tick cmd = read_opt client control_shutdown >>= fun msg -> - ack' client control_shutdown >>= fun () -> - ( match msg, override with - | Some "" , _ -> return false - | None , _ -> return false - | Some "suspend", _ -> suspend () - | Some "poweroff", _-> poweroff () - | Some "reboot", _ -> reboot () - | Some "halt",_ -> halt () - | Some "crash",_ -> crash () - | Some x,_ -> - log c "unknown shutdown reason %s" x >>= fun () -> - return false - ) >>= fun x -> - (* read command and store in override - *) - read_cmd client control_testing >>= fun msg -> - ack' client control_testing >>= fun () -> + ( match cmd, msg with + + (* no testing command present, regular kernel behaviour *) + | None, None -> return true + | None, Some msg -> + ack' client control_shutdown >>= fun () -> ( match msg with - | CmdNone -> return x - | Cmd cmd -> - log c "received testing command" >>= fun () -> - loop (tick+1) (Some cmd) - | CmdError msg -> - log c "received bogus command: %s" msg >>= fun () -> - return x + | "suspend" -> suspend () + | "poweroff" -> poweroff () + | "reboot" -> reboot () + | "halt" -> halt () + | "crash" -> crash () + | x -> log c "unknown shutdown reason %s" x + >>= fun () -> return true + ) + + (* we have a command to execute and to remove it for the + * next iteration of the loop *) + | Some(CMD.Now(action)), _ -> + dispatch action >>= fun _ -> loop (tick+1) None + | Some(CMD.OnShutdown(a, action)), Some _ -> + ack client control_shutdown a >>= fun () -> + dispatch action >>= fun _ -> loop (tick+1) None + | Some(CMD.OnShutdown(_, _)), None -> + return true (* not yet - wait for shutdown message *) + ) >>= fun x -> + + (* read command, ack it, and store it for execution *) + read_cmd c client control_testing >>= + ( function + | Some cmd -> loop (tick+1) (Some cmd) + | None -> return x ) >>= fun _ -> - (* just some reporting *) + + (* report the current state *) sleep 1.0 >>= fun x -> read client "domid" >>= fun domid -> log c "domain %s tick %d" domid tick >>= fun () -> - ( match override with - | Some cmd -> log c "override is active" >>= fun _ -> return x + ( match cmd with + | Some _ -> log c "command is active" >>= fun _ -> return x | None -> return x ) >>= fun _ -> - loop (tick+1) override + + (* loop *) + loop (tick+1) cmd in loop 0 None end From dbafcee6fc134806764505cf3923ec163e1d2088 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Fri, 29 Apr 2016 18:23:03 +0100 Subject: [PATCH 04/16] CP-17113 Adding missing file: commands.ml Signed-off-by: Christian Lindig --- src/commands.ml | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/commands.ml diff --git a/src/commands.ml b/src/commands.ml new file mode 100644 index 0000000..0b8b09a --- /dev/null +++ b/src/commands.ml @@ -0,0 +1,62 @@ +(* vim: set et sw=2 ts=2 *) + +module Y = Yojson.Basic +module U = Yojson.Basic.Util + +exception Error of string +let error fmt = Printf.ksprintf (fun msg -> raise (Error msg)) fmt + +(** actions a guest can take *) +type action = + | Suspend + | PowerOff + | Reboot + | Halt + | Crash + | Ignore + +(** how is a control message from the host acknowledged by the guest *) +type ack = + | AckOK (* ack by putting empty string *) + | AckWrite of string (* ack by putting string *) + | AckNone (* don't ack *) + | AckDelete (* delete key /control/shutdown *) + +(** message to a guest *) +type t = + | Now of action + | OnShutdown of ack * action + +let action = function + | "suspend" -> Suspend + | "poweroff" -> PowerOff + | "reboot" -> Reboot + | "halt" -> Halt + | "crash" -> Crash + | "ignore" -> Ignore + | x -> error "unknown action: %s" x + +let do_when ack action = function + | "now" -> Now(action) + | "onshutdown"-> OnShutdown(ack, action) + | x -> error "unknown when: %s" x + +let ack = function + | "ok" -> AckOK + | "none" -> AckNone + | "delete" -> AckDelete + | x -> AckWrite(x) + +let from_string str = + try + let json = Y.from_string str in + let ack' = json |> U.member "ack" |> U.to_string |> ack in + let action' = json |> U.member "action" |> U.to_string |> action in + json + |> U.member "when" + |> U.to_string + |> do_when ack' action' + with + Yojson.Json_error msg -> error "bad json: %s" msg + + From 55c5c2c7993b9714c434277d97436eb1036ecfa5 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Sun, 1 May 2016 12:06:01 +0100 Subject: [PATCH 05/16] CP-17113 Updated README; explains new JSON interface Signed-off-by: Christian Lindig --- README.md | 93 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 9297751..ff6fe6b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ + + [![Build Status](https://travis-ci.org/xapi-project/xen-test-vm.svg?branch=master)](https://travis-ci.org/xapi-project/xen-test-vm) # Xen Test VM @@ -8,24 +10,20 @@ using the Mirage unikernel framework. # Binary Releases -Binary releases are hosted on +Binary releases are hosted on [GitHub](https://github.com/xapi-project/xen-test-vm/releases) as -`xen-test.vm.gz`. The uncompressed file is the kernel that needs to be -installed. You could use the following code in a script: +`xen-test.vm.gz`. -```sh -VERSION="0.0.5" -NAME="xen-test-vm-$VERSION" -GH="https://github.com/xapi-project" -VM="$GH/xen-test-vm/releases/download/$VERSION/test-vm.xen.gz" -KERNEL="xen-test-vm-${VERSION//./-}.xen.gz" + VERSION="0.0.5" + GH="https://github.com/xapi-project" + VM="$GH/xen-test-vm/releases/download/$VERSION/test-vm.xen.gz" + KERNEL="xen-test-vm-${VERSION//./-}.xen.gz" -curl --fail -s -L "$VM" > "$KERNEL" -``` + curl --fail -s -L "$VM" > "$KERNEL" # Installing the VM -The VM is built as `src/test-vm.xen` and available as binary +The VM is built as `src/test-vm.xen.gz` and available as binary release. The file goes into `/boot/guest` on a host: HOST=host @@ -50,8 +48,8 @@ now, this requires to install the dependencies manually. Apart from that, calling `make` will build `src/test-vm.xen` - ./setup.sh # executes opam installations - make + ./setup.sh # executes opam installations + make A `Dockerfile` can be used to create a Docker container environment for compiling the VM. It is used for building on Travis. @@ -64,13 +62,13 @@ The VM is built on Travis using the [Dockerfile](./Dockerfile) - see the # Out-of-Band Control Messages -The kernel reads control messages from the Xen Store from -"control/shutdown" and responds to them. In addition, it reads from -"control/testing". +In addition to the shutdown messages sent by Xen, the kernel monitors +the Xen Store for messages. These are used to control the response to +shutdown messages. ## Shutdown Messages -The kernel responds to these messages in the "control/shutdown". Usually +The kernel responds to these messages in "control/shutdown". Usually the hypervisor only sends these. suspend @@ -78,37 +76,51 @@ the hypervisor only sends these. reboot halt crash - ignore + +All other messages are logged and ignored. ## Testing Messages -The kernel reads messages in "control/testing". Legal messages are: +The kernel reads messages in "control/testing". It acknowledges a +message by replacing the read message with the empty string. + +A message in "control/testing" is a JSON object: - now:suspend - now:poweroff - now:reboot - now:halt - now:crash - now:ignore + { "when": "now" // when to react + , "ack": "ok" // how to ack control/shutdown + , "action": "reboot" // how to react to control/shutdown + } -Each makes the kernel respond to these immediately. In addition, these -messages are legal: +Note that proper JSON does not permit _//_-style comments. The message +describes three aspects: - next:suspend - next:poweroff - next:reboot - next:halt - next:crash - next:ignore +1. `"when"`: either `"now"` or `"onshutdown"`. The kernel will either + immediately or when then next shutdown message arrives perform the + `"action"`. -The next time the kernel receives a shutdown message, it ignores the -message it received and acts on the next:message instead. This permits -to surprise the hypervisor. +2. `"ack"`: either `"ok"`, `"none"`, `"delete"`, or something else. This + controls, how the kernel acknowledges the next shutdown message. + * `"ok"`: regular behavior + * `"none"`: don't acknowledge the message + * `"delete"`: delete "control/shutdown" + * `"something"`: write the string read to "control/shutdown" -Typically, control/shutdown is written only by Xen. To write to -control/testing, use: +3. `"action"`: what do do (eiter now or on shutdown). The message in + `control/shutdown` is ignored and superseeded by the `action` field: + * `"suspend"`: suspend + * `"poweroff"`: power off + * `"reboot"`: reboot + * `"halt"`: halt + * `"crash"`: crash + * `"ignore"`: do nothing - ignore the message - xenstore write /local/domain//control/testing now:reboot +To write to `control/testing`, use: + + msg='{"when":"now","ack":"ok","action":"reboot"}' + xenstore write /local/domain//control/testing "$msg" + +The _domid_ is logged to the console and can be obtained through the Xen +API. # Debugging the VM @@ -118,4 +130,3 @@ To direct console output of the VM to a file, you can tell the $HOST: Output then goes to `/tmp/console.`. - From a1b67dfe18dff77e94611a197300dd5f358f25b6 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Tue, 3 May 2016 10:36:18 +0100 Subject: [PATCH 06/16] CP-17113 Pin cstuct package to fix build Signed-off-by: Christian Lindig --- Dockerfile | 2 ++ setup.sh | 1 + src/Makefile | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 50d61c5..1f43cd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,8 @@ RUN opam pin add -n -y mirage-bootvar-xen \ git://github.com/jonludlam/mirage-bootvar-xen#better-parser RUN opam pin add -n -y minios-xen \ git://github.com/jonludlam/mini-os#suspend-resume3 + +RUN opam pin add -n -y cstruct 1.9.0 RUN opam install -q -y mirage-xen RUN opam install -q -y mirage-console RUN opam install -q -y mirage-bootvar-xen diff --git a/setup.sh b/setup.sh index e732f06..7d2abad 100755 --- a/setup.sh +++ b/setup.sh @@ -6,6 +6,7 @@ opam pin add -n -y mirage-bootvar-xen git://github.com/jonludlam/mirage-bootvar- opam pin add -n -y minios-xen git://github.com/jonludlam/mini-os#suspend-resume3 +opam pin add -n -y cstruct 1.9.0 opam install -q -y mirage-xen opam install -q -y mirage-console diff --git a/src/Makefile b/src/Makefile index b417346..b21a0a6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -20,7 +20,7 @@ LIBS += _build/main.native.o LIBS += -L$(OPAMLIB) LIBS += -L$(OPAMLIB)/minios-xen LIBS += -L$(OPAMLIB)/io-page -LIBS += -L$(OPAMLIB)/yojson +# LIBS += -L$(OPAMLIB)/yojson LIBS += $(OPAMLIB)/mirage-xen/libxencamlbindings.a LIBS += $(OPAMLIB)/mirage-xen-ocaml/libxenasmrun.a LIBS += $(OPAMLIB)/mirage-xen-ocaml/libxenotherlibs.a From d143707472a075c266a418f48c4295f4d06b6151 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Tue, 3 May 2016 14:15:32 +0100 Subject: [PATCH 07/16] CP-17113 Enable deployment from Travis to GitHub from forked repo So far, Travis would only deploy a binary to GitHub when buiding for the xapi-project account. Now it deploys also when building for another account. The binary is deployed to the GitHub repo that it is building, which is not xapi-project in that case. Signed-off-by: Christian Lindig --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 17fbf88..7231346 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,5 +26,5 @@ deploy: file: src/test-vm.xen.gz skip_cleanup: true on: - repo: xapi-project/xen-test-vm + # repo: xapi-project/xen-test-vm tags: true From 592a42d0f84432e97325f7430764c1d1b6f1302b Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Wed, 4 May 2016 00:21:20 +0100 Subject: [PATCH 08/16] CP-17113 Opam now describes dependencies, can be used for building Signed-off-by: Christian Lindig --- .travis.yml | 22 ++++++++-------------- Dockerfile | 8 -------- Makefile | 28 ++++++++++++---------------- README.md | 13 +++---------- descr | 4 ---- opam | 24 ------------------------ opam/descr | 6 ++++++ opam/opam | 23 +++++++++++++++++++++++ setup.sh | 15 --------------- 9 files changed, 52 insertions(+), 91 deletions(-) delete mode 100644 descr delete mode 100644 opam create mode 100644 opam/descr create mode 100644 opam/opam delete mode 100755 setup.sh diff --git a/.travis.yml b/.travis.yml index 7231346..c6aa327 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,12 @@ -os: -- linux -sudo: required language: c -services: -- docker -before_install: -- docker build -t ring3/ocaml . -- docker images -- rvm use ruby-2.2.3 -script: -- chmod -R o+w src/ -- docker run -t -t -v $PWD:/mnt ring3/ocaml make -C /mnt -- sudo chown travis.travis src/test-vm.xen.gz -- ls -lh src/ +sudo: required +install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh +env: + - OCAML_VERSION=4.02 PACKAGE="xen-test-vm" +os: + - linux +script: + - bash -ex .travis-opam.sh deploy: provider: releases api_key: diff --git a/Dockerfile b/Dockerfile index 1f43cd6..8852442 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,14 +14,6 @@ USER opam ENV HOME /home/opam WORKDIR /home/opam -RUN opam pin add -n -y mirage-xen \ - git://github.com/jonludlam/mirage-platform#reenable-suspend-resume -RUN opam pin add -n -y mirage-bootvar-xen \ - git://github.com/jonludlam/mirage-bootvar-xen#better-parser -RUN opam pin add -n -y minios-xen \ - git://github.com/jonludlam/mini-os#suspend-resume3 - -RUN opam pin add -n -y cstruct 1.9.0 RUN opam install -q -y mirage-xen RUN opam install -q -y mirage-console RUN opam install -q -y mirage-bootvar-xen diff --git a/Makefile b/Makefile index ed1ba33..1ecfc4d 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,26 @@ -# vim:ft=make ts=8: +# vim: set ft=make ts=8: # -# - -HOST = "root@dt87" +PACKAGE = xen-test-vm +PREFIX = . +LIB = $(PREFIX)/$(PACKAGE)/lib +VM = src/test-vm.xen.gz all: src $(MAKE) -C src/ all - ls -lh src/test-vm.xen.gz + ls -lh $(VM) - -install: all - ssh $(HOST) "test -d /boot/guest || mkdir /boot/guest" - ssh $(HOST) "cd /boot/guest; rm -f test-vm.xen" - scp src/test-vm.xen.gz $(HOST):/boot/guest +install: + mkdir -p $(LIB) + cp $(VM) $(LIB) remove: - true - + rm -f $(lib)/$(VM) + clean: $(MAKE) -C src clean -release: opam descr - - -.PHONY: all clean install release +.PHONY: all clean install release diff --git a/README.md b/README.md index ff6fe6b..84e696c 100644 --- a/README.md +++ b/README.md @@ -42,17 +42,10 @@ XenCenter. # Building from Source Code -The code relies on some pinned OCaml packages in Opam. This dependency -cannot be expressed naturally in the depends section of an `opam` file. For -now, this requires to install the dependencies manually. Apart from that, -calling `make` will build `src/test-vm.xen` + opam pin add xen-test-vm . + opam install xen-test-vm - - ./setup.sh # executes opam installations - make - -A `Dockerfile` can be used to create a Docker container environment for -compiling the VM. It is used for building on Travis. +Watch the output for where the kernel gets installed. # Travis CI diff --git a/descr b/descr deleted file mode 100644 index c75a668..0000000 --- a/descr +++ /dev/null @@ -1,4 +0,0 @@ -xen-test-vm - minimal VM kernel for testing Xen - -This code builds a minimal kernel (or VM) that can be run on a Xen -hypervisor for exercising tests. diff --git a/opam b/opam deleted file mode 100644 index b414ea5..0000000 --- a/opam +++ /dev/null @@ -1,24 +0,0 @@ -# -# This opem file currently does NOT reflect dependencies correctly -# as we cannot express directly a dependency on a pinned package. -# - -opam-version: "1.2" -name: "xen-test-vm" -version: "0.1" -maintainer: "Christian Lindig -authors: "Christian Lindig " -build: [ - [make] -] -install: [make "PREFIX=%{prefix}%" "install"] -remove: [make "PREFIX=%{prefix}%" "remove"] -available: [ ocaml-version >= "4.02.3" ] - -depends: [ - "mirage-xen" - "mirage-console" - "mirage-bootvar-xen" - "mirage" -] - diff --git a/opam/descr b/opam/descr new file mode 100644 index 0000000..b34ae69 --- /dev/null +++ b/opam/descr @@ -0,0 +1,6 @@ +xen-test-vm - minimal VM kernel for testing Xen + +This code builds a minimal kernel (or VM) that can be run on a Xen +hypervisor for exercising tests. The behaviour of the kernel can be +controlled with a JSON record that can be passed to the kernel via the +XenStore. diff --git a/opam/opam b/opam/opam new file mode 100644 index 0000000..4d7994a --- /dev/null +++ b/opam/opam @@ -0,0 +1,23 @@ +opam-version: "1.2" +name: "xen-test-vm" +version: "0.2" +maintainer: "Christian Lindig " +authors: "Christian Lindig " +build: [ + [make] +] +install: [ + make "PREFIX=%{prefix}%" "install" +] +remove: [ + make "PREFIX=%{prefix}%" "remove" +] + +depends: [ + "mirage-xen" + "mirage-console" + "mirage-bootvar-xen" + "mirage" + "yojson" +] + diff --git a/setup.sh b/setup.sh deleted file mode 100755 index 7d2abad..0000000 --- a/setup.sh +++ /dev/null @@ -1,15 +0,0 @@ -#! /bin/sh - -opam pin add -n -y mirage-xen git://github.com/jonludlam/mirage-platform#reenable-suspend-resume - -opam pin add -n -y mirage-bootvar-xen git://github.com/jonludlam/mirage-bootvar-xen#better-parser - -opam pin add -n -y minios-xen git://github.com/jonludlam/mini-os#suspend-resume3 - -opam pin add -n -y cstruct 1.9.0 - -opam install -q -y mirage-xen -opam install -q -y mirage-console -opam install -q -y mirage-bootvar-xen -opam install -q -y mirage -opam install -q -y yojson From f82fb4d13523614e0e179f8405b8df66ca7ba5c2 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Wed, 4 May 2016 08:39:22 +0100 Subject: [PATCH 09/16] CP-17113 Amended opam file with dev-repo, homepage, bug-reports This information is going to change in the long run but we need it to use the OCaml .travis that checks for them. Signed-off-by: Christian Lindig --- opam/opam | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opam/opam b/opam/opam index 4d7994a..662d507 100644 --- a/opam/opam +++ b/opam/opam @@ -12,7 +12,11 @@ install: [ remove: [ make "PREFIX=%{prefix}%" "remove" ] +homepage: "https://github.com/lindig/xen-test-vm" +dev-repo: "https://github.com/lindig/xen-test-vm" +bug-reports: "https://github.com/lindig/xen-test-vm" +bug-reports: depends: [ "mirage-xen" "mirage-console" From 010e4a6ccf397f9fd9663da4ae9882af0e67986a Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Wed, 4 May 2016 08:49:56 +0100 Subject: [PATCH 10/16] CP-17113 Fixed typo in opam file Signed-off-by: Christian Lindig --- README.md | 9 +++++++-- opam/opam | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 84e696c..892c569 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,15 @@ XenCenter. # Building from Source Code +The easiest way is to let opam manage the installation of dependencies: + opam pin add xen-test-vm . - opam install xen-test-vm + opam install -v xen-test-vm + +You can also use the provided Makefile: -Watch the output for where the kernel gets installed. + make + make install # Travis CI diff --git a/opam/opam b/opam/opam index 662d507..391786b 100644 --- a/opam/opam +++ b/opam/opam @@ -16,7 +16,6 @@ homepage: "https://github.com/lindig/xen-test-vm" dev-repo: "https://github.com/lindig/xen-test-vm" bug-reports: "https://github.com/lindig/xen-test-vm" -bug-reports: depends: [ "mirage-xen" "mirage-console" From 78a2ee38dd9cedf45f66439c85dd00a7289cdad2 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Wed, 4 May 2016 09:14:09 +0100 Subject: [PATCH 11/16] CP-17113 Dockerfile out, can now build with opam alone on Travis With no longer using pinned packages we also no longer need to build inside a Docker container but can let opam manage compilation. This leads to a vastly simpler .travis. Signed-off-by: Christian Lindig --- Dockerfile | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 8852442..0000000 --- a/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# -# - -FROM ocaml/opam:debian-9_ocaml-4.02.3 -LABEL distro_style="apt" -LABEL distro="debian" -LABEL distro_long="debian-9" -LABEL arch="x86_64" -LABEL ocaml_version="4.02.3" -LABEL opam_version="1.2.2" -LABEL operatingsystem="linux" - -USER opam -ENV HOME /home/opam -WORKDIR /home/opam - -RUN opam install -q -y mirage-xen -RUN opam install -q -y mirage-console -RUN opam install -q -y mirage-bootvar-xen -RUN opam install -q -y mirage -RUN opam install -q -y yojson - -ENTRYPOINT [ "opam", "config", "exec", "--" ] -CMD [ "bash" ] From 3c7905f0ef1b9fe2fee8181cb0a9b6cb176fe4c8 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Wed, 4 May 2016 09:32:32 +0100 Subject: [PATCH 12/16] CP-17113 Fixing deployment step in .travis.yml Signed-off-by: Christian Lindig --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index c6aa327..6edef5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,4 +21,5 @@ deploy: skip_cleanup: true on: # repo: xapi-project/xen-test-vm + repo: lindig/xen-test-vm tags: true From 3e6f8d8e400179aa7813c3041f83daeb9318e0af Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Wed, 4 May 2016 14:24:56 +0100 Subject: [PATCH 13/16] P-17113 back to using pins and Docker I was wrong about not needing the pins. I had overlooked that my packages were still pinned and while code compiles withou pinned packages, it does not implement suspend() correctly. Signed-off-by: Christian Lindig --- .travis.yml | 25 +++++++++++++++---------- Dockerfile | 31 +++++++++++++++++++++++++++++++ README.md | 15 +++++++++++---- 3 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 Dockerfile diff --git a/.travis.yml b/.travis.yml index 6edef5f..17fbf88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,18 @@ -language: c -sudo: required -install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh -env: - - OCAML_VERSION=4.02 PACKAGE="xen-test-vm" os: - - linux -script: - - bash -ex .travis-opam.sh +- linux +sudo: required +language: c +services: +- docker +before_install: +- docker build -t ring3/ocaml . +- docker images +- rvm use ruby-2.2.3 +script: +- chmod -R o+w src/ +- docker run -t -t -v $PWD:/mnt ring3/ocaml make -C /mnt +- sudo chown travis.travis src/test-vm.xen.gz +- ls -lh src/ deploy: provider: releases api_key: @@ -20,6 +26,5 @@ deploy: file: src/test-vm.xen.gz skip_cleanup: true on: - # repo: xapi-project/xen-test-vm - repo: lindig/xen-test-vm + repo: xapi-project/xen-test-vm tags: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e6a780b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# +# + +FROM ocaml/opam:debian-9_ocaml-4.02.3 +LABEL distro_style="apt" +LABEL distro="debian" +LABEL distro_long="debian-9" +LABEL arch="x86_64" +LABEL ocaml_version="4.02.3" +LABEL opam_version="1.2.2" +LABEL operatingsystem="linux" + +USER opam +ENV HOME /home/opam +WORKDIR /home/opam + +RUN opam pin add -n -y mirage-xen \ + git://github.com/jonludlam/mirage-platform#reenable-suspend-resume +RUN opam pin add -n -y mirage-bootvar-xen \ + git://github.com/jonludlam/mirage-bootvar-xen#better-parser +RUN opam pin add -n -y minios-xen \ + git://github.com/jonludlam/mini-os#suspend-resume3 + +RUN opam pin add -n -y cstruct 1.9.0 +RUN opam install -q -y mirage-xen +RUN opam install -q -y mirage-console +RUN opam install -q -y mirage-bootvar-xen +RUN opam install -q -y mirage + +ENTRYPOINT [ "opam", "config", "exec", "--" ] +CMD [ "bash" ] diff --git a/README.md b/README.md index 892c569..75931ac 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,20 @@ XenCenter. The easiest way is to let opam manage the installation of dependencies: + opam pin add -n -y mirage-xen \ + git://github.com/jonludlam/mirage-platform#reenable-suspend-resume + + opam pin add -n -y mirage-bootvar-xen \ + git://github.com/jonludlam/mirage-bootvar-xen#better-parser + + opam pin add -n -y minios-xen \ + git://github.com/jonludlam/mini-os#suspend-resume3 + + opam pin add -n -y cstruct 1.9.0 + opam pin add xen-test-vm . opam install -v xen-test-vm -You can also use the provided Makefile: - - make - make install # Travis CI From fe61870e22096a8186c38d484c7c510fcc5d681c Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Wed, 4 May 2016 14:33:45 +0100 Subject: [PATCH 14/16] CP-17113 Fixed typo in Makefile for "remove" target. The remove target is called by opam (via opam/opam). Signed-off-by: Christian Lindig --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1ecfc4d..6c5c8ce 100644 --- a/Makefile +++ b/Makefile @@ -10,12 +10,16 @@ all: src $(MAKE) -C src/ all ls -lh $(VM) +package: src + opam pin add -y xen-test-vm . + opam install xen-test-vm + install: mkdir -p $(LIB) cp $(VM) $(LIB) remove: - rm -f $(lib)/$(VM) + rm -f $(LIB)/$(VM) clean: $(MAKE) -C src clean From e983d98d91863ac75b063ac86c73d642303efee3 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Wed, 4 May 2016 14:36:50 +0100 Subject: [PATCH 15/16] CP-17113 Added missing package to Dockerfile: yojson Signed-off-by: Christian Lindig --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index e6a780b..1f43cd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,6 +26,7 @@ RUN opam install -q -y mirage-xen RUN opam install -q -y mirage-console RUN opam install -q -y mirage-bootvar-xen RUN opam install -q -y mirage +RUN opam install -q -y yojson ENTRYPOINT [ "opam", "config", "exec", "--" ] CMD [ "bash" ] From eba4a27f0bcd3339d181308a44cc19a4c3c1b806 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Wed, 4 May 2016 15:00:11 +0100 Subject: [PATCH 16/16] CP-17113 Moved pins forwards, removed on pin Jon Ludlam helped to move pins forward. Signed-off-by: Christian Lindig --- Dockerfile | 3 +-- README.md | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1f43cd6..bb07698 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,13 +15,12 @@ ENV HOME /home/opam WORKDIR /home/opam RUN opam pin add -n -y mirage-xen \ - git://github.com/jonludlam/mirage-platform#reenable-suspend-resume + git://github.com/jonludlam/mirage-platform#reenable-suspend-resume2 RUN opam pin add -n -y mirage-bootvar-xen \ git://github.com/jonludlam/mirage-bootvar-xen#better-parser RUN opam pin add -n -y minios-xen \ git://github.com/jonludlam/mini-os#suspend-resume3 -RUN opam pin add -n -y cstruct 1.9.0 RUN opam install -q -y mirage-xen RUN opam install -q -y mirage-console RUN opam install -q -y mirage-bootvar-xen diff --git a/README.md b/README.md index 75931ac..88c7562 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ XenCenter. The easiest way is to let opam manage the installation of dependencies: opam pin add -n -y mirage-xen \ - git://github.com/jonludlam/mirage-platform#reenable-suspend-resume + git://github.com/jonludlam/mirage-platform#reenable-suspend-resume2 opam pin add -n -y mirage-bootvar-xen \ git://github.com/jonludlam/mirage-bootvar-xen#better-parser @@ -53,8 +53,6 @@ The easiest way is to let opam manage the installation of dependencies: opam pin add -n -y minios-xen \ git://github.com/jonludlam/mini-os#suspend-resume3 - opam pin add -n -y cstruct 1.9.0 - opam pin add xen-test-vm . opam install -v xen-test-vm