docker-inspect: Extend docker inspect to export image/container metadata related to graph driver
Export image/container metadata stored in graph driver. Right now 3 fields DeviceId, DeviceSize and DeviceName are being exported from devicemapper. Other graph drivers can export fields as they see fit. This data can be used to mount the thin device outside of docker and tools can look into image/container and do some kind of inspection. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Upstream-commit: 407a626be62996cd6385ea4d80e669ab83f5f04d Component: engine
This commit is contained in:
@ -127,6 +127,13 @@ type Status struct {
|
||||
DeferredRemoveEnabled bool
|
||||
}
|
||||
|
||||
// Structure used to export image/container metadata in docker inspect.
|
||||
type DeviceMetadata struct {
|
||||
deviceId int
|
||||
deviceSize uint64 // size in bytes
|
||||
deviceName string // Device name as used during activation
|
||||
}
|
||||
|
||||
type DevStatus struct {
|
||||
DeviceId int
|
||||
Size uint64
|
||||
@ -1700,6 +1707,20 @@ func (devices *DeviceSet) Status() *Status {
|
||||
return status
|
||||
}
|
||||
|
||||
// Status returns the current status of this deviceset
|
||||
func (devices *DeviceSet) ExportDeviceMetadata(hash string) (*DeviceMetadata, error) {
|
||||
info, err := devices.lookupDevice(hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info.lock.Lock()
|
||||
defer info.lock.Unlock()
|
||||
|
||||
metadata := &DeviceMetadata{info.DeviceId, info.Size, info.Name()}
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
func NewDeviceSet(root string, doInit bool, options []string) (*DeviceSet, error) {
|
||||
devicemapper.SetDevDir("/dev")
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/daemon/graphdriver"
|
||||
@ -91,6 +92,20 @@ func (d *Driver) Status() [][2]string {
|
||||
return status
|
||||
}
|
||||
|
||||
func (d *Driver) GetMetadata(id string) (map[string]string, error) {
|
||||
m, err := d.DeviceSet.ExportDeviceMetadata(id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
metadata := make(map[string]string)
|
||||
metadata["DeviceId"] = strconv.Itoa(m.deviceId)
|
||||
metadata["DeviceSize"] = strconv.FormatUint(m.deviceSize, 10)
|
||||
metadata["DeviceName"] = m.deviceName
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
func (d *Driver) Cleanup() error {
|
||||
err := d.DeviceSet.Shutdown()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user