snap/squashfs: enforce a minimum snap size to eliminate some kernel log noise (#13191)
* squashfs: enforce a minimum snap size to eliminate kernel log noise
* integrity: update tests to account for new minimum snap size
* pack: update tests to account for new minimum snap size
* squashfs: rename truncate functions for clarity
* squashfs: make comment explaining growing a snap more clear
Co-authored-by: Miguel Pires <email address hidden>
* squashfs: add better context to truncation error
Co-authored-by: Miguel Pires <email address hidden>
* squashfs: split error if check onto multiple lines
* snap/pack: make test data consistent with new snap size
* snap/pack: update comment to be consistent with new snap size
* snap/squashfs: use more suited check comparator
* snap/integrity: add comment explaining calculation of verityHashSize
* pack: add comment explaining verityHashSize
* s/squashfs: log random snap data in test failure to enable reproduction
* s/squashfs: reduce mocking needed by calling actual mksquashfs command
---------
Co-authored-by: Miguel Pires <email address hidden>
osutil/epoll: make `e.Wait{,Timeout}()` return immediately when `e.Close()` is called (#13204)
* osutil/epoll: make `e.Wait{,Timeout}()` return immediately when `e.Close()` is called
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: make `WaitTimeout()` reference initial time
Previously, the elapsed time was computed as the total time spent
waiting on the `epoll_wait` syscall, but when waiting for a timeout, one
is generally more concerned with the time which has elapsed since
initiating the call, rather than the total time internally spent waiting
on the syscall (to the extent that can even be accurately measured).
This commit ensures that the function returns once the time since the
start of the call exceeds the given duration.
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: added explicit `IsClosed()` function
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: made epoll file descriptor thread safe
Importantly, this change also makes `Close()` thread safe, eliminating
the previous risk that `close(e.closed)` could be called more than once,
thus causing a panic.
Additionally, the `zeroRegisteredFdCount()` function has been removed,
since guaranteeing that `e.registeredFdCount` is `0` after `Close()`
while other threads may be about to increment/decrement the count
requires additional overhead. It may also be useful to query the number
of registered file descriptors at time of close, and the function
otherwise served no purpose.
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: use `chan struct{}` instead of `chan interface{}`
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: make `IsClosed()` atomic
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: make `IsClosed()` use `closed` channel
Thus, it is not necessary to set `e.fd = -1` when the channel is closed,
which is redundant information with the `closed` channel and meant that
reads and writes of `e.fd` needed to be atomic. Now, `e.fd` is never
changed after the epoll instance is created, so there is no need for
atomic reads/writes of `e.fd`.
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: remove public `Fd()` method
Since `e.fd` is no longer modified, there is no need to internally
control reads of it in any special way, and thus no internal need for a
helper function.
Additionally, we very much do not want outside callers to close the
epoll file descriptor directly, as this should always be done via the
`Close()` method. Therefore, by unexporting access to internal `e.fd`,
this discourages users from closing `e.fd` directly.
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: improved race condition checks in tests
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: added doc comment to `IsClosed()`
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: adjusted file header
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: added `IsClosed()` checks after syscalls
If the epoll instance is closed during a syscall, this could cause the
syscall to return EBADF. However, since closing the epoll instance is
the cause of this, we want to return `ErrEpollClosed` instead of
`EBADF`.
By checking `IsClosed()` immediately after the syscall returns (and
before checking the error returned by the syscall), we are guaranteed to
return `ErrEpollClosed` if the epoll instance was closed during a
syscall, regardless of whether closing the instance was the cause of an
error during the syscall.
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: Only return ErrEpollClosed if error occurred
For methods which invoke syscalls, the epoll instance may be closed
during the syscall, which may cause the syscall to return an error.
Previously, we checked (after the syscall returned) if the epoll
instance was now closed, and if so, returned ErrEpollClosed. However,
there is a race between the end of the syscall and the check for whether
the epoll instance has been closed, so it may be that the syscall
completed successfully, either because the close occurred after the
syscall completed, or because the close did not trigger an error in the
syscall. Regardless, we should not return an error if no error actually
occurred.
Signed-off-by: Oliver Calder <email address hidden>
* osutil/epoll: remove unnecessary type from error variable
Signed-off-by: Oliver Calder <email address hidden>
---------
Signed-off-by: Oliver Calder <email address hidden>