Commit Graph

151 Commits

Author SHA1 Message Date
Miloslav Trmač 92e1bd58a3 Avoid unnecessary manually-coded loops
Use the "slices", "maps" standard library packages, or other
readily-available features.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-09-05 19:45:45 +02:00
Miloslav Trmač 9d58265e9c Use slices.Concat where appropriate
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-09-05 18:56:35 +02:00
Giuseppe Scrivano c8652a508e 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 114cc1522c types: use functionalities from pkg/homedir
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-11-16 08:36:21 +01:00
Nalin Dahyabhai 447e9d8842 "pull up" images when creating them, too
We previously started "pulling up" images when we changed their names,
and started denying the presence of images in read-only stores which
shared their ID with an image in the read-write store, so that it would
be possible to "remove" names from an image in read-only storage.  We
forgot about the Flags field, so start pulling that up, too.

Do all of the above when we're asked to create an image, since denying
the presence of images with the same ID in read-only stores would
prevent us from finding the image by any of the names that it "had" just
a moment before we created the new record.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-04-06 18:21:11 -04:00
Nalin Dahyabhai d272ac1b7c Drop nameLooksLikeID()
Replace the newer nameLooksLikeID() function with calls to
stringid.Validate(), which does the same thing.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-04-03 10:21:35 -04:00
Alexander Larsson bdcddb2b3e Add Store.GarbageCollect() method
This looks in the container store for existing data dirs with ids not in
the container files and removes them. It also adds an (optional) driver
method to list available layers, then uses this and compares it to the
layers json file and removes layers that are not references.

Losing track of containers and layers can potentially happen in the
case of some kind of unclean shutdown, but mainly it happens at reboot
when using transient storage mode. Such users are recommended to run
a garbage collect at boot.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2022-11-14 16:36:30 +01:00
Nalin Dahyabhai 5c6eb01a08 Use defined constants for flag names
Use constants for the names of flags that we set in Flags maps that we
store in layer/image/container records, to make it easier to avoid
possible breakages due to typos in the future.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2022-09-14 10:54:54 -04:00
Miloslav Trmač 6679337b43 Fix an unused line in applyNameOperation
... by actually using it, removing some duplication, and
perhaps micro-optimizing some memory allocations.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-04-13 18:56:24 +02:00
Aditya R 5b58ed404e store: add independent AddNames and RemoveNames for images,layers,containers
Adds AddNames and RemoveNames so operations which are invoked in parallel
manner can use it without destroying names from storage.

For instance

We are deleting names which were already written in store.
This creates faulty behavior when builds are invoked in parallel manner, as
this removes names for other builds.

To fix this behavior we must append to already written names and
override if needed. But this should be optional and not break public API

Following patch will be used by parallel operations at podman or buildah end, directly or indirectly.

Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-01 01:33:35 +05:30
Daniel J Walsh ec59ba74aa Move storageOpts structures into types subdir to shrink bindings.
Currently when we build podman bindings we are pulling in the entire
storage libraries, even though we only need a few structures and
functions.

Testing with the following program

```
package main

import (
	"fmt"
	"github.com/containers/storage/types"
)

func main() {
	fmt.Println(types.GetRootlessRuntimeDir(0))
}
```

Removing types above gives me compile size of the the program

du -s t.old t.new
9640	t.before
3232	t.after

Currently these functions are being vendored into
containers/common/pkg/config, which leads to large size in podman-remote
and podman bindings.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-02-26 05:34:09 -05:00
Nalin Dahyabhai d5a311c30a Fix TestDefaultStoreOpts()
Use the variable name that matches the one used in the config file, and
add environment expansion for the rootless storage location.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-02-24 16:44:51 -05:00
Nalin Dahyabhai 841d9076ad getRootlessRuntimeDirIsolated(): don't use an empty tmpPerUserDir
If the tmpPerUserDir value is the empty string, don't try to use it as a
directory path.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-02-24 16:44:51 -05:00
Daniel J Walsh 3511bb33d0 Use STORAGE_DRIVER environment variable in rootless mode
Currently we ignore STORAGE_DRIVER enviroment variable in
rootless mode, always forcing it to be Overlay if fuse-overlay
is installed of vfs.

