[OpenAFS-devel] flock Input/output error

Hans-Werner Paulsen hans@MPA-Garching.MPG.DE
Thu, 12 Aug 2010 15:43:33 +0200


On Wed, Aug 11, 2010 at 11:34:53PM +0100, Simon Wilkinson wrote:
> I'm still interesting in the error code you're seeing, but on further a=
nalysis, I think I've identified two problems. They're both related to ra=
ce conditions in the way that we enrol AFS locks with the kernel's local =
lock management system (we do this so that the kernel can handle byte-ran=
ge locks on the local machine for us).
>=20
> The first is that locks and unlocks can race against each other. On a l=
ock we do SetAFSLock, SetKernelLock. On unlock we do ReleaseAFSLock, Rele=
aseKernelLock. However, we don't hold any locks on the file whilst we do =
so. Multiple calls to set a lock are safe, as the SetAFSLock serialises t=
hem. However, a lock and an unlock may race each other. In this case we h=
ave
>=20
> Process A                 Process B
> SetAFSLock
> SetKernelLock
> ....
> ReleaseAFSLock
> 			  SetAFSLock
> 			  SetKernelLock
> ReleaseKernelLock
>=20
> Process B can't get the kernel lock, despite the fact that it has the A=
FS lock, because process A hasn't released it yet. So you get an error me=
ssage.

Isn't possible to do ReleaseKernelLock first, and then ReleaseAFSLock on
unlock?

HW

--=20
Hans-Werner Paulsen		hans@MPA-Garching.MPG.DE
MPI f=FCr Astrophysik		Tel 089-30000-2602
Karl-Schwarzschild-Str. 1	Fax 089-30000-2235=09
D-85741 Garching