Merge pull request #5233 from kzys/mkfs-error
Specifically mention "mkfs.ext4" on the error from the command
This commit is contained in:
commit
a7b456d2f8
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 ""`)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user