Commit Graph

17 Commits

Author SHA1 Message Date
Kir Kolyshkin 1ac1730a90 pkg/lockfile: no else needed after panic
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-09-19 16:59:48 -07:00
Jan Rodák 6f4a812ea8
Fix errcheck: error return value of `lockHandle` is not checked
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-07-09 16:58:09 +02:00
Miloslav Trmač 6c173a412b Use the right unlock function on error paths
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-05-21 21:24:38 +02:00
Giuseppe Scrivano c06cd1c168
lockfile: add functions for non blocking lock
extend the public API to allow a non blocking usage.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-05-10 15:42:21 +02:00
Giuseppe Scrivano 1e43992515
lockfile: fix comment
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-05-10 15:00:52 +02:00
Mike Norgate 1ad1a4ecb4
Implement windows lockfile
Signed-off-by: Mike Norgate <mike.norgate@mythical.games>
2023-07-12 09:24:17 +01:00
Rui Chen a7e5b107ac
docs: fix fcn name ref for `AssertLockedForWriting`
Signed-off-by: Rui Chen <rui@chenrui.dev>
2023-01-02 16:49:16 -05:00
Miloslav Trmač b2d3379ed4 Deprecate *LockFile.Modified and *LockFile.Touch
They are a shared state across all users of the *LockFile in the process,
and therefore incorrect to use for any single consumer for change tracking.

Direct users to user the new GetLastWrite, ModifiedSince, and RecordWrite,
instead, and convert all c/storage users.

In addition to just being correct, the new API is also more efficient:
- We now initialize stores with GetLastWrite before loading state;
  so, we don't trigger an immediate reload on the _second_ use of a store,
  due to the problematic semantics of .Modified().
- Unlike Modified() and Touch(), the new APi can be safely used without
  locking *LockFile.stateMutex, for a tiny speedup.

The conversion is, for now, trivial, just immediately updating the lastWrite
value after the ModifiedSince call.  That will get better.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-11-29 18:12:43 +01:00
Miloslav Trmač b74fdf4d23 Convert all c/storage users of Locker to *lockfile.LockFile
This will allow us to benefit from new features.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-11-29 18:12:43 +01:00
Miloslav Trmač 9bcb737123 Modify pkg/lockfile to return a struct instead of an interface
Add lockfile.GetLockFile and lockfile.GetROLockFile (with upper-case
F, as opposed to existing methods with lower-case f) which return a
*LockFile struct, instead of the Locker interface.

This follows the general Go design heuristic: "return structs, accept
interfaces"; more importantly, it allows us to add more methods to the lock
object without breaking the Go API by extending a pre-existing interface.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-11-29 18:12:43 +01:00
Miloslav Trmač d4462aad95 API BREAK: Drop Lockfile.Locked
It is fundamentally incorrect, and no users are remaining.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-21 21:10:33 +02:00
Miloslav Trmač 5791b9d6af Add Lockfile.AssertLocked and AssertLockedForWriting
This will replace Lockfile.Locked for the sanity-checking
purposes.

It is, just like Locked never was, NOT a way for a caller
to check the current state. Hence the panic() instead of an
error return.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-21 21:10:33 +02:00
Miloslav Trmač 082a8161ed Remove lockfile.Locker.RecursiveLock
It is not valid as currently implemented, and there is no known user.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-07 19:45:14 +02:00
Daniel J Walsh 3f8c0dc0de
Wrap errors properly with fmt.Errorf
Also returned errors should not begine with a capatalized errors.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-07-12 13:26:10 -04:00
Sascha Grunert 3455d12729
Switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of the
deprecated github.com/pkg/errors package.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-07 13:22:46 +02:00
Sascha Grunert 6d7ec7a432
Add docs about when locks can panic
Add a note to the locks when panics will occur.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-04-02 12:17:43 +02:00
Nalin Dahyabhai 2dfeb3edf7 Move lockfiles to their own package
Move the lockfile implementation into a subpackage so that we can use it
in the devicemapper driver.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-07-02 11:14:04 -04:00