WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] locking mechanism in hotplug scripts not working

To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] locking mechanism in hotplug scripts not working
From: Marek Marczykowski <marmarek@xxxxxxxxxxxx>
Date: Wed, 06 Jul 2011 20:57:42 +0200
Delivery-date: Wed, 06 Jul 2011 12:02:16 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b3pre Thunderbird/3.1.10
Hello,

I've found that locking isn't working as it should... It allows many
processes to claim lock simultaneously:

Full _claim_lock and description of race:
 48 _claim_lock()
 49 {
 50   local lockdir="$1"
 51   local owner=$(_lock_owner "$lockdir")
 52   local retries=0
 53
 54   while [ $retries -lt $LOCK_RETRIES ]
 55   do
 56     mkdir "$lockdir" 2>/dev/null && trap "_release_lock $lockdir;
sigerr" ERR &&
 57       _update_lock_info "$lockdir" && return
 58
 59     local new_owner=$(_lock_owner "$lockdir")
 60     if [ "$new_owner" != "$owner" ]
 61     then
 62       owner="$new_owner"
 63       retries=0
 64     else
 65       local pid=$(echo $owner | cut -d : -f 1)
 66       if [ -n "$pid" -a "$pid" != "unknown" -a ! -f
"/proc/$pid/status" ]
 67       then
 68         _release_lock $lockdir
 69       fi
 70     fi
 71
 72     if [ $retries -gt $LOCK_SPINNING_RETRIES ]
 73     then
 74       sleep $LOCK_SLEEPTIME
 75     else
 76       sleep 0
 77     fi
 78     retries=$(($retries + 1))
 79   done
 80   _steal_lock "$lockdir"
 81 }


The race is:
P1: claim_lock - success
P2: claim_lock - read lock owner ("owner" file in lock dir) - l51
P1: done things and release_lock
P1: exit
P3: claim_lock - success
P2: notice that P1 is dead (read previously) -> release_lock l68 (!!!)
P2: claim_lock l56 - success

Both P2 and P3 in critical section

I don't have idea how to fix it in current shape. Some workaround is to
remove lines 64-69... Perhaps proper fix is to use flock(1) utility, but
this will may be less portable...

-- 
Pozdrawiam / Best Regards,
Marek Marczykowski         | RLU #390519
marmarek at mimuw edu pl   | xmpp:marmarek at staszic waw pl

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>