Skip to content

Commit b702623

Browse files
bergwolfmxpv
authored andcommitted
snapshot/devmapper: use losetup in mount package
No need to use the private losetup command line wrapper package. The generic package provides the same functionality. Signed-off-by: Peng Tao <[email protected]>
1 parent 9e42070 commit b702623

5 files changed

Lines changed: 8 additions & 229 deletions

File tree

snapshots/devmapper/dmsetup/dmsetup_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
"gotest.tools/v3/assert"
3030
is "gotest.tools/v3/assert/cmp"
3131

32+
"github.com/containerd/containerd/mount"
3233
"github.com/containerd/containerd/pkg/testutil"
33-
"github.com/containerd/containerd/snapshots/devmapper/losetup"
3434
)
3535

3636
const (
@@ -55,16 +55,13 @@ func TestDMSetup(t *testing.T) {
5555
metaImage, loopMetaDevice := createLoopbackDevice(t, tempDir)
5656

5757
defer func() {
58-
err = losetup.RemoveLoopDevicesAssociatedWithImage(dataImage)
59-
assert.NilError(t, err, "failed to detach loop devices for data image: %s", dataImage)
60-
61-
err = losetup.RemoveLoopDevicesAssociatedWithImage(metaImage)
62-
assert.NilError(t, err, "failed to detach loop devices for meta image: %s", metaImage)
58+
err = mount.DetachLoopDevice(loopDataDevice, loopMetaDevice)
59+
assert.NilError(t, err, "failed to detach loop devices for data image: %s and meta image: %s", dataImage, metaImage)
6360
}()
6461

6562
t.Run("CreatePool", func(t *testing.T) {
6663
err := CreatePool(testPoolName, loopDataDevice, loopMetaDevice, 128)
67-
assert.NilError(t, err, "failed to create thin-pool")
64+
assert.NilError(t, err, "failed to create thin-pool with %s %s", loopDataDevice, loopMetaDevice)
6865

6966
table, err := Table(testPoolName)
7067
t.Logf("table: %s", table)
@@ -201,7 +198,7 @@ func createLoopbackDevice(t *testing.T, dir string) (string, string) {
201198

202199
imagePath := file.Name()
203200

204-
loopDevice, err := losetup.AttachLoopDevice(imagePath)
201+
loopDevice, err := mount.AttachLoopDevice(imagePath)
205202
assert.NilError(t, err)
206203

207204
return imagePath, loopDevice

snapshots/devmapper/losetup/losetup.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

snapshots/devmapper/losetup/losetup_test.go

Lines changed: 0 additions & 124 deletions
This file was deleted.

snapshots/devmapper/pool_device_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/containerd/containerd/mount"
3232
"github.com/containerd/containerd/pkg/testutil"
3333
"github.com/containerd/containerd/snapshots/devmapper/dmsetup"
34-
"github.com/containerd/containerd/snapshots/devmapper/losetup"
3534
"github.com/docker/go-units"
3635
"github.com/sirupsen/logrus"
3736
"gotest.tools/v3/assert"
@@ -74,7 +73,7 @@ func TestPoolDevice(t *testing.T) {
7473

7574
defer func() {
7675
// Detach loop devices and remove images
77-
err := losetup.DetachLoopDevice(loopDataDevice, loopMetaDevice)
76+
err := mount.DetachLoopDevice(loopDataDevice, loopMetaDevice)
7877
assert.NilError(t, err)
7978

8079
err = os.RemoveAll(tempDir)
@@ -306,7 +305,7 @@ func createLoopbackDevice(t *testing.T, dir string) (string, string) {
306305

307306
imagePath := file.Name()
308307

309-
loopDevice, err := losetup.AttachLoopDevice(imagePath)
308+
loopDevice, err := mount.AttachLoopDevice(imagePath)
310309
assert.NilError(t, err)
311310

312311
return imagePath, loopDevice

snapshots/devmapper/snapshotter_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"github.com/containerd/containerd/pkg/testutil"
3838
"github.com/containerd/containerd/snapshots"
3939
"github.com/containerd/containerd/snapshots/devmapper/dmsetup"
40-
"github.com/containerd/containerd/snapshots/devmapper/losetup"
4140
"github.com/containerd/containerd/snapshots/testsuite"
4241
)
4342

@@ -70,7 +69,7 @@ func TestSnapshotterSuite(t *testing.T) {
7069
removePool := func() error {
7170
result := multierror.Append(
7271
snap.pool.RemovePool(ctx),
73-
losetup.DetachLoopDevice(loopDataDevice, loopMetaDevice))
72+
mount.DetachLoopDevice(loopDataDevice, loopMetaDevice))
7473

7574
return result.ErrorOrNil()
7675
}

0 commit comments

Comments
 (0)