Skip to content

Commit

Permalink
Add more logging to disk quota setting for overlay
Browse files Browse the repository at this point in the history
[finishes #151942791]
  • Loading branch information
georgethebeatle authored and CF Garden committed Oct 13, 2017
1 parent dcebdb1 commit 38023b0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
6 changes: 4 additions & 2 deletions store/filesystems/overlayxfs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -632,8 +633,9 @@ func (d *Driver) runTardis(logger lager.Logger, args ...string) (*bytes.Buffer,

cmd := exec.Command(d.tardisBinPath, args...)
stdoutBuffer := bytes.NewBuffer([]byte{})
cmd.Stdout = stdoutBuffer
cmd.Stderr = lagregator.NewRelogger(logger)
relogger := lagregator.NewRelogger(logger)
cmd.Stdout = io.MultiWriter(stdoutBuffer, relogger)
cmd.Stderr = relogger

err := cmd.Run()

Expand Down
13 changes: 8 additions & 5 deletions store/filesystems/overlayxfs/quota/projectquota_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import (
"syscall"
"unsafe"

"github.com/sirupsen/logrus"
"code.cloudfoundry.org/lager"
)

// Quota limit params - currently we only control blocks hard limit
Expand All @@ -73,6 +73,7 @@ type Quota struct {
// Control - Context to be used by storage driver (e.g. overlay)
// who wants to apply project quotas to container dirs
type Control struct {
logger lager.Logger
backingFsBlockDev string
nextProjectID uint32
quotas map[string]uint32
Expand Down Expand Up @@ -100,7 +101,8 @@ type Control struct {
// on it. If that works, continue to scan existing containers to map allocated
// project ids.
//
func NewControl(basePath string) (*Control, error) {
func NewControl(logger lager.Logger, basePath string) (*Control, error) {
logger = logger.Session("projectquota")
//
// Get project id of parent dir as minimal id to be used by driver
//
Expand Down Expand Up @@ -130,6 +132,7 @@ func NewControl(basePath string) (*Control, error) {
}

q := Control{
logger: logger,
backingFsBlockDev: backingFsBlockDev,
nextProjectID: minProjectID + 1,
quotas: make(map[string]uint32),
Expand All @@ -143,7 +146,7 @@ func NewControl(basePath string) (*Control, error) {
return nil, err
}

logrus.Debugf("NewControl(%s): nextProjectID = %d", basePath, q.nextProjectID)
q.logger.Debug("quota-control-created", lager.Data{"basePath": basePath, "projectID": q.nextProjectID})
return &q, nil
}

Expand All @@ -169,7 +172,7 @@ func (q *Control) SetQuota(nextProjectID uint32, targetPath string, quota Quota)
//
// set the quota limit for the container's project id
//
logrus.Debugf("SetQuota(%s, %d): projectID=%d", targetPath, quota.Size, projectID)
q.logger.Debug("set-quota", lager.Data{"targetPath": targetPath, "quota": quota.Size, "projectID": projectID})
return setProjectQuota(q.backingFsBlockDev, projectID, quota)
}

Expand Down Expand Up @@ -228,7 +231,7 @@ func (q *Control) GetQuota(targetPath string, quota *Quota) error {
}

// GetProjectID - get the project id of path on xfs
func GetProjectID(targetPath string) (uint32, error) {
func GetProjectID(targetPath string) (projId uint32, err error) {
dir, err := openDir(targetPath)
if err != nil {
return 0, err
Expand Down
4 changes: 3 additions & 1 deletion store/filesystems/overlayxfs/quota/projectquota_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package quota

import "code.cloudfoundry.org/lager"

type Quota struct {
Size uint64
BCount uint64
Expand All @@ -12,7 +14,7 @@ type Quota struct {
type Control struct {
}

func NewControl(basePath string) (*Control, error) {
func NewControl(logger lager.Logger, basePath string) (*Control, error) {
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion store/filesystems/overlayxfs/tardis/commands/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var LimitCommand = cli.Command{
imagePath := ctx.String("image-path")
imagesPath := filepath.Dir(imagePath)

quotaControl, err := quotapkg.NewControl(imagesPath)
quotaControl, err := quotapkg.NewControl(logger, imagesPath)
if err != nil {
logger.Error("creating-quota-control-failed", err, lager.Data{"imagesPath": imagesPath})
return errorspkg.Wrapf(err, "creating xfs quota control %s", imagesPath)
Expand Down
6 changes: 4 additions & 2 deletions store/filesystems/overlayxfs/tardis/ids/discoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ type Discoverer struct {
idsPath string
}

func (i *Discoverer) Alloc(logger lager.Logger) (uint32, error) {
func (i *Discoverer) Alloc(logger lager.Logger) (projId uint32, err error) {
logger = logger.Session("project-id-allocation")
logger.Debug("starting")
defer logger.Debug("ending")
defer func() {
logger.Debug("ending", lager.Data{"projectID": projId})
}()

contents, err := ioutil.ReadDir(i.idsPath)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion store/filesystems/overlayxfs/tardis/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func listQuotaUsage(logger lager.Logger, imagePath string) (int64, error) {
defer logger.Debug("ending")

imagesPath := filepath.Dir(imagePath)
quotaControl, err := quotapkg.NewControl(imagesPath)
quotaControl, err := quotapkg.NewControl(logger, imagesPath)
if err != nil {
logger.Error("creating-quota-control-failed", err)
return 0, errorspkg.Wrapf(err, "creating quota control")
Expand Down

0 comments on commit 38023b0

Please sign in to comment.