Skip to content

Commit aa4f8d9

Browse files
committed
storaged: only delete the qgroup associated with a volume
1 parent 0408e3b commit aa4f8d9

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

pkg/storage/filesystem/btrfs.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99
"syscall"
1010

11+
"github.com/pkg/errors"
1112
"github.com/rs/zerolog/log"
1213

1314
"github.com/threefoldtech/zos/pkg"
@@ -337,21 +338,20 @@ func (p *btrfsPool) AddVolume(name string) (Volume, error) {
337338
func (p *btrfsPool) removeVolume(root string) error {
338339
ctx := context.Background()
339340

340-
if err := p.utils.SubvolumeRemove(ctx, root); err != nil {
341+
info, err := p.utils.SubvolumeInfo(ctx, root)
342+
if err != nil {
341343
return err
342344
}
343345

344-
qgroups, err := p.utils.QGroupList(ctx, root)
345-
if err != nil {
346+
if err := p.utils.SubvolumeRemove(ctx, root); err != nil {
346347
return err
347348
}
348349

349-
for _, qgroup := range qgroups {
350-
log.Debug().Msgf("delete qgroup %s", qgroup.ID)
351-
if err := p.utils.QGroupDestroy(ctx, qgroup.ID, root); err != nil {
352-
return err
353-
}
350+
qgroupID := fmt.Sprintf("0/%d", info.ID)
351+
if err := p.utils.QGroupDestroy(ctx, qgroupID, p.Path()); err != nil {
352+
return errors.Wrapf(err, "failed to delete qgroup %s", qgroupID)
354353
}
354+
355355
return nil
356356
}
357357

pkg/storage/filesystem/btrfs_ci_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
302302

303303
devices, err := SetupDevices(1)
304304
require.NoError(t, err, "failed to initialize devices")
305-
306305
defer devices.Destroy()
306+
307307
loops := devices.Loops()
308308
fs := NewBtrfs(&TestDeviceManager{loops})
309309

@@ -326,6 +326,7 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
326326

327327
volume, err := pool.AddVolume("vol1")
328328
require.NoError(t, err)
329+
t.Logf("volume ID: %v\n", volume.ID())
329330

330331
err = volume.Limit(256 * 1024 * 1024)
331332
require.NoError(t, err)
@@ -336,6 +337,7 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
336337
qgroups, err := btrfsVol.utils.QGroupList(context.TODO(), pool.Path())
337338
require.NoError(t, err)
338339
assert.Equal(t, 2, len(qgroups))
340+
t.Logf("qgroups before delete: %v", qgroups)
339341

340342
_, ok = qgroups[fmt.Sprintf("0/%d", btrfsVol.id)]
341343
assert.True(t, ok, "qgroups should contains a qgroup linked to the subvolume")
@@ -345,5 +347,7 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
345347

346348
qgroups, err = btrfsVol.utils.QGroupList(context.TODO(), pool.Path())
347349
require.NoError(t, err)
348-
assert.Equal(t, 0, len(qgroups), "qgroups should have been deleted with the subvolume")
350+
351+
t.Logf("remaining qgroups: %+v", qgroups)
352+
assert.Equal(t, 1, len(qgroups), "qgroups should have been deleted with the subvolume")
349353
}

0 commit comments

Comments
 (0)