Skip to content

Commit 4246683

Browse files
authored
lxd/instance: Lock image access (from Incus) (#14546)
Cherry-picked from lxc/incus#1408 and tested with script from #12581 Closes #12581
2 parents 1581f5e + e05839a commit 4246683

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lxd/instance.go

+9
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ func instanceCreateFromImage(s *state.State, img *api.Image, args db.InstanceArg
179179
return fmt.Errorf("Failed loading instance storage pool: %w", err)
180180
}
181181

182+
// Lock this operation to ensure that concurrent image operations don't conflict.
183+
// Other operations will wait for this one to finish.
184+
unlock, err := imageOperationLock(img.Fingerprint)
185+
if err != nil {
186+
return err
187+
}
188+
189+
defer unlock()
190+
182191
err = pool.CreateInstanceFromImage(inst, img.Fingerprint, op)
183192
if err != nil {
184193
return fmt.Errorf("Failed creating instance from image: %w", err)

0 commit comments

Comments
 (0)