linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* rename("a","b") succeeds multiple times race
@ 2003-04-24 11:57 Ian Jackson
  2003-04-24 14:30 ` Chris Sykes
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Jackson @ 2003-04-24 11:57 UTC (permalink / raw)
  To: linux-kernel

I'm running 2.2.25 on a dual PIII; I have a program that processes
mail messages which are left in a queue directory as uniquely named
files.  The queue runners each `claim' a message by renaming it away
from the initial filename, so that only one queue runner works on each
message.

However, this does not work because Linux erroneously allows several
processes to simultaneously and `successfully' rename the same file.
The filesystem in question is ext2.

I ran the system under strace, and saw (for example) the following, in
five straces of five different processes:

 02:11:47.293131 rename("q1988na-000xqY", "proc.1988na-000xqY") = 0
 02:11:47.354497 rename("q1988na-000xqY", "proc.1988na-000xqY") = 0
 02:11:47.412207 rename("q1988na-000xqY", "proc.1988na-000xqY") = 0
 02:11:47.414376 rename("q1988na-000xqY", "proc.1988na-000xqY") = 0
 02:11:47.414559 rename("q1988na-000xqY", "proc.1988na-000xqY") = 0

The q... filename was created by Exim 3.35, which did this (for
another message; I can't run the whole of the mail system under
strace):

open("/var/lib/news/mail2news2//temp.2223.chiark.greenend.org.uk", O_WRONLY|O_CREAT, 0660) = 6
[ fiddles with permissions of the file, writes data ]
stat("/var/lib/news/mail2news2//temp.2223.chiark.greenend.org.uk", {st_dev=makedev(8, 2), st_ino=201893, st_mode=S_IFREG|066
0, st_nlink=1, st_uid=9, st_gid=9, st_blksize=4096, st_blocks=0, st_size=0, st_atime=2003/04/23-11:32:14, st_mtime=2003/04/2
3-11:32:14, st_ctime=2003/04/23-11:32:14}) = 0
[...]
close(6)                                = 0
rename("/var/lib/news/mail2news2//temp.2223.chiark.greenend.org.uk", "/var/lib/news/mail2news2//q198HXy-000qWL") = 0

The q... filename is constructed by base-62-encoding the time and the
inode number.

So my questions are:

* Is this a known bug ?  Is it fixed in 2.4 ?

* I can perhaps work around it by having the queue runner rename the
  file to a name which also depends on its own pid, and then check
  that that file exists.  (This will come naturally because it only
  opens the file after renaming it.)  Will this work ?  Will it trash
  my filesystem or my kernel data structures ?

chiark:~> uname -av
Linux chiark 2.2.25 #2 SMP Wed Apr 23 13:05:23 BST 2003 i686 unknown
chiark:~> cat /proc/version
Linux version 2.2.25 (ian@chiark) (gcc version 2.7.2.3) #2 SMP Wed Apr 23 13:05:23 BST 2003
chiark:~>

My kernel is a stock 2.2.25 with patches to:
 * increase NR_TASKS to 2048
 * #define DEBUG 1 in st.c

The distribution is Debian woody; the queue runner software is my own,
written in Perl.

Ian.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-04-24 21:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-24 11:57 rename("a","b") succeeds multiple times race Ian Jackson
2003-04-24 14:30 ` Chris Sykes
2003-04-24 16:46   ` Ian Jackson
2003-04-24 21:34   ` Jamie Lokier
2003-04-24 21:54     ` viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).