~mvo/snapd/+git/snapd-mvo:arch-endian

Last commit made on 2023-07-28
Get this branch:
git clone -b arch-endian https://git.launchpad.net/~mvo/snapd/+git/snapd-mvo

Branch merges

Branch information

Name:
arch-endian
Repository:
lp:~mvo/snapd/+git/snapd-mvo

Recent commits

4413ec7... by Michael Vogt

review feedback

41c94fe... by Michael Vogt

arch: fix usage of runtimeGOARCH

Co-authored-by: Miguel Pires <email address hidden>

433a4b5... by Michael Vogt

arch: add new `arch.Endian()` helper and use it in seccomp

Go has no good way to get the native endianness of a system.
However for certain use-cases (like seccomp) this is quite
important. We already have a (hackish) `isBigEndian()` helper
in our code. However this will also be needed in snap-seccomp
for PR#13014 this will also be needed so moving the helper
to the `arch` package seems to be prudent.

c0e8ad5... by Michael Vogt

client: fix specificErr handling in SnapshotExport() (#13001)

* client: fix specificErr handling in SnapshotExport()

The code was checking generating a `specificErr` but then checked
`if err != nil {` (and not check for specificErr) and also lacked
a unit test.

When adding the code test it became clear that the other issue
there is that the response body was never read so r.err() would
always return nil.

This commit fixes both issues.

* client: fix TestClientExportSnapshotSpecificErr naming

Co-authored-by: Miguel Pires <email address hidden>

---------

Co-authored-by: Miguel Pires <email address hidden>

cc5e5e2... by Michael Vogt

interfaces: fix missing error return in kvm

8e76198... by Zeyad Gouda

store: remove refresh hold data in store requests for older proxies

"held" is supported starting v54 of the store API. Some store proxies might
be running older versions of the store which will fail with: "Additional
properties are not allowed ('held' was unexpected)".

This approach retries bad requests, with the new knowledge of the store
version parsed from the response header ""Snap-Store-Version"" and removes
the "held" field if store version is less than v54.

This approach is generic and can be used for other new fields using
minStoreVersion(storeVer, <MIN_VER>).

* o/snapstate: make debug message consistent and store version check explicit

* o/snapstate: check Snap-Store-Version header is valid for retry logic and fix typo in test name

* o/snapstate: extract refresh hold retrieval into a helper function

* o/snapstate: move effectiveRefreshHold to autorefresh.go

* o/snapstate: bump store api requirement to v55 for held field support

 * v55 includes bug fixes related to held field

Signed-off-by: Zeyad Gouda <email address hidden>

3355b78... by Miguel Pires

o/snapstate: send refresh hold data in store requests

Signed-off-by: Miguel Pires <email address hidden>

bc759f4... by Miguel Pires

o/snapstate: use refresh hints to continue auto-refresh after monitoring (#12970)

Use refresh hints written in the auto-refresh to continue an
inhibited auto-refresh without fetching from the store. Should fix
https://bugs.launchpad.net/snapd/+bug/2019158 where the auto-refresh
for Firefox isn't continued after the user closes it because the second
auto-refresh doesn't get an update from the store (throttling),
resulting in poor UX.

Signed-off-by: Miguel Pires <email address hidden>

4d01b69... by Oliver Calder

prompting: add epoll package (#12963)

* mailmap: map new commits from <email address hidden> to <email address hidden>

Signed-off-by: Oliver Calder <email address hidden>

* Initial commit

Signed-off-by: Zygmunt Krynicki <email address hidden>
Signed-off-by: Oliver Calder <email address hidden>

* Correct references to old name

Signed-off-by: Oliver Calder <email address hidden>

* osutil/epoll: fixed epoll test import

Signed-off-by: Oliver Calder <email address hidden>

* osutil/epoll: make Close() set epoll fd to -1

Signed-off-by: Oliver Calder <email address hidden>

* epoll: renamed `FromSys()` epoll event parameter name to `ev`

Signed-off-by: Oliver Calder <email address hidden>

* epoll: added unit tests, but `Register()` always fails, as does ioctl syscall to prepare fd to register

Signed-off-by: Oliver Calder <email address hidden>

* epoll: removed unused `modeSet` type from epoll_test.go

Signed-off-by: Oliver Calder <email address hidden>

* epoll: replaced `syscall` with vendored `x/sys/unix`

Signed-off-by: Oliver Calder <email address hidden>

* epoll: simplified `Readiness` type to match `EPOLL{IN,OUT}` flags

Signed-off-by: Oliver Calder <email address hidden>

* epoll: fix unit tests using socketpair

Signed-off-by: Oliver Calder <email address hidden>

* epoll: fixed typo in test

Signed-off-by: Oliver Calder <email address hidden>

* epoll: tie events list to instance with entry for each registered fd, and add unit tests

Signed-off-by: Oliver Calder <email address hidden>

* epoll: add `WaitTimeout(msec)` with configurable timeout

Signed-off-by: Oliver Calder <email address hidden>

* epoll: remove comment about using internal/poll instead of epoll

Signed-off-by: Oliver Calder <email address hidden>

* epoll: improve error message when epoll create syscall fails

Signed-off-by: Oliver Calder <email address hidden>

* epoll: use time.Duration instead of int in `WaitTimeout()`

Signed-off-by: Oliver Calder <email address hidden>

* epoll: make epoll package thread safe

Replace the instance-specific event buffer with a mutex-guarded
registered FD count, allowing an event buffer with a number of slots
equal to the current number of registered FDs to be allocated in
`Wait()`, and thus allowing events from all FDs to be handled by a
single `Wait()` call.

Previously, the instance-specific event buffer was shared by separate
calls to `Wait()`, with the address of the start of the buffer passed
into the EPOLL_WAIT syscall, so multiple concurrent calls to `Wait()`
could cause race conditions where the contents of the buffer was
overwritten by multiple threads at once. Now, since the event buffer is
allocated within the `Wait()` function, this race condition is avoided.

Whenever a new FD is registered, the registeredFdCount variable is
incremented, and whenever an FD is deregistered, that variable is
decremented, in both cases guarded by the mutex for the epoll instance.

So what happens if there are n FDs registered, a call to `Wait()`
begins, and then while waiting, another FD is registered with the epoll
instance? Could this result in a buffer with too few entries for the now
(n+1) registered FDs? No, because beyond race conditions where the
kernel receives two write syscalls simultaneously and these end up in
the same epoll response (extremely unlikely), the only way that multiple
events are returned by the same call to `Wait()` is if there were
previous write events which had been caught by epoll but hadn't yet been
handled with an EPOLL_WAIT syscall. In this case, `Wait()` would
immediately return all those previous events, before the new FD is able
to be registered and written to.

The way around this would be if `Wait()` began, allocated the buffer
with size n, and then the thread were interrupted, and the new FD
registered and written to before the EPOLL_WAIT syscall occurred. In
this case, if all the initial n FDs had pending activity, then the
`Wait()` call would return an event buffer of size n, presumably with
the events for the original n FDs, and a subsequent call to `Wait()`
would return the event on the newly-registered FD. No event is lost in
any case.

Signed-off-by: Oliver Calder <email address hidden>

* epoll: simplified duration in `Wait()`

Signed-off-by: Oliver Calder <email address hidden>

* epoll: `s/waitMillisecondsThenWriteToFile/waitMillisecondsThenWriteToFd`

Signed-off-by: Oliver Calder <email address hidden>

* epoll: simplified timeout duration definitions in tests

Signed-off-by: Oliver Calder <email address hidden>

* epoll: gracefully handle `EINT` errors from `EPOLL_WAIT` syscall

Signed-off-by: Oliver Calder <email address hidden>

* epoll: clarified handling of EINTR from EPOLL_WAIT syscall

Signed-off-by: Oliver Calder <email address hidden>

* epoll: replaced mutex with atomic Int32 calls wrapped in helper functions

Signed-off-by: Oliver Calder <email address hidden>

* epoll: added handling for waiting with no registered FDs

It may be the case that one wishes to wait for epoll events without
first registering any file descriptors to which to listen. Perhaps
those file descriptors will be registered later by another thread, and
we want to capture any activity on them as soon as that occurs. In any
case, we do not wish to deny the ability to call `Wait()` if there are
no registered FDs.

However, the `EpollWait` syscall requires a nonzero-length buffer to be
passed in (technically a nonzero length value, along with a pointer to
the buffer). Thus, in order to allow future registered FDs to be handled
by an existing wait call which was initiated when no FDs were
registered, it is necessary to ensure that a buffer of at least length 1
is passed into the `EpollWait` syscall.

Unit tests were added to check for correct waiting behavior when no FDs
are registered, when waiting is initiated before FD is registered, and
when the final FD is deregistered after wait has been initiated.

The `TestWaitThenRegister` function was rewritten to be more salient. In
particular, it now tests behavior when no FDs are registered at the time
`Wait()` is called, and then a new FD is registered and activity occurs
on it.

Signed-off-by: Oliver Calder <email address hidden>

* epoll: added tests for {,de}registering bad file descriptors

Signed-off-by: Oliver Calder <email address hidden>

* epoll: improved the arbitrary nonexistent FD used by {,de}register tests

Signed-off-by: Oliver Calder <email address hidden>

* epoll: cleaned up increment/decrement order on error, and unneeded `runtime.KeepAlive()`

Signed-off-by: Oliver Calder <email address hidden>

* epoll: added early return if epoll_wait returned 0 events

Signed-off-by: Oliver Calder <email address hidden>

* epoll: clean up opened sockets, and ensure Assert not called before reading from channels

Signed-off-by: Oliver Calder <email address hidden>

* epoll: use proper checker methods when applicable

Signed-off-by: Oliver Calder <email address hidden>

* epoll: Add comment about minimum buffer size for epoll_wait

Signed-off-by: Oliver Calder <email address hidden>

* epoll: added unit test for EINTR handling

Signed-off-by: Oliver Calder <email address hidden>

* epoll: reduced test sleep and timeout durations to make unit tests faster

Signed-off-by: Oliver Calder <email address hidden>

* epoll: defined `defaultDuration` for use in timing-sensitive unit tests

Signed-off-by: Oliver Calder <email address hidden>

* epoll: replaced `Errno` magic numbers with defined values

Signed-off-by: Oliver Calder <email address hidden>

---------

Signed-off-by: Oliver Calder <email address hidden>
Signed-off-by: Zygmunt Krynicki <email address hidden>
Co-authored-by: Zygmunt Krynicki <email address hidden>

4161771... by Michael Vogt

daemon: fix crash when a non-model assertion is sent /v2/model

A remodel with an assertion that is not a model assertion will
currently crash the daemon. This commit fixes this and adds a
test.