Browse Source

Remove error return from RootPair

There is no case which would resolve in this error. The root user always exists, and if the id maps are empty, the default value of 0 is correct.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin 8 years ago
parent
commit
93fbdb69ac

+ 1 - 1
daemon/archive.go

@@ -375,7 +375,7 @@ func (daemon *Daemon) CopyOnBuild(cID, destPath, srcRoot, srcPath string, decomp
 
 
 	destExists := true
 	destExists := true
 	destDir := false
 	destDir := false
-	rootIDs, _ := daemon.idMappings.RootPair()
+	rootIDs := daemon.idMappings.RootPair()
 
 
 	// Work in daemon-local OS specific file paths
 	// Work in daemon-local OS specific file paths
 	destPath = filepath.FromSlash(destPath)
 	destPath = filepath.FromSlash(destPath)

+ 3 - 3
daemon/container_operations_unix.go

@@ -109,7 +109,7 @@ func (daemon *Daemon) setupIpcDirs(c *container.Container) error {
 		}
 		}
 		c.ShmPath = "/dev/shm"
 		c.ShmPath = "/dev/shm"
 	} else {
 	} else {
-		rootIDs, _ := daemon.idMappings.RootPair()
+		rootIDs := daemon.idMappings.RootPair()
 		if !c.HasMountFor("/dev/shm") {
 		if !c.HasMountFor("/dev/shm") {
 			shmPath, err := c.ShmResourcePath()
 			shmPath, err := c.ShmResourcePath()
 			if err != nil {
 			if err != nil {
@@ -147,7 +147,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
 	logrus.Debugf("secrets: setting up secret dir: %s", localMountPath)
 	logrus.Debugf("secrets: setting up secret dir: %s", localMountPath)
 
 
 	// retrieve possible remapped range start for root UID, GID
 	// retrieve possible remapped range start for root UID, GID
-	rootIDs, _ := daemon.idMappings.RootPair()
+	rootIDs := daemon.idMappings.RootPair()
 	// create tmpfs
 	// create tmpfs
 	if err := idtools.MkdirAllAndChown(localMountPath, 0700, rootIDs); err != nil {
 	if err := idtools.MkdirAllAndChown(localMountPath, 0700, rootIDs); err != nil {
 		return errors.Wrap(err, "error creating secret local mount path")
 		return errors.Wrap(err, "error creating secret local mount path")
@@ -232,7 +232,7 @@ func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
 	logrus.Debugf("configs: setting up config dir: %s", localPath)
 	logrus.Debugf("configs: setting up config dir: %s", localPath)
 
 
 	// retrieve possible remapped range start for root UID, GID
 	// retrieve possible remapped range start for root UID, GID
-	rootIDs, _ := daemon.idMappings.RootPair()
+	rootIDs := daemon.idMappings.RootPair()
 	// create tmpfs
 	// create tmpfs
 	if err := idtools.MkdirAllAndChown(localPath, 0700, rootIDs); err != nil {
 	if err := idtools.MkdirAllAndChown(localPath, 0700, rootIDs); err != nil {
 		return errors.Wrap(err, "error creating config dir")
 		return errors.Wrap(err, "error creating config dir")

+ 1 - 4
daemon/create.go

@@ -117,10 +117,7 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
 		return nil, err
 		return nil, err
 	}
 	}
 
 
-	rootIDs, err := daemon.idMappings.RootPair()
-	if err != nil {
-		return nil, err
-	}
+	rootIDs := daemon.idMappings.RootPair()
 	if err := idtools.MkdirAndChown(container.Root, 0700, rootIDs); err != nil {
 	if err := idtools.MkdirAndChown(container.Root, 0700, rootIDs); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}

+ 1 - 1
daemon/create_unix.go

@@ -22,7 +22,7 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain
 	}
 	}
 	defer daemon.Unmount(container)
 	defer daemon.Unmount(container)
 
 
-	rootIDs, _ := daemon.idMappings.RootPair()
+	rootIDs := daemon.idMappings.RootPair()
 	if err := container.SetupWorkingDirectory(rootIDs); err != nil {
 	if err := container.SetupWorkingDirectory(rootIDs); err != nil {
 		return err
 		return err
 	}
 	}

+ 3 - 16
daemon/daemon.go

@@ -527,11 +527,7 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
-	rootIDs, err := idMappings.RootPair()
-	if err != nil {
-		return nil, err
-	}
-
+	rootIDs := idMappings.RootPair()
 	if err := setupDaemonProcess(config); err != nil {
 	if err := setupDaemonProcess(config); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -994,7 +990,7 @@ func prepareTempDir(rootDir string, rootIDs idtools.IDPair) (string, error) {
 }
 }
 
 
 func (daemon *Daemon) setupInitLayer(initPath string) error {
 func (daemon *Daemon) setupInitLayer(initPath string) error {
-	rootIDs, _ := daemon.idMappings.RootPair()
+	rootIDs := daemon.idMappings.RootPair()
 	return initlayer.Setup(initPath, rootIDs)
 	return initlayer.Setup(initPath, rootIDs)
 }
 }
 
 
@@ -1157,14 +1153,5 @@ func CreateDaemonRoot(config *config.Config) error {
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	rootIDs, err := idMappings.RootPair()
-	if err != nil {
-		return err
-	}
-
-	if err := setupDaemonRoot(config, realRoot, rootIDs); err != nil {
-		return err
-	}
-
-	return nil
+	return setupDaemonRoot(config, realRoot, idMappings.RootPair())
 }
 }

+ 2 - 8
daemon/graphdriver/vfs/driver.go

@@ -28,10 +28,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
 		home:       home,
 		home:       home,
 		idMappings: idtools.NewIDMappingsFromMaps(uidMaps, gidMaps),
 		idMappings: idtools.NewIDMappingsFromMaps(uidMaps, gidMaps),
 	}
 	}
-	rootIDs, err := d.idMappings.RootPair()
-	if err != nil {
-		return nil, err
-	}
+	rootIDs := d.idMappings.RootPair()
 	if err := idtools.MkdirAllAndChown(home, 0700, rootIDs); err != nil {
 	if err := idtools.MkdirAllAndChown(home, 0700, rootIDs); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
@@ -79,10 +76,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
 	}
 	}
 
 
 	dir := d.dir(id)
 	dir := d.dir(id)
-	rootIDs, err := d.idMappings.RootPair()
-	if err != nil {
-		return err
-	}
+	rootIDs := d.idMappings.RootPair()
 	if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0700, rootIDs); err != nil {
 	if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0700, rootIDs); err != nil {
 		return err
 		return err
 	}
 	}

+ 1 - 1
daemon/info.go

@@ -72,7 +72,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
 	if selinuxEnabled() {
 	if selinuxEnabled() {
 		securityOptions = append(securityOptions, "name=selinux")
 		securityOptions = append(securityOptions, "name=selinux")
 	}
 	}
-	rootIDs, _ := daemon.idMappings.RootPair()
+	rootIDs := daemon.idMappings.RootPair()
 	if rootIDs.UID != 0 || rootIDs.GID != 0 {
 	if rootIDs.UID != 0 || rootIDs.GID != 0 {
 		securityOptions = append(securityOptions, "name=userns")
 		securityOptions = append(securityOptions, "name=userns")
 	}
 	}

+ 1 - 2
daemon/oci_linux.go

@@ -611,8 +611,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
 		Path:     c.BaseFS,
 		Path:     c.BaseFS,
 		Readonly: c.HostConfig.ReadonlyRootfs,
 		Readonly: c.HostConfig.ReadonlyRootfs,
 	}
 	}
-	rootIDs, _ := daemon.idMappings.RootPair()
-	if err := c.SetupWorkingDirectory(rootIDs); err != nil {
+	if err := c.SetupWorkingDirectory(daemon.idMappings.RootPair()); err != nil {
 		return err
 		return err
 	}
 	}
 	cwd := c.Config.WorkingDir
 	cwd := c.Config.WorkingDir

+ 1 - 2
daemon/oci_solaris.go

@@ -130,8 +130,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
 		Path:     filepath.Dir(c.BaseFS),
 		Path:     filepath.Dir(c.BaseFS),
 		Readonly: c.HostConfig.ReadonlyRootfs,
 		Readonly: c.HostConfig.ReadonlyRootfs,
 	}
 	}
-	rootIDs, _ := daemon.idMappings.RootPair()
-	if err := c.SetupWorkingDirectory(rootIDs); err != nil {
+	if err := c.SetupWorkingDirectory(daemon.idMappings.RootPair()); err != nil {
 		return err
 		return err
 	}
 	}
 	cwd := c.Config.WorkingDir
 	cwd := c.Config.WorkingDir

+ 2 - 3
daemon/volumes_unix.go

@@ -54,8 +54,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
 			return nil
 			return nil
 		}
 		}
 
 
-		rootIDs, _ := daemon.idMappings.RootPair()
-		path, err := m.Setup(c.MountLabel, rootIDs, checkfunc)
+		path, err := m.Setup(c.MountLabel, daemon.idMappings.RootPair(), checkfunc)
 		if err != nil {
 		if err != nil {
 			return nil, err
 			return nil, err
 		}
 		}
@@ -85,7 +84,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
 	// if we are going to mount any of the network files from container
 	// if we are going to mount any of the network files from container
 	// metadata, the ownership must be set properly for potential container
 	// metadata, the ownership must be set properly for potential container
 	// remapped root (user namespaces)
 	// remapped root (user namespaces)
-	rootIDs, _ := daemon.idMappings.RootPair()
+	rootIDs := daemon.idMappings.RootPair()
 	for _, mount := range netMounts {
 	for _, mount := range netMounts {
 		if err := os.Chown(mount.Source, rootIDs.UID, rootIDs.GID); err != nil {
 		if err := os.Chown(mount.Source, rootIDs.UID, rootIDs.GID); err != nil {
 			return nil, err
 			return nil, err

+ 1 - 2
daemon/workdir.go

@@ -16,6 +16,5 @@ func (daemon *Daemon) ContainerCreateWorkdir(cID string) error {
 		return err
 		return err
 	}
 	}
 	defer daemon.Unmount(container)
 	defer daemon.Unmount(container)
-	rootIDs, _ := daemon.idMappings.RootPair()
-	return container.SetupWorkingDirectory(rootIDs)
+	return container.SetupWorkingDirectory(daemon.idMappings.RootPair())
 }
 }

+ 2 - 8
pkg/archive/archive.go

@@ -803,10 +803,7 @@ func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) err
 
 
 	var dirs []*tar.Header
 	var dirs []*tar.Header
 	idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
 	idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
-	rootIDs, err := idMappings.RootPair()
-	if err != nil {
-		return err
-	}
+	rootIDs := idMappings.RootPair()
 	whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat)
 	whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat)
 
 
 	// Iterate through the files in the archive.
 	// Iterate through the files in the archive.
@@ -1008,10 +1005,7 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error {
 	// if this archiver is set up with ID mapping we need to create
 	// if this archiver is set up with ID mapping we need to create
 	// the new destination directory with the remapped root UID/GID pair
 	// the new destination directory with the remapped root UID/GID pair
 	// as owner
 	// as owner
-	rootIDs, err := archiver.IDMappings.RootPair()
-	if err != nil {
-		return err
-	}
+	rootIDs := archiver.IDMappings.RootPair()
 	// Create dst, copy src's content into it
 	// Create dst, copy src's content into it
 	logrus.Debugf("Creating dest directory: %s", dst)
 	logrus.Debugf("Creating dest directory: %s", dst)
 	if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil {
 	if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil {

+ 1 - 4
pkg/chrootarchive/archive.go

@@ -47,10 +47,7 @@ func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions
 	}
 	}
 
 
 	idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
 	idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
-	rootIDs, err := idMappings.RootPair()
-	if err != nil {
-		return err
-	}
+	rootIDs := idMappings.RootPair()
 
 
 	dest = filepath.Clean(dest)
 	dest = filepath.Clean(dest)
 	if _, err := os.Stat(dest); os.IsNotExist(err) {
 	if _, err := os.Stat(dest); os.IsNotExist(err) {

+ 8 - 8
pkg/idtools/idtools.go

@@ -158,19 +158,19 @@ func NewIDMappingsFromMaps(uids []IDMap, gids []IDMap) *IDMappings {
 	return &IDMappings{uids: uids, gids: gids}
 	return &IDMappings{uids: uids, gids: gids}
 }
 }
 
 
-// RootPair returns a uid and gid pair for the root user
-func (i *IDMappings) RootPair() (IDPair, error) {
-	uid, gid, err := GetRootUIDGID(i.uids, i.gids)
-	return IDPair{UID: uid, GID: gid}, err
+// RootPair returns a uid and gid pair for the root user. The error is ignored
+// because a root user always exists, and the defaults are correct when the uid
+// and gid maps are empty.
+func (i *IDMappings) RootPair() IDPair {
+	uid, gid, _ := GetRootUIDGID(i.uids, i.gids)
+	return IDPair{UID: uid, GID: gid}
 }
 }
 
 
 // ToHost returns the host UID and GID for the container uid, gid.
 // ToHost returns the host UID and GID for the container uid, gid.
 // Remapping is only performed if the ids aren't already the remapped root ids
 // Remapping is only performed if the ids aren't already the remapped root ids
 func (i *IDMappings) ToHost(pair IDPair) (IDPair, error) {
 func (i *IDMappings) ToHost(pair IDPair) (IDPair, error) {
-	target, err := i.RootPair()
-	if err != nil {
-		return IDPair{}, err
-	}
+	var err error
+	target := i.RootPair()
 
 
 	if pair.UID != target.UID {
 	if pair.UID != target.UID {
 		target.UID, err = toHost(pair.UID, i.uids)
 		target.UID, err = toHost(pair.UID, i.uids)