Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -t option to zfs destroy #15959

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

simons-public
Copy link

@simons-public simons-public commented Mar 4, 2024

Resolves #9522 by adding an optional [-t type] option gate to the zfs destroy command. Checks the type of the supplied argument, then checks if the supplied type is the same or one of the aliases that are also used in zfs list. If the type doesn't match, it prints an error to stderr and exits. I am aware there have been PRs for this before, but I thought a simpler change might be more likely to be accepted.

Motivation and Context

This is a (hopefully) uncomplicated solution to the problem from issue #9522. It just checks the type early and exits if the type isn't a match. This makes something like using zfs list with grep or awk much less of a footgun for scripting and reduces the chances of destroying a dataset instead of a snapshot. I had written a small utility that does this for my own purposes, but when I saw that #9522 was labeled as good first issue I decided to submit a PR.

Description

This change adds a [-t type] option that exits if the supplied volume/filesystem/snapshot argument is not of the specified type.

How Has This Been Tested?

Tested by adding a functional test in zfs-test suite and running on linux. Passes all Github workflow actions that were not already failing. As an optional flag, should not affect any other items.

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)
  • 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:

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

Resolves openzfs#9522 by adding an optional [-t type] option gate to the
`zfs destroy` command. Checks the type of the supplied argument,
then checks if the supplied type is the same or one of the aliases
that are also used in `zfs list`. If the type doesn't match, it
prints an error to stderr and exits.

Signed-off-by: Chris Simons <chris@simons.network>
@behlendorf behlendorf reopened this Mar 26, 2024
@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Apr 3, 2024
@behlendorf behlendorf self-assigned this Apr 3, 2024
robn added a commit to robn/zfs that referenced this pull request May 3, 2024
- add column for TRIM ZIOs
- remove R from ZIO_STAGE_ISSUE_ASYNC, never happened
- remove I from ZIO_STAGE_VDEV_IO_DONE, never happened

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#15959
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.

Ability to specify type to 'zfs destroy`
2 participants