Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #854 from rbradford/fix-volume-status
Browse files Browse the repository at this point in the history
Ensure volumes are marked as in-use
  • Loading branch information
markdryan authored Nov 24, 2016
2 parents 2112270 + d44c862 commit 480a803
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions ciao-controller/internal/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1503,15 +1503,32 @@ func (ds *Datastore) CreateStorageAttachment(instanceID string, blockID string,
Ephemeral: ephemeral,
}

err := ds.db.createStorageAttachment(a)
if err != nil {
return types.StorageAttachment{}, fmt.Errorf("error creating storage attachment: %v", err)
}

// ensure that the volume is marked in use as we have created an attachment
bd, err := ds.GetBlockDevice(blockID)
if err != nil {
ds.db.deleteStorageAttachment(a.ID)
return types.StorageAttachment{}, fmt.Errorf("error creating storage attachment: %v", err)
}

bd.State = types.InUse
err = ds.UpdateBlockDevice(bd)
if err != nil {
ds.db.deleteStorageAttachment(a.ID)
return types.StorageAttachment{}, fmt.Errorf("error creating storage attachment: %v", err)
}

// add it to our links map
ds.attachLock.Lock()
ds.attachments[a.ID] = a
ds.instanceVolumes[link] = a.ID
ds.attachLock.Unlock()

err := ds.db.createStorageAttachment(a)

return a, err
return a, nil
}

// GetStorageAttachments returns a list of volumes associated with this instance.
Expand Down

0 comments on commit 480a803

Please sign in to comment.