From 38023b06b6c76cd41b81aeb56520b055b983a3f2 Mon Sep 17 00:00:00 2001 From: Georgi Sabev Date: Fri, 13 Oct 2017 17:39:01 +0300 Subject: [PATCH] Add more logging to disk quota setting for overlay [finishes #151942791] --- store/filesystems/overlayxfs/driver.go | 6 ++++-- .../overlayxfs/quota/projectquota_cgo.go | 13 ++++++++----- .../overlayxfs/quota/projectquota_nocgo.go | 4 +++- .../filesystems/overlayxfs/tardis/commands/limit.go | 2 +- .../filesystems/overlayxfs/tardis/ids/discoverer.go | 6 ++++-- store/filesystems/overlayxfs/tardis/stats/stats.go | 2 +- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/store/filesystems/overlayxfs/driver.go b/store/filesystems/overlayxfs/driver.go index 334f060d3..dcfe35639 100644 --- a/store/filesystems/overlayxfs/driver.go +++ b/store/filesystems/overlayxfs/driver.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "io" "io/ioutil" "os" "os/exec" @@ -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() diff --git a/store/filesystems/overlayxfs/quota/projectquota_cgo.go b/store/filesystems/overlayxfs/quota/projectquota_cgo.go index 3e97a99d3..1489556ce 100644 --- a/store/filesystems/overlayxfs/quota/projectquota_cgo.go +++ b/store/filesystems/overlayxfs/quota/projectquota_cgo.go @@ -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 @@ -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 @@ -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 // @@ -130,6 +132,7 @@ func NewControl(basePath string) (*Control, error) { } q := Control{ + logger: logger, backingFsBlockDev: backingFsBlockDev, nextProjectID: minProjectID + 1, quotas: make(map[string]uint32), @@ -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 } @@ -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) } @@ -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 diff --git a/store/filesystems/overlayxfs/quota/projectquota_nocgo.go b/store/filesystems/overlayxfs/quota/projectquota_nocgo.go index 2013273c3..3ec66e71c 100644 --- a/store/filesystems/overlayxfs/quota/projectquota_nocgo.go +++ b/store/filesystems/overlayxfs/quota/projectquota_nocgo.go @@ -4,6 +4,8 @@ package quota +import "code.cloudfoundry.org/lager" + type Quota struct { Size uint64 BCount uint64 @@ -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 } diff --git a/store/filesystems/overlayxfs/tardis/commands/limit.go b/store/filesystems/overlayxfs/tardis/commands/limit.go index c685ec786..80a6faf4d 100644 --- a/store/filesystems/overlayxfs/tardis/commands/limit.go +++ b/store/filesystems/overlayxfs/tardis/commands/limit.go @@ -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) diff --git a/store/filesystems/overlayxfs/tardis/ids/discoverer.go b/store/filesystems/overlayxfs/tardis/ids/discoverer.go index b29084fdf..8ae0c8166 100644 --- a/store/filesystems/overlayxfs/tardis/ids/discoverer.go +++ b/store/filesystems/overlayxfs/tardis/ids/discoverer.go @@ -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 { diff --git a/store/filesystems/overlayxfs/tardis/stats/stats.go b/store/filesystems/overlayxfs/tardis/stats/stats.go index 762e5c147..0d4e22261 100644 --- a/store/filesystems/overlayxfs/tardis/stats/stats.go +++ b/store/filesystems/overlayxfs/tardis/stats/stats.go @@ -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")