This patch will respect both the STORAGE_DRIVER and STORAGE_OPT
environment variable if set in rootless mode.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-01-08 06:18:43 -05:00
Daniel J Walsh 6a9d41f93e Revert returning storageOpts
Revert 3a5c606e13

I merged a patch that was a mistake that returned
rootless storage opts early. User had a broken
storage.conf that caused me to get confused.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-12-04 16:04:18 -05:00
Daniel J Walsh 3a5c606e13 Fix reading of ~/.config/containers/storage.conf
Currently rootless users of storage.conf in the home
dir ignore the storage options.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-12-02 17:07:06 -05:00
Roberto Castagnola 4ca7b63468 Restore usage of rootless_storage_path in user storage.conf
Signed-off-by: Roberto Castagnola <roberto.castagnola@gmail.com>
2020-11-02 14:58:06 +01:00
Daniel J Walsh 4d6cf76ec4 If caller Sets the DefaultConfigFilePath, we need to use it
Attempting to override the location of the storage.conf file, using
the SetDefaultConfigFilePath for testing is failing in Podman.

This patch will use the replace configuration file.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-23 16:19:11 -04:00
Giuseppe Scrivano c702dd1896 Merge pull request #733 from rcasta74/podman_issue_7876
Fix usage of rootless_storage_path from system storage.conf file
2020-10-16 14:50:03 +02:00
Daniel J Walsh f911c269e2 Stop excessive wrapping
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-15 06:08:37 -04:00
Roberto Castagnola d70b7a8b6b Fix usage of rootless_storage_path from system storage.conf file 2020-10-05 15:41:20 +02:00
Daniel J Walsh 778db8e477 Support the rootless storage path from the system file
Currently rootless containers are ignoring the rootless_storage_path entry
from the storage.conf file.

This will use the path is specified.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-09-09 15:25:39 -04:00
Daniel J Walsh fdaf9af286 For podman v2.0 we need to use use ignore_chown_errors field if set
It is too risky to add all system options.
This is supposed to work for HPC customers, so we can just
grab this setting if set in system wide settings.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-09-09 15:25:39 -04:00
Ashley Cui 21d07805d9 Allow any env variable for graphroot, runroot, storagepath
Previously only resticted to home, uid, and user

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-08-11 17:18:28 -04:00
Ashley Cui 963f33b7c1 Allow env variables in graphroot and runroot
Expand env variables in paths

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-08-06 11:59:28 -04:00
Daniel J Walsh 2213712870 new interface for MountImage added
Interface added to mount image rootfs without any container.
image can be mounted only in ReadOnly mode.

Signed-off-by: Kunal Kushwaha <kunal.kushwaha@gmail.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-07 13:45:51 -04:00
Andrew Aladjev 8c1bb968e1 use temp instead of run as fallback directory for rootless mode 2020-06-13 16:28:57 +03:00
Giuseppe Scrivano e36672dfb5 store: memoize ReloadConfigurationFile
avoid reloading the same configuration multiple times if the file was
not modified.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-24 08:28:31 +01:00
Giuseppe Scrivano 528552f295 utils: do not write default storage.conf
when running as rootless, do not write the default storage.conf file.

Follow the same pattern used for libpod.conf.

Closes: https://github.com/containers/libpod/issues/5500

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-16 13:10:25 +01:00
Qi Wang 3ec3f3bcbb fix else case for rootless storage path and path match
move the assignment of rootless_storage_path out of `else` block to make the config work even the graphroot is empty.
fix the path match error

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-03-02 09:58:18 -05:00
Daniel J Walsh ac96ec0649 Add `rootless_storage_path` directive to storage.conf
This allows rootless admins to setup alternative
paths to content in the homedir.

