Skip to content

Commit

Permalink
Merge pull request #5233 from kzys/mkfs-error
Browse files Browse the repository at this point in the history
Specifically mention "mkfs.ext4" on the error from the command
  • Loading branch information
crosbymichael committed Mar 19, 2021
2 parents e0c94bb + 7704fe7 commit a7b456d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 8 additions & 7 deletions snapshots/devmapper/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,9 @@ func (s *Snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
return nil, err
}

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

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

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

log.G(ctx).Debugf("mkfs:\n%s", string(output))
log.G(ctx).Debugf("mkfs:\n%s", out)
return nil
}

Expand Down
6 changes: 6 additions & 0 deletions snapshots/devmapper/snapshotter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,9 @@ func testUsage(t *testing.T, snapshotter snapshots.Snapshotter) {
assert.Check(t, layer2Usage.Size >= sizeBytes,
"%d > %d", layer2Usage.Size, sizeBytes)
}

func TestMkfs(t *testing.T) {
ctx := context.Background()
err := mkfs(ctx, "")
assert.ErrorContains(t, err, `mkfs.ext4 couldn't initialize ""`)
}

0 comments on commit a7b456d

Please sign in to comment.