Skip to content

Commit

Permalink
lxd/storage/backend: Handle error from lock
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Pelizäus <[email protected]>
  • Loading branch information
roosterfish committed Oct 13, 2023
1 parent 67cde03 commit c28d382
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions lxd/storage/backend_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2859,7 +2859,11 @@ func (b *lxdBackend) CreateInstanceSnapshot(inst instance.Instance, src instance

// Lock this operation to ensure that the only one snapshot is made at the time.
// Other operations will wait for this one to finish.
unlock := locking.Lock(context.TODO(), drivers.OperationLockName("CreateInstanceSnapshot", b.name, vol.Type(), contentType, src.Name()))
unlock, err := locking.Lock(context.TODO(), drivers.OperationLockName("CreateInstanceSnapshot", b.name, vol.Type(), contentType, src.Name()))
if err != nil {
return err
}

defer unlock()

err = b.driver.CreateVolumeSnapshot(vol, op)
Expand Down Expand Up @@ -3230,7 +3234,11 @@ func (b *lxdBackend) EnsureImage(fingerprint string, op *operations.Operation) e
// We need to lock this operation to ensure that the image is not being created multiple times.
// Uses a lock name of "EnsureImage_<fingerprint>" to avoid deadlocking with CreateVolume below that also
// establishes a lock on the volume type & name if it needs to mount the volume before filling.
unlock := locking.Lock(context.TODO(), drivers.OperationLockName("EnsureImage", b.name, drivers.VolumeTypeImage, "", fingerprint))
unlock, err := locking.Lock(context.TODO(), drivers.OperationLockName("EnsureImage", b.name, drivers.VolumeTypeImage, "", fingerprint))
if err != nil {
return err
}

defer unlock()

// Load image info from database.
Expand Down Expand Up @@ -3463,7 +3471,11 @@ func (b *lxdBackend) DeleteImage(fingerprint string, op *operations.Operation) e
defer l.Debug("DeleteImage finished")

// We need to lock this operation to ensure that the image is not being deleted multiple times.
unlock := locking.Lock(context.TODO(), drivers.OperationLockName("DeleteImage", b.name, drivers.VolumeTypeImage, "", fingerprint))
unlock, err := locking.Lock(context.TODO(), drivers.OperationLockName("DeleteImage", b.name, drivers.VolumeTypeImage, "", fingerprint))
if err != nil {
return err
}

defer unlock()

// Load the storage volume in order to get the volume config which is needed for some drivers.
Expand Down Expand Up @@ -3720,7 +3732,11 @@ func (b *lxdBackend) UpdateBucket(projectName string, bucketName string, bucket
if len(changedConfig) > 0 && !userOnly {
if memberSpecific {
// Stop MinIO process if running so volume can be resized if needed.
minioProc := miniod.Get(curBucketVol.Name())
minioProc, err := miniod.Get(curBucketVol.Name())
if err != nil {
return err
}

if minioProc != nil {
err = minioProc.Stop(context.Background())
if err != nil {
Expand Down Expand Up @@ -3783,7 +3799,11 @@ func (b *lxdBackend) DeleteBucket(projectName string, bucketName string, op *ope
// Handle common MinIO implementation for local storage drivers.

// Stop MinIO process if running.
minioProc := miniod.Get(bucketVolName)
minioProc, err := miniod.Get(bucketVolName)
if err != nil {
return err
}

if minioProc != nil {
err = minioProc.Stop(context.Background())
if err != nil {
Expand All @@ -3792,7 +3812,7 @@ func (b *lxdBackend) DeleteBucket(projectName string, bucketName string, op *ope
}

vol := b.GetVolume(drivers.VolumeTypeBucket, drivers.ContentTypeFS, bucketVolName, nil)
err := b.driver.DeleteVolume(vol, op)
err = b.driver.DeleteVolume(vol, op)
if err != nil {
return err
}
Expand Down Expand Up @@ -5558,7 +5578,11 @@ func (b *lxdBackend) CreateCustomVolumeSnapshot(projectName, volName string, new

// Lock this operation to ensure that the only one snapshot is made at the time.
// Other operations will wait for this one to finish.
unlock := locking.Lock(context.TODO(), drivers.OperationLockName("CreateCustomVolumeSnapshot", b.name, vol.Type(), contentType, volName))
unlock, err := locking.Lock(context.TODO(), drivers.OperationLockName("CreateCustomVolumeSnapshot", b.name, vol.Type(), contentType, volName))
if err != nil {
return err
}

defer unlock()

// Create the snapshot on the storage device.
Expand Down

0 comments on commit c28d382

Please sign in to comment.