[OpenAFS] AFS Locking
Pucky Loucks
ploucks@pixpo.com
Thu, 18 May 2006 09:44:53 -0700
--Apple-Mail-1-12285361
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=WINDOWS-1252;
delsp=yes;
format=flowed
I=92m trying to write a C++ program that will run on multiple Linux =20
machines, and each machine will need to read and write files on an =20
AFS volume. So that two machines don=92t try to write to the same file =20=
at the same time, I would like to use file-level advisory locking, =20
using the flock() system call. I have read that AFS supports locking =20
entire files in this manner.
Using two machines running OpenAFS 1.4 on a Linux 2.4 kernel (White =20
Box distribution), this technique works. One machine acquires a lock =20
with flock(), and the other machine returns EWOULDBLOCK from flock() =20
until the first machine releases the lock.
Using two machines running OpenAFS 1.4 on a Linux 2.6 kernel (CentOS =20
4 distribution), the same code fails. Flock() always returns 0 (lock =20
acquired) even if another machine should already have the lock.
With two 2.4 machines and one 2.6 machine, the locking works across =20
the 2.4 machines, and the 2.6 machine always claims to acquire the =20
lock (based on the return from flock()), but it=92s not actually locked =20=
according to the 2.4 machines. As you can guess, I need to use a 2.6 =20
kernel, to take advantage of some of its other features.
Are there any known issues with file locking with flock(), and if so, =20=
a preferred way to synchronize file accesses? Are there some =20
configuration settings with either my AFS volume or my Linux systems =20
that I should check?
Cheers,
Pucky
--Apple-Mail-1-12285361
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=WINDOWS-1252
<HTML><BODY style=3D"word-wrap: break-word; -khtml-nbsp-mode: space; =
-khtml-line-break: after-white-space; "><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT =
class=3D"Apple-style-span" face=3D"Arial" size=3D"4"><SPAN =
class=3D"Apple-style-span" style=3D"font-size: 13.3px;">I=92m trying to =
write a C++ program that will run on multiple Linux machines, and each =
machine will need to read and write files on an AFS volume. So that two =
machines don=92t try to write to the same file at the same time, I would =
like to use file-level advisory locking, using the flock() system call. =
I have read that AFS supports locking entire files in this =
manner.</SPAN></FONT></DIV><P style=3D"margin: 0.0px 0.0px 0.0px =
0.0px"><FONT class=3D"Apple-style-span" face=3D"Arial" size=3D"4"><SPAN =
class=3D"Apple-style-span" style=3D"font-size: =
13.3px;">=A0</SPAN></FONT></P><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT =
class=3D"Apple-style-span" face=3D"Arial" size=3D"4"><SPAN =
class=3D"Apple-style-span" style=3D"font-size: 13.3px;">Using two =
machines running OpenAFS 1.4 on a Linux 2.4 kernel (White Box =
distribution), this technique works. One machine acquires a lock with =
flock(), and the other machine returns EWOULDBLOCK from flock() until =
the first machine releases the lock.</SPAN></FONT></DIV><P =
style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT class=3D"Apple-style-span"=
face=3D"Arial" size=3D"4"><SPAN class=3D"Apple-style-span" =
style=3D"font-size: 13.3px;">=A0</SPAN></FONT></P><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; "><FONT class=3D"Apple-style-span" face=3D"Arial" =
size=3D"4"><SPAN class=3D"Apple-style-span" style=3D"font-size: =
13.3px;">Using two machines running OpenAFS 1.4 on a Linux 2.6 kernel =
(CentOS 4 distribution), the same code fails. Flock() always returns 0 =
(lock acquired) even if another machine should already have the =
lock.</SPAN></FONT></DIV><P style=3D"margin: 0.0px 0.0px 0.0px =
0.0px"><FONT class=3D"Apple-style-span" face=3D"Arial" size=3D"4"><SPAN =
class=3D"Apple-style-span" style=3D"font-size: =
13.3px;">=A0</SPAN></FONT></P><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT =
class=3D"Apple-style-span" face=3D"Arial" size=3D"4"><SPAN =
class=3D"Apple-style-span" style=3D"font-size: 13.3px;">With two 2.4 =
machines and one 2.6 machine, the locking works across the 2.4 machines, =
and the 2.6 machine always claims to acquire the lock (based on the =
return from flock()), but it=92s not actually locked according to the =
2.4 machines. As you can guess, I need to use a 2.6 kernel, to take =
advantage of some of its other features.</SPAN></FONT></DIV><P =
style=3D"margin: 0.0px 0.0px 0.0px 0.0px"><FONT class=3D"Apple-style-span"=
face=3D"Arial" size=3D"4"><SPAN class=3D"Apple-style-span" =
style=3D"font-size: 13.3px;">=A0</SPAN></FONT></P><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; "><FONT class=3D"Apple-style-span" face=3D"Arial" =
size=3D"4"><SPAN class=3D"Apple-style-span" style=3D"font-size: =
13.3px;">Are there any known issues with file locking with flock(), and =
if so, a preferred way to synchronize file accesses? Are there some =
configuration settings with either my AFS volume or my Linux systems =
that I should check?</SPAN></FONT></DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT =
class=3D"Apple-style-span" face=3D"Arial" size=3D"4"><SPAN =
class=3D"Apple-style-span" style=3D"font-size: 13.3px;"><BR =
class=3D"khtml-block-placeholder"></SPAN></FONT></DIV><DIV =
style=3D"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; =
margin-left: 0px; "><FONT class=3D"Apple-style-span" face=3D"Arial" =
size=3D"4"><SPAN class=3D"Apple-style-span" style=3D"font-size: =
13.3px;">Cheers,</SPAN></FONT></DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><FONT =
class=3D"Apple-style-span" face=3D"Arial" size=3D"4"><SPAN =
class=3D"Apple-style-span" style=3D"font-size: =
13.3px;">Pucky</SPAN></FONT></DIV><DIV style=3D"margin-top: 0px; =
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><BR =
class=3D"khtml-block-placeholder"></DIV></BODY></HTML>=
--Apple-Mail-1-12285361--