Search

Enter a search word or two and press return to see the search results.

Who am I?

Hi, I’m Graeme and these are my notes, from my messy desk. I started this blog because Google proved to be more useful at finding content than anything else I’ve used.

So I started adding my own content in the hopes that Google would index it and allow me to find things again in the future.

It works.

You can find out more about me here, and you should follow me on Twitter here.

Keeping up

You can automatically receive new content here by subscribing to the “Blog RSS” (link below). This is the easiest way to keep up with what I write here.  See this BBC article for a good introduction on RSS and keeping up with the goings on of the Internet more easily.

« When CSS Goes Wrong! | Main | Indexing and searching »
Thursday
25Aug2005

Subversion and NFS file locking

I should prefix this with a warning: I know next to nothing about file locking and the implications of what I've just done. However, it now appears to work, and I'm not too worried about simultaneous access to my subversion repository since I'm the only one that uses it. (Even the web interface is currently running from a read-only mirror of the repository.)

Since DreamHost have upgraded my shell machine to Sarge, my subversion repository has stopped working. Which is not entirely unexpected, since one of the libraries the svn binary dynamically linked to (libgdbm) had shifted its SO_NAME from 1 to 3 in the upgrade. OK, so a rebuild was done and the binaries were working. Except for one major problem:

[code]mathie@Tandoori:mathie$ svn up
svn: Error opening db lockfile
svn: Can't get shared lock on file '/home/mathie/svnroot/locks/db.lock': No locks available[/code]

It couldn't successfully lock the repository. Now my subversion repository uses the fs_fs backend (rather than Berkeley DB), and it's on an NFS mount. It would appear that file locking isn't working over NFS in this particular situation. Looking at apr/file_io/unix/flock.c, I see there's code to use either fcntl() or flock() to do the locking, but given the choice, it'll use fcntl(). So I tried out a wee test: readlock.c This attempts to create a read lock on a file using both methods. Both methods work fine on a local filesystem with my laptop (Mac OS X 10.4) and on the shell server (Debian GNU/Linux 3.1). However the fcntl() method fails on the latter machine when it's on an NFS mount. flock() does work. Yee ha. Solution? Edit apr/include/arch/unix/apr_private.h and comment out the line that reads:

[code]#define HAVE_FCNTL_H 1[/code]

Rebuild apr with a make clean && make && make install and your copy of subversion now 'works' (as in doesn't fail in the obvious way!) on an NFS-mounted filesystem.

Your job is to tell me how much I risk screwing up my repository having made this change...

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (10)

Kai: Obviously I don't speak for DreamHost. However, the only real fix is to arrange for the repositories to be on a local file system, which I suspect doesn't really fit in well with DH's network architecture (at a guess, most of the home directory storage is going to be sitting on NetApp servers?). So it could be a while.

Go vote for everything subversion related in the suggestions page on the control panel, just to let them know that we'd really like proper subversion hosting support. (Including all the bells and whistles -- anonymous http access, trac as a repository front end, that kind of thing!)

October 19, 2005 | Unregistered Commentermathie

I don't see DH moving away from NFS. I don't have time to wait. Isn't there a work around?

I've hosted my repo with fsfs on NFS without these issues. :/

October 20, 2005 | Unregistered CommenterKai Hendry

I'm not sure if this is helpful or not, and the Linux here is Redhat, but a quick man on flock mentions (at the bottom)

"flock(2) does not lock files over nfs. Use fcntl(2) instead: that does work over nsf, ..."

I am actually using a call to lockf(3) which end up (aledgedly) calling fcntl(2).

Take a look and good luck.

-craig

November 15, 2005 | Unregistered CommenterCraig Campbell

I solved this problem with changing the nfs mount option.
When the "svn: Unable to open an ra_local session to URL
svn: Unable to open repository ‘path/to/repo’
svn: Error opening db lockfile
svn: Can’t get shared lock on file ‘path/to/repo’: No locks available" message occured, I changed the NFS mount option from default to "hard,intr,bg,nolock,rw" and remount the nfs directory to my local mount point.

I sugget you apply this solution to your systems.

February 15, 2006 | Unregistered CommenterByung-chul Lee

I agree that Byung-chul Lee's solution does work.

Subversion 1.2.1 running on a Fedora Core 3 server accessed from Ubuntu 5.10 Breezy Badger workstation with eSVN 0.6.8 and svn command-line client version 1.2.0.

February 19, 2006 | Unregistered CommenterChameleon

wow, many thanks - Byung-chul Lee. It is a simple, elegant solution -- certainly saved a lot of head pounding! thanks again.

July 24, 2007 | Unregistered CommenterJramak

Thanks for the NFS mount option solution. Suddenly, I could no longer access repositories or create new ones across drives (but could still create locally). Your solution saved the day.

May 9, 2008 | Unregistered CommenterGDK

I am probably doing something wrong, but at our work we run the SVN server off a Windows Server machine (The best hardware for the job at the time), but I get that same error when I try to commit files when I work from a Mac. When I work from a PC I get no errors, only the Mac throws the "Can't get exclusive ock" error. Any suggestions?

(I wish Byung-chul Lee's suggestion applied to me, but I don't think it does)

May 20, 2008 | Unregistered CommenterNicolas

I have the same issue than Nicolas. I recently bought a MacBook Air, and now develop PHP on it. I tried to use Eclipse with the PHP and SVN plugins and the SCPlugin which is the equivalent of the Tortoise SVN for Mac OS.
In both cases I have the "Can't get exclusive lock" error when trying to commit.
Some suggestion?

May 27, 2008 | Unregistered CommenterCedric

Just a pointer. The "nolock" option turns off file locking via NFS, so make sure you're not using the repository in a multitasking situation (running it via apache, will do just that... especially if more than one person wishes to write to the repository at the same time...)

/E

April 14, 2009 | Unregistered CommenterErik

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>