Skip to content

Commit

Permalink
Merge pull request #4670 from mheon/backports_for_164
Browse files Browse the repository at this point in the history
Backports for v1.6.4
  • Loading branch information
openshift-merge-robot authored Dec 11, 2019
2 parents 94b7842 + ba00eb5 commit 28029fb
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ env:
###
_BUILT_IMAGE_SUFFIX: "libpod-5642998972416000"
FEDORA_CACHE_IMAGE_NAME: "fedora-30-${_BUILT_IMAGE_SUFFIX}"
PRIOR_FEDORA_CACHE_IMAGE_NAME: "fedora-29-${_BUILT_IMAGE_SUFFIX}"
# PRIOR_FEDORA_CACHE_IMAGE_NAME: "fedora-29-${_BUILT_IMAGE_SUFFIX}"
SPECIAL_FEDORA_CACHE_IMAGE_NAME: "xfedora-30-${_BUILT_IMAGE_SUFFIX}"
UBUNTU_CACHE_IMAGE_NAME: "ubuntu-19-${_BUILT_IMAGE_SUFFIX}"
PRIOR_UBUNTU_CACHE_IMAGE_NAME: "ubuntu-18-${_BUILT_IMAGE_SUFFIX}"
Expand Down Expand Up @@ -273,7 +273,7 @@ meta_task:
# Space-separated list of images used by this repository state
IMGNAMES: >-
${FEDORA_CACHE_IMAGE_NAME}
${PRIOR_FEDORA_CACHE_IMAGE_NAME}
# ${PRIOR_FEDORA_CACHE_IMAGE_NAME}
${SPECIAL_FEDORA_CACHE_IMAGE_NAME}
${UBUNTU_CACHE_IMAGE_NAME}
${PRIOR_UBUNTU_CACHE_IMAGE_NAME}
Expand Down Expand Up @@ -332,7 +332,7 @@ testing_task:
matrix:
# Images are generated separately, from build_images_task (below)
image_name: "${FEDORA_CACHE_IMAGE_NAME}"
image_name: "${PRIOR_FEDORA_CACHE_IMAGE_NAME}"
# image_name: "${PRIOR_FEDORA_CACHE_IMAGE_NAME}"
# Multiple test failures on Ubuntu 19 - Fixes TBD in future PR
# TODO: image_name: "${UBUNTU_CACHE_IMAGE_NAME}"
image_name: "${PRIOR_UBUNTU_CACHE_IMAGE_NAME}"
Expand Down
4 changes: 0 additions & 4 deletions cmd/podman/main_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod/config"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/cgroups"
"github.com/containers/libpod/pkg/rootless"
Expand All @@ -34,9 +33,6 @@ const remote = false

func init() {
cgroupManager := define.SystemdCgroupsManager
if runtimeConfig, err := config.NewConfig(""); err == nil {
cgroupManager = runtimeConfig.CgroupManager
}
cgroupHelp := "Cgroup manager to use (cgroupfs or systemd)"
cgroupv2, _ := cgroups.IsCgroup2UnifiedMode()
if rootless.IsRootless() && !cgroupv2 {
Expand Down
19 changes: 11 additions & 8 deletions libpod/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ func NewConfig(userConfigPath string) (*Config, error) {
if defaultConfig, err := defaultConfigFromMemory(); err != nil {
return nil, errors.Wrapf(err, "error generating default config from memory")
} else {
// Check if we need to switch to cgroupfs and logger=file on rootless.
defaultConfig.checkCgroupsAndLogger()

if err := config.mergeConfig(defaultConfig); err != nil {
return nil, errors.Wrapf(err, "error merging default config from memory")
}
Expand All @@ -487,9 +490,6 @@ func NewConfig(userConfigPath string) (*Config, error) {
return nil, errors.Wrapf(define.ErrInvalidArg, "volume path must be an absolute path - instead got %q", config.VolumePath)
}

// Check if we need to switch to cgroupfs on rootless.
config.checkCgroupsAndAdjustConfig()

return config, nil
}

Expand Down Expand Up @@ -524,11 +524,13 @@ func systemConfigs() ([]string, error) {
return configs, nil
}

// checkCgroupsAndAdjustConfig checks if we're running rootless with the systemd
// checkCgroupsAndLogger checks if we're running rootless with the systemd
// cgroup manager. In case the user session isn't available, we're switching the
// cgroup manager to cgroupfs. Note, this only applies to rootless.
func (c *Config) checkCgroupsAndAdjustConfig() {
if !rootless.IsRootless() || c.CgroupManager != define.SystemdCgroupsManager {
// cgroup manager to cgroupfs and the events logger backend to 'file'.
// Note, this only applies to rootless.
func (c *Config) checkCgroupsAndLogger() {
if !rootless.IsRootless() || (c.CgroupManager !=
define.SystemdCgroupsManager && c.EventsLogger == "file") {
return
}

Expand All @@ -543,7 +545,8 @@ func (c *Config) checkCgroupsAndAdjustConfig() {
logrus.Warningf("The cgroups manager is set to systemd but there is no systemd user session available")
logrus.Warningf("For using systemd, you may need to login using an user session")
logrus.Warningf("Alternatively, you can enable lingering with: `loginctl enable-linger %d` (possibly as root)", rootless.GetRootlessUID())
logrus.Warningf("Falling back to --cgroup-manager=cgroupfs")
logrus.Warningf("Falling back to --cgroup-manager=cgroupfs and --events-backend=file")
c.CgroupManager = define.CgroupfsCgroupsManager
c.EventsLogger = "file"
}
}
5 changes: 5 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ func (c *Container) removeConmonFiles() error {
return errors.Wrapf(err, "error removing container %s ctl file", c.ID())
}

winszFile := filepath.Join(c.bundlePath(), "winsz")
if err := os.Remove(winszFile); err != nil && !os.IsNotExist(err) {
return errors.Wrapf(err, "error removing container %s winsz file", c.ID())
}

oomFile := filepath.Join(c.bundlePath(), "oom")
if err := os.Remove(oomFile); err != nil && !os.IsNotExist(err) {
return errors.Wrapf(err, "error removing container %s OOM file", c.ID())
Expand Down
2 changes: 1 addition & 1 deletion libpod/events/journal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (e EventJournalD) Write(ee Event) error {

// Read reads events from the journal and sends qualified events to the event channel
func (e EventJournalD) Read(options ReadOptions) error {
defer close(options.EventChannel)
eventOptions, err := generateEventOptions(options.Filters, options.Since, options.Until)
if err != nil {
return errors.Wrapf(err, "failed to generate event options")
Expand Down Expand Up @@ -87,7 +88,6 @@ func (e EventJournalD) Read(options ReadOptions) error {
if err != nil {
return err
}
defer close(options.EventChannel)
for {
if _, err := j.Next(); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion libpod/events/logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (e EventLogFile) Write(ee Event) error {

// Reads from the log file
func (e EventLogFile) Read(options ReadOptions) error {
defer close(options.EventChannel)
eventOptions, err := generateEventOptions(options.Filters, options.Since, options.Until)
if err != nil {
return errors.Wrapf(err, "unable to generate event options")
Expand Down Expand Up @@ -68,7 +69,6 @@ func (e EventLogFile) Read(options ReadOptions) error {
options.EventChannel <- event
}
}
close(options.EventChannel)
return nil
}

Expand Down
18 changes: 14 additions & 4 deletions libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ func (r *Runtime) refresh(alivePath string) error {
}

// Next refresh the state of all containers to recreate dirs and
// namespaces, and all the pods to recreate cgroups
// namespaces, and all the pods to recreate cgroups.
// Containers, pods, and volumes must also reacquire their locks.
ctrs, err := r.state.AllContainers()
if err != nil {
return errors.Wrapf(err, "error retrieving all containers from state")
Expand All @@ -634,10 +635,14 @@ func (r *Runtime) refresh(alivePath string) error {
if err != nil {
return errors.Wrapf(err, "error retrieving all pods from state")
}
// No locks are taken during pod and container refresh.
// Furthermore, the pod and container refresh() functions are not
vols, err := r.state.AllVolumes()
if err != nil {
return errors.Wrapf(err, "error retrieving all volumes from state")
}
// No locks are taken during pod, volume, and container refresh.
// Furthermore, the pod/volume/container refresh() functions are not
// allowed to take locks themselves.
// We cannot assume that any pod or container has a valid lock until
// We cannot assume that any pod/volume/container has a valid lock until
// after this function has returned.
// The runtime alive lock should suffice to provide mutual exclusion
// until this has run.
Expand All @@ -651,6 +656,11 @@ func (r *Runtime) refresh(alivePath string) error {
logrus.Errorf("Error refreshing pod %s: %v", pod.ID(), err)
}
}
for _, vol := range vols {
if err := vol.refresh(); err != nil {
logrus.Errorf("Error refreshing volume %s: %v", vol.Name(), err)
}
}

// Create a file indicating the runtime is alive and ready
file, err := os.OpenFile(alivePath, os.O_RDONLY|os.O_CREATE, 0644)
Expand Down
12 changes: 12 additions & 0 deletions libpod/volume_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"

"github.com/containers/libpod/libpod/define"
"github.com/pkg/errors"
)

// Creates a new volume
Expand Down Expand Up @@ -46,3 +47,14 @@ func (v *Volume) update() error {
func (v *Volume) save() error {
return v.runtime.state.SaveVolume(v)
}

// Refresh volume state after a restart.
func (v *Volume) refresh() error {
lock, err := v.runtime.lockManager.AllocateAndRetrieveLock(v.config.LockID)
if err != nil {
return errors.Wrapf(err, "error acquiring lock %d for volume %s", v.config.LockID, v.Name())
}
v.lock = lock

return nil
}

0 comments on commit 28029fb

Please sign in to comment.