[Libguestfs] [libnbd PATCH 2/4] api: Rearrange flags argument to block_status

Eric Blake eblake at redhat.com
Tue May 28 02:00:59 UTC 2019


This is an API/ABI break, but we have not yet declared stable API.

In order to use optional arguments in languages that support that, any
optional arguments must be last. Let's be consistent in this by
rearranging the arguments to block_status so that flags is always
last.
---
 generator/generator          | 10 ++++++----
 interop/dirty-bitmap.c       |  6 +++---
 lib/rw.c                     | 12 +++++-------
 python/t/460-block-status.py |  8 ++++++--
 tests/meta-base-allocation.c | 10 ++++------
 5 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/generator/generator b/generator/generator
index 9af5377..8e81d8f 100755
--- a/generator/generator
+++ b/generator/generator
@@ -1341,12 +1341,13 @@ punching a hole.";

   "block_status", {
     default_call with
-    args = [ UInt64 "count"; UInt64 "offset"; UInt32 "flags";
+    args = [ UInt64 "count"; UInt64 "offset";
              Opaque "data";
              Callback ("extent", [Opaque "data"; String "metacontext";
                                   UInt64 "offset";
                                   ArrayAndLen (UInt32 "entries",
-                                               "nr_entries")]) ];
+                                               "nr_entries")]);
+             UInt32 "flags" ];
     ret = RErr;
     shortdesc = "read the block status of the given range";
     longdesc = "\
@@ -1570,12 +1571,13 @@ in C<nbd_zero>.";

   "aio_block_status", {
     default_call with
-    args = [ UInt64 "count"; UInt64 "offset"; UInt32 "flags";
+    args = [ UInt64 "count"; UInt64 "offset";
              Opaque "data";
              Callback ("extent", [Opaque "data"; String "metacontext";
                                   UInt64 "offset";
                                   ArrayAndLen (UInt32 "entries",
-                                               "nr_entries")]) ];
+                                               "nr_entries")]);
+             UInt32 "flags" ];
     ret = RInt64;
     shortdesc = "send block status to the NBD server";
     longdesc = "\
diff --git a/interop/dirty-bitmap.c b/interop/dirty-bitmap.c
index 0a808b2..e096868 100644
--- a/interop/dirty-bitmap.c
+++ b/interop/dirty-bitmap.c
@@ -106,13 +106,13 @@ main (int argc, char *argv[])
     exit (EXIT_FAILURE);
   }

-  if (nbd_block_status (nbd, exportsize, 0, 0, NULL, cb) == -1) {
+  if (nbd_block_status (nbd, exportsize, 0, NULL, cb, 0) == -1) {
     fprintf (stderr, "%s\n", nbd_get_error ());
     exit (EXIT_FAILURE);
   }
   assert (calls == 0x11);
-  if (nbd_block_status (nbd, exportsize, 0, LIBNBD_CMD_FLAG_REQ_ONE,
-                        &exportsize, cb) == -1) {
+  if (nbd_block_status (nbd, exportsize, 0, &exportsize, cb,
+                        LIBNBD_CMD_FLAG_REQ_ONE) == -1) {
     fprintf (stderr, "%s\n", nbd_get_error ());
     exit (EXIT_FAILURE);
   }
diff --git a/lib/rw.c b/lib/rw.c
index bd453d1..feaf468 100644
--- a/lib/rw.c
+++ b/lib/rw.c
@@ -127,13 +127,12 @@ nbd_unlocked_zero (struct nbd_handle *h,
 /* Issue a block status command and wait for the reply. */
 int
 nbd_unlocked_block_status (struct nbd_handle *h,
-                           uint64_t count, uint64_t offset, uint32_t flags,
-                           void *data,
-                           extent_fn extent)
+                           uint64_t count, uint64_t offset,
+                           void *data, extent_fn extent, uint32_t flags)
 {
   int64_t ch;

-  ch = nbd_unlocked_aio_block_status (h, count, offset, flags, data, extent);
+  ch = nbd_unlocked_aio_block_status (h, count, offset, data, extent, flags);
   if (ch == -1)
     return -1;

@@ -371,9 +370,8 @@ nbd_unlocked_aio_zero (struct nbd_handle *h,
 int64_t
 nbd_unlocked_aio_block_status (struct nbd_handle *h,
                                uint64_t count, uint64_t offset,
-                               uint32_t flags,
-                               void *data,
-                               extent_fn extent)
+                               void *data, extent_fn extent,
+                               uint32_t flags)
 {
   if (!h->structured_replies) {
     set_error (ENOTSUP, "server does not support structured replies");
diff --git a/python/t/460-block-status.py b/python/t/460-block-status.py
index c141a79..815caf0 100644
--- a/python/t/460-block-status.py
+++ b/python/t/460-block-status.py
@@ -34,14 +34,18 @@ def f (data, metacontext, offset, e):
         return
     entries = e

-h.block_status (65536, 0, 0, 42, f)
+h.block_status (65536, 0, 42, f, 0)
 assert entries == [ 8192, 0,
                     8192, 1,
                    16384, 3,
                    16384, 2,
                    16384, 0]

-h.block_status (1024, 32256, 0, 42, f)
+h.block_status (1024, 32256, 42, f, 0)
 print ("entries = %r" % entries)
 assert entries == [  512, 3,
                    16384, 2]
+
+h.block_status (1024, 32256, 42, f, nbd.CMD_FLAG_REQ_ONE)
+print ("entries = %r" % entries)
+assert entries == [  512, 3]
diff --git a/tests/meta-base-allocation.c b/tests/meta-base-allocation.c
index 5c37e45..ce344d7 100644
--- a/tests/meta-base-allocation.c
+++ b/tests/meta-base-allocation.c
@@ -98,22 +98,20 @@ main (int argc, char *argv[])

   /* Read the block status. */
   id = 1;
-  if (nbd_block_status (nbd, 65536, 0, 0, &id,
-                        check_extent) == -1) {
+  if (nbd_block_status (nbd, 65536, 0, &id, check_extent, 0) == -1) {
     fprintf (stderr, "%s\n", nbd_get_error ());
     exit (EXIT_FAILURE);
   }

   id = 2;
-  if (nbd_block_status (nbd, 1024, 32768-512, 0, &id,
-                        check_extent) == -1) {
+  if (nbd_block_status (nbd, 1024, 32768-512, &id, check_extent, 0) == -1) {
     fprintf (stderr, "%s\n", nbd_get_error ());
     exit (EXIT_FAILURE);
   }

   id = 3;
-  if (nbd_block_status (nbd, 1024, 32768-512, LIBNBD_CMD_FLAG_REQ_ONE, &id,
-                        check_extent) == -1) {
+  if (nbd_block_status (nbd, 1024, 32768-512, &id, check_extent,
+                        LIBNBD_CMD_FLAG_REQ_ONE) == -1) {
     fprintf (stderr, "%s\n", nbd_get_error ());
     exit (EXIT_FAILURE);
   }
-- 
2.20.1




More information about the Libguestfs mailing list