diff mbox

[for-4.9,2/2] oxenstored: make it work on FreeBSD

Message ID 20170414102018.14853-3-wei.liu2@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Liu April 14, 2017, 10:20 a.m. UTC
Call the uname syscall to determine sysname and return device names
accordingly.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: dave@recoil.org
Cc: christian.lindig@citrix.com
Cc: jonathan.ludlam@citrix.com
Cc: Roger Pau Monné <roger.pau@citrix.com>
---
 tools/ocaml/xenstored/define.ml | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Ian Jackson April 18, 2017, 10:16 a.m. UTC | #1
Wei Liu writes ("[PATCH for-4.9 2/2] oxenstored: make it work on FreeBSD"):
> Call the uname syscall to determine sysname and return device names
> accordingly.
...
> -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.
Christian Lindig April 18, 2017, 10:22 a.m. UTC | #2
> On 18. Apr 2017, at 11:16, Ian Jackson <ian.jackson@eu.citrix.com> wrote:

> 

> Wei Liu writes ("[PATCH for-4.9 2/2] oxenstored: make it work on FreeBSD"):

>> Call the uname syscall to determine sysname and return device names

>> accordingly.

> ...

>> -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 ?


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
diff mbox

Patch

diff --git a/tools/ocaml/xenstored/define.ml b/tools/ocaml/xenstored/define.ml
index 5a604d1bea..15b03e539f 100644
--- a/tools/ocaml/xenstored/define.ml
+++ b/tools/ocaml/xenstored/define.ml
@@ -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"