Skip to content

Commit

Permalink
Exorcise Driver code from libpod/define
Browse files Browse the repository at this point in the history
The libpod/define code should not import any large dependencies,
as it is intended to be structures and definitions only. It
included the libpod/driver package for information on the storage
driver, though, which brought in all of c/storage. Split the
driver package so that define has the struct, and thus does not
need to import Driver. And simplify the driver code while we're
at it.

Signed-off-by: Matthew Heon <[email protected]>
  • Loading branch information
mheon committed Jan 12, 2021
1 parent 1b9366d commit befd40b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion libpod/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c *Container) Inspect(size bool) (*define.InspectContainerData, error) {
return c.inspectLocked(size)
}

func (c *Container) getContainerInspectData(size bool, driverData *driver.Data) (*define.InspectContainerData, error) {
func (c *Container) getContainerInspectData(size bool, driverData *define.DriverData) (*define.InspectContainerData, error) {
config := c.config
runtimeInfo := c.state
ctrSpec, err := c.specFromState()
Expand Down
9 changes: 7 additions & 2 deletions libpod/define/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"github.com/containers/image/v5/manifest"
"github.com/containers/podman/v2/libpod/driver"
)

// InspectContainerConfig holds further data about how a container was initially
Expand Down Expand Up @@ -635,7 +634,7 @@ type InspectContainerData struct {
EffectiveCaps []string `json:"EffectiveCaps"`
BoundingCaps []string `json:"BoundingCaps"`
ExecIDs []string `json:"ExecIDs"`
GraphDriver *driver.Data `json:"GraphDriver"`
GraphDriver *DriverData `json:"GraphDriver"`
SizeRw *int64 `json:"SizeRw,omitempty"`
SizeRootFs int64 `json:"SizeRootFs,omitempty"`
Mounts []InspectMount `json:"Mounts"`
Expand Down Expand Up @@ -700,3 +699,9 @@ type InspectExecProcess struct {
// User is the user the exec session was started as.
User string `json:"user"`
}

// DriverData handles the data for a storage driver
type DriverData struct {
Name string `json:"Name"`
Data map[string]string `json:"Data"`
}
37 changes: 7 additions & 30 deletions libpod/driver/driver.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,26 @@
package driver

import (
cstorage "github.com/containers/storage"
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/storage"
)

// Data handles the data for a storage driver
type Data struct {
Name string `json:"Name"`
Data map[string]string `json:"Data"`
}

// GetDriverName returns the name of the driver for the given store
func GetDriverName(store cstorage.Store) (string, error) {
driver, err := store.GraphDriver()
if err != nil {
return "", err
}
return driver.String(), nil
}

// GetDriverMetadata returns the metadata regarding the driver for the layer in the given store
func GetDriverMetadata(store cstorage.Store, layerID string) (map[string]string, error) {
// GetDriverData returns information on a given store's running graph driver.
func GetDriverData(store storage.Store, layerID string) (*define.DriverData, error) {
driver, err := store.GraphDriver()
if err != nil {
return nil, err
}
return driver.Metadata(layerID)
}

// GetDriverData returns the Data struct with information of the driver used by the store
func GetDriverData(store cstorage.Store, layerID string) (*Data, error) {
name, err := GetDriverName(store)
if err != nil {
return nil, err
}
metaData, err := GetDriverMetadata(store, layerID)
metaData, err := driver.Metadata(layerID)
if err != nil {
return nil, err
}
if mountTimes, err := store.Mounted(layerID); mountTimes == 0 || err != nil {
delete(metaData, "MergedDir")
}

return &Data{
Name: name,
return &define.DriverData{
Name: driver.String(),
Data: metaData,
}, nil
}
3 changes: 2 additions & 1 deletion libpod/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/containers/image/v5/transports"
"github.com/containers/image/v5/transports/alltransports"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/libpod/driver"
"github.com/containers/podman/v2/libpod/events"
"github.com/containers/podman/v2/pkg/inspect"
Expand Down Expand Up @@ -972,7 +973,7 @@ func (i *Image) toImageRef(ctx context.Context) (types.Image, error) {
}

// DriverData gets the driver data from the store on a layer
func (i *Image) DriverData() (*driver.Data, error) {
func (i *Image) DriverData() (*define.DriverData, error) {
return driver.GetDriverData(i.imageruntime.store, i.TopLayer())
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"

"github.com/containers/image/v5/manifest"
"github.com/containers/podman/v2/libpod/driver"
"github.com/containers/podman/v2/libpod/define"
"github.com/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
)
Expand All @@ -25,7 +25,7 @@ type ImageData struct {
Os string `json:"Os"`
Size int64 `json:"Size"`
VirtualSize int64 `json:"VirtualSize"`
GraphDriver *driver.Data `json:"GraphDriver"`
GraphDriver *define.DriverData `json:"GraphDriver"`
RootFS *RootFS `json:"RootFS"`
Labels map[string]string `json:"Labels"`
Annotations map[string]string `json:"Annotations"`
Expand Down

0 comments on commit befd40b

Please sign in to comment.