Skip to content

Commit e432ed3

Browse files
Madhu-1aravindavk
authored andcommitted
Add total and used field to device response
it will be user friendly if we have total, free,used field in device response. total size= total size of device. free size= available size of device for volume creation. used size= space used for volume creation. Signed-off-by: Madhu Rajanna <mrajanna@redhat.com>
1 parent 9bfa471 commit e432ed3

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

plugins/device/api/resp.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
type Info struct {
1111
Device string `json:"device"`
1212
State string `json:"state"`
13-
AvailableSize uint64 `json:"available-size"`
13+
AvailableSize uint64 `json:"free-size"`
14+
TotalSize uint64 `json:"total-size"`
15+
UsedSize uint64 `json:"used-size"`
1416
ExtentSize uint64 `json:"extent-size"`
1517
Used bool `json:"device-used"`
1618
PeerID uuid.UUID `json:"peer-id"`

plugins/device/deviceutils/store-utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func UpdateDeviceFreeSize(peerID, device string) error {
109109
return err
110110
}
111111
dev.AvailableSize = availableSize
112+
dev.UsedSize = dev.TotalSize - availableSize
112113
dev.ExtentSize = extentSize
113114
return AddOrUpdateDevice(*dev)
114115
}
@@ -127,6 +128,7 @@ func UpdateDeviceFreeSizeByVg(peerID, vgname string) error {
127128
return err
128129
}
129130
dev.AvailableSize = availableSize
131+
dev.UsedSize = dev.TotalSize - availableSize
130132
dev.ExtentSize = extentSize
131133
return AddOrUpdateDevice(dev)
132134
}

plugins/device/transaction.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func txnPrepareDevice(c transaction.TxnCtx) error {
4848
Device: device,
4949
State: deviceapi.DeviceEnabled,
5050
AvailableSize: availableSize,
51+
TotalSize: availableSize,
52+
UsedSize: 0,
5153
ExtentSize: extentSize,
5254
PeerID: peerID,
5355
}

0 commit comments

Comments
 (0)