The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6375

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
- Adds contextual logger to backends and drivers.
- Updates backendLXD functions to log start and finish of each function with context of args supplied.

Includes https://github.com/lxc/lxd/pull/6373
From 600825ac9a562005c128a66736c759111026f17a Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 11:51:29 +0000
Subject: [PATCH 01/11] lxd/storage/volumes: Makes storagePoolVolumeTypePut
 logic consistent with storagePoolVolumeSnapshotTypePut

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage_volumes.go | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index 0277b83c03..1f7f31cea4 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -976,9 +976,13 @@ func storagePoolVolumeTypePut(d *Daemon, r *http.Request, 
volumeTypeName string)
                        // means that modifying a snapshot's description gets 
routed here rather
                        // than the dedicated snapshot editing route. So need 
to handle snapshot
                        // volumes here too.
-                       err = d.cluster.StoragePoolVolumeUpdate(vol.Name, 
volumeType, poolID, req.Description, req.Config)
-                       if err != nil {
-                               return response.SmartError(err)
+
+                       // Update the database if description changed.
+                       if req.Description != vol.Description {
+                               err = 
d.cluster.StoragePoolVolumeUpdate(vol.Name, volumeType, poolID, 
req.Description, vol.Config)
+                               if err != nil {
+                                       response.SmartError(err)
+                               }
                        }
                }
        } else {

From 8375d6cdda473179a5d1145c7e463f6f8219d7ac Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 11:52:08 +0000
Subject: [PATCH 02/11] lxd/storage/volumes/snapshot: Moves
 storagePoolVolumeSnapshotTypePut DB logic

Moves DB logic from legacy storage functions into API directly (as just DB 
updates) as its just a description update.

This will then work with both old and new storage layers.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage_volumes_snapshot.go | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/lxd/storage_volumes_snapshot.go b/lxd/storage_volumes_snapshot.go
index f38af7fef8..16794ab836 100644
--- a/lxd/storage_volumes_snapshot.go
+++ b/lxd/storage_volumes_snapshot.go
@@ -398,6 +398,7 @@ func storagePoolVolumeSnapshotTypeGet(d *Daemon, r 
*http.Request) response.Respo
        return response.SyncResponseETag(true, &snapshot, etag)
 }
 
+// storagePoolVolumeSnapshotTypePut allows a snapshot's description to be 
changed.
 func storagePoolVolumeSnapshotTypePut(d *Daemon, r *http.Request) 
