Skip to content

Added a more descriptive error message due the destroy failure #17234

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

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

Conversation

Artem-OSSRevival
Copy link

@Artem-OSSRevival Artem-OSSRevival commented Apr 10, 2025

Motivation and Context

Change improves interaction with the user. Makes an error message more understandable and descriptive.
#14538

Description

Previously, the destroy failure due to a long hold returned a standard error message: dataset is busy
This could cause misunderstanding and confusion among users.
The change makes the error message more understandable and definite, displaying the presence of the holder.

This is implemented by performing an additional check for the presence of holders.
If any, displayed: held by "holder" instead of dataset is busy

Before:

sudo zfs snapshot rpool@test
sudo zfs hold example rpool@test
sudo zfs destroy rpool@test
cannot destroy snapshot rpool@test: dataset is busy
sudo zfs release example rpool@test
sudo zfs destroy rpool@test

After:

sudo zfs snapshot rpool@test
sudo zfs hold example rpool@test
sudo zfs destroy rpool@test
cannot destroy snapshot rpool@test: held by example
sudo zfs release example rpool@test
sudo zfs destroy rpool@test

How Has This Been Tested?

Run the commands in the different combinations.

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:

Copy link
Member

@amotin amotin left a comment

Choose a reason for hiding this comment

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

More detailed errors are always great, but I don't very like that additional details are not obtained atomically from the original error, but fetched separately, so they might be out of sync, theoretically confusing.

@amotin
Copy link
Member

amotin commented Apr 10, 2025

Also seems it failed to build:

   CC       lib/libzfs/libzfs_la-libzfs_import.lo
  lib/libzfs/libzfs_dataset.c: In function 'zfs_destroy_snaps_nvl':
  lib/libzfs/libzfs_dataset.c:4032:4: error: a label can only be part of a statement and a declaration is not a statement
      nvlist_t *existing_holds;
      ^~~~~~~~

Or in Clang:

  lib/libzfs/libzfs_dataset.c:4032:4: error: label followed by a declaration is a C23 extension [-Werror,-Wc23-extensions]
   4032 |                         nvlist_t *existing_holds;
        |                         ^
  1 error generated.

@Artem-OSSRevival
Copy link
Author

Sorry, I did not notice this problem. Everything went smoothly on my device.
build_libzfs_dataset lo

Perhaps other compiler requires that the nvlist_t *existing_holds declaration should be outside switch...case or something. I'll try to figure it out.

@amotin amotin added the Status: Code Review Needed Ready for review and testing label Apr 11, 2025
Copy link
Contributor

@AttilaFueloep AttilaFueloep left a comment

Choose a reason for hiding this comment

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

I agree with amotin about the non-atomicity of the change. Still I think this is a nice improvement, pointing at the hold will benefit users. On the net you'll find a lot of question asked by users confused by the fact they couldn't delete seemingly unused datasets.

As a side note, in this case I think it's OK not to indent the block contents since that would harm readability. What does checkstyle say, by the way?

@Artem-OSSRevival
Copy link
Author

Artem-OSSRevival commented Apr 11, 2025

On my side, the checkstyle was successful.
If indent the block, then it will not fit into the permissible length of the line.

@amotin
Copy link
Member

amotin commented Apr 11, 2025

@Artem-OSSRevival If you search for other examples, more typical is to open the braces at the end of case line and close on the line after break, aligned to the next case. This way you don't need additional indentation.

@amotin
Copy link
Member

amotin commented Apr 11, 2025

Not exactly. Just search for ': {'.

@Artem-OSSRevival
Copy link
Author

I understood correctly? I can now fix the commit.
braces2

@AttilaFueloep
Copy link
Contributor

Yeah, I think this is the best solution.

@AttilaFueloep
Copy link
Contributor

Still looks good.

@AttilaFueloep
Copy link
Contributor

To summarize, as initially written it required C23, starting with C99 case X:; would do the trick, and as it is now, it works from C89 onwards.

Copy link
Contributor

@mcmilk mcmilk left a comment

Choose a reason for hiding this comment

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

The two commits should be merged.

@@ -4028,6 +4028,24 @@ zfs_destroy_snaps_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, boolean_t defer)
dgettext(TEXT_DOMAIN, "snapshot is cloned"));
ret = zfs_error(hdl, EZFS_EXISTS, errbuf);
break;
case EBUSY: {
nvlist_t *existing_holds;
lzc_get_holds(nvpair_name(pair), &existing_holds);
Copy link
Member

Choose a reason for hiding this comment

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

Looking again, all other callers of lzc_get_holds() check for possible errors. Without it you'll likely get some uninitialized memory dereference in nvlist_empty() below.

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.

4 participants