Unnecessary bdm entry is created if same volume is attached twice to an instance
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Compute (nova) |
Invalid
|
Medium
|
Unassigned |
Bug Description
When we try to attach an already attached volume to an instance it raises InvalidVolume exception but creates an entry in block_device_
Steps to reproduce:
1. Created an instance named test_vm_1.
2. Created a volume named test_volume_1.
3. Verified that instance is in active state and volume is in available state.
4. Attach volume using below command:
$ nova volume-attach <instance_id> <volume_id>.
5. Confirmed that volume is in 'in-use' status using below command:
$ cinder list.
6. Execute volume-attach command again with same volume_id.
$ nova volume-attach <instance_id> <volume_id>.
After executing step 6 it raises "Invalid volume" exception and attached volume can be used normally which is correct. But when you check block_device_
select * from block_device_
Changed in nova: | |
importance: | Undecided → Low |
tags: |
added: volumes removed: ntt |
Changed in nova: | |
assignee: | jichenjc (jichenjc) → nobody |
status: | In Progress → Confirmed |
Changed in nova: | |
assignee: | Nikola Đipanov (ndipanov) → Lee Yarwood (lyarwood) |
Changed in nova: | |
assignee: | Lee Yarwood (lyarwood) → Rikimaru Honjo (honjo-rikimaru-c6) |
Changed in nova: | |
assignee: | Rikimaru Honjo (honjo-rikimaru-c6) → Vishakha Agarwal (vishakha.agarwal) |
If we take a look at following code, line 3023,3024 can be moved to previous line before reserve bdm
because it's only a status check , I will try to submit a patch and see whether they are some traps of
concurrency issue there
3007 def _attach_ volume( self, context, instance, volume_id, device, rpcapi. reserve_ block_device_ name( type=device_ type) api.get( context, volume_id) api.check_ attach( context, volume, instance=instance) api.reserve_ volume( context, volume_id) rpcapi. attach_ volume( context, instance=instance, id=volume_ id, mountpoint=device, bdm=volume_bdm) save_and_ reraise_ exception( ): bdm.destroy( )
3008 disk_bus, device_type):
3009 """Attach an existing volume to an existing instance.
3010
3011 This method is separated to make it possible for cells version
3012 to override it.
3013 """
3014 # NOTE(vish): This is done on the compute host because we want
3015 # to avoid a race where two devices are requested at
3016 # the same time. When db access is removed from
3017 # compute, the bdm will be created here and we will
3018 # have to make sure that they are assigned atomically.
3019 volume_bdm = self.compute_
3020 context, instance, device, volume_id, disk_bus=disk_bus,
3021 device_
3022 try:
3023 volume = self.volume_
3024 self.volume_
3025 self.volume_
3026 self.compute_
3027 volume_
3028 except Exception:
3029 with excutils.
3030 volume_
3031