[PATCH v3 00/12] v2v: Change virt-v2v to use nbdkit for input in several modes.
by Richard W.M. Jones
v2 was posted here:
https://www.redhat.com/archives/libguestfs/2019-July/msg00115.html
This also has links to earlier versions.
v3:
- The 01/11 patch in v2 included a bunch of unnecessary plus one
necessary change to how input_password is passed around. I moved
the necessary change into the final patch (implementing SSH
password authentication) and dropped the rest.
- The 01/11 patch in v2 contained a trivial whitespace fix which
unfortunately caused git to make the patch much larger than it
needs to be. I split this trivial change out into a separate patch
for easier review.
- Some trivial grammar corrections in comments.
It's best to view patch 02/12 with the ‘-w’ option to make it slightly
easier to see what's going on.
Rich.
5 years, 4 months
[libnbd PATCH 0/2] in_flight improvements
by Eric Blake
Noticed while thinking about the recent threads wondering if we need a
more efficient lookup from cookie back to command. Both of these fix
bugs, but are tricky enough that I'm posting for review.
Eric Blake (2):
lib: Decrement in_flight at response, not retirement
lib: Do O(1) rather than O(n) queue insertion
generator/states-issue-command.c | 2 ++
generator/states-reply.c | 14 +++++++-------
generator/states.c | 11 +++++++++--
lib/aio.c | 6 ++++--
lib/internal.h | 2 ++
lib/rw.c | 10 ++++------
tests/server-death.c | 10 +++++-----
7 files changed, 33 insertions(+), 22 deletions(-)
--
2.20.1
5 years, 4 months
[PATCH] v2v: remove extra nbdkit bit from documentation (RHBZ#1723305)
by Pino Toscano
Since there is no more need to build nbdkit from sources, then there is
no need to set $PATH with a custom build of nbdkit.
Followup of commit 0704d8eb0bcc8139886eb4291f75a3ca49a91e58.
---
v2v/virt-v2v-input-vmware.pod | 1 -
1 file changed, 1 deletion(-)
diff --git a/v2v/virt-v2v-input-vmware.pod b/v2v/virt-v2v-input-vmware.pod
index b3ebda182..3acdd773e 100644
--- a/v2v/virt-v2v-input-vmware.pod
+++ b/v2v/virt-v2v-input-vmware.pod
@@ -293,7 +293,6 @@ To import a particular guest from vCenter server or ESXi hypervisor,
use a command like the following, substituting the URI, guest name and
SSL thumbprint:
- $ export PATH=/path/to/nbdkit-1.1.x:$PATH
$ virt-v2v \
-ic 'vpx://root@vcenter.example.com/Datacenter/esxi?no_verify=1' \
-it vddk \
--
2.21.0
5 years, 4 months
[libnbd PATCH 0/6] new APIs: aio_in_flight, aio_FOO_notify
by Eric Blake
I still need to wire in the use of *_notify functions into nbdkit to
prove whether it makes the code any faster or easier to maintain, but
at least the added example shows one good use case for the new API.
Eric Blake (6):
api: Add nbd_aio_in_flight
generator: Allow DEAD state actions to run
generator: Allow Int64 in callbacks
states: Prepare for aio notify callback
api: Add new nbd_aio_FOO_notify functions
examples: New example for strict read validations
.gitignore | 1 +
docs/libnbd.pod | 22 +-
examples/Makefile.am | 14 +
examples/batched-read-write.c | 17 +-
examples/strict-structured-reads.c | 270 +++++++++++++
generator/generator | 375 ++++++++++++++++--
generator/states-connect.c | 24 +-
generator/states-issue-command.c | 4 +-
generator/states-magic.c | 6 +-
generator/states-newstyle-opt-export-name.c | 8 +-
generator/states-newstyle-opt-go.c | 20 +-
.../states-newstyle-opt-set-meta-context.c | 24 +-
generator/states-newstyle-opt-starttls.c | 18 +-
.../states-newstyle-opt-structured-reply.c | 10 +-
generator/states-newstyle.c | 6 +-
generator/states-oldstyle.c | 4 +-
generator/states-reply-simple.c | 2 +-
generator/states-reply-structured.c | 58 +--
generator/states-reply.c | 16 +-
generator/states.c | 33 +-
lib/aio.c | 9 +
lib/internal.h | 6 +-
lib/rw.c | 105 ++++-
tests/aio-parallel-load.c | 29 +-
tests/aio-parallel.c | 15 +-
tests/server-death.c | 17 +-
26 files changed, 925 insertions(+), 188 deletions(-)
create mode 100644 examples/strict-structured-reads.c
--
2.20.1
5 years, 4 months
[nbdkit PATCH 0/2] Another libnbd API bump
by Eric Blake
libnbd 0.1.7 was released today, which breaks compilation of
nbdkit-nbd-plugin. We could work around it by using #ifdef
LIBNBD_HAVE_XXX to learn about the renamed functions, but supporting
older versions is not all that important when we don't yet have API
stability. So patch 1 copes by just bumping the minimum version
instead, except that we have yet another pending libnbd patch with an
API break - and those changes are trickier (reordering parameters does
NOT create a new LIBNBD_HAVE_XXX witness macro, so you can't easily
compile for 0.1.7 and 0.1.8 at the same time), so I'm leaning more
towards doing nothing until libnbd 0.1.8 is released and then
squashing these together (as that shouldn't be much longer). If
short-term compilation is needed without these patches, change
PKG_CHECK_MODULES to request [libnbd = 0.1.6] instead of >= (to
gracefully fall back to non-libnbd compilation if you don't have
libnbd 0.1.6 around).
Eric Blake (2):
nbd: Another libnbd API bump
nbd: Another libnbd API bump
configure.ac | 4 ++--
plugins/nbd/nbd.c | 31 ++++++++++++++++---------------
2 files changed, 18 insertions(+), 17 deletions(-)
--
2.20.1
5 years, 4 months
[libnbd PATCH] generator: Prefer closure opaque after function pointer in C
by Eric Blake
Existing practice tends to prefer the void* closure argument for C
callbacks to occur after the function pointer (POSIX: pthread_create;
glibc: qsort_r; glib: g_thread_new; libvirt:
virConnectDomainEventRegisterAny; etc.). It's also handy to think that
calling 'myfunc(cb, arg)' will eventually result in a call to
'cb(arg)'. While I couldn't quickly find any style guide recommending
one way over another, and while it probably doesn't hurt which style
we choose internally as long as we stick to it, it is still probably
worth the notion of listing the closure argument last.
Of course, that means that this also reverts commit
abcdf71a7585f4f6cfe5943a0082ce0184e9b1fb. It also means that this is
yet another API/ABI break - good thing we haven't declared stable API
yet.
---
examples/strict-structured-reads.c | 4 +-
generator/generator | 27 ++++++-------
interop/dirty-bitmap.c | 6 +--
interop/structured-read.c | 6 +--
lib/debug.c | 4 +-
lib/handle.c | 2 +-
lib/internal.h | 4 +-
lib/rw.c | 61 +++++++++++++++---------------
tests/meta-base-allocation.c | 6 +--
tests/oldstyle.c | 4 +-
10 files changed, 62 insertions(+), 62 deletions(-)
diff --git a/examples/strict-structured-reads.c b/examples/strict-structured-reads.c
index 1526344..92eb3e6 100644
--- a/examples/strict-structured-reads.c
+++ b/examples/strict-structured-reads.c
@@ -224,8 +224,8 @@ main (int argc, char *argv[])
*r = (struct range) { .first = offset, .last = offset + maxsize, };
*d = (struct data) { .offset = offset, .count = maxsize, .flags = flags,
.remaining = r, };
- if (nbd_aio_pread_structured_callback (nbd, buf, sizeof buf, offset, d,
- read_chunk, read_verify,
+ if (nbd_aio_pread_structured_callback (nbd, buf, sizeof buf, offset,
+ read_chunk, read_verify, d,
flags) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
exit (EXIT_FAILURE);
diff --git a/generator/generator b/generator/generator
index fab7281..485a76a 100755
--- a/generator/generator
+++ b/generator/generator
@@ -3173,7 +3173,7 @@ let rec c_name_of_arg = function
| BytesPersistIn (n, len) -> [n; len]
| BytesPersistOut (n, len) -> [n; len]
| Closure (_, closures) ->
- "user_data" :: List.map (fun { cbname } -> cbname) closures
+ List.map (fun { cbname } -> cbname) closures @ ["user_data"]
| Flags n -> [n]
| Int n -> [n]
| Int64 n -> [n]
@@ -3211,12 +3211,13 @@ let rec print_c_arg_list ?(handle = false) ?(user_data = false) args =
| BytesOut (n, len)
| BytesPersistOut (n, len) -> pr "void *%s, size_t %s" n len
| Closure (_, cls) ->
- pr "void *user_data";
List.iter (
fun { cbname; cbargs } ->
- pr ", int (*%s) " cbname;
- print_c_arg_list ~user_data:true cbargs
- ) cls
+ pr "int (*%s) " cbname;
+ print_c_arg_list ~user_data:true cbargs;
+ pr ", "
+ ) cls;
+ pr "void *user_data"
| Flags n -> pr "uint32_t %s" n
| Int n -> pr "int %s" n
| Int64 n -> pr "int64_t %s" n
@@ -3305,8 +3306,8 @@ let generate_include_libnbd_h () =
pr "#define LIBNBD_HAVE_NBD_GET_ERRNO 1\n";
pr "\n";
pr "extern int nbd_add_close_callback (struct nbd_handle *h,\n";
- pr " void *user_data,\n";
- pr " nbd_close_callback cb);\n";
+ pr " nbd_close_callback cb,\n";
+ pr " void *user_data);\n";
pr "#define LIBNBD_HAVE_NBD_ADD_CLOSE_CALLBACK 1\n";
pr "\n";
List.iter (
@@ -3593,7 +3594,7 @@ from other programming languages.
typedef void (*nbd_close_callback) (void *user_data);
int nbd_add_close_callback (struct nbd_handle *nbd,
- void *user_data, nbd_close_callback cb);
+ nbd_close_callback cb, void *user_data);
";
@@ -4112,11 +4113,11 @@ let print_python_binding name { args; ret } =
| BytesPersistIn (n, _)
| BytesPersistOut (n, _) -> pr ", %s_buf->data, %s_buf->len" n n
| Closure (_, cls) ->
- pr ", user_data";
List.iter (
fun { cbname } ->
pr ", %s_%s_wrapper" name cbname
- ) cls
+ ) cls;
+ pr ", user_data"
| Flags n -> pr ", %s_u32" n
| Int n -> pr ", %s" n
| Int64 n -> pr ", %s_i64" n
@@ -4195,7 +4196,7 @@ let print_python_binding name { args; ret } =
| Closure (false, _) -> ()
| Closure (true, _) ->
pr " /* This ensures the callback data is freed eventually. */\n";
- pr " nbd_add_close_callback (h, user_data, free_%s_user_data);\n" name
+ pr " nbd_add_close_callback (h, free_%s_user_data, user_data);\n" name
| Flags _ -> ()
| Int _ -> ()
| Int64 _ -> ()
@@ -4342,7 +4343,7 @@ class NBD (object):
| BytesIn (n, _) | BytesPersistIn (n, _) -> [n, None]
| BytesPersistOut (n, _) -> [n, None]
| BytesOut (_, count) -> [count, None]
- | Closure (_, cls) ->
+ | Closure (_, cls) ->
List.map (fun { cbname } -> cbname, None) cls
| Flags n -> [n, Some "0"]
| Int n -> [n, None]
@@ -4888,7 +4889,7 @@ let print_ocaml_binding (name, { args; ret }) =
(match has_closures with
| None | Some false -> ()
| Some true ->
- pr " nbd_add_close_callback (h, user_data, free_%s_user_data);\n" name
+ pr " nbd_add_close_callback (h, free_%s_user_data, user_data);\n" name
);
let errcode =
diff --git a/interop/dirty-bitmap.c b/interop/dirty-bitmap.c
index 6b7493e..8f0087d 100644
--- a/interop/dirty-bitmap.c
+++ b/interop/dirty-bitmap.c
@@ -137,14 +137,14 @@ main (int argc, char *argv[])
}
data = (struct data) { .count = 2, };
- if (nbd_block_status (nbd, exportsize, 0, &data, cb, 0) == -1) {
+ if (nbd_block_status (nbd, exportsize, 0, cb, &data, 0) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
exit (EXIT_FAILURE);
}
assert (data.seen_base && data.seen_dirty);
data = (struct data) { .req_one = true, .count = 2, };
- if (nbd_block_status (nbd, exportsize, 0, &data, cb,
+ if (nbd_block_status (nbd, exportsize, 0, cb, &data,
LIBNBD_CMD_FLAG_REQ_ONE) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
exit (EXIT_FAILURE);
@@ -153,7 +153,7 @@ main (int argc, char *argv[])
/* Trigger a failed callback, to prove connection stays up. */
data = (struct data) { .count = 2, .fail = true, };
- if (nbd_block_status (nbd, exportsize, 0, &data, cb, 0) != -1) {
+ if (nbd_block_status (nbd, exportsize, 0, cb, &data, 0) != -1) {
fprintf (stderr, "unexpected block status success\n");
exit (EXIT_FAILURE);
}
diff --git a/interop/structured-read.c b/interop/structured-read.c
index f9014c8..d00524f 100644
--- a/interop/structured-read.c
+++ b/interop/structured-read.c
@@ -143,7 +143,7 @@ main (int argc, char *argv[])
memset (rbuf, 2, sizeof rbuf);
data = (struct data) { .count = 2, };
- if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2048, &data, read_cb,
+ if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2048, read_cb, &data,
0) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
exit (EXIT_FAILURE);
@@ -153,7 +153,7 @@ main (int argc, char *argv[])
/* Repeat with DF flag. */
memset (rbuf, 2, sizeof rbuf);
data = (struct data) { .df = true, .count = 1, };
- if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2048, &data, read_cb,
+ if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2048, read_cb, &data,
LIBNBD_CMD_FLAG_DF) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
exit (EXIT_FAILURE);
@@ -166,7 +166,7 @@ main (int argc, char *argv[])
*/
memset (rbuf, 2, sizeof rbuf);
data = (struct data) { .count = 2, .fail = true, };
- if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2048, &data, read_cb,
+ if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2048, read_cb, &data,
0) != -1) {
fprintf (stderr, "unexpected pread callback success\n");
exit (EXIT_FAILURE);
diff --git a/lib/debug.c b/lib/debug.c
index 02d49f7..12c10f7 100644
--- a/lib/debug.c
+++ b/lib/debug.c
@@ -40,8 +40,8 @@ nbd_unlocked_get_debug (struct nbd_handle *h)
int
nbd_unlocked_set_debug_callback (struct nbd_handle *h,
- void *data,
- int (*debug_fn) (void *, const char *, const char *))
+ int (*debug_fn) (void *, const char *, const char *),
+ void *data)
{
h->debug_fn = debug_fn;
h->debug_data = data;
diff --git a/lib/handle.c b/lib/handle.c
index 00d0ac2..5003227 100644
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -203,7 +203,7 @@ nbd_unlocked_add_meta_context (struct nbd_handle *h, const char *name)
*/
int
nbd_add_close_callback (struct nbd_handle *h,
- void *user_data, nbd_close_callback cb)
+ nbd_close_callback cb, void *user_data)
{
int ret;
struct close_callback *cc;
diff --git a/lib/internal.h b/lib/internal.h
index 347bf69..5288ca0 100644
--- a/lib/internal.h
+++ b/lib/internal.h
@@ -80,8 +80,8 @@ struct nbd_handle {
/* For debugging. */
bool debug;
- void *debug_data;
int (*debug_fn) (void *, const char *, const char *);
+ void *debug_data;
/* Linked list of close callbacks. */
struct close_callback *close_callbacks;
@@ -249,12 +249,12 @@ typedef int (*read_fn) (void *user_data, const void *buf, size_t count,
typedef int (*callback_fn) (void *user_data, int64_t cookie, int *error);
struct command_cb {
- void *user_data;
union {
extent_fn extent;
read_fn read;
} fn;
callback_fn callback;
+ void *user_data;
};
struct command_in_flight {
diff --git a/lib/rw.c b/lib/rw.c
index f2fe4e0..d32f0dc 100644
--- a/lib/rw.c
+++ b/lib/rw.c
@@ -60,12 +60,12 @@ nbd_unlocked_pread (struct nbd_handle *h, void *buf,
int
nbd_unlocked_pread_structured (struct nbd_handle *h, void *buf,
size_t count, uint64_t offset,
- void *user_data, read_fn read, uint32_t flags)
+ read_fn read, void *user_data, uint32_t flags)
{
int64_t ch;
ch = nbd_unlocked_aio_pread_structured (h, buf, count, offset,
- user_data, read, flags);
+ read, user_data, flags);
if (ch == -1)
return -1;
@@ -145,11 +145,11 @@ nbd_unlocked_zero (struct nbd_handle *h,
int
nbd_unlocked_block_status (struct nbd_handle *h,
uint64_t count, uint64_t offset,
- void *user_data, extent_fn extent, uint32_t flags)
+ extent_fn extent, void *user_data, uint32_t flags)
{
int64_t ch;
- ch = nbd_unlocked_aio_block_status (h, count, offset, user_data, extent,
+ ch = nbd_unlocked_aio_block_status (h, count, offset, extent, user_data,
flags);
if (ch == -1)
return -1;
@@ -257,10 +257,10 @@ nbd_unlocked_aio_pread (struct nbd_handle *h, void *buf,
int64_t
nbd_unlocked_aio_pread_callback (struct nbd_handle *h, void *buf,
size_t count, uint64_t offset,
- void *user_data, callback_fn callback,
+ callback_fn callback, void *user_data,
uint32_t flags)
{
- struct command_cb cb = { .user_data = user_data, .callback = callback, };
+ struct command_cb cb = { .callback = callback, .user_data = user_data, };
/* We could silently accept flag DF, but it really only makes sense
* with callbacks, because otherwise there is no observable change
@@ -278,23 +278,22 @@ nbd_unlocked_aio_pread_callback (struct nbd_handle *h, void *buf,
int64_t
nbd_unlocked_aio_pread_structured (struct nbd_handle *h, void *buf,
size_t count, uint64_t offset,
- void *user_data, read_fn read,
+ read_fn read, void *user_data,
uint32_t flags)
{
return nbd_unlocked_aio_pread_structured_callback (h, buf, count, offset,
- user_data, read, NULL,
+ read, NULL, user_data,
flags);
}
int64_t
nbd_unlocked_aio_pread_structured_callback (struct nbd_handle *h, void *buf,
size_t count, uint64_t offset,
- void *user_data, read_fn read,
- callback_fn callback,
- uint32_t flags)
+ read_fn read, callback_fn callback,
+ void *user_data, uint32_t flags)
{
- struct command_cb cb = { .user_data = user_data, .fn.read = read,
- .callback = callback, };
+ struct command_cb cb = { .fn.read = read, .callback = callback,
+ .user_data = user_data, };
if ((flags & ~LIBNBD_CMD_FLAG_DF) != 0) {
set_error (EINVAL, "invalid flag: %" PRIu32, flags);
@@ -323,10 +322,10 @@ nbd_unlocked_aio_pwrite (struct nbd_handle *h, const void *buf,
int64_t
nbd_unlocked_aio_pwrite_callback (struct nbd_handle *h, const void *buf,
size_t count, uint64_t offset,
- void *user_data, callback_fn callback,
+ callback_fn callback, void *user_data,
uint32_t flags)
{
- struct command_cb cb = { .user_data = user_data, .callback = callback, };
+ struct command_cb cb = { .callback = callback, .user_data = user_data, };
if (nbd_unlocked_read_only (h) == 1) {
set_error (EINVAL, "server does not support write operations");
@@ -355,10 +354,10 @@ nbd_unlocked_aio_flush (struct nbd_handle *h, uint32_t flags)
}
int64_t
-nbd_unlocked_aio_flush_callback (struct nbd_handle *h, void *user_data,
- callback_fn callback, uint32_t flags)
+nbd_unlocked_aio_flush_callback (struct nbd_handle *h, callback_fn callback,
+ void *user_data, uint32_t flags)
{
- struct command_cb cb = { .user_data = user_data, .callback = callback, };
+ struct command_cb cb = { .callback = callback, .user_data = user_data, };
if (nbd_unlocked_can_flush (h) != 1) {
set_error (EINVAL, "server does not support flush operations");
@@ -385,10 +384,10 @@ nbd_unlocked_aio_trim (struct nbd_handle *h,
int64_t
nbd_unlocked_aio_trim_callback (struct nbd_handle *h,
uint64_t count, uint64_t offset,
- void *user_data, callback_fn callback,
+ callback_fn callback, void *user_data,
uint32_t flags)
{
- struct command_cb cb = { .user_data = user_data, .callback = callback, };
+ struct command_cb cb = { .callback = callback, .user_data = user_data, };
if (nbd_unlocked_read_only (h) == 1) {
set_error (EINVAL, "server does not support write operations");
@@ -425,10 +424,10 @@ nbd_unlocked_aio_cache (struct nbd_handle *h,
int64_t
nbd_unlocked_aio_cache_callback (struct nbd_handle *h,
uint64_t count, uint64_t offset,
- void *user_data, callback_fn callback,
+ callback_fn callback, void *user_data,
uint32_t flags)
{
- struct command_cb cb = { .user_data = user_data, .callback = callback, };
+ struct command_cb cb = { .callback = callback, .user_data = user_data, };
/* Actually according to the NBD protocol document, servers do exist
* that support NBD_CMD_CACHE but don't advertise the
@@ -459,10 +458,10 @@ nbd_unlocked_aio_zero (struct nbd_handle *h,
int64_t
nbd_unlocked_aio_zero_callback (struct nbd_handle *h,
uint64_t count, uint64_t offset,
- void *user_data, callback_fn callback,
+ callback_fn callback, void *user_data,
uint32_t flags)
{
- struct command_cb cb = { .user_data = user_data, .callback = callback, };
+ struct command_cb cb = { .callback = callback, .user_data = user_data, };
if (nbd_unlocked_read_only (h) == 1) {
set_error (EINVAL, "server does not support write operations");
@@ -492,22 +491,22 @@ nbd_unlocked_aio_zero_callback (struct nbd_handle *h,
int64_t
nbd_unlocked_aio_block_status (struct nbd_handle *h,
uint64_t count, uint64_t offset,
- void *user_data, extent_fn extent,
+ extent_fn extent, void *user_data,
uint32_t flags)
{
return nbd_unlocked_aio_block_status_callback (h, count, offset,
- user_data, extent,
- NULL, flags);
+ extent, NULL, user_data,
+ flags);
}
int64_t
nbd_unlocked_aio_block_status_callback (struct nbd_handle *h,
uint64_t count, uint64_t offset,
- void *user_data, extent_fn extent,
- callback_fn callback, uint32_t flags)
+ extent_fn extent, callback_fn callback,
+ void *user_data, uint32_t flags)
{
- struct command_cb cb = { .user_data = user_data, .fn.extent = extent,
- .callback = callback, };
+ struct command_cb cb = { .fn.extent = extent, .callback = callback,
+ .user_data = user_data, };
if (!h->structured_replies) {
set_error (ENOTSUP, "server does not support structured replies");
diff --git a/tests/meta-base-allocation.c b/tests/meta-base-allocation.c
index 9b3ad1f..95e029b 100644
--- a/tests/meta-base-allocation.c
+++ b/tests/meta-base-allocation.c
@@ -100,19 +100,19 @@ main (int argc, char *argv[])
/* Read the block status. */
id = 1;
- if (nbd_block_status (nbd, 65536, 0, &id, check_extent, 0) == -1) {
+ if (nbd_block_status (nbd, 65536, 0, check_extent, &id, 0) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
exit (EXIT_FAILURE);
}
id = 2;
- if (nbd_block_status (nbd, 1024, 32768-512, &id, check_extent, 0) == -1) {
+ if (nbd_block_status (nbd, 1024, 32768-512, check_extent, &id, 0) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
exit (EXIT_FAILURE);
}
id = 3;
- if (nbd_block_status (nbd, 1024, 32768-512, &id, check_extent,
+ if (nbd_block_status (nbd, 1024, 32768-512, check_extent, &id,
LIBNBD_CMD_FLAG_REQ_ONE) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
exit (EXIT_FAILURE);
diff --git a/tests/oldstyle.c b/tests/oldstyle.c
index ab8b211..f4397d3 100644
--- a/tests/oldstyle.c
+++ b/tests/oldstyle.c
@@ -125,7 +125,7 @@ main (int argc, char *argv[])
/* Test again for callback operation. */
memset (rbuf, 0, sizeof rbuf);
if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2 * sizeof rbuf,
- &calls, pread_cb, 0) == -1) {
+ pread_cb, &calls, 0) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
exit (EXIT_FAILURE);
}
@@ -141,7 +141,7 @@ main (int argc, char *argv[])
/* Also test that callback errors are reflected correctly. */
if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2 * sizeof rbuf,
- &calls, pread_cb, 0) != -1) {
+ pread_cb, &calls, 0) != -1) {
fprintf (stderr, "%s: expected failure from callback\n", argv[0]);
exit (EXIT_FAILURE);
}
--
2.20.1
5 years, 4 months
[PATCH libnbd] generator: Swap parameters of nbd_add_close_callback.
by Richard W.M. Jones
The API changes from:
int nbd_add_close_callback (struct nbd_handle *h,
nbd_close_callback cb,
void *user_data);
to:
int nbd_add_close_callback (struct nbd_handle *h,
void *user_data,
nbd_close_callback cb);
The second way is consistent with how other callbacks work throughout
the API (ie. having the user_data passed first).
---
generator/generator | 10 +++++-----
lib/handle.c | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/generator/generator b/generator/generator
index 951349d..ed05ea9 100755
--- a/generator/generator
+++ b/generator/generator
@@ -3305,8 +3305,8 @@ let generate_include_libnbd_h () =
pr "#define LIBNBD_HAVE_NBD_GET_ERRNO 1\n";
pr "\n";
pr "extern int nbd_add_close_callback (struct nbd_handle *h,\n";
- pr " nbd_close_callback cb,\n";
- pr " void *user_data);\n";
+ pr " void *user_data,\n";
+ pr " nbd_close_callback cb);\n";
pr "#define LIBNBD_HAVE_NBD_ADD_CLOSE_CALLBACK 1\n";
pr "\n";
List.iter (
@@ -3593,7 +3593,7 @@ from other programming languages.
typedef void (*nbd_close_callback) (void *user_data);
int nbd_add_close_callback (struct nbd_handle *nbd,
- nbd_close_callback cb, void *user_data);
+ void *user_data, nbd_close_callback cb);
";
@@ -4195,7 +4195,7 @@ let print_python_binding name { args; ret } =
| Closure (false, _) -> ()
| Closure (true, _) ->
pr " /* This ensures the callback data is freed eventually. */\n";
- pr " nbd_add_close_callback (h, free_%s_user_data, user_data);\n" name
+ pr " nbd_add_close_callback (h, user_data, free_%s_user_data);\n" name
| Flags _ -> ()
| Int _ -> ()
| Int64 _ -> ()
@@ -4862,7 +4862,7 @@ let print_ocaml_binding (name, { args; ret }) =
(match has_closures with
| None | Some false -> ()
| Some true ->
- pr " nbd_add_close_callback (h, free_%s_user_data, user_data);\n" name
+ pr " nbd_add_close_callback (h, user_data, free_%s_user_data);\n" name
);
let errcode =
diff --git a/lib/handle.c b/lib/handle.c
index 5003227..00d0ac2 100644
--- a/lib/handle.c
+++ b/lib/handle.c
@@ -203,7 +203,7 @@ nbd_unlocked_add_meta_context (struct nbd_handle *h, const char *name)
*/
int
nbd_add_close_callback (struct nbd_handle *h,
- nbd_close_callback cb, void *user_data)
+ void *user_data, nbd_close_callback cb)
{
int ret;
struct close_callback *cc;
--
2.22.0
5 years, 4 months