|
@@ -505,27 +505,20 @@ func (devices *DeviceSet) getNextDeviceId() int {
|
|
return devices.NextDeviceId
|
|
return devices.NextDeviceId
|
|
}
|
|
}
|
|
|
|
|
|
-func (devices *DeviceSet) createDevice(deviceId *int) error {
|
|
|
|
|
|
+func (devices *DeviceSet) createRegisterDevice(hash string) (*DevInfo, error) {
|
|
|
|
+ deviceId := devices.getNextDeviceId()
|
|
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.
|
|
- *deviceId = devices.getNextDeviceId()
|
|
|
|
|
|
+ deviceId = devices.getNextDeviceId()
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
log.Debugf("Error creating device: %s", err)
|
|
log.Debugf("Error creating device: %s", err)
|
|
- return err
|
|
|
|
|
|
+ return nil, err
|
|
}
|
|
}
|
|
break
|
|
break
|
|
}
|
|
}
|
|
- return nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (devices *DeviceSet) createRegisterDevice(hash string) (*DevInfo, error) {
|
|
|
|
- deviceId := devices.getNextDeviceId()
|
|
|
|
- if err := devices.createDevice(&deviceId); err != nil {
|
|
|
|
- return nil, err
|
|
|
|
- }
|
|
|
|
|
|
|
|
transactionId := devices.allocateTransactionId()
|
|
transactionId := devices.allocateTransactionId()
|
|
log.Debugf("Registering device (id %v) with FS size %v", deviceId, devices.baseFsSize)
|
|
log.Debugf("Registering device (id %v) with FS size %v", deviceId, devices.baseFsSize)
|
|
@@ -543,15 +536,13 @@ func (devices *DeviceSet) createRegisterDevice(hash string) (*DevInfo, error) {
|
|
return info, nil
|
|
return info, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (devices *DeviceSet) createSnapDevice(baseInfo *DevInfo, deviceId *int) error {
|
|
|
|
- log.Debugf("[deviceset] createSnapDevice() DeviceId=%d", *deviceId)
|
|
|
|
- defer log.Debugf("[deviceset] createSnapDevice() END DeviceId=%d", *deviceId)
|
|
|
|
-
|
|
|
|
|
|
+func (devices *DeviceSet) createRegisterSnapDevice(hash string, baseInfo *DevInfo) error {
|
|
|
|
+ deviceId := devices.getNextDeviceId()
|
|
for {
|
|
for {
|
|
- 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.
|
|
- *deviceId = devices.getNextDeviceId()
|
|
|
|
|
|
+ deviceId = devices.getNextDeviceId()
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
log.Debugf("Error creating snap device: %s", err)
|
|
log.Debugf("Error creating snap device: %s", err)
|
|
@@ -559,15 +550,6 @@ func (devices *DeviceSet) createSnapDevice(baseInfo *DevInfo, deviceId *int) err
|
|
}
|
|
}
|
|
break
|
|
break
|
|
}
|
|
}
|
|
- return nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (devices *DeviceSet) createRegisterSnapDevice(hash string, baseInfo *DevInfo) error {
|
|
|
|
- deviceId := devices.getNextDeviceId()
|
|
|
|
- if err := devices.createSnapDevice(baseInfo, &deviceId); err != nil {
|
|
|
|
- log.Debugf("Error creating snap device: %s", err)
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
|
|
|
|
transactionId := devices.allocateTransactionId()
|
|
transactionId := devices.allocateTransactionId()
|
|
if _, err := devices.registerDevice(deviceId, hash, baseInfo.Size, transactionId); err != nil {
|
|
if _, err := devices.registerDevice(deviceId, hash, baseInfo.Size, transactionId); err != nil {
|