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
nixos/zfs: Hide useless errors when waiting for zpool to be ready #48546
Conversation
Could we maybe set this up so that it only filters that exact message out? I'm worried that we might silence something useful. |
I tried to figure out how to do this, but I am not nearly enough of a shell magician 😅 As I understand it, we're running in |
@srhb - Okay, I played around with redirection, and I think I have something working. I'm thinking we create two FIFOs, like this little demo: #!/usr/bin/dash
mkfifo /tmp/zfs-pool-ready.stdout.log.fifo
mkfifo /tmp/zfs-pool-ready.stderr.log.fifo
# In a subshell, redirect all output to the fifo.
(
exec >/tmp/zfs-pool-ready.stdout.log.fifo 2>/tmp/zfs-pool-ready.stderr.log.fifo
# Fake ZFS command
echo "no pools available to import" >&2
echo "some other error" >&2
echo "MISSING"
) &
# Print the redirected stderr when filtered
grep -v "no pools available to import" </tmp/zfs-pool-ready.stderr.log.fifo >&2 &
grepJob=$!
# Read the standard input into a variable; this will exit on EOF
state="$(cat /tmp/zfs-pool-ready.stdout.log.fifo)"
# Wait for our stderr forwarder to finish before we continue
wait $grepJob
# Clean up
rm /tmp/zfs-pool-ready.stdout.log.fifo
rm /tmp/zfs-pool-ready.stderr.log.fifo
echo "state: $state" Thoughts on an approach like this? It's a bit heavyweight, but it does allow us to independently filter stdout/stderr as necessary. I'll test it on a NixOS machine tomorrow, too. |
I like it! I don't think it looks terribly heavyweight, and it's very clear to read and extend. I'm wondering if tmp is the right place here, maybe someone else can chime in on that. |
I think you don't need the fifo for stdout actually. Or it might be easier to have a fifo for stdout and pipe stderr through grep directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to care about any errors for this command, because
- The result of
poolReady
is only used as a binary decision whether it's ready. If it's never ready, the code afterpoolReady
still tries to import the pool, and if that fails the error will get reported. There's no situation where we'd lose an error from thepoolReady
phase, because the error will occur later anyways. zpool import
doesn't do any writing, it just displays the available pools. As such, executing this command multiple times should result in the same error, so we aren't losing any unique errors by discarding its stderr, just duplicated ones that would occur later on anyways.
So this PR looks good to me, there's already enough non-trivial non-useless errors appearing on terminals all the time, let's try to keep the number of irrelevant ones down :)
Okay, yeah, that makes sense; as long as we're not losing the error that sounds reasonable! I don't have write access, so if everyone is okay with @infinisil's comment, happy to have someone merge this PR as-is 👍 |
@srhb - Thank you! |
Motivation for this change
Without this warning, we occasionally see "no pools available to import" messages, due to a race between the device showing up and this message being printed. It's not particularly useful, so let's just hide it.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)r? @Baughn @Mic92