From: Al Viro <viro@ZenIV.linux.org.uk>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
hch@infradead.org, torvalds@linux-foundation.org,
dhowells@redhat.com, mszeredi@suse.cz
Subject: Re: [PATCH 00/21] vfs: atomic open v6 (part 2)
Date: Sun, 10 Jun 2012 04:49:21 +0100 [thread overview]
Message-ID: <20120610034921.GB30000@ZenIV.linux.org.uk> (raw)
In-Reply-To: <1338901832-14049-1-git-send-email-miklos@szeredi.hu>
On Tue, Jun 05, 2012 at 03:10:11PM +0200, Miklos Szeredi wrote:
> This is part 2 of the atomic open series. It introduces i_op->atomic_open() and
> converts filesystems that abuse ->lookup() and ->create() to use this new
> interface instead.
>
> This version has one bugfix and several cleanups, reported by David Howells.
> Also updated documentation in Documentation/filesytems/{vfs.txt,Locking}.
>
> Al, please apply.
>
> git tree is here:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git atomic-open.v6
I'm more or less OK with that; one major exception is your struct opendata.
I think it needs to go. Really. You are using it to store three references -
file, vfsmount and dentry. You allocate struct file at the very beginning
and store it there; no arguments with that, if you are opening a file, by
damn you do need one. But that's where it starts to get really, really
odd. At some point you find vfsmount to be used. Again, you'd better -
we will need it. It ends up in file->f_path.mnt. And that's struct file
opendata ->filp points to. So why the hell do you not store it right there?
The same goes for dentry. You will need something to put into
file->f_path.dentry; that field is not going away, no matter what - we do
need to know which filesystem object read() and write() should deal with,
after all. So why bother with storing it in opendata ->dentry in the
meanwhile, when you have the instance of struct file whose ->f_path.dentry
is to be determined by all that activity?
And if you do that, your struct opendata suddenly shrinks to single struct
file *. Which you assign in the very beginning, pass by reference to all
that code and do not reassign. OK, you do reassign it. In one place:
res = do_dentry_open(dentry, od->mnt, od->filp, open, current_cred());
if (!IS_ERR(res))
od->filp = NULL;
return res;
Here do_dentry_open() returns one of two things - the value of its third
argument (i.e. od->filp) or ERR_PTR(-E...). In the latter case struct
file refered to by the third argument has been freed.
So the only remaining reason for having that thing is this: what if we
call ->atomic_open(), but it doesn't call finish_open()? Then we need
to free that unused struct file. If finish_open() failed, we wouldn't.
Same if it succeeded and something *after* it in ->atomic_open() failed
(then we need to fput() that file - your code in ceph leaks it, BTW).
Fair enough. So we need to add one more helper that would discard that
half-set-up struct file as we want it to be discarded. That's all.
IOW, you get three helpers:
finish_open()
finish_no_open() (really confusing name, BTW)
fail_open()
All of them taking struct file *. Any call of ->atomic_open() must
call one of those. Rules:
* if we called finish_no_open(), we need to return NULL.
That's the "won't open, here's your dentry, open it yourself".
BTW, I would've made it return void * - always NULL. So that
callers would be of form return finish_no_open(file, dentry);
* if we called finish_open() and it returned us an error,
we need to return that to our caller. End of story, we'd failed.
* if we called finish_open() and it succeeded, the file
has been opened. Either return it, or fput() it and return ERR_PTR()
if you have something fail past that point.
* otherwise we need to call failed_open(file). And return
appropriate ERR_PTR(). Might make sense to turn that into
return failed_open(file, ERR_PTR(-E...)); to make dumb errors easy
to spot.
And this is it - no more struct opendata, considerably simpler cleanup
in fs/namei.c and much more natural prototypes. Either ->atomic_open()
returns an opened struct file, or it gives us ERR_PTR(...) (in which case
struct file has been freed/vfsmount dropped/etc.) or it gives us NULL.
In the last case struct file is still there and file->f_path contains
the vfsmount/dentry pair we are supposed to deal with (e.g. on hitting
a symlink).
I can massage it to that form, or I can leave conversion at the end;
up to you - it's going to be a single pull request anyway, so prototype
changes midway through the series are not something tragic. OTOH, folding
said changes back into the original patches might make for less confusing
reading later. Credit for dealing with that really, really scary pile
of shit is clearly yours anyway. And I'm absolutely serious - that has
been a work that needed doing and nobody had stomach for it. You have
my sincere gratitude.
next prev parent reply other threads:[~2012-06-10 3:49 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-05 13:10 [PATCH 00/21] vfs: atomic open v6 (part 2) Miklos Szeredi
2012-06-05 13:10 ` [PATCH 01/21] vfs: do_last(): inline lookup_slow() Miklos Szeredi
2012-06-05 13:10 ` [PATCH 02/21] vfs: do_last(): separate O_CREAT specific code Miklos Szeredi
2012-06-05 13:10 ` [PATCH 03/21] vfs: do_last(): common slow lookup Miklos Szeredi
2012-06-05 13:10 ` [PATCH 04/21] vfs: add lookup_open() Miklos Szeredi
2012-06-05 13:10 ` [PATCH 05/21] vfs: lookup_open(): expand lookup_hash() Miklos Szeredi
2012-06-05 13:10 ` [PATCH 06/21] vfs: add i_op->atomic_open() Miklos Szeredi
2012-06-05 13:10 ` [PATCH 07/21] nfs: implement i_op->atomic_open() Miklos Szeredi
2012-06-05 13:10 ` [PATCH 08/21] nfs: clean up ->create in nfs_rpc_ops Miklos Szeredi
2012-06-05 13:10 ` [PATCH 09/21] nfs: don't use nd->intent.open.flags Miklos Szeredi
2012-06-05 13:10 ` [PATCH 10/21] nfs: don't use intents for checking atomic open Miklos Szeredi
2012-06-05 13:10 ` [PATCH 11/21] fuse: implement i_op->atomic_open() Miklos Szeredi
2012-06-05 13:10 ` [PATCH 12/21] cifs: " Miklos Szeredi
[not found] ` <1338901832-14049-13-git-send-email-miklos-sUDqSbJrdHQHWmgEVkV9KA@public.gmane.org>
2012-07-02 18:54 ` Jeff Layton
2012-06-05 13:10 ` [PATCH 13/21] ceph: remove unused arg from ceph_lookup_open() Miklos Szeredi
2012-06-05 13:10 ` [PATCH 14/21] ceph: implement i_op->atomic_open() Miklos Szeredi
2012-06-05 13:10 ` [PATCH 15/21] 9p: " Miklos Szeredi
2012-06-05 13:10 ` [PATCH 16/21] vfs: remove open intents from nameidata Miklos Szeredi
2012-06-05 13:10 ` [PATCH 17/21] vfs: do_last(): clean up error handling Miklos Szeredi
2012-06-05 13:10 ` [PATCH 18/21] vfs: do_last(): clean up labels Miklos Szeredi
2012-06-05 13:10 ` [PATCH 19/21] vfs: do_last(): clean up bool Miklos Szeredi
2012-06-05 13:10 ` [PATCH 20/21] vfs: do_last(): clean up retry Miklos Szeredi
2012-06-05 13:10 ` [PATCH 21/21] vfs: move O_DIRECT check to common code Miklos Szeredi
2012-06-05 15:39 ` [PATCH 00/21] vfs: atomic open v6 (part 2) Linus Torvalds
2012-06-05 15:50 ` Miklos Szeredi
2012-06-10 3:49 ` Al Viro [this message]
2012-06-10 5:54 ` Al Viro
2012-06-10 11:10 ` Al Viro
2012-06-10 17:56 ` Al Viro
2012-06-10 22:27 ` Al Viro
2012-06-13 11:21 ` Christoph Hellwig
2012-06-14 8:08 ` Al Viro
2012-06-17 20:37 ` Christoph Hellwig
2012-06-18 11:58 ` Christoph Hellwig
2012-06-18 13:12 ` Christoph Hellwig
2012-06-18 14:27 ` Miklos Szeredi
2012-06-22 8:49 ` Al Viro
2012-06-22 10:07 ` Al Viro
2012-06-11 10:57 ` Boaz Harrosh
2012-06-11 15:18 ` Miklos Szeredi
2012-06-11 16:33 ` Miklos Szeredi
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=20120610034921.GB30000@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=dhowells@redhat.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=mszeredi@suse.cz \
--cc=torvalds@linux-foundation.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).