public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <matthew@wil.cx>
To: Carlos O'Donell <carlos@systemhalted.org>
Cc: Kyle McMartin <kyle@infradead.org>,
	linux-arch@vger.kernel.org, Stefan Fritsch <sf@sfritsch.de>,
	debian-hppa@lists.debian.org
Subject: Re: flock, FAGAIN, and FWOULDBLOCK
Date: Sun, 22 Feb 2009 20:03:15 -0700	[thread overview]
Message-ID: <20090223030315.GC16891@parisc-linux.org> (raw)
In-Reply-To: <119aab440902221843y7e664581w99a9d44257672ae2@mail.gmail.com>

On Sun, Feb 22, 2009 at 09:43:36PM -0500, Carlos O'Donell wrote:
> flock is not POSIX, it's an interface invented by 4.2BSD, and was
> previously emulated by glibc. The glibc wrapper implemented flock with
> fcntl and made sure to return EWOULDBLOCK.

glibc's emulation of flock() using fcntl() really belongs to the Dark
Ages of Linux.  According to the comments in the kernel, flock(2) was
added in June 1995.  That's four years before parisc-linux really got
going.

The semantics of flock-locks and fcntl-locks are really, really
different.  Emulating one with the other was a really bad idea.

> > +       ret = sys_flock(fd, cmd);
> > +       if (ret == -EAGAIN)
> > +               ret = -EWOULDBLOCK;     /* fuck you HPUX */
> 
> A more robust solution would be?
> 
> if ((ret == -EAGAIN) || (ret == -EWOULDBLOK))
>         ret = -EWOULDBLOCK

How would that differ from what Kyle wrote?  Why would you want to
assign -EWOULDBLOCK to ret if ret is already -EWOULDBLOCK?

> This covers our ass since POSIX says that EAGAIN and EWOULDBLOCK *may*
> be the same.

That's irrelevant.  The only thing that matters is what the kernel does.

> > but somehow I suspect this interchangeable use of EAGAIN and EWOULDBLOCK
> > is going to reveal latent problems in this part of the kernel I would
> > rather not delve into...
> 
> The ABI is fixed, so all we can do is cleanup the uses in the kernel,
> and make sure we adhere to the documented APIs.

We actually can do better than this ...

#ifdef __KERNEL__
#define EWOULDBLOCK	EAGAIN
#else
#define EWOULDBLOCK	/* whatever the fuck HPUX uses */
#endif

Now our kernel never returns -EWOULDBLOCK, only -EAGAIN.  Correct
applications must check for both.  Incorrect applications tend to only
check for AGAIN, not WOULDBLOCK.  Problem solved.

-- 
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."

  parent reply	other threads:[~2009-02-23  3:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200902222252.45051.sf@sfritsch.de>
     [not found] ` <20090222224924.GA13157@bombadil.infradead.org>
2009-02-23  1:42   ` flock, FAGAIN, and FWOULDBLOCK Kyle McMartin
2009-02-23  2:43     ` Carlos O'Donell
2009-02-23  2:43       ` Carlos O'Donell
2009-02-23  2:54       ` Kyle McMartin
2009-02-23  3:00         ` Carlos O'Donell
2009-02-23  3:03       ` Matthew Wilcox [this message]
2009-02-23  3:55         ` Michael Kerrisk
2009-02-23 17:49         ` Helge Deller
2009-02-23 19:31         ` flock, EAGAIN, and EWOULDBLOCK Stefan Fritsch
2009-02-23 19:31           ` Stefan Fritsch
2009-02-23  3:31       ` flock, FAGAIN, and FWOULDBLOCK Michael Kerrisk
2009-02-23  3:20     ` Michael Kerrisk
2009-02-23  3:50       ` Kyle McMartin
2009-02-23  4:01         ` Michael Kerrisk
2009-02-23  8:23       ` Geert Uytterhoeven

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=20090223030315.GC16891@parisc-linux.org \
    --to=matthew@wil.cx \
    --cc=carlos@systemhalted.org \
    --cc=debian-hppa@lists.debian.org \
    --cc=kyle@infradead.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=sf@sfritsch.de \
    /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