mirror of
https://github.com/containers/podman.git
synced 2025-12-01 02:27:13 +08:00
Vendor in containers/(storage,image, common, buildah)
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
39
vendor/github.com/containers/buildah/bind/mount.go
generated
vendored
39
vendor/github.com/containers/buildah/bind/mount.go
generated
vendored
@@ -4,6 +4,7 @@
|
||||
package bind
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -14,7 +15,6 @@ import (
|
||||
"github.com/containers/storage/pkg/idtools"
|
||||
"github.com/containers/storage/pkg/mount"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -29,28 +29,28 @@ func SetupIntermediateMountNamespace(spec *specs.Spec, bundlePath string) (unmou
|
||||
|
||||
// We expect a root directory to be defined.
|
||||
if spec.Root == nil {
|
||||
return nil, errors.Errorf("configuration has no root filesystem?")
|
||||
return nil, errors.New("configuration has no root filesystem?")
|
||||
}
|
||||
rootPath := spec.Root.Path
|
||||
|
||||
// Create a new mount namespace in which to do the things we're doing.
|
||||
if err := unix.Unshare(unix.CLONE_NEWNS); err != nil {
|
||||
return nil, errors.Wrapf(err, "error creating new mount namespace for %v", spec.Process.Args)
|
||||
return nil, fmt.Errorf("error creating new mount namespace for %v: %w", spec.Process.Args, err)
|
||||
}
|
||||
|
||||
// Make all of our mounts private to our namespace.
|
||||
if err := mount.MakeRPrivate("/"); err != nil {
|
||||
return nil, errors.Wrapf(err, "error making mounts private to mount namespace for %v", spec.Process.Args)
|
||||
return nil, fmt.Errorf("error making mounts private to mount namespace for %v: %w", spec.Process.Args, err)
|
||||
}
|
||||
|
||||
// Make sure the bundle directory is searchable. We created it with
|
||||
// TempDir(), so it should have started with permissions set to 0700.
|
||||
info, err := os.Stat(bundlePath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error checking permissions on %q", bundlePath)
|
||||
return nil, fmt.Errorf("error checking permissions on %q: %w", bundlePath, err)
|
||||
}
|
||||
if err = os.Chmod(bundlePath, info.Mode()|0111); err != nil {
|
||||
return nil, errors.Wrapf(err, "error loosening permissions on %q", bundlePath)
|
||||
return nil, fmt.Errorf("error loosening permissions on %q: %w", bundlePath, err)
|
||||
}
|
||||
|
||||
// Figure out who needs to be able to reach these bind mounts in order
|
||||
@@ -117,23 +117,23 @@ func SetupIntermediateMountNamespace(spec *specs.Spec, bundlePath string) (unmou
|
||||
// access.
|
||||
mnt := filepath.Join(bundlePath, "mnt")
|
||||
if err = idtools.MkdirAndChown(mnt, 0100, idtools.IDPair{UID: int(rootUID), GID: int(rootGID)}); err != nil {
|
||||
return unmountAll, errors.Wrapf(err, "error creating %q owned by the container's root user", mnt)
|
||||
return unmountAll, fmt.Errorf("error creating %q owned by the container's root user: %w", mnt, err)
|
||||
}
|
||||
|
||||
// Make that directory private, and add it to the list of locations we
|
||||
// unmount at cleanup time.
|
||||
if err = mount.MakeRPrivate(mnt); err != nil {
|
||||
return unmountAll, errors.Wrapf(err, "error marking filesystem at %q as private", mnt)
|
||||
return unmountAll, fmt.Errorf("error marking filesystem at %q as private: %w", mnt, err)
|
||||
}
|
||||
unmount = append([]string{mnt}, unmount...)
|
||||
|
||||
// Create a bind mount for the root filesystem and add it to the list.
|
||||
rootfs := filepath.Join(mnt, "rootfs")
|
||||
if err = os.Mkdir(rootfs, 0000); err != nil {
|
||||
return unmountAll, errors.Wrapf(err, "error creating directory %q", rootfs)
|
||||
return unmountAll, fmt.Errorf("error creating directory %q: %w", rootfs, err)
|
||||
}
|
||||
if err = unix.Mount(rootPath, rootfs, "", unix.MS_BIND|unix.MS_REC|unix.MS_PRIVATE, ""); err != nil {
|
||||
return unmountAll, errors.Wrapf(err, "error bind mounting root filesystem from %q to %q", rootPath, rootfs)
|
||||
return unmountAll, fmt.Errorf("error bind mounting root filesystem from %q to %q: %w", rootPath, rootfs, err)
|
||||
}
|
||||
logrus.Debugf("bind mounted %q to %q", rootPath, rootfs)
|
||||
unmount = append([]string{rootfs}, unmount...)
|
||||
@@ -154,28 +154,28 @@ func SetupIntermediateMountNamespace(spec *specs.Spec, bundlePath string) (unmou
|
||||
logrus.Warnf("couldn't find %q on host to bind mount into container", spec.Mounts[i].Source)
|
||||
continue
|
||||
}
|
||||
return unmountAll, errors.Wrapf(err, "error checking if %q is a directory", spec.Mounts[i].Source)
|
||||
return unmountAll, fmt.Errorf("error checking if %q is a directory: %w", spec.Mounts[i].Source, err)
|
||||
}
|
||||
stage := filepath.Join(mnt, fmt.Sprintf("buildah-bind-target-%d", i))
|
||||
if info.IsDir() {
|
||||
// If the source is a directory, make one to use as the
|
||||
// mount target.
|
||||
if err = os.Mkdir(stage, 0000); err != nil {
|
||||
return unmountAll, errors.Wrapf(err, "error creating directory %q", stage)
|
||||
return unmountAll, fmt.Errorf("error creating directory %q: %w", stage, err)
|
||||
}
|
||||
} else {
|
||||
// If the source is not a directory, create an empty
|
||||
// file to use as the mount target.
|
||||
file, err := os.OpenFile(stage, os.O_WRONLY|os.O_CREATE, 0000)
|
||||
if err != nil {
|
||||
return unmountAll, errors.Wrapf(err, "error creating file %q", stage)
|
||||
return unmountAll, fmt.Errorf("error creating file %q: %w", stage, err)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
// Bind mount the source from wherever it is to a place where
|
||||
// we know the runtime helper will be able to get to it...
|
||||
if err = unix.Mount(spec.Mounts[i].Source, stage, "", unix.MS_BIND|unix.MS_REC|unix.MS_PRIVATE, ""); err != nil {
|
||||
return unmountAll, errors.Wrapf(err, "error bind mounting bind object from %q to %q", spec.Mounts[i].Source, stage)
|
||||
return unmountAll, fmt.Errorf("error bind mounting bind object from %q to %q: %w", spec.Mounts[i].Source, stage, err)
|
||||
}
|
||||
logrus.Debugf("bind mounted %q to %q", spec.Mounts[i].Source, stage)
|
||||
spec.Mounts[i].Source = stage
|
||||
@@ -209,7 +209,7 @@ func leaveBindMountAlone(mount specs.Mount) bool {
|
||||
func UnmountMountpoints(mountpoint string, mountpointsToRemove []string) error {
|
||||
mounts, err := mount.GetMounts()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error retrieving list of mounts")
|
||||
return fmt.Errorf("error retrieving list of mounts: %w", err)
|
||||
}
|
||||
// getChildren returns the list of mount IDs that hang off of the
|
||||
// specified ID.
|
||||
@@ -255,7 +255,10 @@ func UnmountMountpoints(mountpoint string, mountpointsToRemove []string) error {
|
||||
// find the top of the tree we're unmounting
|
||||
top := getMountByPoint(mountpoint)
|
||||
if top == nil {
|
||||
return errors.Wrapf(err, "%q is not mounted", mountpoint)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%q is not mounted: %w", mountpoint, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// add all of the mounts that are hanging off of it
|
||||
tree := getTree(top.ID)
|
||||
@@ -270,7 +273,7 @@ func UnmountMountpoints(mountpoint string, mountpointsToRemove []string) error {
|
||||
logrus.Debugf("mountpoint %q is not present(?), skipping", mount.Mountpoint)
|
||||
continue
|
||||
}
|
||||
return errors.Wrapf(err, "error checking if %q is mounted", mount.Mountpoint)
|
||||
return fmt.Errorf("error checking if %q is mounted: %w", mount.Mountpoint, err)
|
||||
}
|
||||
if uint64(mount.Major) != uint64(st.Dev) || uint64(mount.Minor) != uint64(st.Dev) { //nolint:unconvert // (required for some OS/arch combinations)
|
||||
logrus.Debugf("%q is apparently not really mounted, skipping", mount.Mountpoint)
|
||||
@@ -293,7 +296,7 @@ func UnmountMountpoints(mountpoint string, mountpointsToRemove []string) error {
|
||||
// if we're also supposed to remove this thing, do that, too
|
||||
if cutil.StringInSlice(mount.Mountpoint, mountpointsToRemove) {
|
||||
if err := os.Remove(mount.Mountpoint); err != nil {
|
||||
return errors.Wrapf(err, "error removing %q", mount.Mountpoint)
|
||||
return fmt.Errorf("error removing %q: %w", mount.Mountpoint, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user