From 5b43a6a7ee6638b6d6cdb129321e42ce0dce6975 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Fri, 13 Jul 2018 11:51:06 -0400 Subject: Only print container size JSON if --size was requested To do this, move it into a separate struct, and embed that in the JSON we return. Signed-off-by: Matthew Heon --- cmd/podman/batchcontainer/container.go | 48 ++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'cmd/podman/batchcontainer') diff --git a/cmd/podman/batchcontainer/container.go b/cmd/podman/batchcontainer/container.go index 6f002f58a..017837a96 100644 --- a/cmd/podman/batchcontainer/container.go +++ b/cmd/podman/batchcontainer/container.go @@ -35,13 +35,13 @@ type PsOptions struct { // BatchContainerStruct is the return obkect from BatchContainer and contains // container related information type BatchContainerStruct struct { - ConConfig *libpod.ContainerConfig - ConState libpod.ContainerStatus - ExitCode int32 - Exited bool - Pid int - RootFsSize, RwSize int64 - StartedTime time.Time + ConConfig *libpod.ContainerConfig + ConState libpod.ContainerStatus + ExitCode int32 + Exited bool + Pid int + StartedTime time.Time + Size *ContainerSize } // Namespace describes output for ps namespace @@ -56,18 +56,25 @@ type Namespace struct { UTS string `json:"uts,omitempty"` } +// ContainerSize holds the size of the container's root filesystem and top +// read-write layer +type ContainerSize struct { + RootFsSize int64 `json:"rootFsSize"` + RwSize int64 `json:"rwSize"` +} + // BatchContainer is used in ps to reduce performance hits by "batching" // locks. func BatchContainerOp(ctr *libpod.Container, opts PsOptions) (BatchContainerStruct, error) { var ( - conConfig *libpod.ContainerConfig - conState libpod.ContainerStatus - err error - exitCode int32 - exited bool - pid int - rootFsSize, rwSize int64 - startedTime time.Time + conConfig *libpod.ContainerConfig + conState libpod.ContainerStatus + err error + exitCode int32 + exited bool + pid int + size *ContainerSize + startedTime time.Time ) batchErr := ctr.Batch(func(c *libpod.Container) error { @@ -97,16 +104,20 @@ func BatchContainerOp(ctr *libpod.Container, opts PsOptions) (BatchContainerStru } } if opts.Size { - rootFsSize, err = c.RootFsSize() + size = new(ContainerSize) + + rootFsSize, err := c.RootFsSize() if err != nil { logrus.Errorf("error getting root fs size for %q: %v", c.ID(), err) } - rwSize, err = c.RWSize() + rwSize, err := c.RWSize() if err != nil { logrus.Errorf("error getting rw size for %q: %v", c.ID(), err) } + size.RootFsSize = rootFsSize + size.RwSize = rwSize } return nil }) @@ -119,9 +130,8 @@ func BatchContainerOp(ctr *libpod.Container, opts PsOptions) (BatchContainerStru ExitCode: exitCode, Exited: exited, Pid: pid, - RootFsSize: rootFsSize, - RwSize: rwSize, StartedTime: startedTime, + Size: size, }, nil } -- cgit v1.2.3-54-g00ecf