Move functions in libkpod to ContainerServer
Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
parent
da176cd379
commit
b1eb754ef5
3 changed files with 39 additions and 116 deletions
|
@ -10,14 +10,18 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// FindContainer searches for a container with the given name or ID in the given store
|
||||
func FindContainer(store cstorage.Store, container string) (*cstorage.Container, error) {
|
||||
return store.Container(container)
|
||||
// GetStorageContainer searches for a container with the given name or ID in the given store
|
||||
func (c *ContainerServer) GetStorageContainer(container string) (*cstorage.Container, error) {
|
||||
ociCtr, err := c.LookupContainer(container)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.store.Container(ociCtr.ID())
|
||||
}
|
||||
|
||||
// GetContainerTopLayerID gets the ID of the top layer of the given container
|
||||
func GetContainerTopLayerID(store cstorage.Store, containerID string) (string, error) {
|
||||
ctr, err := FindContainer(store, containerID)
|
||||
func (c *ContainerServer) GetContainerTopLayerID(containerID string) (string, error) {
|
||||
ctr, err := c.GetStorageContainer(containerID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -25,8 +29,8 @@ func GetContainerTopLayerID(store cstorage.Store, containerID string) (string, e
|
|||
}
|
||||
|
||||
// GetContainerRwSize Gets the size of the mutable top layer of the container
|
||||
func GetContainerRwSize(store cstorage.Store, containerID string) (int64, error) {
|
||||
container, err := store.Container(containerID)
|
||||
func (c *ContainerServer) GetContainerRwSize(containerID string) (int64, error) {
|
||||
container, err := c.store.Container(containerID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -34,42 +38,42 @@ func GetContainerRwSize(store cstorage.Store, containerID string) (int64, error)
|
|||
// 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 := store.Layer(container.LayerID)
|
||||
layer, err := c.store.Layer(container.LayerID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return store.DiffSize(layer.Parent, layer.ID)
|
||||
return c.store.DiffSize(layer.Parent, layer.ID)
|
||||
}
|
||||
|
||||
// GetContainerRootFsSize gets the size of the container's root filesystem
|
||||
// A container FS is split into two parts. The first is the top layer, a
|
||||
// mutable layer, and the rest is the RootFS: the set of immutable layers
|
||||
// that make up the image on which the container is based
|
||||
func GetContainerRootFsSize(store cstorage.Store, containerID string) (int64, error) {
|
||||
container, err := store.Container(containerID)
|
||||
func (c *ContainerServer) GetContainerRootFsSize(containerID string) (int64, error) {
|
||||
container, err := c.store.Container(containerID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Ignore the size of the top layer. The top layer is a mutable RW layer
|
||||
// and is not considered a part of the rootfs
|
||||
rwLayer, err := store.Layer(container.LayerID)
|
||||
rwLayer, err := c.store.Layer(container.LayerID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
layer, err := store.Layer(rwLayer.Parent)
|
||||
layer, err := c.store.Layer(rwLayer.Parent)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
size := int64(0)
|
||||
for layer.Parent != "" {
|
||||
layerSize, err := store.DiffSize(layer.Parent, layer.ID)
|
||||
layerSize, err := c.store.DiffSize(layer.Parent, layer.ID)
|
||||
if err != nil {
|
||||
return size, errors.Wrapf(err, "getting diffsize of layer %q and its parent %q", layer.ID, layer.Parent)
|
||||
}
|
||||
size += layerSize
|
||||
layer, err = store.Layer(layer.Parent)
|
||||
layer, err = c.store.Layer(layer.Parent)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -77,7 +81,7 @@ func GetContainerRootFsSize(store cstorage.Store, containerID string) (int64, er
|
|||
// Get the size of the last layer. Has to be outside of the loop
|
||||
// because the parent of the last layer is "", andlstore.Get("")
|
||||
// will return an error
|
||||
layerSize, err := store.DiffSize(layer.Parent, layer.ID)
|
||||
layerSize, err := c.store.DiffSize(layer.Parent, layer.ID)
|
||||
return size + layerSize, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue