[PATCH libnbd] interop: Add test of qemu-storage-daemon.
by Richard W.M. Jones
This commit adds a simple test of qemu-storage-daemon (QSD). On the
basis that QSD is just qemu-nbd in new clothes this is only a simple
test, not complete coverage. Nor does it test the unique features of
QSD like being able to use QMP to create new server instances.
Unfortunately QSD is not yet stable upstream. This version works with
qemu 5.1.0 but at least two of the command line parameters have
changed name upstream (see comment in patch) so it will break soon.
Also there are quite a few other problems with QSD:
https://lists.gnu.org/archive/html/qemu-devel/2020-09/threads.html#10952
So this is probably not something we can take upstream in libnbd yet,
but here's the patch to look at. (I could push a patch with the test
disabled and plan to enable it later.)
Rich.
4 years, 1 month
[PATCH libnbd] generator: Add SizeT type, maps to C size_t.
by Richard W.M. Jones
---
generator/API.ml | 1 +
generator/API.mli | 1 +
generator/C.ml | 14 ++++++++++----
generator/GoLang.ml | 5 +++++
generator/OCaml.ml | 5 +++++
generator/Python.ml | 11 +++++++++--
6 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/generator/API.ml b/generator/API.ml
index 0a876c4..b93580d 100644
--- a/generator/API.ml
+++ b/generator/API.ml
@@ -47,6 +47,7 @@ and arg =
| Int of string
| Int64 of string
| Path of string
+| SizeT of string
| SockAddrAndLen of string * string
| String of string
| StringList of string
diff --git a/generator/API.mli b/generator/API.mli
index 9d2fdb7..2e7aa78 100644
--- a/generator/API.mli
+++ b/generator/API.mli
@@ -57,6 +57,7 @@ and arg =
| Int of string (** small int *)
| Int64 of string (** 64 bit signed int *)
| Path of string (** filename or path *)
+| SizeT of string (** like size_t, for counting array elements *)
| SockAddrAndLen of string * string (** struct sockaddr * + socklen_t *)
| String of string (** string, cannot be NULL *)
| StringList of string (** argv-style NULL-terminated array of strings *)
diff --git a/generator/C.ml b/generator/C.ml
index 5f68b14..82d5e3d 100644
--- a/generator/C.ml
+++ b/generator/C.ml
@@ -93,6 +93,7 @@ let rec name_of_arg = function
| Int n -> [n]
| Int64 n -> [n]
| Path n -> [n]
+| SizeT n -> [n]
| SockAddrAndLen (n, len) -> [n; len]
| String n -> [n]
| StringList n -> [n]
@@ -157,6 +158,9 @@ and print_arg_list' ?(handle = false) ?(types = true) ?(closure_style = Direct)
| Int64 n ->
if types then pr "int64_t ";
pr "%s" n
+ | SizeT n ->
+ if types then pr "size_t ";
+ pr "%s" n
| Path n
| String n ->
if types then pr "const char *";
@@ -621,7 +625,8 @@ let generate_lib_api_c () =
pr " nbd_internal_printable_string_list (%s);\n" n
| BytesOut _ | BytesPersistOut _
| Bool _ | Closure _ | Enum _ | Flags _ | Fd _ | Int _
- | Int64 _ | SockAddrAndLen _ | UInt _ | UInt32 _ | UInt64 _ -> ()
+ | Int64 _ | SizeT _
+ | SockAddrAndLen _ | UInt _ | UInt32 _ | UInt64 _ -> ()
) args;
pr " debug (h, \"enter:";
List.iter (
@@ -637,6 +642,7 @@ let generate_lib_api_c () =
| Flags (n, _) -> pr " %s=0x%%x" n
| Fd n | Int n -> pr " %s=%%d" n
| Int64 n -> pr " %s=%%\" PRIi64 \"" n
+ | SizeT n -> pr " %s=%%zu" n
| SockAddrAndLen (n, len) -> pr " %s=<sockaddr> %s=%%d" n len
| Path n
| String n -> pr " %s=%%s" n
@@ -662,8 +668,7 @@ let generate_lib_api_c () =
| Closure { cbname } -> ()
| Enum (n, _) -> pr ", %s" n
| Flags (n, _) -> pr ", %s" n
- | Fd n | Int n -> pr ", %s" n
- | Int64 n -> pr ", %s" n
+ | Fd n | Int n | Int64 n | SizeT n -> pr ", %s" n
| SockAddrAndLen (_, len) -> pr ", (int) %s" len
| Path n | String n | StringList n ->
pr ", %s_printable ? %s_printable : \"\"" n n
@@ -686,7 +691,8 @@ let generate_lib_api_c () =
pr " free (%s_printable);\n" n
| BytesOut _ | BytesPersistOut _
| Bool _ | Closure _ | Enum _ | Flags _ | Fd _ | Int _
- | Int64 _ | SockAddrAndLen _ | UInt _ | UInt32 _ | UInt64 _ -> ()
+ | Int64 _ | SizeT _
+ | SockAddrAndLen _ | UInt _ | UInt32 _ | UInt64 _ -> ()
) args;
pr " }\n"
(* Print the trace when we leave a call with debugging enabled. *)
diff --git a/generator/GoLang.ml b/generator/GoLang.ml
index 81446a6..e169173 100644
--- a/generator/GoLang.ml
+++ b/generator/GoLang.ml
@@ -54,6 +54,7 @@ let go_name_of_arg = function
| Int n -> n
| Int64 n -> n
| Path n -> n
+ | SizeT n -> n
| SockAddrAndLen (n, len) -> n
| String n -> n
| StringList n -> n
@@ -74,6 +75,7 @@ let go_arg_type = function
| Int _ -> "int"
| Int64 _ -> "int64"
| Path _ -> "string"
+ | SizeT _ -> "int"
| SockAddrAndLen _ -> "string"
| String _ -> "string"
| StringList _ -> "[]string"
@@ -276,6 +278,8 @@ let print_binding (name, { args; optargs; ret; shortdesc }) =
| Path n ->
pr " c_%s := C.CString (%s)\n" n n;
pr " defer C.free (unsafe.Pointer (c_%s))\n" n
+ | SizeT n ->
+ pr " c_%s := C.size_t (%s)\n" n n
| SockAddrAndLen (n, len) ->
pr " panic (\"SockAddrAndLen not supported\")\n";
pr " var c_%s *C.struct_sockaddr\n" n;
@@ -336,6 +340,7 @@ let print_binding (name, { args; optargs; ret; shortdesc }) =
| Int n -> pr ", c_%s" n
| Int64 n -> pr ", c_%s" n
| Path n -> pr ", c_%s" n
+ | SizeT n -> pr ", c_%s" n
| SockAddrAndLen (n, len) -> pr ", c_%s, c_%s" n len
| String n -> pr ", c_%s" n
| StringList n -> pr ", &c_%s[0]" n
diff --git a/generator/OCaml.ml b/generator/OCaml.ml
index 28acb50..81e5529 100644
--- a/generator/OCaml.ml
+++ b/generator/OCaml.ml
@@ -50,6 +50,7 @@ and ocaml_arg_to_string = function
| Int64 _ -> "int64"
| Path _ -> "string"
| SockAddrAndLen _ -> "string" (* XXX not impl *)
+ | SizeT _ -> "int" (* OCaml int type is always sufficient for counting *)
| String _ -> "string"
| StringList _ -> "string list"
| UInt _ -> "int"
@@ -103,6 +104,7 @@ let ocaml_name_of_arg = function
| Int n -> n
| Int64 n -> n
| Path n -> n
+ | SizeT n -> n
| SockAddrAndLen (n, len) -> n
| String n -> n
| StringList n -> n
@@ -666,6 +668,8 @@ let print_ocaml_binding (name, { args; optargs; ret }) =
pr " int64_t %s = Int64_val (%sv);\n" n n
| Path n | String n ->
pr " const char *%s = String_val (%sv);\n" n n
+ | SizeT n ->
+ pr " size_t %s = Int_val (%sv);\n" n n
| SockAddrAndLen (n, len) ->
pr " const struct sockaddr *%s;\n" n;
pr " socklen_t %s;\n" len;
@@ -738,6 +742,7 @@ let print_ocaml_binding (name, { args; optargs; ret }) =
| Int _
| Int64 _
| Path _
+ | SizeT _
| String _
| SockAddrAndLen _
| UInt _
diff --git a/generator/Python.ml b/generator/Python.ml
index 1705ad9..46b5828 100644
--- a/generator/Python.ml
+++ b/generator/Python.ml
@@ -295,6 +295,8 @@ let print_python_binding name { args; optargs; ret; may_set_error } =
| Path n ->
pr " PyObject *py_%s = NULL;\n" n;
pr " char *%s = NULL;\n" n
+ | SizeT n ->
+ pr " Py_ssize_t %s;\n" n
| SockAddrAndLen (n, _) ->
pr " /* XXX Complicated - Python uses a tuple of different\n";
pr " * lengths for the different socket types.\n";
@@ -341,6 +343,7 @@ let print_python_binding name { args; optargs; ret; may_set_error } =
| Fd n | Int n -> pr " \"i\""
| Int64 n -> pr " \"L\""
| Path n -> pr " \"O&\""
+ | SizeT n -> pr " \"n\""
| SockAddrAndLen (n, _) -> pr " \"O\""
| String n -> pr " \"s\""
| StringList n -> pr " \"O\""
@@ -365,8 +368,7 @@ let print_python_binding name { args; optargs; ret; may_set_error } =
| Closure { cbname } -> pr ", &py_%s_fn" cbname
| Enum (n, _) -> pr ", &%s" n
| Flags (n, _) -> pr ", &%s" n
- | Fd n | Int n -> pr ", &%s" n
- | Int64 n -> pr ", &%s" n
+ | Fd n | Int n | SizeT n | Int64 n -> pr ", &%s" n
| Path n -> pr ", PyUnicode_FSConverter, &py_%s" n
| SockAddrAndLen (n, _) -> pr ", &%s" n
| String n -> pr ", &%s" n
@@ -435,6 +437,7 @@ let print_python_binding name { args; optargs; ret; may_set_error } =
| Path n ->
pr " %s = PyBytes_AS_STRING (py_%s);\n" n n;
pr " assert (%s != NULL);\n" n
+ | SizeT n -> ()
| SockAddrAndLen _ ->
pr " abort (); /* XXX SockAddrAndLen not implemented */\n";
| String _ -> ()
@@ -462,6 +465,7 @@ let print_python_binding name { args; optargs; ret; may_set_error } =
| Fd n | Int n -> pr ", %s" n
| Int64 n -> pr ", %s_i64" n
| Path n -> pr ", %s" n
+ | SizeT n -> pr ", (size_t)%s" n
| SockAddrAndLen (n, _) -> pr ", /* XXX */ (void *) %s, 0" n
| String n -> pr ", %s" n
| StringList n -> pr ", %s" n
@@ -510,6 +514,7 @@ let print_python_binding name { args; optargs; ret; may_set_error } =
| Int64 _
| Path _
| SockAddrAndLen _
+ | SizeT _
| String _
| StringList _
| UInt _
@@ -551,6 +556,7 @@ let print_python_binding name { args; optargs; ret; may_set_error } =
| Int64 _ -> ()
| Path n ->
pr " Py_XDECREF (py_%s);\n" n
+ | SizeT _ -> ()
| SockAddrAndLen _ -> ()
| String n -> ()
| StringList n -> pr " nbd_internal_py_free_string_list (%s);\n" n
@@ -791,6 +797,7 @@ class NBD(object):
| Fd n | Int n -> n, None, None
| Int64 n -> n, None, None
| Path n -> n, None, None
+ | SizeT n -> n, None, None
| SockAddrAndLen (n, _) -> n, None, None
| String n -> n, None, None
| StringList n -> n, None, None
--
2.28.0.rc2
4 years, 1 month