zpool events
does not respect -H option (zpool_main.c)
#17134
Labels
Type: Defect
Incorrect behavior (e.g. crash, hang)
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).
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).The text was updated successfully, but these errors were encountered: