Merge pull request #5233 from kzys/mkfs-error

Specifically mention "mkfs.ext4" on the error from the command
This commit is contained in:
Michael Crosby 2021-03-19 14:31:38 -04:00 committed by GitHub
commit a7b456d2f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -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))
}
@ -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
}

View File

@ -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 ""`)
}