linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton-vpEMnDpepFuMZCB2o+C8xQ@public.gmane.org>
To: Al Viro <viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
Cc: bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org,
	linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v4 03/16] fs: allow __fput_sync to be used by non-kthreads and in modules
Date: Fri, 11 Sep 2015 10:38:30 -0400	[thread overview]
Message-ID: <20150911103830.4f4e5901@tlielax.poochiereds.net> (raw)
In-Reply-To: <20150911140049.GN22011-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>

On Fri, 11 Sep 2015 15:00:49 +0100
Al Viro <viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org> wrote:

> On Fri, Sep 11, 2015 at 06:54:29AM -0400, Jeff Layton wrote:
> > We want nfsd to keep a cache of open files, but that would potentially
> > block userland callers from obtaining leases on them. To fix this,
> > we'll be adding a new notifier chain to the lease code that will call
> > back into nfsd on any attempt to set a FL_LEASE. nfsd can then close
> > any open files for that inode in advance of that.
> > 
> > The problem however is that since that notifier will run in normal
> > process context, the final __fput will be delayed a'la task_work and we
> > are still unable to set a lease. What we need to do is to put the struct
> > file synchronously so that the __fput runs before returning from the
> > notifier call.
> > 
> > The comments over __fput_sync and the BUG_ON in there mandate that it
> > should only be used in kthread context, but I see no reason why that
> > should be so. As long as the caller avoids holding locks that may be
> > problematic, it should be OK to use it from normal process context as
> > well.
> > 
> > Remove the __ prefix and the BUG_ON from that function and update the
> > comments over it. Also export it so that it can be used from nfsd code,
> > and move the export of fput just below the function definition.
> 
> I really don't like that.
> 	a) how deep in kernel stack will that thing run?
> 	b) what locking environment is expected in your case?
> 
> And opening it for use by any random driver that just feels like e.g.
> using it to go parse its config over there in /lib/we/are/special/wank.conf
> with 5Kb worth of kernel stack already eaten is a really bad idea.


Not too deep in our case, and with no real locking held aside from a
SRCU lock. Basically we're going to have a SRCU notifier chain that
will run from vfs_setlease. That will call back into the nfsd code when
it's running which will scan the hash for open files for the inode,
unhash and release them (synchronously). If they're being held open in
the cache but are otherwise idle, that's enough to allow a lease to be
acquired.

That said, I'm not thrilled with it either. There are some
alternatives:

1) we could just call task_work_run after the fput, but that seems
scary if (e.g.) some random interrupt walks in and queues up some
task_work.

2) we could add a "delayed_fput(file)", that adds it to the
delayed_fput_list, even when being run from normal process context.
Then we could just flush_delayed_fput() afterward. More context
switching, but that should be relatively safe I'd think.

-- 
Jeff Layton <jlayton-vpEMnDpepFuMZCB2o+C8xQ@public.gmane.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2015-09-11 14:38 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-11 10:54 [PATCH v4 00/16] nfsd: open file caching Jeff Layton
2015-09-11 10:54 ` [PATCH v4 01/16] locks: change tracepoint for generic_add_lease Jeff Layton
2015-09-11 10:54 ` [PATCH v4 02/16] list_lru: add list_lru_rotate Jeff Layton
2015-09-11 10:54 ` [PATCH v4 03/16] fs: allow __fput_sync to be used by non-kthreads and in modules Jeff Layton
     [not found]   ` <1441968882-7851-4-git-send-email-jeff.layton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2015-09-11 14:00     ` Al Viro
     [not found]       ` <20150911140049.GN22011-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2015-09-11 14:38         ` Jeff Layton [this message]
2015-09-11 10:54 ` [PATCH v4 04/16] fsnotify: export several symbols Jeff Layton
     [not found] ` <1441968882-7851-1-git-send-email-jeff.layton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>
2015-09-11 10:54   ` [PATCH v4 05/16] locks: create a new notifier chain for lease attempts Jeff Layton
2015-09-11 10:54   ` [PATCH v4 08/16] nfsd: add a new struct file caching facility to nfsd Jeff Layton
2015-09-11 10:54   ` [PATCH v4 09/16] nfsd: hook up nfsd_write to the new nfsd_file cache Jeff Layton
2015-09-11 10:54   ` [PATCH v4 10/16] nfsd: hook up nfsd_read to the " Jeff Layton
2015-09-11 10:54   ` [PATCH v4 11/16] nfsd: hook nfsd_commit up " Jeff Layton
2015-09-11 10:54   ` [PATCH v4 13/16] nfsd: have nfsd_test_lock use " Jeff Layton
2015-09-11 10:54   ` [PATCH v4 15/16] nfsd: hook up nfs4_preprocess_stateid_op to " Jeff Layton
2015-09-11 10:54 ` [PATCH v4 06/16] nfsd: move include of state.h from trace.c to trace.h Jeff Layton
2015-09-11 10:54 ` [PATCH v4 07/16] sunrpc: add a new cache_detail operation for when a cache is flushed Jeff Layton
2015-09-11 10:54 ` [PATCH v4 12/16] nfsd: convert nfs4_file->fi_fds array to use nfsd_files Jeff Layton
2015-09-11 10:54 ` [PATCH v4 14/16] nfsd: convert fi_deleg_file and ls_file fields to nfsd_file Jeff Layton
2015-09-11 10:54 ` [PATCH v4 16/16] nfsd: rip out the raparms cache Jeff Layton

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=20150911103830.4f4e5901@tlielax.poochiereds.net \
    --to=jlayton-vpemndpepfumzcb2o+c8xq@public.gmane.org \
    --cc=bfields-uC3wQj2KruNg9hUCZPvPmw@public.gmane.org \
    --cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-nfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.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).