snapshots/devmapper: fix rollback
The rollback mechanism is implemented by calling deleteDevice() and RemoveDevice(). But RemoveDevice() is internally calling deleteDevice() as well. Since a device will be deleted by first deleteDevice(), RemoveDevice() always will see ENODATA. The specific error must be ignored to remove the device's metadata correctly. Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
This commit is contained in:
@@ -152,6 +152,27 @@ func TestPoolDevice(t *testing.T) {
|
||||
t.Run("RemoveDevice", func(t *testing.T) {
|
||||
testRemoveThinDevice(t, pool)
|
||||
})
|
||||
|
||||
t.Run("rollbackActivate", func(t *testing.T) {
|
||||
testCreateThinDevice(t, pool)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
snapDevice := "snap2"
|
||||
|
||||
err := pool.CreateSnapshotDevice(ctx, thinDevice1, snapDevice, device1Size)
|
||||
assert.NilError(t, err)
|
||||
|
||||
info, err := pool.metadata.GetDevice(ctx, snapDevice)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Simulate a case that the device cannot be activated.
|
||||
err = pool.DeactivateDevice(ctx, info.Name, false, false)
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = pool.rollbackActivate(ctx, info, err)
|
||||
assert.NilError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPoolDeviceMarkFaulty(t *testing.T) {
|
||||
@@ -256,6 +277,9 @@ func testDeactivateThinDevice(t *testing.T, pool *PoolDevice) {
|
||||
func testRemoveThinDevice(t *testing.T, pool *PoolDevice) {
|
||||
err := pool.RemoveDevice(testCtx, thinDevice1)
|
||||
assert.NilError(t, err, "should delete thin device from pool")
|
||||
|
||||
err = pool.RemoveDevice(testCtx, thinDevice2)
|
||||
assert.NilError(t, err, "should delete thin device from pool")
|
||||
}
|
||||
|
||||
func getMounts(thinDeviceName string) []mount.Mount {
|
||||
|
||||
Reference in New Issue
Block a user