Commit Graph

5 Commits

Author SHA1 Message Date
Miloslav Trmač f4597cfee5 Use range iterations
... for the trivial cases where the loop body does not reference
the iteration variable at all.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-09-05 18:56:35 +02:00
Valentin Rothberg f4aa849172 fix break during unmount
Move the break statement out of the switch to actually break out of the
loop as intended.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-10-19 10:46:14 +02:00
Valentin Rothberg d885bfb176 mount.Umount: EBUSY: try at most 50 times
The function is being used in a number of places, notably container
removal and cleanup.  While container removal already loops over EBUSY,
cleanup does not.

To make sure that all callers of Unmount get a fair chance of unmounting
cleanly, also loop there.  I used the same values as containerd: 50
loops with 50ms sleeps.

Context: containers/podman/issues/11594
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-10-13 12:33:30 +02:00
Kir Kolyshkin 8b67934cbc pkg/mount: wrap mount/umount errors
The errors returned from Mount and Unmount functions are raw
syscall.Errno errors (like EPERM or EINVAL), which provides
no context about what has happened and why.

Similar to os.PathError type, introduce mount.Error type
with some context. The error messages will now look like this:

> mount /tmp/mount-tests/source:/tmp/mount-tests/target, flags: 0x1001: operation not permitted

or

> mount tmpfs:/tmp/mount-test-source-516297835: operation not permitted

Before this patch, it was just

> operation not permitted

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-10 06:41:39 -07:00
Kir Kolyshkin f64f234a52 pkg/mount: faster Umount(), unify code
1. There is absolutely no need to consult /proc/self/mountinfo
   before calling umount(2) -- it's easier to go ahead and ignore
   EINVAL.

Here, EINVAL can mean two things:
 - the path argument is not a mount point (i.e. it's not mounted)
 - the flags argument is invalid (i.e. bad flags)

We assume we never pass the wrong flags to umount(2), so
EINVAL means "not mounted" and can safely be ignored.

This should speed up Umount() a lot.

2. For every Unix, umount is implemented in the same way,
   so let's consolidate the umount code.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-07 19:49:00 -08:00