Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Su <[email protected]>
  • Loading branch information
derekbit committed Nov 26, 2024
1 parent 1774180 commit bd9951c
Show file tree
Hide file tree
Showing 9 changed files with 1,030 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.23.3
require (
github.com/0xPolygon/polygon-edge v1.3.3
github.com/google/uuid v1.6.0
github.com/jinzhu/copier v0.4.0
github.com/longhorn/backupstore v0.0.0-20241124092526-138305866a87
github.com/longhorn/go-common-libs v0.0.0-20241124035508-d6221574e626
github.com/longhorn/go-spdk-helper v0.0.0-20241124090314-c396ae715a7f
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand Down
31 changes: 31 additions & 0 deletions pkg/spdk/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"sync"
"time"

"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

grpccodes "google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"

Expand Down Expand Up @@ -662,13 +664,42 @@ func (e *Engine) getWithoutLock() (res *spdkrpc.Engine) {
return res
}

func areNvmeSubsystemsEqual(old, new *api.NvmeSubsystem) bool {

Check notice on line 667 in pkg/spdk/engine.go

View check run for this annotation

codefactor.io / CodeFactor

pkg/spdk/engine.go#L667

Redefinition of the built-in function new. (redefines-builtin-id)
if len(old.Paths) != len(old.Paths) {
return false
}
for oldPathName, oldPath := range old.Paths {
newPath, ok := new.Paths[oldPathName]
if !ok {
return false
}
if oldPath.Trtype != newPath.Trtype ||
oldPath.Traddr != newPath.Traddr ||
oldPath.Trsvcid != newPath.Trsvcid ||
oldPath.SrcAddr != newPath.SrcAddr ||
oldPath.State != newPath.State {
return false
}

}
return true
}

func (e *Engine) ValidateAndUpdate(spdkClient *spdkclient.Client) (err error) {
updateRequired := false

existingNvemSubsystem := api.NvmeSubsystem{}
copier.Copy(&existingNvemSubsystem, &e.NvmeSubsystem)

e.Lock()
defer func() {
e.Unlock()

if !areNvmeSubsystemsEqual(&existingNvemSubsystem, &e.NvmeSubsystem) {
e.log.Infof("Found difference between existing nvme subsystem %+v and updated nvme subsystem %+v during ValidateAndUpdate", existingNvemSubsystem, e.NvmeSubsystem)
updateRequired = true
}

if updateRequired {
e.UpdateCh <- nil
}
Expand Down
2 changes: 2 additions & 0 deletions vendor/github.com/jinzhu/copier/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/jinzhu/copier/License

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 132 additions & 0 deletions vendor/github.com/jinzhu/copier/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bd9951c

Please sign in to comment.