MCPcopy
hub / github.com/etcd-io/bbolt / InitFlakey

Function InitFlakey

tests/dmflakey/dmflakey.go:93–131  ·  view source on GitHub ↗

InitFlakey creates an filesystem on a loopback device and returns Flakey on it. The device-mapper device will be /dev/mapper/$flakeyDevice. And the filesystem image will be created at $dataStorePath/$flakeyDevice.img. By default, the device is available for 2 minutes and size is 10 GiB.

(flakeyDevice, dataStorePath string, fsType FSType, mkfsOpt string)

Source from the content-addressed store, hash-verified

91// image will be created at $dataStorePath/$flakeyDevice.img. By default, the
92// device is available for 2 minutes and size is 10 GiB.
93func InitFlakey(flakeyDevice, dataStorePath string, fsType FSType, mkfsOpt string) (_ Flakey, retErr error) {
94 imgPath := filepath.Join(dataStorePath, fmt.Sprintf("%s.img", flakeyDevice))
95 if err := createEmptyFSImage(imgPath, fsType, mkfsOpt); err != nil {
96 return nil, err
97 }
98 defer func() {
99 if retErr != nil {
100 os.RemoveAll(imgPath)
101 }
102 }()
103
104 loopDevice, err := attachToLoopDevice(imgPath)
105 if err != nil {
106 return nil, err
107 }
108 defer func() {
109 if retErr != nil {
110 _ = detachLoopDevice(loopDevice)
111 }
112 }()
113
114 imgSize, err := getBlkSize(loopDevice)
115 if err != nil {
116 return nil, err
117 }
118
119 if err := newFlakeyDevice(flakeyDevice, loopDevice, defaultInterval); err != nil {
120 return nil, err
121 }
122
123 return &flakey{
124 fsType: fsType,
125 imgPath: imgPath,
126 imgSize: imgSize,
127
128 loopDevice: loopDevice,
129 flakeyDevice: flakeyDevice,
130 }, nil
131}
132
133type flakey struct {
134 fsType FSType

Callers 3

initFlakeyDeviceFunction · 0.92
TestBasicFunction · 0.85
initFlakeyFunction · 0.85

Calls 5

createEmptyFSImageFunction · 0.85
attachToLoopDeviceFunction · 0.85
detachLoopDeviceFunction · 0.85
getBlkSizeFunction · 0.85
newFlakeyDeviceFunction · 0.85

Tested by 3

initFlakeyDeviceFunction · 0.74
TestBasicFunction · 0.68
initFlakeyFunction · 0.68