[stgt] tgt-setup-lun concurrency problem
FUJITA Tomonori
fujita.tomonori at lab.ntt.co.jp
Tue Jul 24 00:36:03 CEST 2012
On Mon, 23 Jul 2012 13:13:31 +0200
Mark Gergely <gergely.mark at sztaki.mta.hu> wrote:
> Dear Developers,
>
> we have found a problem with the tgt-setup-lun script, if you have to create 50+ targets concurrently, then the script will fail because the tgtd reports "target already exists" errors. This happens because the queried target id becomes outdated while the script runs. Please check the attached patch for a possible workaround and feel free to use it if you like it
Thanks for the report.
What's the root cause of the problem?
Anyone (who uses this script) has opinions on this?
>> Signed-off-by: Mark Gergely <mgergely at sztaki.hu>
>>
>> diff --git a/scripts/tgt-setup-lun b/scripts/tgt-setup-lun
>> index 14a5f0a..24125cd 100755
>> --- a/scripts/tgt-setup-lun
>> +++ b/scripts/tgt-setup-lun
>> @@ -82,7 +82,7 @@ find_vacant_lun()
>> tid=$1
>> tgt_found=0
>> next_vacant_lun=0
>> - tmp_file=/tmp/target_list.txt
>> + tmp_file=`mktemp`
>>
>> tgtadm --lld $lld_name --op show --mode target > $tmp_file
>>
>> @@ -204,14 +204,27 @@ if [ $? -eq 1 ]; then
>> tid=${tid%:}
>> new_tgt=0
>> else
>> - find_vacant_tgt_id
>> - tid=$?
>> -
>> - # Create the new target
>> - echo "Creating new target (name=$tgt_name, tid=$tid)"
>> - tgtadm --lld $lld_name --op new --mode target --tid $tid -T $tgt_name
>> - res=$?
>>
>> + i=0
>> + while [ true ]
>> + do
>> + let i=i+1
>> + find_vacant_tgt_id
>> + tid=$?
>> + # Create the new target
>> + echo "Creating new target (name=$tgt_name, tid=$tid)"
>> + tgtoutput=`tgtadm --lld $lld_name --op new --mode target --tid $tid -T $tgt_name 2>&1`
>> + res=$?
>> + if [ "$tgtoutput" == "tgtadm: this target already exists" ]; then
>> + echo "Target already exists (this should not happen)... Attempt $i"
>> + elif [ $res -eq 0 ]; then # output is not about duplication and return value is zero, this is the normal condition
>> + break
>> + fi
>> + if [ $i -eq 10 ]; then
>> + echo "Too many attempts, giving up"
>> + break
>> + fi
>> + done
>> if [ $res -ne 0 ]; then
>> echo "Error: failed to create target (name=$tgt_name, tid=$tid)"
>> exit 1
>
>
> All the best,
> Mark Gergely
> MTA-SZTAKI
>
> --
> To unsubscribe from this list: send the line "unsubscribe stgt" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list