1
0
Fork 0
remarkable-linux/fs/fuse
Seth Forshee bbd5f23b1e fuse: Add reference counting for fuse_io_priv
[ Upstream commit 744742d692 ]

The 'reqs' member of fuse_io_priv serves two purposes. First is to track
the number of oustanding async requests to the server and to signal that
the io request is completed. The second is to be a reference count on the
structure to know when it can be freed.

For sync io requests these purposes can be at odds.  fuse_direct_IO() wants
to block until the request is done, and since the signal is sent when
'reqs' reaches 0 it cannot keep a reference to the object. Yet it needs to
use the object after the userspace server has completed processing
requests. This leads to some handshaking and special casing that it
needlessly complicated and responsible for at least one race condition.

It's much cleaner and safer to maintain a separate reference count for the
object lifecycle and to let 'reqs' just be a count of outstanding requests
to the userspace server. Then we can know for sure when it is safe to free
the object without any handshaking or special cases.

The catch here is that most of the time these objects are stack allocated
and should not be freed. Initializing these objects with a single reference
that is never released prevents accidental attempts to free the objects.

Fixes: 9d5722b777 ("fuse: handle synchronous iocbs internally")
Cc: stable@vger.kernel.org # v4.1+
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
2016-04-18 08:50:57 -04:00
..
Kconfig fuse: Move CUSE Kconfig entry from fs/Kconfig into fs/fuse/Kconfig 2013-01-17 13:08:45 +01:00
Makefile CUSE: implement CUSE - Character device in Userspace 2009-06-09 11:24:11 +02:00
control.c VFS: normal filesystems (and lustre): d_inode() annotations 2015-04-15 15:06:57 -04:00
cuse.c fuse: Add reference counting for fuse_io_priv 2016-04-18 08:50:57 -04:00
dev.c fuse: use iov_iter_get_pages() for non-splice path 2015-04-11 22:29:41 -04:00
dir.c VFS: normal filesystems (and lustre): d_inode() annotations 2015-04-15 15:06:57 -04:00
file.c fuse: Add reference counting for fuse_io_priv 2016-04-18 08:50:57 -04:00
fuse_i.h fuse: Add reference counting for fuse_io_priv 2016-04-18 08:50:57 -04:00
inode.c fuse: initialize fc->release before calling it 2015-08-03 09:29:14 -07:00