new file mode 100644
@@ -0,0 +1,2 @@
+_build
+.merlin
@@ -34,3 +34,36 @@ build-tools-oxenstored:
$(MAKE) -s -C libs/xb
$(MAKE) -s -C libs/xc
$(MAKE) -C xenstored
+
+LIBRARY_PATH=$(XEN_libxenctrl):$(XEN_libxenguest):$(XEN_libxentoollog):$(XEN_libxencall):$(XEN_libxenevtchn):$(XEN_libxenforeignmemory):$(XEN_libxengnttab):$(XEN_libxendevicemodel):$(XEN_libxentoolcore)
+C_INCLUDE_PATH=$(XEN_libxenctrl)/include:$(XEN_libxengnttab)/include:$(XEN_libxenevtchn)/include:$(XEN_libxentoollog)/include:$(XEN_INCLUDE)
+
+# Files generated by the Makefile
+# These cannot be generated from dune, because dune cannot refer to files
+# in the parent directory (so it couldn't copy/use Config.mk)
+.PHONY: dune-pre
+dune-pre:
+ $(MAKE) -s -C ../../ build-tools-public-headers
+ $(MAKE) -s -C libs/xs paths.ml
+ $(MAKE) -s -C libs/xc xenctrl_abi_check.h
+ $(MAKE) -s -C xenstored paths.ml _paths.h
+
+.PHONY: check
+check: dune-pre
+ # --force isn't necessary here if the test is deterministic
+ OCAMLRUNPARAM=b C_INCLUDE_PATH=$(C_INCLUDE_PATH) dune runtest --profile=release --no-buffer --force
+
+# Convenience targets for development
+
+.PHONY: dune-clean
+dune-clean:
+ $(MAKE) clean
+ dune clean
+
+.PHONY: dune-syntax-check
+dune-syntax-check: dune-pre
+ LIBRARY_PATH=$(LIBRARY_PATH) C_INCLUDE_PATH=$(C_INCLUDE_PATH) dune build --profile=release @check
+
+.PHONY: build-oxenstored-dune
+dune-build-oxenstored: dune-pre
+ LD_LIBRARY_PATH=$(LIBRARY_PATH) LIBRARY_PATH=$(LIBRARY_PATH) C_INCLUDE_PATH=$(C_INCLUDE_PATH) dune build --profile=release @all
new file mode 100644
@@ -0,0 +1,5 @@
+(lang dune 2.0)
+
+(name xen)
+
+(formatting disabled)
new file mode 100644
@@ -0,0 +1,8 @@
+(library
+ (foreign_stubs
+ (language c)
+ (names xeneventchn_stubs))
+ (name xeneventchn)
+ (public_name xen.eventchn)
+ (libraries unix)
+ (c_library_flags -lxenevtchn))
new file mode 100644
@@ -0,0 +1,8 @@
+(library
+ (foreign_stubs
+ (language c)
+ (names xenmmap_stubs))
+ (name xenmmap)
+ (public_name xen.mmap)
+ (libraries unix)
+ (install_c_headers mmap_stubs))
new file mode 100644
@@ -0,0 +1,7 @@
+(library
+ (foreign_stubs
+ (language c)
+ (names xenbus_stubs xs_ring_stubs))
+ (name xenbus)
+ (public_name xen.bus)
+ (libraries unix xenmmap))
new file mode 100644
@@ -0,0 +1,9 @@
+(library
+ (foreign_stubs
+ (language c)
+ (names xenctrl_stubs))
+ (name xenctrl)
+ (public_name xen.ctrl)
+ (libraries unix xenmmap)
+ (c_library_flags -lxenctrl -lxenguest -lxencall -lxenforeignmemory
+ -lxengnttab))
new file mode 100644
@@ -0,0 +1,4 @@
+(library
+ (name xenstore)
+ (public_name xen.store)
+ (libraries unix xenbus))
new file mode 100644
new file mode 100644
new file mode 100644
@@ -0,0 +1,18 @@
+opam-version: "2.0"
+synopsis: "In-memory key-value store for the Xen hypervisor"
+maintainer: "lindig@gmail.com"
+authors: "lindig@gmail.com"
+license: "LGPL"
+homepage: "https://github.com/lindig/xen-ocaml-tools"
+bug-reports: "https://github.com/lindig/xen-ocaml-tools/issues"
+depends: [
+ "ocaml"
+ "dune" {build}
+ "base-unix"
+ "crowbar" {with-test}
+ "qcheck-core" {with-test}
+ "qcstm" {with-test}
+]
+build: ["dune" "build" "-p" name "-j" jobs]
+depexts: ["m4" "libxen-dev" "libsystemd-dev"] {os-distribution = "debian"}
+dev-repo: "git+https://github.com/lindig/xen-ocaml-tools.git"
@@ -56,7 +56,8 @@ OBJS = paths \
history \
parse_arg \
process \
- xenstored
+ xenstored \
+ xenstored_main
INTF = symbol.cmi trie.cmi syslog.cmi systemd.cmi poll.cmi
new file mode 100644
@@ -0,0 +1,19 @@
+(executable
+ (modes byte exe)
+ (name xenstored)
+ (modules (:standard \ syslog systemd))
+ (public_name xenstored)
+ (package xenstored)
+ (flags (:standard -w -52))
+ (libraries unix xen.bus xen.mmap xen.ctrl xen.eventchn xenstubs))
+
+(library
+ (foreign_stubs
+ (language c)
+ (names syslog_stubs systemd_stubs select_stubs)
+ (flags (-DHAVE_SYSTEMD)))
+ (modules syslog systemd)
+ (name xenstubs)
+ (wrapped false)
+ (libraries unix)
+ (c_library_flags -lsystemd))
@@ -28,7 +28,7 @@ type config =
disable_socket: bool;
}
-let do_argv =
+let do_argv () =
let pidfile = ref "" and tracefile = ref "" (* old xenstored compatibility *)
and domain_init = ref true
and activate_access_log = ref true
@@ -64,4 +64,5 @@ let poll_select in_fds out_fds exc_fds timeout =
a r
let () =
- set_fd_limit (get_sys_fs_nr_open ())
+ if Unix.geteuid () = 0 then
+ set_fd_limit (get_sys_fs_nr_open ())
new file mode 100644
@@ -0,0 +1,11 @@
+(copy_files# ../*.ml{,i})
+
+(test
+ (modes native)
+ (ocamlopt_flags -afl-instrument)
+ (name xenstored_test)
+ (modules (:standard \ syslog systemd))
+ (package xenstored)
+ (flags (:standard -w -52))
+ ;;(action (run %{test} -v --seed 364172147))
+ (libraries unix xen.bus xen.mmap xenstubs crowbar xen.store fmt fmt.tty))
new file mode 100644
@@ -0,0 +1,48 @@
+(*
+ * Copyright (C) 2006-2007 XenSource Ltd.
+ * Copyright (C) 2008 Citrix Ltd.
+ * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+(** *)
+type domid = int
+
+(* ** xenctrl.h ** *)
+
+
+type domaininfo =
+{
+ domid : domid;
+ dying : bool;
+ shutdown : bool;
+ shutdown_code : int;
+}
+
+exception Error of string
+
+type handle = unit
+
+let interface_open () = ()
+let interface_close () = ()
+
+let domain_getinfo () domid = {
+ domid = domid;
+ dying = false;
+ shutdown = false;
+ shutdown_code = 0;
+}
+
+let devzero = Unix.openfile "/dev/zero" [] 0
+let nullmap () = Xenmmap.mmap devzero Xenmmap.RDWR Xenmmap.PRIVATE 4096 0
+
+let map_foreign_range _ _ _ _ = nullmap ()
new file mode 100644
@@ -0,0 +1,50 @@
+(*
+ * Copyright (C) 2006-2007 XenSource Ltd.
+ * Copyright (C) 2008 Citrix Ltd.
+ * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+type handle = Unix.file_descr * int ref
+
+let devnull = Unix.openfile "/dev/null" [] 0
+let init () = devnull, ref 0
+let fd (h, _) = h
+
+type t = int
+
+type virq_t =
+ | Timer (* #define VIRQ_TIMER 0 *)
+ | Debug (* #define VIRQ_DEBUG 1 *)
+ | Console (* #define VIRQ_CONSOLE 2 *)
+ | Dom_exc (* #define VIRQ_DOM_EXC 3 *)
+ | Tbuf (* #define VIRQ_TBUF 4 *)
+ | Reserved_5 (* Do not use this value as it's not defined *)
+ | Debugger (* #define VIRQ_DEBUGGER 6 *)
+ | Xenoprof (* #define VIRQ_XENOPROF 7 *)
+ | Con_ring (* #define VIRQ_CON_RING 8 *)
+ | Pcpu_state (* #define VIRQ_PCPU_STATE 9 *)
+ | Mem_event (* #define VIRQ_MEM_EVENT 10 *)
+ | Xc_reserved (* #define VIRQ_XC_RESERVED 11 *)
+ | Enomem (* #define VIRQ_ENOMEM 12 *)
+ | Xenpmu (* #define VIRQ_XENPMU 13 *)
+
+let notify _h _ = ()
+let bind_interdomain (_h, port) domid remote_port = incr port; !port
+let bind_virq (_h, port) _ = incr port; !port
+let bind_dom_exc_virq handle = bind_virq handle Dom_exc
+let unbind _ _ = ()
+let pending (_h, port) = !port
+let unmask _ _ = ()
+
+let to_int x = x
+let of_int x = x
new file mode 100644
@@ -0,0 +1,2 @@
+open Xenstored
+let () = ()
@@ -265,8 +265,8 @@ let to_file store cons fds file =
(fun () -> close_out channel)
end
-let _ =
- let cf = do_argv in
+let main () =
+ let cf = do_argv () in
let pidfile =
if Sys.file_exists (config_filename cf) then
parse_config (config_filename cf)
Based on initial work by Christian Lindig Doing oxenstored development, especially fuzzing/unit tests requires an incremental and fast build system. Dune is the preferred upstream build system for OCaml, and has been in use by the XAPI project for years. Is is incremental and also generates editor integration files (.merlin). Usage: ./xs-reconfigure.sh cd tools/ocaml make clean make check There are some other convenience targets as well: make dune-clean make dune-syntax-check make dune-build-oxenstored There are some files that are generated by Make, these are created by a 'dune-pre' target, they are too closely tied to make and cannot yet be generated by Dune itself. The various Makefile targets are used as entrypoints into Dune that set the needed env vars (for C include files and libraries) and ensure that the generated files are available. The unit tests do not require Xen to be available, so add mock eventchn and xenctrl libraries for the unit test to use, and copy the non-system specific modules from xenstored/ to xenstored/test/. Xenstored had to be split into Xenstored and Xenstored_main, so that we can use the functions defined in Xenstored without actually starting up the daemon in a unit test. Similarly argument parsing had to be delayed until after daemon startup. Also had to disable setrlimit when running as non-root in poll.ml. Signed-off-by: Edwin Török <edvin.torok@citrix.com> --- tools/ocaml/.gitignore | 2 + tools/ocaml/Makefile | 33 +++++++++++++ tools/ocaml/dune-project | 5 ++ tools/ocaml/libs/eventchn/dune | 8 ++++ tools/ocaml/libs/mmap/dune | 8 ++++ tools/ocaml/libs/xb/dune | 7 +++ tools/ocaml/libs/xc/dune | 9 ++++ tools/ocaml/libs/xs/dune | 4 ++ tools/ocaml/xen.opam | 0 tools/ocaml/xenstore.opam | 0 tools/ocaml/xenstored.opam | 18 +++++++ tools/ocaml/xenstored/Makefile | 3 +- tools/ocaml/xenstored/dune | 19 ++++++++ tools/ocaml/xenstored/parse_arg.ml | 2 +- tools/ocaml/xenstored/poll.ml | 3 +- tools/ocaml/xenstored/test/dune | 11 +++++ tools/ocaml/xenstored/test/xenctrl.ml | 48 +++++++++++++++++++ tools/ocaml/xenstored/test/xeneventchn.ml | 50 ++++++++++++++++++++ tools/ocaml/xenstored/test/xenstored_test.ml | 2 + tools/ocaml/xenstored/xenstored.ml | 4 +- 20 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 tools/ocaml/.gitignore create mode 100644 tools/ocaml/dune-project create mode 100644 tools/ocaml/libs/eventchn/dune create mode 100644 tools/ocaml/libs/mmap/dune create mode 100644 tools/ocaml/libs/xb/dune create mode 100644 tools/ocaml/libs/xc/dune create mode 100644 tools/ocaml/libs/xs/dune create mode 100644 tools/ocaml/xen.opam create mode 100644 tools/ocaml/xenstore.opam create mode 100644 tools/ocaml/xenstored.opam create mode 100644 tools/ocaml/xenstored/dune create mode 100644 tools/ocaml/xenstored/test/dune create mode 100644 tools/ocaml/xenstored/test/xenctrl.ml create mode 100644 tools/ocaml/xenstored/test/xeneventchn.ml create mode 100644 tools/ocaml/xenstored/test/xenstored_test.ml