Skip to content

Commit 37373c1

Browse files
Eric Renrenzhen.rz
authored andcommitted
devmapper: deferred remove can break consistency
dmsetup remove with "--deferred" option may remove device in kernel latter than the time when its device info has been removed in database, causing the "file exists" error as previous commit. This error really happens in our extreme testing: power off server and disk disappear while k8s is creating/deleting pods. The fix reveals a testcase bug in "TestSnapshotterSuite/RemoveIntermediateSnapshot", for block device snapshot, we should umount the snapshot before removing it. Signed-off-by: Eric Ren <[email protected]>
1 parent 89043f9 commit 37373c1

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

snapshots/devmapper/pool_device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func (p *PoolDevice) RemoveDevice(ctx context.Context, deviceName string) error
324324
return errors.Wrapf(err, "can't query metadata for device %q", deviceName)
325325
}
326326

327-
if err := p.DeactivateDevice(ctx, deviceName, true, true); err != nil {
327+
if err := p.DeactivateDevice(ctx, deviceName, false, true); err != nil {
328328
return err
329329
}
330330

snapshots/testsuite/testsuite.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,12 @@ func checkRemoveIntermediateSnapshot(ctx context.Context, t *testing.T, snapshot
501501
if err != nil {
502502
t.Fatal(err)
503503
}
504-
defer testutil.Unmount(t, base)
504+
needUmount := true
505+
defer func() {
506+
if needUmount {
507+
testutil.Unmount(t, base)
508+
}
509+
}()
505510

506511
committedBase := filepath.Join(work, "committed-base")
507512
if err = snapshotter.Commit(ctx, committedBase, base, opt); err != nil {
@@ -540,6 +545,10 @@ func checkRemoveIntermediateSnapshot(ctx context.Context, t *testing.T, snapshot
540545
if err != nil {
541546
t.Fatal(err)
542547
}
548+
549+
testutil.Unmount(t, base)
550+
needUmount = false
551+
543552
err = snapshotter.Remove(ctx, committedBase)
544553
if err != nil {
545554
t.Fatal(err)

0 commit comments

Comments
 (0)