mirror of
https://github.com/containers/podman.git
synced 2025-07-03 09:17:15 +08:00
Update container Mounted() and Mountpoint() functions
Addresses a regression in `podman mount` due to our mount changes to allow concurrency by letting c/storage handle mounting and unmounting. Combine Mounted() and Mountpoint() into one function and query c/storage directly to ensure we get accurate information. Fixes: #1143 Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #1144 Approved by: baude
This commit is contained in:
@ -105,13 +105,15 @@ func mountCmd(c *cli.Context) error {
|
|||||||
return errors.Wrapf(err2, "error reading list of all containers")
|
return errors.Wrapf(err2, "error reading list of all containers")
|
||||||
}
|
}
|
||||||
for _, container := range containers {
|
for _, container := range containers {
|
||||||
mountPoint, err := container.Mountpoint()
|
mounted, mountPoint, err := container.Mounted()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "error getting mountpoint for %q", container.ID())
|
return errors.Wrapf(err, "error getting mountpoint for %q", container.ID())
|
||||||
}
|
}
|
||||||
if mountPoint == "" {
|
|
||||||
|
if !mounted {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if json {
|
if json {
|
||||||
jsonMountPoints = append(jsonMountPoints, jsonMountPoint{ID: container.ID(), Names: []string{container.Name()}, MountPoint: mountPoint})
|
jsonMountPoints = append(jsonMountPoints, jsonMountPoint{ID: container.ID(), Names: []string{container.Name()}, MountPoint: mountPoint})
|
||||||
continue
|
continue
|
||||||
|
@ -617,31 +617,37 @@ func (c *Container) State() (ContainerStatus, error) {
|
|||||||
return c.state.State, nil
|
return c.state.State, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mounted returns a bool as to if the container's storage
|
// Mounted returns whether the container is mounted and the path it is mounted
|
||||||
// is mounted
|
// at (if it is mounted).
|
||||||
func (c *Container) Mounted() (bool, error) {
|
// If the container is not mounted, no error is returned, and the mountpoint
|
||||||
|
// will be set to "".
|
||||||
|
func (c *Container) Mounted() (bool, string, error) {
|
||||||
if !c.batched {
|
if !c.batched {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
if err := c.syncContainer(); err != nil {
|
if err := c.syncContainer(); err != nil {
|
||||||
return false, errors.Wrapf(err, "error updating container %s state", c.ID())
|
return false, "", errors.Wrapf(err, "error updating container %s state", c.ID())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c.state.Mounted, nil
|
// We cannot directly return c.state.Mountpoint as it is not guaranteed
|
||||||
}
|
// to be set if the container is mounted, only if the container has been
|
||||||
|
// prepared with c.prepare().
|
||||||
|
// Instead, let's call into c/storage
|
||||||
|
mountedTimes, err := c.runtime.storageService.MountedContainerImage(c.ID())
|
||||||
|
if err != nil {
|
||||||
|
return false, "", err
|
||||||
|
}
|
||||||
|
|
||||||
// Mountpoint returns the path to the container's mounted storage as a string
|
if mountedTimes > 0 {
|
||||||
// If the container is not mounted, no error is returned, but the mountpoint
|
mountPoint, err := c.runtime.storageService.GetMountpoint(c.ID())
|
||||||
// will be ""
|
if err != nil {
|
||||||
func (c *Container) Mountpoint() (string, error) {
|
return false, "", err
|
||||||
if !c.batched {
|
|
||||||
c.lock.Lock()
|
|
||||||
defer c.lock.Unlock()
|
|
||||||
if err := c.syncContainer(); err != nil {
|
|
||||||
return "", errors.Wrapf(err, "error updating container %s state", c.ID())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true, mountPoint, nil
|
||||||
}
|
}
|
||||||
return c.state.Mountpoint, nil
|
|
||||||
|
return false, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartedTime is the time the container was started
|
// StartedTime is the time the container was started
|
||||||
|
@ -263,6 +263,22 @@ func (r *storageService) MountedContainerImage(idOrName string) (int, error) {
|
|||||||
return mounted, nil
|
return mounted, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *storageService) GetMountpoint(id string) (string, error) {
|
||||||
|
container, err := r.store.Container(id)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Cause(err) == storage.ErrContainerUnknown {
|
||||||
|
return "", ErrNoSuchCtr
|
||||||
|
}
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
layer, err := r.store.Layer(container.LayerID)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return layer.MountPoint, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *storageService) GetWorkDir(id string) (string, error) {
|
func (r *storageService) GetWorkDir(id string) (string, error) {
|
||||||
container, err := r.store.Container(id)
|
container, err := r.store.Container(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user