mirror of https://github.com/docker/docs.git
devmapper: Provide a helper function getNextDeviceId()
Right now we are accessing devices.NextDeviceId directly and also incrementing it at various places. Instead provide a helper function which is responsile for incrementing NextDeviceId and return next deviceId. This is just code structuring. This will help later once we convert this function to find a free device Id and it goes through a bitmap of used/free device Ids. Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
parent
39dc7829de
commit
a44c23fe66
|
@ -500,13 +500,17 @@ func (devices *DeviceSet) incNextDeviceId() {
|
||||||
devices.NextDeviceId = (devices.NextDeviceId + 1) & MaxDeviceId
|
devices.NextDeviceId = (devices.NextDeviceId + 1) & MaxDeviceId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (devices *DeviceSet) getNextDeviceId() int {
|
||||||
|
devices.incNextDeviceId()
|
||||||
|
return devices.NextDeviceId
|
||||||
|
}
|
||||||
|
|
||||||
func (devices *DeviceSet) createDevice(deviceId *int) error {
|
func (devices *DeviceSet) createDevice(deviceId *int) error {
|
||||||
for {
|
for {
|
||||||
if err := devicemapper.CreateDevice(devices.getPoolDevName(), *deviceId); err != nil {
|
if err := devicemapper.CreateDevice(devices.getPoolDevName(), *deviceId); err != nil {
|
||||||
if devicemapper.DeviceIdExists(err) {
|
if devicemapper.DeviceIdExists(err) {
|
||||||
// Device Id already exists. Try a new one.
|
// Device Id already exists. Try a new one.
|
||||||
devices.incNextDeviceId()
|
*deviceId = devices.getNextDeviceId()
|
||||||
*deviceId = devices.NextDeviceId
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Debugf("Error creating device: %s", err)
|
log.Debugf("Error creating device: %s", err)
|
||||||
|
@ -514,12 +518,11 @@ func (devices *DeviceSet) createDevice(deviceId *int) error {
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
devices.incNextDeviceId()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (devices *DeviceSet) createRegisterDevice(hash string) (*DevInfo, error) {
|
func (devices *DeviceSet) createRegisterDevice(hash string) (*DevInfo, error) {
|
||||||
deviceId := devices.NextDeviceId
|
deviceId := devices.getNextDeviceId()
|
||||||
if err := devices.createDevice(&deviceId); err != nil {
|
if err := devices.createDevice(&deviceId); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -548,8 +551,7 @@ func (devices *DeviceSet) createSnapDevice(baseInfo *DevInfo, deviceId *int) err
|
||||||
if err := devicemapper.CreateSnapDevice(devices.getPoolDevName(), *deviceId, baseInfo.Name(), baseInfo.DeviceId); err != nil {
|
if err := devicemapper.CreateSnapDevice(devices.getPoolDevName(), *deviceId, baseInfo.Name(), baseInfo.DeviceId); err != nil {
|
||||||
if devicemapper.DeviceIdExists(err) {
|
if devicemapper.DeviceIdExists(err) {
|
||||||
// Device Id already exists. Try a new one.
|
// Device Id already exists. Try a new one.
|
||||||
devices.incNextDeviceId()
|
*deviceId = devices.getNextDeviceId()
|
||||||
*deviceId = devices.NextDeviceId
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Debugf("Error creating snap device: %s", err)
|
log.Debugf("Error creating snap device: %s", err)
|
||||||
|
@ -557,12 +559,11 @@ func (devices *DeviceSet) createSnapDevice(baseInfo *DevInfo, deviceId *int) err
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
devices.incNextDeviceId()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (devices *DeviceSet) createRegisterSnapDevice(hash string, baseInfo *DevInfo) error {
|
func (devices *DeviceSet) createRegisterSnapDevice(hash string, baseInfo *DevInfo) error {
|
||||||
deviceId := devices.NextDeviceId
|
deviceId := devices.getNextDeviceId()
|
||||||
if err := devices.createSnapDevice(baseInfo, &deviceId); err != nil {
|
if err := devices.createSnapDevice(baseInfo, &deviceId); err != nil {
|
||||||
log.Debugf("Error creating snap device: %s", err)
|
log.Debugf("Error creating snap device: %s", err)
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue