Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"path/filepath"
"strings"
"syscall"

"github.com/opencontainers/go-digest"
)
Expand Down Expand Up @@ -115,19 +114,12 @@ func (c *context) Resource(p string, fi os.FileInfo) (Resource, error) {
}
}

// TODO(stevvooe): This need to be resolved for the container's root,
// where here we are really getting the host OS's value. We need to allow
// this be passed in and fixed up to make these uid/gid mappings portable.
// Either this can be part of the driver or we can achieve it through some
// other mechanism.
sys, ok := fi.Sys().(*syscall.Stat_t)
if !ok {
// TODO(stevvooe): This may not be a hard error for all platforms. We
// may want to move this to the driver.
return nil, fmt.Errorf("unable to resolve syscall.Stat_t from (os.FileInfo).Sys(): %#v", fi)
uid, gid, err := getUidGidFromFileInfo(fi)
if err != nil {
return nil, err
}

base, err := newBaseResource(p, fi.Mode(), fmt.Sprint(sys.Uid), fmt.Sprint(sys.Gid))
base, err := newBaseResource(p, fi.Mode(), fmt.Sprint(uid), fmt.Sprint(gid))
if err != nil {
return nil, err
}
Expand Down
26 changes: 26 additions & 0 deletions context_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// +build linux darwin

package continuity

import (
"fmt"
"os"
"syscall"
)

// getUidGidFromFileInfo extracts the user and group IDs from a fileinfo.
// This is Unix-specific functionality.
func getUidGidFromFileInfo(fi os.FileInfo) (uint32, uint32, error) {
// TODO(stevvooe): This need to be resolved for the container's root,
// where here we are really getting the host OS's value. We need to allow
// this be passed in and fixed up to make these uid/gid mappings portable.
// Either this can be part of the driver or we can achieve it through some
// other mechanism.
sys, ok := fi.Sys().(*syscall.Stat_t)
if !ok {
// TODO(stevvooe): This may not be a hard error for all platforms. We
// may want to move this to the driver.
return 0, 0, fmt.Errorf("unable to resolve syscall.Stat_t from (os.FileInfo).Sys(): %#v", fi)
}
return sys.Uid, sys.Gid, nil
}
9 changes: 9 additions & 0 deletions context_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package continuity

import "os"

// getUidGidFromFileInfo extracts the user and group IDs from a fileinfo.
// This is Unix-specific functionality.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there still not an owner and group in msft? We made these strings specifically to be compatible here. Seems odd removing it. How will this data be recovered when used with continuity?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UID/GID are very Unix specific. Windows uses ACES in ACLS (https://msdn.microsoft.com/en-us/library/windows/desktop/aa374872(v=vs.85).aspx). Certainly as a longer-term plan, this needs to be considered. However, I wish to re-iterate this is just to get this component to compile on Windows, not to functionally prove it. It allows forward progress on containerd.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not foresee putting ACEs in uid/gid? If not, can we revert these fields to integers?

On other systems, I have seen these as strings since they can be used for the ACE identifier, but I may be missing something here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The easiest way to encode an ACL is in SDDL which is essentially a string. See https://msdn.microsoft.com/en-us/library/windows/desktop/aa379567(v=vs.85).aspx. You can see an example of SDDL in the docker code base such as https://github.com/moby/moby/blob/master/pkg/system/filesys_windows.go#L99-L120.

Calling them a uid or gid is really not appropriate on Windows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhowardmsft Sounds like we'll need another field...

func getUidGidFromFileInfo(fi os.FileInfo) (uint32, uint32, error) {
return 0, 0, nil
}
14 changes: 2 additions & 12 deletions driver.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package continuity

import (
"errors"
"os"
"strconv"
)
Expand Down Expand Up @@ -144,15 +143,6 @@ func (d *driver) Symlink(oldname, newname string) error {
return os.Symlink(oldname, newname)
}

func (d *driver) Mknod(path string, mode os.FileMode, major, minor int) error {
return mknod(path, mode, major, minor)
}

func (d *driver) Mkfifo(path string, mode os.FileMode) error {
if mode&os.ModeNamedPipe == 0 {
return errors.New("mode passed to Mkfifo does not have the named pipe bit set")
}
// mknod with a mode that has ModeNamedPipe set creates a fifo, not a
// device.
return mknod(path, mode, 0, 0)
func (d *driver) DeviceInfo(fi os.FileInfo) (maj uint64, min uint64, err error) {
return deviceInfo(fi)
}
7 changes: 0 additions & 7 deletions driver_darwin.go

This file was deleted.

14 changes: 12 additions & 2 deletions driver_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package continuity

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -102,6 +103,15 @@ func (d *driver) LSetxattr(path string, attrMap map[string][]byte) error {
return nil
}

func (d *driver) DeviceInfo(fi os.FileInfo) (maj uint64, min uint64, err error) {
return deviceInfo(fi)
func (d *driver) Mknod(path string, mode os.FileMode, major, minor int) error {
return mknod(path, mode, major, minor)
}

func (d *driver) Mkfifo(path string, mode os.FileMode) error {
if mode&os.ModeNamedPipe == 0 {
return errors.New("mode passed to Mkfifo does not have the named pipe bit set")
}
// mknod with a mode that has ModeNamedPipe set creates a fifo, not a
// device.
return mknod(path, mode, 0, 0)
}
30 changes: 30 additions & 0 deletions driver_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package continuity

import (
"fmt"
"os"
)

var (
errdeviceInfoNotImplemented = fmt.Errorf("deviceInfo not implemented on Windows")
errLchmodNotImplemented = fmt.Errorf("Lchmod not implemented on Windows")
errMknodNotImplemented = fmt.Errorf("Mknod not implemented on Windows")
errMkfifoNotImplemented = fmt.Errorf("Mkfifo not implemented on Windows")
)

func deviceInfo(fi os.FileInfo) (maj uint64, min uint64, err error) {
return 0, 0, errdeviceInfoNotImplemented
}

// Lchmod changes the mode of an file not following symlinks.
func (d *driver) Lchmod(path string, mode os.FileMode) (err error) {
return errLchmodNotImplemented
}

func (d *driver) Mknod(path string, mode os.FileMode, major, minor int) error {
return errMknodNotImplemented
}

func (d *driver) Mkfifo(path string, mode os.FileMode) error {
return errMkfifoNotImplemented
}
2 changes: 2 additions & 0 deletions groups_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux darwin

package continuity

import (
Expand Down
3 changes: 2 additions & 1 deletion hardlinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
)

var (
errNotAHardLink = fmt.Errorf("invalid hardlink")
errNotAHardLink = fmt.Errorf("invalid hardlink")
errNotHardLinkImplemented = fmt.Errorf("hardlink not implemented")
)

type hardlinkManager struct {
Expand Down
2 changes: 2 additions & 0 deletions hardlinks_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build linux darwin

package continuity

import (
Expand Down
14 changes: 14 additions & 0 deletions hardlinks_windows.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package continuity

import "os"

// NOTE(stevvooe): Obviously, this is not yet implemented. However, the
// makings of an implementation are available in src/os/types_windows.go. More
// investigation needs to be done to figure out exactly how to do this.

// hardlinkKey provides a tuple-key for managing hardlinks. This is system-
// specific.
type hardlinkKey struct {
}

// newHardlinkKey returns a hardlink key for the provided file info. If the
// resource does not represent a possible hardlink, errNotAHardLink will be
// returned.
func newHardlinkKey(fi os.FileInfo) (hardlinkKey, error) {
return hardlinkKey{}, errNotHardLinkImplemented
}
Loading