lxd/instance: Fix image download race condition in instanceCreateFromImage
lxd/instance: Fix image download race condition in instanceCreateFromImage

If multiple instances were launched on the same cluster member, using the same image, at the same time,
then it was possible for both to come to the conclusion that the image required didn't exist locally
and start the process of downloading it to the local member.

Unfortunately the lock that ensures this process doesn't happen concurrently was being taken too later,
when really we needed to ensure that the 2nd instance waited until the 1st instance has finished downloading
the image and adding it the local member's DB record before checking whether it is available.

Fixes #9326

Signed-off-by: Thomas Parrott <6b778ce645fb0e3dde76d79eccad490955b1ae74@canonical.com>

lxc/lxd,lxc/lxd,lxc/lxd,stgraber/lxd,stgraber/lxd,hallyn/lxd,stgraber/lxd,lxc/lxd,hallyn/lxd,lxc/lxd,stgraber/lxd,stgraber/lxd,hallyn/lxd,lxc/lxd,hallyn/lxd,stgraber/lxd,lxc/lxd,hallyn/lxd,hallyn/lxd,stgraber/lxd