linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ftp.linux.org.uk>
To: Christoph Hellwig <hch@lst.de>,
	akpm@osdl.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] coda: file count cannot be used to discover last close
Date: Fri, 20 Jul 2007 06:38:07 +0100	[thread overview]
Message-ID: <20070720053807.GD21668@ftp.linux.org.uk> (raw)
In-Reply-To: <20070720040959.GK8857@delft.aura.cs.cmu.edu>

On Fri, Jul 20, 2007 at 12:10:00AM -0400, Jan Harkes wrote:
> I will try to find a clean way to block the close syscall until fput
> drops the last reference. However I realize that such an implementation
> would not be acceptable for other file systems, and there are some
> interesting unresolved details such as 'which close is going to be the
> last close'.

Simply impossible.

	fd = open(...);
	fd2 = dup(fd);
	....
	close(fd2);  <-- deadlock
	close(fd);

Or
	fd = open(...);
	p = mmap(..., fd, ...);
	close(fd);  <-- deadlock
	...
	munmap(p, ...);

The problem is that you are mixing two different operations:
	* closing descriptor: descriptor doesn't refer to this opened file
anymore.  Can be done by close(), can be done by dup2(), can be done by
fcntl() analog of dup2(), can be done by execve(), can be done by exit().
And can be done by death-by-signal.
	* closing opened file: no references (including descriptors) exist
anymore, no IO of any kind will be done on that IO channel.  Can happen
when descriptor gets closed, can happen when mapping gets destroyed (munmap,
etc.), can happen when SCM_RIGHTS datagram gets destroyed (including the
garbage collection), can happen when any syscall on that file finishes
after another thread has closed descriptor passed to that syscall, etc.

	You _can't_ expect the errors from the latter to be reliably
passed to some process; for one thing, many files can get closed by
single system call (e.g. closing an AF_UNIX socket with pending SCM_RIGHTS
datagrams will flush those datagrams, dropping references to files we
tried to pass via them).

	Why does CODA need special warranties in that area, anyway?
Related question: does fsync() force the writeback?

  reply	other threads:[~2007-07-20  5:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-19 21:45 [PATCH] coda: kill file_count abuse Christoph Hellwig
2007-07-19 22:16 ` Jan Harkes
2007-07-20  0:45   ` David Chinner
2007-07-20  0:53     ` Al Viro
2007-07-20  2:36       ` David Chinner
2007-07-20  3:16         ` Al Viro
2007-07-20  4:10           ` [PATCH] coda: file count cannot be used to discover last close Jan Harkes
2007-07-20  5:38             ` Al Viro [this message]
2007-07-20 14:26               ` Jan Harkes
2007-07-20  6:03           ` [PATCH] coda: kill file_count abuse David Chinner
2007-07-20  2:40       ` Jan Harkes

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=20070720053807.GD21668@ftp.linux.org.uk \
    --to=viro@ftp.linux.org.uk \
    --cc=akpm@osdl.org \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@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).