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/
Home Products Support Community News


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

To: Marek Marczykowski <marmarek@xxxxxxxxxxxx>
Subject: Re: [Xen-devel] locking mechanism in hotplug scripts not working
From: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
Date: Thu, 7 Jul 2011 09:16:05 +0100
Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Thu, 07 Jul 2011 01:16:51 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <4E14B026.90107@xxxxxxxxxxxx>
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>
Organization: Citrix Systems, Inc.
References: <4E14B026.90107@xxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
On Wed, 2011-07-06 at 19:57 +0100, Marek Marczykowski wrote:
> Hello,
> I've found that locking isn't working as it should... It allows many
> processes to claim lock simultaneously:
> 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

Urk, yes, I think you are correct about this.

> I don't have idea how to fix it in current shape.

Me neither.

> Some workaround is to remove lines 64-69... 

I don't think that would be all that bad. It seems like this is trying
to handle the case where a script exits without unlocking but we have a
trap on exit handler for that.

If the trap handler isn't working then either (a) the hotplug script has
added another trap handler during the critical section overwriting this
one IMHO this is buggy if it doesn't also release the lock or (b) there
is a bug of some sort in the shell implementation itself. We should fix
cases of (a) and ignore cases of (b) since it indicates a more
fundamental problem is at work.

> Perhaps proper fix is to use flock(1) utility, but
> this will may be less portable...

The scripts in question live under tools/hotplug/Linux, which suggests
they are at least somewhat Linux specific, where I think it is
reasonable to rely on flock(1) being available (it comes from util-linux
which is widespread in the Linux world).

Looking at flock(1) it seems that using it would involve quite a bit of
restructuring of the callers (since we'd likely be using the 3rd form
shown in the manpage).


Xen-devel mailing list

<Prev in Thread] Current Thread [Next in Thread>