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

nixos/zfs: Hide useless errors when waiting for zpool to be ready #48546

Merged
merged 1 commit into from Oct 19, 2018

Conversation

andrew-d
Copy link
Contributor

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
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

r? @Baughn @Mic92

@srhb
Copy link
Contributor

srhb commented Oct 16, 2018

Could we maybe set this up so that it only filters that exact message out? I'm worried that we might silence something useful.

@andrew-d
Copy link
Contributor Author

Could we maybe set this up so that it only filters that exact message out?

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 ash in stage-1, so we can't do any fancy Bash process substitution. I guess we could try ... writing to a temp file? Or something with FIFOs? Suggestions appreciated!

@andrew-d
Copy link
Contributor Author

@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.

@srhb
Copy link
Contributor

srhb commented Oct 18, 2018

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.

@srhb srhb self-requested a review October 18, 2018 08:51
@Mic92
Copy link
Member

Mic92 commented Oct 18, 2018

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.

Copy link
Member

@infinisil infinisil left a 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 after poolReady 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 the poolReady 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 :)

@andrew-d
Copy link
Contributor Author

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 srhb merged commit 5871775 into NixOS:master Oct 19, 2018
@andrew-d andrew-d deleted the andrew/hide-zfs-import-warning branch October 19, 2018 08:31
@andrew-d
Copy link
Contributor Author

@srhb - Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants