From: John Griffith Date: Wed, 23 Jan 2013 04:15:40 +0000 (+0000) Subject: Get updated vol status in volume.api.reserve. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2c84413c74e6481abe4af716ea12d8c75b405c25;p=openstack-build%2Fcinder-build.git Get updated vol status in volume.api.reserve. A race condtion was discovered where a nova volume attach could easily be performed twice for the same volume. Although the cinder attach update would fail, this occured after the BDM updates were made and in essence the attach to the compute instance had already been issued. This change simply forces a get from the DB of the volume-ref in the reserve call and checks if an attach is already in progress. Fixes bug: 1096983 Change-Id: Ie0e4156d691ee92b6981078ef0ba62f8c4cdf0c8 --- diff --git a/cinder/volume/api.py b/cinder/volume/api.py index e17ec141f..b5bb98c7e 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -416,7 +416,15 @@ class API(base.Base): @wrap_check_policy def reserve_volume(self, context, volume): - self.update(context, volume, {"status": "attaching"}) + #NOTE(jdg): check for Race condition bug 1096983 + #explicitly get updated ref and check + volume = self.db.volume_get(context, volume['id']) + if volume['status'] == 'available': + self.update(context, volume, {"status": "attaching"}) + else: + msg = _("Volume status must be available to reserve") + LOG.error(msg) + raise exception.InvalidVolume(reason=msg) @wrap_check_policy def unreserve_volume(self, context, volume):