Commit Graph

84 Commits

Author SHA1 Message Date
Giuseppe Scrivano 5d76a2ef43
types: Always apply rootless path defaults
When running as non-root, the code previously checked
if usePerUserStorage() before applying default paths
for RunRoot and GraphRoot if they were missing from
the configuration file. This check prevented defaults
from being applied if the STORAGE_DRIVER environment
variable was set.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2025-04-14 12:31:13 +02:00
Kir Kolyshkin dc1d9738aa types: use strings.ReplaceAll
This fixes the following linter warning:

> types/utils.go:17:9: QF1004: could use strings.ReplaceAll instead (staticcheck)
> 	path = strings.Replace(path, "$UID", strconv.Itoa(rootlessUID), -1)
> 	       ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-26 14:29:57 -07:00
Kir Kolyshkin 62ab0d3c3b types: use time.Equal
This fixes the following linter warnings:

> types/options.go:397:45: QF1009: probably want to use time.Time.Equal instead (staticcheck)
> 	if prevReloadConfig.storeOptions != nil && prevReloadConfig.mod == mtime && prevReloadConfig.configFile == configFile {
> 	                                           ^
> types/utils.go:64:45: QF1009: probably want to use time.Time.Equal instead (staticcheck)
> 	if prevReloadConfig.storeOptions != nil && prevReloadConfig.mod == mtime && prevReloadConfig.configFile == configFile {
> 	                                           ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-26 14:29:57 -07:00
Miloslav Trmač dd32248f47 Update to gotest.tools/v3
We have been using a version over 6 years old.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2025-03-26 21:00:20 +01:00
Kir Kolyshkin fd5483f4a8 all: use strings.Cut{Prefix,Suffix} where appropriate
Functions strings.CutPrefix and strings.CutSuffix are available
since Go 1.20 and can be used instead of strings.Has* counterparts
when the latter is followed by removing the prefix or suffix.

This simplifies the code a bit, allowing for less mistakes.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-09-19 17:03:19 -07:00
Miloslav Trmač 412ff916c2 Remove various unused parameters
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-07-10 23:54:30 +02:00
Jan Rodák b48c88b66f
Fix errcheck: error return value of `ReloadConfigurationFile` is not checked
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-07-09 17:26:30 +02:00
Giuseppe Scrivano 2d959dd4bf
store: drop remap-[ug]ids
drop the possibility to configure a remapping for all the layers in
the storage.

The feature dates back to the initial fork from Docker, that supported
a single user namespace where all the images were pulled. It was never
used by the container tools since we have a finer control of the user
namespaces.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-24 13:15:04 +02:00
Maya Rashish 730997e4dd Share the options_freebsd.go between netbsd and freebsd
For packaging for NetBSD, we will patch this file anyway (we don't
have a hard-coded install directory for packages)

Signed-off-by: Maya Rashish <maya@NetBSD.org>
2024-06-01 08:47:34 -04:00
Kir Kolyshkin 137ba2cc35 Remove devicemapper storage driver
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-04-15 14:44:29 -07:00
Giuseppe Scrivano de0900aab7
types: use fileutils.{Le,E}xist()
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-08 16:07:27 +02:00
Giuseppe Scrivano b0885dfba9
store: drop rootless from arguments
drop the rootless argument from DefaultStoreOptions and
UpdateStoreOptions since this can be retrieved internally through the
unshare package.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-11-16 21:13:28 +01:00
Giuseppe Scrivano c72a594c83
types: use functionalities from pkg/homedir
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-11-16 08:36:21 +01:00
Daniel J Walsh 42d1d96371
Run codespell on code
Cleanup description of imagestore.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-09-15 06:16:12 -04:00
Kevin Hannon 91da0c2be7 add documentation on imagestore and add a warning if set
Signed-off-by: Kevin Hannon <kehannon@redhat.com>
2023-08-28 10:35:41 -04:00
Aditya R 2bcafa5897
options,rootless: honor imagestore from config file
Honor `imagestore` option from config file for rootless setups.

Fixes issues in: https://github.com/containers/podman/pull/18224

Signed-off-by: Aditya R <arajan@redhat.com>
2023-06-16 12:56:04 +05:30
Aditya R e31225e1f9
types/options: check prior drivers using readdir
Fetch prior drivers if any using `ReadDir` and looking for traces of
`%s-images` dirs if present already on the system where `%s` is the
prior driver.

Signed-off-by: Aditya R <arajan@redhat.com>
2023-06-12 17:48:51 +05:30
Kir Kolyshkin a4d8f720a2 Format sources with gofumpt
gofumpt is a superset of gofmt, enabling some more code formatting
rules.

This commit is brought to you by

	gofumpt -w .

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-26 16:17:31 -07:00
Daniel J Walsh 55ee2d1929
Merge pull request #1618 from flouthoc/default-vfs-old-users
options: keep using prior drivers if found
2023-05-26 07:44:21 -04:00
Toshiki Sonoda 01fccaa58f options: enable Remap-User/Group setting
Remap-User/Group setting is always override by
Remap-UIDs/GIDs setting and ignored.

This commit enables Remap-User/Group setting.

Signed-off-by: Toshiki Sonoda <sonoda.toshiki@fujitsu.com>
2023-05-26 15:42:26 +09:00
Aditya R 9ef15e4d49
options: keep using prior drivers if found
There is no need for `vfs` to be the default storage driver since kernel
>= 5.13 supports `overlay` natively however there is use-case for users
who don't had any configs and they started using `vfs` in a default
manner following check is a hack to keep `buildah` and `podman` working
for such users.

See: https://github.com/containers/storage/pull/1571 for prior
discussions.

Signed-off-by: Aditya R <arajan@redhat.com>
2023-05-26 05:39:55 +05:30
Daniel J Walsh 4428f8b775
Merge pull request #1549 from flouthoc/pull-store
store: add support to split filesystem using `imagestore`
2023-04-17 16:55:03 -04:00
Giuseppe Scrivano e3b18ab721
types: try harder to use overlay with rootless
if there are no configuration files present, attempt to use overlay
for rootless if fuse-overlayfs is installed or if the kernel is >= 5.13.

Closes: https://github.com/containers/storage/issues/1570

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-04-17 09:47:50 +02:00
Aditya R 30775d4b2b
store: add support to split ImageStore
Allow storage users to split the filesystem of containers vs image
store, `imagestore` if configured will pull images in image storage
instead of the `graphRoot` while keeping the other parts still in the
originally configured `graphRoot`.

overlay: set workdir and upperdir according to splitstore
If splitstore is set `workdir` and `upperdir` must go into the
splitstore i.e `graphRoot`.

Signed-off-by: Aditya R <arajan@redhat.com>
2023-04-14 17:34:27 +05:30
Nalin Dahyabhai cabf1b9fd0 Initial implementation of consistency checks
Add initial Check() and Repair() methods to Stores.

Check() checks for inconsistencies between the layers which the
lower-level storage driver claims to know about and the ones which we
know we're managing.  It checks that layers referenced by layers,
images, and containers are known to us and that images referenced by
containers are known to us.  It checks that data which we store
alongside layers, images, and containers is still present, and to the
extent which we store other information about that data (frequenly just
the size of the data), verifies that it matches recorded expectations.
Lastly, it checks that layers which are part of images (and which we
therefore know what they should have in them) have the expected content,
and nothing else.

Repair() removes any containers, images, and layers which have any
errors associated with them.  This is destructive, so its use should be
considered and deliberate.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-04-13 10:38:24 -04:00
Giuseppe Scrivano 9ebdbd9d9d
options: reject empty runroot or graphroot
make sure that the runroot and graphroot are not empty otherwise we will
end up using an empty directory as path prefix and create files in the
current directory.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-02-16 15:52:40 +01:00
Daniel J Walsh 0ee26255cd
Run codespell on codebase
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-02-09 12:27:59 -05:00
Giuseppe Scrivano f64e1bd14a
store: prefer /etc/containers/storage.conf
when running in rootful mode, if it is present, prefer the override path
/etc/containers/storage.conf instead of using the default storage.conf
provided by the package under the /usr/share/containers/ directory.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-01-17 11:02:23 +01:00
Dan Čermák df0cb3234e
Only override the graphdriver to vfs if the priority is unset
This is an amend to https://github.com/containers/storage/pull/1460

That PR was not addressing the case when the system wide config had the
driver_priority option configured and the user had no config file of their
own. Then `getRootlessStorageOpts` would be called and it would override the
graph driver to "vfs".

With this commit we only override the graph driver if driver priority is
empty. Otherwise we propagate the driver priority into the storage options, so
that the driver autodetection works as expected.

Signed-off-by: Dan Čermák <dcermak@suse.com>
2023-01-16 09:03:42 +01:00
Dan Čermák b2b2fefb3e
Only warn about 'driver' not being set if the priority list is unset
Currently we would display an error when the user does not specify a `driver` in
their config file. This has been present for historical reasons mostly to
prevent users from accidentally getting the vfs
driver (https://github.com/containers/storage/pull/1460#issuecomment-1370866271). Now
that most systems support the overlay driver natively, we can reduce this to a
warning and only warn about it if the driver_priority list is unset. If it is
provided, then clearly the user or the distribution wanted for c/storage to pick
a driver itself and the warning would be only confusing to users.

Signed-off-by: Dan Čermák <dcermak@suse.com>
2023-01-06 08:43:46 +01:00
Dan Čermák 881ac4864a
Make the priority for picking the storage driver configurable
This fixes https://github.com/containers/storage/issues/1457

Co-authored-by: Valentin Rothberg <vrothberg@redhat.com>
Signed-off-by: Dan Čermák <dcermak@suse.com>
2023-01-05 12:38:33 +01:00
Daniel J Walsh 22ea83a845
Define error type for ErrNoAvailableIDs
Want to allow Podman to print helpful error message when
users runs out of UIDs to use with podman run --userns=auto.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-01-03 14:24:35 -05:00
Alexander Larsson 522b67c944 Add new storage.conf option "transient_store"
This just adds the support for setting and handling this key, it
doesn't really do anything yet.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2022-11-14 16:36:30 +01:00
Daniel J Walsh 68a0b369a2
Expose System wide config file
Currently Podman warns when attempting to reset storage, if the
system wide storage.conf file
/usr/share/containers/storage.conf exists.

Since distros ship this, we need to allow Podman to check if the
default is the System default and therefore do not warn.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-10-26 12:10:09 -04:00
Daniel J Walsh 9e06c38dfe
Only read storage.conf once
Currently running a simple container runs and stats configuration
storage.conf files multiple times on a simple container run.

This PR cuts the opens and stats in half by caching the first read.
This speeds up start by about 10-20 microseconds.

If container engines want to react to storage files changing, added a
new function UpdateStoreOptions to allow engines to reload options.

Fixes: https://github.com/containers/storage/issues/1403

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-10-20 08:39:06 -04:00
Miloslav Trmač 4c96809f7e Use testing.T.Setenv
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-17 20:04:31 +02:00
Miloslav Trmač 2d90000b09 Add missing error checks in tests
... and remove one WriteFile that was always failing.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-14 17:17:54 +02:00
Miloslav Trmač f42467020f Misc. warning cleanups
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-01 02:53:06 +02:00
Daniel J Walsh f75d738e63
Use system defaults if storage.conf does not exist in XDG_CONFIG_HOME
Follow up to https://github.com/containers/storage/pull/1357

Podman tests suggest that do not need to use XDG_CONFIG_HOME if
storage.conf does not exists.  In that case we fall back to
/etc/containers/storage.conf and /usr/share/containers/storage.conf

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-27 14:21:54 -04:00
Daniel J Walsh 9415b88c35
If XDG_CONFIG_HOME env is set we should use it and ignore defaults
HPC Customers noticed that storage was attempting to read files in /usr
and /etc, even though they set XDG_CONFIG_HOME, they expect to only read
config files in this directory.

Fixes: https://github.com/containers/podman/issues/15680

(Actually partial fixes), need to look at other config files.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-23 15:40:13 -04:00
Miloslav Trmač a1ccc9d862 Use os.WriteFile instead of ioutil.WriteFile
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:31:34 +02:00
Miloslav Trmač 4b28197720 Use os.ReadFile instead of ioutil.ReadFile
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:30:43 +02:00
Eng Zer Jun 6ea3603b6b
test: use `T.TempDir` to create temporary test directory
This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `ioutil.TempDir`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-30 01:21:37 +08:00
Sascha Grunert a10dcf45f5
Do not error if no storage.conf exists
This allows consumers of this library to rely on the in-memory default
rather than requiring a storage.conf.

Refers to https://github.com/containers/storage/pull/1279 and
1f647d954f

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-14 10:37:00 +02: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
Giuseppe Scrivano cbb1446d16
options: copy all options on explicit config file
when the configuration file was explicitly specified, all the graph
drivers options are copied, not only the ones allowed for rootless.

Closes: https://github.com/containers/storage/issues/1278

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-07-02 16:04:54 +02:00
Giuseppe Scrivano 63f6bba7bb
options: store a copy for prevReloadConfig
otherwise changes applied later to the object are propagated to the
copy in prevReloadConfig.storeOptions.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-07-02 16:04:54 +02:00
Giuseppe Scrivano 880f7a7b34
options: treat missing $CONTAINERS_STORAGE_CONF as error
if the CONTAINERS_STORAGE_CONF environment variable is set and the
specified file doesn't exist, then return an error.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-07-02 16:04:54 +02:00
Giuseppe Scrivano 1f647d954f
types: propagate configuration load errors
if any error happens when loading the default configuration file,
report it to the caller.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-07-02 16:04:54 +02:00
Giuseppe Scrivano 8e9ae4fd4b
options: fix function name
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-07-01 22:50:31 +02:00