From ea09ddbfb48b79aa1e39e720215a33c5e1b50c86 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sun, 4 Jan 2026 09:27:36 +0000 Subject: [PATCH] Rebase to nbdkit 1.46.1 Backport nbdkit_debug_hexdiff from nbdkit 1.47. resolves: RHEL-111242 Synchronize spec file with Fedora. vddk: Don't use FNM_PATHNAME when matching export parameter resolves: RHEL-122755 --- ...-to-C-man-pages-for-module-functions.patch | 143 +++++ ...mentation-for-module-functions-in-or.patch | 44 ++ ...er-Add-nbdkit_debug_hexdiff-function.patch | 538 ++++++++++++++++++ ...ay-differences-if-D-checkwrite.showd.patch | 254 +++++++++ ...g_hexdump.pod-Document-when-hexdiff-.patch | 33 ++ nbdkit.spec | 13 +- sources | 4 +- 7 files changed, 1023 insertions(+), 6 deletions(-) create mode 100644 0001-python-Link-to-C-man-pages-for-module-functions.patch create mode 100644 0002-python-Sort-documentation-for-module-functions-in-or.patch create mode 100644 0003-server-Add-nbdkit_debug_hexdiff-function.patch create mode 100644 0004-checkwrite-Display-differences-if-D-checkwrite.showd.patch create mode 100644 0005-docs-nbdkit_debug_hexdump.pod-Document-when-hexdiff-.patch diff --git a/0001-python-Link-to-C-man-pages-for-module-functions.patch b/0001-python-Link-to-C-man-pages-for-module-functions.patch new file mode 100644 index 0000000..d449d05 --- /dev/null +++ b/0001-python-Link-to-C-man-pages-for-module-functions.patch @@ -0,0 +1,143 @@ +From a54aedafc2738a4ce5cba078a9bfa632e3ced85b Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Sat, 3 Jan 2026 11:46:13 +0000 +Subject: [PATCH] python: Link to C man pages for module functions + +Since first writing the Python documentation, we now have much more +consistent coverage of the underlying C functions in separate man +pages, so link to those consistently here. + +(cherry picked from commit 458928a627718b30456c47300366137d1dc2c109) +--- + plugins/python/nbdkit-python-plugin.pod | 45 ++++++++++++++++++++----- + 1 file changed, 36 insertions(+), 9 deletions(-) + +diff --git a/plugins/python/nbdkit-python-plugin.pod b/plugins/python/nbdkit-python-plugin.pod +index 0bc99bdc..87750ea1 100644 +--- a/plugins/python/nbdkit-python-plugin.pod ++++ b/plugins/python/nbdkit-python-plugin.pod +@@ -119,46 +119,62 @@ methods in the C module: + Send a debug message to stderr or syslog if verbose messages are + enabled. + ++See: L ++ + =head3 C + + Disconnect from the client. If C is C then nbdkit will + disconnect the client immediately. + ++See: L ++ + =head3 C + + Return the export name negotiated with the client as a Unicode string. + Note this should not be trusted because the client can send whatever + it wants. + ++See: L ++ + =head3 C + + Returns C if the client completed TLS authentication, or + C if the connection is plaintext. + ++See: L ++ + =head3 C + + Sleep for seconds and nanoseconds. + ++See: L ++ + =head3 C + + Parse a human-readable boolean (such as "yes" or "false"), returning + C or C. Wraps the L function. + ++See: L ++ + =head3 C + + Parse a delay or sleep (such as "10ms") into a pair (sec, nsec). + Wraps the L function. + ++See: L ++ + =head3 C + +-Parse a string (such as "100M") into a size in bytes. Wraps the +-L C function. ++Parse a string (such as "100M") into a size in bytes. ++ ++See: L + + =head3 C + + Parse a string (such as "100%") into a probability, returning a +-floating point number. Wraps the L +-function. ++floating point number. ++ ++See: L + + =head3 C, + C, +@@ -171,22 +187,27 @@ Unix domain socket, and then only on some operating systems. The + security context is usually the SELinux label, IPSEC label or + NetLabel. + ++See: L, L, ++L and L ++ + =head3 C + + Return the client TLS Distinguished Name. +-See L. ++ ++See: L + + =head3 C + + Return the client certificate issuer's TLS Distinguished Name. +-See L. ++ ++See: L + + =head3 C + + Read a password from a config parameter. This returns the password as +-a Python C object. See L for more +-information on the different ways that the C parameter can be +-parsed. ++a Python C object. ++ ++See: L + + =head3 C + +@@ -201,15 +222,21 @@ C: + nbdkit.set_error(errno.EPERM) + raise RuntimeError() + ++See: L ++ + =head3 C + + Request asynchronous server shutdown. + ++See: L ++ + =head3 C + + Returns C if it is safe to interact with stdin and stdout + during the configuration phase. + ++See: L ++ + =head2 Module constants + + After C the following constants are available. These +-- +2.47.3 + diff --git a/0002-python-Sort-documentation-for-module-functions-in-or.patch b/0002-python-Sort-documentation-for-module-functions-in-or.patch new file mode 100644 index 0000000..33fc273 --- /dev/null +++ b/0002-python-Sort-documentation-for-module-functions-in-or.patch @@ -0,0 +1,44 @@ +From ed37c814307ad027529b052ce7a7a3d3d15cdc58 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Sat, 3 Jan 2026 11:54:07 +0000 +Subject: [PATCH] python: Sort documentation for module functions in order + +Updates: commit 02df929dd5ac7f24a969dd4e680b8cb50bf585a7 +(cherry picked from commit e4dd09af5e0f836f4b306274517f381c23f6e461) +--- + plugins/python/nbdkit-python-plugin.pod | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +diff --git a/plugins/python/nbdkit-python-plugin.pod b/plugins/python/nbdkit-python-plugin.pod +index 87750ea1..9ea00f5e 100644 +--- a/plugins/python/nbdkit-python-plugin.pod ++++ b/plugins/python/nbdkit-python-plugin.pod +@@ -163,12 +163,6 @@ Wraps the L function. + + See: L + +-=head3 C +- +-Parse a string (such as "100M") into a size in bytes. +- +-See: L +- + =head3 C + + Parse a string (such as "100%") into a probability, returning a +@@ -176,6 +170,12 @@ floating point number. + + See: L + ++=head3 C ++ ++Parse a string (such as "100M") into a size in bytes. ++ ++See: L ++ + =head3 C, + C, + C, +-- +2.47.3 + diff --git a/0003-server-Add-nbdkit_debug_hexdiff-function.patch b/0003-server-Add-nbdkit_debug_hexdiff-function.patch new file mode 100644 index 0000000..4b9e72f --- /dev/null +++ b/0003-server-Add-nbdkit_debug_hexdiff-function.patch @@ -0,0 +1,538 @@ +From b2305c7e16e37869c6c649444ac257298e6addc2 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 30 Dec 2025 15:24:13 +0000 +Subject: [PATCH] server: Add nbdkit_debug_hexdiff function + +Useful function for showing the differences between two buffers, +similar to the earlier nbdkit_debug_hexdump function. + +This also adds a test. + +(cherry picked from commit 753d8d468240e613f3d905282446011c31548e34) +--- + docs/Makefile.am | 1 + + docs/nbdkit-plugin.pod | 1 + + docs/nbdkit_debug.pod | 1 + + docs/nbdkit_debug_hexdiff.3 | 1 + + docs/nbdkit_debug_hexdump.pod | 25 ++++++- + include/nbdkit-common.h | 4 + + server/debug.c | 75 +++++++++++++++++-- + server/nbdkit.syms | 1 + + tests/Makefile.am | 21 ++++++ + tests/test-debug-hexdiff-plugin.c | 92 +++++++++++++++++++++++ + tests/test-debug-hexdiff.sh | 118 ++++++++++++++++++++++++++++++ + 11 files changed, 331 insertions(+), 9 deletions(-) + create mode 100644 docs/nbdkit_debug_hexdiff.3 + create mode 100755 tests/test-debug-hexdiff-plugin.c + create mode 100755 tests/test-debug-hexdiff.sh + +diff --git a/docs/Makefile.am b/docs/Makefile.am +index 240d9e1d..4ee6994c 100644 +--- a/docs/Makefile.am ++++ b/docs/Makefile.am +@@ -94,6 +94,7 @@ EXTRA_DIST = \ + # tarball. + non_generated_mans = \ + nbdkit_absolute_path.3 \ ++ nbdkit_debug_hexdiff.3 \ + nbdkit_disconnect.3 \ + nbdkit_parse_int8_t.3 \ + nbdkit_parse_int16_t.3 \ +diff --git a/docs/nbdkit-plugin.pod b/docs/nbdkit-plugin.pod +index 61deb63b..308364d4 100644 +--- a/docs/nbdkit-plugin.pod ++++ b/docs/nbdkit-plugin.pod +@@ -1624,6 +1624,7 @@ Utility functions provided by nbdkit for plugins and filters to use: + + L, + L, ++L, + L, + L, + L, +diff --git a/docs/nbdkit_debug.pod b/docs/nbdkit_debug.pod +index 43bb5a41..d58d9bda 100644 +--- a/docs/nbdkit_debug.pod ++++ b/docs/nbdkit_debug.pod +@@ -57,6 +57,7 @@ C was present in nbdkit 0.1.0. + =head1 SEE ALSO + + L, ++L, + L, + L, + L, +diff --git a/docs/nbdkit_debug_hexdiff.3 b/docs/nbdkit_debug_hexdiff.3 +new file mode 100644 +index 00000000..c1fe3540 +--- /dev/null ++++ b/docs/nbdkit_debug_hexdiff.3 +@@ -0,0 +1 @@ ++.so man3/nbdkit_debug_hexdump.3 +diff --git a/docs/nbdkit_debug_hexdump.pod b/docs/nbdkit_debug_hexdump.pod +index 035873a6..274380bf 100644 +--- a/docs/nbdkit_debug_hexdump.pod ++++ b/docs/nbdkit_debug_hexdump.pod +@@ -1,6 +1,7 @@ + =head1 NAME + +-nbdkit_debug_hexdump - display buffer in hexdump format ++nbdkit_debug_hexdump, ++nbdkit_debug_hexdiff - display buffer in hexdump format + + =head1 SYNOPSIS + +@@ -9,11 +10,15 @@ nbdkit_debug_hexdump - display buffer in hexdump format + void nbdkit_debug_hexdump (const void *buf, size_t len, + const char *prefix, uint64_t start); + ++ void nbdkit_debug_hexdiff (const void *buf1, const void *buf2, ++ size_t len, ++ const char *prefix, uint64_t start); ++ + =head1 DESCRIPTION + +-This function displays a buffer of binary data in canonical hexdump +-format, sending the output to the same place as L. +-For example: ++B displays a buffer of binary data in canonical ++hexdump format, sending the output to the same place as ++L. For example: + + char buf[33] = "12345678123456781234567812345678"; + nbdkit_debug_hexdump (buf, 32, "data: ", 0); +@@ -29,6 +34,17 @@ line of output. (This may be C or C<""> for no prefix). + An optional C may be given which changes the first offset + displayed in the output. + ++B displays the differences between two binary ++buffers (of the same length). ++ ++For rows which are the same in both buffers, the output is the same as ++above. For rows which are different it shows the first buffer in the ++first row (prefixed with C<->) and the differences in the second ++buffer in the second row (prefixed with C<+>): ++ ++ -00000000: 31 32 33 34 35 36 37 38 31 32 33 34 35 36 37 38 |1234567812345678| ++ +00000000: 39 38 37 36 34 33 32 | 9876 432| ++ + =head1 LANGUAGE BINDINGS + + (There are no language bindings of this function in the current version.) +@@ -43,6 +59,7 @@ L, + L, + L, + L, ++L, + L, + L. + +diff --git a/include/nbdkit-common.h b/include/nbdkit-common.h +index 8bc16ee3..d23fedb0 100644 +--- a/include/nbdkit-common.h ++++ b/include/nbdkit-common.h +@@ -131,6 +131,10 @@ NBDKIT_EXTERN_DECL (void, nbdkit_vdebug, + NBDKIT_EXTERN_DECL (char *, nbdkit_absolute_path, + (const char *path) + NBDKIT_ATTRIBUTE_NONNULL ((1))); ++NBDKIT_EXTERN_DECL (void, nbdkit_debug_hexdiff, ++ (const void *buf1, const void *buf2, size_t len, ++ const char *prefix, uint64_t start) ++ NBDKIT_ATTRIBUTE_NONNULL ((1, 2))); + NBDKIT_EXTERN_DECL (void, nbdkit_debug_hexdump, + (const void *buf, size_t len, + const char *prefix, uint64_t start) +diff --git a/server/debug.c b/server/debug.c +index 90ffc600..68c768fe 100644 +--- a/server/debug.c ++++ b/server/debug.c +@@ -201,12 +201,13 @@ hexdump_set_byte (struct hexdump_line *line, size_t i, uint8_t b) + + /* Send the final string to nbdkit_debug. */ + static inline void +-hexdump_emit_debug (struct hexdump_line *line, const char *prefix) ++hexdump_emit_debug (struct hexdump_line *line, ++ const char *prefix, const char *plusminus) + { + /* Start by splitting up the hex digits into two groups of 8. */ + line->hex[8*3-1] = '\0'; +- nbdkit_debug ("%s%s: %s %s |%s|", +- prefix ? : "", ++ nbdkit_debug ("%s%s%s: %s %s |%s|", ++ prefix ? : "", plusminus ? : "", + line->str_offset, line->hex, &line->hex[8*3], line->chars); + } + +@@ -235,7 +236,7 @@ nbdkit_debug_hexdump (const void *vbuf, size_t len, + line.offset++; + len--; + } +- hexdump_emit_debug (&line, prefix); ++ hexdump_emit_debug (&line, prefix, NULL); + } + + /* Aligned body and unaligned tail. */ +@@ -248,6 +249,70 @@ nbdkit_debug_hexdump (const void *vbuf, size_t len, + line.offset++; + len--; + } +- hexdump_emit_debug (&line, prefix); ++ hexdump_emit_debug (&line, prefix, NULL); ++ } ++} ++ ++NBDKIT_DLL_PUBLIC void ++nbdkit_debug_hexdiff (const void *vbuf1, const void *vbuf2, size_t len, ++ const char *prefix, uint64_t start) ++{ ++ if (!verbose) ++ return; ++ ++ struct hexdump_line line1 = { .offset = start }; ++ struct hexdump_line line2 = { .offset = start }; ++ const uint8_t *buf1 = vbuf1, *buf2 = vbuf2; ++ uint64_t skip; ++ bool differences; ++ size_t i; ++ ++ /* Unaligned head. */ ++ if (! IS_ALIGNED (line1.offset, 16)) { ++ hexdump_reset_line (&line1); ++ hexdump_reset_line (&line2); ++ skip = line1.offset % 16; ++ differences = false; ++ ++ for (i = skip; i < 16 && len > 0; ++i) { ++ hexdump_set_byte (&line1, i, *buf1); ++ if (*buf1 != *buf2) { ++ differences = true; ++ hexdump_set_byte (&line2, i, *buf2); ++ } ++ buf1++; ++ buf2++; ++ line1.offset++; ++ line2.offset++; ++ len--; ++ } ++ hexdump_emit_debug (&line1, prefix, differences ? "-" : " "); ++ if (differences) ++ hexdump_emit_debug (&line2, prefix, "+"); ++ } ++ ++ /* Aligned body and unaligned tail. */ ++ while (len > 0) { ++ assert (IS_ALIGNED (line1.offset, 16)); ++ assert (IS_ALIGNED (line2.offset, 16)); ++ hexdump_reset_line (&line1); ++ hexdump_reset_line (&line2); ++ differences = false; ++ ++ for (i = 0; i < 16 && len > 0; ++i) { ++ hexdump_set_byte (&line1, i, *buf1); ++ if (*buf1 != *buf2) { ++ differences = true; ++ hexdump_set_byte (&line2, i, *buf2); ++ } ++ buf1++; ++ buf2++; ++ line1.offset++; ++ line2.offset++; ++ len--; ++ } ++ hexdump_emit_debug (&line1, prefix, differences ? "-" : " "); ++ if (differences) ++ hexdump_emit_debug (&line2, prefix, "+"); + } + } +diff --git a/server/nbdkit.syms b/server/nbdkit.syms +index 239e6db1..c22356fb 100644 +--- a/server/nbdkit.syms ++++ b/server/nbdkit.syms +@@ -44,6 +44,7 @@ + nbdkit_context_get_backend; + nbdkit_context_set_next; + nbdkit_debug; ++ nbdkit_debug_hexdiff; + nbdkit_debug_hexdump; + nbdkit_disconnect; + nbdkit_error; +diff --git a/tests/Makefile.am b/tests/Makefile.am +index 759a5237..a887ac75 100644 +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -328,6 +328,7 @@ TESTS += \ + test-log-to-file-append.sh \ + test-at-file.sh \ + test-debug-hexdump.sh \ ++ test-debug-hexdiff.sh \ + $(NULL) + if !IS_WINDOWS + TESTS += \ +@@ -359,6 +360,8 @@ EXTRA_DIST += \ + test-export-handshake.sh \ + test-export-handshake-tls.sh \ + test-debug-flags.sh \ ++ test-debug-hexdiff.sh \ ++ test-debug-hexdiff-plugin.c \ + test-debug-hexdump.sh \ + test-debug-hexdump-plugin.c \ + test-disconnect-tls.sh \ +@@ -538,8 +541,10 @@ test_shutdown_plugin_la_LIBADD = $(IMPORT_LIBRARY_ON_WINDOWS) + # So we have to do this and add a dependency. + noinst_LTLIBRARIES += \ + test-debug-hexdump-plugin.la \ ++ test-debug-hexdiff-plugin.la \ + $(NULL) + test-debug-hexdump.sh: test-debug-hexdump-plugin.la ++test-debug-hexdiff.sh: test-debug-hexdiff-plugin.la + + test_debug_hexdump_plugin_la_SOURCES = \ + test-debug-hexdump-plugin.c \ +@@ -557,6 +562,22 @@ test_debug_hexdump_plugin_la_LDFLAGS = \ + $(NULL) + test_debug_hexdump_plugin_la_LIBADD = $(IMPORT_LIBRARY_ON_WINDOWS) + ++test_debug_hexdiff_plugin_la_SOURCES = \ ++ test-debug-hexdiff-plugin.c \ ++ $(top_srcdir)/include/nbdkit-plugin.h \ ++ $(NULL) ++test_debug_hexdiff_plugin_la_CPPFLAGS = \ ++ -I$(top_srcdir)/include \ ++ -I$(top_builddir)/include \ ++ $(NULL) ++test_debug_hexdiff_plugin_la_CFLAGS = $(WARNINGS_CFLAGS) ++# For use of the -rpath option, see: ++# https://lists.gnu.org/archive/html/libtool/2007-07/msg00067.html ++test_debug_hexdiff_plugin_la_LDFLAGS = \ ++ -module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \ ++ $(NULL) ++test_debug_hexdiff_plugin_la_LIBADD = $(IMPORT_LIBRARY_ON_WINDOWS) ++ + endif HAVE_PLUGINS + + # Test the header files can be included on their own. +diff --git a/tests/test-debug-hexdiff-plugin.c b/tests/test-debug-hexdiff-plugin.c +new file mode 100755 +index 00000000..89fe0de3 +--- /dev/null ++++ b/tests/test-debug-hexdiff-plugin.c +@@ -0,0 +1,92 @@ ++/* nbdkit ++ * Copyright Red Hat ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions are ++ * met: ++ * ++ * * Redistributions of source code must retain the above copyright ++ * notice, this list of conditions and the following disclaimer. ++ * ++ * * Redistributions in binary form must reproduce the above copyright ++ * notice, this list of conditions and the following disclaimer in the ++ * documentation and/or other materials provided with the distribution. ++ * ++ * * Neither the name of Red Hat nor the names of its contributors may be ++ * used to endorse or promote products derived from this software without ++ * specific prior written permission. ++ * ++ * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ++ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A ++ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR ++ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ++ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ++ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ++ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ++ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ++ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ++ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++ * SUCH DAMAGE. ++ */ ++ ++/* Plugin for testing nbdkit_debug_hexdiff. See nbdkit-debug-hexdiff.sh */ ++ ++#include ++ ++#include ++#include ++#include ++#include ++ ++#define NBDKIT_API_VERSION 2 ++#include ++ ++static const uint64_t size = 1024 * 1024; ++static uint8_t data[1024 * 1024]; ++ ++static void * ++hexdiff_open (int readonly) ++{ ++ return NBDKIT_HANDLE_NOT_NEEDED; ++} ++ ++static int64_t ++hexdiff_get_size (void *handle) ++{ ++ return size; ++} ++ ++#define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL ++ ++static int ++hexdiff_pread (void *handle, void *buf, uint32_t count, uint64_t offset, ++ uint32_t flags) ++{ ++ memcpy (buf, &data[offset], count); ++ return 0; ++} ++ ++static int ++hexdiff_pwrite (void *handle, const void *buf, uint32_t count, uint64_t offset, ++ uint32_t flags) ++{ ++ /* Show the differences between the existing data and what we are ++ * about to write. ++ */ ++ nbdkit_debug_hexdiff (&data[offset], buf, count, "DIFF: ", offset); ++ /* Update the RAM disk. */ ++ memcpy (&data[offset], buf, count); ++ return 0; ++} ++ ++static struct nbdkit_plugin plugin = { ++ .name = "hexdiff", ++ .version = PACKAGE_VERSION, ++ .open = hexdiff_open, ++ .get_size = hexdiff_get_size, ++ .pread = hexdiff_pread, ++ .pwrite = hexdiff_pwrite, ++}; ++ ++NBDKIT_REGISTER_PLUGIN (plugin) +diff --git a/tests/test-debug-hexdiff.sh b/tests/test-debug-hexdiff.sh +new file mode 100755 +index 00000000..99d0b1ff +--- /dev/null ++++ b/tests/test-debug-hexdiff.sh +@@ -0,0 +1,118 @@ ++#!/usr/bin/env bash ++# nbdkit ++# Copyright Red Hat ++# ++# Redistribution and use in source and binary forms, with or without ++# modification, are permitted provided that the following conditions are ++# met: ++# ++# * Redistributions of source code must retain the above copyright ++# notice, this list of conditions and the following disclaimer. ++# ++# * Redistributions in binary form must reproduce the above copyright ++# notice, this list of conditions and the following disclaimer in the ++# documentation and/or other materials provided with the distribution. ++# ++# * Neither the name of Red Hat nor the names of its contributors may be ++# used to endorse or promote products derived from this software without ++# specific prior written permission. ++# ++# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ++# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ++# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A ++# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR ++# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ++# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ++# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ++# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ++# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ++# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ++# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++# SUCH DAMAGE. ++ ++# Test nbdkit_debug_hexdiff function. ++# ++# We assume that the tests of nbdkit_debug_hexdump do most of the ++# heavy lifting as the two functions are very similar. This only ++# tests the different behaviour of hexdiff. ++ ++source ./functions.sh ++set -e ++set -x ++set -u ++ ++requires_run ++requires_nbdsh_uri ++requires diff --version ++requires $SED --version ++ ++plugin=.libs/test-debug-hexdiff-plugin.$SOEXT ++requires test -f $plugin ++ ++out=debug-hexdiff.out ++hexout=debug-hexdiff.hexout ++files="$out $hexout" ++rm -f $files ++cleanup_fn rm -f $files ++ ++define script <<'EOF' ++import os ++ ++# Write zeros over zeroes ++b = bytearray(32) ++h.pwrite(b, 0) ++ ++# Write 4 lines over zeroes ++b = b"1234567890abcdef" * 4 ++h.pwrite(b, 0) ++ ++# Partially overwrite second line ++b = b"56780000" ++h.pwrite(b, 20) ++ ++# Partially overwrite third and fourth lines ++b = b"56780000cdef1234555590" ++h.pwrite(b, 36) ++ ++EOF ++export script ++ ++define expected <<'EOF' ++# Write zeros over zeroes ++ 00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| ++ 00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| ++ ++# Write 4 lines over zeroes ++-00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +++00000000: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 |1234567890abcdef| ++-00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +++00000010: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 |1234567890abcdef| ++-00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +++00000020: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 |1234567890abcdef| ++-00000030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +++00000030: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 |1234567890abcdef| ++ ++# Partially overwrite second line ++-00000010: 35 36 37 38 39 30 61 62 | 567890ab | +++00000010: 30 30 30 | 0 00 | ++ ++# Partially overwrite third and fourth lines ++-00000020: 35 36 37 38 39 30 61 62 63 64 65 66 | 567890abcdef| +++00000020: 30 30 30 | 0 00 | ++-00000030: 31 32 33 34 35 36 37 38 39 30 |1234567890 | +++00000030: 35 35 35 | 555 | ++EOF ++ ++# Run nbdkit with the plugin and debug enabled. Capture the full ++# output including stderr so we can find the hexdump output. ++fail= ++nbdkit -f -v $plugin --run 'nbdsh -u "$uri" -c "$script"' >$out 2>&1 || fail=1 ++cat $out ++if test "$fail"; then exit 1; fi ++ ++# Get the hexdiff lines from the output. ++grep "DIFF: " < $out | $SED 's/.*DIFF: //' > $hexout ++cat $hexout ++ ++# Compare it to the expected output (in $expected variable). ++diff -u $hexout <(echo -n "$expected" | grep -v '^#' | grep -v '^$') +-- +2.47.3 + diff --git a/0004-checkwrite-Display-differences-if-D-checkwrite.showd.patch b/0004-checkwrite-Display-differences-if-D-checkwrite.showd.patch new file mode 100644 index 0000000..3a90dbd --- /dev/null +++ b/0004-checkwrite-Display-differences-if-D-checkwrite.showd.patch @@ -0,0 +1,254 @@ +From 99153ed5592c9a08c5d5c393a625c54a5a0ea0c0 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 30 Dec 2025 17:09:07 +0000 +Subject: [PATCH] checkwrite: Display differences if -D checkwrite.showdiffs=1 + is used + +Add a debug flag which shows the differences between what was written +and what we expected. + +(cherry picked from commit 6a1c92f6a30941f8a891e704eeb95296e6d5669a) +--- + filters/checkwrite/checkwrite.c | 27 +++++-- + .../checkwrite/nbdkit-checkwrite-filter.pod | 14 +++- + tests/Makefile.am | 2 + + tests/test-checkwrite-evil.sh | 80 +++++++++++++++++++ + tests/test-checkwrite-fail.sh | 1 + + tests/test-checkwrite.sh | 3 +- + 6 files changed, 120 insertions(+), 7 deletions(-) + create mode 100755 tests/test-checkwrite-evil.sh + +diff --git a/filters/checkwrite/checkwrite.c b/filters/checkwrite/checkwrite.c +index d5f20e54..44fb22aa 100644 +--- a/filters/checkwrite/checkwrite.c ++++ b/filters/checkwrite/checkwrite.c +@@ -108,9 +108,26 @@ checkwrite_can_multi_conn (nbdkit_next *next, + return 1; + } + ++NBDKIT_DLL_PUBLIC int checkwrite_debug_showdiffs = 0; ++ + static inline int +-data_does_not_match (int *err) ++data_does_not_match (int *err, ++ const void *expected, const void *actual, size_t count, ++ uint64_t offset) + { ++ if (checkwrite_debug_showdiffs) { ++ /* Caller passes expected == NULL to mean we expected zeroes. ++ * However hexdiff requires an actual buffer, so ... ++ */ ++ CLEANUP_FREE char *zerobuf = NULL; ++ ++ if (expected == NULL) ++ zerobuf = calloc (count, 1); ++ ++ if (expected || zerobuf) ++ nbdkit_debug_hexdiff (expected ? : zerobuf, actual, count, NULL, offset); ++ } ++ + *err = EIO; + nbdkit_error ("data written does not match expected"); + return -1; +@@ -137,8 +154,8 @@ checkwrite_pwrite (nbdkit_next *next, + return -1; + + /* If data written doesn't match data expected, inject EIO. */ +- if (memcmp (buf, expected, count) != 0) +- return data_does_not_match (err); ++ if (memcmp (expected, buf, count) != 0) ++ return data_does_not_match (err, expected, buf, count, offset); + + return 0; + } +@@ -207,7 +224,7 @@ checkwrite_trim_zero (nbdkit_next *next, + if (next->pread (next, buf, buflen, offset, 0, err) == -1) + return -1; + if (! is_zero (buf, buflen)) +- return data_does_not_match (err); ++ return data_does_not_match (err, NULL, buf, buflen, offset); + + count -= buflen; + offset += buflen; +@@ -243,7 +260,7 @@ checkwrite_trim_zero (nbdkit_next *next, + if (next->pread (next, buf, n, offset, 0, err) == -1) + return -1; + if (! is_zero (buf, n)) +- return data_does_not_match (err); ++ return data_does_not_match (err, NULL, buf, n, offset); + count -= n; + offset += n; + } +diff --git a/filters/checkwrite/nbdkit-checkwrite-filter.pod b/filters/checkwrite/nbdkit-checkwrite-filter.pod +index 6855d798..0689fb26 100644 +--- a/filters/checkwrite/nbdkit-checkwrite-filter.pod ++++ b/filters/checkwrite/nbdkit-checkwrite-filter.pod +@@ -4,7 +4,7 @@ nbdkit-checkwrite-filter - check writes match contents of plugin + + =head1 SYNOPSIS + +- nbdkit --filter=checkwrite PLUGIN ++ nbdkit --filter=checkwrite PLUGIN [-D checkwrite.showdiffs=1] + + =head1 DESCRIPTION + +@@ -59,6 +59,17 @@ with arbitrary plugins. + There are no parameters specific to this filter. Parameters are + passed through to the underlying plugin. + ++=head1 DEBUG FLAG ++ ++When both foreground mode and debugging are enabled (I<-fv>) you can ++get checkwrite to show the differences between what was written and ++what should have been written by adding: ++ ++ nbdkit -fv --filter=checkwrite -D checkwrite.showdiffs=1 [...] ++ ++For further information on the format used see ++L. ++ + =head1 FILES + + =over 4 +@@ -82,6 +93,7 @@ L, + L, + L, + L, ++L, + L, + L. + +diff --git a/tests/Makefile.am b/tests/Makefile.am +index a887ac75..beeb0fc3 100644 +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -1806,12 +1806,14 @@ EXTRA_DIST += \ + TESTS += \ + test-checkwrite.sh \ + test-checkwrite-bounds.sh \ ++ test-checkwrite-evil.sh \ + test-checkwrite-fail.sh \ + test-checkwrite-fastzero.sh \ + $(NULL) + EXTRA_DIST += \ + test-checkwrite.sh \ + test-checkwrite-bounds.sh \ ++ test-checkwrite-evil.sh \ + test-checkwrite-fail.sh \ + test-checkwrite-fastzero.sh \ + $(NULL) +diff --git a/tests/test-checkwrite-evil.sh b/tests/test-checkwrite-evil.sh +new file mode 100755 +index 00000000..2d9e25b4 +--- /dev/null ++++ b/tests/test-checkwrite-evil.sh +@@ -0,0 +1,80 @@ ++#!/usr/bin/env bash ++# nbdkit ++# Copyright Red Hat ++# ++# Redistribution and use in source and binary forms, with or without ++# modification, are permitted provided that the following conditions are ++# met: ++# ++# * Redistributions of source code must retain the above copyright ++# notice, this list of conditions and the following disclaimer. ++# ++# * Redistributions in binary form must reproduce the above copyright ++# notice, this list of conditions and the following disclaimer in the ++# documentation and/or other materials provided with the distribution. ++# ++# * Neither the name of Red Hat nor the names of its contributors may be ++# used to endorse or promote products derived from this software without ++# specific prior written permission. ++# ++# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND ++# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ++# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A ++# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR ++# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ++# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ++# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ++# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ++# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ++# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ++# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++# SUCH DAMAGE. ++ ++# Test checkwrite + evil filters together. ++ ++source ./functions.sh ++set -e ++set -x ++set -u ++ ++# Across a 1G disk, with the default failure probability of the evil ++# filter, we expect about 43 stuck high bits. The test actually fails ++# at the first stuck high bit so we don't end up grinding across the ++# whole virtual size. ++size=1G ++ ++requires_plugin null ++requires_filter checkwrite ++requires_filter evil ++requires_filter noextents ++ ++# nbdcopy >= 1.5.9 required for this test. ++requires_nbdcopy ++requires_libnbd_version 1.5.9 ++ ++sock1=$(mktemp -u /tmp/nbdkit-test-sock.XXXXXX) ++sock2=$(mktemp -u /tmp/nbdkit-test-sock.XXXXXX) ++pid1=checkwrite-evil.pid1 ++pid2=checkwrite-evil.pid2 ++files="$sock1 $sock2 $pid1 $pid2" ++rm -f $files ++cleanup_fn rm -f $files ++ ++# Source nbdkit. ++start_nbdkit -P $pid1 -U $sock1 \ ++ null $size \ ++ --filter=evil \ ++ --filter=noextents ++ ++# Target nbdkit. ++start_nbdkit -P $pid2 -U $sock2 \ ++ -v -D checkwrite.showdiffs=1 \ ++ null $size \ ++ --filter=checkwrite ++ ++fail= ++nbdcopy "nbd+unix:///?socket=$sock1" "nbd+unix:///?socket=$sock2" || fail=1 ++if ! test "$fail"; then ++ echo "$0: expected nbdcopy to fail but it did not" ++ exit 1 ++fi +diff --git a/tests/test-checkwrite-fail.sh b/tests/test-checkwrite-fail.sh +index d46c2865..c577b12d 100755 +--- a/tests/test-checkwrite-fail.sh ++++ b/tests/test-checkwrite-fail.sh +@@ -49,6 +49,7 @@ import sys + + h.connect_command(["nbdkit", "-s", "-v", + "--filter=checkwrite", ++ "-D", "checkwrite.showdiffs=1", + "memory", "1M"]) + try: + h.pwrite(b"1", 0) +diff --git a/tests/test-checkwrite.sh b/tests/test-checkwrite.sh +index aecb729c..490ab45b 100755 +--- a/tests/test-checkwrite.sh ++++ b/tests/test-checkwrite.sh +@@ -46,7 +46,8 @@ requires_libnbd_version 1.5.9 + + do_test () + { +- nbdkit -v --filter=checkwrite "$@" --run 'nbdcopy "$uri" "$uri"' ++ nbdkit -v --filter=checkwrite -D checkwrite.showdiffs=1 "$@" \ ++ --run 'nbdcopy "$uri" "$uri"' + } + + # Tests zero-sized disk. +-- +2.47.3 + diff --git a/0005-docs-nbdkit_debug_hexdump.pod-Document-when-hexdiff-.patch b/0005-docs-nbdkit_debug_hexdump.pod-Document-when-hexdiff-.patch new file mode 100644 index 0000000..48ea260 --- /dev/null +++ b/0005-docs-nbdkit_debug_hexdump.pod-Document-when-hexdiff-.patch @@ -0,0 +1,33 @@ +From abb8c973c47797fb8cdf0081fff3f20e28ce0862 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Tue, 30 Dec 2025 21:59:24 +0000 +Subject: [PATCH] docs/nbdkit_debug_hexdump.pod: Document when hexdiff was + added to nbdkit + +Not until the next stable branch, so 1.48. + +Fixes: commit 753d8d468240e613f3d905282446011c31548e34 + +Cherry picked from commit 7e9ec310d4149449229a8ddbb50395a3bdbd7227. +For RHEL 10.2, add a note that it was backported. +--- + docs/nbdkit_debug_hexdump.pod | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/docs/nbdkit_debug_hexdump.pod b/docs/nbdkit_debug_hexdump.pod +index 274380bf..4c4cae19 100644 +--- a/docs/nbdkit_debug_hexdump.pod ++++ b/docs/nbdkit_debug_hexdump.pod +@@ -53,6 +53,9 @@ buffer in the second row (prefixed with C<+>): + + C was added in nbdkit 1.46. + ++C was added in nbdkit 1.48 ++(and backported to RHEL 10.2). ++ + =head1 SEE ALSO + + L, +-- +2.47.3 + diff --git a/nbdkit.spec b/nbdkit.spec index 98959fd..fb302fa 100644 --- a/nbdkit.spec +++ b/nbdkit.spec @@ -54,7 +54,7 @@ %global source_directory 1.46-stable Name: nbdkit -Version: 1.46.0 +Version: 1.46.1 Release: 1%{?dist} Summary: NBD server @@ -80,7 +80,11 @@ Source3: copy-patches.sh # https://gitlab.com/nbdkit/nbdkit/-/commits/rhel-10.2/ # Patches. -#(nothing) +Patch0001: 0001-python-Link-to-C-man-pages-for-module-functions.patch +Patch0002: 0002-python-Sort-documentation-for-module-functions-in-or.patch +Patch0003: 0003-server-Add-nbdkit_debug_hexdiff-function.patch +Patch0004: 0004-checkwrite-Display-differences-if-D-checkwrite.showd.patch +Patch0005: 0005-docs-nbdkit_debug_hexdump.pod-Document-when-hexdiff-.patch # For automatic RPM Provides generation. # See: https://rpm-software-management.github.io/rpm/manual/dependency_generators.html @@ -1588,8 +1592,9 @@ fi %changelog -* Sat Dec 20 2025 Richard W.M. Jones - 1.46.0-1 -- Rebase to nbdkit 1.46.0 +* Sun Jan 04 2026 Richard W.M. Jones - 1.46.1-1 +- Rebase to nbdkit 1.46.1 +- Backport nbdkit_debug_hexdiff from nbdkit 1.47. resolves: RHEL-111242 - Synchronize spec file with Fedora. - vddk: Don't use FNM_PATHNAME when matching export parameter diff --git a/sources b/sources index 4462799..279ae3d 100644 --- a/sources +++ b/sources @@ -1,2 +1,2 @@ -SHA512 (nbdkit-1.46.0.tar.gz) = ed225bdbd5c1e96b40ed0493f72173853cedafc9ada2296e6418021d4e3f2e6732dbbb764d24baf6263f4b07c3868b05207518d34667fe68c7324360fc3f5254 -SHA512 (nbdkit-1.46.0.tar.gz.sig) = 73c37deac7f18c7a55d401bf569aabc0a017872fc8ed3e4554f32a1007367d6db975c80cdfc3310c3c13ebaf0c506fcf0563360ee663784a653852ec6bde0e3a +SHA512 (nbdkit-1.46.1.tar.gz) = 7a4223e4b22314dd711cfa09e24d248b02a084ffef35b4cd4df83f9c9e5c485abc1cd2dfc609be82ef2c35841259035b3a388dd0b779bf17d20318132da69747 +SHA512 (nbdkit-1.46.1.tar.gz.sig) = 53140ec57584b7f2946f193036fedd1ea232f6364f75716c11dfb6d6d9941a7a28d82a51d959ae1b7a075b36604c013182c10a9cab7f6ee3b58cba937b150e4c