Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #566 from ganeshmaharaj/bp-1.6.5
Browse files Browse the repository at this point in the history
mount: Add a proper rollback path to addStorages()
  • Loading branch information
Eric Ernst authored Jun 4, 2019
2 parents 768809f + d52195f commit 9b19138
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,28 @@ func mountStorage(storage pb.Storage) error {
// associated operations such as waiting for the device to show up, and mount
// it to a specific location, according to the type of handler chosen, and for
// each storage.
func addStorages(ctx context.Context, storages []*pb.Storage, s *sandbox) ([]string, error) {
func addStorages(ctx context.Context, storages []*pb.Storage, s *sandbox) (mounts []string, err error) {
span, ctx := trace(ctx, "mount", "addStorages")
span.SetTag("sandbox", s.id)
defer span.Finish()

var mountList []string
var storageList []string

defer func() {
if err != nil {
s.Lock()
for _, path := range storageList {
if err := s.unsetAndRemoveSandboxStorage(path); err != nil {
agentLog.WithFields(logrus.Fields{
"error": err,
"path": path,
}).Error("failed to roll back addStorages")
}
}
s.Unlock()
}
}()

for _, storage := range storages {
if storage == nil {
Expand All @@ -304,6 +320,10 @@ func addStorages(ctx context.Context, storages []*pb.Storage, s *sandbox) ([]str
mountPoint, err := devHandler(*storage, s)
handlerSpan.Finish()

if _, ok := s.storages[storage.MountPoint]; ok {
storageList = append([]string{storage.MountPoint}, storageList...)
}

if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9b19138

Please sign in to comment.