moby/volume
Kir Kolyshkin bb934c6aca pkg/mount: implement/use filter for mountinfo parsing
Functions `GetMounts()` and `parseMountTable()` return all the entries
as read and parsed from /proc/self/mountinfo. In many cases the caller
is only interested only one or a few entries, not all of them.

One good example is `Mounted()` function, which looks for a specific
entry only. Another example is `RecursiveUnmount()` which is only
interested in mount under a specific path.

This commit adds `filter` argument to `GetMounts()` to implement
two things:
 1. filter out entries a caller is not interested in
 2. stop processing if a caller is found what it wanted

`nil` can be passed to get a backward-compatible behavior, i.e. return
all the entries.

A few filters are implemented:
 - `PrefixFilter`: filters out all entries not under `prefix`
 - `SingleEntryFilter`: looks for a specific entry

Finally, `Mounted()` is modified to use `SingleEntryFilter()`, and
`RecursiveUnmount()` is using `PrefixFilter()`.

Unit tests are added to check filters are working.

[v2: ditch NoFilter, use nil]
[v3: ditch GetMountsFiltered()]
[v4: add unit test for filters]
[v5: switch to gotestyourself]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-04-19 14:48:09 -07:00
..
drivers Remove use of global volume driver store 2018-04-17 14:07:08 -04:00
local pkg/mount: implement/use filter for mountinfo parsing 2018-04-19 14:48:09 -07:00
store Remove use of global volume driver store 2018-04-17 14:07:08 -04:00
testutils Merge pull request #35829 from cpuguy83/no_private_mount_for_plugins 2018-02-21 12:28:13 +01:00
lcow_parser.go Add canonical import comment 2018-02-05 16:51:57 -05:00
linux_parser.go Print which path failed when the mount source doesn't exist. 2018-02-27 23:19:46 +00:00
parser.go Add canonical import comment 2018-02-05 16:51:57 -05:00
validate.go Print which path failed when the mount source doesn't exist. 2018-02-27 23:19:46 +00:00
validate_test.go Print which path failed when the mount source doesn't exist. 2018-02-27 23:19:46 +00:00
validate_unix_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
validate_windows_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
volume.go Add canonical import comment 2018-02-05 16:51:57 -05:00
volume_copy.go Add canonical import comment 2018-02-05 16:51:57 -05:00
volume_test.go Print which path failed when the mount source doesn't exist. 2018-02-27 23:19:46 +00:00
volume_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
volume_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
windows_parser.go Print which path failed when the mount source doesn't exist. 2018-02-27 23:19:46 +00:00