response.Response {
        // Get the name of the storage pool the volume is supposed to be
        // attached to.
@@ -420,7 +421,7 @@ func storagePoolVolumeSnapshotTypePut(d *Daemon, r 
*http.Request) response.Respo
 
        // Check that the storage volume type is valid.
        if volumeType != storagePoolVolumeTypeCustom {
-               return response.BadRequest(fmt.Errorf("invalid storage volume 
type %s", volumeTypeName))
+               return response.BadRequest(fmt.Errorf("Invalid storage volume 
type %s", volumeTypeName))
        }
 
        resp := ForwardedResponseIfTargetIsRemote(d, r)
@@ -439,13 +440,13 @@ func storagePoolVolumeSnapshotTypePut(d *Daemon, r 
*http.Request) response.Respo
                return resp
        }
 
-       _, volume, err := 
d.cluster.StoragePoolNodeVolumeGetType(fullSnapshotName, volumeType, poolID)
+       _, vol, err := d.cluster.StoragePoolNodeVolumeGetType(fullSnapshotName, 
volumeType, poolID)
        if err != nil {
                return response.SmartError(err)
        }
 
        // Validate the ETag
-       etag := []interface{}{snapshotName, volume.Description, volume.Config}
+       etag := []interface{}{snapshotName, vol.Description, vol.Config}
        err = util.EtagCheck(r, etag)
        if err != nil {
                return response.PreconditionFailed(err)
@@ -457,22 +458,22 @@ func storagePoolVolumeSnapshotTypePut(d *Daemon, r 
*http.Request) response.Respo
                return response.BadRequest(err)
        }
 
-       var do func(*operations.Operation) error
-       var opDescription db.OperationType
-       do = func(op *operations.Operation) error {
-               err = storagePoolVolumeSnapshotUpdate(d.State(), poolName, 
volume.Name, volumeType, req.Description)
-               if err != nil {
-                       return err
+       do := func(op *operations.Operation) error {
+               // Update the database if description changed.
+               if req.Description != vol.Description {
+                       err = d.cluster.StoragePoolVolumeUpdate(vol.Name, 
volumeType, poolID, req.Description, vol.Config)
+                       if err != nil {
+                               return err
+                       }
                }
 
-               opDescription = db.OperationVolumeSnapshotDelete
                return nil
        }
 
        resources := map[string][]string{}
        resources["storage_volume_snapshots"] = []string{volumeName}
 
-       op, err := operations.OperationCreate(d.State(), "", 
operations.OperationClassTask, opDescription, resources, nil, do, nil, nil)
+       op, err := operations.OperationCreate(d.State(), "", 
operations.OperationClassTask, db.OperationSnapshotUpdate, resources, nil, do, 
nil, nil)
        if err != nil {
                return response.InternalError(err)
        }

From 441d1ad5bda2aeb4f370dd954b804938391d943e Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 11:53:28 +0000
Subject: [PATCH 03/11] lxd/storage/volumes/utils: Removes unused
 storagePoolVolumeSnapshotUpdate

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage_volumes_utils.go | 22 ----------------------
 1 file changed, 22 deletions(-)

diff --git a/lxd/storage_volumes_utils.go b/lxd/storage_volumes_utils.go
index c70e8acb8a..ab7791e742 100644
--- a/lxd/storage_volumes_utils.go
+++ b/lxd/storage_volumes_utils.go
@@ -207,28 +207,6 @@ func storagePoolVolumeUpdate(state *state.State, poolName 
string, volumeName str
        return nil
 }
 
-func storagePoolVolumeSnapshotUpdate(state *state.State, poolName string, 
volumeName string, volumeType int, newDescription string) error {
-       s, err := storagePoolVolumeInit(state, "default", poolName, volumeName, 
volumeType)
-       if err != nil {
-               return err
-       }
-
-       oldWritable := s.GetStoragePoolVolumeWritable()
-       oldDescription := oldWritable.Description
-
-       poolID, err := state.Cluster.StoragePoolGetID(poolName)
-       if err != nil {
-               return err
-       }
-
-       // Update the database if something changed
-       if newDescription != oldDescription {
-               return state.Cluster.StoragePoolVolumeUpdate(volumeName, 
volumeType, poolID, newDescription, oldWritable.Config)
-       }
-
-       return nil
-}
-
 func storagePoolVolumeUsedByContainersGet(s *state.State, project, poolName 
string, volumeName string) ([]string, error) {
        insts, err := instanceLoadByProject(s, project)
        if err != nil {

From f524067312ef9617c79933745764bbc6e9c55ab9 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 13:24:31 +0000
Subject: [PATCH 04/11] lxd/storage/backend/lxd: Adds basic debug logging

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/backend_lxd.go | 80 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 5619577fb0..c88e0ddc31 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -15,6 +15,9 @@ import (
        "github.com/lxc/lxd/lxd/storage/memorypipe"
        "github.com/lxc/lxd/shared"
        "github.com/lxc/lxd/shared/api"
+       log "github.com/lxc/lxd/shared/log15"
+       "github.com/lxc/lxd/shared/logger"
+       "github.com/lxc/lxd/shared/logging"
 )
 
 type lxdBackend struct {
@@ -22,6 +25,7 @@ type lxdBackend struct {
        id     int64
        name   string
        state  *state.State
+       logger logger.Logger
 }
 
 func (b *lxdBackend) DaemonState() *state.State {
@@ -51,6 +55,10 @@ func (b *lxdBackend) MigrationTypes(contentType 
drivers.ContentType) []migration
 
 // create creates the storage pool layout on the storage device.
 func (b *lxdBackend) create(dbPool *api.StoragePool, op *operations.Operation) 
error {
+       logger := logging.AddContext(b.logger, log.Ctx{"args": dbPool})
+       logger.Debug("create started")
+       defer logger.Debug("created finished")
+
        revertPath := true
 
        // Create the storage path.
@@ -103,11 +111,19 @@ func (b *lxdBackend) newVolume(volType 
drivers.VolumeType, contentType drivers.C
 }
 
 func (b *lxdBackend) GetResources() (*api.ResourcesStoragePool, error) {
+       logger := logging.AddContext(b.logger, nil)
+       logger.Debug("GetResources started")
+       defer logger.Debug("GetResources finished")
+
        return b.driver.GetResources()
 }
 
 // Delete removes the pool.
 func (b *lxdBackend) Delete(op *operations.Operation) error {
+       logger := logging.AddContext(b.logger, nil)
+       logger.Debug("Delete started")
+       defer logger.Debug("Delete finished")
+
        // Delete the low-level storage.
        err := b.driver.Delete(op)
        if err != nil {
@@ -126,11 +142,19 @@ func (b *lxdBackend) Delete(op *operations.Operation) 
error {
 
 // Mount mounts the storage pool.
 func (b *lxdBackend) Mount() (bool, error) {
+       logger := logging.AddContext(b.logger, nil)
+       logger.Debug("Mount started")
+       defer logger.Debug("Mount finished")
+
        return b.driver.Mount()
 }
 
 // Unmount unmounts the storage pool.
 func (b *lxdBackend) Unmount() (bool, error) {
+       logger := logging.AddContext(b.logger, nil)
+       logger.Debug("Unmount started")
+       defer logger.Debug("Unmount finished")
+
        return b.driver.Unmount()
 }
 
@@ -224,6 +248,10 @@ func (b *lxdBackend) CreateImage(img api.Image, op 
*operations.Operation) error
 
 // DeleteImage removes an image from the database and underlying storage 
device if needed.
 func (b *lxdBackend) DeleteImage(fingerprint string, op *operations.Operation) 
error {
+       logger := logging.AddContext(b.logger, log.Ctx{"fingerprint": 
fingerprint})
+       logger.Debug("DeleteImage started")
+       defer logger.Debug("DeleteImage finished")
+
        regexSHA256, err := regexp.Compile("^[0-9a-f]{64}$")
        if err != nil {
                return err
@@ -248,6 +276,10 @@ func (b *lxdBackend) DeleteImage(fingerprint string, op 
*operations.Operation) e
 
 // CreateCustomVolume creates an empty custom volume.
 func (b *lxdBackend) CreateCustomVolume(volName, desc string, config 
map[string]string, op *operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName, 
"desc": desc, "config": config})
+       logger.Debug("CreateCustomVolume started")
+       defer logger.Debug("CreateCustomVolume finished")
+
        // Validate config.
        err := b.driver.ValidateVolume(b.newVolume(drivers.VolumeTypeCustom, 
drivers.ContentTypeFS, volName, config), false)
        if err != nil {
@@ -281,6 +313,10 @@ func (b *lxdBackend) CreateCustomVolume(volName, desc 
string, config map[string]
 // CreateCustomVolumeFromCopy creates a custom volume from an existing custom 
volume.
 // It copies the snapshots from the source volume by default, but can be 
disabled if requested.
 func (b *lxdBackend) CreateCustomVolumeFromCopy(volName, desc string, config 
map[string]string, srcPoolName, srcVolName string, srcVolOnly bool, op 
*operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName, 
"desc": desc, "config": config, "srcPoolName": srcPoolName, "srcVolName": 
srcVolName, "srcVolOnly": srcVolOnly})
+       logger.Debug("CreateCustomVolumeFromCopy started")
+       defer logger.Debug("CreateCustomVolumeFromCopy finished")
+
        // Setup the source pool backend instance.
        var srcPool *lxdBackend
        if b.name == srcPoolName {
@@ -395,6 +431,10 @@ func (b *lxdBackend) CreateCustomVolumeFromCopy(volName, 
desc string, config map
 
 // MigrateCustomVolume sends a volume for migration.
 func (b *lxdBackend) MigrateCustomVolume(conn io.ReadWriteCloser, args 
migration.VolumeSourceArgs, op *operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": args.Name, 
"args": args})
+       logger.Debug("MigrateCustomVolume started")
+       defer logger.Debug("MigrateCustomVolume finished")
+
        vol := b.newVolume(drivers.VolumeTypeCustom, drivers.ContentTypeFS, 
args.Name, nil)
        err := b.driver.MigrateVolume(vol, conn, args, op)
        if err != nil {
@@ -406,6 +446,10 @@ func (b *lxdBackend) MigrateCustomVolume(conn 
io.ReadWriteCloser, args migration
 
 // CreateCustomVolumeFromMigration receives a volume being migrated.
 func (b *lxdBackend) CreateCustomVolumeFromMigration(conn io.ReadWriteCloser, 
args migration.VolumeTargetArgs, op *operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": args.Name, 
"args": args})
+       logger.Debug("CreateCustomVolumeFromMigration started")
+       defer logger.Debug("CreateCustomVolumeFromMigration finished")
+
        // Create slice to record DB volumes created if revert needed later.
        revertDBVolumes := []string{}
        defer func() {
@@ -455,6 +499,10 @@ func (b *lxdBackend) CreateCustomVolumeFromMigration(conn 
io.ReadWriteCloser, ar
 
 // RenameCustomVolume renames a custom volume and its snapshots.
 func (b *lxdBackend) RenameCustomVolume(volName string, newVolName string, op 
*operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName, 
"newVolName": newVolName})
+       logger.Debug("RenameCustomVolume started")
+       defer logger.Debug("RenameCustomVolume finished")
+
        if shared.IsSnapshot(volName) {
                return fmt.Errorf("Volume name cannot be a snapshot")
        }
@@ -518,6 +566,10 @@ func (b *lxdBackend) RenameCustomVolume(volName string, 
newVolName string, op *o
 
 // UpdateCustomVolume applies the supplied config to the custom volume.
 func (b *lxdBackend) UpdateCustomVolume(volName, newDesc string, newConfig 
map[string]string, op *operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName, 
"newDesc": newDesc, "newConfig": newConfig})
+       logger.Debug("UpdateCustomVolume started")
+       defer logger.Debug("UpdateCustomVolume finished")
+
        if shared.IsSnapshot(volName) {
                return fmt.Errorf("Volume name cannot be a snapshot")
        }
@@ -609,6 +661,10 @@ func (b *lxdBackend) UpdateCustomVolume(volName, newDesc 
string, newConfig map[s
 
 // DeleteCustomVolume removes a custom volume and its snapshots.
 func (b *lxdBackend) DeleteCustomVolume(volName string, op 
*operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName})
+       logger.Debug("DeleteCustomVolume started")
+       defer logger.Debug("DeleteCustomVolume finished")
+
        _, _, isSnap := shared.ContainerGetParentAndSnapshotName(volName)
        if isSnap {
                return fmt.Errorf("Volume name cannot be a snapshot")
@@ -667,16 +723,28 @@ func (b *lxdBackend) SetCustomVolumeQuota(vol 
api.StorageVolume, quota uint64) e
 
 // MountCustomVolume mounts a custom volume.
 func (b *lxdBackend) MountCustomVolume(volName string, op 
*operations.Operation) (bool, error) {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName})
+       logger.Debug("MountCustomVolume started")
+       defer logger.Debug("MountCustomVolume finished")
+
        return b.driver.MountVolume(drivers.VolumeTypeCustom, volName, op)
 }
 
 // UnmountCustomVolume unmounts a custom volume.
 func (b *lxdBackend) UnmountCustomVolume(volName string, op 
*operations.Operation) (bool, error) {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName})
+       logger.Debug("UnmountCustomVolume started")
+       defer logger.Debug("UnmountCustomVolume finished")
+
        return b.driver.UnmountVolume(drivers.VolumeTypeCustom, volName, op)
 }
 
 // CreateCustomVolumeSnapshot creates a snapshot of a custom volume.
 func (b *lxdBackend) CreateCustomVolumeSnapshot(volName string, 
newSnapshotName string, op *operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName, 
"newSnapshotName": newSnapshotName})
+       logger.Debug("CreateCustomVolumeSnapshot started")
+       defer logger.Debug("CreateCustomVolumeSnapshot finished")
+
        if shared.IsSnapshot(volName) {
                return fmt.Errorf("Volume cannot be snapshot")
        }
@@ -732,6 +800,10 @@ func (b *lxdBackend) CreateCustomVolumeSnapshot(volName 
string, newSnapshotName
 
 // RenameCustomVolumeSnapshot renames a custom volume.
 func (b *lxdBackend) RenameCustomVolumeSnapshot(volName string, 
newSnapshotName string, op *operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName, 
"newSnapshotName": newSnapshotName})
+       logger.Debug("RenameCustomVolumeSnapshot started")
+       defer logger.Debug("RenameCustomVolumeSnapshot finished")
+
        parentName, oldSnapshotName, isSnap := 
shared.ContainerGetParentAndSnapshotName(volName)
        if !isSnap {
                return fmt.Errorf("Volume name must be a snapshot")
@@ -759,6 +831,10 @@ func (b *lxdBackend) RenameCustomVolumeSnapshot(volName 
string, newSnapshotName
 
 // DeleteCustomVolumeSnapshot removes a custom volume snapshot.
 func (b *lxdBackend) DeleteCustomVolumeSnapshot(volName string, op 
*operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName})
+       logger.Debug("DeleteCustomVolumeSnapshot started")
+       defer logger.Debug("DeleteCustomVolumeSnapshot finished")
+
        parentName, snapName, isSnap := 
shared.ContainerGetParentAndSnapshotName(volName)
        if !isSnap {
                return fmt.Errorf("Volume name must be a snapshot")
@@ -781,6 +857,10 @@ func (b *lxdBackend) DeleteCustomVolumeSnapshot(volName 
string, op *operations.O
 
 // RestoreCustomVolume restores a custom volume from a snapshot.
 func (b *lxdBackend) RestoreCustomVolume(volName string, snapshotName string, 
op *operations.Operation) error {
+       logger := logging.AddContext(b.logger, log.Ctx{"volName": volName, 
"snapshotName": snapshotName})
+       logger.Debug("RestoreCustomVolume started")
+       defer logger.Debug("RestoreCustomVolume finished")
+
        if shared.IsSnapshot(volName) {
                return fmt.Errorf("Volume cannot be snapshot")
        }

From c08aada7660e7d72ba0bf93ebca596aa9d88e057 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 13:24:47 +0000
Subject: [PATCH 05/11] lxd/storage/backend/mock: Adds logger support

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/backend_mock.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lxd/storage/backend_mock.go b/lxd/storage/backend_mock.go
index aa5f5f67f9..05aa1b9b4f 100644
--- a/lxd/storage/backend_mock.go
+++ b/lxd/storage/backend_mock.go
@@ -8,11 +8,13 @@ import (
        "github.com/lxc/lxd/lxd/state"
        "github.com/lxc/lxd/lxd/storage/drivers"
        "github.com/lxc/lxd/shared/api"
+       "github.com/lxc/lxd/shared/logger"
 )
 
 type mockBackend struct {
-       name  string
-       state *state.State
+       name   string
+       state  *state.State
+       logger logger.Logger
 }
 
 func (b *mockBackend) DaemonState() *state.State {

From e1a482df3cb1956d0a1f79b91d95e698f0f8de0f Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 13:25:36 +0000
Subject: [PATCH 06/11] lxd/storage/load: Initialises logger

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/load.go | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lxd/storage/load.go b/lxd/storage/load.go
index d25163f7fd..2c7298e4e7 100644
--- a/lxd/storage/load.go
+++ b/lxd/storage/load.go
@@ -8,6 +8,9 @@ import (
        "github.com/lxc/lxd/lxd/state"
        "github.com/lxc/lxd/lxd/storage/drivers"
        "github.com/lxc/lxd/shared/api"
+       log "github.com/lxc/lxd/shared/log15"
+       "github.com/lxc/lxd/shared/logger"
+       "github.com/lxc/lxd/shared/logging"
 )
 
 // MockBackend controls whether to run the storage logic in mock mode.
@@ -56,6 +59,7 @@ func CreatePool(state *state.State, poolID int64, dbPool 
*api.StoragePool, op *o
                pool := mockBackend{}
                pool.name = dbPool.Name
                pool.state = state
+               pool.logger = logging.AddContext(logger.Log, log.Ctx{"driver": 
"mock", "pool": pool.name})
                return &pool, nil
        }
 
@@ -71,6 +75,7 @@ func CreatePool(state *state.State, poolID int64, dbPool 
*api.StoragePool, op *o
        pool.id = poolID
        pool.name = dbPool.Name
        pool.state = state
+       pool.logger = logging.AddContext(logger.Log, log.Ctx{"driver": 
dbPool.Driver, "pool": pool.name})
 
        // Create the pool itself on the storage device..
        err = pool.create(dbPool, op)
@@ -88,6 +93,7 @@ func GetPoolByName(state *state.State, name string) (Pool, 
error) {
                pool := mockBackend{}
                pool.name = name
                pool.state = state
+               pool.logger = logging.AddContext(logger.Log, log.Ctx{"driver": 
"mock", "pool": pool.name})
                return &pool, nil
        }
 
@@ -114,6 +120,7 @@ func GetPoolByName(state *state.State, name string) (Pool, 
error) {
        pool.id = poolID
        pool.name = dbPool.Name
        pool.state = state
+       pool.logger = logging.AddContext(logger.Log, log.Ctx{"driver": 
dbPool.Driver, "pool": pool.name})
 
        return &pool, nil
 }

From 63a1244d0886cfc6fd0c2a90f81a15b356597c39 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 15:48:34 +0000
Subject: [PATCH 07/11] lxd/storage/drivers/driver/common: Adds driver logger
 with pool context

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/drivers/driver_common.go | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/driver_common.go 
b/lxd/storage/drivers/driver_common.go
index bf6dc8e158..6712aec86e 100644
--- a/lxd/storage/drivers/driver_common.go
+++ b/lxd/storage/drivers/driver_common.go
@@ -6,6 +6,7 @@ import (
 
        "github.com/lxc/lxd/lxd/migration"
        "github.com/lxc/lxd/lxd/state"
+       "github.com/lxc/lxd/shared/logger"
 )
 
 type common struct {
@@ -14,14 +15,16 @@ type common struct {
        getVolID       func(volType VolumeType, volName string) (int64, error)
        getCommonRules func() map[string]func(string) error
        state          *state.State
+       logger         logger.Logger
 }
 
-func (d *common) init(state *state.State, name string, config 
map[string]string, volIDFunc func(volType VolumeType, volName string) (int64, 
error), commonRulesFunc func() map[string]func(string) error) {
+func (d *common) init(state *state.State, name string, config 
map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, 
volName string) (int64, error), commonRulesFunc func() map[string]func(string) 
error) {
        d.name = name
        d.config = config
        d.getVolID = volIDFunc
        d.getCommonRules = commonRulesFunc
        d.state = state
+       d.logger = logger
 }
 
 // validateVolume validates a volume config against common rules and optional 
driver specific rules.

From 0724ac3f79933834040ddd4a2794742ff1057eae Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 15:48:54 +0000
Subject: [PATCH 08/11] lxd/storage/drivers/interface: Updates with pool
 context logger

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/drivers/interface.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/interface.go b/lxd/storage/drivers/interface.go
index 09710b17ef..f98b634586 100644
--- a/lxd/storage/drivers/interface.go
+++ b/lxd/storage/drivers/interface.go
@@ -7,13 +7,14 @@ import (
        "github.com/lxc/lxd/lxd/operations"
        "github.com/lxc/lxd/lxd/state"
        "github.com/lxc/lxd/shared/api"
+       "github.com/lxc/lxd/shared/logger"
 )
 
 // driver is the extended internal interface.
 type driver interface {
        Driver
 
-       init(state *state.State, name string, config map[string]string, 
volIDFunc func(volType VolumeType, volName string) (int64, error), 
commonRulesFunc func() map[string]func(string) error)
+       init(state *state.State, name string, config map[string]string, logger 
logger.Logger, volIDFunc func(volType VolumeType, volName string) (int64, 
error), commonRulesFunc func() map[string]func(string) error)
 }
 
 // Driver represents a low-level storage driver.

From 2f1737528f8e891d265e0a4622525a6fa09b1e92 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 15:49:18 +0000
Subject: [PATCH 09/11] lxd/storage/utils: Updates VolumeValidateConfig to use
 update driver loader

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/utils.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage/utils.go b/lxd/storage/utils.go
index acc5e6069c..b22e8c1ada 100644
--- a/lxd/storage/utils.go
+++ b/lxd/storage/utils.go
@@ -526,7 +526,7 @@ var StorageVolumeConfigKeys = map[string]func(value string) 
([]string, error){
 // VolumeValidateConfig validations volume config.
 func VolumeValidateConfig(name string, config map[string]string, parentPool 
*api.StoragePool) error {
        // Validate volume config using the new driver interface if supported.
-       driver, err := drivers.Load(nil, parentPool.Driver, parentPool.Name, 
parentPool.Config, nil, validateVolumeCommonRules)
+       driver, err := drivers.Load(nil, parentPool.Driver, parentPool.Name, 
parentPool.Config, nil, nil, validateVolumeCommonRules)
        if err != drivers.ErrUnknownDriver {
                // Note: This legacy validation function doesn't have the 
concept of validating
                // different volumes types, so the types are hard coded as 
Custom and FS.

From 01e5b3d84dfa84064a0a0cfb9907334a91d26ea2 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 15:49:44 +0000
Subject: [PATCH 10/11] lxd/storage/load: Updates loaders to support contextual
 loggers

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/load.go | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/lxd/storage/load.go b/lxd/storage/load.go
index 2c7298e4e7..1c134d75d6 100644
--- a/lxd/storage/load.go
+++ b/lxd/storage/load.go
@@ -63,8 +63,10 @@ func CreatePool(state *state.State, poolID int64, dbPool 
*api.StoragePool, op *o
                return &pool, nil
        }
 
+       logger := logging.AddContext(logger.Log, log.Ctx{"driver": 
dbPool.Driver, "pool": dbPool.Name})
+
        // Load the storage driver.
-       driver, err := drivers.Load(state, dbPool.Driver, dbPool.Name, 
dbPool.Config, volIDFuncMake(state, poolID), validateVolumeCommonRules)
+       driver, err := drivers.Load(state, dbPool.Driver, dbPool.Name, 
dbPool.Config, logger, volIDFuncMake(state, poolID), validateVolumeCommonRules)
        if err != nil {
                return nil, err
        }
@@ -75,7 +77,7 @@ func CreatePool(state *state.State, poolID int64, dbPool 
*api.StoragePool, op *o
        pool.id = poolID
        pool.name = dbPool.Name
        pool.state = state
-       pool.logger = logging.AddContext(logger.Log, log.Ctx{"driver": 
dbPool.Driver, "pool": pool.name})
+       pool.logger = logger
 
        // Create the pool itself on the storage device..
        err = pool.create(dbPool, op)
@@ -108,8 +110,10 @@ func GetPoolByName(state *state.State, name string) (Pool, 
error) {
                dbPool.Config = map[string]string{}
        }
 
+       logger := logging.AddContext(logger.Log, log.Ctx{"driver": 
dbPool.Driver, "pool": dbPool.Name})
+
        // Load the storage driver.
-       driver, err := drivers.Load(state, dbPool.Driver, dbPool.Name, 
dbPool.Config, volIDFuncMake(state, poolID), validateVolumeCommonRules)
+       driver, err := drivers.Load(state, dbPool.Driver, dbPool.Name, 
dbPool.Config, logger, volIDFuncMake(state, poolID), validateVolumeCommonRules)
        if err != nil {
                return nil, err
        }
@@ -120,7 +124,7 @@ func GetPoolByName(state *state.State, name string) (Pool, 
error) {
        pool.id = poolID
        pool.name = dbPool.Name
        pool.state = state
-       pool.logger = logging.AddContext(logger.Log, log.Ctx{"driver": 
dbPool.Driver, "pool": pool.name})
+       pool.logger = logger
 
        return &pool, nil
 }

From 4ef30c990afdcdcd13b1e65bd671357051aafc5f Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Thu, 31 Oct 2019 15:50:03 +0000
Subject: [PATCH 11/11] lxd/storage/drivers/load: Updates loaders to support
 contextual loggers

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/drivers/load.go | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lxd/storage/drivers/load.go b/lxd/storage/drivers/load.go
index a10fdfd01f..17ca227f7b 100644
--- a/lxd/storage/drivers/load.go
+++ b/lxd/storage/drivers/load.go
@@ -2,6 +2,7 @@ package drivers
 
 import (
        "github.com/lxc/lxd/lxd/state"
+       "github.com/lxc/lxd/shared/logger"
 )
 
 var drivers = map[string]func() driver{
@@ -9,7 +10,7 @@ var drivers = map[string]func() driver{
 }
 
 // Load returns a Driver for an existing low-level storage pool.
-func Load(state *state.State, driverName string, name string, config 
map[string]string, volIDFunc func(volType VolumeType, volName string) (int64, 
error), commonRulesFunc func() map[string]func(string) error) (Driver, error) {
+func Load(state *state.State, driverName string, name string, config 
map[string]string, logger logger.Logger, volIDFunc func(volType VolumeType, 
volName string) (int64, error), commonRulesFunc func() map[string]func(string) 
error) (Driver, error) {
        // Locate the driver loader.
        driverFunc, ok := drivers[driverName]
        if !ok {
@@ -17,7 +18,7 @@ func Load(state *state.State, driverName string, name string, 
config map[string]
        }
 
        d := driverFunc()
-       d.init(state, name, config, volIDFunc, commonRulesFunc)
+       d.init(state, name, config, logger, volIDFunc, commonRulesFunc)
 
        return d, nil
 }
@@ -38,7 +39,7 @@ func SupportedDrivers() []Info {
        supportedDrivers := []Info{}
 
        for driverName := range drivers {
-               driver, err := Load(nil, driverName, "", nil, nil, nil)
+               driver, err := Load(nil, driverName, "", nil, nil, nil, nil)
                if err != nil {
                        continue
                }
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to