Skip to content

zfs hold: extend to filesystems and volumes#18515

Open
chrislongros wants to merge 3 commits into
openzfs:masterfrom
chrislongros:feature/zfs-hold-datasets
Open

zfs hold: extend to filesystems and volumes#18515
chrislongros wants to merge 3 commits into
openzfs:masterfrom
chrislongros:feature/zfs-hold-datasets

Conversation

@chrislongros
Copy link
Copy Markdown
Contributor

@chrislongros chrislongros commented May 9, 2026

Motivation and Context

Extends zfs hold to filesystems and volumes.

Description

Lift the snapshot-only checks in the user-hold code so zfs hold, zfs release, and zfs holds accept filesystems and volumes. When a dataset has user holds, zfs destroy returns EBUSY until they are released, matching snapshot behavior.

How Has This Been Tested?

  • Linux (Arch, kernel 6.19.10, debug): new ZTS test zfs_destroy_017_neg passes; manual checks confirm hold release on filesystems, volumes, and pool root, plus zfs holds -r on a parent+child hierarchy.
  • FreeBSD (16.0-CURRENT, debug): full tree compiles clean with no errors or warnings.
  • Full ZTS suite not yet run.

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Documentation (a change to man pages or other documentation)

Checklist:

  • My code follows the OpenZFS code style requirements.
  • I have updated the documentation accordingly.
  • I have read the contributing document.
  • I have added tests to cover my changes.
  • I have run the ZFS Test Suite with this change applied.
  • All commit messages are properly formatted and contain Signed-off-by.

@chrislongros chrislongros force-pushed the feature/zfs-hold-datasets branch from f85a37d to f6ce72b Compare May 9, 2026 13:37
@chrislongros chrislongros changed the title zfs hold: extend to all dataset types zfs hold: extend to filesystems and volumes May 9, 2026
@chrislongros chrislongros force-pushed the feature/zfs-hold-datasets branch from f6ce72b to 9e950c1 Compare May 11, 2026 10:25
Copy link
Copy Markdown
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.

It's nice to see this finally implemented! A few comments inline, and I'm sure you already saw but some of the hold tests in ./contrib/pyzfs/libzfs_core/test/test_libzfs_core.py will need to be updated.

  12:40:14.53 FAIL: test_hold_invalid_snap_name_2 (libzfs_core.test.test_libzfs_core.ZFSTest)
  12:40:14.53 ----------------------------------------------------------------------
  12:40:14.53 Traceback (most recent call last):
  12:40:14.53   File "/usr/lib/python3.6/site-packages/libzfs_core/test/test_libzfs_core.py", line 3286, in test_hold_invalid_snap_name_2
  12:40:14.53     lzc.lzc_hold({snap: b'tag'}, fd)
  12:40:14.53 AssertionError: HoldFailure not raised

Comment thread cmd/zfs/zfs_main.c Outdated
Comment thread cmd/zfs/zfs_main.c Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment should be updated too.

Comment thread man/man8/zfs-hold.8 Outdated
.Sh NAME
.Nm zfs-hold
.Nd hold ZFS snapshots to prevent their removal
.Nd hold ZFS snapshots or datasets to prevent their removal
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should adopt similar phrasing as used in the zfs-get(8) man page. Specifically, ZFS snapshots, volumes, and filesystem are all just different types of datasets. We can refer to this set as "datasets" rather than "ZFS snapshots or datasets", so in this case:

hold datasets to prevent their removal

We should make the same change throughout the man page.

Comment thread man/man8/zfs-hold.8 Outdated
.Cm hold
.Op Fl r
.Ar tag Ar snapshot Ns …
.Ar tag Ar snapshot Ns | Ns Ar dataset Ns
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.Ar tag Ar filesystem Ns | Ns Ar volume Ns | Ns Ar snapshot Ns …

And for the usage we should call out each type.

Comment thread module/zfs/zfs_ioctl.c
error = dmu_fsname(nvpair_name(pair), fsname);
if (error != 0)
return (error);
const char *name = nvpair_name(pair);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should return EINVAL for bookmarks, the easiest way to check is probably using dataset_namecheck(). zfs_secpolicy_release() will need the same check.

# Verify that holds can be listed and released on datasets.
# Verify that destruction succeeds after all holds are released.
# Verify that 'zfs hold -r' applies to descendent datasets.
# Verify that recursive destroy fails while a child dataset is held.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verify the holds don't work on bookmarks.

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label May 12, 2026
@chrislongros chrislongros force-pushed the feature/zfs-hold-datasets branch from d122000 to 6a60624 Compare May 14, 2026 11:15
chrislongros and others added 3 commits May 23, 2026 12:43
Allow zfs hold/release/holds to operate on filesystems and volumes,
not only snapshots, so users can protect datasets from accidental
destruction with the existing hold mechanism. When a dataset has one
or more user holds, zfs destroy returns EBUSY until all are released,
matching snapshot behavior.

Signed-off-by: Christos Longros <chris.longros@gmail.com>
Co-authored-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Christos Longros <98426896+chrislongros@users.noreply.github.com>
Use filesystem|volume|snapshot in zfs(8) and zfs-hold(8). Adopt
"datasets" terminology matching zfs-get(8). Reject bookmarks in
zfs_secpolicy_hold/release with EINVAL via dataset_namecheck; covered
by zfs_destroy_017_neg.

Signed-off-by: Christos Longros <chris.longros@gmail.com>
@chrislongros chrislongros force-pushed the feature/zfs-hold-datasets branch from 6a60624 to 88a7776 Compare May 23, 2026 10:43
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