devmapper: log pool status when mkfs fails

If mkfs on device mapper thin pool fails, it will show pool status
as returned by dmsetup for enahnced error reporting.

Signed-off-by: Alakesh Haloi <alakeshh@amazon.com>
This commit is contained in:
Alakesh Haloi 2021-04-02 19:08:51 +00:00
parent 054a3e281e
commit 5ce35ac398
2 changed files with 12 additions and 5 deletions

View File

@ -274,10 +274,11 @@ func Version() (string, error) {
// DeviceStatus represents devmapper device status information
type DeviceStatus struct {
Offset int64
Length int64
Target string
Params []string
RawOutput string
Offset int64
Length int64
Target string
Params []string
}
// Status provides status information for devmapper device
@ -291,6 +292,7 @@ func Status(deviceName string) (*DeviceStatus, error) {
if err != nil {
return nil, err
}
status.RawOutput = output
// Status output format:
// Offset (int64)

View File

@ -366,8 +366,13 @@ func (s *Snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
}
if err := mkfs(ctx, dmsetup.GetFullDevicePath(deviceName)); err != nil {
status, sErr := dmsetup.Status(s.pool.poolName)
if sErr != nil {
multierror.Append(err, sErr)
}
// 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)
log.G(ctx).WithError(err).Errorf("failed to initialize thin device %q for snapshot %s pool status %s", deviceName, snap.ID, status.RawOutput)
return nil, multierror.Append(err,
s.pool.RemoveDevice(ctx, deviceName))
}