mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
devmapper: Keep track of number of deleted devices
Keep track of number of deleted devices and export this information through "docker info". Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
parent
d929589c1f
commit
d295dc6652
2 changed files with 28 additions and 1 deletions
|
@ -110,6 +110,7 @@ type DeviceSet struct {
|
||||||
deferredRemove bool // use deferred removal
|
deferredRemove bool // use deferred removal
|
||||||
deferredDelete bool // use deferred deletion
|
deferredDelete bool // use deferred deletion
|
||||||
BaseDeviceUUID string //save UUID of base device
|
BaseDeviceUUID string //save UUID of base device
|
||||||
|
nrDeletedDevices uint //number of deleted devices
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiskUsage contains information about disk usage and is used when reporting Status of a device.
|
// DiskUsage contains information about disk usage and is used when reporting Status of a device.
|
||||||
|
@ -149,7 +150,8 @@ type Status struct {
|
||||||
// deactivated. Thin device is still in thin pool and can be activated
|
// deactivated. Thin device is still in thin pool and can be activated
|
||||||
// again. But "deletion" means that thin device will be deleted from
|
// again. But "deletion" means that thin device will be deleted from
|
||||||
// thin pool and it can't be activated again.
|
// thin pool and it can't be activated again.
|
||||||
DeferredDeleteEnabled bool
|
DeferredDeleteEnabled bool
|
||||||
|
DeferredDeletedDeviceCount uint
|
||||||
}
|
}
|
||||||
|
|
||||||
// Structure used to export image/container metadata in docker inspect.
|
// Structure used to export image/container metadata in docker inspect.
|
||||||
|
@ -581,6 +583,11 @@ func (devices *DeviceSet) migrateOldMetaData() error {
|
||||||
// loaded in the hash table. Should be called with devices.Lock() held.
|
// loaded in the hash table. Should be called with devices.Lock() held.
|
||||||
// Will drop the lock for device deletion and return with lock acquired.
|
// Will drop the lock for device deletion and return with lock acquired.
|
||||||
func (devices *DeviceSet) cleanupDeletedDevices() error {
|
func (devices *DeviceSet) cleanupDeletedDevices() error {
|
||||||
|
// If there are no deleted devices, there is nothing to do.
|
||||||
|
if devices.nrDeletedDevices == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var deletedDevices []*devInfo
|
var deletedDevices []*devInfo
|
||||||
|
|
||||||
for _, info := range devices.Devices {
|
for _, info := range devices.Devices {
|
||||||
|
@ -606,6 +613,15 @@ func (devices *DeviceSet) cleanupDeletedDevices() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (devices *DeviceSet) countDeletedDevices() {
|
||||||
|
for _, info := range devices.Devices {
|
||||||
|
if !info.Deleted {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
devices.nrDeletedDevices++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (devices *DeviceSet) initMetaData() error {
|
func (devices *DeviceSet) initMetaData() error {
|
||||||
devices.Lock()
|
devices.Lock()
|
||||||
defer devices.Unlock()
|
defer devices.Unlock()
|
||||||
|
@ -626,6 +642,7 @@ func (devices *DeviceSet) initMetaData() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
devices.constructDeviceIDMap()
|
devices.constructDeviceIDMap()
|
||||||
|
devices.countDeletedDevices()
|
||||||
|
|
||||||
if err := devices.processPendingTransaction(); err != nil {
|
if err := devices.processPendingTransaction(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1601,6 +1618,8 @@ func (devices *DeviceSet) markForDeferredDeletion(info *devInfo) error {
|
||||||
info.Deleted = false
|
info.Deleted = false
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
devices.nrDeletedDevices++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1628,6 +1647,12 @@ func (devices *DeviceSet) deleteTransaction(info *devInfo, syncDelete bool) erro
|
||||||
if err := devices.unregisterDevice(info.DeviceID, info.Hash); err != nil {
|
if err := devices.unregisterDevice(info.DeviceID, info.Hash); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// If device was already in deferred delete state that means
|
||||||
|
// deletion was being tried again later. Reduce the deleted
|
||||||
|
// device count.
|
||||||
|
if info.Deleted {
|
||||||
|
devices.nrDeletedDevices--
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := devices.markForDeferredDeletion(info); err != nil {
|
if err := devices.markForDeferredDeletion(info); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -2110,6 +2135,7 @@ func (devices *DeviceSet) Status() *Status {
|
||||||
status.UdevSyncSupported = devicemapper.UdevSyncSupported()
|
status.UdevSyncSupported = devicemapper.UdevSyncSupported()
|
||||||
status.DeferredRemoveEnabled = devices.deferredRemove
|
status.DeferredRemoveEnabled = devices.deferredRemove
|
||||||
status.DeferredDeleteEnabled = devices.deferredDelete
|
status.DeferredDeleteEnabled = devices.deferredDelete
|
||||||
|
status.DeferredDeletedDeviceCount = devices.nrDeletedDevices
|
||||||
|
|
||||||
totalSizeInSectors, _, dataUsed, dataTotal, metadataUsed, metadataTotal, err := devices.poolStatus()
|
totalSizeInSectors, _, dataUsed, dataTotal, metadataUsed, metadataTotal, err := devices.poolStatus()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -85,6 +85,7 @@ func (d *Driver) Status() [][2]string {
|
||||||
{"Udev Sync Supported", fmt.Sprintf("%v", s.UdevSyncSupported)},
|
{"Udev Sync Supported", fmt.Sprintf("%v", s.UdevSyncSupported)},
|
||||||
{"Deferred Removal Enabled", fmt.Sprintf("%v", s.DeferredRemoveEnabled)},
|
{"Deferred Removal Enabled", fmt.Sprintf("%v", s.DeferredRemoveEnabled)},
|
||||||
{"Deferred Deletion Enabled", fmt.Sprintf("%v", s.DeferredDeleteEnabled)},
|
{"Deferred Deletion Enabled", fmt.Sprintf("%v", s.DeferredDeleteEnabled)},
|
||||||
|
{"Deferred Deleted Device Count", fmt.Sprintf("%v", s.DeferredDeletedDeviceCount)},
|
||||||
}
|
}
|
||||||
if len(s.DataLoopback) > 0 {
|
if len(s.DataLoopback) > 0 {
|
||||||
status = append(status, [2]string{"Data loop file", s.DataLoopback})
|
status = append(status, [2]string{"Data loop file", s.DataLoopback})
|
||||||
|
|
Loading…
Reference in a new issue