The workflow of tgt-admin is:
1. get the available tid(usually it is the current max tid plus 1),I named it next_tid ;
2. use the next_tid to create a target:
tgtadm -C 0 --lld iscsi --op new --mode target --tid next_tid -T target_name
But there is a race condition between step 1 and step 2. If multiple tgt-admin commands executed simultaneous in the same node, some of them have the chance to get the same next_tid, and then use the same tid to create target, this will cause the error of 'tgtadm: this target already exists'.
I think the best way to solve this problem is to add a lock when create a tgt target.
The current code will retry if it encounters the error, but this is a work-around, not the root cause.
Current code of tgt.py use command 'tgt-admin --update name' to create the iscsi target of tgt: /github. com/openstack/ cinder/ blob/master/ cinder/ volume/ targets/ tgt.py# L119
https:/
The workflow of tgt-admin is:
1. get the available tid(usually it is the current max tid plus 1),I named it next_tid ;
2. use the next_tid to create a target:
tgtadm -C 0 --lld iscsi --op new --mode target --tid next_tid -T target_name
Here is the source code of tgt-admin: /github. com/fujita/ tgt/blob/ master/ scripts/ tgt-admin# L278
https:/
But there is a race condition between step 1 and step 2. If multiple tgt-admin commands executed simultaneous in the same node, some of them have the chance to get the same next_tid, and then use the same tid to create target, this will cause the error of 'tgtadm: this target already exists'.
I think the best way to solve this problem is to add a lock when create a tgt target.