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

zpool events does not respect -H option (zpool_main.c) #17134

Open
dodexahedron opened this issue Mar 11, 2025 · 1 comment
Open

zpool events does not respect -H option (zpool_main.c) #17134

dodexahedron opened this issue Mar 11, 2025 · 1 comment
Labels
Type: Defect Incorrect behavior (e.g. crash, hang)

Comments

@dodexahedron
Copy link
Contributor

dodexahedron commented Mar 11, 2025

zpool events -v -H provides largely the same output as without the -H and does not do what the manpage or usage summary say..

All properties of the events are prefixed with 8 spaces, fields are separated from values by an explicit space equals space sequence (=), and both name and value of each nvpair are wrapped in double-quote characters.

Documented behavior in the zpool-events(8) manpage (and what would be consistent with other commands as well) is that -H uses a simplified tab-delimited format without arbitrary spaces or other formatting. But that's not what happens, and output is the same as if -H weren't there except for one spot. The header line, which already only has one instance of "arbitrary" internal spacing in the first place and is left-aligned (link to source below).

I noticed it in 2.3.0 and there's no change in 2.3.1. I do not know if it applies to older versions or if it's a regression, as I didn't look at history beyond 2.3.0 and wasn't using it until now.

Line 12268 of in cmd/zpool/zpool_main.c, in the zpool_do_events_next function, appears to be the only line which respects that flag, and neither the loop over the nvlist nor the zpool_do_events_nvprint function respect the flag.

On top of the spacing, the quoted names of each nvpair seem unnecessary, since they won't contain whitespace, and quotes around their values are also inconsistent with other utilities' -H options.

Also, for tab-delimited output, having a more specific type discriminator very early in the list would be extremely helpful to enable skipping parsing of events one is not interested in. In particular, this is troublesome with history_events, as both zpool and zfs events use the same zfs.history_event type, but the available means of discriminating between them is not until much lower in the list (basically, if there's a dataset involved or not).

A formal definition would be helpful, regardless, for the format of the output.

Documentation doesn't mention how they are separated, nor do any comments in code, but the current code of the code in the above methods and the rest of that output routine ends up separating each event by a total of 3 newline characters (two blank lines plus the one at the end of the final nvpair). That's fine and easy to handle, but I'm wary of relying on it if it's not behavior and formatting that's documented and has potential to change.

Here's a sample of output with and without the -H flag.
First is without -H (two spaces in the header line).
Second is with -H (one SPACE - not tab - in the header line).

Mar 10 2025 20:20:20.639560166  sysevent.fs.zfs.history_event
        version = 0x0
        class = "sysevent.fs.zfs.history_event"
        pool = "pool1"
        pool_guid = 0x6588ac6f05fc2cd8
        pool_state = 0x0
        pool_context = 0x0
        history_hostname = "nunya.biz"
        history_dsname = "pool1/also/nuny@biz"
        history_internal_str = " "
        history_internal_name = "destroy"
        history_dsid = 0x14954
        history_txg = 0x62fceb
        history_time = 0x67cfabf4
        time = 0x67cfabf4 0x261ee9e6
        eid = 0x5fe97
Mar 10 2025 20:20:20.639560166 sysevent.fs.zfs.history_event
        version = 0x0
        class = "sysevent.fs.zfs.history_event"
        pool = "pool1"
        pool_guid = 0x6588ac6f05fc2cd8
        pool_state = 0x0
        pool_context = 0x0
        history_hostname = "nunya.biz"
        history_dsname = "pool1/also/nuny@biz"
        history_internal_str = " "
        history_internal_name = "destroy"
        history_dsid = 0x14954
        history_txg = 0x62fceb
        history_time = 0x67cfabf4
        time = 0x67cfabf4 0x261ee9e6
        eid = 0x5fe97

Perhaps an even more awesome nice-to-have would be if the zpool events command got the --json love that many other commands have, so custom parsers don't even have to be a thing at all (I'm writing one right now for a snapshot and replication manager, to consume the events for state updates of things happening outside of the application).

@dodexahedron dodexahedron added the Type: Defect Incorrect behavior (e.g. crash, hang) label Mar 11, 2025
@dodexahedron
Copy link
Contributor Author

Something I hadn't thought of before that should probably also be a difference in -H output is the date in the header line, which is localized right now. Should probably be ISO8601 or something instead for portability of the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Defect Incorrect behavior (e.g. crash, hang)
Projects
None yet
Development

No branches or pull requests

1 participant