Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure SizeRw is shown when a user does 'inspect --size -t container'. #4753

Merged
merged 1 commit into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions libpod/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ type InspectContainerData struct {
BoundingCaps []string `json:"BoundingCaps"`
ExecIDs []string `json:"ExecIDs"`
GraphDriver *driver.Data `json:"GraphDriver"`
SizeRw int64 `json:"SizeRw,omitempty"`
SizeRw *int64 `json:"SizeRw,omitempty"`
SizeRootFs int64 `json:"SizeRootFs,omitempty"`
Mounts []InspectMount `json:"Mounts"`
Dependencies []string `json:"Dependencies"`
Expand Down Expand Up @@ -809,12 +809,13 @@ func (c *Container) getContainerInspectData(size bool, driverData *driver.Data)
if err != nil {
logrus.Errorf("error getting rootfs size %q: %v", config.ID, err)
}
data.SizeRootFs = rootFsSize

rwSize, err := c.rwSize()
if err != nil {
logrus.Errorf("error getting rw size %q: %v", config.ID, err)
}
data.SizeRootFs = rootFsSize
data.SizeRw = rwSize
data.SizeRw = &rwSize
}
return data, nil
}
Expand Down
14 changes: 8 additions & 6 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (c *Container) rootFsSize() (int64, error) {
return size + layerSize, err
}

// rwSize Gets the size of the mutable top layer of the container.
// rwSize gets the size of the mutable top layer of the container.
func (c *Container) rwSize() (int64, error) {
if c.config.Rootfs != "" {
var size int64
Expand All @@ -103,14 +103,16 @@ func (c *Container) rwSize() (int64, error) {
return 0, err
}

// Get the size of the top layer by calculating the size of the diff
// between the layer and its parent. The top layer of a container is
// the only RW layer, all others are immutable
layer, err := c.runtime.store.Layer(container.LayerID)
// The top layer of a container is
// the only readable/writeable layer, all others are immutable.
rwLayer, err := c.runtime.store.Layer(container.LayerID)
if err != nil {
return 0, err
}
return c.runtime.store.DiffSize(layer.Parent, layer.ID)

// Get the size of the top layer by calculating the size of the diff
// between the layer and its parent.
return c.runtime.store.DiffSize(rwLayer.Parent, rwLayer.ID)
}

// bundlePath returns the path to the container's root filesystem - where the OCI spec will be
Expand Down
1 change: 1 addition & 0 deletions test/e2e/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var _ = Describe("Podman inspect", func() {
Expect(result.ExitCode()).To(Equal(0))
conData := result.InspectContainerToJSON()
Expect(conData[0].SizeRootFs).To(BeNumerically(">", 0))
Expect(*conData[0].SizeRw).To(BeNumerically(">=", 0))
})

It("podman inspect container and image", func() {
Expand Down