Network fs helper library & fscache kiocb API
Subsystems (16)
David Howells
maintainerv4 cover Network fs helper library & fscache kiocb API
Here's a set of patches to do two things:
(1) Add a helper library to handle the new VM readahead interface. This is intended to be used unconditionally by the filesystem (whether or not caching is enabled) and provides a common framework for doing caching, transparent huge pages and, in the future, possibly fscrypt and read bandwidth maximisation. It also allows the netfs and the cache to align, expand and slice up a read request from the VM in various ways; the netfs need only provide a function to read a stretch of data to the pagecache and the helper takes care of the rest.
(2) Add an alternative fscache/cachfiles I/O API that uses the kiocb facility to do async DIO to transfer data to/from the netfs's pages, rather than using readpage with wait queue snooping on one side and vfs_write() on the other. It also uses less memory, since it doesn't do buffered I/O on the backing file.
Note that this uses SEEK_HOLE/SEEK_DATA to locate the data available to be read from the cache. Whilst this is an improvement from the bmap interface, it still has a problem with regard to a modern extent-based filesystem inserting or removing bridging blocks of zeros. Fixing that requires a much greater overhaul.
This is a step towards overhauling the fscache API. The change is opt-in on the part of the network filesystem. A netfs should not try to mix the old and the new API because of conflicting ways of handling pages and the PG_fscache page flag and because it would be mixing DIO with buffered I/O. Further, the helper library can't be used with the old API.
This does not change any of the fscache cookie handling APIs or the way invalidation is done.
In the near term, I intend to deprecate and remove the old I/O API (fscache_allocate_page{,s}(), fscache_read_or_alloc_page{,s}(), fscache_write_page() and fscache_uncache_page()) and eventually replace most of fscache/cachefiles with something simpler and easier to follow.
The patchset contains the following parts:
(1) Some helper patches, including provision of an ITER_XARRAY iov iterator and a function to do readahead expansion.
(2) Patches to add the netfs helper library.
(3) A patch to add the fscache/cachefiles kiocb API.
(4) Patches to add support in AFS for this.
Jeff Layton has patches to add support in Ceph for this.
Dave Wysochanski also has patches for NFS for this, though they're not included on this branch as there's an issue with PNFS.
With this, AFS without a cache passes all expected xfstests; with a cache, there's an extra failure, but that's also there before these patches. Fixing that probably requires a greater overhaul. Ceph and NFS also pass the expected tests.
These patches can be found also on:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=fscache-netfs-lib
Changes
=======
ver #4:
Fixed some review comments from Christoph Hellwig, including dropping the export of rw_verify_area()[3] and some minor stuff[4].
Moved the declaration of readahead_expand() to a better location[5].
Rebased to v5.12-rc2 and added a bunch of references into individual commits.
Dropped Ceph support - that will go through the maintainer's tree.
Added interface documentation for the netfs helper library.
ver #3:
Rolled in the bug fixes.
Adjusted the functions that unlock and wait for PG_fscache according to Linus's suggestion[1].
Hold a ref on a page when PG_fscache is set as per Linus's suggestion[2].
Dropped NFS support and added Ceph support.
ver #2:
Fixed some bugs and added NFS support.
References
==========
These patches have been published for review before, firstly as part of a larger set:
Then as a cut-down set:
Proposals/information about the design has been published here:
And requests for information:
The NFS parts, though not included here, have been tested by someone who's using fscache in production:
I've posted partial patches to try and help 9p and cifs along:
David
---
David Howells (28):
iov_iter: Add ITER_XARRAY
mm: Add an unlock function for PG_private_2/PG_fscache
mm: Implement readahead_control pageset expansion
netfs: Make a netfs helper module
netfs: Documentation for helper library
netfs, mm: Move PG_fscache helper funcs to linux/netfs.h netfs, mm: Add unlock_page_fscache() and wait_on_page_fscache()
netfs: Provide readahead and readpage netfs helpers
netfs: Add tracepoints
netfs: Gather stats
netfs: Add write_begin helper
netfs: Define an interface to talk to a cache
netfs: Hold a ref on a page when PG_private_2 is set
fscache, cachefiles: Add alternate API to use kiocb for read/write to cache
afs: Disable use of the fscache I/O routines
afs: Pass page into dirty region helpers to provide THP size
afs: Print the operation debug_id when logging an unexpected data version
afs: Move key to afs_read struct
afs: Don't truncate iter during data fetch
afs: Log remote unmarshalling errors
afs: Set up the iov_iter before calling afs_extract_data()
afs: Use ITER_XARRAY for writing
afs: Wait on PG_fscache before modifying/releasing a page
afs: Extract writeback extension into its own function
afs: Prepare for use of THPs
afs: Use the fs operation ops to handle FetchData completion
afs: Use new fscache read helper API
afs: Use the fscache_write_begin() helper
Documentation/filesystems/index.rst | 1 + Documentation/filesystems/netfs_library.rst | 526 +++++++++ fs/Kconfig | 1 + fs/Makefile | 1 + fs/afs/Kconfig | 1 + fs/afs/dir.c | 225 ++-- fs/afs/file.c | 483 ++------ fs/afs/fs_operation.c | 4 +- fs/afs/fsclient.c | 108 +- fs/afs/inode.c | 7 +- fs/afs/internal.h | 59 +- fs/afs/rxrpc.c | 150 +-- fs/afs/write.c | 656 +++++------ fs/afs/yfsclient.c | 82 +- fs/cachefiles/Makefile | 1 + fs/cachefiles/interface.c | 5 +- fs/cachefiles/internal.h | 9 + fs/cachefiles/rdwr2.c | 403 +++++++ fs/fscache/Kconfig | 1 + fs/fscache/Makefile | 1 + fs/fscache/internal.h | 4 + fs/fscache/io.c | 116 ++ fs/fscache/page.c | 2 +- fs/fscache/stats.c | 1 + fs/netfs/Kconfig | 23 + fs/netfs/Makefile | 5 + fs/netfs/internal.h | 97 ++ fs/netfs/read_helper.c | 1180 +++++++++++++++++++ fs/netfs/stats.c | 59 + include/linux/fscache-cache.h | 4 + include/linux/fscache.h | 50 +- include/linux/netfs.h | 200 ++++ include/linux/pagemap.h | 3 + include/net/af_rxrpc.h | 2 +- include/trace/events/afs.h | 74 +- include/trace/events/netfs.h | 201 ++++ mm/filemap.c | 20 + mm/readahead.c | 70 ++ net/rxrpc/recvmsg.c | 9 +- 39 files changed, 3774 insertions(+), 1070 deletions(-) create mode 100644 Documentation/filesystems/netfs_library.rst create mode 100644 fs/cachefiles/rdwr2.c create mode 100644 fs/fscache/io.c create mode 100644 fs/netfs/Kconfig create mode 100644 fs/netfs/Makefile create mode 100644 fs/netfs/internal.h create mode 100644 fs/netfs/read_helper.c create mode 100644 fs/netfs/stats.c create mode 100644 include/linux/netfs.h create mode 100644 include/trace/events/netfs.h
David Howells
maintainerPATCH v4 1/28 iov_iter: Add ITER_XARRAY
Add an iterator, ITER_XARRAY, that walks through a set of pages attached to an xarray, starting at a given page and offset and walking for the specified amount of bytes. The iterator supports transparent huge pages.
The iterate_xarray() macro calls the helper function with rcu_access() helped. I think that this is only a problem for iov_iter_for_each_range()
- and that returns an error for ITER_XARRAY (also, this function does not appear to be called).
The caller must guarantee that the pages are all present and they must be locked using PG_locked, PG_writeback or PG_fscache to prevent them from going away or being migrated whilst they're being accessed.
This is useful for copying data from socket buffers to inodes in network filesystems and for transferring data between those inodes and the cache using direct I/O.
Whilst it is true that ITER_BVEC could be used instead, that would require a bio_vec array to be allocated to refer to all the pages - which should be redundant if inode->i_pages also points to all these pages.
Note that older versions of this patch implemented an ITER_MAPPING instead, which was almost the same.
---
include/linux/uio.h | 11 ++ lib/iov_iter.c | 313 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 301 insertions(+), 23 deletions(-)
include/linux/uio.h +11 -0
@@ -10,6 +10,7 @@#include <uapi/linux/uio.h> struct page ; +struct address_space ;struct pipe_inode_info ;struct kvec {
@@ -24,6 +25,7 @@ enum iter_type {ITER_BVEC =16 ,ITER_PIPE =32 ,ITER_DISCARD =64 , + ITER_XARRAY = 128, }; struct iov_iter {
@@ -39,6 +41,7 @@ struct iov_iter {const struct iovec *iov;const struct kvec *kvec;const struct bio_vec *bvec; +struct xarray *xarray;struct pipe_inode_info *pipe; };union {
@@ -47,6 +50,7 @@ struct iov_iter {unsigned int head;unsigned int start_head; }; +loff_t xarray_start; }; };
@@ -80,6 +84,11 @@ static inline bool iov_iter_is_discard(const struct iov_iter *i)return iov_iter_type (i) ==ITER_DISCARD ; } +static inline bool iov_iter_is_xarray (const struct iov_iter *i) +{ +return iov_iter_type (i) ==ITER_XARRAY ; +} +static inline unsigned char iov_iter_rw (const struct iov_iter *i) {return i->type & (READ |WRITE );
@@ -221,6 +230,8 @@ void iov_iter_bvec(struct iov_iter *i, unsigned int direction, const struct bio_void iov_iter_pipe (struct iov_iter *i,unsigned int direction,struct pipe_inode_info *pipe,size_t count);void iov_iter_discard (struct iov_iter *i,unsigned int direction,size_t count); +void iov_iter_xarray (struct iov_iter *i,unsigned int direction,struct xarray *xarray, +loff_t start,size_t count);ssize_t iov_iter_get_pages (struct iov_iter *i,struct page **pages,size_t maxsize,unsigned maxpages,size_t *start); ssize_t iov_iter_get_pages_alloc(struct iov_iter *i, struct page ***pages,
lib/iov_iter.c +290 -23
522 lines not on this page · raw message
David Howells
maintainerPATCH v4 2/28 mm: Add an unlock function for PG_private_2/PG_fscache
In reply to David HowellsAdd a function, unlock_page_private_2(), to unlock PG_private_2 analogous to that of PG_lock. Add a kerneldoc banner to that indicating the example usage case.
A wrapper will need to be placed in the netfs header in the patch that adds that.
[This implements a suggestion by Linus[1] to not mix the terminology of
PG_private_2 and PG_fscache in the mm core function]
Changes:
- Remove extern from the declaration[2].
---
include/linux/pagemap.h | 1 + mm/filemap.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+)
include/linux/pagemap.h +1 -0
@@ -591,6 +591,7 @@ extern int __lock_page_async(struct page *page, struct wait_page_queue *wait);extern int __lock_page_or_retry (struct page *page,struct mm_struct *mm,unsigned int flags);extern void unlock_page (struct page *page); +void unlock_page_private_2 (struct page *page);/* * Return true if the page was successfully locked
mm/filemap.c +20 -0
@@ -1432,6 +1432,26 @@ void unlock_page(struct page *page) }EXPORT_SYMBOL (unlock_page); +/** +* unlock_page_private_2 - Unlock a page that's locked with PG_private_2 +* @page: The page +* +* Unlocks a page that's locked with PG_private_2 and wakes up sleepers in +* wait_on_page_private_2(). +* +* This is, for example, used when a netfs page is being written to a local +* disk cache, thereby allowing writes to the cache for the same page to be +* serialised. +*/ +void unlock_page_private_2 (struct page *page) +{ + page =compound_head (page); +VM_BUG_ON_PAGE (!PagePrivate2 (page), page); +clear_bit_unlock (PG_private_2, &page->flags); +wake_up_page_bit (page, PG_private_2); +} +EXPORT_SYMBOL (unlock_page_private_2); +/** * end_page_writeback - end writeback against a page * @page: the page
Matthew Wilcox
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 3 lines · David Howells
Add a function,
unlock_page_private_2(), to unlockPG_private_2analogous to that ofPG_lock. Add a kerneldoc banner to that indicating the example usage case.
This isn't a problem with this patch per se, but I'm concerned about private2 and expected page refcounts.
static inline int is_page_cache_freeable(struct page *page)
{
/*
* A freeable page cache page is referenced only by the caller
* that isolated the page, the page cache and optional buffer
* heads at page->private.
*/
int page_cache_pins = thp_nr_pages(page);
return page_count(page) - page_has_private(page) == 1 + page_cache_pins;
}static inline int page_has_private(struct page *page)
{
return !!(page->flags & PAGE_FLAGS_PRIVATE);
}#define PAGE_FLAGS_PRIVATE \
(1UL << PG_private | 1UL << PG_private_2)So ... a page with both flags cleared should have a refcount of N. A page with one or both flags set should have a refcount of N+1.
How is a poor filesystem supposed to make that true? Also btrfs has this problem since it uses private_2 for its own purposes.
David Howells
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 5 lines · Matthew Wilcox
So ... a page with both flags cleared should have a refcount of N. A page with one or both flags set should have a refcount of N+1.
...
How is a poor filesystem supposed to make that true? Also btrfs has this problem since it usesprivate_2for its own purposes.
It's simpler if it's N+2 for both patches set. Btw, patch 13 adds that - and possibly that should be merged into an earlier patch.
David
Matthew Wilcox
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 10 lines · David Howells
Quoted 5 lines · Matthew Wilcox
So ... a page with both flags cleared should have a refcount of N. A page with one or both flags set should have a refcount of N+1.
...
How is a poor filesystem supposed to make that true? Also btrfs has this problem since it usesprivate_2for its own purposes.It's simpler if it's N+2 for both patches set. Btw, patch 13 adds that - and possibly that should be merged into an earlier patch.
So ...
static inline int page_has_private(struct page *page)
{
unsigned long flags = page->flags;
return ((flags >> PG_private) & 1) + ((flags >> PG_private_2) & 1);
}perhaps?
Re: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
In reply to Matthew Wilcox[ Adding btrfs people explicitly, maybe they see this on the fs-devel list, but maybe they don't react .. ]
Quoted 3 lines · Matthew Wilcox
This isn't a problem with this patch per se, but I'm concerned about private2 and expected page refcounts.
Ugh. You are very right.
It would be good to just change the rules - I get the feeling nobody actually depended on them anyway because they were _so_ esoteric.
Quoted 9 lines
static inline int
is_page_cache_freeable(struct page *page){ /* * A freeable page cache page is referenced only by the caller * that isolated the page, the page cache and optional buffer * heads at page->private. */ int page_cache_pins = thp_nr_pages(page); return page_count(page) - page_has_private(page) == 1 + page_cache_pins;
You're right, that "page_has_private()" is really really nasty.
The comment is, I think, the traditional usage case, which used to be about page->buffers. Obviously these days it is now about page->private with PG_private set, pointing to buffers (attach_page_private() and detach_page_private()).
But as you point out:
Quoted 5 lines
#define PAGE_FLAGS_PRIVATE \ (1UL << PG_private | 1UL << PG_private_2)So ... a page with both flags cleared should have a refcount of N. A page with one or both flags set should have a refcount of N+1.
Could we just remove the PG_private_2 thing in this context entirely, and make the rule be that
(a) PG_private means that you have some local private data inpage->private, and that's all that matters for the "freeable" thing.
(b) PG_private_2 does *not* have the same meaning, and has no bearing
on freeability (and only the refcount matters)
I _)think_ the btrfs behavior is to only use PagePrivate2() when it has a reference to the page, so btrfs doesn't care?
I think fscache is already happy to take the page count when using PG_private_2 for locking, exactly because I didn't want to have any confusion about lifetimes. But this "page_has_private()" math ends up meaning it's confusing anyway.
btrfs people? What are the semantics for PG_private_2? Is it just a flag, and you really don't want it to have anything to do with any page lifetime decisions? Or?
Linus
Re: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 50 lines · Linus Torvalds
[ Adding btrfs people explicitly, maybe they see this on the fs-devel list, but maybe they don't react .. ]
Quoted 3 lines · Matthew Wilcox
This isn't a problem with this patch per se, but I'm concerned about private2 and expected page refcounts.
Ugh. You are very right.
It would be good to just change the rules - I get the feeling nobody actually depended on them anyway because they were _so_ esoteric.
Quoted 9 lines
static inline int
is_page_cache_freeable(struct page *page){ /* * A freeable page cache page is referenced only by the caller * that isolated the page, the page cache and optional buffer * heads at page->private. */ int page_cache_pins = thp_nr_pages(page); return page_count(page) - page_has_private(page) == 1 + page_cache_pins;You're right, that "
page_has_private()" is really really nasty.The comment is, I think, the traditional usage case, which used to be about
page->buffers. Obviously these days it is now aboutpage->privatewithPG_privateset, pointing to buffers (attach_page_private()anddetach_page_private()).But as you point out:
Quoted 5 lines
#define PAGE_FLAGS_PRIVATE \ (1UL << PG_private | 1UL << PG_private_2)So ... a page with both flags cleared should have a refcount of N. A page with one or both flags set should have a refcount of N+1.
Could we just remove the
PG_private_2thing in this context entirely, and make the rule be that(a)
PG_privatemeans that you have some local private data inpage->private, and that's all that matters for the "freeable" thing.(b)
PG_private_2does *not* have the same meaning, and has no bearing
on freeability (and only the refcount matters)I _)think_ the btrfs behavior is to only use
PagePrivate2()when it has a reference to the page, so btrfs doesn't care?
Quoted 9 lines
I think fscache is already happy to take the page count when using
PG_private_2for locking, exactly because I didn't want to have any confusion about lifetimes. But this "page_has_private()" math ends up meaning it's confusing anyway.btrfs people? What are the semantics for
PG_private_2? Is it just a flag, and you really don't want it to have anything to do with any page lifetime decisions? Or?
Yeah it's just a flag, we use it to tell that the page is part of a range that has been allocated for IO. The lifetime of the page is independent of the page, but is generally either dirty or under writeback, so either it goes through truncate and we clear PagePrivate2 there, or it actually goes through IO and is cleared before we drop the page in our endio. We _always_ have PG_private set on the page as long as we own it, and PG_private_2 is only set in this IO related context, so we're safe there because of the rules around PG_dirty/PG_writeback. We don't need it to have an extra ref for it being set.
Thanks,
Josef
Re: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 7 lines · Josef Bacik
Yeah it's just a flag, we use it to tell that the page is part of a range that has been allocated for IO. The lifetime of the page is independent of the page, but is generally either dirty or under writeback, so either it goes through truncate and we clear PagePrivate2 there, or it actually goes through IO and is cleared before we drop the page in our endio.
Ok, that's what it looked like from my very limited "looking at a couple of grep cases", but I didn't go any further than that.
Quoted 4 lines
We _always_ have
PG_privateset on the page as long as we own it, andPG_private_2is only set in this IO related context, so we're safe there because of the rules around PG_dirty/PG_writeback. We don't need it to have an extra ref for it being set.
Perfect. That means that at least as far as btrfs is concerned, we could trivially remove PG_private_2 from that page_has_private() math
- you'd always see the same result anyway, exactly because you have PG_private set.
And as far as I can tell, fscache doesn't want that PG_private_2 bit to interact with the random VM lifetime or migration rules either, and should rely entirely on the page count. David?
There's actually a fair number of page_has_private() users, so we'd better make sure that's the case. But it's simplified by this but really only being used by btrfs (which doesn't care) and fscache, so this cleanup would basically be entirely up to the whole fscache series.
Hmm? Objections?
Linus
David Howells
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 3 lines · Linus Torvalds
And as far as I can tell, fscache doesn't want that
PG_private_2bit to interact with the random VM lifetime or migration rules either, and should rely entirely on the page count. David?
It's slightly complicated for fscache as there are two separate pieces of code involved:
(1) For the old fscache code that I'm trying to phase out, it does not take a ref when PG_fscache is taken (probably incorrectly), relying instead on releasepage, etc. getting called to strip the PG_fscache bit. PG_fscache is held for the lifetime of the page, indicating that fscache knows about it and might access it at any time (to write to the cache in the background for example or to move pages around in the cache).
Here PG_fscache should not prevent page eviction or migration and it's analogous to PG_private.
That said, the old fscache code keeps its own radix trees of pages that are undergoing write to the cache, so to allow a page to be evicted, releasepage and co. have to consult those (__fscache_maybe_release_page()).
(2) For the new netfs lib, PG_fscache is ignored by fscache itself and is used by the read helpers. The helpers simply use it analogously to PG_writeback, indicating that there's I/O in progress from this page to the cache[*]. It's fine to take a ref here because we know we'll drop it shortly.
Here PG_fscache might prevent page eviction or migration, but only because I/O is in progress. If an increment on the page refcount suffices, that's fine.
In both cases, releasepage, etc. look at PG_fscache and decide whether to wait or not (releasepage may tell the caller to skip the page if PG_fscache is set).
[*] Willy suggested using PG_writeback to cover both write to the server and write to the cache, and getting rid of PG_fscache entirely, but that would require extra mechanisms. There are three cases:
(a) We might be writing to only the cache, e.g. because we just read from the server.
Note that this may adversely affect code that does accounting associated with PG_writeback because we woudn't actually be writing back a user-made change or dealing with a dirty page. I'm not sure if that's an issue.
(b) We might writing to both, in which case we can expect both writes to finish at different times.
(c) We might only be writing to the server, e.g. because there's no space in the cache or there is no cache.
It's something that might make sense, however, and we can look at in the future, but for the moment having two separate page flags is simplest.
An additional use of PG_fscache is to prevent a second write to the cache from being started whilst one is in progress. I guess that would be taken over by PG_writeback if we used that.
David
David Howells
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 7 lines · David Howells
(1) For the old fscache code that I'm trying to phase out, it does not take a ref when
PG_fscacheis taken (probably incorrectly), relying instead on releasepage, etc. getting called to strip thePG_fscachebit.PG_fscacheis held for the lifetime of the page, indicating that fscache knows about it and might access it at any time (to write to the cache in the background for example or to move pages around in the cache).
Quoted 7 lines
Here
PG_fscacheshould not prevent page eviction or migration and it's analogous toPG_private.That said, the old fscache code keeps its own radix trees of pages that are undergoing write to the cache, so to allow a page to be evicted, releasepage and co. have to consult those (
__fscache_maybe_release_page()).
Note that, ideally, we'll be able to remove the old fscache I/O code in the next merge window or the one after.
David
Matthew Wilcox
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
In reply to David HowellsQuoted 3 lines · David Howells
Add a function,
unlock_page_private_2(), to unlockPG_private_2analogous to that ofPG_lock. Add a kerneldoc banner to that indicating the example usage case.
One of the things which confused me about this was ... where's the other side? Where's lock_page_private_2()? Then I found this:
#ifdef CONFIG_AFS_FSCACHE
if (PageFsCache(page) &&
wait_on_page_bit_killable(page, PG_fscache) < 0)
return VM_FAULT_RETRY;#endif
Please respect the comment!
/*
* This is exported only for wait_on_page_locked/wait_on_page_writeback, etc.,
* and should not be used directly.
*/
extern void wait_on_page_bit(struct page *page, int bit_nr); extern int wait_on_page_bit_killable(struct page *page, int bit_nr);
I think we need the exported API to be wait_on_page_private_2(), and AFS needs to not tinker in the guts of filemap. Otherwise you miss out on bugfixes like c2407cf7d22d0c0d94cf20342b3b8f06f1d904e7 (see also
https://lore.kernel.org/linux-fsdevel/[email protected]/T/#u
).
That also brings up that there is no set_page_private_2(). I think that's OK -- you only set PageFsCache() immediately after reading the page from the server. But I feel this "unlock_page_private_2" is actually "clear_page_private_2" -- ie it's equivalent to writeback, not to lock.
Quoted 26 lines
+++
b/mm/filemap.cmm/filemap.c +20
-0@@ -1432,6 +1432,26 @@ void unlock_page(struct page *page) }EXPORT_SYMBOL (unlock_page); +/** +* unlock_page_private_2 - Unlock a page that's locked with PG_private_2 +* @page: The page +* +* Unlocks a page that's locked with PG_private_2 and wakes up sleepers in +* wait_on_page_private_2(). +* +* This is, for example, used when a netfs page is being written to a local +* disk cache, thereby allowing writes to the cache for the same page to be +* serialised. +*/ +void unlock_page_private_2 (struct page *page) +{ + page =compound_head (page); +VM_BUG_ON_PAGE (!PagePrivate2 (page), page); +clear_bit_unlock (PG_private_2, &page->flags); +wake_up_page_bit (page, PG_private_2); +} +EXPORT_SYMBOL (unlock_page_private_2); +/**
David Howells
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 4 lines · Matthew Wilcox
That also brings up that there is no
set_page_private_2(). I think that's OK -- you only setPageFsCache()immediately after reading the page from the server. But I feel this "unlock_page_private_2" is actually "clear_page_private_2" -- ie it's equivalent to writeback, not to lock.
How about I do the following:
(1) Add set_page_private_2() or mark_page_private_2() to set the PG_fscache_2 bit. It could take a ref on the page here.
(2) Rename unlock_page_private_2() to end_page_private_2(). It could drop the ref on the page here, but that then means I can't use pagevec_release().
(3) Add wait_on_page_private_2() an analogue of wait_on_page_writeback() rather than wait_on_page_locked().
(4) Provide fscache synonyms of the above.
David
David Howells
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 12 lines · David Howells
Quoted 4 lines · Matthew Wilcox
That also brings up that there is no
set_page_private_2(). I think that's OK -- you only setPageFsCache()immediately after reading the page from the server. But I feel this "unlock_page_private_2" is actually "clear_page_private_2" -- ie it's equivalent to writeback, not to lock.How about I do the following:
(1) Add
set_page_private_2()ormark_page_private_2()to set thePG_fscache_2bit. It could take a ref on the page here.
Quoted 8 lines
(2) Rename
unlock_page_private_2()toend_page_private_2(). It could drop the ref on the page here, but that then means I can't usepagevec_release().(3) Add
wait_on_page_private_2()an analogue ofwait_on_page_writeback()rather thanwait_on_page_locked().(4) Provide fscache synonyms of the above.
Perhaps something like the attached changes (they'll need merging back into the other patches).
David
--- include/linux/pagemap.h | 21 +++++++++++++++++- include/linux/netfs.h | 54 ++++++++++++++++++++++++++++++++++++------------ fs/afs/write.c | 5 ++-- fs/netfs/read_helper.c | 17 +++++---------- mm/filemap.c | 49 +++++++++++++++++++++++++++++++++++++++---- mm/page-writeback.c | 25 ++++++++++++++++++++++ 6 files changed, 139 insertions(+), 32 deletions(-)
include/linux/pagemap.h +20 -1
@@ -591,7 +591,6 @@ extern int __lock_page_async(struct page *page, struct wait_page_queue *wait);extern int __lock_page_or_retry (struct page *page,struct mm_struct *mm,unsigned int flags);extern void unlock_page (struct page *page); -void unlock_page_private_2 (struct page *page);/* * Return true if the page was successfully locked
@@ -684,11 +683,31 @@ static inline int wait_on_page_locked_killable(struct page *page)int put_and_wait_on_page_locked (struct page *page,int state);void wait_on_page_writeback (struct page *page); +int wait_on_page_writeback_killable (struct page *page);extern void end_page_writeback (struct page *page);void wait_for_stable_page (struct page *page);void page_endio (struct page *page,bool is_write,int err); +/** +* set_page_private_2 - Set PG_private_2 on a page and take a ref +* @page: The page. +* +* Set the PG_private_2 flag on a page and take the reference needed for the VM +* to handle its lifetime correctly. This sets the flag and takes the +* reference unconditionally, so care must be taken not to set the flag again +* if it's already set. +*/ +static inline void set_page_private_2 (struct page *page) +{ +get_page (page); +SetPagePrivate2 (page); +} + +void end_page_private_2 (struct page *page); +void wait_on_page_private_2 (struct page *page); +int wait_on_page_private_2_killable (struct page *page); +/* * Add an arbitrary waiter to a page's wait queue */
include/linux/netfs.h +41 -13
73 lines not on this page · raw message
fs/afs/write.c +3 -2
@@ -846,7 +846,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)*/ #ifdef CONFIG_AFS_FSCACHE if (PageFsCache (page) && -wait_on_page_bit_killable (page, PG_fscache) <0 ) +wait_on_page_fscache_killable (page) <0 )return VM_FAULT_RETRY ;#endif
@@ -861,7 +861,8 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)* details the portion of the page we need to write back and we might * need to redirty the page if there's a problem. */ -wait_on_page_writeback (page); +if (wait_on_page_writeback_killable (page) <0 ) +return VM_FAULT_RETRY |VM_FAULT_LOCKED ; priv =afs_page_dirty (page,0 ,thp_size (page)); priv =afs_page_dirty_mmapped (priv);
fs/netfs/read_helper.c +6 -11
@@ -239,13 +239,10 @@ static void netfs_rreq_unmark_after_write(struct netfs_read_request *rreq, bool was_async) {struct netfs_read_subrequest *subreq; -struct pagevec pvec;struct page *page;pgoff_t unlocked =0 ;bool have_unlocked = false; -pagevec_init (&pvec); -rcu_read_lock ();list_for_each_entry (subreq, &rreq->subrequests, rreq_link) {
@@ -258,9 +255,7 @@ static void netfs_rreq_unmark_after_write(struct netfs_read_request *rreq,if (have_unlocked && page->index <= unlocked)continue ; unlocked = page->index; -unlock_page_fscache (page); -if (pagevec_add (&pvec, page) ==0 ) -pagevec_release (&pvec); +end_page_fscache (page); have_unlocked = true; } }
@@ -419,10 +414,8 @@ static void netfs_rreq_unlock(struct netfs_read_request *rreq) pg_failed = true;break ; } -if (test_bit (NETFS_SREQ_WRITE_TO_CACHE , &subreq->flags)) { -get_page (page); -SetPageFsCache (page); - } +if (test_bit (NETFS_SREQ_WRITE_TO_CACHE , &subreq->flags)) +set_page_fscache (page); pg_failed |= subreq_failed;if (pgend < iopos + subreq->len)break ;
@@ -1167,7 +1160,9 @@ int netfs_write_begin(struct file *file, struct address_space *mapping, goto error; have_page: -wait_on_page_fscache (page); + ret =wait_on_page_fscache_killable (page); +if (ret <0 ) + goto error; have_page_no_wait:if (netfs_priv) ops->cleanup (netfs_priv, mapping);
mm/filemap.c +44 -5
68 lines not on this page · raw message
mm/page-writeback.c +25 -0
@@ -2833,6 +2833,31 @@ void wait_on_page_writeback(struct page *page) }EXPORT_SYMBOL_GPL (wait_on_page_writeback); +/** +* Wait for a page to complete writeback +* @page: The page to wait on +* +* Wait for the writeback status of a page to clear or a fatal signal to occur. +* +* Return: +* - 0 on success. +* - -EINTR if a fatal signal was encountered. +*/ +int wait_on_page_writeback_killable (struct page *page) +{ +int ret =0 ; + +while (PageWriteback (page)) { +trace_wait_on_page_writeback (page,page_mapping (page)); + ret =wait_on_page_bit_killable (page, PG_writeback); +if (ret <0 ) +break ; + } + +return ret; +} +EXPORT_SYMBOL (wait_on_page_writeback_killable); +/** * wait_for_stable_page() - wait for writeback to finish, if necessary. * @page: The page to wait on.
Matthew Wilcox
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 11 lines · David Howells
+++
b/fs/afs/write.cfs/afs/write.c +1
-1@@ -846,7 +846,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)*/ #ifdef CONFIG_AFS_FSCACHE if (PageFsCache (page) && -wait_on_page_bit_killable (page, PG_fscache) <0 ) +wait_on_page_fscache_killable (page) <0 )return VM_FAULT_RETRY ;#endif
fs/afs/write.c vm_fault_t afs_page_mkwrite(struct vm_fault *vmf) · line 865
Quoted 6 lines
fs/afs/write.c +2
-1@@ -861,7 +861,8 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)* details the portion of the page we need to write back and we might * need to redirty the page if there's a problem. */ -wait_on_page_writeback (page); +if (wait_on_page_writeback_killable (page) <0 ) +return VM_FAULT_RETRY |VM_FAULT_LOCKED ;
You forgot to unlock the page. Also, if you're waiting killably here, do you need to wait before you get the page lock? Ditto for waiting on fscache -- do you want to do that before or after you get the page lock?
Also, I never quite understood why you needed to wait for fscache writes to finish before allowing the page to be dirtied. Is this a wait_for_stable_page() kind of situation, where the cache might be calculating a checksum on it? Because as far as I can tell, once the page is dirty in RAM, the contents of the on-disk cache are irrelevant ... unless they're part of a RAID 5 checksum kind of situation.
I didn't spot any other problems ...
David Howells
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 11 lines · Matthew Wilcox
Quoted 10 lines · David Howells
+++
b/fs/afs/write.cfs/afs/write.c +1
-1@@ -846,7 +846,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)*/ #ifdef CONFIG_AFS_FSCACHE if (PageFsCache (page) && -wait_on_page_bit_killable (page, PG_fscache) <0 ) +wait_on_page_fscache_killable (page) <0 )return VM_FAULT_RETRY ;#endif
Quoted 9 lines
fs/afs/write.c vm_fault_t afs_page_mkwrite(struct vm_fault *vmf) · line 865
Quoted 7 lines
fs/afs/write.c +2
-1@@ -861,7 +861,8 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)* details the portion of the page we need to write back and we might * need to redirty the page if there's a problem. */ -wait_on_page_writeback (page); +if (wait_on_page_writeback_killable (page) <0 ) +return VM_FAULT_RETRY |VM_FAULT_LOCKED ;You forgot to unlock the page.
Do I need to? Doesn't VM_FAULT_LOCKED indicate that to the caller? Or is it impermissible to do it like that?
Quoted 3 lines
Also, if you're waiting killably here, do you need to wait before you get the page lock? Ditto for waiting on fscache -- do you want to do that before or after you get the page lock?
I'm waiting both before and after. If I wait before, write() can go and trample over the page between PG_writeback/PG_fscache being cleared and us getting the lock here. Probably I should only be waiting after locking the page.
Quoted 6 lines
Also, I never quite understood why you needed to wait for fscache writes to finish before allowing the page to be dirtied. Is this a
wait_for_stable_page()kind of situation, where the cache might be calculating a checksum on it? Because as far as I can tell, once the page is dirty in RAM, the contents of the on-disk cache are irrelevant ... unless they're part of a RAID 5 checksum kind of situation.
Um. I do want to add disconnected operation in the future and cache encryption, but, as things currently stand, it isn't necessary because the cache object is marked "in use" and will be discarded on rebinding after a power loss or crash if it's still marked when it's opened again.
Also, the thought has occurred to me that I can make use of reflink copy to handle the caching of local modifications to cached files, in which case I'd rather have a clean copy to link from.
David
David Howells
maintainerRe: [PATCH v4 02/28] mm: Add an unlock function for PG_private_2/PG_fscache
Quoted 8 lines · David Howells
Quoted 5 lines
fs/afs/write.c vm_fault_t afs_page_mkwrite(struct vm_fault *vmf) · line 865
Quoted 3 lines
fs/afs/write.c +2
-1-wait_on_page_writeback (page); +if (wait_on_page_writeback_killable (page) <0 ) +return VM_FAULT_RETRY |VM_FAULT_LOCKED ;You forgot to unlock the page.
Do I need to? Doesn't
VM_FAULT_LOCKEDindicate that to the caller? Or is it impermissible to do it like that?
Looks like, yes, I do need to. VM_FAULT_LOCKED is ignored if RETRY is given.
David
David Howells
maintainerPATCH v4 3/28 mm: Implement readahead_control pageset expansion
In reply to David HowellsProvide a function, readahead_expand(), that expands the set of pages specified by a readahead_control object to encompass a revised area with a proposed size and length.
The proposed area must include all of the old area and may be expanded yet more by this function so that the edges align on (transparent huge) page boundaries as allocated.
The expansion will be cut short if a page already exists in either of the areas being expanded into. Note that any expansion made in such a case is not rolled back.
This will be used by fscache so that reads can be expanded to cache granule boundaries, thereby allowing whole granules to be stored in the cache, but there are other potential users also.
Changes:
- Moved the declaration of readahead_expand() to a better place[1].
---
include/linux/pagemap.h | 2 + mm/readahead.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
include/linux/pagemap.h +2 -0
@@ -818,6 +818,8 @@ void page_cache_sync_ra(struct readahead_control *, struct file_ra_state *, unsigned long req_count);void page_cache_async_ra (struct readahead_control *,struct file_ra_state *,struct page *,unsigned long req_count); +void readahead_expand (struct readahead_control *ractl, +loff_t new_start,size_t new_len);/** * page_cache_sync_readahead - generic file readahead
mm/readahead.c +70 -0
73 lines not on this page · raw message
David Howells
maintainerPATCH v4 4/28 netfs: Make a netfs helper module
In reply to David HowellsMake a netfs helper module to manage read request segmentation, caching support and transparent huge page support on behalf of a network filesystem.
---
fs/netfs/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 fs/netfs/Kconfig
fs/netfs/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config NETFS_SUPPORT + tristate "Support for network filesystem high-level I/O" + help + This option enables support for network filesystems, including + helpers for high-level buffered I/O, abstracting out read + segmentation, local caching and transparent huge page support.
David Howells
maintainerPATCH v4 5/28 netfs: Documentation for helper library
In reply to David HowellsAdd interface documentation for the netfs helper library.
---
Documentation/filesystems/index.rst | 1 Documentation/filesystems/netfs_library.rst | 526 +++++++++++++++++++++++++++ 2 files changed, 527 insertions(+) create mode 100644 Documentation/filesystems/netfs_library.rst
Documentation/filesystems/index.rst +1 -0
@@ -53,6 +53,7 @@ filesystem implementations. journalling fscrypt fsverity + netfs_library Filesystems ===========
Documentation/filesystems/netfs_library.rst new file +526 -0
526 lines not on this page · raw message
David Howells
maintainerPATCH v4 6/28 netfs, mm: Move PG_fscache helper funcs to linux/netfs.h
In reply to David HowellsMove the PG_fscache related helper funcs (such as SetPageFsCache()) to linux/netfs.h rather than linux/fscache.h as the intention is to move to a model where they're used by the network filesystem and the helper library, but not by fscache/cachefiles itself.
---
include/linux/fscache.h | 11 +---------- include/linux/netfs.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 include/linux/netfs.h
include/linux/fscache.h +1 -10
@@ -19,6 +19,7 @@#include <linux/pagemap.h> #include <linux/pagevec.h> #include <linux/list_bl.h> +#include <linux/netfs.h> #if defined(CONFIG_FSCACHE ) || defined(CONFIG_FSCACHE_MODULE )#define fscache_available () (1)
@@ -29,16 +30,6 @@#endif -/* -* overload PG_private_2 to give us PG_fscache - this is used to indicate that -* a page is currently backed by a local disk cache -*/ -#define PageFsCache (page) PagePrivate2((page)) -#define SetPageFsCache (page) SetPagePrivate2((page)) -#define ClearPageFsCache (page) ClearPagePrivate2((page)) -#define TestSetPageFsCache (page) TestSetPagePrivate2((page)) -#define TestClearPageFsCache (page) TestClearPagePrivate2((page)) -/* pattern used to fill dead space in an index entry */ #define FSCACHE_INDEX_DEADFILL_PATTERN 0x79
include/linux/netfs.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Network filesystem support services. +* +* Copyright (C) 2021 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* See: +* +* Documentation/filesystems/netfs_library.rst +* +* for a description of the network filesystem interface declared here. +*/ + +#ifndef _LINUX_NETFS_H +#define _LINUX_NETFS_H + +#include <linux/pagemap.h> + +/* +* Overload PG_private_2 to give us PG_fscache - this is used to indicate that +* a page is currently backed by a local disk cache +*/ +#define PageFsCache (page) PagePrivate2((page)) +#define SetPageFsCache (page) SetPagePrivate2((page)) +#define ClearPageFsCache (page) ClearPagePrivate2((page)) +#define TestSetPageFsCache (page) TestSetPagePrivate2((page)) +#define TestClearPageFsCache (page) TestClearPagePrivate2((page)) + +#endif /* _LINUX_NETFS_H */
David Howells
maintainerPATCH v4 7/28 netfs, mm: Add unlock_page_fscache() and wait_on_page_fscache()
In reply to David HowellsAdd unlock_page_fscache() as an alias of unlock_page_private_2(). This allows a page 'locked' with PG_fscache to be unlocked.
Add wait_on_page_fscache() to wait for PG_fscache to be unlocked.
[Linus suggested putting the fscache-themed functions into the
caching-specific headers rather than pagemap.h[1]]
---
include/linux/netfs.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
include/linux/netfs.h +29 -0
@@ -26,4 +26,33 @@#define TestSetPageFsCache (page) TestSetPagePrivate2((page))#define TestClearPageFsCache (page) TestClearPagePrivate2((page)) +/** +* unlock_page_fscache - Unlock a page that's locked with PG_fscache +* @page: The page +* +* Unlocks a page that's locked with PG_fscache and wakes up sleepers in +* wait_on_page_fscache(). This page bit is used by the netfs helpers when a +* netfs page is being written to a local disk cache, thereby allowing writes +* to the cache for the same page to be serialised. +*/ +static inline void unlock_page_fscache (struct page *page) +{ +unlock_page_private_2 (page); +} + +/** +* wait_on_page_fscache - Wait for PG_fscache to be cleared on a page +* @page: The page +* +* Wait for the PG_fscache (PG_private_2) page bit to be removed from a page. +* This is, for example, used to handle a netfs page being written to a local +* disk cache, thereby allowing writes to the cache for the same page to be +* serialised. +*/ +static inline void wait_on_page_fscache (struct page *page) +{ +if (PageFsCache (page)) +wait_on_page_bit (compound_head (page), PG_fscache); +} +#endif /* _LINUX_NETFS_H */
David Howells
maintainerPATCH v4 8/28 netfs: Provide readahead and readpage netfs helpers
In reply to David HowellsAdd a pair of helper functions:
(*) netfs_readahead()
(*) netfs_readpage()
to do the work of handling a readahead or a readpage, where the page(s) that form part of the request may be split between the local cache, the server or just require clearing, and may be single pages and transparent huge pages. This is all handled within the helper.
Note that while both will read from the cache if there is data present, only netfs_readahead() will expand the request beyond what it was asked to do, and only netfs_readahead() will write back to the cache.
netfs_readpage(), on the other hand, is synchronous and only fetches the page (which might be a THP) it is asked for.
The netfs gives the helper parameters from the VM, the cache cookie it wants to use (or NULL) and a table of operations (only one of which is mandatory):
(*) expand_readahead() [optional]
Called to allow the netfs to request an expansion of a readahead request to meet its own alignment requirements. This is done by changing rreq->start and rreq->len.
(*) clamp_length() [optional]
Called to allow the netfs to cut down a subrequest to meet its own boundary requirements. If it does this, the helper will generate additional subrequests until the full request is satisfied.
(*) is_still_valid() [optional]
Called to find out if the data just read from the cache has been invalidated and must be reread from the server.
(*) issue_op() [required]
Called to ask the netfs to issue a read to the server. The subrequest describes the read. The read request holds information about the file being accessed.
The netfs can cache information in rreq->netfs_priv.
Upon completion, the netfs should set the error, transferred and can also set FSCACHE_SREQ_CLEAR_TAIL and then call fscache_subreq_terminated().
(*) done() [optional]
Called after the pages have been unlocked. The read request is still pinning the file and mapping and may still be pinning pages with PG_fscache. rreq->error indicates any error that has been accumulated.
(*) cleanup() [optional]
Called when the helper is disposing of a finished read request. This allows the netfs to clear rreq->netfs_priv.
Netfs support is enabled with CONFIG_NETFS_SUPPORT=y. It will be built even if CONFIG_FSCACHE=n and in this case much of it should be optimised away, allowing the filesystem to use it even when caching is disabled.
Changes:
- Folded in a kerneldoc comment fix.
- Folded in a fix for the error handling in the case that ENOMEM occurs.
- Added flag to netfs_subreq_terminated() to indicate that the caller may have been running async and stuff that might sleep needs punting to a workqueue (can't use in_softirq()[1]).
---
fs/Kconfig | 1 fs/Makefile | 1 fs/netfs/Makefile | 6 fs/netfs/internal.h | 61 ++++ fs/netfs/read_helper.c | 717 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 82 +++++ 6 files changed, 868 insertions(+) create mode 100644 fs/netfs/Makefile create mode 100644 fs/netfs/internal.h create mode 100644 fs/netfs/read_helper.c
fs/Kconfig +1 -0
@@ -125,6 +125,7 @@ source "fs/overlayfs/Kconfig" menu "Caches" +source "fs/netfs/Kconfig" source "fs/fscache/Kconfig" source "fs/cachefiles/Kconfig"
fs/Makefile +1 -0
@@ -67,6 +67,7 @@ obj-y += devpts/ obj-$(CONFIG_DLM) += dlm/ # Do not add any filesystems before this line +obj-$(CONFIG_NETFS_SUPPORT) += netfs/ obj-$(CONFIG_FSCACHE) += fscache/ obj-$(CONFIG_REISERFS_FS) += reiserfs/ obj-$(CONFIG_EXT4_FS) += ext4/
fs/netfs/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +netfs-y := \ + read_helper.o + +obj-$(CONFIG_NETFS_SUPPORT) := netfs.o
fs/netfs/internal.h new file +61 -0
61 lines not on this page · raw message
fs/netfs/read_helper.c new file +717 -0
717 lines not on this page · raw message
include/linux/netfs.h +82 -0
92 lines not on this page · raw message
David Howells
maintainerRe: [PATCH v4 08/28] netfs: Provide readahead and readpage netfs helpers
I'm going to make the code generate more information when warning about a subread reporting having over-read (see attached).
David
---
fs/netfs/read_helper.c +4 -1
@@ -641,7 +641,10 @@ void netfs_subreq_terminated(struct netfs_read_subrequest *subreq, goto failed; } -if (WARN_ON (transferred_or_error > subreq->len - subreq->transferred)) +if (WARN (transferred_or_error > subreq->len - subreq->transferred, +"R%x[%x] %zd > %zu - %zu" , + rreq->debug_id, subreq->debug_index, + transferred_or_error, subreq->len, subreq->transferred)) transferred_or_error = subreq->len - subreq->transferred; subreq->error =0 ;
Matthew Wilcox
maintainerRe: [PATCH v4 08/28] netfs: Provide readahead and readpage netfs helpers
In reply to David HowellsQuoted 21 lines · David Howells
fs/netfs/read_helper.c new file +21
-0+void netfs_readahead (struct readahead_control *ractl, +const struct netfs_read_request_ops *ops, +void *netfs_priv) +{ +struct netfs_read_request *rreq; +struct page *page; +unsigned int debug_index =0 ; + +_enter ("%lx,%x" ,readahead_index (ractl),readahead_count (ractl)); + +if (readahead_count (ractl) ==0 ) + goto cleanup; + + rreq =netfs_alloc_read_request (ops, netfs_priv, ractl->file); +if (!rreq) + goto cleanup; + rreq->mapping = ractl->mapping; + rreq->start =readahead_pos (ractl); + rreq->len =readahead_length (ractl); + +netfs_rreq_expand (rreq, ractl);
fs/netfs/read_helper.c line 640
Quoted 10 lines
fs/netfs/read_helper.c new file +10
-0+ +atomic_set (&rreq->nr_rd_ops,1 ); +do { +if (!netfs_rreq_submit_slice (rreq, &debug_index)) +break ; + + }while (rreq->submitted < rreq->len); + +while ((page =readahead_page (ractl))) +put_page (page);
You don't need this pair of lines (unless I'm missing something). read_pages() in mm/readahead.c puts the reference and unlocks any pages which are not read by the readahead op. Indeed, I think doing this is buggy because you don't unlock the page.
Quoted 21 lines
fs/netfs/read_helper.c new file +20
-0+/* If we decrement nr_rd_ops to 0, the ref belongs to us. */ +if (atomic_dec_and_test (&rreq->nr_rd_ops)) +netfs_rreq_assess (rreq, false); +return ; + +cleanup: +if (netfs_priv) + ops->cleanup (ractl->mapping, netfs_priv); +return ; +} +EXPORT_SYMBOL (netfs_readahead); +int netfs_readpage (struct file *file, +struct page *page, +const struct netfs_read_request_ops *ops, +void *netfs_priv) +{ +struct netfs_read_request *rreq; +unsigned int debug_index =0 ; +int ret; +
fs/netfs/read_helper.c line 689
Quoted 10 lines
fs/netfs/read_helper.c new file +10
-0+_enter ("%lx" , page->index); + + rreq =netfs_alloc_read_request (ops, netfs_priv, file); +if (!rreq) { +if (netfs_priv) + ops->cleanup (netfs_priv, page->mapping); +unlock_page (page); +return -ENOMEM ; + } + rreq->mapping = page->mapping;
FYI, this isn't going to work with swap-over-NFS. You have to use page_file_mapping().
fs/netfs/read_helper.c line 690
Quoted 1 line
fs/netfs/read_helper.c new file +1
-0+ rreq->start = page->index *PAGE_SIZE ;
and page_index() here.
I rather dislike it that swap-over-NFS uses readpage which makes this need to exist. If somebody were to switch SWP_FS_OPS to using kiocbs, some of this pain could go away.
David Howells
maintainerRe: [PATCH v4 08/28] netfs: Provide readahead and readpage netfs helpers
Quoted 7 lines · Matthew Wilcox
fs/netfs/read_helper.c line 640
Quoted 2 lines
fs/netfs/read_helper.c new file +2
-0+while ((page =readahead_page (ractl))) +put_page (page);You don't need this pair of lines (unless I'm missing something).
read_pages()inmm/readahead.cputs the reference and unlocks any pages which are not read by the readahead op. Indeed, I think doing this is buggy because you don't unlock the page.
Actually, I do need them. The pages haven't been removed from the ractl at this point so just returning would cause them all to be unlocked prematurely.
I don't pass the ractl to the filesystem or the cache because I may be calling them for partial pages, I may be issuing multiple ops sequentially on a page and the ractl may have ceased to exist by the time I issue an op.
The unlocking is done by netfs_rreq_unlock(), even for pages that didn't get read.
I've added a comment to this effect.
David
David Howells
maintainerPATCH v4 9/28 netfs: Add tracepoints
In reply to David HowellsAdd three tracepoints to track the activity of the read helpers:
(1) netfs/netfs_read
This logs entry to the read helpers and also expansion of the range in a readahead request.
(2) netfs/netfs_rreq
This logs the progress of netfs_read_request objects which track read requests. A read request may be a compound of multiple subrequests.
(3) netfs/netfs_sreq
This logs the progress of netfs_read_subrequest objects, which track the contributions from various sources to a read request.
---
fs/netfs/read_helper.c | 28 ++++++ include/linux/netfs.h | 2 include/trace/events/netfs.h | 199 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 229 insertions(+) create mode 100644 include/trace/events/netfs.h
fs/netfs/read_helper.c +28 -0
@@ -16,6 +16,8 @@#include <linux/task_io_accounting_ops.h> #include <linux/netfs.h> #include "internal.h" +#define CREATE_TRACE_POINTS +#include <trace/events/netfs.h> MODULE_DESCRIPTION ("Network fs support" );MODULE_AUTHOR ("Red Hat, Inc." );
@@ -39,6 +41,7 @@ static struct netfs_read_request *netfs_alloc_read_request( const struct netfs_read_request_ops *ops, void *netfs_priv, struct file *file) { + static atomic_t debug_ids;struct netfs_read_request *rreq; rreq =kzalloc (sizeof (struct netfs_read_request ),GFP_KERNEL );
@@ -47,6 +50,7 @@ static struct netfs_read_request *netfs_alloc_read_request( rreq->netfs_priv = netfs_priv; rreq->inode =file_inode (file); rreq->i_size =i_size_read (rreq->inode); + rreq->debug_id =atomic_inc_return (&debug_ids);INIT_LIST_HEAD (&rreq->subrequests);INIT_WORK (&rreq->work, netfs_rreq_work);refcount_set (&rreq->usage,1 );
@@ -82,6 +86,7 @@ static void netfs_free_read_request(struct work_struct *work)netfs_rreq_clear_subreqs (rreq, false);if (rreq->netfs_priv) rreq->netfs_ops->cleanup (rreq->mapping, rreq->netfs_priv); +trace_netfs_rreq (rreq, netfs_rreq_trace_free);kfree (rreq); }
@@ -127,6 +132,7 @@ static void __netfs_put_subrequest(struct netfs_read_subrequest *subreq, {struct netfs_read_request *rreq = subreq->rreq; +trace_netfs_sreq (subreq, netfs_sreq_trace_free);kfree (subreq);netfs_put_read_request (rreq, was_async); }
@@ -181,6 +187,7 @@ static void netfs_read_from_server(struct netfs_read_request *rreq,*/ static void netfs_rreq_completed (struct netfs_read_request *rreq,bool was_async) { +trace_netfs_rreq (rreq, netfs_rreq_trace_done);netfs_rreq_clear_subreqs (rreq, was_async);netfs_put_read_request (rreq, was_async); }
@@ -219,6 +226,8 @@ static void netfs_rreq_unlock(struct netfs_read_request *rreq) iopos =0 ; subreq_failed = (subreq->error <0 ); +trace_netfs_rreq (rreq, netfs_rreq_trace_unlock); +rcu_read_lock ();xas_for_each (&xas, page, last_page) {unsigned int pgpos = (page->index - start_page) *PAGE_SIZE ;
@@ -279,6 +288,8 @@ static void netfs_rreq_short_read(struct netfs_read_request *rreq,__clear_bit (NETFS_SREQ_SHORT_READ , &subreq->flags);__set_bit (NETFS_SREQ_SEEK_DATA_READ , &subreq->flags); +trace_netfs_sreq (subreq, netfs_sreq_trace_resubmit_short); +netfs_get_read_subrequest (subreq);atomic_inc (&rreq->nr_rd_ops);netfs_read_from_server (rreq, subreq);
@@ -294,6 +305,8 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_read_request *rreq)WARN_ON (in_interrupt ()); +trace_netfs_rreq (rreq, netfs_rreq_trace_resubmit); +/* We don't want terminating submissions trying to wake us up whilst * we're still going through the list. */
@@ -306,6 +319,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_read_request *rreq)break ; subreq->source =NETFS_DOWNLOAD_FROM_SERVER ; subreq->error =0 ; +trace_netfs_sreq (subreq, netfs_sreq_trace_download_instead);netfs_get_read_subrequest (subreq);atomic_inc (&rreq->nr_rd_ops);netfs_read_from_server (rreq, subreq);
@@ -330,6 +344,8 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_read_request *rreq)*/ static void netfs_rreq_assess (struct netfs_read_request *rreq,bool was_async) { +trace_netfs_rreq (rreq, netfs_rreq_trace_assess); + again:if (!test_bit (NETFS_RREQ_FAILED , &rreq->flags) &&test_bit (NETFS_RREQ_INCOMPLETE_IO , &rreq->flags)) {
@@ -417,6 +433,8 @@ void netfs_subreq_terminated(struct netfs_read_subrequest *subreq,set_bit (NETFS_RREQ_WRITE_TO_CACHE , &rreq->flags); out: +trace_netfs_sreq (subreq, netfs_sreq_trace_terminated); +/* If we decrement nr_rd_ops to 0, the ref belongs to us. */ u =atomic_dec_return (&rreq->nr_rd_ops);if (u ==0 )
@@ -505,6 +523,7 @@ netfs_rreq_prepare_read(struct netfs_read_request *rreq, out: subreq->source = source; +trace_netfs_sreq (subreq, netfs_sreq_trace_prepare);return source; }
@@ -544,6 +563,7 @@ static bool netfs_rreq_submit_slice(struct netfs_read_request *rreq, rreq->submitted += subreq->len; +trace_netfs_sreq (subreq, netfs_sreq_trace_submit);switch (source) {case NETFS_FILL_WITH_ZEROES :netfs_fill_with_zeroes (rreq, subreq);
@@ -586,6 +606,9 @@ static void netfs_rreq_expand(struct netfs_read_request *rreq,readahead_expand (ractl, rreq->start, rreq->len); rreq->start =readahead_pos (ractl); rreq->len =readahead_length (ractl); + +trace_netfs_read (rreq,readahead_pos (ractl),readahead_length (ractl), + netfs_read_trace_expanded); } }
@@ -627,6 +650,9 @@ void netfs_readahead(struct readahead_control *ractl, rreq->start =readahead_pos (ractl); rreq->len =readahead_length (ractl); +trace_netfs_read (rreq,readahead_pos (ractl),readahead_length (ractl), + netfs_read_trace_readahead); +netfs_rreq_expand (rreq, ractl);atomic_set (&rreq->nr_rd_ops,1 );
@@ -690,6 +716,8 @@ int netfs_readpage(struct file *file, rreq->start = page->index *PAGE_SIZE ; rreq->len =thp_size (page); +trace_netfs_read (rreq, rreq->start, rreq->len, netfs_read_trace_readpage); +netfs_get_read_request (rreq);atomic_set (&rreq->nr_rd_ops,1 );
include/linux/netfs.h +2 -0
@@ -95,6 +95,8 @@ struct netfs_read_request {struct address_space *mapping;/* The mapping being accessed */ struct list_head subrequests;/* Requests to fetch I/O from disk or net */ void *netfs_priv;/* Private data for the netfs */ +unsigned int debug_id; +unsigned int cookie_debug_id;atomic_t nr_rd_ops;/* Number of read ops in progress */ size_t submitted;/* Amount submitted for I/O so far */ size_t len;/* Length of the request */
include/trace/events/netfs.h new file +199 -0
199 lines not on this page · raw message
David Howells
maintainerPATCH v4 10/28 netfs: Gather stats
In reply to David HowellsGather statistics from the netfs interface that can be exported through a seqfile. This is intended to be called by a later patch when viewing /proc/fs/fscache/stats.
---
fs/netfs/Kconfig | 15 +++++++++++++ fs/netfs/Makefile | 3 +-- fs/netfs/internal.h | 34 ++++++++++++++++++++++++++++++ fs/netfs/read_helper.c | 23 ++++++++++++++++++++ fs/netfs/stats.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 1 + 6 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 fs/netfs/stats.c
fs/netfs/Kconfig +15 -0
@@ -6,3 +6,18 @@ config NETFS_SUPPORT This option enables support for network filesystems, including helpers for high-level buffered I/O, abstracting out read segmentation, local caching and transparent huge page support. + +config NETFS_STATS + bool "Gather statistical information on local caching" + depends on NETFS_SUPPORT && PROC_FS + help + This option causes statistical information to be gathered on local + caching and exported through file: + + /proc/fs/fscache/stats + + The gathering of statistics adds a certain amount of overhead to + execution as there are a quite a few stats gathered, and on a + multi-CPU system these may be on cachelines that keep bouncing + between CPUs. On the other hand, the stats are very useful for + debugging purposes. Saying 'Y' here is recommended.
fs/netfs/Makefile +1 -2
@@ -1,6 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -netfs-y := \ - read_helper.o +netfs-y := read_helper.o stats.o obj-$(CONFIG_NETFS_SUPPORT) := netfs.o
fs/netfs/internal.h +34 -0
@@ -16,8 +16,42 @@*/ extern unsigned int netfs_debug; +/* +* stats.c +*/ +#ifdef CONFIG_NETFS_STATS +extern atomic_t netfs_n_rh_readahead; +extern atomic_t netfs_n_rh_readpage; +extern atomic_t netfs_n_rh_rreq; +extern atomic_t netfs_n_rh_sreq; +extern atomic_t netfs_n_rh_download; +extern atomic_t netfs_n_rh_download_done; +extern atomic_t netfs_n_rh_download_failed; +extern atomic_t netfs_n_rh_download_instead; +extern atomic_t netfs_n_rh_read; +extern atomic_t netfs_n_rh_read_done; +extern atomic_t netfs_n_rh_read_failed; +extern atomic_t netfs_n_rh_zero; +extern atomic_t netfs_n_rh_short_read; +extern atomic_t netfs_n_rh_write; +extern atomic_t netfs_n_rh_write_done; +extern atomic_t netfs_n_rh_write_failed; + + +static inline void netfs_stat (atomic_t *stat) +{ +atomic_inc (stat); +} + +static inline void netfs_stat_d (atomic_t *stat) +{ +atomic_dec (stat); +} + +#else #define netfs_stat (x) do {} while(0)#define netfs_stat_d (x) do {} while(0) +#endif /*****************************************************************************/ /*
fs/netfs/read_helper.c +23 -0
@@ -56,6 +56,7 @@ static struct netfs_read_request *netfs_alloc_read_request(refcount_set (&rreq->usage,1 );__set_bit (NETFS_RREQ_IN_PROGRESS , &rreq->flags); ops->init_rreq (rreq, file); +netfs_stat (&netfs_n_rh_rreq); }return rreq;
@@ -88,6 +89,7 @@ static void netfs_free_read_request(struct work_struct *work) rreq->netfs_ops->cleanup (rreq->mapping, rreq->netfs_priv);trace_netfs_rreq (rreq, netfs_rreq_trace_free);kfree (rreq); +netfs_stat_d (&netfs_n_rh_rreq); }static void netfs_put_read_request (struct netfs_read_request *rreq,bool was_async)
@@ -117,6 +119,7 @@ static struct netfs_read_subrequest *netfs_alloc_subrequest(refcount_set (&subreq->usage,2 ); subreq->rreq = rreq;netfs_get_read_request (rreq); +netfs_stat (&netfs_n_rh_sreq); }return subreq;
@@ -134,6 +137,7 @@ static void __netfs_put_subrequest(struct netfs_read_subrequest *subreq,trace_netfs_sreq (subreq, netfs_sreq_trace_free);kfree (subreq); +netfs_stat_d (&netfs_n_rh_sreq);netfs_put_read_request (rreq, was_async); }
@@ -156,6 +160,7 @@ static void netfs_clear_unread(struct netfs_read_subrequest *subreq)static void netfs_fill_with_zeroes (struct netfs_read_request *rreq,struct netfs_read_subrequest *subreq) { +netfs_stat (&netfs_n_rh_zero);__set_bit (NETFS_SREQ_CLEAR_TAIL , &subreq->flags);netfs_subreq_terminated (subreq,0 , false); }
@@ -179,6 +184,7 @@ static void netfs_fill_with_zeroes(struct netfs_read_request *rreq,static void netfs_read_from_server (struct netfs_read_request *rreq,struct netfs_read_subrequest *subreq) { +netfs_stat (&netfs_n_rh_download); rreq->netfs_ops->issue_op (subreq); }
@@ -288,6 +294,7 @@ static void netfs_rreq_short_read(struct netfs_read_request *rreq,__clear_bit (NETFS_SREQ_SHORT_READ , &subreq->flags);__set_bit (NETFS_SREQ_SEEK_DATA_READ , &subreq->flags); +netfs_stat (&netfs_n_rh_short_read);trace_netfs_sreq (subreq, netfs_sreq_trace_resubmit_short);netfs_get_read_subrequest (subreq);
@@ -319,6 +326,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_read_request *rreq)break ; subreq->source =NETFS_DOWNLOAD_FROM_SERVER ; subreq->error =0 ; +netfs_stat (&netfs_n_rh_download_instead);trace_netfs_sreq (subreq, netfs_sreq_trace_download_instead);netfs_get_read_subrequest (subreq);atomic_inc (&rreq->nr_rd_ops);
@@ -414,6 +422,17 @@ void netfs_subreq_terminated(struct netfs_read_subrequest *subreq, subreq->debug_index, subreq->start, subreq->flags, transferred_or_error); +switch (subreq->source) { +case NETFS_READ_FROM_CACHE : +netfs_stat (&netfs_n_rh_read_done); +break ; +case NETFS_DOWNLOAD_FROM_SERVER : +netfs_stat (&netfs_n_rh_download_done); +break ; +default : +break ; + } +if (IS_ERR_VALUE (transferred_or_error)) { subreq->error = transferred_or_error; goto failed;
@@ -467,8 +486,10 @@ void netfs_subreq_terminated(struct netfs_read_subrequest *subreq, failed:if (subreq->source ==NETFS_READ_FROM_CACHE ) { +netfs_stat (&netfs_n_rh_read_failed);set_bit (NETFS_RREQ_INCOMPLETE_IO , &rreq->flags); }else { +netfs_stat (&netfs_n_rh_download_failed);set_bit (NETFS_RREQ_FAILED , &rreq->flags); rreq->error = subreq->error; }
@@ -650,6 +671,7 @@ void netfs_readahead(struct readahead_control *ractl, rreq->start =readahead_pos (ractl); rreq->len =readahead_length (ractl); +netfs_stat (&netfs_n_rh_readahead);trace_netfs_read (rreq,readahead_pos (ractl),readahead_length (ractl), netfs_read_trace_readahead);
@@ -716,6 +738,7 @@ int netfs_readpage(struct file *file, rreq->start = page->index *PAGE_SIZE ; rreq->len =thp_size (page); +netfs_stat (&netfs_n_rh_readpage);trace_netfs_read (rreq, rreq->start, rreq->len, netfs_read_trace_readpage);netfs_get_read_request (rreq);
fs/netfs/stats.c new file +54 -0
54 lines not on this page · raw message
include/linux/netfs.h +1 -0
@@ -138,5 +138,6 @@ extern int netfs_readpage(struct file *, void *);extern void netfs_subreq_terminated (struct netfs_read_subrequest *,ssize_t ,bool ); +extern void netfs_stats_show (struct seq_file *);#endif /* _LINUX_NETFS_H */
David Howells
maintainerPATCH v4 11/28 netfs: Add write_begin helper
In reply to David HowellsAdd a helper to do the pre-reading work for the netfs write_begin address space op.
Changes
- Added flag to netfs_subreq_terminated() to indicate that the caller may have been running async and stuff that might sleep needs punting to a workqueue (can't use in_softirq()[1]).
---
fs/netfs/internal.h | 2 + fs/netfs/read_helper.c | 165 ++++++++++++++++++++++++++++++++++++++++++ fs/netfs/stats.c | 11 ++- include/linux/netfs.h | 8 ++ include/trace/events/netfs.h | 4 + 5 files changed, 186 insertions(+), 4 deletions(-)
fs/netfs/internal.h +2 -0
@@ -34,8 +34,10 @@ extern atomic_t netfs_n_rh_read_failed;extern atomic_t netfs_n_rh_zero;extern atomic_t netfs_n_rh_short_read;extern atomic_t netfs_n_rh_write; +extern atomic_t netfs_n_rh_write_begin;extern atomic_t netfs_n_rh_write_done;extern atomic_t netfs_n_rh_write_failed; +extern atomic_t netfs_n_rh_write_zskip;static inline void netfs_stat (atomic_t *stat)
fs/netfs/read_helper.c +165 -0
168 lines not on this page · raw message
fs/netfs/stats.c +8 -3
@@ -24,19 +24,24 @@ atomic_t netfs_n_rh_read_failed;atomic_t netfs_n_rh_zero;atomic_t netfs_n_rh_short_read;atomic_t netfs_n_rh_write; +atomic_t netfs_n_rh_write_begin;atomic_t netfs_n_rh_write_done;atomic_t netfs_n_rh_write_failed; +atomic_t netfs_n_rh_write_zskip;void netfs_stats_show (struct seq_file *m) { -seq_printf (m,"RdHelp : RA=%u RP=%u rr=%u sr=%u\n" , +seq_printf (m,"RdHelp : RA=%u RP=%u WB=%u WBZ=%u rr=%u sr=%u\n" ,atomic_read (&netfs_n_rh_readahead),atomic_read (&netfs_n_rh_readpage), +atomic_read (&netfs_n_rh_write_begin), +atomic_read (&netfs_n_rh_write_zskip),atomic_read (&netfs_n_rh_rreq),atomic_read (&netfs_n_rh_sreq)); -seq_printf (m,"RdHelp : ZR=%u sh=%u\n" , +seq_printf (m,"RdHelp : ZR=%u sh=%u sk=%u\n" ,atomic_read (&netfs_n_rh_zero), -atomic_read (&netfs_n_rh_short_read)); +atomic_read (&netfs_n_rh_short_read), +atomic_read (&netfs_n_rh_write_zskip)); seq_printf(m, "RdHelp : DL=%u ds=%u df=%u di=%u\n", atomic_read(&netfs_n_rh_download), atomic_read(&netfs_n_rh_download_done),
include/linux/netfs.h +8 -0
@@ -119,11 +119,14 @@ struct netfs_read_request {* Operations the network filesystem can/must provide to the helpers. */ struct netfs_read_request_ops { +bool (*is_cache_enabled)(struct inode *inode);void (*init_rreq)(struct netfs_read_request *rreq,struct file *file);void (*expand_readahead)(struct netfs_read_request *rreq);bool (*clamp_length)(struct netfs_read_subrequest *subreq);void (*issue_op)(struct netfs_read_subrequest *subreq);bool (*is_still_valid)(struct netfs_read_request *rreq); +int (*check_write_begin)(struct file *file,loff_t pos,unsigned len, +struct page *page,void **_fsdata);void (*done)(struct netfs_read_request *rreq);void (*cleanup)(struct address_space *mapping,void *netfs_priv); };
@@ -136,6 +139,11 @@ extern int netfs_readpage(struct file *, struct page *, const struct netfs_read_request_ops *, void *); +extern int netfs_write_begin (struct file *,struct address_space *, +loff_t ,unsigned int ,unsigned int ,struct page **, +void **, +const struct netfs_read_request_ops *, +void *);extern void netfs_subreq_terminated (struct netfs_read_subrequest *,ssize_t ,bool );extern void netfs_stats_show (struct seq_file *);
include/trace/events/netfs.h +3 -1
@@ -22,6 +22,7 @@ enum netfs_read_trace { netfs_read_trace_expanded, netfs_read_trace_readahead, netfs_read_trace_readpage, + netfs_read_trace_write_begin, }; enum netfs_rreq_trace {
@@ -50,7 +51,8 @@ enum netfs_sreq_trace {#define netfs_read_traces \ EM(netfs_read_trace_expanded, "EXPANDED ") \ EM(netfs_read_trace_readahead, "READAHEAD") \ - E_(netfs_read_trace_readpage, "READPAGE ") + EM(netfs_read_trace_readpage, "READPAGE ") \ + E_(netfs_read_trace_write_begin, "WRITEBEGN")#define netfs_rreq_traces \ EM(netfs_rreq_trace_assess, "ASSESS") \
David Howells
maintainerPATCH v4 12/28 netfs: Define an interface to talk to a cache
In reply to David HowellsAdd an interface to the netfs helper library for reading data from the cache instead of downloading it from the server and support for writing data just downloaded or cleared to the cache.
The API passes an iov_iter to the cache read/write routines to indicate the data/buffer to be used. This is done using the ITER_XARRAY type to provide direct access to the netfs inode's pagecache.
When the netfs's ->begin_cache_operation() method is called, this must fill in the cache_resources in the netfs_read_request struct, including the netfs_cache_ops used by the helper lib to talk to the cache. The helper lib does not directly access the cache.
Changes
- Added flag to netfs_subreq_terminated() to indicate that the caller may have been running async and stuff that might sleep needs punting to a workqueue (can't use in_softirq()[1]).
- Add missing inc of netfs_n_rh_read stat.
- Move initial definition of fscache_begin_read_operation() elsewhere.
- Need to call op->begin_cache_operation() from netfs_write_begin().
---
fs/netfs/read_helper.c | 241 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 49 ++++++++++ 2 files changed, 289 insertions(+), 1 deletion(-)
fs/netfs/read_helper.c +240 -1
@@ -88,6 +88,8 @@ static void netfs_free_read_request(struct work_struct *work)if (rreq->netfs_priv) rreq->netfs_ops->cleanup (rreq->mapping, rreq->netfs_priv);trace_netfs_rreq (rreq, netfs_rreq_trace_free); +if (rreq->cache_resources.ops) + rreq->cache_resources.ops->end_operation (&rreq->cache_resources);kfree (rreq);netfs_stat_d (&netfs_n_rh_rreq); }
@@ -154,6 +156,34 @@ static void netfs_clear_unread(struct netfs_read_subrequest *subreq)iov_iter_zero (iov_iter_count (&iter), &iter); } +static void netfs_cache_read_terminated (void *priv,ssize_t transferred_or_error, +bool was_async) +{ +struct netfs_read_subrequest *subreq = priv; + +netfs_subreq_terminated (subreq, transferred_or_error, was_async); +} + +/* +* Issue a read against the cache. +* - Eats the caller's ref on subreq. +*/ +static void netfs_read_from_cache (struct netfs_read_request *rreq, +struct netfs_read_subrequest *subreq, +bool seek_data) +{ +struct netfs_cache_resources *cres = &rreq->cache_resources; +struct iov_iter iter; + +netfs_stat (&netfs_n_rh_read); +iov_iter_xarray (&iter,READ , &rreq->mapping->i_pages, + subreq->start + subreq->transferred, + subreq->len - subreq->transferred); + + cres->ops->read (cres, subreq->start, &iter, seek_data, + netfs_cache_read_terminated, subreq); +} +/* * Fill a subrequest region with zeroes. */
@@ -198,6 +228,144 @@ static void netfs_rreq_completed(struct netfs_read_request *rreq, bool was_asyncnetfs_put_read_request (rreq, was_async); } +/* +* Deal with the completion of writing the data to the cache. We have to clear +* the PG_fscache bits on the pages involved and release the caller's ref. +* +* May be called in softirq mode and we inherit a ref from the caller. +*/ +static void netfs_rreq_unmark_after_write (struct netfs_read_request *rreq, +bool was_async) +{ +struct netfs_read_subrequest *subreq; +struct page *page; +pgoff_t unlocked =0 ; +bool have_unlocked = false; + +rcu_read_lock (); + +list_for_each_entry (subreq, &rreq->subrequests, rreq_link) { +XA_STATE (xas, &rreq->mapping->i_pages, subreq->start /PAGE_SIZE ); + +xas_for_each (&xas, page, (subreq->start + subreq->len -1 ) /PAGE_SIZE ) { +/* We might have multiple writes from the same huge +* page, but we mustn't unlock a page more than once. +*/ +if (have_unlocked && page->index <= unlocked) +continue ; + unlocked = page->index; +unlock_page_fscache (page); + have_unlocked = true; + } + } + +rcu_read_unlock (); +netfs_rreq_completed (rreq, was_async); +} + +static void netfs_rreq_copy_terminated (void *priv,ssize_t transferred_or_error, +bool was_async) +{ +struct netfs_read_subrequest *subreq = priv; +struct netfs_read_request *rreq = subreq->rreq; + +if (IS_ERR_VALUE (transferred_or_error)) { + subreq->error = transferred_or_error; +netfs_stat (&netfs_n_rh_write_failed); + }else { + subreq->error =0 ; +netfs_stat (&netfs_n_rh_write_done); + } + +trace_netfs_sreq (subreq, netfs_sreq_trace_write_term); + +/* If we decrement nr_wr_ops to 0, the ref belongs to us. */ +if (atomic_dec_and_test (&rreq->nr_wr_ops)) +netfs_rreq_unmark_after_write (rreq, was_async); + +netfs_put_subrequest (subreq, was_async); +} + +/* +* Perform any outstanding writes to the cache. We inherit a ref from the +* caller. +*/ +static void netfs_rreq_do_write_to_cache (struct netfs_read_request *rreq) +{ +struct netfs_cache_resources *cres = &rreq->cache_resources; +struct netfs_read_subrequest *subreq, *next, *p; +struct iov_iter iter; +loff_t pos; + +trace_netfs_rreq (rreq, netfs_rreq_trace_write); + +/* We don't want terminating writes trying to wake us up whilst we're +* still going through the list. +*/ +atomic_inc (&rreq->nr_wr_ops); + +list_for_each_entry_safe (subreq, p, &rreq->subrequests, rreq_link) { +if (!test_bit (NETFS_SREQ_WRITE_TO_CACHE , &subreq->flags)) { +list_del_init (&subreq->rreq_link); +netfs_put_subrequest (subreq, false); + } + } + +list_for_each_entry (subreq, &rreq->subrequests, rreq_link) { +/* Amalgamate adjacent writes */ + pos =round_down (subreq->start,PAGE_SIZE ); +if (pos != subreq->start) { + subreq->len += subreq->start - pos; + subreq->start = pos; + } + subreq->len =round_up (subreq->len,PAGE_SIZE ); + +while (!list_is_last (&subreq->rreq_link, &rreq->subrequests)) { + next =list_next_entry (subreq, rreq_link); +if (next->start > subreq->start + subreq->len) +break ; + subreq->len += next->len; + subreq->len =round_up (subreq->len,PAGE_SIZE ); +list_del_init (&next->rreq_link); +netfs_put_subrequest (next, false); + } + +iov_iter_xarray (&iter,WRITE , &rreq->mapping->i_pages, + subreq->start, subreq->len); + +atomic_inc (&rreq->nr_wr_ops); +netfs_stat (&netfs_n_rh_write); +netfs_get_read_subrequest (subreq); +trace_netfs_sreq (subreq, netfs_sreq_trace_write); + cres->ops->write (cres, subreq->start, &iter, + netfs_rreq_copy_terminated, subreq); + } + +/* If we decrement nr_wr_ops to 0, the usage ref belongs to us. */ +if (atomic_dec_and_test (&rreq->nr_wr_ops)) +netfs_rreq_unmark_after_write (rreq, false); +} + +static void netfs_rreq_write_to_cache_work (struct work_struct *work) +{ +struct netfs_read_request *rreq = + container_of(work, struct netfs_read_request, work); + +netfs_rreq_do_write_to_cache (rreq); +} + +static void netfs_rreq_write_to_cache (struct netfs_read_request *rreq, +bool was_async) +{ +if (was_async) { + rreq->work.func = netfs_rreq_write_to_cache_work; +if (!queue_work (system_unbound_wq, &rreq->work)) +BUG (); + }else { +netfs_rreq_do_write_to_cache (rreq); + } +} +/* * Unlock the pages in a read operation. We need to set PG_fscache on any * pages we're going to write back before we unlock them.
@@ -299,7 +467,10 @@ static void netfs_rreq_short_read(struct netfs_read_request *rreq,netfs_get_read_subrequest (subreq);atomic_inc (&rreq->nr_rd_ops); -netfs_read_from_server (rreq, subreq); +if (subreq->source ==NETFS_READ_FROM_CACHE ) +netfs_read_from_cache (rreq, subreq, true); +else +netfs_read_from_server (rreq, subreq); }/*
@@ -344,6 +515,25 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_read_request *rreq)return false; } +/* +* Check to see if the data read is still valid. +*/ +static void netfs_rreq_is_still_valid (struct netfs_read_request *rreq) +{ +struct netfs_read_subrequest *subreq; + +if (!rreq->netfs_ops->is_still_valid || + rreq->netfs_ops->is_still_valid (rreq)) +return ; + +list_for_each_entry (subreq, &rreq->subrequests, rreq_link) { +if (subreq->source ==NETFS_READ_FROM_CACHE ) { + subreq->error = -ESTALE ; +__set_bit (NETFS_RREQ_INCOMPLETE_IO , &rreq->flags); + } + } +} +/* * Assess the state of a read request and decide what to do next. *
@@ -355,6 +545,8 @@ static void netfs_rreq_assess(struct netfs_read_request *rreq, bool was_async)trace_netfs_rreq (rreq, netfs_rreq_trace_assess); again: +netfs_rreq_is_still_valid (rreq); +if (!test_bit (NETFS_RREQ_FAILED , &rreq->flags) &&test_bit (NETFS_RREQ_INCOMPLETE_IO , &rreq->flags)) {if (netfs_rreq_perform_resubmissions (rreq))
@@ -367,6 +559,9 @@ static void netfs_rreq_assess(struct netfs_read_request *rreq, bool was_async)clear_bit_unlock (NETFS_RREQ_IN_PROGRESS , &rreq->flags);wake_up_bit (&rreq->flags,NETFS_RREQ_IN_PROGRESS ); +if (test_bit (NETFS_RREQ_WRITE_TO_CACHE , &rreq->flags)) +return netfs_rreq_write_to_cache (rreq, was_async); +netfs_rreq_completed (rreq, was_async); }
@@ -501,7 +696,10 @@ static enum netfs_read_source netfs_cache_prepare_read(struct netfs_read_subrequ loff_t i_size) {struct netfs_read_request *rreq = subreq->rreq; +struct netfs_cache_resources *cres = &rreq->cache_resources; +if (cres->ops) +return cres->ops->prepare_read (subreq, i_size);if (subreq->start >= rreq->i_size)return NETFS_FILL_WITH_ZEROES ;return NETFS_DOWNLOAD_FROM_SERVER ;
@@ -592,6 +790,9 @@ static bool netfs_rreq_submit_slice(struct netfs_read_request *rreq,case NETFS_DOWNLOAD_FROM_SERVER :netfs_read_from_server (rreq, subreq);break ; +case NETFS_READ_FROM_CACHE : +netfs_read_from_cache (rreq, subreq, false); +break ;default :BUG (); }
@@ -604,9 +805,23 @@ static bool netfs_rreq_submit_slice(struct netfs_read_request *rreq,return false; } +static void netfs_cache_expand_readahead (struct netfs_read_request *rreq, +loff_t *_start,size_t *_len,loff_t i_size) +{ +struct netfs_cache_resources *cres = &rreq->cache_resources; + +if (cres->ops && cres->ops->expand_readahead) + cres->ops->expand_readahead (cres, _start, _len, i_size); +} +static void netfs_rreq_expand (struct netfs_read_request *rreq,struct readahead_control *ractl) { +/* Give the cache a chance to change the request parameters. The +* resultant request must contain the original region. +*/ +netfs_cache_expand_readahead (rreq, &rreq->start, &rreq->len, rreq->i_size); +/* Give the netfs a chance to change the request parameters. The * resultant request must contain the original region. */
@@ -658,6 +873,7 @@ void netfs_readahead(struct readahead_control *ractl,struct netfs_read_request *rreq;struct page *page;unsigned int debug_index =0 ; +int ret;_enter ("%lx,%x" ,readahead_index (ractl),readahead_count (ractl));
@@ -675,6 +891,11 @@ void netfs_readahead(struct readahead_control *ractl,trace_netfs_read (rreq,readahead_pos (ractl),readahead_length (ractl), netfs_read_trace_readahead); +if (ops->begin_cache_operation) { + ret = ops->begin_cache_operation (rreq); +if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS ) + goto cleanup_free; + }netfs_rreq_expand (rreq, ractl);atomic_set (&rreq->nr_rd_ops,1 );
@@ -692,6 +913,9 @@ void netfs_readahead(struct readahead_control *ractl,netfs_rreq_assess (rreq, false);return ; +cleanup_free: +netfs_put_read_request (rreq, false); +return ; cleanup:if (netfs_priv) ops->cleanup (ractl->mapping, netfs_priv);
@@ -741,6 +965,14 @@ int netfs_readpage(struct file *file,netfs_stat (&netfs_n_rh_readpage);trace_netfs_read (rreq, rreq->start, rreq->len, netfs_read_trace_readpage); +if (ops->begin_cache_operation) { + ret = ops->begin_cache_operation (rreq); +if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS ) { +unlock_page (page); + goto out; + } + } +netfs_get_read_request (rreq);atomic_set (&rreq->nr_rd_ops,1 );
@@ -762,6 +994,7 @@ int netfs_readpage(struct file *file, ret = rreq->error;if (ret ==0 && rreq->submitted < rreq->len) ret = -EIO ; +out:netfs_put_read_request (rreq, false);return ret; }
@@ -875,6 +1108,12 @@ int netfs_write_begin(struct file *file, struct address_space *mapping,netfs_stat (&netfs_n_rh_write_begin);trace_netfs_read (rreq, pos, len, netfs_read_trace_write_begin); +if (ops->begin_cache_operation) { + ret = ops->begin_cache_operation (rreq); +if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS ) + goto error; + } +/* Expand the request to meet caching requirements and download * preferences. */
include/linux/netfs.h +49 -0
78 lines not on this page · raw message
David Howells
maintainerPATCH v4 13/28 netfs: Hold a ref on a page when PG_private_2 is set
In reply to David HowellsTake a reference on a page when PG_private_2 is set and drop it once the bit is unlocked[1].
---
fs/netfs/read_helper.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/netfs/read_helper.c +9 -1
@@ -10,6 +10,7 @@#include <linux/fs.h> #include <linux/mm.h> #include <linux/pagemap.h> +#include <linux/pagevec.h> #include <linux/slab.h> #include <linux/uio.h> #include <linux/sched/mm.h>
@@ -238,10 +239,13 @@ static void netfs_rreq_unmark_after_write(struct netfs_read_request *rreq, bool was_async) {struct netfs_read_subrequest *subreq; +struct pagevec pvec;struct page *page;pgoff_t unlocked =0 ;bool have_unlocked = false; +pagevec_init (&pvec); +rcu_read_lock ();list_for_each_entry (subreq, &rreq->subrequests, rreq_link) {
@@ -255,6 +259,8 @@ static void netfs_rreq_unmark_after_write(struct netfs_read_request *rreq,continue ; unlocked = page->index;unlock_page_fscache (page); +if (pagevec_add (&pvec, page) ==0 ) +pagevec_release (&pvec); have_unlocked = true; } }
@@ -413,8 +419,10 @@ static void netfs_rreq_unlock(struct netfs_read_request *rreq) pg_failed = true;break ; } -if (test_bit (NETFS_SREQ_WRITE_TO_CACHE , &subreq->flags)) +if (test_bit (NETFS_SREQ_WRITE_TO_CACHE , &subreq->flags)) { +get_page (page);SetPageFsCache (page); + } pg_failed |= subreq_failed;if (pgend < iopos + subreq->len)break ;
David Howells
maintainerPATCH v4 14/28 fscache, cachefiles: Add alternate API to use kiocb for read/write to cache
In reply to David HowellsAdd an alternate API by which the cache can be accessed through a kiocb, doing async DIO, rather than using the current API that tells the cache where all the pages are.
The new API is intended to be used in conjunction with the netfs helper library. A filesystem must pick one or the other and not mix them.
Filesystems wanting to use the new API must #define FSCACHE_USE_NEW_IO_API before #including the header. This prevents them from continuing to use the old API at the same time as there are incompatibilities in how the PG_fscache page bit is used.
Changes:
- Use the vfs_iocb_iter_read/write() helpers[1]
- Move initial definition of fscache_begin_read_operation() here.
- Remove a commented-out line[2]
- Combine ki->term_func calls in cachefiles_read_complete()[2].
- Remove explicit NULL initialiser[2].
- Remove extern on func decl[2].
- Put in param names on func decl[2].
- Remove redundant else[2].
- Fill out the kdoc comment for fscache_begin_read_operation().
- Rename fs/fscache/page2.c to io.c to match later patches.
---
fs/cachefiles/Makefile | 1 fs/cachefiles/interface.c | 5 - fs/cachefiles/internal.h | 9 + fs/cachefiles/rdwr2.c | 403 +++++++++++++++++++++++++++++++++++++++++ fs/fscache/Kconfig | 1 fs/fscache/Makefile | 1 fs/fscache/internal.h | 4 fs/fscache/io.c | 116 ++++++++++++ fs/fscache/page.c | 2 fs/fscache/stats.c | 1 include/linux/fscache-cache.h | 4 include/linux/fscache.h | 39 ++++ 12 files changed, 583 insertions(+), 3 deletions(-) create mode 100644 fs/cachefiles/rdwr2.c create mode 100644 fs/fscache/io.c
fs/cachefiles/Makefile +1 -0
@@ -11,6 +11,7 @@ cachefiles-y := \ main.o \ namei.o \ rdwr.o \ + rdwr2.o \ security.o \ xattr.o
fs/cachefiles/interface.c +3 -2
@@ -319,8 +319,8 @@ static void cachefiles_drop_object(struct fscache_object *_object)/* * dispose of a reference to an object */ -static void cachefiles_put_object (struct fscache_object *_object, -enum fscache_obj_ref_trace why) +void cachefiles_put_object (struct fscache_object *_object, +enum fscache_obj_ref_trace why) {struct cachefiles_object *object;struct fscache_cache *cache;
@@ -568,4 +568,5 @@ const struct fscache_cache_ops cachefiles_cache_ops = { .uncache_page = cachefiles_uncache_page, .dissociate_pages = cachefiles_dissociate_pages, .check_consistency = cachefiles_check_consistency, + .begin_read_operation = cachefiles_begin_read_operation, };
fs/cachefiles/internal.h +9 -0
@@ -150,6 +150,9 @@ extern int cachefiles_has_space(struct cachefiles_cache *cache,*/ extern const struct fscache_cache_ops cachefiles_cache_ops; +void cachefiles_put_object (struct fscache_object *_object, +enum fscache_obj_ref_trace why); +/* * key.c */
@@ -217,6 +220,12 @@ extern int cachefiles_allocate_pages(struct fscache_retrieval *,extern int cachefiles_write_page (struct fscache_storage *,struct page *);extern void cachefiles_uncache_page (struct fscache_object *,struct page *); +/* +* rdwr2.c +*/ +extern int cachefiles_begin_read_operation (struct netfs_read_request *, +struct fscache_retrieval *); +/* * security.c */
fs/cachefiles/rdwr2.c new file +403 -0
403 lines not on this page · raw message
fs/fscache/Kconfig +1 -0
@@ -2,6 +2,7 @@ config FSCACHE tristate "General filesystem local caching manager" + select NETFS_SUPPORT help This option enables a generic filesystem caching manager that can be used by various network and other filesystems to cache data locally.
fs/fscache/Makefile +1 -0
@@ -7,6 +7,7 @@ fscache-y := \ cache.o \ cookie.o \ fsdef.o \ + io.o \ main.o \ netfs.o \ object.o \
fs/fscache/internal.h +4 -0
@@ -142,6 +142,10 @@ extern int fscache_wait_for_operation_activation(struct fscache_object *, atomic_t *, atomic_t *);extern void fscache_invalidate_writes (struct fscache_cookie *); +struct fscache_retrieval *fscache_alloc_retrieval (struct fscache_cookie *cookie, +struct address_space *mapping, +fscache_rw_complete_t end_io_func, +void *context);/* * proc.c
fs/fscache/io.c new file +116 -0
116 lines not on this page · raw message
fs/fscache/page.c +1 -1
@@ -299,7 +299,7 @@ static void fscache_release_retrieval_op(struct fscache_operation *_op)/* * allocate a retrieval op */ -static struct fscache_retrieval *fscache_alloc_retrieval( +struct fscache_retrieval *fscache_alloc_retrieval( struct fscache_cookie *cookie, struct address_space *mapping, fscache_rw_complete_t end_io_func,
fs/fscache/stats.c +1 -0
@@ -278,5 +278,6 @@ int fscache_stats_show(struct seq_file *m, void *v)atomic_read (&fscache_n_cache_stale_objects),atomic_read (&fscache_n_cache_retired_objects), atomic_read(&fscache_n_cache_culled_objects)); +netfs_stats_show (m);return 0 ; }
include/linux/fscache-cache.h +4 -0
@@ -304,6 +304,10 @@ struct fscache_cache_ops {/* dissociate a cache from all the pages it was backing */ void (*dissociate_pages)(struct fscache_cache *cache); + +/* Begin a read operation for the netfs lib */ +int (*begin_read_operation)(struct netfs_read_request *rreq, +struct fscache_retrieval *op); };extern struct fscache_cookie fscache_fsdef_index;
include/linux/fscache.h +39 -0
@@ -37,6 +37,7 @@ struct pagevec;struct fscache_cache_tag ;struct fscache_cookie ;struct fscache_netfs ; +struct netfs_read_request ; typedef void (*fscache_rw_complete_t)(struct page *page, void *context,
@@ -191,6 +192,10 @@ extern void __fscache_update_cookie(struct fscache_cookie *, const void *);extern int __fscache_attr_changed (struct fscache_cookie *);extern void __fscache_invalidate (struct fscache_cookie *);extern void __fscache_wait_on_invalidate (struct fscache_cookie *); + +#ifdef FSCACHE_USE_NEW_IO_API +extern int __fscache_begin_read_operation (struct netfs_read_request *,struct fscache_cookie *); +#else extern int __fscache_read_or_alloc_page(struct fscache_cookie *, struct page *, fscache_rw_complete_t,
@@ -214,6 +219,8 @@ extern void __fscache_uncache_all_inode_pages(struct fscache_cookie *, struct inode *);extern void __fscache_readpages_cancel (struct fscache_cookie *cookie,struct list_head *pages); +#endif /* FSCACHE_USE_NEW_IO_API */ +extern void __fscache_disable_cookie (struct fscache_cookie *,const void *,bool );extern void __fscache_enable_cookie (struct fscache_cookie *,const void *,loff_t ,bool (*)(void *),void *);
@@ -498,6 +505,36 @@ int fscache_reserve_space(struct fscache_cookie *cookie, loff_t size)return -ENOBUFS ; } +#ifdef FSCACHE_USE_NEW_IO_API + +/** +* fscache_begin_read_operation - Begin a read operation for the netfs lib +* @rreq: The read request being undertaken +* @cookie: The cookie representing the cache object +* +* Begin a read operation on behalf of the netfs helper library. @rreq +* indicates the read request to which the operation state should be attached; +* @cookie indicates the cache object that will be accessed. +* +* This is intended to be called from the ->begin_cache_operation() netfs lib +* operation as implemented by the network filesystem. +* +* Returns: +* * 0 - Success +* * -ENOBUFS - No caching available +* * Other error code from the cache, such as -ENOMEM. +*/ +static inline +int fscache_begin_read_operation (struct netfs_read_request *rreq, +struct fscache_cookie *cookie) +{ +if (fscache_cookie_valid (cookie) &&fscache_cookie_enabled (cookie)) +return __fscache_begin_read_operation (rreq, cookie); +return -ENOBUFS ; +} + +#else /* FSCACHE_USE_NEW_IO_API */ +/** * fscache_read_or_alloc_page - Read a page from the cache or allocate a block * in which to store it
@@ -777,6 +814,8 @@ void fscache_uncache_all_inode_pages(struct fscache_cookie *cookie, __fscache_uncache_all_inode_pages(cookie, inode); } +#endif /* FSCACHE_USE_NEW_IO_API */ +/** * fscache_disable_cookie - Disable a cookie * @cookie: The cookie representing the cache object
David Howells
maintainerPATCH v4 15/28 afs: Disable use of the fscache I/O routines
In reply to David HowellsDisable use of the fscache I/O routined by the AFS filesystem. It's about to transition to passing iov_iters down and fscache is about to have its I/O path to use iov_iter, so all that needs to change.
---
fs/afs/file.c | 199 ++++++++++---------------------------------------------- fs/afs/inode.c | 2 - fs/afs/write.c | 10 --- 3 files changed, 36 insertions(+), 175 deletions(-)
fs/afs/file.c +35 -164
@@ -203,24 +203,6 @@ void afs_put_read(struct afs_read *req) } } -#ifdef CONFIG_AFS_FSCACHE -/* -* deal with notification that a page was read from the cache -*/ -static void afs_file_readpage_read_complete (struct page *page, -void *data, -int error) -{ -_enter ("%p,%p,%d" , page, data, error); - -/* if the read completes with an error, we just unlock the page and let -* the VM reissue the readpage */ -if (!error) -SetPageUptodate (page); -unlock_page (page); -} -#endif -static void afs_fetch_data_success (struct afs_operation *op) {struct afs_vnode *vnode = op->file[0 ].vnode;
@@ -288,89 +270,46 @@ int afs_page_filler(void *data, struct page *page)if (test_bit (AFS_VNODE_DELETED , &vnode->flags)) goto error; -/* is it cached? */ -#ifdef CONFIG_AFS_FSCACHE - ret =fscache_read_or_alloc_page (vnode->cache, - page, - afs_file_readpage_read_complete, -NULL , -GFP_KERNEL ); -#else - ret = -ENOBUFS ; -#endif -switch (ret) { -/* read BIO submitted (page in cache) */ -case 0 : -break ; - -/* page not yet cached */ -case -ENODATA : -_debug ("cache said ENODATA" ); - goto go_on; - -/* page will not be cached */ -case -ENOBUFS : -_debug ("cache said ENOBUFS" ); - - fallthrough; -default : - go_on: - req =kzalloc (struct_size (req, array,1 ),GFP_KERNEL ); -if (!req) - goto enomem; - -/* We request a full page. If the page is a partial one at the -* end of the file, the server will return a short read and the -* unmarshalling code will clear the unfilled space. -*/ -refcount_set (&req->usage,1 ); - req->pos = (loff_t )page->index <<PAGE_SHIFT ; - req->len =PAGE_SIZE ; - req->nr_pages =1 ; - req->pages = req->array; - req->pages[0 ] = page; -get_page (page); - -/* read the contents of the file from the server into the -* page */ - ret =afs_fetch_data (vnode, key, req); -afs_put_read (req); - -if (ret <0 ) { -if (ret == -ENOENT ) { -_debug ("got NOENT from server" -" - marking file deleted and stale" ); -set_bit (AFS_VNODE_DELETED , &vnode->flags); - ret = -ESTALE ; - } - -#ifdef CONFIG_AFS_FSCACHE -fscache_uncache_page (vnode->cache, page); -#endif -BUG_ON (PageFsCache (page)); - -if (ret == -EINTR || - ret == -ENOMEM || - ret == -ERESTARTSYS || - ret == -EAGAIN ) - goto error; - goto io_error; - } + req =kzalloc (struct_size (req, array,1 ),GFP_KERNEL ); +if (!req) + goto enomem; -SetPageUptodate (page); +/* We request a full page. If the page is a partial one at the +* end of the file, the server will return a short read and the +* unmarshalling code will clear the unfilled space. +*/ +refcount_set (&req->usage,1 ); + req->pos = (loff_t )page->index <<PAGE_SHIFT ; + req->len =PAGE_SIZE ; + req->nr_pages =1 ; + req->pages = req->array; + req->pages[0 ] = page; +get_page (page); + +/* read the contents of the file from the server into the +* page */ + ret =afs_fetch_data (vnode, key, req); +afs_put_read (req); -/* send the page to the cache */ -#ifdef CONFIG_AFS_FSCACHE -if (PageFsCache (page) && -fscache_write_page (vnode->cache, page, vnode->status.size, -GFP_KERNEL ) !=0 ) { -fscache_uncache_page (vnode->cache, page); -BUG_ON (PageFsCache (page)); +if (ret <0 ) { +if (ret == -ENOENT ) { +_debug ("got NOENT from server" +" - marking file deleted and stale" ); +set_bit (AFS_VNODE_DELETED , &vnode->flags); + ret = -ESTALE ; } -#endif -unlock_page (page); + +if (ret == -EINTR || + ret == -ENOMEM || + ret == -ERESTARTSYS || + ret == -EAGAIN ) + goto error; + goto io_error; } +SetPageUptodate (page); +unlock_page (page); +_leave (" = 0" );return 0 ;
@@ -416,23 +355,10 @@ static int afs_readpage(struct file *file, struct page *page)*/ static void afs_readpages_page_done (struct afs_read *req) { -#ifdef CONFIG_AFS_FSCACHE -struct afs_vnode *vnode = req->vnode; -#endif struct page *page = req->pages[req->index]; req->pages[req->index] =NULL ;SetPageUptodate (page); - -/* send the page to the cache */ -#ifdef CONFIG_AFS_FSCACHE -if (PageFsCache (page) && -fscache_write_page (vnode->cache, page, vnode->status.size, -GFP_KERNEL ) !=0 ) { -fscache_uncache_page (vnode->cache, page); -BUG_ON (PageFsCache (page)); - } -#endif unlock_page (page);put_page (page); }
@@ -491,9 +417,6 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping, index = page->index;if (add_to_page_cache_lru (page, mapping, index,readahead_gfp_mask (mapping))) { -#ifdef CONFIG_AFS_FSCACHE -fscache_uncache_page (vnode->cache, page); -#endif put_page (page);break ; }
@@ -526,9 +449,6 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,for (i =0 ; i < req->nr_pages; i++) { page = req->pages[i];if (page) { -#ifdef CONFIG_AFS_FSCACHE -fscache_uncache_page (vnode->cache, page); -#endif SetPageError (page);unlock_page (page); }
@@ -560,37 +480,6 @@ static int afs_readpages(struct file *file, struct address_space *mapping, }/* attempt to read as many of the pages as possible */ -#ifdef CONFIG_AFS_FSCACHE - ret =fscache_read_or_alloc_pages (vnode->cache, - mapping, - pages, - &nr_pages, - afs_file_readpage_read_complete, -NULL , -mapping_gfp_mask (mapping)); -#else - ret = -ENOBUFS ; -#endif - -switch (ret) { -/* all pages are being read from the cache */ -case 0 : -BUG_ON (!list_empty (pages)); -BUG_ON (nr_pages !=0 ); -_leave (" = 0 [reading all]" ); -return 0 ; - -/* there were pages that couldn't be read from the cache */ -case -ENODATA : -case -ENOBUFS : -break ; - -/* other error */ -default : -_leave (" = %d" , ret); -return ret; - } -while (!list_empty (pages)) { ret =afs_readpages_one (file, mapping, pages);if (ret <0 )
@@ -670,17 +559,6 @@ static void afs_invalidatepage(struct page *page, unsigned int offset,BUG_ON (!PageLocked (page)); -#ifdef CONFIG_AFS_FSCACHE -/* we clean up only if the entire page is being invalidated */ -if (offset ==0 && length ==PAGE_SIZE ) { -if (PageFsCache (page)) { -struct afs_vnode *vnode =AFS_FS_I (page->mapping->host); -fscache_wait_on_page_write (vnode->cache, page); -fscache_uncache_page (vnode->cache, page); - } - } -#endif -if (PagePrivate (page))afs_invalidate_dirty (page, offset, length);
@@ -702,13 +580,6 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)/* deny if page is being written to the cache and the caller hasn't * elected to wait */ -#ifdef CONFIG_AFS_FSCACHE -if (!fscache_maybe_release_page (vnode->cache, page, gfp_flags)) { -_leave (" = F [cache busy]" ); -return 0 ; - } -#endif -if (PagePrivate (page)) { priv = (unsigned long )detach_page_private (page); trace_afs_page_dirty(vnode, tracepoint_string("rel"),
fs/afs/inode.c +1 -1
@@ -428,7 +428,7 @@ static void afs_get_inode_cache(struct afs_vnode *vnode) }__packed key;struct afs_vnode_cache_aux aux; -if (vnode->status.type ==AFS_FTYPE_DIR ) { +if (vnode->status.type !=AFS_FTYPE_FILE ) { vnode->cache =NULL ;return ; }
fs/afs/write.c +0 -10
@@ -847,9 +847,6 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)/* Wait for the page to be written to the cache before we allow it to * be modified. We then assume the entire page will need writing back. */ -#ifdef CONFIG_AFS_FSCACHE -fscache_wait_on_page_write (vnode->cache, vmf->page); -#endif if (PageWriteback (vmf->page) &&wait_on_page_bit_killable (vmf->page, PG_writeback) <0 )
@@ -936,12 +933,5 @@ int afs_launder_page(struct page *page) priv = (unsigned long )detach_page_private (page);trace_afs_page_dirty (vnode,tracepoint_string ("laundered" ), page->index, priv); - -#ifdef CONFIG_AFS_FSCACHE -if (PageFsCache (page)) { -fscache_wait_on_page_write (vnode->cache, page); -fscache_uncache_page (vnode->cache, page); - } -#endif return ret; }
David Howells
maintainerPATCH v4 16/28 afs: Pass page into dirty region helpers to provide THP size
In reply to David HowellsPass a pointer to the page being accessed into the dirty region helpers so that the size of the page can be determined in case it's a transparent huge page.
This also required the page to be passed into the afs_page_dirty trace point - so there's no need to specifically pass in the index or private data as these can be retrieved directly from the page struct.
---
fs/afs/file.c | 20 +++++++-------- fs/afs/internal.h | 16 ++++++------ fs/afs/write.c | 60 ++++++++++++++++++-------------------------- include/trace/events/afs.h | 23 ++++++++++------- 4 files changed, 55 insertions(+), 64 deletions(-)
fs/afs/file.c +9 -11
@@ -515,8 +515,8 @@ static void afs_invalidate_dirty(struct page *page, unsigned int offset,return ;/* We may need to shorten the dirty region */ - f =afs_page_dirty_from (priv); - t =afs_page_dirty_to (priv); + f =afs_page_dirty_from (page, priv); + t =afs_page_dirty_to (page, priv);if (t <= offset || f >= end)return ;/* Doesn't overlap */
@@ -534,17 +534,17 @@ static void afs_invalidate_dirty(struct page *page, unsigned int offset,if (f == t) goto undirty; - priv =afs_page_dirty (f, t); + priv =afs_page_dirty (page, f, t);set_page_private (page, priv); -trace_afs_page_dirty (vnode,tracepoint_string ("trunc" ), page->index, priv); +trace_afs_page_dirty (vnode,tracepoint_string ("trunc" ), page);return ; undirty: -trace_afs_page_dirty (vnode,tracepoint_string ("undirty" ), page->index, priv); +trace_afs_page_dirty (vnode,tracepoint_string ("undirty" ), page);clear_page_dirty_for_io (page); full_invalidate: - priv = (unsigned long )detach_page_private (page); -trace_afs_page_dirty (vnode,tracepoint_string ("inval" ), page->index, priv); +detach_page_private (page); +trace_afs_page_dirty (vnode,tracepoint_string ("inval" ), page); }/*
@@ -572,7 +572,6 @@ static void afs_invalidatepage(struct page *page, unsigned int offset,static int afs_releasepage (struct page *page,gfp_t gfp_flags) {struct afs_vnode *vnode =AFS_FS_I (page->mapping->host); -unsigned long priv; _enter("{{%llx:%llu}[%lu],%lx},%x", vnode->fid.vid, vnode->fid.vnode, page->index, page->flags,
@@ -581,9 +580,8 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)/* deny if page is being written to the cache and the caller hasn't * elected to wait */ if (PagePrivate (page)) { - priv = (unsigned long )detach_page_private (page); -trace_afs_page_dirty (vnode,tracepoint_string ("rel" ), - page->index, priv); +detach_page_private (page); +trace_afs_page_dirty (vnode,tracepoint_string ("rel" ), page); }/* indicate that the page can be released */
fs/afs/internal.h +8 -8
@@ -875,31 +875,31 @@ struct afs_vnode_cache_aux {#define __AFS_PAGE_PRIV_MMAPPED 0x8000UL#endif -static inline unsigned int afs_page_dirty_resolution (void ) +static inline unsigned int afs_page_dirty_resolution (struct page *page) { -int shift =PAGE_SHIFT - (__AFS_PAGE_PRIV_SHIFT -1 ); +int shift =thp_order (page) +PAGE_SHIFT - (__AFS_PAGE_PRIV_SHIFT -1 );return (shift >0 ) ? shift :0 ; } -static inline size_t afs_page_dirty_from (unsigned long priv) +static inline size_t afs_page_dirty_from (struct page *page,unsigned long priv) {unsigned long x = priv & __AFS_PAGE_PRIV_MASK;/* The lower bound is inclusive */ -return x <<afs_page_dirty_resolution (); +return x <<afs_page_dirty_resolution (page); } -static inline size_t afs_page_dirty_to (unsigned long priv) +static inline size_t afs_page_dirty_to (struct page *page,unsigned long priv) {unsigned long x = (priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK;/* The upper bound is immediately beyond the region */ -return (x +1 ) <<afs_page_dirty_resolution (); +return (x +1 ) <<afs_page_dirty_resolution (page); } -static inline unsigned long afs_page_dirty (size_t from,size_t to) +static inline unsigned long afs_page_dirty (struct page *page,size_t from,size_t to) { -unsigned int res =afs_page_dirty_resolution (); +unsigned int res =afs_page_dirty_resolution (page); from >>= res; to = (to -1 ) >> res;return (to << __AFS_PAGE_PRIV_SHIFT) | from;
fs/afs/write.c +25 -35
139 lines not on this page · raw message
include/trace/events/afs.h +13 -10
@@ -969,30 +969,33 @@ TRACE_EVENT(afs_dir_check_failed, );TRACE_EVENT (afs_page_dirty, - TP_PROTO(struct afs_vnode *vnode, const char *where, - pgoff_t page, unsigned long priv), + TP_PROTO(struct afs_vnode *vnode, const char *where, struct page *page), -TP_ARGS (vnode, where, page, priv), +TP_ARGS (vnode, where, page),TP_STRUCT__entry ( __field(struct afs_vnode *, vnode ) __field(const char *, where ) __field(pgoff_t, page ) - __field(unsigned long, priv ) + __field(unsigned long, from ) + __field(unsigned long, to ) ),TP_fast_assign ( __entry->vnode = vnode; __entry->where = where; - __entry->page = page; - __entry->priv = priv; + __entry->page = page->index; + __entry->from = afs_page_dirty_from(page, page->private); + __entry->to = afs_page_dirty_to(page, page->private); + __entry->to |= (afs_is_page_dirty_mmapped (page->private) ? + (1UL << (BITS_PER_LONG - 1)) : 0); ), -TP_printk ("vn=%p %lx %s %zx-%zx%s" , +TP_printk ("vn=%p %lx %s %lx-%lx%s" , __entry->vnode, __entry->page, __entry->where, -afs_page_dirty_from (__entry->priv), -afs_page_dirty_to (__entry->priv), -afs_is_page_dirty_mmapped (__entry->priv) ?" M" :"" ) + __entry->from, + __entry->to & ~(1UL << (BITS_PER_LONG -1 )), + __entry->to & (1UL << (BITS_PER_LONG -1 )) ?" M" :"" ) ); TRACE_EVENT(afs_call_state,
David Howells
maintainerPATCH v4 17/28 afs: Print the operation debug_id when logging an unexpected data version
In reply to David HowellsPrint the afs_operation debug_id when logging an unexpected change in the data version. This allows the logged message to be matched against tracelines.
---
fs/afs/inode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/afs/inode.c +3 -2
@@ -215,11 +215,12 @@ static void afs_apply_status(struct afs_operation *op,if (vp->dv_before + vp->dv_delta != status->data_version) {if (test_bit (AFS_VNODE_CB_PROMISED , &vnode->flags)) -pr_warn ("kAFS: vnode modified {%llx:%llu} %llx->%llx %s\n" , +pr_warn ("kAFS: vnode modified {%llx:%llu} %llx->%llx %s (op=%x)\n" , vnode->fid.vid, vnode->fid.vnode, (unsigned long long )vp->dv_before + vp->dv_delta, (unsigned long long )status->data_version, - op->type ? op->type->name :"???" ); + op->type ? op->type->name :"???" , + op->debug_id); vnode->invalid_before = status->data_version;if (vnode->status.type ==AFS_FTYPE_DIR ) {
David Howells
maintainerPATCH v4 18/28 afs: Move key to afs_read struct
In reply to David HowellsStash the key used to authenticate read operations in the afs_read struct. This will be necessary to reissue the operation against the server if a read from the cache fails in upcoming cache changes.
---
fs/afs/dir.c | 3 ++- fs/afs/file.c | 16 +++++++++------- fs/afs/internal.h | 3 ++- fs/afs/write.c | 12 ++++++------ 4 files changed, 19 insertions(+), 15 deletions(-)
fs/afs/dir.c +2 -1
@@ -242,6 +242,7 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)return ERR_PTR (-ENOMEM );refcount_set (&req->usage,1 ); + req->key =key_get (key); req->nr_pages = nr_pages; req->actual_len = i_size;/* May change */ req->len = nr_pages *PAGE_SIZE ;/* We can ask for more than there is */
@@ -306,7 +307,7 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)if (!test_bit (AFS_VNODE_DIR_VALID , &dvnode->flags)) {trace_afs_reload_dir (dvnode); - ret =afs_fetch_data (dvnode, key, req); + ret =afs_fetch_data (dvnode, req);if (ret <0 ) goto error_unlock;
fs/afs/file.c +9 -7
@@ -199,6 +199,7 @@ void afs_put_read(struct afs_read *req)if (req->pages != req->array)kfree (req->pages); } +key_put (req->key);kfree (req); } }
@@ -229,7 +230,7 @@ static const struct afs_operation_ops afs_fetch_data_operation = {/* * Fetch file data from the volume. */ -int afs_fetch_data (struct afs_vnode *vnode,struct key *key,struct afs_read *req) +int afs_fetch_data (struct afs_vnode *vnode,struct afs_read *req) {struct afs_operation *op;
@@ -238,9 +239,9 @@ int afs_fetch_data(struct afs_vnode *vnode, struct key *key, struct afs_read *re vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique, - key_serial(key)); + key_serial(req->key)); - op =afs_alloc_operation (key, vnode->volume); + op =afs_alloc_operation (req->key, vnode->volume);if (IS_ERR (op))return PTR_ERR (op);
@@ -279,6 +280,7 @@ int afs_page_filler(void *data, struct page *page)* unmarshalling code will clear the unfilled space. */ refcount_set (&req->usage,1 ); + req->key =key_get (key); req->pos = (loff_t )page->index <<PAGE_SHIFT ; req->len =PAGE_SIZE ; req->nr_pages =1 ;
@@ -288,7 +290,7 @@ int afs_page_filler(void *data, struct page *page)/* read the contents of the file from the server into the * page */ - ret =afs_fetch_data (vnode, key, req); + ret =afs_fetch_data (vnode, req);afs_put_read (req);if (ret <0 ) {
@@ -373,7 +375,6 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,struct afs_read *req;struct list_head *p;struct page *first, *page; -struct key *key =afs_file_key (file);pgoff_t index;int ret, n, i;
@@ -397,6 +398,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,refcount_set (&req->usage,1 ); req->vnode = vnode; + req->key =key_get (afs_file_key (file)); req->page_done = afs_readpages_page_done; req->pos = first->index; req->pos <<=PAGE_SHIFT ;
@@ -426,11 +428,11 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping, }while (req->nr_pages < n);if (req->nr_pages ==0 ) { -kfree (req); +afs_put_read (req);return 0 ; } - ret =afs_fetch_data (vnode, key, req); + ret =afs_fetch_data (vnode, req);if (ret <0 ) goto error;
fs/afs/internal.h +2 -1
@@ -204,6 +204,7 @@ struct afs_read {loff_t actual_len;/* How much we're actually getting */ loff_t remain;/* Amount remaining */ loff_t file_size;/* File size returned by server */ +struct key *key;/* The key to use to reissue the read */ afs_dataversion_t data_version;/* Version number returned by server */ refcount_t usage;unsigned int index;/* Which page we're reading into */
@@ -1045,7 +1046,7 @@ extern int afs_cache_wb_key(struct afs_vnode *, struct afs_file *);extern void afs_put_wb_key (struct afs_wb_key *);extern int afs_open (struct inode *,struct file *);extern int afs_release (struct inode *,struct file *); -extern int afs_fetch_data (struct afs_vnode *,struct key *,struct afs_read *); +extern int afs_fetch_data (struct afs_vnode *,struct afs_read *);extern int afs_page_filler (void *,struct page *);extern void afs_put_read (struct afs_read *);
fs/afs/write.c +6 -6
@@ -25,9 +25,10 @@ int afs_set_page_dirty(struct page *page)/* * partly or wholly fill a page that's under preparation for writing */ -static int afs_fill_page (struct afs_vnode *vnode,struct key *key, +static int afs_fill_page (struct file *file,loff_t pos,unsigned int len,struct page *page) { +struct afs_vnode *vnode =AFS_FS_I (file_inode (file));struct afs_read *req;size_t p;void *data;
@@ -49,6 +50,7 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key,return -ENOMEM ;refcount_set (&req->usage,1 ); + req->key =key_get (afs_file_key (file)); req->pos = pos; req->len = len; req->nr_pages =1 ;
@@ -56,7 +58,7 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key, req->pages[0 ] = page;get_page (page); - ret =afs_fetch_data (vnode, key, req); + ret =afs_fetch_data (vnode, req);afs_put_read (req);if (ret <0 ) {if (ret == -ENOENT ) {
@@ -80,7 +82,6 @@ int afs_write_begin(struct file *file, struct address_space *mapping, {struct afs_vnode *vnode =AFS_FS_I (file_inode (file));struct page *page; -struct key *key =afs_file_key (file);unsigned long priv;unsigned f, from = pos & (PAGE_SIZE -1 );unsigned t, to = from + len;
@@ -95,7 +96,7 @@ int afs_write_begin(struct file *file, struct address_space *mapping,return -ENOMEM ;if (!PageUptodate (page) && len !=PAGE_SIZE ) { - ret =afs_fill_page (vnode, key, pos &PAGE_MASK ,PAGE_SIZE , page); + ret =afs_fill_page (file, pos &PAGE_MASK ,PAGE_SIZE , page);if (ret <0 ) {unlock_page (page);put_page (page);
@@ -163,7 +164,6 @@ int afs_write_end(struct file *file, struct address_space *mapping, struct page *page, void *fsdata) { struct afs_vnode *vnode = AFS_FS_I(file_inode(file)); -struct key *key =afs_file_key (file);unsigned long priv;unsigned int f, from = pos & (PAGE_SIZE -1 );unsigned int t, to = from + copied;
@@ -193,7 +193,7 @@ int afs_write_end(struct file *file, struct address_space *mapping,* unmarshalling routine will take care of clearing any * bits that are beyond the EOF. */ - ret =afs_fill_page (vnode, key, pos + copied, + ret =afs_fill_page (file, pos + copied, len - copied, page);if (ret <0 ) goto out;
David Howells
maintainerPATCH v4 19/28 afs: Don't truncate iter during data fetch
In reply to David HowellsDon't truncate the iterator to correspond to the actual data size when fetching the data from the server - rather, pass the length we want to read to rxrpc.
This will allow the clear-after-read code in future to simply clear the remaining iterator capacity rather than having to reinitialise the iterator.
---
fs/afs/fsclient.c | 6 ++++-- fs/afs/internal.h | 6 ++++++ fs/afs/rxrpc.c | 13 +++++++++---- fs/afs/yfsclient.c | 6 ++++-- include/net/af_rxrpc.h | 2 +- net/rxrpc/recvmsg.c | 9 +++++---- 6 files changed, 29 insertions(+), 13 deletions(-)
fs/afs/fsclient.c +4 -2
@@ -305,8 +305,9 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call)unsigned int size;int ret; -_enter ("{%u,%zu/%llu}" , - call->unmarshall,iov_iter_count (call->iter), req->actual_len); +_enter ("{%u,%zu,%zu/%llu}" , + call->unmarshall, call->iov_len,iov_iter_count (call->iter), + req->actual_len);switch (call->unmarshall) {case 0 :
@@ -343,6 +344,7 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call) size =PAGE_SIZE - req->offset; else size = req->remain; + call->iov_len = size; call->bvec[0 ].bv_len = size; call->bvec[0 ].bv_offset = req->offset; call->bvec[0 ].bv_page = req->pages[req->index];
fs/afs/internal.h +6 -0
@@ -104,6 +104,7 @@ struct afs_call {struct afs_server *server;/* The fileserver record if fs op (pins ref) */ struct afs_vlserver *vlserver;/* The vlserver record if vl op */ void *request;/* request data (first part) */ +size_t iov_len;/* Size of *iter to be used */ struct iov_iter def_iter;/* Default buffer/data iterator */ struct iov_iter *iter;/* Iterator currently in use */ union {/* Convenience for ->def_iter */
@@ -1271,6 +1272,7 @@ static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *cstatic inline void afs_extract_begin (struct afs_call *call,void *buf,size_t size) { + call->iov_len = size; call->kvec[0 ].iov_base = buf; call->kvec[0 ].iov_len = size;iov_iter_kvec (&call->def_iter,READ , call->kvec,1 , size);
@@ -1278,21 +1280,25 @@ static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t sistatic inline void afs_extract_to_tmp (struct afs_call *call) { + call->iov_len =sizeof (call->tmp);afs_extract_begin (call, &call->tmp,sizeof (call->tmp)); }static inline void afs_extract_to_tmp64 (struct afs_call *call) { + call->iov_len =sizeof (call->tmp64);afs_extract_begin (call, &call->tmp64,sizeof (call->tmp64)); }static inline void afs_extract_discard (struct afs_call *call,size_t size) { + call->iov_len = size;iov_iter_discard (&call->def_iter,READ , size); }static inline void afs_extract_to_buf (struct afs_call *call,size_t size) { + call->iov_len = size;afs_extract_begin (call, call->buffer, size); }
fs/afs/rxrpc.c +9 -4
@@ -363,6 +363,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)struct rxrpc_call *rxcall;struct msghdr msg;struct kvec iov[1 ]; +size_t len;s64 tx_total_len;int ret;
@@ -466,9 +467,10 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)rxrpc_kernel_abort_call (call->net->socket, rxcall,RX_USER_ABORT , ret,"KSD" ); }else { + len =0 ;iov_iter_kvec (&msg.msg_iter,READ ,NULL ,0 ,0 );rxrpc_kernel_recv_data (call->net->socket, rxcall, - &msg.msg_iter, false, + &msg.msg_iter, &len, false, &call->abort_code, &call->service_id); ac->abort_code = call->abort_code; ac->responded = true;
@@ -504,6 +506,7 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)static void afs_deliver_to_call (struct afs_call *call) {enum afs_call_state state; +size_t len;u32 abort_code, remote_abort =0 ;int ret;
@@ -516,10 +519,11 @@ static void afs_deliver_to_call(struct afs_call *call) state == AFS_CALL_SV_AWAIT_ACK ) {if (state ==AFS_CALL_SV_AWAIT_ACK ) { + len =0 ;iov_iter_kvec (&call->def_iter,READ ,NULL ,0 ,0 ); ret =rxrpc_kernel_recv_data (call->net->socket, call->rxcall, &call->def_iter, - false, &remote_abort, + &len, false, &remote_abort, &call->service_id);trace_afs_receive_data (call, &call->def_iter, false, ret);
@@ -929,10 +933,11 @@ int afs_extract_data(struct afs_call *call, bool want_more)u32 remote_abort =0 ;int ret; -_enter ("{%s,%zu},%d" , call->type->name,iov_iter_count (iter), want_more); +_enter ("{%s,%zu,%zu},%d" , + call->type->name, call->iov_len,iov_iter_count (iter), want_more); ret =rxrpc_kernel_recv_data (net->socket, call->rxcall, iter, - want_more, &remote_abort, + &call->iov_len, want_more, &remote_abort, &call->service_id);if (ret ==0 || ret == -EAGAIN )return ret;
fs/afs/yfsclient.c +4 -2
@@ -363,8 +363,9 @@ static int yfs_deliver_fs_fetch_data64(struct afs_call *call)unsigned int size;int ret; -_enter ("{%u,%zu/%llu}" , - call->unmarshall,iov_iter_count (call->iter), req->actual_len); +_enter ("{%u,%zu, %zu/%llu}" , + call->unmarshall, call->iov_len,iov_iter_count (call->iter), + req->actual_len);switch (call->unmarshall) {case 0 :
@@ -396,6 +397,7 @@ static int yfs_deliver_fs_fetch_data64(struct afs_call *call) size =PAGE_SIZE - req->offset; else size = req->remain; + call->iov_len = size; call->bvec[0 ].bv_len = size; call->bvec[0 ].bv_offset = req->offset; call->bvec[0 ].bv_page = req->pages[req->index];
include/net/af_rxrpc.h +1 -1
@@ -53,7 +53,7 @@ int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *, struct msghdr *, size_t, rxrpc_notify_end_tx_t);int rxrpc_kernel_recv_data (struct socket *,struct rxrpc_call *, -struct iov_iter *,bool ,u32 *,u16 *); +struct iov_iter *,size_t *,bool ,u32 *,u16 *);bool rxrpc_kernel_abort_call (struct socket *,struct rxrpc_call *,u32 ,int ,const char *);void rxrpc_kernel_end_call (struct socket *,struct rxrpc_call *);
net/rxrpc/recvmsg.c +5 -4
@@ -669,6 +669,7 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,* @sock: The socket that the call exists on * @call: The call to send data through * @iter: The buffer to receive into +* @_len: The amount of data we want to receive (decreased on return) * @want_more: True if more data is expected to be read * @_abort: Where the abort code is stored if -ECONNABORTED is returned * @_service: Where to store the actual service ID (may be upgraded)
@@ -684,7 +685,7 @@ int rxrpc_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,* *_abort should also be initialised to 0. */ int rxrpc_kernel_recv_data (struct socket *sock,struct rxrpc_call *call, -struct iov_iter *iter, +struct iov_iter *iter,size_t *_len,bool want_more,u32 *_abort,u16 *_service) {size_t offset =0 ;
@@ -692,7 +693,7 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,_enter ("{%d,%s},%zu,%d" , call->debug_id, rxrpc_call_states[call->state], -iov_iter_count (iter), want_more); + *_len, want_more); ASSERTCMP(call->state, !=, RXRPC_CALL_SERVER_SECURING);
@@ -703,8 +704,8 @@ int rxrpc_kernel_recv_data(struct socket *sock, struct rxrpc_call *call,case RXRPC_CALL_SERVER_RECV_REQUEST :case RXRPC_CALL_SERVER_ACK_REQUEST : ret =rxrpc_recvmsg_data (sock, call,NULL , iter, -iov_iter_count (iter),0 , - &offset); + *_len,0 , &offset); + *_len -= offset;if (ret <0 ) goto out;
David Howells
maintainerPATCH v4 20/28 afs: Log remote unmarshalling errors
In reply to David HowellsLog unmarshalling errors reported by the peer (ie. it can't parse what we sent it). Limit the maximum number of messages to 3.
---
fs/afs/rxrpc.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
fs/afs/rxrpc.c +34 -0
@@ -500,6 +500,39 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)_leave (" = %d" , ret); } +/* +* Log remote abort codes that indicate that we have a protocol disagreement +* with the server. +*/ +static void afs_log_error (struct afs_call *call,s32 remote_abort) +{ +static int max =0 ; +const char *msg; +int m; + +switch (remote_abort) { +case RX_EOF : msg ="unexpected EOF" ;break ; +case RXGEN_CC_MARSHAL : msg ="client marshalling" ;break ; +case RXGEN_CC_UNMARSHAL : msg ="client unmarshalling" ;break ; +case RXGEN_SS_MARSHAL : msg ="server marshalling" ;break ; +case RXGEN_SS_UNMARSHAL : msg ="server unmarshalling" ;break ; +case RXGEN_DECODE : msg ="opcode decode" ;break ; +case RXGEN_SS_XDRFREE : msg ="server XDR cleanup" ;break ; +case RXGEN_CC_XDRFREE : msg ="client XDR cleanup" ;break ; +case -32 : msg ="insufficient data" ;break ; +default : +return ; + } + + m = max; +if (m <3 ) { + max = m +1 ; +pr_notice ("kAFS: Peer reported %s failure on %s [%pISp]\n" , + msg, call->type->name, + &call->alist->addrs[call->addr_ix].transport); + } +} +/* * deliver messages to a call */
@@ -563,6 +596,7 @@ static void afs_deliver_to_call(struct afs_call *call) goto out;case -ECONNABORTED : ASSERTCMP(state, ==, AFS_CALL_COMPLETE); +afs_log_error (call, call->abort_code); goto done;case -ENOTSUPP : abort_code =RXGEN_OPCODE ;
David Howells
maintainerPATCH v4 21/28 afs: Set up the iov_iter before calling afs_extract_data()
In reply to David Howellsafs_extract_data() sets up a temporary iov_iter and passes it to AF_RXRPC each time it is called to describe the remaining buffer to be filled.
Instead:
(1) Put an iterator in the afs_call struct.
(2) Set the iterator for each marshalling stage to load data into the appropriate places. A number of convenience functions are provided to this end (eg. afs_extract_to_buf()).
This iterator is then passed to afs_extract_data().
(3) Use the new ITER_MAPPING iterator when reading data to load directly into the inode's pages without needing to create a list of them.
This will allow O_DIRECT calls to be supported in future patches.
---
fs/afs/dir.c | 222 +++++++++++++++++++++++++++++++++++----------------- fs/afs/file.c | 190 ++++++++++++++++++++++++++------------------- fs/afs/fsclient.c | 54 +++---------- fs/afs/internal.h | 16 ++-- fs/afs/write.c | 27 ++++-- fs/afs/yfsclient.c | 54 +++---------- 6 files changed, 314 insertions(+), 249 deletions(-)
fs/afs/dir.c +149 -73
@@ -103,6 +103,35 @@ struct afs_lookup_cookie {struct afs_fid fids[50 ]; }; +/* +* Drop the refs that we're holding on the pages we were reading into. We've +* got refs on the first nr_pages pages. +*/ +static void afs_dir_read_cleanup (struct afs_read *req) +{ +struct address_space *mapping = req->vnode->vfs_inode.i_mapping; +struct page *page; +pgoff_t last = req->nr_pages -1 ; + +XA_STATE (xas, &mapping->i_pages,0 ); + +if (unlikely (!req->nr_pages)) +return ; + +rcu_read_lock (); +xas_for_each (&xas, page, last) { +if (xas_retry (&xas, page)) +continue ; +BUG_ON (xa_is_value (page)); +BUG_ON (PageCompound (page)); + ASSERTCMP(page->mapping, ==, mapping); + +put_page (page); + } + +rcu_read_unlock (); +} +/* * check that a directory page is valid */
@@ -128,7 +157,7 @@ static bool afs_dir_check_page(struct afs_vnode *dvnode, struct page *page, qty /=sizeof (union afs_xdr_dir_block );/* check them */ - dbuf =kmap (page); + dbuf =kmap_atomic (page);for (tmp =0 ; tmp < qty; tmp++) {if (dbuf->blocks[tmp].hdr.magic !=AFS_DIR_MAGIC ) { printk("kAFS: %s(%lx): bad magic %d/%d is %04hx\n",
@@ -147,7 +176,7 @@ static bool afs_dir_check_page(struct afs_vnode *dvnode, struct page *page, ((u8 *)&dbuf->blocks[tmp])[AFS_DIR_BLOCK_SIZE -1 ] =0 ; } -kunmap (page); +kunmap_atomic (dbuf); checked:afs_stat_v (dvnode, n_read_dir);
@@ -158,35 +187,74 @@ static bool afs_dir_check_page(struct afs_vnode *dvnode, struct page *page, }/* -* Check the contents of a directory that we've just read. +* Dump the contents of a directory. */ -static bool afs_dir_check_pages (struct afs_vnode *dvnode,struct afs_read *req) +static void afs_dir_dump (struct afs_vnode *dvnode,struct afs_read *req) {struct afs_xdr_dir_page *dbuf; -unsigned int i, j, qty =PAGE_SIZE /sizeof (union afs_xdr_dir_block ); +struct address_space *mapping = dvnode->vfs_inode.i_mapping; +struct page *page; +unsigned int i, qty =PAGE_SIZE /sizeof (union afs_xdr_dir_block ); +pgoff_t last = req->nr_pages -1 ; -for (i =0 ; i < req->nr_pages; i++) -if (!afs_dir_check_page (dvnode, req->pages[i], req->actual_len)) - goto bad; -return true; +XA_STATE (xas, &mapping->i_pages,0 ); -bad: -pr_warn ("DIR %llx:%llx f=%llx l=%llx al=%llx r=%llx\n" , +pr_warn ("DIR %llx:%llx f=%llx l=%llx al=%llx\n" , dvnode->fid.vid, dvnode->fid.vnode, - req->file_size, req->len, req->actual_len, req->remain); -pr_warn ("DIR %llx %x %x %x\n" , - req->pos, req->index, req->nr_pages, req->offset); + req->file_size, req->len, req->actual_len); +pr_warn ("DIR %llx %x %zx %zx\n" , + req->pos, req->nr_pages, + req->iter->iov_offset,iov_iter_count (req->iter)); -for (i =0 ; i < req->nr_pages; i++) { - dbuf =kmap (req->pages[i]); -for (j =0 ; j < qty; j++) { -union afs_xdr_dir_block *block = &dbuf->blocks[j]; +xas_for_each (&xas, page, last) { +if (xas_retry (&xas, page)) +continue ; + +BUG_ON (PageCompound (page)); +BUG_ON (page->mapping != mapping); + + dbuf =kmap_atomic (page); +for (i =0 ; i < qty; i++) { +union afs_xdr_dir_block *block = &dbuf->blocks[i]; -pr_warn ("[%02x] %32phN\n" , i * qty + j, block); +pr_warn ("[%02lx] %32phN\n" , page->index * qty + i, block); } -kunmap (req->pages[i]); +kunmap_atomic (dbuf); } -return false; +} + +/* +* Check all the pages in a directory. All the pages are held pinned. +*/ +static int afs_dir_check (struct afs_vnode *dvnode,struct afs_read *req) +{ +struct address_space *mapping = dvnode->vfs_inode.i_mapping; +struct page *page; +pgoff_t last = req->nr_pages -1 ; +int ret =0 ; + +XA_STATE (xas, &mapping->i_pages,0 ); + +if (unlikely (!req->nr_pages)) +return 0 ; + +rcu_read_lock (); +xas_for_each (&xas, page, last) { +if (xas_retry (&xas, page)) +continue ; + +BUG_ON (PageCompound (page)); +BUG_ON (page->mapping != mapping); + +if (!afs_dir_check_page (dvnode, page, req->file_size)) { +afs_dir_dump (dvnode, req); + ret = -EIO ; +break ; + } + } + +rcu_read_unlock (); +return ret; }/*
@@ -215,58 +283,57 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key) {struct afs_read *req;loff_t i_size; -int nr_pages, nr_inline, i, n; -int ret = -ENOMEM ; +int nr_pages, i, n; +int ret; + +_enter ("" ); -retry: + req =kzalloc (sizeof (*req),GFP_KERNEL ); +if (!req) +return ERR_PTR (-ENOMEM ); + +refcount_set (&req->usage,1 ); + req->vnode = dvnode; + req->key =key_get (key); + req->cleanup = afs_dir_read_cleanup; + +expand: i_size =i_size_read (&dvnode->vfs_inode); -if (i_size <2048 ) -return ERR_PTR (afs_bad (dvnode, afs_file_error_dir_small)); +if (i_size <2048 ) { + ret =afs_bad (dvnode, afs_file_error_dir_small); + goto error; + }if (i_size >2048 *1024 ) {trace_afs_file_error (dvnode, -EFBIG , afs_file_error_dir_big); -return ERR_PTR (-EFBIG ); + ret = -EFBIG ; + goto error; }_enter ("%llu" , i_size); -/* Get a request record to hold the page list. We want to hold it -* inline if we can, but we don't want to make an order 1 allocation. -*/ nr_pages = (i_size +PAGE_SIZE -1 ) /PAGE_SIZE ; - nr_inline = nr_pages; -if (nr_inline > (PAGE_SIZE -sizeof (*req)) /sizeof (struct page *)) - nr_inline =0 ; - req =kzalloc (struct_size (req, array, nr_inline),GFP_KERNEL ); -if (!req) -return ERR_PTR (-ENOMEM ); - -refcount_set (&req->usage,1 ); - req->key =key_get (key); - req->nr_pages = nr_pages; req->actual_len = i_size;/* May change */ req->len = nr_pages *PAGE_SIZE ;/* We can ask for more than there is */ req->data_version = dvnode->status.data_version;/* May change */ -if (nr_inline >0 ) { - req->pages = req->array; - }else { - req->pages =kcalloc (nr_pages,sizeof (struct page *), -GFP_KERNEL ); -if (!req->pages) - goto error; - } +iov_iter_xarray (&req->def_iter,READ , &dvnode->vfs_inode.i_mapping->i_pages, +0 , i_size); + req->iter = &req->def_iter; -/* Get a list of all the pages that hold or will hold the directory -* content. We need to fill in any gaps that we might find where the -* memory reclaimer has been at work. If there are any gaps, we will +/* Fill in any gaps that we might find where the memory reclaimer has +* been at work and pin all the pages. If there are any gaps, we will * need to reread the entire directory contents. */ - i =0 ; - do { + i = req->nr_pages; +while (i < nr_pages) { +struct page *pages[8 ], *page; + n =find_get_pages_contig (dvnode->vfs_inode.i_mapping, i, - req->nr_pages - i, - req->pages + i); - _debug("find %u at %u/%u", n, i, req->nr_pages); + min_t(unsigned int, nr_pages - i, +ARRAY_SIZE (pages)), + pages); +_debug ("find %u at %u/%u" , n, i, nr_pages); +if (n ==0 ) {gfp_t gfp = dvnode->vfs_inode.i_mapping->gfp_mask;
@@ -274,22 +341,24 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)afs_stat_v (dvnode, n_inval); ret = -ENOMEM ; - req->pages[i] =__page_cache_alloc (gfp); -if (!req->pages[i]) + page =__page_cache_alloc (gfp); +if (!page) goto error; - ret =add_to_page_cache_lru (req->pages[i], + ret =add_to_page_cache_lru (page, dvnode->vfs_inode.i_mapping, i, gfp);if (ret <0 ) goto error; -attach_page_private (req->pages[i], (void *)1 ); -unlock_page (req->pages[i]); +attach_page_private (page, (void *)1 ); +unlock_page (page); + req->nr_pages++; i++; }else { + req->nr_pages += n; i += n; } - }while (i < req->nr_pages); + }/* If we're going to reload, we need to lock all the pages to prevent * races.
@@ -313,12 +382,17 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)task_io_account_read (PAGE_SIZE * req->nr_pages); -if (req->len < req->file_size) - goto content_has_grown; +if (req->len < req->file_size) { +/* The content has grown, so we need to expand the +* buffer. +*/ +up_write (&dvnode->validate_lock); + goto expand; + }/* Validate the data we just read. */ - ret = -EIO ; -if (!afs_dir_check_pages (dvnode, req)) + ret =afs_dir_check (dvnode, req); +if (ret <0 ) goto error_unlock;// TODO: Trim excess pages
@@ -336,11 +410,6 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)afs_put_read (req);_leave (" = %d" , ret);return ERR_PTR (ret); - -content_has_grown: -up_write (&dvnode->validate_lock); -afs_put_read (req); - goto retry; }/*
@@ -450,6 +519,7 @@ static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx,struct afs_read *req;struct page *page;unsigned blkoff, limit; +void __rcu **slot;int ret;_enter ("{%lu},%u,," , dir->i_ino, (unsigned )ctx->pos);
@@ -474,9 +544,15 @@ static int afs_dir_iterate(struct inode *dir, struct dir_context *ctx, blkoff = ctx->pos & ~(sizeof (union afs_xdr_dir_block ) -1 );/* Fetch the appropriate page from the directory and re-add it -* to the LRU. +* to the LRU. We have all the pages pinned with an extra ref. */ - page = req->pages[blkoff /PAGE_SIZE ]; +rcu_read_lock (); + page =NULL ; + slot =radix_tree_lookup_slot (&dvnode->vfs_inode.i_mapping->i_pages, + blkoff /PAGE_SIZE ); +if (slot) + page =radix_tree_deref_slot (slot); +rcu_read_unlock ();if (!page) { ret =afs_bad (dvnode, afs_file_error_dir_missing_page);break ;
fs/afs/file.c +110 -80
287 lines not on this page · raw message
fs/afs/fsclient.c +14 -40
103 lines not on this page · raw message
fs/afs/internal.h +8 -8
@@ -31,6 +31,7 @@struct pagevec ;struct afs_call ; +struct afs_vnode ;/* * Partial file-locking emulation mode. (The problem being that AFS3 only
@@ -203,18 +204,18 @@ struct afs_read {loff_t pos;/* Where to start reading */ loff_t len;/* How much we're asking for */ loff_t actual_len;/* How much we're actually getting */ -loff_t remain;/* Amount remaining */ loff_t file_size;/* File size returned by server */ struct key *key;/* The key to use to reissue the read */ +struct afs_vnode *vnode;/* The file being read into. */ afs_dataversion_t data_version;/* Version number returned by server */ refcount_t usage; -unsigned int index;/* Which page we're reading into */ +unsigned int call_debug_id;unsigned int nr_pages; -unsigned int offset;/* offset into current page */ -struct afs_vnode *vnode; -void (*page_done)(struct afs_read *); -struct page **pages; -struct page *array[]; +int error; +void (*done)(struct afs_read *); +void (*cleanup)(struct afs_read *); +struct iov_iter *iter;/* Iterator representing the buffer */ +struct iov_iter def_iter;/* Default iterator */ };/*
@@ -1048,7 +1049,6 @@ extern void afs_put_wb_key(struct afs_wb_key *);extern int afs_open (struct inode *,struct file *);extern int afs_release (struct inode *,struct file *);extern int afs_fetch_data (struct afs_vnode *,struct afs_read *); -extern int afs_page_filler (void *,struct page *);extern void afs_put_read (struct afs_read *);static inline struct afs_read *afs_get_read (struct afs_read *req)
fs/afs/write.c +19 -8
@@ -22,6 +22,16 @@ int afs_set_page_dirty(struct page *page)return __set_page_dirty_nobuffers (page); } +/* +* Handle completion of a read operation to fill a page. +*/ +static void afs_fill_hole (struct afs_read *req) +{ +if (iov_iter_count (req->iter) >0 ) +/* The read was short - clear the excess buffer. */ +iov_iter_zero (iov_iter_count (req->iter), req->iter); +} +/* * partly or wholly fill a page that's under preparation for writing */
@@ -45,18 +55,19 @@ static int afs_fill_page(struct file *file,return 0 ; } - req =kzalloc (struct_size (req, array,1 ),GFP_KERNEL ); + req =kzalloc (sizeof (struct afs_read ),GFP_KERNEL );if (!req)return -ENOMEM ;refcount_set (&req->usage,1 ); - req->key =key_get (afs_file_key (file)); - req->pos = pos; - req->len = len; - req->nr_pages =1 ; - req->pages = req->array; - req->pages[0 ] = page; -get_page (page); + req->vnode = vnode; + req->done = afs_fill_hole; + req->key =key_get (afs_file_key (file)); + req->pos = pos; + req->len = len; + req->nr_pages =1 ; + req->iter = &req->def_iter; +iov_iter_xarray (&req->def_iter,READ , &file->f_mapping->i_pages, pos, len); ret =afs_fetch_data (vnode, req);afs_put_read (req);
fs/afs/yfsclient.c +14 -40
101 lines not on this page · raw message
David Howells
maintainerPATCH v4 22/28 afs: Use ITER_XARRAY for writing
In reply to David HowellsUse a single ITER_XARRAY iterator to describe the portion of a file to be transmitted to the server rather than generating a series of small ITER_BVEC iterators on the fly. This will make it easier to implement AIO in afs.
In theory we could maybe use one giant ITER_BVEC, but that means potentially allocating a huge array of bio_vec structs (max 256 per page) when in fact the pagecache already has a structure listing all the relevant pages (radix_tree/xarray) that can be walked over.
---
fs/afs/fsclient.c | 50 +++++++++------------ fs/afs/internal.h | 15 +++--- fs/afs/rxrpc.c | 103 ++++++-------------------------------------- fs/afs/write.c | 100 ++++++++++++++++++++++++------------------- fs/afs/yfsclient.c | 25 +++-------- include/trace/events/afs.h | 51 ++++++++-------------- 6 files changed, 126 insertions(+), 218 deletions(-)
fs/afs/fsclient.c +20 -30
@@ -1055,8 +1055,7 @@ static const struct afs_call_type afs_RXFSStoreData64 = {/* * store a set of pages to a very large file */ -static void afs_fs_store_data64 (struct afs_operation *op, -loff_t pos,loff_t size,loff_t i_size) +static void afs_fs_store_data64 (struct afs_operation *op) {struct afs_vnode_param *vp = &op->file[0 ];struct afs_call *call;
@@ -1071,7 +1070,7 @@ static void afs_fs_store_data64(struct afs_operation *op,if (!call)return afs_op_nomem (op); - call->send_pages = true; + call->write_iter = op->store.write_iter;/* marshall the parameters */ bp = call->request;
@@ -1087,47 +1086,38 @@ static void afs_fs_store_data64(struct afs_operation *op, *bp++ =0 ;/* unix mode */ *bp++ =0 ;/* segment size */ - *bp++ =htonl (upper_32_bits (pos)); - *bp++ =htonl (lower_32_bits (pos)); - *bp++ =htonl (upper_32_bits (size)); - *bp++ =htonl (lower_32_bits (size)); - *bp++ =htonl (upper_32_bits (i_size)); - *bp++ =htonl (lower_32_bits (i_size)); + *bp++ =htonl (upper_32_bits (op->store.pos)); + *bp++ =htonl (lower_32_bits (op->store.pos)); + *bp++ =htonl (upper_32_bits (op->store.size)); + *bp++ =htonl (lower_32_bits (op->store.size)); + *bp++ =htonl (upper_32_bits (op->store.i_size)); + *bp++ =htonl (lower_32_bits (op->store.i_size));trace_afs_make_fs_call (call, &vp->fid);afs_make_op_call (op, call,GFP_NOFS ); }/* -* store a set of pages +* Write data to a file on the server. */ void afs_fs_store_data (struct afs_operation *op) {struct afs_vnode_param *vp = &op->file[0 ];struct afs_call *call; -loff_t size, pos, i_size;__be32 *bp;_enter (",%x,{%llx:%llu},," ,key_serial (op->key), vp->fid.vid, vp->fid.vnode); - size = (loff_t )op->store.last_to - (loff_t )op->store.first_offset; -if (op->store.first != op->store.last) - size += (loff_t)(op->store.last - op->store.first) <<PAGE_SHIFT ; - pos = (loff_t )op->store.first <<PAGE_SHIFT ; - pos += op->store.first_offset; - - i_size =i_size_read (&vp->vnode->vfs_inode); -if (pos + size > i_size) - i_size = size + pos; -_debug ("size %llx, at %llx, i_size %llx" , - (unsigned long long ) size, (unsigned long long ) pos, - (unsigned long long ) i_size); + (unsigned long long )op->store.size, + (unsigned long long )op->store.pos, + (unsigned long long )op->store.i_size); -if (upper_32_bits (pos) ||upper_32_bits (i_size) ||upper_32_bits (size) || -upper_32_bits (pos + size)) -return afs_fs_store_data64 (op, pos, size, i_size); +if (upper_32_bits (op->store.pos) || +upper_32_bits (op->store.size) || +upper_32_bits (op->store.i_size)) +return afs_fs_store_data64 (op); call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData, (4 + 6 + 3) * 4,
@@ -1135,7 +1125,7 @@ void afs_fs_store_data(struct afs_operation *op)if (!call)return afs_op_nomem (op); - call->send_pages = true; + call->write_iter = op->store.write_iter;/* marshall the parameters */ bp = call->request;
@@ -1151,9 +1141,9 @@ void afs_fs_store_data(struct afs_operation *op) *bp++ =0 ;/* unix mode */ *bp++ =0 ;/* segment size */ - *bp++ =htonl (lower_32_bits (pos)); - *bp++ =htonl (lower_32_bits (size)); - *bp++ =htonl (lower_32_bits (i_size)); + *bp++ =htonl (lower_32_bits (op->store.pos)); + *bp++ =htonl (lower_32_bits (op->store.size)); + *bp++ =htonl (lower_32_bits (op->store.i_size));trace_afs_make_fs_call (call, &vp->fid);afs_make_op_call (op, call,GFP_NOFS );
fs/afs/internal.h +8 -7
@@ -107,6 +107,7 @@ struct afs_call {void *request;/* request data (first part) */ size_t iov_len;/* Size of *iter to be used */ struct iov_iter def_iter;/* Default buffer/data iterator */ +struct iov_iter *write_iter;/* Iterator defining write to be made */ struct iov_iter *iter;/* Iterator currently in use */ union {/* Convenience for ->def_iter */ struct kvec kvec[1 ];
@@ -133,7 +134,6 @@ struct afs_call {unsigned char unmarshall;/* unmarshalling phase */ unsigned char addr_ix;/* Address in ->alist */ bool drop_ref;/* T if need to drop ref for incoming call */ -bool send_pages;/* T if data from mapping should be sent */ bool need_attention;/* T if RxRPC poked us */ bool async;/* T if asynchronous */ bool upgrade;/* T to request service upgrade */
@@ -811,12 +811,13 @@ struct afs_operation {afs_lock_type_t type; } lock;struct { -struct address_space *mapping;/* Pages being written from */ -pgoff_t first;/* first page in mapping to deal with */ -pgoff_t last;/* last page in mapping to deal with */ -unsigned first_offset;/* offset into mapping[first] */ -unsigned last_to;/* amount of mapping[last] */ -bool laundering;/* Laundering page, PG_writeback not set */ +struct iov_iter *write_iter; +loff_t pos; +loff_t size; +loff_t i_size; +pgoff_t first;/* first page in mapping to deal with */ +pgoff_t last;/* last page in mapping to deal with */ +bool laundering;/* Laundering page, PG_writeback not set */ } store;struct {struct iattr *attr;
fs/afs/rxrpc.c +15 -88
133 lines not on this page · raw message
fs/afs/write.c +57 -43
176 lines not on this page · raw message
fs/afs/yfsclient.c +7 -18
@@ -1078,25 +1078,15 @@ void yfs_fs_store_data(struct afs_operation *op) {struct afs_vnode_param *vp = &op->file[0 ];struct afs_call *call; -loff_t size, pos, i_size;__be32 *bp;_enter (",%x,{%llx:%llu},," ,key_serial (op->key), vp->fid.vid, vp->fid.vnode); - size = (loff_t )op->store.last_to - (loff_t )op->store.first_offset; -if (op->store.first != op->store.last) - size += (loff_t)(op->store.last - op->store.first) <<PAGE_SHIFT ; - pos = (loff_t )op->store.first <<PAGE_SHIFT ; - pos += op->store.first_offset; - - i_size =i_size_read (&vp->vnode->vfs_inode); -if (pos + size > i_size) - i_size = size + pos; -_debug ("size %llx, at %llx, i_size %llx" , - (unsigned long long )size, (unsigned long long )pos, - (unsigned long long )i_size); + (unsigned long long )op->store.size, + (unsigned long long )op->store.pos, + (unsigned long long )op->store.i_size); call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64, sizeof(__be32) +
@@ -1109,8 +1099,7 @@ void yfs_fs_store_data(struct afs_operation *op)if (!call)return afs_op_nomem (op); - call->key = op->key; - call->send_pages = true; + call->write_iter = op->store.write_iter;/* marshall the parameters */ bp = call->request;
@@ -1118,9 +1107,9 @@ void yfs_fs_store_data(struct afs_operation *op) bp =xdr_encode_u32 (bp,0 );/* RPC flags */ bp =xdr_encode_YFSFid (bp, &vp->fid); bp =xdr_encode_YFSStoreStatus_mtime (bp, &op->mtime); - bp =xdr_encode_u64 (bp, pos); - bp =xdr_encode_u64 (bp, size); - bp =xdr_encode_u64 (bp, i_size); + bp =xdr_encode_u64 (bp, op->store.pos); + bp =xdr_encode_u64 (bp, op->store.size); + bp =xdr_encode_u64 (bp, op->store.i_size);yfs_check_req (call, bp);trace_afs_make_fs_call (call, &vp->fid);
include/trace/events/afs.h +19 -32
84 lines not on this page · raw message
David Howells
maintainerPATCH v4 23/28 afs: Wait on PG_fscache before modifying/releasing a page
In reply to David HowellsPG_fscache is going to be used to indicate that a page is being written to the cache, and that the page should not be modified or released until it's finished.
Make afs_invalidatepage() and afs_releasepage() wait for it.
---
fs/afs/file.c | 9 +++++++++ fs/afs/write.c | 10 ++++++++++ 2 files changed, 19 insertions(+)
fs/afs/file.c +9 -0
@@ -594,6 +594,7 @@ static void afs_invalidatepage(struct page *page, unsigned int offset,if (PagePrivate (page))afs_invalidate_dirty (page, offset, length); +wait_on_page_fscache (page);_leave ("" ); }
@@ -611,6 +612,14 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)/* deny if page is being written to the cache and the caller hasn't * elected to wait */ +#ifdef CONFIG_AFS_FSCACHE +if (PageFsCache (page)) { +if (!(gfp_flags & __GFP_DIRECT_RECLAIM) || !(gfp_flags & __GFP_FS)) +return false; +wait_on_page_fscache (page); + } +#endif +if (PagePrivate (page)) {detach_page_private (page);trace_afs_page_dirty (vnode,tracepoint_string ("rel" ), page);
fs/afs/write.c +10 -0
@@ -117,6 +117,10 @@ int afs_write_begin(struct file *file, struct address_space *mapping,SetPageUptodate (page); } +#ifdef CONFIG_AFS_FSCACHE +wait_on_page_fscache (page); +#endif + try_again:/* See if this page is already partially written in a way that we can * merge the new write with.
@@ -857,6 +861,11 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)/* Wait for the page to be written to the cache before we allow it to * be modified. We then assume the entire page will need writing back. */ +#ifdef CONFIG_AFS_FSCACHE +if (PageFsCache (vmf->page) && +wait_on_page_bit_killable (vmf->page, PG_fscache) <0 ) +return VM_FAULT_RETRY ; +#endif if (PageWriteback (vmf->page) &&wait_on_page_bit_killable (vmf->page, PG_writeback) <0 )
@@ -948,5 +957,6 @@ int afs_launder_page(struct page *page)detach_page_private (page);trace_afs_page_dirty (vnode,tracepoint_string ("laundered" ), page); +wait_on_page_fscache (page);return ret; }
David Howells
maintainerPATCH v4 24/28 afs: Extract writeback extension into its own function
In reply to David HowellsExtract writeback extension into its own function to break up the writeback function a bit.
---
fs/afs/write.c | 109 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 42 deletions(-)
fs/afs/write.c +67 -42
@@ -490,47 +490,25 @@ static int afs_store_data(struct afs_vnode *vnode, struct iov_iter *iter, }/* -* Synchronously write back the locked page and any subsequent non-locked dirty -* pages. +* Extend the region to be written back to include subsequent contiguously +* dirty pages if possible, but don't sleep while doing so. +* +* If this page holds new content, then we can include filler zeros in the +* writeback. */ -static int afs_write_back_from_locked_page (struct address_space *mapping, -struct writeback_control *wbc, -struct page *primary_page, -pgoff_t final_page) +static void afs_extend_writeback (struct address_space *mapping, +struct afs_vnode *vnode, +long *_count, +pgoff_t start, +pgoff_t final_page, +unsigned *_offset, +unsigned *_to, +bool new_content) { -struct afs_vnode *vnode =AFS_FS_I (mapping->host); -struct iov_iter iter;struct page *pages[8 ], *page; -unsigned long count, priv; -unsigned n, offset, to, f, t; -pgoff_t start, first, last; -loff_t i_size, pos, end; -int loop, ret; - -_enter (",%lx" , primary_page->index); - - count =1 ; -if (test_set_page_writeback (primary_page)) -BUG (); - -/* Find all consecutive lockable dirty pages that have contiguous -* written regions, stopping when we find a page that is not -* immediately lockable, is not dirty or is missing, or we reach the -* end of the range. -*/ - start = primary_page->index; - priv =page_private (primary_page); - offset =afs_page_dirty_from (primary_page, priv); - to =afs_page_dirty_to (primary_page, priv); -trace_afs_page_dirty (vnode,tracepoint_string ("store" ), primary_page); - -WARN_ON (offset == to); -if (offset == to) -trace_afs_page_dirty (vnode,tracepoint_string ("WARN" ), primary_page); - -if (start >= final_page || - (to <PAGE_SIZE && !test_bit (AFS_VNODE_NEW_CONTENT , &vnode->flags))) - goto no_more; +unsigned long count = *_count, priv; +unsigned offset = *_offset, to = *_to, n, f, t; +int loop; start++; do {
@@ -551,8 +529,7 @@ static int afs_write_back_from_locked_page(struct address_space *mapping,for (loop =0 ; loop < n; loop++) { page = pages[loop]; -if (to !=PAGE_SIZE && - !test_bit (AFS_VNODE_NEW_CONTENT , &vnode->flags)) +if (to !=PAGE_SIZE && !new_content)break ;if (page->index > final_page)break ;
@@ -566,8 +543,7 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, priv =page_private (page); f =afs_page_dirty_from (page, priv); t =afs_page_dirty_to (page, priv); -if (f !=0 && - !test_bit (AFS_VNODE_NEW_CONTENT , &vnode->flags)) { +if (f !=0 && !new_content) {unlock_page (page);break ; }
@@ -593,6 +569,55 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, }while (start <= final_page && count <65536 ); no_more: + *_count = count; + *_offset = offset; + *_to = to; +} + +/* +* Synchronously write back the locked page and any subsequent non-locked dirty +* pages. +*/ +static int afs_write_back_from_locked_page (struct address_space *mapping, +struct writeback_control *wbc, +struct page *primary_page, +pgoff_t final_page) +{ +struct afs_vnode *vnode =AFS_FS_I (mapping->host); +struct iov_iter iter; +unsigned long count, priv; +unsigned offset, to; +pgoff_t start, first, last; +loff_t i_size, pos, end; +bool new_content =test_bit (AFS_VNODE_NEW_CONTENT , &vnode->flags); +int ret; + +_enter (",%lx" , primary_page->index); + + count =1 ; +if (test_set_page_writeback (primary_page)) +BUG (); + +/* Find all consecutive lockable dirty pages that have contiguous +* written regions, stopping when we find a page that is not +* immediately lockable, is not dirty or is missing, or we reach the +* end of the range. +*/ + start = primary_page->index; + priv =page_private (primary_page); + offset =afs_page_dirty_from (primary_page, priv); + to =afs_page_dirty_to (primary_page, priv); +trace_afs_page_dirty (vnode,tracepoint_string ("store" ), primary_page); + +WARN_ON (offset == to); +if (offset == to) +trace_afs_page_dirty (vnode,tracepoint_string ("WARN" ), primary_page); + +if (start < final_page && + (to ==PAGE_SIZE || new_content)) +afs_extend_writeback (mapping, vnode, &count, start, final_page, + &offset, &to, new_content); +/* We now have a contiguous set of dirty pages, each with writeback * set; the first page is still locked at this point, but all the rest * have been unlocked.
David Howells
maintainerPATCH v4 25/28 afs: Prepare for use of THPs
In reply to David HowellsAs a prelude to supporting transparent huge pages, use thp_size() and similar rather than PAGE_SIZE/SHIFT.
Further, try and frame everything in terms of file positions and lengths rather than page indices and numbers of pages.
---
fs/afs/dir.c | 2 fs/afs/file.c | 8 - fs/afs/internal.h | 2 fs/afs/write.c | 436 +++++++++++++++++++++++++++++------------------------ 4 files changed, 245 insertions(+), 203 deletions(-)
fs/afs/dir.c +1 -1
@@ -2084,6 +2084,6 @@ static void afs_dir_invalidatepage(struct page *page, unsigned int offset,afs_stat_v (dvnode, n_inval);/* we clean up only if the entire page is being invalidated */ -if (offset ==0 && length ==PAGE_SIZE ) +if (offset ==0 && length ==thp_size (page))detach_page_private (page); }
fs/afs/file.c +4 -4
@@ -330,8 +330,8 @@ static int afs_page_filler(struct key *key, struct page *page) req->vnode = vnode; req->key =key_get (key); req->pos = (loff_t )page->index <<PAGE_SHIFT ; - req->len =PAGE_SIZE ; - req->nr_pages =1 ; + req->len =thp_size (page); + req->nr_pages =thp_nr_pages (page); req->done = afs_file_read_done; req->cleanup = afs_file_read_cleanup;
@@ -575,8 +575,8 @@ static void afs_invalidate_dirty(struct page *page, unsigned int offset,trace_afs_page_dirty (vnode,tracepoint_string ("undirty" ), page);clear_page_dirty_for_io (page); full_invalidate: -detach_page_private (page);trace_afs_page_dirty (vnode,tracepoint_string ("inval" ), page); +detach_page_private (page); }/*
@@ -621,8 +621,8 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)#endif if (PagePrivate (page)) { -detach_page_private (page);trace_afs_page_dirty (vnode,tracepoint_string ("rel" ), page); +detach_page_private (page); }/* indicate that the page can be released */
fs/afs/internal.h +0 -2
@@ -815,8 +815,6 @@ struct afs_operation {loff_t pos;loff_t size;loff_t i_size; -pgoff_t first;/* first page in mapping to deal with */ -pgoff_t last;/* last page in mapping to deal with */ bool laundering;/* Laundering page, PG_writeback not set */ } store;struct {
fs/afs/write.c +240 -196
755 lines not on this page · raw message
David Howells
maintainerPATCH v4 26/28 afs: Use the fs operation ops to handle FetchData completion
In reply to David HowellsUse the 'success' and 'aborted' afs_operations_ops methods and add a 'failed' method to handle the completion of an AFS.FetchData, AFS.FetchData64 or YFS.FetchData64 RPC operation rather than directly calling the done func pointed to by the afs_read struct from the call delivery handler.
This means the done function will be called back on error also, not just on successful completion.
This allows motion towards asynchronous data reception on data fetch calls and allows any error to be handed off to the fscache read helper in the same place as a successful completion.
---
fs/afs/file.c | 15 +++++++++++++++ fs/afs/fs_operation.c | 4 +++- fs/afs/fsclient.c | 3 --- fs/afs/internal.h | 1 + fs/afs/yfsclient.c | 3 --- 5 files changed, 19 insertions(+), 7 deletions(-)
fs/afs/file.c +15 -0
@@ -255,6 +255,19 @@ void afs_put_read(struct afs_read *req) } } +static void afs_fetch_data_notify (struct afs_operation *op) +{ +struct afs_read *req = op->fetch.req; +int error = op->error; + +if (error == -ECONNABORTED ) + error =afs_abort_to_error (op->ac.abort_code); + req->error = error; + +if (req->done) + req->done (req); +} +static void afs_fetch_data_success (struct afs_operation *op) {struct afs_vnode *vnode = op->file[0 ].vnode;
@@ -263,6 +276,7 @@ static void afs_fetch_data_success(struct afs_operation *op)afs_vnode_commit_status (op, &op->file[0 ]);afs_stat_v (vnode, n_fetches);atomic_long_add (op->fetch.req->actual_len, &op->net->n_fetch_bytes); +afs_fetch_data_notify (op); }static void afs_fetch_data_put (struct afs_operation *op)
@@ -276,6 +290,7 @@ static const struct afs_operation_ops afs_fetch_data_operation = { .issue_yfs_rpc = yfs_fs_fetch_data, .success = afs_fetch_data_success, .aborted = afs_check_for_remote_deletion, + .failed = afs_fetch_data_notify, .put = afs_fetch_data_put, };
fs/afs/fs_operation.c +3 -1
@@ -195,8 +195,10 @@ void afs_wait_for_operation(struct afs_operation *op)case -ECONNABORTED :if (op->ops->aborted) op->ops->aborted (op); -break ; + fallthrough;default : +if (op->ops->failed) + op->ops->failed (op);break ; }
fs/afs/fsclient.c +0 -3
@@ -392,9 +392,6 @@ static int afs_deliver_fs_fetch_data(struct afs_call *call)break ; } -if (req->done) - req->done (req); -_leave (" = 0 [done]" );return 0 ; }
fs/afs/internal.h +1 -0
@@ -742,6 +742,7 @@ struct afs_operation_ops {void (*issue_yfs_rpc)(struct afs_operation *op);void (*success)(struct afs_operation *op);void (*aborted)(struct afs_operation *op); +void (*failed)(struct afs_operation *op);void (*edit_dir)(struct afs_operation *op);void (*put)(struct afs_operation *op); };
fs/afs/yfsclient.c +0 -3
@@ -449,9 +449,6 @@ static int yfs_deliver_fs_fetch_data64(struct afs_call *call)break ; } -if (req->done) - req->done (req); -_leave (" = 0 [done]" );return 0 ; }
David Howells
maintainerPATCH v4 27/28 afs: Use new fscache read helper API
In reply to David HowellsMake AFS use the new fscache read helpers to implement the VM read operations:
- afs_readpage() now hands off responsibility to fscache_readpage().
- afs_readpages() is gone and replaced with afs_readahead().
- afs_readahead() just hands off responsibility to fscache_readahead().
These make use of the cache if a cookie is supplied, otherwise just call the ->issue_op() method a sufficient number of times to complete the entire request.
Changes:
- Folded in error handling fixes to afs_req_issue_op().
- Added flag to netfs_subreq_terminated() to indicate that the caller may have been running async and stuff that might sleep needs punting to a workqueue.
---
fs/afs/Kconfig | 1 fs/afs/file.c | 327 +++++++++++++---------------------------------------- fs/afs/fsclient.c | 1 fs/afs/internal.h | 3 4 files changed, 83 insertions(+), 249 deletions(-)
fs/afs/Kconfig +1 -0
@@ -4,6 +4,7 @@ config AFS_FS depends on INET select AF_RXRPC select DNS_RESOLVER + select NETFS_SUPPORT help If you say Y here, you will get an experimental Andrew File System driver. It currently only supports unsecured read-only AFS access.
fs/afs/file.c +78 -249
404 lines not on this page · raw message
fs/afs/fsclient.c +1 -0
@@ -10,6 +10,7 @@#include <linux/sched.h> #include <linux/circ_buf.h> #include <linux/iversion.h> +#include <linux/netfs.h> #include "internal.h" #include "afs_fs.h" #include "xdr_fs.h"
fs/afs/internal.h +3 -0
@@ -14,6 +14,7 @@#include <linux/key.h> #include <linux/workqueue.h> #include <linux/sched.h> +#define FSCACHE_USE_NEW_IO_API #include <linux/fscache.h> #include <linux/backing-dev.h> #include <linux/uuid.h>
@@ -207,6 +208,7 @@ struct afs_read {loff_t file_size;/* File size returned by server */ struct key *key;/* The key to use to reissue the read */ struct afs_vnode *vnode;/* The file being read into. */ +struct netfs_read_subrequest *subreq;/* Fscache helper read request this belongs to */ afs_dataversion_t data_version;/* Version number returned by server */ refcount_t usage;unsigned int call_debug_id;
@@ -1049,6 +1051,7 @@ extern void afs_put_wb_key(struct afs_wb_key *);extern int afs_open (struct inode *,struct file *);extern int afs_release (struct inode *,struct file *);extern int afs_fetch_data (struct afs_vnode *,struct afs_read *); +extern struct afs_read *afs_alloc_read (gfp_t );extern void afs_put_read (struct afs_read *);static inline struct afs_read *afs_get_read (struct afs_read *req)
David Howells
maintainerPATCH v4 28/28 afs: Use the fscache_write_begin() helper
In reply to David HowellsMake AFS use the new fscache_write_begin() helper to do the pre-reading required before the write. If successful, the helper returns with the required page filled in and locked. It may read more than just one page, expanding the read to meet cache granularity requirements as necessary.
Note: A more advanced version of this could be made that does generic_perform_write() for a whole cache granule. This would make it easier to avoid doing the download/read for the data to be overwritten.
---
fs/afs/file.c | 19 +++++++++ fs/afs/internal.h | 1 fs/afs/write.c | 108 ++++++----------------------------------------------- 3 files changed, 31 insertions(+), 97 deletions(-)
fs/afs/file.c +18 -1
@@ -334,6 +334,13 @@ static void afs_init_rreq(struct netfs_read_request *rreq, struct file *file) rreq->netfs_priv =key_get (afs_file_key (file)); } +static bool afs_is_cache_enabled (struct inode *inode) +{ +struct fscache_cookie *cookie =afs_vnode_cache (AFS_FS_I (inode)); + +return fscache_cookie_enabled (cookie) && !hlist_empty (&cookie->backing_objects); +} +static int afs_begin_cache_operation (struct netfs_read_request *rreq) {struct afs_vnode *vnode =AFS_FS_I (rreq->inode);
@@ -341,14 +348,24 @@ static int afs_begin_cache_operation(struct netfs_read_request *rreq)return fscache_begin_read_operation (rreq,afs_vnode_cache (vnode)); } +static int afs_check_write_begin (struct file *file,loff_t pos,unsigned len, +struct page *page,void **_fsdata) +{ +struct afs_vnode *vnode =AFS_FS_I (file_inode (file)); + +return test_bit (AFS_VNODE_DELETED , &vnode->flags) ? -ESTALE :0 ; +} +static void afs_priv_cleanup (struct address_space *mapping,void *netfs_priv) {key_put (netfs_priv); } -static const struct netfs_read_request_ops afs_req_ops = { +const struct netfs_read_request_ops afs_req_ops = { .init_rreq = afs_init_rreq, + .is_cache_enabled = afs_is_cache_enabled, .begin_cache_operation = afs_begin_cache_operation, + .check_write_begin = afs_check_write_begin, .issue_op = afs_req_issue_op, .cleanup = afs_priv_cleanup, };
fs/afs/internal.h +1 -0
@@ -1045,6 +1045,7 @@ extern void afs_dynroot_depopulate(struct super_block *);extern const struct address_space_operations afs_fs_aops;extern const struct inode_operations afs_file_inode_operations;extern const struct file_operations afs_file_operations; +extern const struct netfs_read_request_ops afs_req_ops;extern int afs_cache_wb_key (struct afs_vnode *,struct afs_file *);extern void afs_put_wb_key (struct afs_wb_key *);
fs/afs/write.c +12 -96
148 lines not on this page · raw message