diff options
Diffstat (limited to 'pkg/sentry/device')
-rw-r--r-- | pkg/sentry/device/BUILD | 20 | ||||
-rw-r--r-- | pkg/sentry/device/device_state_autogen.go | 91 | ||||
-rw-r--r-- | pkg/sentry/device/device_test.go | 59 |
3 files changed, 91 insertions, 79 deletions
diff --git a/pkg/sentry/device/BUILD b/pkg/sentry/device/BUILD deleted file mode 100644 index e403cbd8b..000000000 --- a/pkg/sentry/device/BUILD +++ /dev/null @@ -1,20 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test") - -package(licenses = ["notice"]) - -go_library( - name = "device", - srcs = ["device.go"], - visibility = ["//pkg/sentry:internal"], - deps = [ - "//pkg/abi/linux", - "//pkg/sync", - ], -) - -go_test( - name = "device_test", - size = "small", - srcs = ["device_test.go"], - library = ":device", -) diff --git a/pkg/sentry/device/device_state_autogen.go b/pkg/sentry/device/device_state_autogen.go new file mode 100644 index 000000000..8a28a4be4 --- /dev/null +++ b/pkg/sentry/device/device_state_autogen.go @@ -0,0 +1,91 @@ +// automatically generated by stateify. + +package device + +import ( + "gvisor.dev/gvisor/pkg/state" +) + +func (x *Registry) StateTypeName() string { + return "pkg/sentry/device.Registry" +} + +func (x *Registry) StateFields() []string { + return []string{ + "lastAnonDeviceMinor", + "devices", + } +} + +func (x *Registry) beforeSave() {} + +func (x *Registry) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.lastAnonDeviceMinor) + m.Save(1, &x.devices) +} + +func (x *Registry) afterLoad() {} + +func (x *Registry) StateLoad(m state.Source) { + m.Load(0, &x.lastAnonDeviceMinor) + m.Load(1, &x.devices) +} + +func (x *ID) StateTypeName() string { + return "pkg/sentry/device.ID" +} + +func (x *ID) StateFields() []string { + return []string{ + "Major", + "Minor", + } +} + +func (x *ID) beforeSave() {} + +func (x *ID) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.Major) + m.Save(1, &x.Minor) +} + +func (x *ID) afterLoad() {} + +func (x *ID) StateLoad(m state.Source) { + m.Load(0, &x.Major) + m.Load(1, &x.Minor) +} + +func (x *Device) StateTypeName() string { + return "pkg/sentry/device.Device" +} + +func (x *Device) StateFields() []string { + return []string{ + "ID", + "last", + } +} + +func (x *Device) beforeSave() {} + +func (x *Device) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.ID) + m.Save(1, &x.last) +} + +func (x *Device) afterLoad() {} + +func (x *Device) StateLoad(m state.Source) { + m.Load(0, &x.ID) + m.Load(1, &x.last) +} + +func init() { + state.Register((*Registry)(nil)) + state.Register((*ID)(nil)) + state.Register((*Device)(nil)) +} diff --git a/pkg/sentry/device/device_test.go b/pkg/sentry/device/device_test.go deleted file mode 100644 index e3f51ce4f..000000000 --- a/pkg/sentry/device/device_test.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2018 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package device - -import ( - "testing" -) - -func TestMultiDevice(t *testing.T) { - device := &MultiDevice{} - - // Check that Load fails to install virtual inodes that are - // uninitialized. - if device.Load(MultiDeviceKey{}, 0) { - t.Fatalf("got load of invalid virtual inode 0, want unsuccessful") - } - - inode := device.Map(MultiDeviceKey{}) - - // Assert that the same raw device and inode map to - // a consistent virtual inode. - if i := device.Map(MultiDeviceKey{}); i != inode { - t.Fatalf("got inode %d, want %d in %s", i, inode, device) - } - - // Assert that a new inode or new device does not conflict. - if i := device.Map(MultiDeviceKey{Device: 0, Inode: 1}); i == inode { - t.Fatalf("got reused inode %d, want new distinct inode in %s", i, device) - } - last := device.Map(MultiDeviceKey{Device: 1, Inode: 0}) - if last == inode { - t.Fatalf("got reused inode %d, want new distinct inode in %s", last, device) - } - - // Virtual is the virtual inode we want to load. - virtual := last + 1 - - // Assert that we can load a virtual inode at a new place. - if !device.Load(MultiDeviceKey{Device: 0, Inode: 2}, virtual) { - t.Fatalf("got load of virtual inode %d failed, want success in %s", virtual, device) - } - - // Assert that the next inode skips over the loaded one. - if i := device.Map(MultiDeviceKey{Device: 0, Inode: 3}); i != virtual+1 { - t.Fatalf("got inode %d, want %d in %s", i, virtual+1, device) - } -} |