Skip to content

Commit a7b456d

Browse files
Merge pull request #5233 from kzys/mkfs-error
Specifically mention "mkfs.ext4" on the error from the command
2 parents e0c94bb + 7704fe7 commit a7b456d

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

snapshots/devmapper/snapshotter.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ func (s *Snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
365365
return nil, err
366366
}
367367

368-
if err := s.mkfs(ctx, deviceName); err != nil {
368+
if err := mkfs(ctx, dmsetup.GetFullDevicePath(deviceName)); err != nil {
369369
// Rollback thin device creation if mkfs failed
370+
log.G(ctx).WithError(err).Errorf("failed to initialize thin device %q for snapshot %s", deviceName, snap.ID)
370371
return nil, multierror.Append(err,
371372
s.pool.RemoveDevice(ctx, deviceName))
372373
}
@@ -393,22 +394,22 @@ func (s *Snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
393394
}
394395

395396
// mkfs creates ext4 filesystem on the given devmapper device
396-
func (s *Snapshotter) mkfs(ctx context.Context, deviceName string) error {
397+
func mkfs(ctx context.Context, path string) error {
397398
args := []string{
398399
"-E",
399400
// We don't want any zeroing in advance when running mkfs on thin devices (see "man mkfs.ext4")
400401
"nodiscard,lazy_itable_init=0,lazy_journal_init=0",
401-
dmsetup.GetFullDevicePath(deviceName),
402+
path,
402403
}
403404

404405
log.G(ctx).Debugf("mkfs.ext4 %s", strings.Join(args, " "))
405-
output, err := exec.Command("mkfs.ext4", args...).CombinedOutput()
406+
b, err := exec.Command("mkfs.ext4", args...).CombinedOutput()
407+
out := string(b)
406408
if err != nil {
407-
log.G(ctx).WithError(err).Errorf("failed to write fs:\n%s", string(output))
408-
return err
409+
return errors.Wrapf(err, "mkfs.ext4 couldn't initialize %q: %s", path, out)
409410
}
410411

411-
log.G(ctx).Debugf("mkfs:\n%s", string(output))
412+
log.G(ctx).Debugf("mkfs:\n%s", out)
412413
return nil
413414
}
414415

snapshots/devmapper/snapshotter_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,9 @@ func testUsage(t *testing.T, snapshotter snapshots.Snapshotter) {
139139
assert.Check(t, layer2Usage.Size >= sizeBytes,
140140
"%d > %d", layer2Usage.Size, sizeBytes)
141141
}
142+
143+
func TestMkfs(t *testing.T) {
144+
ctx := context.Background()
145+
err := mkfs(ctx, "")
146+
assert.ErrorContains(t, err, `mkfs.ext4 couldn't initialize ""`)
147+
}

0 commit comments

Comments
 (0)