linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <ijackson@chiark.greenend.org.uk>
To: linux-kernel@vger.kernel.org
Subject: rename("a","b") succeeds multiple times race
Date: Thu, 24 Apr 2003 12:57:07 +0100	[thread overview]
Message-ID: <16039.53523.533498.354359@chiark.greenend.org.uk> (raw)

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.

             reply	other threads:[~2003-04-24 11:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-24 11:57 Ian Jackson [this message]
2003-04-24 14:30 ` rename("a","b") succeeds multiple times race Chris Sykes
2003-04-24 16:46   ` Ian Jackson
2003-04-24 21:34   ` Jamie Lokier
2003-04-24 21:54     ` viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16039.53523.533498.354359@chiark.greenend.org.uk \
    --to=ijackson@chiark.greenend.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).