GetUsage reports total size in bytes consumed by a thin-device. It relies on the number of used blocks reported by 'dmsetup status'. The output looks like: device2: 0 204800 thin 17280 204799 Where 17280 is the number of used sectors
(deviceName string)
| 524 | // |
| 525 | // Where 17280 is the number of used sectors |
| 526 | func (p *PoolDevice) GetUsage(deviceName string) (int64, error) { |
| 527 | status, err := dmsetup.Status(deviceName) |
| 528 | if err != nil { |
| 529 | return 0, fmt.Errorf("can't get status for device %q: %w", deviceName, err) |
| 530 | } |
| 531 | |
| 532 | if len(status.Params) == 0 { |
| 533 | return 0, errors.New("failed to get the number of used blocks, unexpected output from dmsetup status") |
| 534 | } |
| 535 | |
| 536 | count, err := strconv.ParseInt(status.Params[0], 10, 64) |
| 537 | if err != nil { |
| 538 | return 0, fmt.Errorf("failed to parse status params: %q: %w", status.Params[0], err) |
| 539 | } |
| 540 | |
| 541 | return count * dmsetup.SectorSize, nil |
| 542 | } |
| 543 | |
| 544 | // RemoveDevice completely wipes out thin device from thin-pool and frees it's device ID |
| 545 | func (p *PoolDevice) RemoveDevice(ctx context.Context, deviceName string) error { |