oxenstored: make it work on FreeBSD
cover oxenstored: make it work on FreeBSD
I managed to remove almost all Linux-ism in my previous work to make all paths configurable.
The last bits missing are the two device node paths.
Unfortunately there is an easy way to determine system name in the standard library so I wrote a wrapper for uname syscall.
I think this is a good candidate for inclusion in 4.9. I wouldn't be too disappointed if they don't end up there though. I will let Julien decide.
Wei Liu (2):
oxenstored: add an Unix syscall C extension
oxenstored: make it work on FreeBSD
tools/ocaml/xenstored/Makefile | 9 ++++-- tools/ocaml/xenstored/define.ml | 16 ++++++++-- tools/ocaml/xenstored/unix_syscalls.ml | 29 ++++++++++++++++++ tools/ocaml/xenstored/unix_syscalls.mli | 29 ++++++++++++++++++ tools/ocaml/xenstored/unix_syscalls_stubs.c | 46 +++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 tools/ocaml/xenstored/unix_syscalls.ml create mode 100644 tools/ocaml/xenstored/unix_syscalls.mli create mode 100644 tools/ocaml/xenstored/unix_syscalls_stubs.c
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/2 oxenstored: add an Unix syscall C extension
Currently there is only uname syscall in it.
---
Cc: Ian Jackson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: Roger Pau Monné <[email protected]>
--- tools/ocaml/xenstored/Makefile | 9 ++++-- tools/ocaml/xenstored/unix_syscalls.ml | 29 ++++++++++++++++++ tools/ocaml/xenstored/unix_syscalls.mli | 29 ++++++++++++++++++ tools/ocaml/xenstored/unix_syscalls_stubs.c | 46 +++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 tools/ocaml/xenstored/unix_syscalls.ml create mode 100644 tools/ocaml/xenstored/unix_syscalls.mli create mode 100644 tools/ocaml/xenstored/unix_syscalls_stubs.c
tools/ocaml/xenstored/Makefile +6 -3
@@ -18,12 +18,14 @@ OCAMLINCLUDE += \ -I $(OCAML_TOPLEVEL)/libs/xc \ -I $(OCAML_TOPLEVEL)/libs/eventchn -LIBS = syslog.cma syslog.cmxa select.cma select.cmxa +LIBS = syslog.cma syslog.cmxa select.cma select.cmxa unix_syscalls.cma unix_syscalls.cmxa syslog_OBJS = syslog syslog_C_OBJS = syslog_stubs select_OBJS = select select_C_OBJS = select_stubs -OCAML_LIBRARY = syslog select +unix_syscalls_C_OBJS = unix_syscalls_stubs +unix_syscalls_OBJS = unix_syscalls +OCAML_LIBRARY = syslog select unix_syscalls LIBS += systemd.cma systemd.cmxa systemd_OBJS = systemd
@@ -58,13 +60,14 @@ OBJS = paths \ process \ xenstored -INTF = symbol.cmi trie.cmi syslog.cmi systemd.cmi select.cmi +INTF = symbol.cmi trie.cmi syslog.cmi systemd.cmi select.cmi unix_syscalls.cmi XENSTOREDLIBS = \ unix.cmxa \ -ccopt -L -ccopt . syslog.cmxa \ -ccopt -L -ccopt . systemd.cmxa \ -ccopt -L -ccopt . select.cmxa \ + -ccopt -L -ccopt . unix_syscalls.cmxa \ -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/mmap $(OCAML_TOPLEVEL)/libs/mmap/xenmmap.cmxa \ -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn $(OCAML_TOPLEVEL)/libs/eventchn/xeneventchn.cmxa \ -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc $(OCAML_TOPLEVEL)/libs/xc/xenctrl.cmxa \
tools/ocaml/xenstored/unix_syscalls.ml new file +29 -0
@@ -0,0 +1,29 @@ +(* + * unix_syscalls.ml + * + * Stubs for unix syscalls + * + * Copyright (C) 2017 Wei Liu <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License, version 2.1, as published by the Free Software Foundation. + * + * This library 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see <http://www.gnu.org/licenses/>. + *) + +type utsname = { + sysname: string; + nodename: string; + release: string; + version: string; + machine: string; +} + +external uname : unit -> utsname = "unix_uname"
tools/ocaml/xenstored/unix_syscalls.mli new file +29 -0
@@ -0,0 +1,29 @@ +(* + * unix_syscalls.mli + * + * Stubs for unix syscalls + * + * Copyright (C) 2017 Wei Liu <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License, version 2.1, as published by the Free Software Foundation. + * + * This library 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see <http://www.gnu.org/licenses/>. + *) + +type utsname = { + sysname: string; + nodename: string; + release: string; + version: string; + machine: string; +} + +external uname : unit -> utsname = "unix_uname"
tools/ocaml/xenstored/unix_syscalls_stubs.c new file +46 -0
46 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/2 oxenstored: make it work on FreeBSD
In reply to Wei LiuCall the uname syscall to determine sysname and return device names accordingly.
---
Cc: Ian Jackson <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: Roger Pau Monné <[email protected]>
--- tools/ocaml/xenstored/define.ml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
tools/ocaml/xenstored/define.ml +14 -2
@@ -14,11 +14,23 @@ * GNU Lesser General Public License for more details. *) +open Unix_syscalls + let xenstored_major = 1 let xenstored_minor = 0 -let xenstored_proc_kva = "/proc/xen/xsd_kva" -let xenstored_proc_port = "/proc/xen/xsd_port" +let xenstored_proc_kva = + let info = Unix_syscalls.uname () in + match info.sysname with + | "Linux" -> "/proc/xen/xsd_kva" + | "FreeBSD" -> "/dev/xen/xenstored" + | _ -> "nonexistent" +let xenstored_proc_port = + let info = Unix_syscalls.uname () in + match info.sysname with + | "Linux" -> "/proc/xen/xsd_port" + | "FreeBSD" -> "/dev/xen/xenstored" + | _ -> "nonexistent" let xs_daemon_socket = Paths.xen_run_stored ^ "/socket" let xs_daemon_socket_ro = Paths.xen_run_stored ^ "/socket_ro"
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/1 oxenstored: remove "_proc" in names
They aren't limited to proc file system anymore. Use more generic names.
No functional change.
---
This is a follow-up patch for "oxenstored: make it work on FreeBSD".
--- tools/ocaml/xenstored/define.ml | 4 ++-- tools/ocaml/xenstored/domains.ml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
tools/ocaml/xenstored/define.ml +2 -2
@@ -19,13 +19,13 @@ open Unix_syscalls let xenstored_major = 1 let xenstored_minor = 0 -let xenstored_proc_kva = +let xenstored_kva = let info = Unix_syscalls.uname () in match info.sysname with | "Linux" -> "/proc/xen/xsd_kva" | "FreeBSD" -> "/dev/xen/xenstored" | _ -> "nonexistent" -let xenstored_proc_port = +let xenstored_port = let info = Unix_syscalls.uname () in match info.sysname with | "Linux" -> "/proc/xen/xsd_port"
tools/ocaml/xenstored/domains.ml +2 -2
@@ -130,8 +130,8 @@ let create xc doms domid mfn port = let create0 doms = let port, interface = ( - let port = Utils.read_file_single_integer Define.xenstored_proc_port - and fd = Unix.openfile Define.xenstored_proc_kva + let port = Utils.read_file_single_integer Define.xenstored_port + and fd = Unix.openfile Define.xenstored_kva [ Unix.O_RDWR ] 0o600 in let interface = Xenmmap.mmap fd Xenmmap.RDWR Xenmmap.SHARED (Xenmmap.getpagesize()) 0 in
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 5 lines · Wei Liu
Unfortunately there is an easy way to determine system name in the standard library so I wrote a wrapper for uname syscall.
I think there are two solutions to using the correct path:
(1) Determine the path at compile time and use the mechanism in config.ml to read the path at startup.
https://github.com/mirage/xen/blob/master/tools/ocaml/xenstored/oxenstored.conf.in
https://github.com/mirage/xen/blob/master/tools/ocaml/xenstored/xenstored.ml#L90
(2) Determine the path at runtime and this is what the patch does by using uname:
-let xenstored_proc_kva = "/proc/xen/xsd_kva"
-let xenstored_proc_port = "/proc/xen/xsd_port"
+let xenstored_proc_kva =
+ let info = Unix_syscalls.uname () in + match info.sysname with + | "Linux" -> "/proc/xen/xsd_kva" + | "FreeBSD" -> "/dev/xen/xenstored" + | _ -> "nonexistent" +let xenstored_proc_port = + let info = Unix_syscalls.uname () in + match info.sysname with + | "Linux" -> "/proc/xen/xsd_port" + | "FreeBSD" -> "/dev/xen/xenstored" + | _ -> "nonexistent"
I wonder whether this could be simplified without binding a system call in C by simply checking the presence of the two paths (using Sys.is_directory) and picking the one that does exist. In general I’m in favour of (1) but would also consider a simple run-time check.
- Christian
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 6 lines · Christian Lindig
Quoted 5 lines · Wei Liu
Unfortunately there is an easy way to determine system name in the standard library so I wrote a wrapper for uname syscall.
Quoted 7 lines
I think there are two solutions to using the correct path:
(1) Determine the path at compile time and use the mechanism in config.ml to read the path at startup.
https://github.com/mirage/xen/blob/master/tools/ocaml/xenstored/oxenstored.conf.in
https://github.com/mirage/xen/blob/master/tools/ocaml/xenstored/xenstored.ml#L90
Forgive my ignorance for the Ocaml ecosystem, but I can't seem to find a way to conditionally compile ocaml source code easily.
Presumably you mean "Determine the path at *configure* time"? Even if we make those configurable, there should still be two default values in define.ml -- what should they be?
All in all I don't think it is nice to require extra configurations when all relevant information is already available during build phase and run time.
Quoted 17 lines
(2) Determine the path at runtime and this is what the patch does by using uname:
(quoted diff) +12
-2-let xenstored_proc_kva = "/proc/xen/xsd_kva" -let xenstored_proc_port = "/proc/xen/xsd_port" +let xenstored_proc_kva = + let info = Unix_syscalls.uname () in + match info.sysname with + | "Linux" -> "/proc/xen/xsd_kva" + | "FreeBSD" -> "/dev/xen/xenstored" + | _ -> "nonexistent" +let xenstored_proc_port = + let info = Unix_syscalls.uname () in + match info.sysname with + | "Linux" -> "/proc/xen/xsd_port" + | "FreeBSD" -> "/dev/xen/xenstored" + | _ -> "nonexistent"
Quoted 4 lines
I wonder whether this could be simplified without binding a system call in C by simply checking the presence of the two paths (using Sys.is_directory) and picking the one that does exist. In general I’m in favour of (1) but would also consider a simple run-time check.
I am fine with checking the paths using Sys.is_directory.
Wei.
Quoted 4 lines
- Christian
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 9 lines · Wei Liu
Forgive my ignorance for the Ocaml ecosystem, but I can't seem to find a way to conditionally compile ocaml source code easily.
Presumably you mean "Determine the path at *configure* time"? Even if we make those configurable, there should still be two default values in define.ml -- what should they be?
Sorry for the confusion. I was conflating configure time and compile times. The configure step could provide the correct paths in the config file that is read at startup. I would definitely avoid conditional compilation.
— Christian
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 9 lines · Wei Liu
Forgive my ignorance for the Ocaml ecosystem, but I can't seem to find a way to conditionally compile ocaml source code easily.
Presumably you mean "Determine the path at *configure* time"? Even if we make those configurable, there should still be two default values in define.ml -- what should they be?
Sorry for the confusion. I was conflating configure time and compile times. The configure step could provide the correct paths in the config file that is read at startup. I would definitely avoid conditional compilation.
— Christian
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH for-4.9 1/2] oxenstored: add an Unix syscall C extension
In reply to Wei LiuWei Liu writes ("[PATCH for-4.9 1/2] oxenstored: add an Unix syscall C extension"):
Quoted 1 line
Currently there is only uname syscall in it.
I agree that this would be good to have in 4.9. The ocaml FFI has tricky memory management, so this needs review by an ocaml expert.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH for-4.9] oxenstored: remove "_proc" in names
In reply to Wei LiuWei Liu writes ("[PATCH for-4.9] oxenstored: remove "_proc" in names"):
Quoted 3 lines
They aren't limited to proc file system anymore. Use more generic names.
No functional change.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Wei Liu writes ("[PATCH for-4.9 2/2] oxenstored: make it work on FreeBSD"):
Quoted 2 lines
Call the uname syscall to determine sysname and return device names accordingly.
...
tools/ocaml/xenstored/define.ml line 27
Quoted 8 lines
tools/ocaml/xenstored/define.ml +6
-2-let xenstored_proc_kva = "/proc/xen/xsd_kva" -let xenstored_proc_port = "/proc/xen/xsd_port" +let xenstored_proc_kva = + let info = Unix_syscalls.uname () in + match info.sysname with + | "Linux" -> "/proc/xen/xsd_kva" + | "FreeBSD" -> "/dev/xen/xenstored" + | _ -> "nonexistent"
This isn't very good. If this code wants to fail, it returns a string "nonexistent" which would then be used to construct pathnames, and actually accessed.
In Haskell one could simply leave the default case off, which would generate a runtime failure. Is that possible in ocaml ?
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 20 lines · Ian Jackson
Wei Liu writes ("[PATCH for-4.9 2/2] oxenstored: make it work on FreeBSD"):
Quoted 2 lines
Call the uname syscall to determine sysname and return device names accordingly.
...
tools/ocaml/xenstored/define.ml line 27
Quoted 8 lines
tools/ocaml/xenstored/define.ml +6
-2-let xenstored_proc_kva = "/proc/xen/xsd_kva" -let xenstored_proc_port = "/proc/xen/xsd_port" +let xenstored_proc_kva = + let info = Unix_syscalls.uname () in + match info.sysname with + | "Linux" -> "/proc/xen/xsd_kva" + | "FreeBSD" -> "/dev/xen/xenstored" + | _ -> "nonexistent"This isn't very good. If this code wants to fail, it returns a string "nonexistent" which would then be used to construct pathnames, and actually accessed.
Quoted 2 lines
In Haskell one could simply leave the default case off, which would generate a runtime failure. Is that possible in ocaml ?
In Ocaml you would either use “assert false” or raise a dedicated exception for the catch-all case. You would get a run-time Match_failure exception without but this is nasty. The current solution has the problem you describe.
— C
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 6 lines · Christian Lindig
Quoted 6 lines · Wei Liu
Forgive my ignorance for the Ocaml ecosystem, but I can't seem to find a way to conditionally compile ocaml source code easily.
Quoted 8 lines
Quoted 3 lines
Presumably you mean "Determine the path at *configure* time"? Even if we make those configurable, there should still be two default values in define.ml -- what should they be?
Sorry for the confusion. I was conflating configure time and compile times. The configure step could provide the correct paths in the config file that is read at startup. I would definitely avoid conditional compilation.
OK. I'm fine with this. Let me give it a shot.
Wei.
Quoted 2 lines
— Christian
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel