Skip to content

Commit

Permalink
Backport wildcard virtio prefix
Browse files Browse the repository at this point in the history
Cherry-picked

* ac7b49b
* 8a1a382

Bumped additional bosh-utils vendor files since there were some
additional bumps between us and 8a1a382.

[#129982207](https://www.pivotaltracker.com/story/show/129982207)

Signed-off-by: Danny Berger <dberger@pivotal.io>
  • Loading branch information
DennisDenuto authored and dpb587-pivotal committed Sep 13, 2016
1 parent 9636120 commit 287b000
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 56 deletions.
2 changes: 1 addition & 1 deletion deps.txt
Expand Up @@ -10,7 +10,7 @@ github.com/golang/mock/gomock:06883d9
github.com/nats-io/nats:d996dcd
github.com/onsi/gomega:d6dbcad
github.com/cloudfoundry/bosh-init/registry:c99761b
github.com/cloudfoundry/bosh-utils/...:06a8b54
github.com/cloudfoundry/bosh-utils/...:b5c4af4
github.com/cloudfoundry/bosh-davcli/...:6b59ec2
golang.org/x/sys/windows:7a56174
golang.org/x/sys/windows/...:7a56174
Expand Down
27 changes: 13 additions & 14 deletions infrastructure/devicepathresolver/id_device_path_resolver.go
Expand Up @@ -11,24 +11,19 @@ import (
boshsys "github.com/cloudfoundry/bosh-utils/system"
)

const defaultDevicePrefix = "virtio"

type idDevicePathResolver struct {
diskWaitTimeout time.Duration
devicePrefix string
udev boshudev.UdevDevice
fs boshsys.FileSystem
}

func NewIDDevicePathResolver(
diskWaitTimeout time.Duration,
devicePrefix string,
udev boshudev.UdevDevice,
fs boshsys.FileSystem,
) DevicePathResolver {
return idDevicePathResolver{
diskWaitTimeout: diskWaitTimeout,
devicePrefix: devicePrefix,
udev: udev,
fs: fs,
}
Expand Down Expand Up @@ -59,26 +54,30 @@ func (idpr idDevicePathResolver) GetRealDevicePath(diskSettings boshsettings.Dis
var realPath string

diskID := diskSettings.ID[0:20]
deviceID := fmt.Sprintf("%s-%s", defaultDevicePrefix, diskID)
if idpr.devicePrefix != "" {
deviceID = fmt.Sprintf("%s-%s", idpr.devicePrefix, diskID)
}
deviceGlobPattern := fmt.Sprintf("*%s", diskID)
deviceIDPathGlobPattern := path.Join("/", "dev", "disk", "by-id", deviceGlobPattern)

for !found {
if time.Now().After(stopAfter) {
return "", true, bosherr.Errorf("Timed out getting real device path for '%s'", diskID)
}

time.Sleep(100 * time.Millisecond)

deviceIDPath := path.Join("/", "dev", "disk", "by-id", deviceID)
realPath, err = idpr.fs.ReadLink(deviceIDPath)
realPathMatches, err := idpr.fs.Glob(deviceIDPathGlobPattern)
if err != nil {
continue
}

if idpr.fs.FileExists(realPath) {
found = true
switch len(realPathMatches) {
case 0:
continue
case 1:
realPath = realPathMatches[0]
if idpr.fs.FileExists(realPath) {
found = true
}
default:
return "", true, bosherr.Errorf("More than one disk matched glob %q while getting real device path for %q", deviceIDPathGlobPattern, diskID)
}
}

Expand Down
66 changes: 35 additions & 31 deletions infrastructure/devicepathresolver/id_device_path_resolver_test.go
Expand Up @@ -19,7 +19,6 @@ var _ = Describe("IDDevicePathResolver", func() {
var (
fs *fakesys.FakeFileSystem
udev *fakeudev.FakeUdevDevice
devicePrefix string
diskSettings boshsettings.DiskSettings
pathResolver DevicePathResolver
)
Expand All @@ -30,11 +29,10 @@ var _ = Describe("IDDevicePathResolver", func() {
diskSettings = boshsettings.DiskSettings{
ID: "fake-disk-id-include-truncate",
}
devicePrefix = ""
})

JustBeforeEach(func() {
pathResolver = NewIDDevicePathResolver(500*time.Millisecond, devicePrefix, udev, fs)
pathResolver = NewIDDevicePathResolver(500*time.Millisecond, udev, fs)
})

Describe("GetRealDevicePath", func() {
Expand All @@ -48,37 +46,40 @@ var _ = Describe("IDDevicePathResolver", func() {
BeforeEach(func() {
err := fs.MkdirAll("fake-device-path", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())
})

Context("when using the default device prefix", func() {
BeforeEach(func() {
err := fs.Symlink("fake-device-path", "/dev/disk/by-id/virtio-fake-disk-id-include")
Expect(err).ToNot(HaveOccurred())
})
err = fs.Symlink("fake-device-path", "/dev/disk/by-id/virtio-fake-disk-id-include")
Expect(err).ToNot(HaveOccurred())

It("returns the path", func() {
path, timeout, err := pathResolver.GetRealDevicePath(diskSettings)
Expect(err).ToNot(HaveOccurred())
fs.SetGlob("/dev/disk/by-id/*fake-disk-id-include", []string{"fake-device-path"})
})

Expect(path).To(Equal("fake-device-path"))
Expect(timeout).To(BeFalse())
})
It("returns the path", func() {
path, timeout, err := pathResolver.GetRealDevicePath(diskSettings)
Expect(err).ToNot(HaveOccurred())

Expect(path).To(Equal("fake-device-path"))
Expect(timeout).To(BeFalse())
})
})

Context("when using a custom device prefix", func() {
BeforeEach(func() {
devicePrefix = "prefix"
err := fs.Symlink("fake-device-path", "/dev/disk/by-id/prefix-fake-disk-id-include")
Expect(err).ToNot(HaveOccurred())
})
Context("when disks with the same ID but different virtio prefixes exist ", func() {
BeforeEach(func() {
err := fs.MkdirAll("fake-device-path-1", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())
err = fs.MkdirAll("fake-device-path-2", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())

It("returns the path", func() {
path, timeout, err := pathResolver.GetRealDevicePath(diskSettings)
Expect(err).ToNot(HaveOccurred())
err = fs.Symlink("fake-device-path-1", "/dev/disk/by-id/virtio-fake-disk-id-include")
Expect(err).ToNot(HaveOccurred())
err = fs.Symlink("fake-device-path-2", "/dev/disk/by-id/customprefix-fake-disk-id-include")
Expect(err).ToNot(HaveOccurred())

Expect(path).To(Equal("fake-device-path"))
Expect(timeout).To(BeFalse())
})
fs.SetGlob("/dev/disk/by-id/*fake-disk-id-include", []string{"fake-device-path-1", "fake-device-path-2"})
})
It("returns an error", func() {
_, _, err := pathResolver.GetRealDevicePath(diskSettings)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("More than one disk matched"))
})
})

Expand All @@ -104,13 +105,16 @@ var _ = Describe("IDDevicePathResolver", func() {
Context("when no matching device is found the first time", func() {
Context("when the timeout has not expired", func() {
BeforeEach(func() {
time.AfterFunc(100*time.Millisecond, func() {
fs.GlobStub = func(pattern string) ([]string, error) {
err := fs.MkdirAll("fake-device-path", os.FileMode(0750))
Expect(err).ToNot(HaveOccurred())

err = fs.Symlink("fake-device-path", "/dev/disk/by-id/virtio-fake-disk-id-include")
Expect(err).ToNot(HaveOccurred())
})
fs.SetGlob("/dev/disk/by-id/*fake-disk-id-include", []string{"fake-device-path"})

fs.GlobStub = nil

return nil, errors.New("new error")
}
})

It("returns the real path", func() {
Expand Down
3 changes: 0 additions & 3 deletions platform/linux_platform.go
Expand Up @@ -68,9 +68,6 @@ type LinuxOptions struct {
// Strategy for resolving device paths;
// possible values: virtio, scsi, ''
DevicePathResolutionType string

// Device prexix when using virtio (defaults to 'virtio')
VirtioDevicePrefix string
}

type linux struct {
Expand Down
2 changes: 1 addition & 1 deletion platform/provider.go
Expand Up @@ -89,7 +89,7 @@ func NewProvider(logger boshlog.Logger, dirProvider boshdirs.Provider, statsColl
switch options.Linux.DevicePathResolutionType {
case "virtio":
udev := boshudev.NewConcreteUdevDevice(runner, logger)
idDevicePathResolver := devicepathresolver.NewIDDevicePathResolver(500*time.Millisecond, options.Linux.VirtioDevicePrefix, udev, fs)
idDevicePathResolver := devicepathresolver.NewIDDevicePathResolver(500*time.Millisecond, udev, fs)
mappedDevicePathResolver := devicepathresolver.NewMappedDevicePathResolver(30000*time.Millisecond, fs)
devicePathResolver = devicepathresolver.NewVirtioDevicePathResolver(idDevicePathResolver, mappedDevicePathResolver, logger)
case "scsi":
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions vendor/github.com/cloudfoundry/bosh-utils/http/byte_read_closer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 287b000

Please sign in to comment.