[libnbd PATCH 00/18] wrap hand-written source code at 80 characters
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 This series wraps the non-generated C-language source code (*.c and *.h files) at 80 characters. "ocaml/helpers.c" remains overlong, but I couldn't find a way to wrap it: its single overlong line contains the comment /* For how we're getting the exception name, see: * https://github.com/libguestfs/libguestfs/blob/5d94be2583d557cfc7f8a8cfee7988... */ and even if I truncate the blob hash to 12 nibbles, the line remains too long. The following files are also too wide: include/libnbd.h lib/api.c lib/states-run.c lib/states.c lib/states.h lib/unlocked.h ocaml/nbd-c.c python/libnbdmod.c python/methods.h but they are all generated; we'll have to discuss them separately. Laszlo Laszlo Ersek (18): examples/copy-libev: wrap source code at 80 characters examples/glib-main-loop: wrap source code at 80 characters examples/strict-structured-reads: wrap source code at 80 characters fuse/nbdfuse: wrap source code at 80 characters generator/states: wrap source code at 80 characters interop/{dirty-bitmap,structured-read}: wrap the source code at 80 chars interop/interop: wrap source code at 80 characters lib/internal.h: wrap source code at 80 characters lib/opt: wrap source code at 80 characters python/handle: wrap source code at 80 characters tests/closure-lifetimes: wrap source code at 80 characters tests/connect-uri: wrap source code at 80 characters tests/meta-base-allocation: wrap source code at 80 characters tests/newstyle-limited: wrap source code at 80 characters tests/oldstyle: wrap source code at 80 characters tests/requires: wrap source code at 80 characters ublk/nbdublk: wrap source code at 80 characters ublk/tgt: wrap source code at 80 characters examples/copy-libev.c | 8 ++-- examples/glib-main-loop.c | 6 ++- examples/strict-structured-reads.c | 11 +++-- fuse/nbdfuse.c | 4 +- generator/states-magic.c | 3 +- generator/states-newstyle-opt-go.c | 12 +++-- interop/dirty-bitmap.c | 12 ++--- interop/interop.c | 3 +- interop/structured-read.c | 15 +++---- lib/internal.h | 7 ++- lib/opt.c | 8 ++-- python/handle.c | 4 +- tests/closure-lifetimes.c | 47 ++++++++------------ tests/connect-uri.c | 3 +- tests/meta-base-allocation.c | 13 +++--- tests/newstyle-limited.c | 8 ++-- tests/oldstyle.c | 8 ++-- tests/requires.c | 16 ++++++- ublk/nbdublk.c | 4 +- ublk/tgt.c | 6 ++- 20 files changed, 106 insertions(+), 92 deletions(-) base-commit: 424420a55bab1a8ec9acffe684e0bbd0dc4ec45d
The invocation instructions for the copy-libev example are a bit too wide. The obvious wrapping ./copy-ev \ nbd+unix:///?socket=/tmp/src.sock \ nbd+unix:///?socket=/tmp/dst.sock is not desirable in a C-language comment, because the C standard places line splicing before comment squashing (translation phases #2 and #3, respectively). Therefore use shell variables. While at it, fix a small typo (from commit 6be6a9029abb, "examples: Add example for integrating with libev", 2021-03-01): the executable is called "copy-libev", not "copy-ev". Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- examples/copy-libev.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/copy-libev.c b/examples/copy-libev.c index 02f9cad492b9..32cb46b3d815 100644 --- a/examples/copy-libev.c +++ b/examples/copy-libev.c @@ -7,9 +7,11 @@ * * To run it: * - * nbdkit -r pattern size=1G -U /tmp/src.sock - * nbdkit memory size=1g -U /tmp/dst.sock - * ./copy-ev nbd+unix:///?socket=/tmp/src.sock nbd+unix:///?socket=/tmp/dst.sock + * SRC=/tmp/src.sock + * DST=/tmp/dst.sock + * nbdkit -r pattern size=1G -U $SRC + * nbdkit memory size=1g -U $DST + * ./copy-libev nbd+unix:///?socket=$SRC nbd+unix:///?socket=$DST * * To debug it: *
Insert straight-forward line breaks into some compound literals, for keeping the source code width <= 80 chars. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- examples/glib-main-loop.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/glib-main-loop.c b/examples/glib-main-loop.c index 1982f94131cc..8403a9708327 100644 --- a/examples/glib-main-loop.c +++ b/examples/glib-main-loop.c @@ -384,7 +384,8 @@ read_data (gpointer user_data) if (nbd_aio_pread (gssrc->nbd, buffers[i].data, BUFFER_SIZE, buffers[i].offset, - (nbd_completion_callback) { .callback = finished_read, .user_data = &buffers[i] }, + (nbd_completion_callback) { .callback = finished_read, + .user_data = &buffers[i] }, 0) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); @@ -431,7 +432,8 @@ write_data (gpointer user_data) buffer->state = BUFFER_WRITING; if (nbd_aio_pwrite (gsdest->nbd, buffer->data, BUFFER_SIZE, buffer->offset, - (nbd_completion_callback) { .callback = finished_write, .user_data = buffer }, + (nbd_completion_callback) { .callback = finished_write, + .user_data = buffer }, 0) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE);
These compound literals are hard to break down to short lines without making them look ugly (the type names would have to stand alone on a line); let's use normal local variables instead. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- examples/strict-structured-reads.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/strict-structured-reads.c b/examples/strict-structured-reads.c index 1c9664260654..a2596713f3cd 100644 --- a/examples/strict-structured-reads.c +++ b/examples/strict-structured-reads.c @@ -222,6 +222,11 @@ main (int argc, char *argv[]) struct data *d = malloc (sizeof *d); struct range *r = malloc (sizeof *r); uint64_t offset; + nbd_chunk_callback chunk_callback = { .callback = read_chunk, + .user_data = d }; + nbd_completion_callback completion_callback = { .callback = read_verify, + .user_data = d, + .free = free }; assert (d && r); offset = rand () % (exportsize - maxsize); @@ -230,10 +235,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 (nbd, buf, sizeof buf, offset, - (nbd_chunk_callback) { .callback = read_chunk, .user_data = d }, - (nbd_completion_callback) { .callback = read_verify, .user_data = d, .free = free }, - flags) == -1) { + if (nbd_aio_pread_structured (nbd, buf, sizeof buf, offset, chunk_callback, + completion_callback, flags) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); }
Beyond breaking up the long string in the error message, replace "parameter" with the more correct (pedantic...) "option-argument" term. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- fuse/nbdfuse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fuse/nbdfuse.c b/fuse/nbdfuse.c index 8efe2989d5e1..d3eca25632a6 100644 --- a/fuse/nbdfuse.c +++ b/fuse/nbdfuse.c @@ -229,8 +229,8 @@ main (int argc, char *argv[]) case 'C': if (sscanf (optarg, "%u", &connections) != 1 || connections < 1 || connections > 1024) { - fprintf (stderr, "%s: --connections parameter must be an unsigned integer >= 1\n", - argv[0]); + fprintf (stderr, "%s: --connections option-argument must be an " + "unsigned integer >= 1\n", argv[0]); exit (EXIT_FAILURE); } break;
Rewrap some error messages to keep the source code width at most 80 chars. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- generator/states-magic.c | 3 ++- generator/states-newstyle-opt-go.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/generator/states-magic.c b/generator/states-magic.c index b06057b5acd8..7928959ff86c 100644 --- a/generator/states-magic.c +++ b/generator/states-magic.c @@ -53,7 +53,8 @@ MAGIC.CHECK_MAGIC: } else { SET_NEXT_STATE (%.DEAD); - set_error (0, "handshake: server is not either an oldstyle or fixed newstyle NBD server"); + set_error (0, "handshake: server is not either an oldstyle or fixed " + "newstyle NBD server"); return 0; } return 0; diff --git a/generator/states-newstyle-opt-go.c b/generator/states-newstyle-opt-go.c index ffd7233985d6..2ef440d43095 100644 --- a/generator/states-newstyle-opt-go.c +++ b/generator/states-newstyle-opt-go.c @@ -163,7 +163,8 @@ NEWSTYLE.OPT_GO.CHECK_REPLY: case NBD_INFO_EXPORT: if (len != sizeof h->sbuf.or.payload.export) { SET_NEXT_STATE (%.DEAD); - set_error (0, "handshake: incorrect NBD_INFO_EXPORT option reply length"); + set_error (0, "handshake: incorrect NBD_INFO_EXPORT option reply " + "length"); return 0; } exportsize = be64toh (h->sbuf.or.payload.export.exportsize); @@ -176,7 +177,8 @@ NEWSTYLE.OPT_GO.CHECK_REPLY: case NBD_INFO_BLOCK_SIZE: if (len != sizeof h->sbuf.or.payload.block_size) { SET_NEXT_STATE (%.DEAD); - set_error (0, "handshake: incorrect NBD_INFO_BLOCK_SIZE option reply length"); + set_error (0, "handshake: incorrect NBD_INFO_BLOCK_SIZE option " + "reply length"); return 0; } min = be32toh (h->sbuf.or.payload.block_size.minimum); @@ -191,7 +193,8 @@ NEWSTYLE.OPT_GO.CHECK_REPLY: if (len > sizeof h->sbuf.or.payload.name_desc.info + NBD_MAX_STRING || len < sizeof h->sbuf.or.payload.name_desc.info) { SET_NEXT_STATE (%.DEAD); - set_error (0, "handshake: incorrect NBD_INFO_NAME option reply length"); + set_error (0, "handshake: incorrect NBD_INFO_NAME option reply " + "length"); return 0; } free (h->canonical_name); @@ -206,7 +209,8 @@ NEWSTYLE.OPT_GO.CHECK_REPLY: if (len > sizeof h->sbuf.or.payload.name_desc.info + NBD_MAX_STRING || len < sizeof h->sbuf.or.payload.name_desc.info) { SET_NEXT_STATE (%.DEAD); - set_error (0, "handshake: incorrect NBD_INFO_DESCRIPTION option reply length"); + set_error (0, "handshake: incorrect NBD_INFO_DESCRIPTION option " + "reply length"); return 0; } free (h->description);
On Tue, Apr 18, 2023 at 07:26:18PM +0200, Laszlo Ersek wrote:
Rewrap some error messages to keep the source code width at most 80 chars.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- generator/states-magic.c | 3 ++- generator/states-newstyle-opt-go.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/generator/states-magic.c b/generator/states-magic.c index b06057b5acd8..7928959ff86c 100644 --- a/generator/states-magic.c +++ b/generator/states-magic.c @@ -53,7 +53,8 @@ MAGIC.CHECK_MAGIC: } else { SET_NEXT_STATE (%.DEAD); - set_error (0, "handshake: server is not either an oldstyle or fixed newstyle NBD server"); + set_error (0, "handshake: server is not either an oldstyle or fixed " + "newstyle NBD server");
The term 'fixed newstyle' has enough relevance on its own in the protocol that I might wrap one word earlier to keep that phrasing together; but I'm not opposed to your patch going in as-is. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On 4/18/23 22:16, Eric Blake wrote:
On Tue, Apr 18, 2023 at 07:26:18PM +0200, Laszlo Ersek wrote:
Rewrap some error messages to keep the source code width at most 80 chars.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- generator/states-magic.c | 3 ++- generator/states-newstyle-opt-go.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/generator/states-magic.c b/generator/states-magic.c index b06057b5acd8..7928959ff86c 100644 --- a/generator/states-magic.c +++ b/generator/states-magic.c @@ -53,7 +53,8 @@ MAGIC.CHECK_MAGIC: } else { SET_NEXT_STATE (%.DEAD); - set_error (0, "handshake: server is not either an oldstyle or fixed newstyle NBD server"); + set_error (0, "handshake: server is not either an oldstyle or fixed " + "newstyle NBD server");
The term 'fixed newstyle' has enough relevance on its own in the protocol that I might wrap one word earlier to keep that phrasing together; but I'm not opposed to your patch going in as-is.
I'll update the patch. Thanks! Laszlo
In "dirty-bitmap.c", the "nbd_extent_callback" compound literals are not only too wide, they're also initialized with the same contents. Replace all three with a common local variable. The same applies to "structured-read.c", modulo the type being "nbd_chunk_callback". Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- interop/dirty-bitmap.c | 12 ++++-------- interop/structured-read.c | 15 +++++++-------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/interop/dirty-bitmap.c b/interop/dirty-bitmap.c index fc32e3352eaf..05f6e9db11ff 100644 --- a/interop/dirty-bitmap.c +++ b/interop/dirty-bitmap.c @@ -124,6 +124,7 @@ main (int argc, char *argv[]) struct nbd_handle *nbd; int64_t exportsize; struct data data; + nbd_extent_callback extent_callback = { .callback = cb, .user_data = &data }; char c; if (argc < 3) { @@ -153,17 +154,14 @@ main (int argc, char *argv[]) } data = (struct data) { .count = 2, }; - if (nbd_block_status (nbd, exportsize, 0, - (nbd_extent_callback) { .callback = cb, .user_data = &data }, - 0) == -1) { + if (nbd_block_status (nbd, exportsize, 0, extent_callback, 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, - (nbd_extent_callback) { .callback = cb, .user_data = &data }, + if (nbd_block_status (nbd, exportsize, 0, extent_callback, LIBNBD_CMD_FLAG_REQ_ONE) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); @@ -172,9 +170,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, - (nbd_extent_callback) { .callback = cb, .user_data = &data }, - 0) != -1) { + if (nbd_block_status (nbd, exportsize, 0, extent_callback, 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 c2e99c17b174..84eaab0baacc 100644 --- a/interop/structured-read.c +++ b/interop/structured-read.c @@ -106,6 +106,8 @@ main (int argc, char *argv[]) struct nbd_handle *nbd; int64_t exportsize; struct data data; + nbd_chunk_callback chunk_callback = { .callback = read_cb, + .user_data = &data }; char c; if (argc < 2) { @@ -141,9 +143,8 @@ main (int argc, char *argv[]) memset (rbuf, 2, sizeof rbuf); data = (struct data) { .count = 2, }; - if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2048, - (nbd_chunk_callback) { .callback = read_cb, .user_data = &data }, - 0) == -1) { + if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2048, chunk_callback, 0) == + -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } @@ -152,8 +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, - (nbd_chunk_callback) { .callback = read_cb, .user_data = &data }, + if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2048, chunk_callback, LIBNBD_CMD_FLAG_DF) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); @@ -166,9 +166,8 @@ 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, - (nbd_chunk_callback) { .callback = read_cb, .user_data = &data }, - 0) != -1) { + if (nbd_pread_structured (nbd, rbuf, sizeof rbuf, 2048, chunk_callback, 0) != + -1) { fprintf (stderr, "unexpected pread callback success\n"); exit (EXIT_FAILURE); }
Wrap a long error message. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- interop/interop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interop/interop.c b/interop/interop.c index 23212f8be82a..20e101d4ae73 100644 --- a/interop/interop.c +++ b/interop/interop.c @@ -191,7 +191,8 @@ main (int argc, char *argv[]) #if TLS_FALLBACK if (nbd_get_tls_negotiated (nbd) != 0) { fprintf (stderr, - "%s: TLS disabled, but connection didn't fall back to plaintext\n", + "%s: TLS disabled, but connection didn't fall back to " + "plaintext\n", argv[0]); exit (EXIT_FAILURE); }
(The changes in this patch are simple, but likely more controversial than the rest.) The following four components don't play nice together: - Needlessly spelling out "extern" for function declarations in header files. (C99 6.2.2p5: "If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern [...]".) - Long return type names. - Very long function names, such as "nbd_internal" + ("crypto_create_session" or "state_group_parent"). - Not placing function names seen in declarators (as opposed to those seen in definitions) at column #0, lest we confuse utilities that scan for "tags". Shorten lines by breaking the function names to new lines as well, but indent them to column #2. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/internal.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal.h b/lib/internal.h index 2de8e4e5e043..b155681d057f 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -407,7 +407,9 @@ extern int nbd_internal_wait_until_connected (struct nbd_handle *h) LIBNBD_ATTRIBUTE_NONNULL (1); /* crypto.c */ -extern struct socket *nbd_internal_crypto_create_session (struct nbd_handle *, struct socket *oldsock) +extern struct socket * + nbd_internal_crypto_create_session (struct nbd_handle *, + struct socket *oldsock) LIBNBD_ATTRIBUTE_NONNULL (1, 2); extern bool nbd_internal_crypto_is_reading (struct nbd_handle *) LIBNBD_ATTRIBUTE_NONNULL (1); @@ -504,7 +506,8 @@ extern int nbd_internal_run (struct nbd_handle *h, enum external_event ev) LIBNBD_ATTRIBUTE_NONNULL (1); extern const char *nbd_internal_state_short_string (enum state state); extern enum state_group nbd_internal_state_group (enum state state); -extern enum state_group nbd_internal_state_group_parent (enum state_group group); +extern enum state_group + nbd_internal_state_group_parent (enum state_group group); extern int nbd_internal_aio_get_direction (enum state state); #define set_next_state(h,next_state) ((h)->state) = (next_state)
On Tue, Apr 18, 2023 at 07:26:21PM +0200, Laszlo Ersek wrote:
(The changes in this patch are simple, but likely more controversial than the rest.)
The following four components don't play nice together:
- Needlessly spelling out "extern" for function declarations in header files. (C99 6.2.2p5: "If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern [...]".)
Well I didn't know that ...
- Long return type names.
- Very long function names, such as "nbd_internal" + ("crypto_create_session" or "state_group_parent").
- Not placing function names seen in declarators (as opposed to those seen in definitions) at column #0, lest we confuse utilities that scan for "tags".
Shorten lines by breaking the function names to new lines as well, but indent them to column #2.
As long as the first column doesn't have the function name, so I can still 'git grep ^function' to find the definition, it's fine. And that seems to be the case here. Rich.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/internal.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/internal.h b/lib/internal.h index 2de8e4e5e043..b155681d057f 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -407,7 +407,9 @@ extern int nbd_internal_wait_until_connected (struct nbd_handle *h) LIBNBD_ATTRIBUTE_NONNULL (1);
/* crypto.c */ -extern struct socket *nbd_internal_crypto_create_session (struct nbd_handle *, struct socket *oldsock) +extern struct socket * + nbd_internal_crypto_create_session (struct nbd_handle *, + struct socket *oldsock) LIBNBD_ATTRIBUTE_NONNULL (1, 2); extern bool nbd_internal_crypto_is_reading (struct nbd_handle *) LIBNBD_ATTRIBUTE_NONNULL (1); @@ -504,7 +506,8 @@ extern int nbd_internal_run (struct nbd_handle *h, enum external_event ev) LIBNBD_ATTRIBUTE_NONNULL (1); extern const char *nbd_internal_state_short_string (enum state state); extern enum state_group nbd_internal_state_group (enum state state); -extern enum state_group nbd_internal_state_group_parent (enum state_group group); +extern enum state_group + nbd_internal_state_group_parent (enum state_group group); extern int nbd_internal_aio_get_direction (enum state state);
#define set_next_state(h,next_state) ((h)->state) = (next_state)
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
On Wed, Apr 19, 2023 at 11:53:44AM +0100, Richard W.M. Jones wrote:
On Tue, Apr 18, 2023 at 07:26:21PM +0200, Laszlo Ersek wrote:
(The changes in this patch are simple, but likely more controversial than the rest.)
The following four components don't play nice together:
- Needlessly spelling out "extern" for function declarations in header files. (C99 6.2.2p5: "If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern [...]".)
Well I didn't know that ...
https://stackoverflow.com/questions/18171373/why-are-some-functions-declared... gives some more interesting details (including what happens if you declare a function more than once, using different specifiers across the declarations). I'm okay with dropping extern on functions if you want, but that can be a separate patch; leaving them doesn't hurt either (other than the line length issues where your line splitting techniques are fine).
+++ b/lib/internal.h @@ -407,7 +407,9 @@ extern int nbd_internal_wait_until_connected (struct nbd_handle *h) LIBNBD_ATTRIBUTE_NONNULL (1);
/* crypto.c */ -extern struct socket *nbd_internal_crypto_create_session (struct nbd_handle *, struct socket *oldsock) +extern struct socket * + nbd_internal_crypto_create_session (struct nbd_handle *, + struct socket *oldsock) LIBNBD_ATTRIBUTE_NONNULL (1, 2);
Looks reasonable to me. emacs may have a bit of a difficulty in auto-indenting this back to the same place, but it is infrequent enough that manual override is still viable. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On 4/19/23 15:19, Eric Blake wrote:
On Wed, Apr 19, 2023 at 11:53:44AM +0100, Richard W.M. Jones wrote:
On Tue, Apr 18, 2023 at 07:26:21PM +0200, Laszlo Ersek wrote:
(The changes in this patch are simple, but likely more controversial than the rest.)
The following four components don't play nice together:
- Needlessly spelling out "extern" for function declarations in header files. (C99 6.2.2p5: "If the declaration of an identifier for a function has no storage-class specifier, its linkage is determined exactly as if it were declared with the storage-class specifier extern [...]".)
Well I didn't know that ...
https://stackoverflow.com/questions/18171373/why-are-some-functions-declared...
gives some more interesting details (including what happens if you declare a function more than once, using different specifiers across the declarations).
In 2009, I constructed the following table, and I've been using it since: ----------------- Name space: ordinary identifiers Declaration | Scope | Linkage | Storage duration | Definition ------------------------+-------+--------------------------------------------------------------------+------------------------+-------------------------- int obj_1; | file | external ((6.1.2.2 p5) | static (6.1.2.4 p2) | tentative (6.7.2 p2) extern int obj_2; | file | same as any visible file scope declaration / external (6.1.2.2 p4) | static (6.1.2.4 p2)* | none (6.7.2) static int obj_3; | file | internal (6.1.2.2 p3) | static (6.1.2.4 p2) | tentative (6.7.2 p2) int obj_4 = 1; | file | external ((6.1.2.2 p5) | static (6.1.2.4 p2) | external (6.7.2 p1) extern int obj_5 = 1; | file | same as any visible file scope declaration / external (6.1.2.2 p4) | static (6.1.2.4 p2)* | external (6.7.2 p1) static int obj_6 = 1; | file | internal (6.1.2.2 p3) | static (6.1.2.4 p2) | external (6.7.2 p1) int fun_1(void); | file | same as any visible file scope declaration / external (6.1.2.2 p5) | n/a (6.1.2.4) | none (6.5 p4 fn56, 6.7.1) extern int fun_2(void); | file | same as any visible file scope declaration / external (6.1.2.2 p4) | n/a (6.1.2.4) | none (6.5 p4 fn56, 6.7.1) static int fun_3(void); | file | internal (6.1.2.2 p3) | n/a (6.1.2.4) | none (6.5 p4 fn56, 6.7.1) ------------------------+-------+--------------------------------------------------------------------+------------------------+-------------------------- int obj_7; | block | none (6.1.2.2 p6) | automatic (6.1.2.4 p3) | yes (6.1.2.4 p3, 6.5 p4) extern int obj_8; | block | same as any visible file scope declaration / external (6.1.2.2 p4) | static (6.1.2.4 p2)* | none (6.7.2) static int obj_9; | block | none (6.1.2.2 p6) | static (6.1.2.4 p2) | yes (6.1.2.4 p2, 6.5 p4) int obj_10 = 1; | block | none (6.1.2.2 p6) | automatic (6.1.2.4 p3) | yes (6.1.2.4 p3, 6.5 p4) extern int obj_11 = 1; | block | INVALID (6.5.7 p4)** | INVALID | INVALID static int obj_12 = 1; | block | none (6.1.2.2 p6) | static (6.1.2.4 p2) | yes (6.1.2.4 p2, 6.5 p4) int fun_4(void); | block | same as any visible file scope declaration / external (6.1.2.2 p5) | n/a (6.1.2.4) | none (6.5 p4 fn56, 6.7.1) extern int fun_5(void); | block | same as any visible file scope declaration / external (6.1.2.2 p4) | n/a (6.1.2.4) | none (6.5 p4 fn56, 6.7.1) static int fun_6(void); | block | INVALID (6.1.2.2 p3 fn13, 6.5.1 p4) | INVALID | INVALID * any visible file scope declaration can only specify either external or internal linkage ** such a declaration would specify "same as any visible file scope declaration / external (6.1.2.2 p4)" linkage, that is, external or internal (see *) ----------------- All the references are to C89, unfortunately. I've never gotten around updating them to C99. :/
I'm okay with dropping extern on functions if you want, but that can be a separate patch; leaving them doesn't hurt either (other than the line length issues where your line splitting techniques are fine).
Removing the "extern"s is too much churn :) We use them very consistently, and they are not "wrong" by any means. They're a bit uncomfortable in this case, but if the current patch is tolerable, I'd prefer it over a global de-extern-ing.
+++ b/lib/internal.h @@ -407,7 +407,9 @@ extern int nbd_internal_wait_until_connected (struct nbd_handle *h) LIBNBD_ATTRIBUTE_NONNULL (1);
/* crypto.c */ -extern struct socket *nbd_internal_crypto_create_session (struct nbd_handle *, struct socket *oldsock) +extern struct socket * + nbd_internal_crypto_create_session (struct nbd_handle *, + struct socket *oldsock) LIBNBD_ATTRIBUTE_NONNULL (1, 2);
Looks reasonable to me. emacs may have a bit of a difficulty in auto-indenting this back to the same place, but it is infrequent enough that manual override is still viable.
Thanks! I'll stick with this, then. Laszlo
We're down to truncating function parameter names in this one, with the functions being nbd_unlocked_aio_opt_list_meta_context_queries() and nbd_unlocked_aio_opt_set_meta_context_queries(). Note that I don't modify the declarations in "lib/unlocked.h": first, that file is generated, and I'm skipping generated files for now; second, the declarations and the definitions already call the last parameter differently ("completion_callback" vs. "complete"). Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- lib/opt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/opt.c b/lib/opt.c index ab3abf860c5c..f58d5e198365 100644 --- a/lib/opt.c +++ b/lib/opt.c @@ -467,10 +467,10 @@ int nbd_unlocked_aio_opt_list_meta_context_queries (struct nbd_handle *h, char **queries, nbd_context_callback *context, - nbd_completion_callback *complete) + nbd_completion_callback *compl) { return aio_opt_meta_context_queries (h, NBD_OPT_LIST_META_CONTEXT, - queries, context, complete); + queries, context, compl); } /* Issue NBD_OPT_SET_META_CONTEXT without waiting. */ @@ -488,8 +488,8 @@ int nbd_unlocked_aio_opt_set_meta_context_queries (struct nbd_handle *h, char **queries, nbd_context_callback *context, - nbd_completion_callback *complete) + nbd_completion_callback *compl) { return aio_opt_meta_context_queries (h, NBD_OPT_SET_META_CONTEXT, - queries, context, complete); + queries, context, compl); }
Wrap the message of the #error directive, based on the following (all excerpts from C99): - 5.1.1.2 Translation phases, p1, phase 2:
Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines. [...]"
- 5.1.1.2 Translation phases, p1, phase 3:
The source file is decomposed into preprocessing tokens [...] and sequences of white-space characters (including comments). [...] New-line characters are retained. Whether each nonempty sequence of white-space characters other than new-line is retained or replaced by one space character is implementation-defined.
- 6.10.5 Error directive, p1:
A preprocessing directive of the form
# error pp-tokens opt new-line
causes the implementation to produce a diagnostic message that includes the specified sequence of preprocessing tokens.
This means that the #error directive does not need a string literal (preprocessing tokens are a lower-level concept), and that we can break the sequence of pp-tokens to multiple physical lines with backslashes, and that an implementation may or may not squeeze our multiple space characters (even before the patch, after the full stop!) into single space characters. In practice, when forcing the #error post-patch, gcc prints (not wrapped here intentionally):
handle.c:29:2: error: #error These bindings will not work with Python 2. Recompile using Python 3 or use ./configure --disable-python. 29 | #error \ | ^~~~~
IOW, gcc does squeeze the space characters. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- python/handle.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/handle.c b/python/handle.c index 29a612bbe5f5..2b04cdcda89f 100644 --- a/python/handle.c +++ b/python/handle.c @@ -26,7 +26,9 @@ #include <Python.h> #if PY_MAJOR_VERSION == 2 -#error "These bindings will not work with Python 2. Recompile using Python 3 or use ./configure --disable-python." +#error \ + These bindings will not work with Python 2. \ + Recompile using Python 3 or use ./configure --disable-python. #endif #include <stdio.h>
The debug, chunk, extent, and completion callbacks are all created with multiplicated compound initializers. Introduce just one local variable for each callback structure, also bringing the width of the source file under 80 characters. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- tests/closure-lifetimes.c | 47 ++++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/tests/closure-lifetimes.c b/tests/closure-lifetimes.c index caf0ac275d42..9bb4e120847b 100644 --- a/tests/closure-lifetimes.c +++ b/tests/closure-lifetimes.c @@ -117,6 +117,14 @@ main (int argc, char *argv[]) struct nbd_handle *nbd; int64_t cookie; char buf[512]; + nbd_debug_callback debug_callback = { .callback = debug_fn, + .free = debug_fn_free }; + nbd_chunk_callback chunk_callback = { .callback = read_cb, + .free = read_cb_free }; + nbd_extent_callback extent_callback = { .callback = block_status_cb, + .free = block_status_cb_free }; + nbd_completion_callback completion_callback = { .callback = completion_cb, + .free = completion_cb_free }; /* Check debug functions are freed when a new debug function is * registered, and when the handle is closed. @@ -124,13 +132,10 @@ main (int argc, char *argv[]) nbd = nbd_create (); if (nbd == NULL) NBD_ERROR; - nbd_set_debug_callback (nbd, - (nbd_debug_callback) { .callback = debug_fn, - .free = debug_fn_free }); + nbd_set_debug_callback (nbd, debug_callback); assert (debug_fn_freed == 0); - nbd_set_debug_callback (nbd, (nbd_debug_callback) { .callback = debug_fn, - .free = debug_fn_free }); + nbd_set_debug_callback (nbd, debug_callback); assert (debug_fn_freed == 1); debug_fn_freed = 0; @@ -142,12 +147,8 @@ main (int argc, char *argv[]) if (nbd == NULL) NBD_ERROR; if (nbd_connect_command (nbd, nbdkit) == -1) NBD_ERROR; - cookie = nbd_aio_pread_structured (nbd, buf, sizeof buf, 0, - (nbd_chunk_callback) { .callback = read_cb, - .free = read_cb_free }, - (nbd_completion_callback) { .callback = completion_cb, - .free = completion_cb_free }, - 0); + cookie = nbd_aio_pread_structured (nbd, buf, sizeof buf, 0, chunk_callback, + completion_callback, 0); if (cookie == -1) NBD_ERROR; assert (read_cb_freed == 0); assert (completion_cb_freed == 0); @@ -172,12 +173,8 @@ main (int argc, char *argv[]) if (nbd == NULL) NBD_ERROR; if (nbd_connect_command (nbd, nbdkit_delay) == -1) NBD_ERROR; - cookie = nbd_aio_pread_structured (nbd, buf, sizeof buf, 0, - (nbd_chunk_callback) { .callback = read_cb, - .free = read_cb_free }, - (nbd_completion_callback) { .callback = completion_cb, - .free = completion_cb_free }, - 0); + cookie = nbd_aio_pread_structured (nbd, buf, sizeof buf, 0, chunk_callback, + completion_callback, 0); if (cookie == -1) NBD_ERROR; nbd_kill_subprocess (nbd, 0); nbd_close (nbd); @@ -195,12 +192,8 @@ main (int argc, char *argv[]) /* Intentionally omit a call to: * nbd_add_meta_context (nbd, LIBNBD_CONTEXT_BASE_ALLOCATION); */ - cookie = nbd_aio_block_status (nbd, sizeof buf, 0, - (nbd_extent_callback) { .callback = block_status_cb, - .free = block_status_cb_free }, - (nbd_completion_callback) { .callback = completion_cb, - .free = completion_cb_free }, - 0); + cookie = nbd_aio_block_status (nbd, sizeof buf, 0, extent_callback, + completion_callback, 0); if (cookie != -1) { fprintf (stderr, "%s: Expecting block_status failure\n", argv[0]); exit (EXIT_FAILURE); @@ -213,12 +206,8 @@ main (int argc, char *argv[]) if (nbd_connect_command (nbd, nbdkit) == -1) NBD_ERROR; - cookie = nbd_aio_block_status (nbd, sizeof buf, 0, - (nbd_extent_callback) { .callback = block_status_cb, - .free = block_status_cb_free }, - (nbd_completion_callback) { .callback = completion_cb, - .free = completion_cb_free }, - 0); + cookie = nbd_aio_block_status (nbd, sizeof buf, 0, extent_callback, + completion_callback, 0); if (cookie != -1) { fprintf (stderr, "%s: Expecting block_status failure\n", argv[0]); exit (EXIT_FAILURE);
On Tue, Apr 18, 2023 at 07:26:24PM +0200, Laszlo Ersek wrote:
The debug, chunk, extent, and completion callbacks are all created with multiplicated compound initializers. Introduce just one local variable for
I understand how you arrived at 'multiplicated', given 'duplicated' and 'triplicated' in other patches; but it still sounds funny to me and aspell doesn't like it. I think this is one case where 'duplicated' can be used in the sense of 'done more than once' rather than 'done twice' (even 'triplicate' as 'done thrice' is less frequently heard). Another alternative is 'repeated'. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On 4/19/23 15:30, Eric Blake wrote:
On Tue, Apr 18, 2023 at 07:26:24PM +0200, Laszlo Ersek wrote:
The debug, chunk, extent, and completion callbacks are all created with multiplicated compound initializers. Introduce just one local variable for
I understand how you arrived at 'multiplicated', given 'duplicated' and 'triplicated' in other patches; but it still sounds funny to me and aspell doesn't like it.
Sigh. I did invent the word, but then I did my homework -- or so I thought -- and verified it in wiktionary immediately: https://en.wiktionary.org/wiki/multiplicate#Verb ---------- Verb multiplicate (third-person singular simple present *multiplicates*, present participle *multiplicating*, simple past and past participle *multiplicated*) 1. To make multiple copies of ---------- And funnily enough, in Hungarian, we have perfectly matching words for "duplicated", "triplicated", *and* "multiplicated". What good is a dictionary if words it does *not* call archaic or obsolete sound funny to native speakers? /smh
I think this is one case where 'duplicated' can be used in the sense of 'done more than once' rather than 'done twice' (even 'triplicate' as 'done thrice' is less frequently heard). Another alternative is 'repeated'.
Thanks, I like "repeated". Laszlo
Break up a long error message. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- tests/connect-uri.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/connect-uri.c b/tests/connect-uri.c index 1896e289186b..f0fd18803a61 100644 --- a/tests/connect-uri.c +++ b/tests/connect-uri.c @@ -198,7 +198,8 @@ compare_uris (const char *uri1, const char *uri2) if (strstr (uri2, q) != NULL) r = 0; else { - fprintf (stderr, "error: compare_uris: query string '%s' does not appear in returned URI\n", q); + fprintf (stderr, "error: compare_uris: query string '%s' does not appear " + "in returned URI\n", q); r = 1; } free (q);
The extent callback struct is created with a triplicate compound initializer. Introduce just one local variable for the callback struct, also bringing the width of the source file under 80 characters. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- tests/meta-base-allocation.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/meta-base-allocation.c b/tests/meta-base-allocation.c index cc49ba41efee..a7b3af0967f8 100644 --- a/tests/meta-base-allocation.c +++ b/tests/meta-base-allocation.c @@ -43,6 +43,8 @@ main (int argc, char *argv[]) struct nbd_handle *nbd; char plugin_path[256]; int id; + nbd_extent_callback extent_callback = { .callback = check_extent, + .user_data = &id }; int r; const char *s; char *tmp; @@ -148,24 +150,19 @@ main (int argc, char *argv[]) /* Read the block status. */ id = 1; - if (nbd_block_status (nbd, 65536, 0, - (nbd_extent_callback) { .callback = check_extent, .user_data = &id }, - 0) == -1) { + if (nbd_block_status (nbd, 65536, 0, extent_callback, 0) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } id = 2; - if (nbd_block_status (nbd, 1024, 32768-512, - (nbd_extent_callback) { .callback = check_extent, .user_data = &id }, - 0) == -1) { + if (nbd_block_status (nbd, 1024, 32768-512, extent_callback, 0) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } id = 3; - if (nbd_block_status (nbd, 1024, 32768-512, - (nbd_extent_callback) { .callback = check_extent, .user_data = &id }, + if (nbd_block_status (nbd, 1024, 32768-512, extent_callback, LIBNBD_CMD_FLAG_REQ_ONE) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE);
The chunk callback struct is created with a duplicate compound initializer. Introduce just one local variable for the callback struct, also bringing the width of the source file under 80 characters. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- tests/newstyle-limited.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/newstyle-limited.c b/tests/newstyle-limited.c index b86e3614a859..eccca2a24145 100644 --- a/tests/newstyle-limited.c +++ b/tests/newstyle-limited.c @@ -113,6 +113,8 @@ main (int argc, char *argv[]) "can_write=exit 0", NULL }; int calls = 0; + nbd_chunk_callback chunk_callback = { .callback = pread_cb, + .user_data = &calls }; const char *s; progname = argv[0]; @@ -323,8 +325,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, - (nbd_chunk_callback) { .callback = pread_cb, .user_data = &calls }, - 0) == -1) { + chunk_callback, 0) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } @@ -340,8 +341,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, - (nbd_chunk_callback) { .callback = pread_cb, .user_data = &calls }, - 0) != -1) { + chunk_callback, 0) != -1) { fprintf (stderr, "%s: expected failure from callback\n", argv[0]); exit (EXIT_FAILURE); }
The chunk callback struct is created with a duplicate compound initializer. Introduce just one local variable for the callback struct, also bringing the width of the source file under 80 characters. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- tests/oldstyle.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/oldstyle.c b/tests/oldstyle.c index 46fd2a64fcb8..e67c428e63e2 100644 --- a/tests/oldstyle.c +++ b/tests/oldstyle.c @@ -84,6 +84,8 @@ main (int argc, char *argv[]) char *args[] = { "nbdkit", "-s", "-o", "--exit-with-parent", "-v", "memory", "size=" STR (SIZE), NULL }; int calls = 0; + nbd_chunk_callback chunk_callback = { .callback = pread_cb, + .user_data = &calls }; const char *s; progname = argv[0]; @@ -174,8 +176,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, - (nbd_chunk_callback) { .callback = pread_cb, .user_data = &calls }, - 0) == -1) { + chunk_callback, 0) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } @@ -191,8 +192,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, - (nbd_chunk_callback) { .callback = pread_cb, .user_data = &calls }, - 0) != -1) { + chunk_callback, 0) != -1) { fprintf (stderr, "%s: expected failure from callback\n", argv[0]); exit (EXIT_FAILURE); }
Embedding a shell script in a multi-line C string literal is an exercise in pain. I can see why the original author (whom I shall not look up with git-blame :) ) went for the easy route. Still, we want the source code to fit in 80 columns. Note: in my "interop/test-suite.log", I see
SKIP: interop-qemu-nbd-tls-certs ================================
requires test -d /home/lacos/src/v2v/libnbd/tests/pki Test skipped because prerequisite is missing or not working. SKIP interop-qemu-nbd-tls-certs (exit status: 77)
SKIP: interop-qemu-nbd-tls-psk ==============================
requires test -f /home/lacos/src/v2v/libnbd/tests/keys.psk Test skipped because prerequisite is missing or not working. SKIP interop-qemu-nbd-tls-psk (exit status: 77)
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- tests/requires.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/requires.c b/tests/requires.c index 199e30605473..cc5fd77b9f27 100644 --- a/tests/requires.c +++ b/tests/requires.c @@ -57,7 +57,13 @@ requires_qemu_nbd_tls_support (const char *qemu_nbd) * interested in the error message that it prints. */ snprintf (cmd, sizeof cmd, - "if %s --object tls-creds-x509,id=tls0 |& grep -sq 'TLS credentials support requires GNUTLS'; then exit 1; else exit 0; fi", + "if %s --object tls-creds-x509,id=tls0 \\\n" + " |& grep -sq 'TLS credentials support requires GNUTLS'\n" + "then\n" + " exit 1\n" + "else\n" + " exit 0\n" + "fi\n", qemu_nbd); requires (cmd); } @@ -72,7 +78,13 @@ requires_qemu_nbd_tls_psk_support (const char *qemu_nbd) * interested in the error message that it prints. */ snprintf (cmd, sizeof cmd, - "if %s --object tls-creds-psk,id=tls0 / |& grep -sq 'invalid object type'; then exit 1; else exit 0; fi", + "if %s --object tls-creds-psk,id=tls0 / \\\n" + " |& grep -sq 'invalid object type'\n" + "then\n" + " exit 1\n" + "else\n" + " exit 0\n" + "fi\n", qemu_nbd); requires (cmd); }
On Tue, Apr 18, 2023 at 07:26:29PM +0200, Laszlo Ersek wrote:
Embedding a shell script in a multi-line C string literal is an exercise in pain. I can see why the original author (whom I shall not look up with git-blame :) ) went for the easy route. Still, we want the source code to fit in 80 columns.
Note: in my "interop/test-suite.log", I see
SKIP: interop-qemu-nbd-tls-certs ================================
requires test -d /home/lacos/src/v2v/libnbd/tests/pki Test skipped because prerequisite is missing or not working. SKIP interop-qemu-nbd-tls-certs (exit status: 77)
SKIP: interop-qemu-nbd-tls-psk ==============================
requires test -f /home/lacos/src/v2v/libnbd/tests/keys.psk Test skipped because prerequisite is missing or not working. SKIP interop-qemu-nbd-tls-psk (exit status: 77)
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- tests/requires.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/tests/requires.c b/tests/requires.c index 199e30605473..cc5fd77b9f27 100644 --- a/tests/requires.c +++ b/tests/requires.c @@ -57,7 +57,13 @@ requires_qemu_nbd_tls_support (const char *qemu_nbd) * interested in the error message that it prints. */ snprintf (cmd, sizeof cmd, - "if %s --object tls-creds-x509,id=tls0 |& grep -sq 'TLS credentials support requires GNUTLS'; then exit 1; else exit 0; fi", + "if %s --object tls-creds-x509,id=tls0 \\\n" + " |& grep -sq 'TLS credentials support requires GNUTLS'\n"
Note: |& is a bashism; but system() might not invoke bash. So this is already non-portable code; and we should be fixing that. (I don't mind doing it as a followup if you end up pushing before seeing this message).
+ "then\n" + " exit 1\n" + "else\n" + " exit 0\n" + "fi\n",
For that matter, 'if ...; then exit 1; else exit 0; fi' can be compressed to '! ...'. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On 4/19/23 15:37, Eric Blake wrote:
On Tue, Apr 18, 2023 at 07:26:29PM +0200, Laszlo Ersek wrote:
Embedding a shell script in a multi-line C string literal is an exercise in pain. I can see why the original author (whom I shall not look up with git-blame :) ) went for the easy route. Still, we want the source code to fit in 80 columns.
Note: in my "interop/test-suite.log", I see
SKIP: interop-qemu-nbd-tls-certs ================================
requires test -d /home/lacos/src/v2v/libnbd/tests/pki Test skipped because prerequisite is missing or not working. SKIP interop-qemu-nbd-tls-certs (exit status: 77)
SKIP: interop-qemu-nbd-tls-psk ==============================
requires test -f /home/lacos/src/v2v/libnbd/tests/keys.psk Test skipped because prerequisite is missing or not working. SKIP interop-qemu-nbd-tls-psk (exit status: 77)
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- tests/requires.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/tests/requires.c b/tests/requires.c index 199e30605473..cc5fd77b9f27 100644 --- a/tests/requires.c +++ b/tests/requires.c @@ -57,7 +57,13 @@ requires_qemu_nbd_tls_support (const char *qemu_nbd) * interested in the error message that it prints. */ snprintf (cmd, sizeof cmd, - "if %s --object tls-creds-x509,id=tls0 |& grep -sq 'TLS credentials support requires GNUTLS'; then exit 1; else exit 0; fi", + "if %s --object tls-creds-x509,id=tls0 \\\n" + " |& grep -sq 'TLS credentials support requires GNUTLS'\n"
Note: |& is a bashism; but system() might not invoke bash. So this is already non-portable code; and we should be fixing that. (I don't mind doing it as a followup if you end up pushing before seeing this message).
I noticed |& too; my thought was "TIL". :)
+ "then\n" + " exit 1\n" + "else\n" + " exit 0\n" + "fi\n",
For that matter, 'if ...; then exit 1; else exit 0; fi' can be compressed to '! ...'.
Yes, I noticed that too, but I assumed there was a finer point I was missing. :/ I'll redo this patch then. Thanks! Laszlo
On Wed, Apr 19, 2023 at 03:53:57PM +0200, Laszlo Ersek wrote:
On 4/19/23 15:37, Eric Blake wrote:
On Tue, Apr 18, 2023 at 07:26:29PM +0200, Laszlo Ersek wrote:
Embedding a shell script in a multi-line C string literal is an exercise in pain. I can see why the original author (whom I shall not look up with git-blame :) ) went for the easy route. Still, we want the source code to fit in 80 columns.
Note: in my "interop/test-suite.log", I see
SKIP: interop-qemu-nbd-tls-certs ================================
requires test -d /home/lacos/src/v2v/libnbd/tests/pki Test skipped because prerequisite is missing or not working. SKIP interop-qemu-nbd-tls-certs (exit status: 77)
SKIP: interop-qemu-nbd-tls-psk ==============================
requires test -f /home/lacos/src/v2v/libnbd/tests/keys.psk Test skipped because prerequisite is missing or not working. SKIP interop-qemu-nbd-tls-psk (exit status: 77)
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- tests/requires.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/tests/requires.c b/tests/requires.c index 199e30605473..cc5fd77b9f27 100644 --- a/tests/requires.c +++ b/tests/requires.c @@ -57,7 +57,13 @@ requires_qemu_nbd_tls_support (const char *qemu_nbd) * interested in the error message that it prints. */ snprintf (cmd, sizeof cmd, - "if %s --object tls-creds-x509,id=tls0 |& grep -sq 'TLS credentials support requires GNUTLS'; then exit 1; else exit 0; fi", + "if %s --object tls-creds-x509,id=tls0 \\\n" + " |& grep -sq 'TLS credentials support requires GNUTLS'\n"
Note: |& is a bashism; but system() might not invoke bash. So this is already non-portable code; and we should be fixing that. (I don't mind doing it as a followup if you end up pushing before seeing this message).
I noticed |& too; my thought was "TIL". :)
+ "then\n" + " exit 1\n" + "else\n" + " exit 0\n" + "fi\n",
For that matter, 'if ...; then exit 1; else exit 0; fi' can be compressed to '! ...'.
Yes, I noticed that too, but I assumed there was a finer point I was missing. :/
I don't think there was anything deep here. If '!...' is the same then let's use that. Rich.
I'll redo this patch then.
Thanks! Laszlo _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com nbdkit - Flexible, fast NBD server with plugins https://gitlab.com/nbdkit/nbdkit
On 4/19/23 15:53, Laszlo Ersek wrote:
On 4/19/23 15:37, Eric Blake wrote:
On Tue, Apr 18, 2023 at 07:26:29PM +0200, Laszlo Ersek wrote:
Embedding a shell script in a multi-line C string literal is an exercise in pain. I can see why the original author (whom I shall not look up with git-blame :) ) went for the easy route. Still, we want the source code to fit in 80 columns.
Note: in my "interop/test-suite.log", I see
SKIP: interop-qemu-nbd-tls-certs ================================
requires test -d /home/lacos/src/v2v/libnbd/tests/pki Test skipped because prerequisite is missing or not working. SKIP interop-qemu-nbd-tls-certs (exit status: 77)
SKIP: interop-qemu-nbd-tls-psk ==============================
requires test -f /home/lacos/src/v2v/libnbd/tests/keys.psk Test skipped because prerequisite is missing or not working. SKIP interop-qemu-nbd-tls-psk (exit status: 77)
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- tests/requires.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/tests/requires.c b/tests/requires.c index 199e30605473..cc5fd77b9f27 100644 --- a/tests/requires.c +++ b/tests/requires.c @@ -57,7 +57,13 @@ requires_qemu_nbd_tls_support (const char *qemu_nbd) * interested in the error message that it prints. */ snprintf (cmd, sizeof cmd, - "if %s --object tls-creds-x509,id=tls0 |& grep -sq 'TLS credentials support requires GNUTLS'; then exit 1; else exit 0; fi", + "if %s --object tls-creds-x509,id=tls0 \\\n" + " |& grep -sq 'TLS credentials support requires GNUTLS'\n"
Note: |& is a bashism; but system() might not invoke bash. So this is already non-portable code; and we should be fixing that. (I don't mind doing it as a followup if you end up pushing before seeing this message).
I noticed |& too; my thought was "TIL". :)
+ "then\n" + " exit 1\n" + "else\n" + " exit 0\n" + "fi\n",
For that matter, 'if ...; then exit 1; else exit 0; fi' can be compressed to '! ...'.
Yes, I noticed that too, but I assumed there was a finer point I was missing. :/
Ah, it's not too relevant, but now I remember what was bothering me, about "!": if you embed the original construct in a "set -e" environment, it will exit with status 1 on the appropriate branch; but if you embed the "! ..." construct, it won't exit! Anyway, the context is not like that here. We pass the command string to system(), and I understand "set -e" is not in effect there. Laszlo
On Wed, Apr 19, 2023 at 05:27:45PM +0200, Laszlo Ersek wrote:
Yes, I noticed that too, but I assumed there was a finer point I was missing. :/
Ah, it's not too relevant, but now I remember what was bothering me, about "!": if you embed the original construct in a "set -e" environment, it will exit with status 1 on the appropriate branch; but if you embed the "! ..." construct, it won't exit!
Indeed, that's another reason to be cautious about ! at a top level. Most uses of ! are inside conditionals (such as if ! ...; then' where set -e already can't touch), whereas this snippet is indeed at a top level,...
Anyway, the context is not like that here. We pass the command string to system(), and I understand "set -e" is not in effect there.
...but you are correct that system() does not use 'set -e' automatically. Then again, since shell snippes run in Makefile ARE supposed to use implicit set -e, it never hurts to be vigilant about context when looking at shell snippets embedded in a larger file. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On Wed, Apr 19, 2023 at 03:53:57PM +0200, Laszlo Ersek wrote:
snprintf (cmd, sizeof cmd, - "if %s --object tls-creds-x509,id=tls0 |& grep -sq 'TLS credentials support requires GNUTLS'; then exit 1; else exit 0; fi", + "if %s --object tls-creds-x509,id=tls0 \\\n" + " |& grep -sq 'TLS credentials support requires GNUTLS'\n"
Note: |& is a bashism; but system() might not invoke bash. So this is already non-portable code; and we should be fixing that. (I don't mind doing it as a followup if you end up pushing before seeing this message).
I noticed |& too; my thought was "TIL". :)
+ "then\n" + " exit 1\n" + "else\n" + " exit 0\n" + "fi\n",
For that matter, 'if ...; then exit 1; else exit 0; fi' can be compressed to '! ...'.
Yes, I noticed that too, but I assumed there was a finer point I was missing. :/
autoconf still avoids it because of portability to Solaris /bin/sh (not /bin/xpg4/sh), which lacked !. But that's ancient history these days; ALL modern sh support ! correctly. (Note that support for '! command...' is different than 'test ! expr...', which itself has its own set of portability pitfalls that autoconf cares about; but that is yet another place where modern sh is now quite portable). -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Beyond breaking up the long string in the error message, replace "parameter" with the more correct (pedantic...) "option-argument" term. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- ublk/nbdublk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ublk/nbdublk.c b/ublk/nbdublk.c index 3c6ab90037fc..b079d577ae6f 100644 --- a/ublk/nbdublk.c +++ b/ublk/nbdublk.c @@ -196,8 +196,8 @@ main (int argc, char *argv[]) case 'C': if (sscanf (optarg, "%u", &connections) != 1 || connections < 1 || connections > 1024) { - fprintf (stderr, "%s: --connections parameter must be an unsigned integer >= 1\n", - argv[0]); + fprintf (stderr, "%s: --connections option-argument must be an " + "unsigned integer >= 1\n", argv[0]); exit (EXIT_FAILURE); } break;
Just break the initializers (for the local constant variables) to new lines, as seen elsewhere in "ublk/tgt.c" (in the context too, for example). Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- ublk/tgt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ublk/tgt.c b/ublk/tgt.c index a4a4748b4c03..77d396617fb2 100644 --- a/ublk/tgt.c +++ b/ublk/tgt.c @@ -268,7 +268,8 @@ static int set_parameters (struct ublksrv_ctrl_dev *ctrl_dev, const struct ublksrv_dev *dev) { - const struct ublksrv_ctrl_dev_info *dinfo = ublksrv_ctrl_get_dev_info (ctrl_dev); + const struct ublksrv_ctrl_dev_info *dinfo = + ublksrv_ctrl_get_dev_info (ctrl_dev); const unsigned attrs = (readonly ? UBLK_ATTR_READ_ONLY : 0) | (rotational ? UBLK_ATTR_ROTATIONAL : 0) | @@ -308,7 +309,8 @@ set_parameters (struct ublksrv_ctrl_dev *ctrl_dev, int start_daemon (struct ublksrv_ctrl_dev *ctrl_dev) { - const struct ublksrv_ctrl_dev_info *dinfo = ublksrv_ctrl_get_dev_info (ctrl_dev); + const struct ublksrv_ctrl_dev_info *dinfo = + ublksrv_ctrl_get_dev_info (ctrl_dev); const struct ublksrv_dev *dev; size_t i; int r;
Looks fine. I agree with Eric about "newstyle fixed", that ought not to be split. For the series: Reviewed-by: Richard W.M. Jones <rjones@redhat.com> Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
On 4/19/23 12:56, Richard W.M. Jones wrote:
Looks fine. I agree with Eric about "newstyle fixed", that ought not to be split. For the series:
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Thanks! I'll wait some more to see if Eric has further notes. Cheers! Laszlo
On Tue, Apr 18, 2023 at 07:26:13PM +0200, Laszlo Ersek wrote:
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516
[I started this email yesterday, then postponed it while looking at individual patches...]
This series wraps the non-generated C-language source code (*.c and *.h files) at 80 characters.
"ocaml/helpers.c" remains overlong, but I couldn't find a way to wrap it: its single overlong line contains the comment
/* For how we're getting the exception name, see: * https://github.com/libguestfs/libguestfs/blob/5d94be2583d557cfc7f8a8cfee7988... */
and even if I truncate the blob hash to 12 nibbles, the line remains too long.
Truncating is fine to reduce the worst of the width, but I also understand your reluctance to trim too short (git defaults to 7 nibbles in a fresh repository, but larger repositories like linux.git output at least 10 nibbles and sometimes more because there are just that many more hash prefix collisions as history grows - it's never fun when a link valid today stops working tomorrow when a prefix collision is introduced into the repo). At any rate, I have no problems with long URLs in source files that are otherwise length-constrained.
The following files are also too wide:
include/libnbd.h lib/api.c lib/states-run.c lib/states.c lib/states.h lib/unlocked.h ocaml/nbd-c.c python/libnbdmod.c python/methods.h
but they are all generated; we'll have to discuss them separately.
Wrapping a generated file for legibility is definitely harder work; legible generated code still has its benefits, but longer generated lines for faster coding of the generator is a tolerable tradeoff in my book. Overall, the series looked okay to me at a first read through; I did spot some things on individual patches where I made comments, but they are of the nature where I'm also okay with you adding: Reviewed-by: Eric Blake <eblake@redhat.com> whether or not you touch things up. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On 4/19/23 15:40, Eric Blake wrote:
On Tue, Apr 18, 2023 at 07:26:13PM +0200, Laszlo Ersek wrote:
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516
[I started this email yesterday, then postponed it while looking at individual patches...]
This series wraps the non-generated C-language source code (*.c and *.h files) at 80 characters.
"ocaml/helpers.c" remains overlong, but I couldn't find a way to wrap it: its single overlong line contains the comment
/* For how we're getting the exception name, see: * https://github.com/libguestfs/libguestfs/blob/5d94be2583d557cfc7f8a8cfee7988... */
and even if I truncate the blob hash to 12 nibbles, the line remains too long.
Truncating is fine to reduce the worst of the width, but I also understand your reluctance to trim too short (git defaults to 7 nibbles in a fresh repository, but larger repositories like linux.git output at least 10 nibbles and sometimes more because there are just that many more hash prefix collisions as history grows - it's never fun when a link valid today stops working tomorrow when a prefix collision is introduced into the repo). At any rate, I have no problems with long URLs in source files that are otherwise length-constrained.
Right, I seem to remember Linux now recommends capturing 12 nibbles.
The following files are also too wide:
include/libnbd.h lib/api.c lib/states-run.c lib/states.c lib/states.h lib/unlocked.h ocaml/nbd-c.c python/libnbdmod.c python/methods.h
but they are all generated; we'll have to discuss them separately.
Wrapping a generated file for legibility is definitely harder work; legible generated code still has its benefits, but longer generated lines for faster coding of the generator is a tolerable tradeoff in my book.
So Rich pointed out in <https://bugzilla.redhat.com/show_bug.cgi?id=2172516#c3> that the generator already had wrapping goodies. The problem that made me put generated code aside immediately was not a lack of wrapping; instead, the code was nicely wrapped (such that I couldn't improve it even by manually tweaking the result!), but it was *still* too wide! Consider, from "include/libnbd.h": -------- extern int nbd_aio_opt_list_meta_context_queries (struct nbd_handle *h, char **queries, nbd_context_callback context_callback, nbd_completion_callback completion_callback) LIBNBD_ATTRIBUTE_NONNULL (1, 2); -------- That's 94 chars wide; even if we drop the "extern ", it remains 87 characters wide. :/ So I wanted to keep that discussion separate.
Overall, the series looked okay to me at a first read through; I did spot some things on individual patches where I made comments, but they are of the nature where I'm also okay with you adding:
Reviewed-by: Eric Blake <eblake@redhat.com>
whether or not you touch things up.
I'll go through the patches and see how I feel about just pushing them with the suggested updates, or posting v2. Thanks! Laszlo
On 4/19/23 16:01, Laszlo Ersek wrote:
On 4/19/23 15:40, Eric Blake wrote:
On Tue, Apr 18, 2023 at 07:26:13PM +0200, Laszlo Ersek wrote:
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2172516
[I started this email yesterday, then postponed it while looking at individual patches...]
This series wraps the non-generated C-language source code (*.c and *.h files) at 80 characters.
"ocaml/helpers.c" remains overlong, but I couldn't find a way to wrap it: its single overlong line contains the comment
/* For how we're getting the exception name, see: * https://github.com/libguestfs/libguestfs/blob/5d94be2583d557cfc7f8a8cfee7988... */
and even if I truncate the blob hash to 12 nibbles, the line remains too long.
Truncating is fine to reduce the worst of the width, but I also understand your reluctance to trim too short (git defaults to 7 nibbles in a fresh repository, but larger repositories like linux.git output at least 10 nibbles and sometimes more because there are just that many more hash prefix collisions as history grows - it's never fun when a link valid today stops working tomorrow when a prefix collision is introduced into the repo). At any rate, I have no problems with long URLs in source files that are otherwise length-constrained.
Right, I seem to remember Linux now recommends capturing 12 nibbles.
The following files are also too wide:
include/libnbd.h lib/api.c lib/states-run.c lib/states.c lib/states.h lib/unlocked.h ocaml/nbd-c.c python/libnbdmod.c python/methods.h
but they are all generated; we'll have to discuss them separately.
Wrapping a generated file for legibility is definitely harder work; legible generated code still has its benefits, but longer generated lines for faster coding of the generator is a tolerable tradeoff in my book.
So Rich pointed out in <https://bugzilla.redhat.com/show_bug.cgi?id=2172516#c3> that the generator already had wrapping goodies.
The problem that made me put generated code aside immediately was not a lack of wrapping; instead, the code was nicely wrapped (such that I couldn't improve it even by manually tweaking the result!), but it was *still* too wide! Consider, from "include/libnbd.h":
-------- extern int nbd_aio_opt_list_meta_context_queries (struct nbd_handle *h, char **queries, nbd_context_callback context_callback, nbd_completion_callback completion_callback) LIBNBD_ATTRIBUTE_NONNULL (1, 2); --------
That's 94 chars wide; even if we drop the "extern ", it remains 87 characters wide. :/
So I wanted to keep that discussion separate.
Overall, the series looked okay to me at a first read through; I did spot some things on individual patches where I made comments, but they are of the nature where I'm also okay with you adding:
Reviewed-by: Eric Blake <eblake@redhat.com>
whether or not you touch things up.
I'll go through the patches and see how I feel about just pushing them with the suggested updates, or posting v2.
I've pushed the series as commit range 1acdeec1a248..a458f0644de0, *except* patch #16 (I've updated patches #5 and #11). I'll post a v2 of patch #16. Thanks! Laszlo
participants (3)
-
Eric Blake -
Laszlo Ersek -
Richard W.M. Jones