Rootless users on NFS homedirs will not be allowed to run
podman, if an admin wants to setup alternative directory say
in /var/tmp on local storage, they could configure the storage.conf
file and then all users would automatically get storage in /var/tmp.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-02-24 14:40:03 -05:00
Valentin Rothberg 676cf70050 use pkg/homedir
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-02-17 11:43:01 +01:00
Sascha Grunert 9f54ec7535 Enable golint linter and fix lints
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-01-28 15:59:15 +01:00
Sascha Grunert 524537729e Enable deadcode linter and fix lints
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-01-28 15:59:15 +01:00
Daniel J Walsh 341cc6a2cc Move runroot containers storage into containers directory
Currently we are throwing lots of files/directories into the
top level of /run/user/UID/  And this makes it difficult to cleanup.
Switching to using /run/user/UID/containers, makes it easier and cleaner.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-11-22 12:49:57 -05:00
Giuseppe Scrivano 12d85ccc50 utils: fix check for missing conf file
the previous error condition was causing an early failure when the
configuration file existed.  It prevented some additional checks and
to correctly set the RunRoot and GraphRoot to their default values
when they are not overriden in the configuration file.

We have not noticed it earlier as Podman would still use the
configuration from the DB in this case, so the issue is visible with
Podman only when the RunRoot is not specified in the configuration
file and in the libpod DB as well.

Closes: https://github.com/containers/libpod/issues/3274

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-06-23 23:28:48 +02:00
Daniel J Walsh e051f1f657 Return XDG_RUNTIME_DIR as RootlessRuntimeDir if set
We are currently ignoring XDG_RUNTIME_DIR if it is set, while
we should be using it.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-06-07 17:19:03 -04:00
Giuseppe Scrivano 2cdc25d542 utils: root in a userns uses global conf file
If the root user created a new user namespace, it still has to use the
system configuration and storage.

Previously if root created a user namespace when missing
CAP_SYS_ADMIN, we would use the configuration file under
/root/.config/containers instead of /etc/containers.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-23 14:12:03 +02:00
Daniel J Walsh 75aacf9b13 Correctly check permissions on rootless directory
We have not been checking the permissions on the rootless directory
this causes issues in tools trying to access the login directory
if XDG_RUNTIME_DIR is not set correctly.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-04-17 10:22:48 -04:00
Giuseppe Scrivano 42fdddef40 storage: move the logic to detect rootless into utils.go
add a helper function that automatically detects the UID when running
in a user namespace..

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-05 15:11:57 +02:00
Daniel J Walsh 65f3bffc55 Fix cross compilation code for other platforms
When trying to vendor into containers/image we found issues
with cross platform compilation.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-03-20 08:36:26 -04:00
Daniel J Walsh 69f16a0a2d Move pkg/util default storage functions from libpod to containers/storage
In an effort to remove cross vendoring, trying to fix buildah from importing
from libpod.  I beleive these libraries make more sense in containers/storage
then in libpod.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-03-19 08:33:42 -04:00
Victor Vieux 8a70ccefb0 remove utils.go
Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
2014-03-10 21:06:27 +00:00
Michael Crosby 36dab5aae7 Move runtime and container into sub pkg
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
2014-03-09 23:03:40 -07:00
Alexander Larsson d9a682fba3 Drop EofReader
This is not used any more

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
2014-02-14 13:46:21 +01:00
Solomon Hykes ed03dc32cb Move the canonical run configuration objects to a sub-package
* Config is now runconfig.Config
    * HostConfig is now runconfig.HostConfig
    * MergeConfig is now runconfig.Merge
    * CompareConfig is now runconfig.Compare
    * ParseRun is now runconfig.Parse
    * ContainerConfigFromJob is now runconfig.ContainerConfigFromJob
    * ContainerHostConfigFromJob is now runconfig.ContainerHostConfigFromJob

This facilitates refactoring commands.go and shrinks the core.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
2014-02-11 20:18:46 -08:00
Solomon Hykes e9b6fef8ea pkg/opts: a collection of custom value parsers implementing flag.Value
This facilitates the refactoring of commands.go.

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
2014-02-11 19:59:52 -08:00
Solomon Hykes c3a8b359b0 New package `nat`: utilities for manipulating the text description of network ports.
This facilitates the refactoring of commands.go

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
2014-02-11 16:51:01 -08:00
Alexander Larsson 24a32a47d1 Add Put() to graphdriver API and use it
This makes all users of Put() have a corresponding call
to Get() which means we will be able to track whether
any particular ID is in use and if not unmount it.

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
2014-01-21 11:25:37 +01:00
Michael Crosby 4969309d87 Move RootIsShared to lxc driver
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
2014-01-17 17:42:22 -08:00