Skip to content

Improve libzfs api for zfs diff and add JSON support#18299

Open
anodos325 wants to merge 1 commit intoopenzfs:masterfrom
truenas:improve-zfs-diff-upstream
Open

Improve libzfs api for zfs diff and add JSON support#18299
anodos325 wants to merge 1 commit intoopenzfs:masterfrom
truenas:improve-zfs-diff-upstream

Conversation

@anodos325
Copy link
Contributor

@anodos325 anodos325 commented Mar 9, 2026

This commit adds json output support for zfs-diff and expands the libzfs API to include an easier-to-use function for generating a diff programmatically. JSON zfs-diff streams output with one JSON object per line.

Motivation and Context

Description

How Has This Been Tested?

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:

This commit adds json output support for zfs-diff and
expands the libzfs API to include an easier-to-use function
for generating a diff programmatically. JSON zfs-diff
streams output with one JSON object per line.

Signed-off-by: Andrew Walker <andrew.walker@truenas.com>
@anodos325
Copy link
Contributor Author

root@testMW87SLWSMH[~/zfs]# zfs diff -j dozer/foo@now1
{"change_type":"modified","inode":2,"gen":6215,"file_type":"directory","path":"/mnt/dozer/foo/d1","changes":{"mode":{"from":16877,"to":16832}}}
{"change_type":"modified","inode":34,"gen":6213,"file_type":"directory","path":"/mnt/dozer/foo/"}
{"change_type":"modified","inode":128,"gen":6216,"file_type":"regular","path":"/mnt/dozer/foo/d1/f1"}
{"change_type":"renamed","inode":129,"gen":6218,"file_type":"regular","path":"/mnt/dozer/foo/f2","changes":{"path":"/mnt/dozer/foo/f3"}}
{"change_type":"added","inode":130,"gen":6254,"file_type":"regular","path":"/mnt/dozer/foo/d1/f5"}

^^^ sample output.

I included what additional information I could glean with existing diff ioctl into the JSON output. This means catching:

  • txg / inode generation + inode number (useful for uniquely identifying files)
  • changes in mode (potentially useful for catching when permissions on file is changing -- though not authoritative if ACLs are enabled)

This was mainly an exercise in getting zfs diff output available in a useful way for truenas_pylibzfs, but I thought having JSON output implemented would provide better test coverage of the libzfs_iter_diffs (new function) and give some new useful knobs for regular consumers of zfs-diff.

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Code Review Needed Ready for review and testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants