Merge pull request #335 from Random-Liu/fix-fs-uuid

Use device number to find uuid
This commit is contained in:
Lantao Liu 2017-10-10 16:06:18 -07:00 committed by GitHub
commit d50c610947
3 changed files with 12 additions and 14 deletions

View File

@ -45,7 +45,7 @@ type OS interface {
Unmount(target string, flags int) error Unmount(target string, flags int) error
GetMounts() ([]*mount.Info, error) GetMounts() ([]*mount.Info, error)
LookupMount(path string) (containerdmount.Info, error) LookupMount(path string) (containerdmount.Info, error)
DeviceUUID(device string) (string, error) DeviceUUID(device uint64) (string, error)
} }
// RealOS is used to dispatch the real system level operations. // RealOS is used to dispatch the real system level operations.
@ -144,14 +144,9 @@ func blkrdev(device string) (uint64, error) {
return stat.Rdev, nil return stat.Rdev, nil
} }
// DeviceUUID gets device uuid of a device. The passed in device should be // DeviceUUID gets device uuid of a device. The passed in rdev should be
// an absolute path of the device. // linux device number.
func (RealOS) DeviceUUID(device string) (string, error) { func (RealOS) DeviceUUID(rdev uint64) (string, error) {
rdev, err := blkrdev(device)
if err != nil {
return "", err
}
const uuidDir = "/dev/disk/by-uuid" const uuidDir = "/dev/disk/by-uuid"
files, err := ioutil.ReadDir(uuidDir) files, err := ioutil.ReadDir(uuidDir)
if err != nil { if err != nil {
@ -169,5 +164,5 @@ func (RealOS) DeviceUUID(device string) (string, error) {
return file.Name(), nil return file.Name(), nil
} }
} }
return "", fmt.Errorf("device %q not found", device) return "", fmt.Errorf("device %d not found", rdev)
} }

View File

@ -52,7 +52,7 @@ type FakeOS struct {
UnmountFn func(target string, flags int) error UnmountFn func(target string, flags int) error
GetMountsFn func() ([]*mount.Info, error) GetMountsFn func() ([]*mount.Info, error)
LookupMountFn func(path string) (containerdmount.Info, error) LookupMountFn func(path string) (containerdmount.Info, error)
DeviceUUIDFn func(device string) (string, error) DeviceUUIDFn func(device uint64) (string, error)
calls []CalledDetail calls []CalledDetail
errors map[string]error errors map[string]error
} }
@ -258,7 +258,7 @@ func (f *FakeOS) LookupMount(path string) (containerdmount.Info, error) {
} }
// DeviceUUID is a fake call that invodes DeviceUUIDFn or just return nil. // DeviceUUID is a fake call that invodes DeviceUUIDFn or just return nil.
func (f *FakeOS) DeviceUUID(device string) (string, error) { func (f *FakeOS) DeviceUUID(device uint64) (string, error) {
f.appendCalls("DeviceUUID", device) f.appendCalls("DeviceUUID", device)
if err := f.getError("DeviceUUID"); err != nil { if err := f.getError("DeviceUUID"); err != nil {
return "", err return "", err

View File

@ -34,6 +34,7 @@ import (
runcapparmor "github.com/opencontainers/runc/libcontainer/apparmor" runcapparmor "github.com/opencontainers/runc/libcontainer/apparmor"
runcseccomp "github.com/opencontainers/runc/libcontainer/seccomp" runcseccomp "github.com/opencontainers/runc/libcontainer/seccomp"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix"
"google.golang.org/grpc" "google.golang.org/grpc"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
"k8s.io/kubernetes/pkg/kubelet/server/streaming" "k8s.io/kubernetes/pkg/kubelet/server/streaming"
@ -143,6 +144,7 @@ func NewCRIContainerdService(config options.Config) (CRIContainerdService, error
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get imagefs uuid of %q: %v", imageFSPath, err) return nil, fmt.Errorf("failed to get imagefs uuid of %q: %v", imageFSPath, err)
} }
glog.V(2).Infof("Get device uuid %q for image filesystem %q", c.imageFSUUID, imageFSPath)
c.netPlugin, err = ocicni.InitCNI(config.NetworkPluginConfDir, config.NetworkPluginBinDir) c.netPlugin, err = ocicni.InitCNI(config.NetworkPluginConfDir, config.NetworkPluginBinDir)
if err != nil { if err != nil {
@ -243,11 +245,12 @@ func (c *criContainerdService) Stop() {
// getDeviceUUID gets device uuid for a given path. // getDeviceUUID gets device uuid for a given path.
func (c *criContainerdService) getDeviceUUID(path string) (string, error) { func (c *criContainerdService) getDeviceUUID(path string) (string, error) {
info, err := c.os.LookupMount(path) mount, err := c.os.LookupMount(path)
if err != nil { if err != nil {
return "", err return "", err
} }
return c.os.DeviceUUID(info.Source) rdev := unix.Mkdev(uint32(mount.Major), uint32(mount.Minor))
return c.os.DeviceUUID(rdev)
} }
// imageFSPath returns containerd image filesystem path. // imageFSPath returns containerd image filesystem path.