Skip to content

zstream: consolidate shared code#18284

Merged
behlendorf merged 1 commit intoopenzfs:masterfrom
GarthSnyder:pr-zstream-dups
Mar 5, 2026
Merged

zstream: consolidate shared code#18284
behlendorf merged 1 commit intoopenzfs:masterfrom
GarthSnyder:pr-zstream-dups

Conversation

@GarthSnyder
Copy link
Contributor

zstream currently contains three identical copies of dump_record(), which ultimately appear to all have been drawn from libzfs_sendrecv.c. The original is marked internal and so can't be referenced directly, although exposing that API might be a good idea. (At least in theory...)

This PR adds zstream_util.[hc] and puts the shared code there along with a couple of other items in common.

No functional changes.

Notes

I used the libzfs version of dump_record() as the shared code. It is identical to the zstream versions except that the payload length is a size_t rather than an int and it uses the uppercase assertion macros.

How Has This Been Tested?

Compiles and runs with no errors.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Quality assurance (non-breaking change which makes the code more robust against bugs)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

Copilot AI review requested due to automatic review settings March 5, 2026 02:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors cmd/zstream to remove duplicated helper implementations by introducing a shared zstream_util.[ch] module, intended to centralize common helpers (notably dump_record() plus “safe_” helpers) used across multiple zstream subcommands.

Changes:

  • Add new zstream_util.c/.h containing shared helpers (e.g., dump_record(), safe_malloc(), safe_calloc(), sfread()).
  • Replace per-file copies of these helpers in zstream_{redup,recompress,decompress,dump}.c with calls to the shared module.
  • Update build inputs (Makefile.am) and exported declarations (zstream.h) accordingly.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
cmd/zstream/zstream_util.h New shared header for zstream utility helpers.
cmd/zstream/zstream_util.c New shared implementation of dump_record() and “safe_” IO/allocation helpers.
cmd/zstream/zstream_redup.c Removes local helper copies; uses zstream_util.h.
cmd/zstream/zstream_recompress.c Removes local dump_record(); uses shared implementation.
cmd/zstream/zstream_decompress.c Removes local dump_record(); uses shared implementation.
cmd/zstream/zstream_dump.c Removes local safe_malloc(); uses shared implementation.
cmd/zstream/zstream.h Stops exporting utility helper prototypes from the main zstream header.
cmd/zstream/Makefile.am Builds/ships the new shared utility module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings March 5, 2026 04:13
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

zstream currently contains three identical copies of dump_record(),
which appear to all be drawn from libzfs_sendrecv.c. The original
is marked internal.

This PR adds zstream_util.[hc] and puts the shared code there along with
a couple of other items in common.

No functional changes.

UPDATED to address Copilot issues and checkstyle.

Signed-off-by: Garth Snyder <garth@garthsnyder.com>
Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find, and thanks for the cleanup. I'd prefer not to add another symbol to the libzfs ABI for now, even if zstream already links against libzfs, so your approach here makes good sense to me.

@behlendorf behlendorf added the Status: Accepted Ready to integrate (reviewed, tested) label Mar 5, 2026
@behlendorf behlendorf merged commit d979457 into openzfs:master Mar 5, 2026
38 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Accepted Ready to integrate (reviewed, tested)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants