On Mon, 23 Jul 2012 13:13:31 +0200 Mark Gergely <gergely.mark@xxxxxxxxxxxxx> 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@xxxxxxxxx> >> >> 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@xxxxxxxxxxxxxxx > 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@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html