[Libguestfs] [nbdkit PATCH] ocaml: Map more errno values

Eric Blake eblake at redhat.com
Fri Aug 16 13:29:28 UTC 2019


Mapping of EOVERFLOW was missed in commit 6f8c8084.

Mapping of EOPNOTSUPP is essential for .zero to trigger a fallback to
.pwrite, missed in commit 6c0e00e9 (not to mention that it becomes a
valid protocol failure once fast zero support is added).  There is no
Unix.ENOTSUP, or that would get the same treatment per commit
abb2b47c.

Preserving EROFS and EFBIG is useful because protocol.c special-cases
those (by merging them into EPERM and ENOSPC over the wire).  There is
no Unix.EDQUOT, or that would get the same treatment.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 plugins/ocaml/ocaml.c   | 7 +++++++
 plugins/ocaml/NBDKit.ml | 4 ++++
 2 files changed, 11 insertions(+)

diff --git a/plugins/ocaml/ocaml.c b/plugins/ocaml/ocaml.c
index 064cdedb..5161775f 100644
--- a/plugins/ocaml/ocaml.c
+++ b/plugins/ocaml/ocaml.c
@@ -849,12 +849,19 @@ ocaml_nbdkit_set_error (value nv)
   int err;

   switch (Int_val (nv)) {
+    /* On-the-wire values */
   case 1: err = EPERM; break;
   case 2: err = EIO; break;
   case 3: err = ENOMEM; break;
   case 4: err = EINVAL; break;
   case 5: err = ENOSPC; break;
   case 6: err = ESHUTDOWN; break;
+  case 7: err = EOVERFLOW; break;
+    /* Necessary for .zero support */
+  case 8: err = ENOTSUP; break;
+    /* Other errno that server/protocol.c treats specially */
+  case 9: err = EROFS; break;
+  case 10: err = EFBIG; break;
   default: abort ();
   }

diff --git a/plugins/ocaml/NBDKit.ml b/plugins/ocaml/NBDKit.ml
index 68d15836..e54a7705 100644
--- a/plugins/ocaml/NBDKit.ml
+++ b/plugins/ocaml/NBDKit.ml
@@ -267,6 +267,10 @@ let set_error unix_error =
     | Unix.EINVAL     -> 4
     | Unix.ENOSPC     -> 5
     | Unix.ESHUTDOWN  -> 6
+    | Unix.EOVERFLOW  -> 7
+    | Unix.EOPNOTSUPP -> 8
+    | Unix.EROFS      -> 9
+    | Unix.EFBIG      -> 10
     | _               -> 4 (* EINVAL *) in

   _set_error nbd_error
-- 
2.20.1




More information about the Libguestfs mailing list