Permit filesystem local caching [try #2]
Subsystems (18)
David Howells
maintainercover Permit filesystem local caching [try #2]
These patches add local caching for network filesystems such as NFS and AFS.
FS-Cache now runs fully asynchronously as required by Trond Myklebust for NFS.
--
Changes:
(*) The CacheFiles module no longer accepts directory fds in its cull and
inuse commands from cachefilesd. Instead it uses the current working directory of the calling process as the basis for looking up the object. Corollary to this, fget_light() no longer needs to be exported.
--
A tarball of the patches is available at:
http://people.redhat.com/~dhowells/fscache/patches/nfs+fscache-21.tar.bz2
To use this version of CacheFiles, the cachefilesd-0.9 is also required. It is available as an SRPM:
http://people.redhat.com/~dhowells/fscache/cachefilesd-0.9-1.fc7.src.rpm
Or as individual bits:
http://people.redhat.com/~dhowells/fscache/cachefilesd-0.9.tar.bz2
http://people.redhat.com/~dhowells/fscache/cachefilesd.fc
http://people.redhat.com/~dhowells/fscache/cachefilesd.if
http://people.redhat.com/~dhowells/fscache/cachefilesd.te
http://people.redhat.com/~dhowells/fscache/cachefilesd.spec
The .fc, .if and .te files are for manipulating SELinux.
David
David Howells
maintainerPATCH 1/14 FS-Cache: Release page->private after failed readahead [try #2]
The attached patch causes read_cache_pages() to release page-private data on a page for which add_to_page_cache() fails or the filler function fails. This permits pages with caching references associated with them to be cleaned up.
The invalidatepage() address space op is called (indirectly) to do the honours.
---
mm/readahead.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 files changed, 38 insertions(+), 2 deletions(-)
mm/readahead.c +38 -2
@@ -15,6 +15,7 @@#include <linux/backing-dev.h> #include <linux/task_io_accounting_ops.h> #include <linux/pagevec.h> +#include <linux/buffer_head.h> void default_unplug_io_fn (struct backing_dev_info *bdi,struct page *page) {
@@ -51,6 +52,41 @@ EXPORT_SYMBOL_GPL(file_ra_state_init);#define list_to_page (head) (list_entry((head)->prev, struct page, lru)) +/* +* see if a page needs releasing upon read_cache_pages() failure +* - the caller of read_cache_pages() may have set PG_private before calling, +* such as the NFS fs marking pages that are cached locally on disk, thus we +* need to give the fs a chance to clean up in the event of an error +*/ +static void read_cache_pages_invalidate_page (struct address_space *mapping, +struct page *page) +{ +if (PagePrivate (page)) { +if (TestSetPageLocked (page)) +BUG (); + page->mapping = mapping; +do_invalidatepage (page,0 ); + page->mapping =NULL ; +unlock_page (page); + } +page_cache_release (page); +} + +/* +* release a list of pages, invalidating them first if need be +*/ +static void read_cache_pages_invalidate_pages (struct address_space *mapping, +struct list_head *pages) +{ +struct page *victim; + +while (!list_empty (pages)) { + victim =list_to_page (pages); +list_del (&victim->lru); +read_cache_pages_invalidate_page (mapping, victim); + } +} +/** * read_cache_pages - populate an address space with some pages & start reads against them * @mapping: the address_space
@@ -74,14 +110,14 @@ int read_cache_pages(struct address_space *mapping, struct list_head *pages, page =list_to_page (pages);list_del (&page->lru);if (add_to_page_cache (page, mapping, page->index,GFP_KERNEL )) { -page_cache_release (page); +read_cache_pages_invalidate_page (mapping, page);continue ; } ret =filler (data, page);if (!pagevec_add (&lru_pvec, page))__pagevec_lru_add (&lru_pvec);if (ret) { -put_pages_list (pages); +read_cache_pages_invalidate_pages (mapping, pages);break ; }task_io_account_read (PAGE_CACHE_SIZE );
David Howells
maintainerPATCH 2/14 FS-Cache: Recruit a couple of page flags for cache management [try #2]
In reply to David HowellsRecruit a couple of page flags to aid in cache management. The following extra flags are defined:
(1) PG_fscache (PG_owner_priv_2)
The marked page is backed by a local cache and is pinning resources in the cache driver.
(2) PG_fscache_write (PG_owner_priv_3)
The marked page is being written to the local cache. The page may not be modified whilst this is in progress.
If PG_fscache is set, then things that checked for PG_private will now also check for that. This includes things like truncation and page invalidation. The function page_has_private() had been added to detect this.
---
fs/splice.c | 2 +- include/linux/page-flags.h | 30 +++++++++++++++++++++++++++++- include/linux/pagemap.h | 11 +++++++++++ mm/filemap.c | 16 ++++++++++++++++ mm/migrate.c | 2 +- mm/page_alloc.c | 3 +++ mm/readahead.c | 9 +++++---- mm/swap.c | 4 ++-- mm/swap_state.c | 4 ++-- mm/truncate.c | 10 +++++----- mm/vmscan.c | 2 +- 11 files changed, 76 insertions(+), 17 deletions(-)
fs/splice.c +1 -1
@@ -58,7 +58,7 @@ static int page_cache_pipe_buf_steal(struct pipe_inode_info *pipe,*/ wait_on_page_writeback (page); -if (PagePrivate (page)) +if (page_has_private (page))try_to_release_page (page,GFP_KERNEL );/*
include/linux/page-flags.h +29 -1
@@ -83,19 +83,24 @@#define PG_private 11/* If pagecache, has fs-private data */ #define PG_writeback 12/* Page is under writeback */ +#define PG_owner_priv_2 13/* Owner use. If pagecache, fs may use */ #define PG_compound 14/* Part of a compound page */ #define PG_swapcache 15/* Swap page: swp_entry_t in private */ #define PG_mappedtodisk 16/* Has blocks allocated on-disk */ #define PG_reclaim 17/* To be reclaimed asap */ +#define PG_owner_priv_3 18/* Owner use. If pagecache, fs may use */ #define PG_buddy 19/* Page is free, on buddy lists */ /* PG_readahead is only used for file reads; PG_reclaim is only for writes */ #define PG_readahead PG_reclaim/* Reminder to do async read-ahead */ -/* PG_owner_priv_1 users should have descriptive aliases */ +/* PG_owner_priv_1/2/3 users should have descriptive aliases */ #define PG_checked PG_owner_priv_1/* Used by some filesystems */ #define PG_pinned PG_owner_priv_1/* Xen pinned pagetable */ +#define PG_fscache PG_owner_priv_2/* Backed by local cache */ +#define PG_fscache_write PG_owner_priv_3/* Writing to local cache */ +#if (BITS_PER_LONG >32 )/*
@@ -199,6 +204,18 @@ static inline void SetPageUptodate(struct page *page)#define TestClearPageWriteback (page) test_and_clear_bit(PG_writeback, \ &(page)->flags) +#define PageFsCache (page) test_bit(PG_fscache, &(page)->flags) +#define SetPageFsCache (page) set_bit(PG_fscache, &(page)->flags) +#define ClearPageFsCache (page) clear_bit(PG_fscache, &(page)->flags) +#define TestSetPageFsCache (page) test_and_set_bit(PG_fscache, &(page)->flags) +#define TestClearPageFsCache (page) test_and_clear_bit(PG_fscache, &(page)->flags) + +#define PageFsCacheWrite (page) test_bit(PG_fscache_write, &(page)->flags) +#define SetPageFsCacheWrite (page) set_bit(PG_fscache_write, &(page)->flags) +#define ClearPageFsCacheWrite (page) clear_bit(PG_fscache_write, &(page)->flags) +#define TestSetPageFsCacheWrite (page) test_and_set_bit(PG_fscache_write, &(page)->flags) +#define TestClearPageFsCacheWrite (page) test_and_clear_bit(PG_fscache_write, &(page)->flags) +#define PageBuddy (page) test_bit(PG_buddy, &(page)->flags)#define __SetPageBuddy (page) __set_bit(PG_buddy, &(page)->flags)#define __ClearPageBuddy (page) __clear_bit(PG_buddy, &(page)->flags)
@@ -272,4 +289,15 @@ static inline void set_page_writeback(struct page *page) test_set_page_writeback(page); } +/** +* page_has_private - Determine if page has private stuff +* @page: The page to be checked +* +* Determine if a page has private stuff, indicating that release routines +* should be invoked upon it. +*/ +#define page_has_private (page) \ + ((page)->flags & ((1 << PG_private) | \ + (1 << PG_fscache))) +#endif /* PAGE_FLAGS_H */
include/linux/pagemap.h +11 -0
@@ -208,6 +208,17 @@ static inline void wait_on_page_writeback(struct page *page)extern void end_page_writeback (struct page *page); +/* +* Wait for a page to finish being written to a local cache +*/ +static inline void wait_on_page_fscache_write (struct page *page) +{ +if (PageFsCacheWrite (page)) +wait_on_page_bit (page, PG_fscache_write); +} + +extern void end_page_fscache_write (struct page *page); +/* * Fault a userspace page into pagetables. Return non-zero on a fault. *
mm/filemap.c +16 -0
@@ -557,6 +557,19 @@ void end_page_writeback(struct page *page)EXPORT_SYMBOL (end_page_writeback);/** +* end_page_fscache_write - End writing page to cache +* @page: the page +*/ +void end_page_fscache_write (struct page *page) +{ +if (!TestClearPageFsCacheWrite (page)) +BUG (); +smp_mb__after_clear_bit (); +wake_up_page (page, PG_fscache_write); +} +EXPORT_SYMBOL (end_page_fscache_write); + +/** * __lock_page - get a lock on the page, assuming we need to sleep to get it * @page: the page to lock *
@@ -2243,6 +2256,9 @@ out:* (presumably at page->private). If the release was successful, return `1'. * Otherwise return zero. * +* This may also be called if PG_fscache is set on a page, indicating that the +* page is known to the local caching routines. +* * The @gfp_mask argument specifies whether I/O may be performed to release * this page (__GFP_IO), and whether the call may block (__GFP_WAIT). *
mm/migrate.c +1 -1
@@ -544,7 +544,7 @@ static int fallback_migrate_page(struct address_space *mapping,* Buffers may be managed in a filesystem specific way. * We must have no buffers or drop them. */ -if (PagePrivate (page) && +if (page_has_private (page) && !try_to_release_page (page,GFP_KERNEL ))return -EAGAIN ;
mm/page_alloc.c +3 -0
@@ -208,6 +208,7 @@ static void bad_page(struct page *page)dump_stack (); page->flags &= ~(1 << PG_lru | 1 << PG_private | + 1 << PG_fscache | 1 << PG_locked | 1 << PG_active | 1 << PG_dirty |
@@ -445,6 +446,7 @@ static inline int free_pages_check(struct page *page) (page->flags & ( 1 << PG_lru | 1 << PG_private | + 1 << PG_fscache | 1 << PG_locked | 1 << PG_active | 1 << PG_slab |
@@ -593,6 +595,7 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags) (page->flags & ( 1 << PG_lru | 1 << PG_private | + 1 << PG_fscache | 1 << PG_locked | 1 << PG_active | 1 << PG_dirty |
mm/readahead.c +5 -4
@@ -54,14 +54,15 @@ EXPORT_SYMBOL_GPL(file_ra_state_init);/* * see if a page needs releasing upon read_cache_pages() failure -* - the caller of read_cache_pages() may have set PG_private before calling, -* such as the NFS fs marking pages that are cached locally on disk, thus we -* need to give the fs a chance to clean up in the event of an error +* - the caller of read_cache_pages() may have set PG_private or PG_fscache +* before calling, such as the NFS fs marking pages that are cached locally +* on disk, thus we need to give the fs a chance to clean up in the event of +* an error */ static void read_cache_pages_invalidate_page (struct address_space *mapping,struct page *page) { -if (PagePrivate (page)) { +if (page_has_private (page)) {if (TestSetPageLocked (page))BUG (); page->mapping = mapping;
mm/swap.c +2 -2
@@ -412,8 +412,8 @@ void pagevec_strip(struct pagevec *pvec)for (i =0 ; i <pagevec_count (pvec); i++) {struct page *page = pvec->pages[i]; -if (PagePrivate (page) && !TestSetPageLocked (page)) { -if (PagePrivate (page)) +if (page_has_private (page) && !TestSetPageLocked (page)) { +if (page_has_private (page))try_to_release_page (page,0 );unlock_page (page); }
mm/swap_state.c +2 -2
@@ -75,7 +75,7 @@ static int __add_to_swap_cache(struct page *page, swp_entry_t entry,int error;BUG_ON (PageSwapCache (page)); -BUG_ON (PagePrivate (page)); +BUG_ON (page_has_private (page)); error =radix_tree_preload (gfp_mask);if (!error) {write_lock_irq (&swapper_space.tree_lock);
@@ -126,7 +126,7 @@ void __delete_from_swap_cache(struct page *page)BUG_ON (!PageLocked (page));BUG_ON (!PageSwapCache (page));BUG_ON (PageWriteback (page)); -BUG_ON (PagePrivate (page)); +BUG_ON (page_has_private (page));radix_tree_delete (&swapper_space.page_tree,page_private (page));set_page_private (page,0 );
mm/truncate.c +5 -5
@@ -48,7 +48,7 @@ void do_invalidatepage(struct page *page, unsigned long offset)static inline void truncate_partial_page (struct page *page,unsigned partial) {zero_user_page (page, partial,PAGE_CACHE_SIZE - partial,KM_USER0 ); -if (PagePrivate (page)) +if (page_has_private (page))do_invalidatepage (page, partial); }
@@ -97,7 +97,7 @@ truncate_complete_page(struct address_space *mapping, struct page *page)cancel_dirty_page (page,PAGE_CACHE_SIZE ); -if (PagePrivate (page)) +if (page_has_private (page))do_invalidatepage (page,0 );remove_from_page_cache (page);
@@ -122,7 +122,7 @@ invalidate_complete_page(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return 0 ; -if (PagePrivate (page) && !try_to_release_page (page,0 )) +if (page_has_private (page) && !try_to_release_page (page,0 ))return 0 ; ret =remove_mapping (mapping, page);
@@ -344,14 +344,14 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page)if (page->mapping != mapping)return 0 ; -if (PagePrivate (page) && !try_to_release_page (page,GFP_KERNEL )) +if (page_has_private (page) && !try_to_release_page (page,GFP_KERNEL ))return 0 ;write_lock_irq (&mapping->tree_lock);if (PageDirty (page)) goto failed; -BUG_ON (PagePrivate (page)); +BUG_ON (page_has_private (page));__remove_from_page_cache (page);write_unlock_irq (&mapping->tree_lock);ClearPageUptodate (page);
mm/vmscan.c +1 -1
@@ -548,7 +548,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,* process address space (page_count == 1) it can be freed. * Otherwise, leave the page on the LRU so it is swappable. */ -if (PagePrivate (page)) { +if (page_has_private (page)) {if (!try_to_release_page (page, sc->gfp_mask)) goto activate_locked;if (!mapping &&page_count (page) ==1 )
David Howells
maintainerPATCH 3/14 FS-Cache: Provide an add_wait_queue_tail() function [try #2]
In reply to David HowellsProvide an add_wait_queue_tail() function to add a waiter to the back of a wait queue instead of the front.
---
include/linux/wait.h | 1 + kernel/wait.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
include/linux/wait.h +1 -0
@@ -118,6 +118,7 @@ static inline int waitqueue_active(wait_queue_head_t *q)#define is_sync_wait (wait) (!(wait) || ((wait)->private))extern void FASTCALL (add_wait_queue (wait_queue_head_t *q,wait_queue_t * wait)); +extern void FASTCALL (add_wait_queue_tail (wait_queue_head_t *q,wait_queue_t * wait));extern void FASTCALL (add_wait_queue_exclusive (wait_queue_head_t *q,wait_queue_t * wait));extern void FASTCALL (remove_wait_queue (wait_queue_head_t *q,wait_queue_t * wait));
kernel/wait.c +18 -0
@@ -29,6 +29,24 @@ void fastcall add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait) }EXPORT_SYMBOL (add_wait_queue); +/** +* add_wait_queue_tail - Add a waiter to the back of a waitqueue +* @q: the wait queue to append the waiter to +* @wait: the waiter to be queued +* +* Add a waiter to the back of a waitqueue so that it gets woken up last. +*/ +void fastcall add_wait_queue_tail(wait_queue_head_t *q, wait_queue_t *wait) +{ +unsigned long flags; + + wait->flags &= ~WQ_FLAG_EXCLUSIVE ; +spin_lock_irqsave (&q->lock, flags); +__add_wait_queue_tail (q, wait); +spin_unlock_irqrestore (&q->lock, flags); +} +EXPORT_SYMBOL (add_wait_queue_tail); + void fastcall add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait) {unsigned long flags;
David Howells
maintainerPATCH 4/14 FS-Cache: Generic filesystem caching facility [try #2]
In reply to David HowellsThe attached patch adds a generic intermediary (FS-Cache) by which filesystems may call on local caching capabilities, and by which local caching backends may make caches available:
+---------+ | | +--------------+ | NFS |--+ | | | | | +-->| CacheFS | +---------+ | +----------+ | | /dev/hda5 | | | | | +--------------+ +---------+ +-->| | | | | | |--+ | AFS |----->| FS-Cache | | | | |--+ +---------+ +-->| | | | | | | +--------------+ +---------+ | +----------+ | | | | | | +-->| CacheFiles | | ISOFS |--+ | /var/cache | | | +--------------+ +---------+
The patch also documents the netfs interface and the cache backend interface provided by the facility.
There are a number of reasons why I'm not using i_mapping to do this. These have been discussed a lot on the LKML and CacheFS mailing lists, but to summarise the basics:
(1) Most filesystems don't do hole reportage. Holes in files are treated as blocks of zeros and can't be distinguished otherwise, making it difficult to distinguish blocks that have been read from the network and cached from those that haven't.
(2) The backing inode must be fully populated before being exposed to userspace through the main inode because the VM/VFS goes directly to the backing inode and does not interrogate the front inode on VM ops.
Therefore:
(a) The backing inode must fit entirely within the cache.
(b) All backed files currently open must fit entirely within the cache at the same time.
(c) A working set of files in total larger than the cache may not be cached.
(d) A file may not grow larger than the available space in the cache.
(e) A file that's open and cached, and remotely grows larger than the cache is potentially stuffed.
(3) Writes go to the backing filesystem, and can only be transferred to the network when the file is closed.
(4) There's no record of what changes have been made, so the whole file must be written back.
(5) The pages belong to the backing filesystem, and all metadata associated with that page are relevant only to the backing filesystem, and not anything stacked atop it.
The attached patch adds a generic core to which both networking filesystems and caches may bind. It transfers requests from networking filesystems to appropriate caches if possible, or else gracefully denies them.
If this facility is disabled in the kernel configuration, then all its operations will be trivially reducible to nothing by the compiler.
FS-Cache provides the following facilities:
(1) Caches can be added / removed at any time, even whilst in use.
(2) Adds a facility by which tags can be used to refer to caches, even if they're not mounted yet.
(3) More than one cache can be used at once. Caches can be selected explicitly by use of tags.
(4) The netfs is provided with an interface that allows either party to withdraw caching facilities from a file (required for (1)).
(5) A netfs may annotate cache objects that belongs to it.
(6) Cache objects can be pinned and reservations made.
(7) The interface to the netfs returns as few errors as possible, preferring rather to let the netfs remain oblivious.
(8) Cookies are used to represent indices, files and other objects to the netfs. The simplest cookie is just a NULL pointer - indicating nothing cached there.
(9) The netfs is allowed to propose - dynamically - any index hierarchy it desires, though it must be aware that the index search function is recursive, stack space is limited, and indices can only be children of indices.
(10) Indices can be used to group files together to reduce key size and to make group invalidation easier. The use of indices may make lookup quicker, but that's cache dependent.
(11) Data I/O is effectively done directly to and from the netfs's pages. The netfs indicates that page A is at index B of the data-file represented by cookie C, and that it should be read or written. The cache backend may or may not start I/O on that page, but if it does, a netfs callback will be invoked to indicate completion. The I/O may be either synchronous or asynchronous.
(12) Cookies can be "retired" upon release. At this point FS-Cache will mark them as obsolete and the index hierarchy rooted at that point will get recycled.
(13) The netfs provides a "match" function for index searches. In addition to saying whether a match was made or not, this can also specify that an entry should be updated or deleted.
FS-Cache maintains a virtual indexing tree in which all indices, files, objects and pages are kept. Bits of this tree may actually reside in one or more caches.
FSDEF
|
+------------------------------------+
| |
NFS AFS
| |
+--------------------------+ +-----------+
| | | |
homedir mirror afs.org redhat.com
| | |
+------------+ +---------------+ +----------+
| | | | | |
00001 00002 00007 00125 vol00001 vol00002
| | | | |
+---+---+ +-----+ +---+ +------+------+ +-----+----+
| | | | | | | | | | | | |
PG0 PG1 PG2 PG0 XATTR PG0 PG1 DIRENT DIRENT DIRENT R/W R/O Bak
| |
PG0 +-------+
| |
00001 00003
|
+---+---+
| | |
PG0 PG1 PG2In the example above, you can see two netfs's being backed: NFS and AFS. These have different index hierarchies:
(*) The NFS primary index will probably contain per-server indices. Each
server index is indexed by NFS file handles to get data file objects. Each data file objects can have an array of pages, but may also have further child objects, such as extended attributes and directory entries. Extended attribute objects themselves have page-array contents.
(*) The AFS primary index contains per-cell indices. Each cell index contains
per-logical-volume indices. Each of volume index contains up to three indices for the read-write, read-only and backup mirrors of those volumes. Each of these contains vnode data file objects, each of which contains an array of pages.
The very top index is the FS-Cache master index in which individual netfs's have entries.
Any index object may reside in more than one cache, provided it only has index children. Any index with non-index object children will be assumed to only reside in one cache.
The FS-Cache overview can be found in:
Documentation/filesystems/caching/fscache.txt
The netfs API to FS-Cache can be found in:
Documentation/filesystems/caching/netfs-api.txt
The cache backend API to FS-Cache can be found in:
Documentation/filesystems/caching/backend-api.txt
---
Documentation/filesystems/caching/backend-api.txt | 625 +++++++++++++++ Documentation/filesystems/caching/fscache.txt | 295 +++++++ Documentation/filesystems/caching/netfs-api.txt | 741 ++++++++++++++++++ fs/Kconfig | 6 fs/Makefile | 1 fs/fscache/Kconfig | 49 + fs/fscache/Makefile | 19 fs/fscache/fsc-cache.c | 512 ++++++++++++ fs/fscache/fsc-cookie.c | 494 ++++++++++++ fs/fscache/fsc-fsdef.c | 111 +++ fs/fscache/fsc-internal.h | 376 +++++++++ fs/fscache/fsc-main.c | 127 +++ fs/fscache/fsc-manage.c | 260 ++++++ fs/fscache/fsc-object.c | 586 ++++++++++++++ fs/fscache/fsc-page.c | 863 +++++++++++++++++++++ fs/fscache/fsc-proc.c | 399 ++++++++++ fs/fscache/fsc-stats.c | 103 +++ fs/fscache/fsc-threads.c | 590 ++++++++++++++ include/linux/fscache-cache.h | 433 +++++++++++ include/linux/fscache.h | 593 ++++++++++++++ 20 files changed, 7183 insertions(+), 0 deletions(-)
Documentation/filesystems/caching/backend-api.txt new file +625 -0
@@ -0,0 +1,625 @@ + ========================== + FS-CACHE CACHE BACKEND API + ========================== + +The FS-Cache system provides an API by which actual caches can be supplied to +FS-Cache for it to then serve out to network filesystems and other interested +parties. + +This API is declared in <linux/fscache-cache.h>. + + +==================================== +INITIALISING AND REGISTERING A CACHE +==================================== + +To start off, a cache definition must be initialised and registered for each +cache the backend wants to make available. For instance, CacheFS does this in +the fill_super() operation on mounting. + +The cache definition (struct fscache_cache) should be initialised by calling: + + void fscache_init_cache(struct fscache_cache *cache, + struct fscache_cache_ops *ops, + const char *idfmt, + ...); + +Where: + + (*) "cache" is a pointer to the cache definition; + + (*) "ops" is a pointer to the table of operations that the backend supports on + this cache; and + + (*) "idfmt" is a format and printf-style arguments for constructing a label + for the cache. + + +The cache should then be registered with FS-Cache by passing a pointer to the +previously initialised cache definition to: + + int fscache_add_cache(struct fscache_cache *cache, + struct fscache_object *fsdef, + const char *tagname); + +Two extra arguments should also be supplied: + + (*) "fsdef" which should point to the object representation for the FS-Cache + master index in this cache. Netfs primary index entries will be created + here. + + (*) "tagname" which, if given, should be a text string naming this cache. If + this is NULL, the identifier will be used instead. For CacheFS, the + identifier is set to name the underlying block device and the tag can be + supplied by mount. + +This function may return -ENOMEM if it ran out of memory or -EEXIST if the tag +is already in use. 0 will be returned on success. + + +===================== +UNREGISTERING A CACHE +===================== + +A cache can be withdrawn from the system by calling this function with a +pointer to the cache definition: + + void fscache_withdraw_cache(struct fscache_cache *cache); + +In CacheFS's case, this is called by put_super(). + + +======== +SECURITY +======== + +The cache methods are executed one of two contexts: + + (1) that of the userspace process that issued the netfs operation that caused + the cache method to be invoked, or + + (2) that of one of the processes in the FS-Cache thread pool. + +In either case, this may not be an appropriate context in which to access the +cache. + +The calling process's fsuid, fsgid and SELinux security identities may need to +be masqueraded for the duration of the cache driver's access to the cache. +This is left to the cache to handle; FS-Cache makes no effort in this regard. + + +=================================== +CONTROL AND STATISTICS PRESENTATION +=================================== + +The cache may present data to the outside world through FS-Cache's interfaces +in sysfs and procfs - the former for control and the latter for statistics. + +A sysfs directory called /sys/fs/fscache/<cachetag>/ is created if CONFIG_SYSFS +is enabled. This is accessible through the kobject struct fscache_cache::kobj +and is for use by the cache as it sees fit. + +The cache driver may create itself a directory named for the cache type in the +/proc/fs/fscache/ directory. This is available if CONFIG_FSCACHE_PROC is +enabled and is accessible through: + + struct proc_dir_entry *proc_fscache; + + +======================== +RELEVANT DATA STRUCTURES +======================== + + (*) Index/Data file FS-Cache representation cookie: + + struct fscache_cookie { + struct fscache_object_def *def; + struct fscache_netfs *netfs; + void *netfs_data; + ... + }; + + The fields that might be of use to the backend describe the object + definition, the netfs definition and the netfs's data for this cookie. + The object definition contain functions supplied by the netfs for loading + and matching index entries; these are required to provide some of the + cache operations. + + + (*) In-cache object representation: + + struct fscache_object { + int debug_id; + enum { + FSCACHE_OBJECT_RECYCLING, + ... + } state; + spinlock_t lock + struct fscache_cache *cache; + struct fscache_cookie *cookie; + ... + }; + + Structures of this type should be allocated by the cache backend and + passed to FS-Cache when requested by the appropriate cache operation. In + the case of CacheFS, they're embedded in CacheFS's internal object + structures. + + The debug_id is a simple integer that can be used in debugging messages + that refer to a particular object. In such a case it should be printed + using "OBJ%x" to be consistent with FS-Cache. + + Each object contains a pointer to the cookie that represents the object it + is backing. An object should retired when put_object() is called if it is + in state FSCACHE_OBJECT_RECYCLING. The fscache_object struct should be + initialised by calling fscache_object_init(object). + + + (*) FS-Cache operation record: + + struct fscache_operation { + atomic_t usage; + struct fscache_object *object; + unsigned long flags; + #define FSCACHE_OP_EXCLUSIVE + void (*processor)(struct fscache_operation *op); + void (*release)(struct fscache_operation *op); + ... + }; + + FS-Cache has a pool of threads that it uses to give CPU time to the + various asynchronous operations that need to be done as part of driving + the cache. These are represented by the above structure. The processor + method is called to give the op CPU time, and the release method to get + rid of it when its usage count reaches 0. + + An operation can be made exclusive upon an object by setting the + appropriate flag before enqueuing it with fscache_enqueue_operation(). If + an operation needs more processing time, it should be enqueued again. + + + (*) FS-Cache retrieval operation record: + + struct fscache_retrieval { + struct fscache_operation op; + struct address_space *mapping; + struct list_head *to_do; + ... + }; + + A structure of this type is allocated by FS-Cache to record retrieval and + allocation requests made by the netfs. This struct is then passed to the + backend to do the operation. The backend may get extra refs to it by + calling fscache_get_retrieval() and refs may be discarded by calling + fscache_put_retrieval(). + + A retrieval operation can be used by the backend to do retrieval work. To + do this, the retrieval->op.processor method pointer should be set + appropriately by the backend and fscache_enqueue_retrieval() called to + submit it to the thread pool. CacheFiles, for example, uses this to queue + page examination when it detects PG_lock being cleared. + + The to_do field is an empty list available for the cache backend to use as + it sees fit. + + + (*) FS-Cache storage operation record: + + struct fscache_storage { + struct fscache_operation op; + pgoff_t store_limit; + ... + }; + + A structure of this type is allocated by FS-Cache to record outstanding + writes to be made. FS-Cache itself enqueues this operation and invokes + the write_page() method on the object at appropriate times to effect + storage. + + +================ +CACHE OPERATIONS +================ + +The cache backend provides FS-Cache with a table of operations that can be +performed on the denizens of the cache. These are held in a structure of type: + + struct fscache_cache_ops + + (*) Name of cache provider [mandatory]: + + const char *name + + This isn't strictly an operation, but should be pointed at a string naming + the backend. + + + (*) Allocate a new object [mandatory]: + + struct fscache_object *(*alloc_object)(struct fscache_cache *cache, + struct fscache_cookie *cookie) + + This method is used to allocate a cache object representation to back a + cookie in a particular cache. fscache_object_init() should be called on + the object to initialise it prior to returning. + + This function may also be used to parse the index key to be used for + multiple lookup calls to turn it into a more convenient form. FS-Cache + will call the lookup_complete() method to allow the cache to release the + form once lookup is complete or aborted. + + + (*) Look up and create object [mandatory]: + + void (*lookup_object)(struct fscache_object *object) + + This method is used to look up an object, given that the object is already + allocated and attached to the cookie. This should instantiate that object + in the cache if it can. + + The method should call fscache_object_lookup_negative() as soon as + possible if it determines the object doesn't exist in the cache. If the + object is found to exist and the netfs indicates that it is valid then + fscache_obtained_object() should be called once the object is in a + position to have data stored in it. Similarly, fscache_obtained_object() + should also be called once a non-present object has been created. + + If a lookup error occurs, fscache_object_lookup_error() should be called + to abort the lookup of that object. + + + (*) Release lookup data [mandatory]: + + void (*lookup_complete)(struct fscache_object *object) + + This method is called to ask the cache to release any resources it was + using to perform a lookup. + + + (*) Increment object refcount [mandatory]: + + struct fscache_object *(*grab_object)(struct fscache_object *object) + + This method is called to increment the reference count on an object. It + may fail (for instance if the cache is being withdrawn) by returning NULL. + It should return the object pointer if successful. + + + (*) Lock/Unlock object [mandatory]: + + void (*lock_object)(struct fscache_object *object) + void (*unlock_object)(struct fscache_object *object) + + These methods are used to exclusively lock an object. It must be possible + to schedule with the lock held, so a spinlock isn't sufficient. + + + (*) Pin/Unpin object [optional]: + + int (*pin_object)(struct fscache_object *object) + void (*unpin_object)(struct fscache_object *object) + + These methods are used to pin an object into the cache. Once pinned an + object cannot be reclaimed to make space. Return -ENOSPC if there's not + enough space in the cache to permit this. + + + (*) Update object [mandatory]: + + int (*update_object)(struct fscache_object *object) + + This is called to update the index entry for the specified object. The + new information should be in object->cookie->netfs_data. This can be + obtained by calling object->cookie->def->get_aux()/get_attr(). + + + (*) Discard object [mandatory]: + + void (*drop_object)(struct fscache_object *object) + + This method is called to indicate that an object has been unbound from its + cookie, and that the cache should release the object's resources and + retire it if it's in state FSCACHE_OBJECT_RECYCLING. + + This method should not attempt to release any references held by the + caller. The caller will invoke the put_object() method as appropriate. + + + (*) Release object reference [mandatory]: + + void (*put_object)(struct fscache_object *object) + + This method is used to discard a reference to an object. The object may + be freed when all the references to it are released. + + + (*) Synchronise a cache [mandatory]: + + void (*sync)(struct fscache_cache *cache) + + This is called to ask the backend to synchronise a cache with its backing + device. + + + (*) Dissociate a cache [mandatory]: + + void (*dissociate_pages)(struct fscache_cache *cache) + + This is called to ask a cache to perform any page dissociations as part of + cache withdrawal. + + + (*) Notification that the attributes on a netfs file changed [mandatory]: + + int (*attr_changed)(struct fscache_object *object); + + This is called to indicate to the cache that certain attributes on a netfs + file have changed (for example the maximum size a file may reach). The + cache can read these from the netfs by calling the cookie's get_attr() + method. + + The cache may use the file size information to reserve space on the cache. + It should also call fscache_set_store_limit() to indicate to FS-Cache the + highest byte it's willing to store for an object. + + This method may return -ve if an error occurred or the cache object cannot + be expanded. In such a case, the object will be withdrawn from service. + + This operation is run asynchronously from FS-Cache's thread pool, and + storage and retrieval operations from the netfs are excluded during the + execution of this operation. + + + (*) Reserve cache space for an object's data [optional]: + + int (*reserve_space)(struct fscache_object *object, loff_t size); + + This is called to request that cache space be reserved to hold the data + for an object and the metadata used to track it. Zero size should be + taken as request to cancel a reservation. + + This should return 0 if successful, -ENOSPC if there isn't enough space + available, or -ENOMEM or -EIO on other errors. + + The reservation may exceed the current size of the object, thus permitting + future expansion. If the amount of space consumed by an object would + exceed the reservation, it's permitted to refuse requests to allocate + pages, but not required. An object may be pruned down to its reservation + size if larger than that already. + + + (*) Request page be read from cache [mandatory]: + + int (*read_or_alloc_page)(struct fscache_retrieval *op, + struct page *page, + gfp_t gfp) + + This is called to attempt to read a netfs page from the cache, or to + reserve a backing block if not. FS-Cache will have done as much checking + as it can before calling, but most of the work belongs to the backend. + + If there's no page in the cache, then -ENODATA should be returned if the + backend managed to reserve a backing block; -ENOBUFS or -ENOMEM if it + didn't. + + If there is suitable data in the cache, then a read operation should be + queued and 0 returned. When the read finishes, fscache_end_io() should be + called. + + The fscache_mark_pages_cached() should be called for the page if any cache + metadata is retained. This will indicate to the netfs that the page needs + explicit uncaching. This operation takes a pagevec, thus allowing several + pages to be marked at once. + + The retrieval record pointed to by op should be retained for each page + queued and released when I/O on the page has been formally ended. + fscache_get/put_retrieval() are available for this purpose. + + The retrieval record may be used to get CPU time via the FS-Cache thread + pool. If this is desired, the op->op.processor should be set to point to + the appropriate processing routine, and fscache_enqueue_retrieval() should + be called at an appropriate point to request CPU time. For instance, the + retrieval routine could be enqueued upon the completion of a disk read. + The to_do field in the retrieval record is provided to aid in this. + + If an I/O error occurs, fscache_io_error() should be called and -ENOBUFS + returned if possible or fscache_end_io() called with a suitable error + code.. + + + (*) Request pages be read from cache [mandatory]: + + int (*read_or_alloc_pages)(struct fscache_retrieval *op, + struct list_head *pages, + unsigned *nr_pages, + gfp_t gfp) + + This is like the read_or_alloc_page() method, except it is handed a list + of pages instead of one page. Any pages on which a read operation is + started must be added to the page cache for the specified mapping and also + to the LRU. Such pages must also be removed from the pages list and + *nr_pages decremented per page. + + If there was an error such as -ENOMEM, then that should be returned; else + if one or more pages couldn't be read or allocated, then -ENOBUFS should + be returned; else if one or more pages couldn't be read, then -ENODATA + should be returned. If all the pages are dispatched then 0 should be + returned. + + + (*) Request page be allocated in the cache [mandatory]: + + int (*allocate_page)(struct fscache_retrieval *op, + struct page *page, + gfp_t gfp) + + This is like the read_or_alloc_page() method, except that it shouldn't + read from the cache, even if there's data there that could be retrieved. + It should, however, set up any internal metadata required such that + the write_page() method can write to the cache. + + If there's no backing block available, then -ENOBUFS should be returned + (or -ENOMEM if there were other problems). If a block is successfully + allocated, then the netfs page should be marked and 0 returned. + + + (*) Request pages be allocated in the cache [mandatory]: + + int (*allocate_pages)(struct fscache_retrieval *op, + struct list_head *pages, + unsigned *nr_pages, + gfp_t gfp) + + This is an multiple page version of the allocate_page() method. pages and + nr_pages should be treated as for the read_or_alloc_pages() method. + + + (*) Request page be written to cache [mandatory]: + + int (*write_page)(struct fscache_storage *op, + struct page *page); + + This is called to write from a page on which there was a previously + successful read_or_alloc_page() call or similar. FS-Cache filters out + pages that don't have mappings. + + This method is called asynchronously from the FS-Cache thread pool. It is + not required to actually store anything, provided -ENODATA is then + returned to the next read of this page. + + If an error occurred, then a negative error code should be returned, + otherwise zero should be returned. FS-Cache will take appropriate action + in response to an error, such as withdrawing this object. + + If this method returns success then FS-Cache will inform the netfs + appropriately. + + + (*) Discard retained per-page metadata [mandatory]: + + void (*uncache_page)(struct fscache_object *object, struct page *page) + + This is called when a netfs page is being evicted from the pagecache. The + cache backend should tear down any internal representation or tracking it + maintains for this page. + + +================== +FS-CACHE UTILITIES +================== + +FS-Cache provides some utilities that a cache backend may make use of: + + (*) Note occurrence of an I/O error in a cache: + + void fscache_io_error(struct fscache_cache *cache) + + This tells FS-Cache that an I/O error occurred in the cache. After this + has been called, only resource dissociation operations (object and page + release) will be passed from the netfs to the cache backend for the + specified cache. + + This does not actually withdraw the cache. That must be done separately. + + + (*) Invoke the retrieval I/O completion function: + + void fscache_end_io(struct fscache_retrieval *op, struct page *page, + int error); + + This is called to note the end of an attempt to retrieve a page. The + error value should be 0 if successful and an error otherwise. + + + (*) Set highest store limit: + + void fscache_set_store_limit(struct fscache_object *object, + loff_t i_size); + + This sets the limit FS-Cache imposes on the highest byte it's willing to + try and store for a netfs. Any page over this limit is automatically + rejected by fscache_read_alloc_page() and co with -ENOBUFS. + + + (*) Mark pages as being cached: + + void fscache_mark_pages_cached(struct fscache_retrieval *op, + struct pagevec *pagevec); + + This marks a set of pages as being cached. After this has been called, + the netfs must call fscache_uncache_page() to unmark the pages. + + + (*) Initialise a freshly allocated object: + + void fscache_object_init(struct fscache_object *object); + + This initialises all the fields in an object representation. + + + (*) Indicate negative lookup on an object: + + void fscache_object_lookup_negative(struct fscache_object *object); + + This is called to indicate to FS-Cache that a lookup process for an object + found a negative result. + + This changes the state of an object to permit reads pending on lookup + completion to go off and start fetching data from the netfs server as it's + known at this point that there can't be any data in the cache. + + This may be called multiple times on an object. Only the first call is + significant - all subsequent calls are ignored. + + + (*) Indicate an object has been obtained: + + void fscache_obtained_object(struct fscache_object *object); + + This is called to indicate to FS-Cache that a lookup process for an object + produced a positive result, or that an object was created. This should + only be called once for any particular object. + + This changes the state of an object to indicate: + + (1) if no call to fscache_object_lookup_negative() has been made on + this object, that there may be data available, and that reads can + now go and look for it; and + + (2) that writes may now proceed against this object. + + + (*) Indicate that object lookup failed: + + void fscache_object_lookup_error(struct fscache_object *object); + + This marks an object as having encountered a fatal error (usually EIO) + and causes it to move into a state whereby it will be withdrawn as soon + as possible. + + + (*) Get and release references on a retrieval record: + + void fscache_get_retrieval(struct fscache_retrieval *op); + void fscache_put_retrieval(struct fscache_retrieval *op); + + These two functions are used to retain a retrieval record whilst doing + asynchronous data retrieval and block allocation. + + + (*) Enqueue a retrieval record for processing. + + void fscache_enqueue_retrieval(struct fscache_retrieval *op); + + This enqueues a retrieval record for processing by the FS-Cache thread + pool. One of the threads in the pool will invoke the retrieval record's + op->op.processor callback function. This function may be called from + within the callback function. + + + (*) List of object state names: + + const char *fscache_object_states[]; + + For debugging purposes, this may be used to turn the state that an object + is in into a text string for display purposes.
Documentation/filesystems/caching/fscache.txt new file +295 -0
295 lines not on this page · raw message
Documentation/filesystems/caching/netfs-api.txt new file +741 -0
741 lines not on this page · raw message
fs/Kconfig +6 -0
@@ -631,6 +631,12 @@ config GENERIC_ACL bool select FS_POSIX_ACL +menu "Caches" + +source "fs/fscache/Kconfig" + +endmenu + if BLOCK menu "CD-ROM/DVD Filesystems"
fs/Makefile +1 -0
@@ -65,6 +65,7 @@ obj-$(CONFIG_PROFILING) += dcookies.o obj-$(CONFIG_DLM) += dlm/ # Do not add any filesystems before this line +obj-$(CONFIG_FSCACHE) += fscache/ obj-$(CONFIG_REISERFS_FS) += reiserfs/ obj-$(CONFIG_EXT3_FS) += ext3/ # Before ext2 so root fs can be ext3 obj-$(CONFIG_EXT4DEV_FS) += ext4/ # Before ext2 so root fs can be ext4dev
fs/fscache/Kconfig new file +49 -0
49 lines not on this page · raw message
fs/fscache/Makefile new file +19 -0
@@ -0,0 +1,19 @@ +# +# Makefile for general filesystem caching code +# + +fscache-y := \ + fsc-cache.o \ + fsc-cookie.o \ + fsc-fsdef.o \ + fsc-main.o \ + fsc-manage.o \ + fsc-object.o \ + fsc-page.o \ + fsc-threads.o + +fscache-$(CONFIG_FSCACHE_PROC) += \ + fsc-proc.o \ + fsc-stats.o + +obj-$(CONFIG_FSCACHE) := fscache.o
fs/fscache/fsc-cache.c new file +512 -0
512 lines not on this page · raw message
fs/fscache/fsc-cookie.c new file +494 -0
494 lines not on this page · raw message
fs/fscache/fsc-fsdef.c new file +111 -0
111 lines not on this page · raw message
fs/fscache/fsc-internal.h new file +376 -0
135 lines not on this page · raw message
fs/fscache/fsc-main.c new file +127 -0
127 lines not on this page · raw message
fs/fscache/fsc-manage.c new file +260 -0
260 lines not on this page · raw message
fs/fscache/fsc-object.c new file +586 -0
586 lines not on this page · raw message
fs/fscache/fsc-page.c new file +863 -0
863 lines not on this page · raw message
fs/fscache/fsc-proc.c new file +399 -0
399 lines not on this page · raw message
fs/fscache/fsc-stats.c new file +103 -0
103 lines not on this page · raw message
fs/fscache/fsc-threads.c new file +590 -0
590 lines not on this page · raw message
include/linux/fscache-cache.h new file +433 -0
433 lines not on this page · raw message
include/linux/fscache.h new file +593 -0
593 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
David Howells
maintainerPATCH 5/14 CacheFiles: Add missing copy_page export for ia64 [try #2]
In reply to David HowellsThis one-line patch fixes the missing export of copy_page introduced by the cachefile patches. This patch is not yet upstream, but is required for cachefile on ia64. It will be pushed upstream when cachefile goes upstream.
---
arch/ia64/kernel/ia64_ksyms.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/ia64/kernel/ia64_ksyms.c +1 -0
@@ -43,6 +43,7 @@ EXPORT_SYMBOL(__do_clear_user);EXPORT_SYMBOL (__strlen_user);EXPORT_SYMBOL (__strncpy_from_user);EXPORT_SYMBOL (__strnlen_user); +EXPORT_SYMBOL (copy_page);/* from arch/ia64/lib */ extern void __divsi3 (void );
David Howells
maintainerPATCH 6/14 CacheFiles: Add a hook to write a single page of data to an inode [try #2]
In reply to David HowellsAdd an address space operation to write one single page of data to an inode at a page-aligned location (thus permitting the implementation to be highly optimised).
This is used by CacheFiles to store the contents of netfs pages into their backing file pages.
Supply a generic implementation for this that uses the prepare_write() and commit_write() address_space operations to bound a copy directly into the page cache.
Hook the Ext2 and Ext3 operations to the generic implementation.
---
fs/ext2/inode.c | 2 + fs/ext3/inode.c | 3 ++ include/linux/fs.h | 7 ++++ mm/filemap.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 0 deletions(-)
fs/ext2/inode.c +2 -0
@@ -695,6 +695,7 @@ const struct address_space_operations ext2_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, };const struct address_space_operations ext2_aops_xip = {
@@ -713,6 +714,7 @@ const struct address_space_operations ext2_nobh_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, };/*
fs/ext3/inode.c +3 -0
@@ -1713,6 +1713,7 @@ static const struct address_space_operations ext3_ordered_aops = { .releasepage = ext3_releasepage, .direct_IO = ext3_direct_IO, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, };static const struct address_space_operations ext3_writeback_aops = {
@@ -1727,6 +1728,7 @@ static const struct address_space_operations ext3_writeback_aops = { .releasepage = ext3_releasepage, .direct_IO = ext3_direct_IO, .migratepage = buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, };static const struct address_space_operations ext3_journalled_aops = {
@@ -1740,6 +1742,7 @@ static const struct address_space_operations ext3_journalled_aops = { .bmap = ext3_bmap, .invalidatepage = ext3_invalidatepage, .releasepage = ext3_releasepage, + .write_one_page = generic_file_buffered_write_one_page, };void ext3_set_aops (struct inode *inode)
include/linux/fs.h +7 -0
@@ -433,6 +433,11 @@ struct address_space_operations {int (*migratepage) (struct address_space *,struct page *,struct page *);int (*launder_page) (struct page *); +/* write the contents of the source page over the page at the specified +* index in the target address space (the source page does not need to +* be related to the target address space) */ +int (*write_one_page)(struct address_space *,pgoff_t ,struct page *); + };struct backing_dev_info ;
@@ -1669,6 +1674,8 @@ extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, unsigned long *, loff_t, loff_t *, size_t, size_t);extern ssize_t generic_file_buffered_write (struct kiocb *,const struct iovec *,unsigned long ,loff_t ,loff_t *,size_t ,ssize_t ); +extern int generic_file_buffered_write_one_page (struct address_space *, +pgoff_t ,struct page *);extern ssize_t do_sync_read (struct file *filp,char __user *buf,size_t len,loff_t *ppos);extern ssize_t do_sync_write (struct file *filp,const char __user *buf,size_t len,loff_t *ppos); extern void do_generic_mapping_read(struct address_space *mapping,
mm/filemap.c +95 -0
101 lines not on this page · raw message
David Howells
maintainerPATCH 7/14 CacheFiles: Permit the page lock state to be monitored [try #2]
In reply to David HowellsAdd a function to install a monitor on the page lock waitqueue for a particular page, thus allowing the page being unlocked to be detected.
This is used by CacheFiles to detect read completion on a page in the backing filesystem so that it can then copy the data to the waiting netfs page.
---
include/linux/pagemap.h | 5 +++++ mm/filemap.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-)
include/linux/pagemap.h +5 -0
@@ -220,6 +220,11 @@ static inline void wait_on_page_fscache_write(struct page *page)extern void end_page_fscache_write (struct page *page);/* +* Add an arbitrary waiter to a page's wait queue +*/ +extern void add_page_wait_queue (struct page *page,wait_queue_t *waiter); + +/* * Fault a userspace page into pagetables. Return non-zero on a fault. * * This assumes that two userspace pages are always sufficient. That's
mm/filemap.c +19 -0
@@ -518,6 +518,25 @@ void fastcall wait_on_page_bit(struct page *page, int bit_nr)EXPORT_SYMBOL (wait_on_page_bit);/** +* add_page_wait_queue - Add an arbitrary waiter to a page's wait queue +* @page - Page defining the wait queue of interest +* @waiter - Waiter to add to the queue +* +* Add an arbitrary @waiter to the wait queue for the nominated @page. +*/ +void add_page_wait_queue (struct page *page,wait_queue_t *waiter) +{ +wait_queue_head_t *q =page_waitqueue (page); +unsigned long flags; + +spin_lock_irqsave (&q->lock, flags); +__add_wait_queue (q, waiter); +spin_unlock_irqrestore (&q->lock, flags); +} + +EXPORT_SYMBOL_GPL (add_page_wait_queue); + +/** * unlock_page - unlock a locked page * @page: the page *
David Howells
maintainerPATCH 8/14 CacheFiles: Export things for CacheFiles [try #2]
In reply to David HowellsExport a number of functions for CacheFiles's use.
---
fs/super.c | 2 ++ kernel/auditsc.c | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
fs/super.c +2 -0
@@ -270,6 +270,8 @@ int fsync_super(struct super_block *sb)return sync_blockdev (sb->s_bdev); } +EXPORT_SYMBOL_GPL (fsync_super); +/** * generic_shutdown_super - common helper for ->kill_sb() * @sb: superblock to kill
kernel/auditsc.c +2 -0
@@ -1526,6 +1526,8 @@ add_names: } } +EXPORT_SYMBOL_GPL (__audit_inode_child); +/** * auditsc_get_stamp - get local copies of audit_context values * @ctx: audit_context for the task
David Howells
maintainerPATCH 9/14 CacheFiles: Permit a process's create SID to be overridden [try #2]
In reply to David HowellsMake it possible for a process's file creation SID to be temporarily overridden by CacheFiles so that files created in the cache have the right label attached.
Without this facility, files created in the cache will be given the current file creation SID of whatever process happens to have invoked CacheFiles indirectly by means of opening a netfs file at the time the cache file is created.
---
include/linux/security.h | 35 +++++++++++++++++++++++++++++++++++ security/dummy.c | 12 ++++++++++++ security/selinux/hooks.c | 18 ++++++++++++++++++ 3 files changed, 65 insertions(+), 0 deletions(-)
include/linux/security.h +35 -0
@@ -1147,6 +1147,13 @@ struct request_sock;* @secdata contains the security context. * @seclen contains the length of the security context. * +* @get_fscreate_secid: +* Get the current FS security ID. +* +* @set_fscreate_secid: +* Set the current FS security ID. +* @secid contains the security ID to set. +* * This is the main security structure. */ struct security_operations {
@@ -1330,6 +1337,8 @@ struct security_operations {int (*setprocattr)(struct task_struct *p,char *name,void *value,size_t size);int (*secid_to_secctx)(u32 secid,char **secdata,u32 *seclen);void (*release_secctx)(char *secdata,u32 seclen); +u32 (*get_fscreate_secid)(void); +u32 (*set_fscreate_secid)(u32 secid);#ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect) (struct socket * sock,
@@ -2127,6 +2136,16 @@ static inline void security_release_secctx(char *secdata, u32 seclen)return security_ops->release_secctx (secdata, seclen); } +static inline u32 security_get_fscreate_secid (void ) +{ +return security_ops->get_fscreate_secid (); +} + +static inline u32 security_set_fscreate_secid (u32 secid) +{ +return security_ops->set_fscreate_secid (secid); +} +/* prototypes */ extern int security_init (void );extern int register_security (struct security_operations *ops);
@@ -2795,6 +2814,11 @@ static inline void securityfs_remove(struct dentry *dentry) { } +static inline int security_to_secctx_secid (char *secdata,u32 seclen,u32 *secid) +{ +return -EOPNOTSUPP ; +} +static inline int security_secid_to_secctx (u32 secid,char **secdata,u32 *seclen) {return -EOPNOTSUPP ;
@@ -2803,6 +2827,17 @@ static inline int security_secid_to_secctx(u32 secid, char **secdata, u32 *seclestatic inline void security_release_secctx (char *secdata,u32 seclen) { } + +static inline u32 security_get_fscreate_secid (void ) +{ +return 0 ; +} + +static inline u32 security_set_fscreate_secid (u32 secid) +{ +return 0 ; +} +#endif /* CONFIG_SECURITY */ #ifdef CONFIG_SECURITY_NETWORK
security/dummy.c +12 -0
@@ -930,6 +930,16 @@ static void dummy_release_secctx(char *secdata, u32 seclen) { } +static u32 dummy_get_fscreate_secid (void ) +{ +return 0 ; +} + +static u32 dummy_set_fscreate_secid (u32 secid) +{ +return 0 ; +} +#ifdef CONFIG_KEYS static inline int dummy_key_alloc (struct key *key,struct task_struct *ctx,unsigned long flags)
@@ -1084,6 +1094,8 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, setprocattr);set_to_dummy_if_null (ops, secid_to_secctx);set_to_dummy_if_null (ops, release_secctx); +set_to_dummy_if_null (ops, get_fscreate_secid); +set_to_dummy_if_null (ops, set_fscreate_secid);#ifdef CONFIG_SECURITY_NETWORK set_to_dummy_if_null (ops, unix_stream_connect);set_to_dummy_if_null (ops, unix_may_send);
security/selinux/hooks.c +18 -0
@@ -4661,6 +4661,22 @@ static void selinux_release_secctx(char *secdata, u32 seclen)kfree (secdata); } +static u32 selinux_get_fscreate_secid (void ) +{ +struct task_security_struct *tsec = current->security; + +return tsec->create_sid; +} + +static u32 selinux_set_fscreate_secid (u32 secid) +{ +struct task_security_struct *tsec = current->security; +u32 oldsid = tsec->create_sid; + + tsec->create_sid = secid; +return oldsid; +} +#ifdef CONFIG_KEYS static int selinux_key_alloc(struct key *k, struct task_struct *tsk,
@@ -4843,6 +4859,8 @@ static struct security_operations selinux_ops = { .secid_to_secctx = selinux_secid_to_secctx, .release_secctx = selinux_release_secctx, + .get_fscreate_secid = selinux_get_fscreate_secid, + .set_fscreate_secid = selinux_set_fscreate_secid, .unix_stream_connect = selinux_socket_unix_stream_connect, .unix_may_send = selinux_socket_unix_may_send,
Re: [PATCH 09/14] CacheFiles: Permit a process's create SID to be overridden [try #2]
Quoted 9 lines · --- David Howells
Make it possible for a process's file creation SID to be temporarily overridden
by CacheFiles so that files created in the cache have the right label attached.Without this facility, files created in the cache will be given the current file creation SID of whatever process happens to have invoked CacheFiles indirectly by means of opening a netfs file at the time the cache file is created.
This is SELinux specific funtionality and should be done in the SELinux code. You should not be adding interfaces that are SELinux specific, in this case using secids instead of the LSM blob interfaces.
Casey Schaufler
[email protected]
David Howells
maintainerRe: [PATCH 09/14] CacheFiles: Permit a process's create SID to be overridden [try #2]
Quoted 3 lines · Casey Schaufler
This is SELinux specific funtionality and should be done in the SELinux code. You should not be adding interfaces that are SELinux specific, in this case using secids instead of the LSM blob interfaces.
Is using secids your only objection? Or are you objecting to the whole 'act-as' concept?
David
Re: [PATCH 09/14] CacheFiles: Permit a process's create SID to be overridden [try #2]
Quoted 8 lines · --- David Howells
Quoted 3 lines · Casey Schaufler
This is SELinux specific funtionality and should be done in the SELinux code. You should not be adding interfaces that are SELinux specific, in this case using secids instead of the LSM blob interfaces.
Is using secids your only objection? Or are you objecting to the whole 'act-as' concept?
My knee jerk reaction is that that is likely to be SELinux specific behavior as well. I'm going to have to look at the patch more carefully before I can say for sure. I will try to make a constructive proposal once I've had the chance to think on it a little. Sorry about the terse and unhelpful initial reaction.
Casey Schaufler
[email protected]
David Howells
maintainerPATCH 10/14 CacheFiles: Add an act-as SID override in task_security_struct [try #2]
In reply to David HowellsAdd an act-as SID to task_security_struct that is equivalent to fsuid/fsgid in task_struct. This permits a task to perform operations as if it is the overriding SID, without changing its own SID as that might be needed to control access to the process by ptrace, signals, /proc, etc.
This is useful for CacheFiles in that it allows CacheFiles to access the cache files and directories using the cache's security context rather than the security context of the process on whose behalf it is working, and in the context of which it is running.
---
include/linux/security.h | 32 +++++++ security/dummy.c | 12 +++ security/selinux/exports.c | 2 security/selinux/hooks.c | 160 +++++++++++++++++++++++-------------- security/selinux/include/objsec.h | 1 security/selinux/selinuxfs.c | 2 security/selinux/xfrm.c | 6 + 7 files changed, 148 insertions(+), 67 deletions(-)
include/linux/security.h +32 -0
@@ -1154,6 +1154,16 @@ struct request_sock;* Set the current FS security ID. * @secid contains the security ID to set. * +* @act_as_secid: +* Set the security ID as which to act, returning the security ID as which +* the process was previously acting. +* @secid contains the security ID to act as. +* +* @act_as_self: +* Reset the security ID as which to act to be the same as the process's +* owning security ID, and return the security ID as which the process was +* previously acting. +* * This is the main security structure. */ struct security_operations {
@@ -1339,6 +1349,8 @@ struct security_operations {void (*release_secctx)(char *secdata,u32 seclen);u32 (*get_fscreate_secid)(void);u32 (*set_fscreate_secid)(u32 secid); +u32 (*act_as_secid)(u32 secid); +u32 (*act_as_self)(void);#ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect) (struct socket * sock,
@@ -2146,6 +2158,16 @@ static inline u32 security_set_fscreate_secid(u32 secid)return security_ops->set_fscreate_secid (secid); } +static inline u32 security_act_as_secid (u32 secid) +{ +return security_ops->act_as_secid (secid); +} + +static inline u32 security_act_as_self (void ) +{ +return security_ops->act_as_self (); +} +/* prototypes */ extern int security_init (void );extern int register_security (struct security_operations *ops);
@@ -2838,6 +2860,16 @@ static inline u32 security_set_fscreate_secid(u32 secid) return 0; } +static inline u32 security_act_as_secid (u32 secid) +{ +return 0 ; +} + +static inline u32 security_act_as_self (void ) +{ +return 0 ; +} +#endif /* CONFIG_SECURITY */ #ifdef CONFIG_SECURITY_NETWORK
security/dummy.c +12 -0
@@ -940,6 +940,16 @@ static u32 dummy_set_fscreate_secid(u32 secid)return 0 ; } +static u32 dummy_act_as_secid (u32 secid) +{ +return 0 ; +} + +static u32 dummy_act_as_self (void ) +{ +return 0 ; +} +#ifdef CONFIG_KEYS static inline int dummy_key_alloc (struct key *key,struct task_struct *ctx,unsigned long flags)
@@ -1096,6 +1106,8 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, release_secctx);set_to_dummy_if_null (ops, get_fscreate_secid);set_to_dummy_if_null (ops, set_fscreate_secid); +set_to_dummy_if_null (ops, act_as_secid); +set_to_dummy_if_null (ops, act_as_self);#ifdef CONFIG_SECURITY_NETWORK set_to_dummy_if_null (ops, unix_stream_connect);set_to_dummy_if_null (ops, unix_may_send);
security/selinux/exports.c +1 -1
@@ -79,7 +79,7 @@ int selinux_relabel_packet_permission(u32 sid)if (selinux_enabled) {struct task_security_struct *tsec = current->security; -return avc_has_perm (tsec->sid, sid,SECCLASS_PACKET , +return avc_has_perm (tsec->actor_sid, sid,SECCLASS_PACKET ,PACKET__RELABELTO ,NULL ); }return 0 ;
security/selinux/hooks.c +98 -62
503 lines not on this page · raw message
security/selinux/include/objsec.h +1 -0
@@ -31,6 +31,7 @@ struct task_security_struct {struct task_struct *task;/* back pointer to task object */ u32 osid;/* SID prior to last execve */ u32 sid;/* current SID */ +u32 actor_sid;/* act-as SID (normally == sid) */ u32 exec_sid;/* exec SID */ u32 create_sid;/* fscreate SID */ u32 keycreate_sid;/* keycreate SID */
security/selinux/selinuxfs.c +1 -1
@@ -83,7 +83,7 @@ static int task_has_security(struct task_struct *tsk,if (!tsec)return -EACCES ; -return avc_has_perm (tsec->sid,SECINITSID_SECURITY , +return avc_has_perm (tsec->actor_sid,SECINITSID_SECURITY ,SECCLASS_SECURITY , perms,NULL ); }
security/selinux/xfrm.c +3 -3
@@ -240,7 +240,7 @@ static int selinux_xfrm_sec_ctx_alloc(struct xfrm_sec_ctx **ctxp,/* * Does the subject have permission to set security context? */ - rc =avc_has_perm (tsec->sid, ctx->ctx_sid, + rc =avc_has_perm (tsec->actor_sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL );if (rc)
@@ -341,7 +341,7 @@ int selinux_xfrm_policy_delete(struct xfrm_policy *xp)int rc =0 ;if (ctx) - rc =avc_has_perm (tsec->sid, ctx->ctx_sid, + rc =avc_has_perm (tsec->actor_sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL );
@@ -383,7 +383,7 @@ int selinux_xfrm_state_delete(struct xfrm_state *x)int rc =0 ;if (ctx) - rc =avc_has_perm (tsec->sid, ctx->ctx_sid, + rc =avc_has_perm (tsec->actor_sid, ctx->ctx_sid,SECCLASS_ASSOCIATION ,ASSOCIATION__SETCONTEXT ,NULL );
David Howells
maintainerPATCH 11/14 CacheFiles: Permit an inode's security ID to be obtained [try #2]
In reply to David HowellsPermit an inode's security ID to be obtained by the CacheFiles module. This is then used as the SID with which files and directories will be created in the cache.
---
include/linux/security.h | 13 +++++++++++++ security/dummy.c | 6 ++++++ security/selinux/hooks.c | 8 ++++++++ 3 files changed, 27 insertions(+), 0 deletions(-)
include/linux/security.h +13 -0
@@ -1252,6 +1252,7 @@ struct security_operations {int (*inode_getsecurity)(const struct inode *inode,const char *name,void *buffer,size_t size,int err);int (*inode_setsecurity)(struct inode *inode,const char *name,const void *value,size_t size,int flags);int (*inode_listsecurity)(struct inode *inode,char *buffer,size_t buffer_size); +u32 (*inode_get_secid)(struct inode *inode);int (*file_permission) (struct file * file,int mask);int (*file_alloc_security) (struct file * file);
@@ -1814,6 +1815,13 @@ static inline int security_inode_listsecurity(struct inode *inode, char *buffer,return security_ops->inode_listsecurity (inode, buffer, buffer_size); } +static inline u32 security_inode_get_secid (struct inode *inode) +{ +if (unlikely (IS_PRIVATE (inode))) +return 0 ; +return security_ops->inode_get_secid (inode); +} +static inline int security_file_permission (struct file *file,int mask) {return security_ops->file_permission (file, mask);
@@ -2514,6 +2522,11 @@ static inline int security_inode_listsecurity(struct inode *inode, char *buffer,return 0 ; } +static inline u32 security_inode_get_secid (struct inode *inode) +{ +return 0 ; +} +static inline int security_file_permission (struct file *file,int mask) {return 0 ;
security/dummy.c +6 -0
@@ -392,6 +392,11 @@ static int dummy_inode_listsecurity(struct inode *inode, char *buffer, size_t bureturn 0 ; } +static u32 dummy_inode_get_secid (struct inode *inode) +{ +return 0 ; +} +static const char *dummy_inode_xattr_getsuffix (void ) {return NULL ;
@@ -1042,6 +1047,7 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, inode_getsecurity);set_to_dummy_if_null (ops, inode_setsecurity);set_to_dummy_if_null (ops, inode_listsecurity); +set_to_dummy_if_null (ops, inode_get_secid);set_to_dummy_if_null (ops, file_permission);set_to_dummy_if_null (ops, file_alloc_security);set_to_dummy_if_null (ops, file_free_security);
security/selinux/hooks.c +8 -0
@@ -2464,6 +2464,13 @@ static int selinux_inode_listsecurity(struct inode *inode, char *buffer, size_treturn len; } +static u32 selinux_inode_get_secid (struct inode *inode) +{ +struct inode_security_struct *isec = inode->i_security; + +return isec->sid; +} +/* file security operations */ static int selinux_file_permission (struct file *file,int mask)
@@ -4822,6 +4829,7 @@ static struct security_operations selinux_ops = { .inode_getsecurity = selinux_inode_getsecurity, .inode_setsecurity = selinux_inode_setsecurity, .inode_listsecurity = selinux_inode_listsecurity, + .inode_get_secid = selinux_inode_get_secid, .file_permission = selinux_file_permission, .file_alloc_security = selinux_file_alloc_security,
Re: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
Quoted 4 lines · --- David Howells
Permit an inode's security ID to be obtained by the CacheFiles module. This is
then used as the SID with which files and directories will be created in the cache.
This is SELinux specific functionality. It should not be an LSM interface.
Casey Schaufler
[email protected]
Re: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
Quoted 9 lines · Casey Schaufler
Quoted 4 lines · --- David Howells
Permit an inode's security ID to be obtained by the CacheFiles module. This is
then used as the SID with which files and directories will be created in the cache.This is SELinux specific functionality. It should not be an LSM interface.
Odd, you proposed exactly the same hook (aside from naming convention and secid as argument vs. as retval) in recent postings on linux-audit and selinux list for use by the audit system.
Signature · 2 lines
Stephen Smalley National Security Agency
Re: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
Quoted 8 lines · --- Stephen Smalley
Quoted 3 lines · Casey Schaufler
Quoted 1 line · --- David Howells
Permit an inode's security ID to be obtained by the CacheFiles module.
This
Quoted 2 lines
Quoted 2 lines
is
then used as the SID with which files and directories will be created inthe
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
cache.
This is SELinux specific functionality. It should not be an LSM interface.
Odd, you proposed exactly the same hook (aside from naming convention and secid as argument vs. as retval) in recent postings on linux-audit and selinux list for use by the audit system.
And that's exposing SELinux specific functionality too. And I don't like the fact that the audit system already requires a secid interface. The audit system, however, does not use the secid for anything other than a handle that gets passed around and eventually used to get the data that goes into the audit record. It's annoying, but harmless and does not affect any access control decisions. The change proposed here would use the secid in access control decisions. The LSM interface ought not to be exposing module specific internal data structures. My work on pulling selinux code out of audit left the secid interface in place. You're right in that audit should get fixed. I had been hoping to make that a phase II activity.
Casey Schaufler
[email protected]
David Howells
maintainerRe: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
In reply to Casey SchauflerQuoted 2 lines · Casey Schaufler
This is SELinux specific functionality. It should not be an LSM interface.
This is what I worked out in conjunction with the denizens of the SELinux mailing list. What would you have me do differently? Change things like:
u32 (*act_as_secid)(u32 secid);
to something like:
void (*act_as_secid)(const char *newsecdata, u32 newseclen, char *oldsecdata, u32 *oldseclen);
David
James Morris
maintainerRe: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
In reply to Casey SchauflerQuoted 2 lines · Casey Schaufler
This is SELinux specific functionality. It should not be an LSM interface.
As long as the security labels are themselves not being exported to the kernel to be used e.g. for display or transport, then I agree, and we should avoid passing them around outside the LSM entirely if possible.
Usually, they're attached to a significant kernel object, which you typically pass around as part of the interface anyway.
David, I've looked at the code and can't see that you need to access the label itself outside the LSM. Could you instead simply pass the inode pointer around?
(I know it's not always possible, but much preferred).
- James
Signature · 2 lines
James Morris <[email protected]>
David Howells
maintainerRe: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
Quoted 3 lines · James Morris
David, I've looked at the code and can't see that you need to access the label itself outside the LSM. Could you instead simply pass the inode pointer around?
It's not quite that simple. I need to impose *two* security labels in cachefiles_begin_secure() when I'm about to act on behalf of a process that's tried to access a netfs file:
(1) The security label to act as. This is the label attached to the cachefilesd process when it starts the cache. This is obtained by cachefiles_get_security_ID().
(2) The security label to create files as. This is the label attached to root directory of the cache. This is obtained by cachefiles_determine_cache_secid().
David
James Morris
maintainerRe: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
Quoted 9 lines · David Howells
Quoted 3 lines · James Morris
David, I've looked at the code and can't see that you need to access the label itself outside the LSM. Could you instead simply pass the inode pointer around?
It's not quite that simple. I need to impose *two* security labels in
cachefiles_begin_secure()when I'm about to act on behalf of a process that's tried to access a netfs file:
Ah ok, we had a similar problem with NFS mount options.
While I'm concerned about encoding SELinux-optimized secid labels into general kernel structures, moving to more generalized pointers introduces lifecycle maintenance issues and complexity which is not needed in the mainline kernel. i.e. it'll be unused infrastructure maintained by upstream, and used only by out-of-tree modules.
So, given that the kernel has no stable API, I suggest accepting the u32 secid as you propose, and if someone wants to merge a module which also uses these hooks, but is entirely unable to use u32 labels, then they can also justify making the interface more generalized and provide the code for it.
- James
Signature · 2 lines
James Morris <[email protected]>
Re: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
Quoted 21 lines · --- James Morris
Quoted 8 lines · David Howells
Quoted 3 lines · James Morris
David, I've looked at the code and can't see that you need to access the label itself outside the LSM. Could you instead simply pass the inode pointer around?
It's not quite that simple. I need to impose *two* security labels in
cachefiles_begin_secure()when I'm about to act on behalf of a processthat's
Quoted 1 line
tried to access a netfs file:
Ah ok, we had a similar problem with NFS mount options.
While I'm concerned about encoding SELinux-optimized secid labels into general kernel structures, moving to more generalized pointers introduces lifecycle maintenance issues and complexity which is not needed in the mainline kernel. i.e. it'll be unused infrastructure maintained by upstream, and used only by out-of-tree modules.
Quoted 5 lines
So, given that the kernel has no stable API, I suggest accepting the u32 secid as you propose, and if someone wants to merge a module which also uses these hooks, but is entirely unable to use u32 labels, then they can also justify making the interface more generalized and provide the code for it.
Grumble. Yet another thing to undo in the near future. I still hope to suggest what I would consider a viable alternative "soon".
Casey Schaufler
[email protected]
David Howells
maintainerRe: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
Quoted 2 lines · Casey Schaufler
Grumble. Yet another thing to undo in the near future. I still hope to suggest what I would consider a viable alternative "soon".
Use a struct key with the overrides attached? The key can be generated by SELinux or whatever module is there.
David
James Morris
maintainerRe: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
In reply to David Howellsinclude/linux/security.h struct security_operations { · line 1255
Quoted 1 line · David Howells
include/linux/security.h +1
-0+u32 (*inode_get_secid)(struct inode *inode);
To maintain API consistency, please return an int which only acts as an error code, and returning the secid via a *u32 function parameter.
- James
Signature · 2 lines
James Morris <[email protected]>
David Howells
maintainerRe: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
Quoted 4 lines · James Morris
include/linux/security.h struct security_operations { · line 1255
Quoted 1 line
include/linux/security.h +1
-0+u32 (*inode_get_secid)(struct inode *inode);To maintain API consistency, please return an int which only acts as an error code, and returning the secid via a *u32 function parameter.
Does that apply to *all* the functions, irrespective of whether or not they return an error?
David
James Morris
maintainerRe: [PATCH 11/14] CacheFiles: Permit an inode's security ID to be obtained [try #2]
Quoted 9 lines · David Howells
Quoted 4 lines · James Morris
include/linux/security.h struct security_operations { · line 1255
Quoted 1 line
include/linux/security.h +1
-0+u32 (*inode_get_secid)(struct inode *inode);To maintain API consistency, please return an int which only acts as an error code, and returning the secid via a *u32 function parameter.
Does that apply to *all* the functions, irrespective of whether or not they return an error?
LSM is theoretically an API, so we generally don't know if a security module will return an error or not.
If they were simply calls directly into SElinux, where we could always know the semantics, then that would be a different story.
- James
Signature · 2 lines
James Morris <[email protected]>
David Howells
maintainerPATCH 12/14 CacheFiles: Get the SID under which the CacheFiles module should operate [try #2]
In reply to David HowellsGet the SID under which the CacheFiles module should operate so that the SELinux security system can control the accesses it makes.
---
include/linux/security.h | 20 ++++++++++++++++++++ security/dummy.c | 7 +++++++ security/selinux/hooks.c | 7 +++++++ 3 files changed, 34 insertions(+), 0 deletions(-)
include/linux/security.h +20 -0
@@ -1164,6 +1164,14 @@ struct request_sock;* owning security ID, and return the security ID as which the process was * previously acting. * +* @cachefiles_get_secid: +* Determine the security ID for the CacheFiles module to use when +* accessing the filesystem containing the cache. +* @secid contains the security ID under which cachefiles daemon is +* running. +* @modsecid contains the pointer to where the security ID for the module +* is to be stored. +* * This is the main security structure. */ struct security_operations {
@@ -1352,6 +1360,7 @@ struct security_operations {u32 (*set_fscreate_secid)(u32 secid);u32 (*act_as_secid)(u32 secid);u32 (*act_as_self)(void); +int (*cachefiles_get_secid)(u32 secid,u32 *modsecid);#ifdef CONFIG_SECURITY_NETWORK int (*unix_stream_connect) (struct socket * sock,
@@ -2176,6 +2185,11 @@ static inline u32 security_act_as_self(void)return security_ops->act_as_self (); } +static inline int security_cachefiles_get_secid (u32 secid,u32 *modsecid) +{ +return security_ops->cachefiles_get_secid (secid, modsecid); +} +/* prototypes */ extern int security_init (void );extern int register_security (struct security_operations *ops);
@@ -2883,6 +2897,12 @@ static inline u32 security_act_as_self(void) return 0; } +static inline int security_cachefiles_get_secid (u32 secid,u32 *modsecid) +{ + *modsecid =0 ; +return 0 ; +} +#endif /* CONFIG_SECURITY */ #ifdef CONFIG_SECURITY_NETWORK
security/dummy.c +7 -0
@@ -955,6 +955,12 @@ static u32 dummy_act_as_self(void)return 0 ; } +static int dummy_cachefiles_get_secid (u32 secid,u32 *modsecid) +{ + *modsecid =0 ; +return 0 ; +} +#ifdef CONFIG_KEYS static inline int dummy_key_alloc (struct key *key,struct task_struct *ctx,unsigned long flags)
@@ -1114,6 +1120,7 @@ void security_fixup_ops (struct security_operations *ops)set_to_dummy_if_null (ops, set_fscreate_secid);set_to_dummy_if_null (ops, act_as_secid);set_to_dummy_if_null (ops, act_as_self); +set_to_dummy_if_null (ops, cachefiles_get_secid);#ifdef CONFIG_SECURITY_NETWORK set_to_dummy_if_null (ops, unix_stream_connect);set_to_dummy_if_null (ops, unix_may_send);
security/selinux/hooks.c +7 -0
@@ -4718,6 +4718,12 @@ static u32 selinux_act_as_self(void)return oldactor_sid; } +static int selinux_cachefiles_get_secid (u32 secid,u32 *modsecid) +{ +return security_transition_sid (secid,SECINITSID_KERNEL , +SECCLASS_PROCESS , modsecid); +} +#ifdef CONFIG_KEYS static int selinux_key_alloc(struct key *k, struct task_struct *tsk,
@@ -4905,6 +4911,7 @@ static struct security_operations selinux_ops = { .set_fscreate_secid = selinux_set_fscreate_secid, .act_as_secid = selinux_act_as_secid, .act_as_self = selinux_act_as_self, + .cachefiles_get_secid = selinux_cachefiles_get_secid, .unix_stream_connect = selinux_socket_unix_stream_connect, .unix_may_send = selinux_socket_unix_may_send,
David Howells
maintainerPATCH 13/14 CacheFiles: A cache that backs onto a mounted filesystem [try #2]
In reply to David HowellsAdd an FS-Cache cache-backend that permits a mounted filesystem to be used as a backing store for the cache.
CacheFiles uses a userspace daemon to do some of the cache management - such as reaping stale nodes and culling. This is called cachefilesd and lives in /sbin. The source for the daemon can be downloaded from:
http://people.redhat.com/~dhowells/cachefs/cachefilesd.c
And an example configuration from:
http://people.redhat.com/~dhowells/cachefs/cachefilesd.conf
The filesystem and data integrity of the cache are only as good as those of the filesystem providing the backing services. Note that CacheFiles does not attempt to journal anything since the journalling interfaces of the various filesystems are very specific in nature.
CacheFiles creates a proc-file - "/proc/fs/cachefiles" - that is used for communication with the daemon. Only one thing may have this open at once, and whilst it is open, a cache is at least partially in existence. The daemon opens this and sends commands down it to control the cache.
CacheFiles is currently limited to a single cache.
CacheFiles attempts to maintain at least a certain percentage of free space on the filesystem, shrinking the cache by culling the objects it contains to make space if necessary - see the "Cache Culling" section. This means it can be placed on the same medium as a live set of data, and will expand to make use of spare space and automatically contract when the set of data requires more space.
============
REQUIREMENTS
============
The use of CacheFiles and its daemon requires the following features to be available in the system and in the cache filesystem:
- dnotify.
- extended attributes (xattrs).
- openat() and friends.
- bmap() support on files in the filesystem (FIBMAP ioctl).
- The use of bmap() to detect a partial page at the end of the file.
It is strongly recommended that the "dir_index" option is enabled on Ext3 filesystems being used as a cache.
=============
CONFIGURATION
=============
The cache is configured by a script in /etc/cachefilesd.conf. These commands set up cache ready for use. The following script commands are available:
(*) brun <N>%
(*) bcull <N>%
(*) bstop <N>%
Configure the culling limits. Optional. See the section on culling The defaults are 7%, 5% and 1% respectively.
(*) dir <path>
Specify the directory containing the root of the cache. Mandatory.
(*) tag <name>
Specify a tag to FS-Cache to use in distinguishing multiple caches. Optional. The default is "CacheFiles".
(*) debug <mask>
Specify a numeric bitmask to control debugging in the kernel module. Optional. The default is zero (all off).
==================
STARTING THE CACHE
==================
The cache is started by running the daemon. The daemon opens the cache proc file, configures the cache and tells it to begin caching. At that point the cache binds to fscache and the cache becomes live.
The daemon is run as follows:
/sbin/cachefilesd [-d]* [-s] [-n] [-f <configfile>]
The flags are:
(*) -d
Increase the debugging level. This can be specified multiple times and is cumulative with itself.
(*) -s
Send messages to stderr instead of syslog.
(*) -n
Don't daemonise and go into background.
(*) -f <configfile>
Use an alternative configuration file rather than the default one.
===============
THINGS TO AVOID
===============
Do not mount other things within the cache as this will cause problems. The kernel module contains its own very cut-down path walking facility that ignores mountpoints, but the daemon can't avoid them.
Do not create, rename or unlink files and directories in the cache whilst the cache is active, as this may cause the state to become uncertain.
Renaming files in the cache might make objects appear to be other objects (the filename is part of the lookup key).
Do not change or remove the extended attributes attached to cache files by the cache as this will cause the cache state management to get confused.
Do not create files or directories in the cache, lest the cache get confused or serve incorrect data.
Do not chmod files in the cache. The module creates things with minimal permissions to prevent random users being able to access them directly.
=============
CACHE CULLING
=============
The cache may need culling occasionally to make space. This involves discarding objects from the cache that have been used less recently than anything else. Culling is based on the access time of data objects. Empty directories are culled if not in use.
Cache culling is done on the basis of the percentage of blocks available in the underlying filesystem. There are three "limits":
(*) brun
If the amount of available space in the cache rises above this limit, then culling is turned off.
(*) bcull
If the amount of available space in the cache falls below this limit, then culling is started.
(*) bstop
If the amount of available space in the cache falls below this limit, then no further allocation of disk space is permitted until culling has raised the amount above this limit again.
These must be configured thusly:
0 <= bstop < bcull < brun < 100
Note that these are percentages of available space, and do _not_ appear as 100 minus the percentage displayed by the "df" program.
The userspace daemon scans the cache to build up a table of cullable objects. These are then culled in least recently used order. A new scan of the cache is started as soon as space is made in the table. Objects will be skipped if their atimes have changed or if the kernel module says it is still using them.
===============
CACHE STRUCTURE
===============
The CacheFiles module will create two directories in the directory it was given:
(*) cache/
(*) graveyard/
The active cache objects all reside in the first directory. The CacheFiles kernel module moves any retired or culled objects that it can't simply unlink to the graveyard from which the daemon will actually delete them.
The daemon uses dnotify to monitor the graveyard directory, and will delete anything that appears therein.
The module represents index objects as directories with the filename "I..." or "J...". Note that the "cache/" directory is itself a special index.
Data objects are represented as files if they have no children, or directories if they do. Their filenames all begin "D..." or "E...". If represented as a directory, data objects will have a file in the directory called "data" that actually holds the data.
Special objects are similar to data objects, except their filenames begin "S..." or "T...".
If an object has children, then it will be represented as a directory. Immediately in the representative directory are a collection of directories named for hash values of the child object keys with an '@' prepended. Into this directory, if possible, will be placed the representations of the child objects:
INDEX INDEX INDEX DATA FILES ========= ========== ================================= ================ cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400 cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...DB1ry cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...N22ry cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...FP1ry
If the key is so long that it exceeds NAME_MAX with the decorations added on to it, then it will be cut into pieces, the first few of which will be used to make a nest of directories, and the last one of which will be the objects inside the last directory. The names of the intermediate directories will have '+' prepended:
J1223/@23/+xy...z/+kl...m/Epqr
Note that keys are raw data, and not only may they exceed NAME_MAX in size, they may also contain things like '/' and NUL characters, and so they may not be suitable for turning directly into a filename.
To handle this, CacheFiles will use a suitably printable filename directly and "base-64" encode ones that aren't directly suitable. The two versions of object filenames indicate the encoding:
OBJECT TYPE PRINTABLE ENCODED =============== =============== =============== Index "I..." "J..." Data "D..." "E..." Special "S..." "T..."
Intermediate directories are always "@" or "+" as appropriate.
Each object in the cache has an extended attribute label that holds the object type ID (required to distinguish special objects) and the auxiliary data from the netfs. The latter is used to detect stale objects in the cache and update or retire them.
Note that CacheFiles will erase from the cache any file it doesn't recognise or any file of an incorrect type (such as a FIFO file or a device file).
This documentation is added by the patch to:
Documentation/filesystems/caching/cachefiles.txt
---
Documentation/filesystems/caching/cachefiles.txt | 395 ++++++++++++ fs/Kconfig | 1 fs/Makefile | 1 fs/cachefiles/Kconfig | 33 + fs/cachefiles/Makefile | 18 + fs/cachefiles/cf-bind.c | 288 +++++++++ fs/cachefiles/cf-daemon.c | 720 +++++++++++++++++++++ fs/cachefiles/cf-interface.c | 442 +++++++++++++ fs/cachefiles/cf-internal.h | 414 ++++++++++++ fs/cachefiles/cf-key.c | 159 +++++ fs/cachefiles/cf-main.c | 109 +++ fs/cachefiles/cf-namei.c | 743 ++++++++++++++++++++++ fs/cachefiles/cf-proc.c | 166 +++++ fs/cachefiles/cf-security.c | 107 +++ fs/cachefiles/cf-xattr.c | 292 +++++++++ 15 files changed, 3888 insertions(+), 0 deletions(-)
Documentation/filesystems/caching/cachefiles.txt new file +395 -0
@@ -0,0 +1,395 @@ + =============================================== + CacheFiles: CACHE ON ALREADY MOUNTED FILESYSTEM + =============================================== + +Contents: + + (*) Overview. + + (*) Requirements. + + (*) Configuration. + + (*) Starting the cache. + + (*) Things to avoid. + + (*) Cache culling. + + (*) Cache structure. + + (*) Security model and SELinux. + +======== +OVERVIEW +======== + +CacheFiles is a caching backend that's meant to use as a cache a directory on +an already mounted filesystem of a local type (such as Ext3). + +CacheFiles uses a userspace daemon to do some of the cache management - such as +reaping stale nodes and culling. This is called cachefilesd and lives in +/sbin. + +The filesystem and data integrity of the cache are only as good as those of the +filesystem providing the backing services. Note that CacheFiles does not +attempt to journal anything since the journalling interfaces of the various +filesystems are very specific in nature. + +CacheFiles creates a misc character device - "/dev/cachefiles" - that is used +to communication with the daemon. Only one thing may have this open at once, +and whilst it is open, a cache is at least partially in existence. The daemon +opens this and sends commands down it to control the cache. + +CacheFiles is currently limited to a single cache. + +CacheFiles attempts to maintain at least a certain percentage of free space on +the filesystem, shrinking the cache by culling the objects it contains to make +space if necessary - see the "Cache Culling" section. This means it can be +placed on the same medium as a live set of data, and will expand to make use of +spare space and automatically contract when the set of data requires more +space. + + +============ +REQUIREMENTS +============ + +The use of CacheFiles and its daemon requires the following features to be +available in the system and in the cache filesystem: + + - dnotify. + + - extended attributes (xattrs). + + - openat() and friends. + + - bmap() support on files in the filesystem (FIBMAP ioctl). + + - The use of bmap() to detect a partial page at the end of the file. + +It is strongly recommended that the "dir_index" option is enabled on Ext3 +filesystems being used as a cache. + + +============= +CONFIGURATION +============= + +The cache is configured by a script in /etc/cachefilesd.conf. These commands +set up cache ready for use. The following script commands are available: + + (*) brun <N>% + (*) bcull <N>% + (*) bstop <N>% + (*) frun <N>% + (*) fcull <N>% + (*) fstop <N>% + + Configure the culling limits. Optional. See the section on culling + The defaults are 7% (run), 5% (cull) and 1% (stop) respectively. + + The commands beginning with a 'b' are file space (block) limits, those + beginning with an 'f' are file count limits. + + (*) dir <path> + + Specify the directory containing the root of the cache. Mandatory. + + (*) tag <name> + + Specify a tag to FS-Cache to use in distinguishing multiple caches. + Optional. The default is "CacheFiles". + + (*) debug <mask> + + Specify a numeric bitmask to control debugging in the kernel module. + Optional. The default is zero (all off). The following values can be + OR'd into the mask to collect various information: + + 1 Turn on trace of function entry (_enter() macros) + 2 Turn on trace of function exit (_leave() macros) + 4 Turn on trace of internal debug points (_debug()) + + This mask can also be set through sysfs, eg: + + echo 5 >/sys/modules/cachefiles/parameters/debug + + +================== +STARTING THE CACHE +================== + +The cache is started by running the daemon. The daemon opens the cache device, +configures the cache and tells it to begin caching. At that point the cache +binds to fscache and the cache becomes live. + +The daemon is run as follows: + + /sbin/cachefilesd [-d]* [-s] [-n] [-f <configfile>] + +The flags are: + + (*) -d + + Increase the debugging level. This can be specified multiple times and + is cumulative with itself. + + (*) -s + + Send messages to stderr instead of syslog. + + (*) -n + + Don't daemonise and go into background. + + (*) -f <configfile> + + Use an alternative configuration file rather than the default one. + + +=============== +THINGS TO AVOID +=============== + +Do not mount other things within the cache as this will cause problems. The +kernel module contains its own very cut-down path walking facility that ignores +mountpoints, but the daemon can't avoid them. + +Do not create, rename or unlink files and directories in the cache whilst the +cache is active, as this may cause the state to become uncertain. + +Renaming files in the cache might make objects appear to be other objects (the +filename is part of the lookup key). + +Do not change or remove the extended attributes attached to cache files by the +cache as this will cause the cache state management to get confused. + +Do not create files or directories in the cache, lest the cache get confused or +serve incorrect data. + +Do not chmod files in the cache. The module creates things with minimal +permissions to prevent random users being able to access them directly. + + +============= +CACHE CULLING +============= + +The cache may need culling occasionally to make space. This involves +discarding objects from the cache that have been used less recently than +anything else. Culling is based on the access time of data objects. Empty +directories are culled if not in use. + +Cache culling is done on the basis of the percentage of blocks and the +percentage of files available in the underlying filesystem. There are six +"limits": + + (*) brun + (*) frun + + If the amount of free space and the number of available files in the cache + rises above both these limits, then culling is turned off. + + (*) bcull + (*) fcull + + If the amount of available space or the number of available files in the + cache falls below either of these limits, then culling is started. + + (*) bstop + (*) fstop + + If the amount of available space or the number of available files in the + cache falls below either of these limits, then no further allocation of + disk space or files is permitted until culling has raised things above + these limits again. + +These must be configured thusly: + + 0 <= bstop < bcull < brun < 100 + 0 <= fstop < fcull < frun < 100 + +Note that these are percentages of available space and available files, and do +_not_ appear as 100 minus the percentage displayed by the "df" program. + +The userspace daemon scans the cache to build up a table of cullable objects. +These are then culled in least recently used order. A new scan of the cache is +started as soon as space is made in the table. Objects will be skipped if +their atimes have changed or if the kernel module says it is still using them. + + +=============== +CACHE STRUCTURE +=============== + +The CacheFiles module will create two directories in the directory it was +given: + + (*) cache/ + + (*) graveyard/ + +The active cache objects all reside in the first directory. The CacheFiles +kernel module moves any retired or culled objects that it can't simply unlink +to the graveyard from which the daemon will actually delete them. + +The daemon uses dnotify to monitor the graveyard directory, and will delete +anything that appears therein. + + +The module represents index objects as directories with the filename "I..." or +"J...". Note that the "cache/" directory is itself a special index. + +Data objects are represented as files if they have no children, or directories +if they do. Their filenames all begin "D..." or "E...". If represented as a +directory, data objects will have a file in the directory called "data" that +actually holds the data. + +Special objects are similar to data objects, except their filenames begin +"S..." or "T...". + + +If an object has children, then it will be represented as a directory. +Immediately in the representative directory are a collection of directories +named for hash values of the child object keys with an '@' prepended. Into +this directory, if possible, will be placed the representations of the child +objects: + + INDEX INDEX INDEX DATA FILES + ========= ========== ================================= ================ + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400 + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...DB1ry + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...N22ry + cache/@4a/I03nfs/@30/Ji000000000000000--fHg8hi8400/@75/Es0g000w...FP1ry + + +If the key is so long that it exceeds NAME_MAX with the decorations added on to +it, then it will be cut into pieces, the first few of which will be used to +make a nest of directories, and the last one of which will be the objects +inside the last directory. The names of the intermediate directories will have +'+' prepended: + + J1223/@23/+xy...z/+kl...m/Epqr + + +Note that keys are raw data, and not only may they exceed NAME_MAX in size, +they may also contain things like '/' and NUL characters, and so they may not +be suitable for turning directly into a filename. + +To handle this, CacheFiles will use a suitably printable filename directly and +"base-64" encode ones that aren't directly suitable. The two versions of +object filenames indicate the encoding: + + OBJECT TYPE PRINTABLE ENCODED + =============== =============== =============== + Index "I..." "J..." + Data "D..." "E..." + Special "S..." "T..." + +Intermediate directories are always "@" or "+" as appropriate. + + +Each object in the cache has an extended attribute label that holds the object +type ID (required to distinguish special objects) and the auxiliary data from +the netfs. The latter is used to detect stale objects in the cache and update +or retire them. + + +Note that CacheFiles will erase from the cache any file it doesn't recognise or +any file of an incorrect type (such as a FIFO file or a device file). + + +========================== +SECURITY MODEL AND SELINUX +========================== + +CacheFiles is implemented to deal properly with the LSM security features of +the Linux kernel and the SELinux facility. + +One of the problems that CacheFiles faces is that it is generally acting on +behalf of a process, and running in that process's context, and that includes a +security context that is not appropriate for accessing the cache - either +because the files in the cache are inaccessible to that process, or because if +the process creates a file in the cache, that file may be inaccessible to other +processes. + +The way CacheFiles works is to temporarily change the security context (fsuid, +fsgid and actor security label) that the process acts as - without changing the +security context of the process when it the target of an operation performed by +some other process (so signalling and suchlike still work correctly). + + +When the CacheFiles module is asked to bind to its cache, it: + + (1) Finds the security label attached to the root cache directory and uses + that as the security label with which it will create files. By default, + this is: + + cachefiles_var_t + + (2) Finds the security label of the process which issued the bind request + (presumed to be the cachefilesd daemon), which by default will be: + + cachefilesd_t + + and asks LSM to supply a security ID as which it should act given the + daemon's label. By default, this will be: + + cachefiles_kernel_t + + SELinux transitions the daemon's security ID to the module's security ID + based on a rule of this form in the policy. + + type_transition <daemon's-ID> kernel_t : process <module's-ID>; + + For instance: + + type_transition cachefilesd_t kernel_t : process cachefiles_kernel_t; + + +The module's security ID gives it permission to create, move and remove files +and directories in the cache, to find and access directories and files in the +cache, to set and access extended attributes on cache objects, and to read and +write files in the cache. + +The daemon's security ID gives it only a very restricted set of permissions: it +may scan directories, stat files and erase files and directories. It may +not read or write files in the cache, and so it is precluded from accessing the +data cached therein; nor is it permitted to create new files in the cache. + + +There are policy source files available in: + + http://people.redhat.com/~dhowells/fscache/cachefilesd-0.8.tar.bz2 + +and later versions. In that tarball, see the files: + + cachefilesd.te + cachefilesd.fc + cachefilesd.if + +They are built and installed directly by the RPM. + +If a non-RPM based system is being used, then copy the above files to their own +directory and run: + + make -f /usr/share/selinux/devel/Makefile + semodule -i cachefilesd.pp + +You will need checkpolicy and selinux-policy-devel installed prior to the +build. + + +By default, the cache is located in /var/fscache, but if it is desirable that +it should be elsewhere, than either the above policy files must be altered, or +an auxiliary policy must be installed to label the alternate location of the +cache. + +For instructions on how to add an auxiliary policy to enable the cache to be +located elsewhere when SELinux is in enforcing mode, please see: + + /usr/share/doc/cachefilesd-*/move-cache.txt + +When the cachefilesd rpm is installed; alternatively, the document can be found +in the sources.
fs/Kconfig +1 -0
@@ -634,6 +634,7 @@ config GENERIC_ACL menu "Caches" source "fs/fscache/Kconfig" +source "fs/cachefiles/Kconfig" endmenu
fs/Makefile +1 -0
@@ -116,6 +116,7 @@ obj-$(CONFIG_AFS_FS) += afs/ obj-$(CONFIG_BEFS_FS) += befs/ obj-$(CONFIG_HOSTFS) += hostfs/ obj-$(CONFIG_HPPFS) += hppfs/ +obj-$(CONFIG_CACHEFILES) += cachefiles/ obj-$(CONFIG_DEBUG_FS) += debugfs/ obj-$(CONFIG_OCFS2_FS) += ocfs2/ obj-$(CONFIG_GFS2_FS) += gfs2/
fs/cachefiles/Kconfig new file +33 -0
@@ -0,0 +1,33 @@ + +config CACHEFILES + tristate "Filesystem caching on files" + depends on FSCACHE + help + This permits use of a mounted filesystem as a cache for other + filesystems - primarily networking filesystems - thus allowing fast + local disk to enhance the speed of slower devices. + + See Documentation/filesystems/caching/cachefiles.txt for more + information. + +config CACHEFILES_DEBUG + bool "Debug CacheFiles" + depends on CACHEFILES + help + This permits debugging to be dynamically enabled in the filesystem + caching on files module. If this is set, the debugging output may be + enabled by setting bits in /sys/modules/cachefiles/parameter/debug or + by including a debugging specifier in /etc/cachefilesd.conf. + +config CACHEFILES_HISTOGRAM + bool "Gather latency information on CacheFiles" + depends on CACHEFILES && FSCACHE_PROC + help + + This option causes latency information to be gathered on CacheFiles + operation and exported through file: + + /proc/fs/fscache/cachefiles/histogram + + See Documentation/filesystems/caching/cachefiles.txt for more + information.
fs/cachefiles/Makefile new file +18 -0
@@ -0,0 +1,18 @@ +# +# Makefile for caching in a mounted filesystem +# + +cachefiles-y := \ + cf-bind.o \ + cf-daemon.o \ + cf-interface.o \ + cf-key.o \ + cf-main.o \ + cf-namei.o \ + cf-rdwr.o \ + cf-xattr.o + +cachefiles-$(CONFIG_SECURITY) += cf-security.o +cachefiles-$(CONFIG_CACHEFILES_HISTOGRAM) += cf-proc.o + +obj-$(CONFIG_CACHEFILES) := cachefiles.o
fs/cachefiles/cf-bind.c new file +288 -0
288 lines not on this page · raw message
fs/cachefiles/cf-daemon.c new file +720 -0
720 lines not on this page · raw message
fs/cachefiles/cf-interface.c new file +442 -0
442 lines not on this page · raw message
fs/cachefiles/cf-internal.h new file +414 -0
414 lines not on this page · raw message
fs/cachefiles/cf-key.c new file +159 -0
159 lines not on this page · raw message
fs/cachefiles/cf-main.c new file +109 -0
109 lines not on this page · raw message
fs/cachefiles/cf-namei.c new file +743 -0
408 lines not on this page · raw message
fs/cachefiles/cf-proc.c new file +166 -0
166 lines not on this page · raw message
fs/cachefiles/cf-security.c new file +107 -0
107 lines not on this page · raw message
fs/cachefiles/cf-xattr.c new file +292 -0
292 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
David Howells
maintainerPATCH 14/14 NFS: Use local caching [try #2]
In reply to David HowellsThe attached patch makes it possible for the NFS filesystem to make use of the network filesystem local caching service (FS-Cache).
To be able to use this, an updated mount program is required. This can be obtained from:
http://people.redhat.com/steved/cachefs/util-linux/
To mount an NFS filesystem to use caching, add an "fsc" option to the mount:
mount warthog:/ /a -o fsc
---
fs/Kconfig | 8 + fs/nfs/Makefile | 1 fs/nfs/client.c | 11 + fs/nfs/file.c | 38 +++- fs/nfs/fscache.c | 303 +++++++++++++++++++++++++++++ fs/nfs/fscache.h | 464 ++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/inode.c | 16 ++ fs/nfs/internal.h | 8 + fs/nfs/read.c | 27 ++- fs/nfs/super.c | 1 fs/nfs/sysctl.c | 43 ++++ fs/nfs/write.c | 3 include/linux/nfs4_mount.h | 3 include/linux/nfs_fs.h | 6 + include/linux/nfs_fs_sb.h | 5 include/linux/nfs_mount.h | 3 16 files changed, 931 insertions(+), 9 deletions(-)
fs/Kconfig +8 -0
@@ -1600,6 +1600,14 @@ config NFS_V4 If unsure, say N. +config NFS_FSCACHE + bool "Provide NFS client caching support (EXPERIMENTAL)" + depends on EXPERIMENTAL + depends on NFS_FS=m && FSCACHE || NFS_FS=y && FSCACHE=y + help + Say Y here if you want NFS data to be cached locally on disc through + the general filesystem cache manager + config NFS_DIRECTIO bool "Allow direct I/O on NFS files" depends on NFS_FS
fs/nfs/Makefile +1 -0
@@ -16,4 +16,5 @@ nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \ nfs4namespace.o nfs-$(CONFIG_NFS_DIRECTIO) += direct.o nfs-$(CONFIG_SYSCTL) += sysctl.o +nfs-$(CONFIG_NFS_FSCACHE) += fscache.o nfs-objs := $(nfs-y)
fs/nfs/client.c +8 -3
@@ -137,6 +137,8 @@ static struct nfs_client *nfs_alloc_client(const char *hostname, clp->cl_state =1 <<NFS4CLNT_LEASE_EXPIRED ;#endif +nfs_fscache_get_client_cookie (clp); +return clp; error_3:
@@ -168,6 +170,8 @@ static void nfs_free_client(struct nfs_client *clp)nfs4_shutdown_client (clp); +nfs_fscache_release_client_cookie (clp); +/* -EIO all pending I/O */ if (!IS_ERR (clp->cl_rpcclient))rpc_shutdown_client (clp->cl_rpcclient);
@@ -1308,7 +1312,7 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)/* display header on line 1 */ if (v == &nfs_volume_list) { -seq_puts (m,"NV SERVER PORT DEV FSID\n" ); +seq_puts (m,"NV SERVER PORT DEV FSID FSC\n" );return 0 ; }/* display one transport per line on subsequent lines */
@@ -1322,12 +1326,13 @@ static int nfs_volume_list_show(struct seq_file *m, void *v) (unsigned long long ) server->fsid.major, (unsigned long long) server->fsid.minor); -seq_printf (m,"v%d %02x%02x%02x%02x %4hx %-7s %-17s\n" , +seq_printf (m,"v%d %02x%02x%02x%02x %4hx %-7s %-17s %s\n" , clp->cl_nfsversion,NIPQUAD (clp->cl_addr.sin_addr),ntohs (clp->cl_addr.sin_port), dev, - fsid); + fsid, +nfs_server_fscache_state (server));return 0 ; }
fs/nfs/file.c +36 -2
@@ -34,6 +34,7 @@#include "delegation.h" #include "iostat.h" +#include "internal.h" #define NFSDBG_FACILITY NFSDBG_FILE
@@ -259,6 +260,10 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma) status =nfs_revalidate_mapping (inode, file->f_mapping);if (!status) status =generic_file_mmap (file, vma); + +if (status ==0 ) +nfs_fscache_install_vm_ops (inode, vma); +return status; }
@@ -311,22 +316,51 @@ static int nfs_commit_write(struct file *file, struct page *page, unsigned offsereturn status; } +/* +* partially or wholly invalidate a page +* - release the private state associated with a page if undergoing complete +* page invalidation +* - caller holds page lock +*/ static void nfs_invalidate_page (struct page *page,unsigned long offset) {if (offset !=0 )return ;/* Cancel any unstarted writes on this page */ nfs_wb_page_priority (page->mapping->host, page,FLUSH_INVALIDATE ); + +nfs_fscache_invalidate_page (page, page->mapping->host, offset); + +/* we can do this here as the bits are only set with the page lock +* held, and our caller is holding that */ +if (!page->private) +ClearPagePrivate (page); } +/* +* release the private state associated with a page, if the page isn't busy +* - caller holds page lock +* - return true (may release) or false (may not) +*/ static int nfs_release_page (struct page *page,gfp_t gfp) { -/* If PagePrivate() is set, then the page is not freeable */ -return 0 ; +/* +* Avoid deadlock on nfs_wait_on_request(). +*/ +if (!(gfp & __GFP_FS)) +return 0 ; + +if (!nfs_fscache_release_page (page, gfp)) +return 0 ; + +BUG_ON (page->private !=0 ); +ClearPagePrivate (page); +return 1 ; }static int nfs_launder_page (struct page *page) { +nfs_fscache_invalidate_page (page, page->mapping->host,0 );return nfs_wb_page (page->mapping->host, page); }
fs/nfs/fscache.c new file +303 -0
303 lines not on this page · raw message
fs/nfs/fscache.h new file +464 -0
464 lines not on this page · raw message
fs/nfs/inode.c +16 -0
@@ -88,6 +88,7 @@ void nfs_clear_inode(struct inode *inode)BUG_ON (atomic_read (&NFS_I (inode)->data_updates) !=0 );nfs_zap_acl_cache (inode);nfs_access_zap_cache (inode); +nfs_fscache_release_fh_cookie (inode); }/**
@@ -220,6 +221,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) };struct inode *inode =ERR_PTR (-ENOENT );unsigned long hash; +int maycache =1 ;if ((fattr->valid &NFS_ATTR_FATTR ) ==0 ) goto out_no_inode;
@@ -269,6 +271,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)else inode->i_op = &nfs_mountpoint_inode_operations; inode->i_fop =NULL ; + maycache =0 ; } }else if (S_ISLNK (inode->i_mode)) inode->i_op = &nfs_symlink_inode_operations;
@@ -300,6 +303,8 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)memset (nfsi->cookieverf,0 ,sizeof (nfsi->cookieverf)); nfsi->access_cache =RB_ROOT ; +nfs_fscache_init_fh_cookie (inode); +unlock_new_inode (inode); }else nfs_refresh_inode (inode, fattr);
@@ -573,6 +578,7 @@ int nfs_open(struct inode *inode, struct file *filp) ctx->mode = filp->f_mode;nfs_file_set_open_context (filp, ctx);put_nfs_open_context (ctx); +nfs_fscache_set_fh_cookie (inode, filp);return 0 ; }
@@ -698,6 +704,7 @@ static int nfs_invalidate_mapping_nolock(struct inode *inode, struct address_spa }spin_unlock (&inode->i_lock);nfs_inc_stats (inode,NFSIOS_DATAINVALIDATE ); +nfs_fscache_renew_fh_cookie (inode);dfprintk (PAGECACHE ,"NFS: (%s/%Ld) data cache invalidated\n" , inode->i_sb->s_id, (long long )NFS_FILEID (inode));return 0 ;
@@ -1000,11 +1007,13 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)if (data_stable) { inode->i_size = new_isize; invalid |=NFS_INO_INVALID_DATA ; +nfs_fscache_attr_changed (inode); } invalid |=NFS_INO_INVALID_ATTR ; }else if (new_isize > cur_isize) { inode->i_size = new_isize; invalid |=NFS_INO_INVALID_ATTR |NFS_INO_INVALID_DATA ; +nfs_fscache_attr_changed (inode); } nfsi->cache_change_attribute = now; dprintk("NFS: isize change on server for file %s/%ld\n",
@@ -1191,6 +1200,10 @@ static int __init init_nfs_fs(void) {int err; + err =nfs_fscache_register (); +if (err <0 ) + goto out6; + err =nfs_fs_proc_init ();if (err) goto out5;
@@ -1237,6 +1250,8 @@ out3: out4:nfs_fs_proc_exit (); out5: +nfs_fscache_unregister (); +out6:return err; }
@@ -1247,6 +1262,7 @@ static void __exit exit_nfs_fs(void)nfs_destroy_readpagecache ();nfs_destroy_inodecache ();nfs_destroy_nfspagecache (); +nfs_fscache_unregister ();#ifdef CONFIG_PROC_FS rpc_proc_unregister ("nfs" );#endif
fs/nfs/internal.h +8 -0
@@ -27,6 +27,11 @@ struct nfs_clone_mount {rpc_authflavor_t authflavor; }; +/* +* include filesystem caching stuff here +*/ +#include "fscache.h" +/* client.c */ extern struct rpc_program nfs_program;
@@ -149,6 +154,9 @@ extern int nfs4_path_walk(struct nfs_server *server, const char *path);#endif +/* read.c */ +extern int nfs_readpage_async (struct nfs_open_context *,struct inode *,struct page *); +/* * Determine the device name as a string */
fs/nfs/read.c +25 -2
@@ -18,6 +18,7 @@#include <linux/sunrpc/clnt.h> #include <linux/nfs_fs.h> #include <linux/nfs_page.h> +#include <linux/nfs_mount.h> #include <linux/smp_lock.h> #include <asm/system.h>
@@ -114,8 +115,8 @@ static void nfs_readpage_truncate_uninitialised_page(struct nfs_read_data *data) } } -static int nfs_readpage_async (struct nfs_open_context *ctx,struct inode *inode, -struct page *page) +int nfs_readpage_async (struct nfs_open_context *ctx,struct inode *inode, +struct page *page) {LIST_HEAD (one_request);struct nfs_page *new;
@@ -142,6 +143,11 @@ static int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,static void nfs_readpage_release (struct nfs_page *req) { +struct inode *d_inode = req->wb_context->path.dentry->d_inode; + +if (PageUptodate (req->wb_page)) +nfs_readpage_to_fscache (d_inode, req->wb_page,0 ); +unlock_page (req->wb_page); dprintk("NFS: read done (%s/%Ld %d@%Ld)\n",
@@ -500,8 +506,15 @@ int nfs_readpage(struct file *file, struct page *page) ctx =get_nfs_open_context ((struct nfs_open_context *) file->private_data); +if (!IS_SYNC (inode)) { + error =nfs_readpage_from_fscache (ctx, inode, page); +if (error ==0 ) + goto out; + } + error =nfs_readpage_async (ctx, inode, page); +out:put_nfs_open_context (ctx);return error; out_unlock:
@@ -578,6 +591,15 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, }else desc.ctx =get_nfs_open_context ((struct nfs_open_context *) filp->private_data); + +/* attempt to read as many of the pages as possible from the cache +* - this returns -ENOBUFS immediately if the cookie is negative +*/ + ret =nfs_readpages_from_fscache (desc.ctx, inode, mapping, + pages, &nr_pages); +if (ret ==0 ) + goto read_complete;/* all pages were read */ +if (rsize <PAGE_CACHE_SIZE )nfs_pageio_init (&pgio, inode, nfs_pagein_multi, rsize,0 );else
@@ -588,6 +610,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,nfs_pageio_complete (&pgio); npages = (pgio.pg_bytes_written +PAGE_CACHE_SIZE -1 ) >>PAGE_CACHE_SHIFT ;nfs_add_stats (inode,NFSIOS_READPAGES , npages); +read_complete:put_nfs_open_context (desc.ctx); out:return ret;
fs/nfs/super.c +1 -0
@@ -456,6 +456,7 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, { NFS_MOUNT_NOACL, ",noacl", "" }, { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" }, { NFS_MOUNT_UNSHARED, ",nosharecache", ""}, + { NFS_MOUNT_FSCACHE, ",fsc", "" }, { 0, NULL, NULL } };const struct proc_nfs_info *nfs_infop;
fs/nfs/sysctl.c +43 -0
55 lines not on this page · raw message
fs/nfs/write.c +3 -0
@@ -147,6 +147,9 @@ static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int creturn ;nfs_inc_stats (inode,NFSIOS_EXTENDWRITE );i_size_write (inode, end); +#ifdef FSCACHE_WRITE_SUPPORT +nfs_set_fscsize (NFS_SERVER (inode),NFS_I (inode), end); +#endif }/* A writeback failed: mark the page as bad, and invalidate the page cache */
include/linux/nfs4_mount.h +2 -1
@@ -66,6 +66,7 @@ struct nfs4_mount_data {#define NFS4_MOUNT_NOAC 0x0020/* 1 */ #define NFS4_MOUNT_STRICTLOCK 0x1000/* 1 */ #define NFS4_MOUNT_UNSHARED 0x8000/* 1 */ -#define NFS4_MOUNT_FLAGMASK 0x9033 +#define NFS4_MOUNT_FSCACHE 0x10000/* 1 */ +#define NFS4_MOUNT_FLAGMASK 0x19033#endif
include/linux/nfs_fs.h +6 -0
@@ -172,6 +172,9 @@ struct nfs_inode {int delegation_state;struct rw_semaphore rwsem;#endif /* CONFIG_NFS_V4*/ +#ifdef CONFIG_NFS_FSCACHE +struct fscache_cookie *fscache; +#endif struct inode vfs_inode; };
@@ -193,6 +196,7 @@ struct nfs_inode {#define NFS_INO_ADVISE_RDPLUS (1)/* advise readdirplus */ #define NFS_INO_STALE (2)/* possible stale inode */ #define NFS_INO_ACL_LRU_SET (3)/* Inode is on the LRU list */ +#define NFS_INO_FSCACHE (4)/* inode can be cached by FS-Cache */ static inline struct nfs_inode *NFS_I (struct inode *inode) {
@@ -218,6 +222,7 @@ static inline struct nfs_inode *NFS_I(struct inode *inode)#define NFS_FLAGS (inode) (NFS_I(inode)->flags)#define NFS_STALE (inode) (test_bit(NFS_INO_STALE, &NFS_FLAGS(inode))) +#define NFS_FSCACHE (inode) (test_bit(NFS_INO_FSCACHE, &NFS_FLAGS(inode)))#define NFS_FILEID (inode) (NFS_I(inode)->fileid)
@@ -553,6 +558,7 @@ extern void * nfs_root_data(void);#define NFSDBG_CALLBACK 0x0100#define NFSDBG_CLIENT 0x0200#define NFSDBG_MOUNT 0x0400 +#define NFSDBG_FSCACHE 0x0800#define NFSDBG_ALL 0xFFFF#ifdef __KERNEL__
include/linux/nfs_fs_sb.h +5 -0
@@ -3,6 +3,7 @@#include <linux/list.h> #include <linux/backing-dev.h> +#include <linux/fscache.h> struct nfs_iostats ;
@@ -65,6 +66,10 @@ struct nfs_client {char cl_ipaddr[16 ];unsigned char cl_id_uniquifier;#endif + +#ifdef CONFIG_NFS_FSCACHE +struct fscache_cookie *fscache;/* client index cache cookie */ +#endif };/*
include/linux/nfs_mount.h +2 -1
@@ -63,6 +63,7 @@ struct nfs_mount_data {#define NFS_MOUNT_SECFLAVOUR 0x2000/* 5 */ #define NFS_MOUNT_NORDIRPLUS 0x4000/* 5 */ #define NFS_MOUNT_UNSHARED 0x8000/* 5 */ -#define NFS_MOUNT_FLAGMASK 0xFFFF +#define NFS_MOUNT_FSCACHE 0x10000/* 5 */ +#define NFS_MOUNT_FLAGMASK 0x1FFFF#endif
Re: [PATCH 14/14] NFS: Use local caching [try #2]
Dang, that's a lot of inlines... AFAICS, approx half of fs/nfs/fscache.h should really be moved into fscache.c.
Otherwise, this looks a lot less intrusive than previous patches.
See inlined comments.
Quoted 96 lines · David Howells
The attached patch makes it possible for the NFS filesystem to make use of the network filesystem local caching service (FS-Cache).
To be able to use this, an updated mount program is required. This can be obtained from:
http://people.redhat.com/steved/cachefs/util-linux/
To mount an NFS filesystem to use caching, add an "fsc" option to the mount:
mount warthog:/ /a -o fsc
Signed-off-by David Howells <[email protected]>---
fs/Kconfig | 8 + fs/nfs/Makefile | 1 fs/nfs/client.c | 11 + fs/nfs/file.c | 38 +++- fs/nfs/fscache.c | 303 +++++++++++++++++++++++++++++ fs/nfs/fscache.h | 464 ++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/inode.c | 16 ++ fs/nfs/internal.h | 8 + fs/nfs/read.c | 27 ++- fs/nfs/super.c | 1 fs/nfs/sysctl.c | 43 ++++ fs/nfs/write.c | 3 include/linux/nfs4_mount.h | 3 include/linux/nfs_fs.h | 6 + include/linux/nfs_fs_sb.h | 5 include/linux/nfs_mount.h | 3 16 files changed, 931 insertions(+), 9 deletions(-)fs/Kconfig +8
-0@@ -1600,6 +1600,14 @@ config NFS_V4 If unsure, say N. +config NFS_FSCACHE + bool "Provide NFS client caching support (EXPERIMENTAL)" + depends on EXPERIMENTAL + depends on NFS_FS=m && FSCACHE || NFS_FS=y && FSCACHE=y + help + Say Y here if you want NFS data to be cached locally on disc through + the general filesystem cache manager + config NFS_DIRECTIO bool "Allow direct I/O on NFS files" depends on NFS_FSfs/nfs/Makefile +1
-0@@ -16,4 +16,5 @@ nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \ nfs4namespace.o nfs-$(CONFIG_NFS_DIRECTIO) += direct.o nfs-$(CONFIG_SYSCTL) += sysctl.o +nfs-$(CONFIG_NFS_FSCACHE) += fscache.o nfs-objs := $(nfs-y)fs/nfs/client.c +5
-1@@ -137,6 +137,8 @@ static struct nfs_client *nfs_alloc_client(const char *hostname, clp->cl_state =1 <<NFS4CLNT_LEASE_EXPIRED ;#endif +nfs_fscache_get_client_cookie (clp); +return clp; error_3:@@ -168,6 +170,8 @@ static void nfs_free_client(struct nfs_client *clp)nfs4_shutdown_client (clp); +nfs_fscache_release_client_cookie (clp); +/* -EIO all pending I/O */ if (!IS_ERR (clp->cl_rpcclient))rpc_shutdown_client (clp->cl_rpcclient);@@ -1308,7 +1312,7 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)/* display header on line 1 */ if (v == &nfs_volume_list) { -seq_puts (m,"NV SERVER PORT DEV FSID\n" ); +seq_puts (m,"NV SERVER PORT DEV FSID FSC\n" );return 0 ; }/* display one transport per line on subsequent lines */ @@ -1322,12 +1326,13 @@ static int nfs_volume_list_show(struct seq_file *m, void *v) (unsigned long long ) server->fsid.major, (unsigned long long) server->fsid.minor);
fs/nfs/client.c static int nfs_volume_list_show(struct seq_file *m, void *v) · line 1335
Quoted 10 lines
fs/nfs/client.c +3
-2-seq_printf (m,"v%d %02x%02x%02x%02x %4hx %-7s %-17s\n" , +seq_printf (m,"v%d %02x%02x%02x%02x %4hx %-7s %-17s %s\n" , clp->cl_nfsversion,NIPQUAD (clp->cl_addr.sin_addr),ntohs (clp->cl_addr.sin_port), dev, - fsid); + fsid, +nfs_server_fscache_state (server));
Please send these changes as a separate patch: they change an existing interface.
Quoted 16 lines
fs/nfs/client.c +0
-0return 0 ; }fs/nfs/file.c +1
-0@@ -34,6 +34,7 @@#include "delegation.h" #include "iostat.h" +#include "internal.h" #define NFSDBG_FACILITY NFSDBG_FILE
fs/nfs/file.c nfs_file_mmap(struct file * file, struct vm_area_struct * vma) · line 267
Quoted 8 lines
fs/nfs/file.c +4
-0@@ -259,6 +260,10 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma) status =nfs_revalidate_mapping (inode, file->f_mapping);if (!status) status =generic_file_mmap (file, vma); + +if (status ==0 ) +nfs_fscache_install_vm_ops (inode, vma); +return status;
Please note that in 2.6.24 the NFS client will be gaining a page_mkwrite() method in order to fix the remaining mmap() races. AFAICS, it should be fairly trivial to merge with your nfs_file_page_mkwrite.
Quoted 15 lines
fs/nfs/file.c +6
-0}@@ -311,22 +316,51 @@ static int nfs_commit_write(struct file *file, struct page *page, unsigned offsereturn status; } +/* +* partially or wholly invalidate a page +* - release the private state associated with a page if undergoing complete +* page invalidation +* - caller holds page lock +*/ static void nfs_invalidate_page (struct page *page,unsigned long offset) {if (offset !=0 )
fs/nfs/file.c static int nfs_commit_write(struct file *file, struct page *page, unsigned offse · line 337
Quoted 10 lines
fs/nfs/file.c +7
-0return ;/* Cancel any unstarted writes on this page */ nfs_wb_page_priority (page->mapping->host, page,FLUSH_INVALIDATE ); + +nfs_fscache_invalidate_page (page, page->mapping->host, offset); + +/* we can do this here as the bits are only set with the page lock +* held, and our caller is holding that */ +if (!page->private) +ClearPagePrivate (page);
Why would PG_private be set at this point?
In any case, please send this and other PagePrivate changes as a separate patch. Any changes to the PagePrivate semantics must be made easy to debug.
Quoted 6 lines
fs/nfs/file.c +4
-0} +/* +* release the private state associated with a page, if the page isn't busy +* - caller holds page lock +* - return true (may release) or false (may not)
fs/nfs/file.c static int nfs_commit_write(struct file *file, struct page *page, unsigned offse · line 351
Quoted 10 lines
fs/nfs/file.c +6
-2+*/ static int nfs_release_page (struct page *page,gfp_t gfp) { -/* If PagePrivate() is set, then the page is not freeable */ -return 0 ; +/* +* Avoid deadlock on nfs_wait_on_request(). +*/ +if (!(gfp & __GFP_FS)) +return 0 ;
We got rid of this. There should be no race with nfs_wait_on_request(). Either fix up the comment, or remove the test.
fs/nfs/file.c static int nfs_commit_write(struct file *file, struct page *page, unsigned offse · line 354
Quoted 3 lines
fs/nfs/file.c +3
-0+ +if (!nfs_fscache_release_page (page, gfp)) +return 0 ;
This looks _very_ dubious. Why shouldn't I be able to discard a page just because fscache isn't done writing it out? I may have very good reasons to do so.
fs/nfs/file.c static int nfs_commit_write(struct file *file, struct page *page, unsigned offse · line 363
Quoted 8 lines
fs/nfs/file.c +4
-0+BUG_ON (page->private !=0 ); +ClearPagePrivate (page); +return 1 ; }static int nfs_launder_page (struct page *page) { +nfs_fscache_invalidate_page (page, page->mapping->host,0 );
Why? The function of launder_page() is to clean the page, not to truncate it.
Quoted 836 lines
fs/nfs/file.c +0
-0return nfs_wb_page (page->mapping->host, page); }fs/nfs/fscache.c new file +303
-0@@ -0,0 +1,303 @@ +/* fscache.c: NFS filesystem cache interface +* +* Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + + +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/mm.h> +#include <linux/nfs_fs.h> +#include <linux/nfs_fs_sb.h> +#include <linux/in6.h> + +#include "internal.h" + +/* +* Sysctl variables +*/ +atomic_t nfs_fscache_to_pages; +atomic_t nfs_fscache_from_pages; +atomic_t nfs_fscache_uncache_page; +int nfs_fscache_from_error; +int nfs_fscache_to_error; + +#define NFSDBG_FACILITY NFSDBG_FSCACHE + +/* the auxiliary data in the cache (used for coherency management) */ +struct nfs_fh_auxdata { +struct timespec i_mtime; +struct timespec i_ctime; +loff_t i_size; +}; + +static struct fscache_netfs_operations nfs_cache_ops = { +}; + +struct fscache_netfs nfs_cache_netfs = { + .name ="nfs" , + .version =0 , + .ops = &nfs_cache_ops, +}; + +static const uint8_t nfs_cache_ipv6_wrapper_for_ipv4[12 ] = { + [0 ...9 ] =0x00 , + [10 ...11 ] =0xff +}; + +struct nfs_server_key { +uint16_t nfsversion; +uint16_t port; +union { +struct { +uint8_t ipv6wrapper[12 ]; +struct in_addr addr; + } ipv4_addr; +struct in6_addr ipv6_addr; + }; +}; + +static uint16_t nfs_server_get_key (const void *cookie_netfs_data, +void *buffer,uint16_t bufmax) +{ +const struct nfs_client *clp = cookie_netfs_data; +struct nfs_server_key *key = buffer; +uint16_t len =0 ; + + key->nfsversion = clp->cl_nfsversion; + +switch (clp->cl_addr.sin_family) { +case AF_INET : + key->port = clp->cl_addr.sin_port; + +memcpy (&key->ipv4_addr.ipv6wrapper, + &nfs_cache_ipv6_wrapper_for_ipv4, +sizeof (key->ipv4_addr.ipv6wrapper)); +memcpy (&key->ipv4_addr.addr, + &clp->cl_addr.sin_addr, +sizeof (key->ipv4_addr.addr)); + len =sizeof (struct nfs_server_key ); +break ; + +case AF_INET6 : + key->port = clp->cl_addr.sin_port; + +memcpy (&key->ipv6_addr, + &clp->cl_addr.sin_addr, +sizeof (key->ipv6_addr)); + len =sizeof (struct nfs_server_key ); +break ; + +default : + len =0 ; +printk (KERN_WARNING "NFS: Unknown network family '%d'\n" , + clp->cl_addr.sin_family); +break ; + } + +return len; +} + +/* +* the root index for the filesystem is defined by nfsd IP address and ports +*/ +struct fscache_cookie_def nfs_cache_server_index_def = { + .name ="NFS.servers" , + .type =FSCACHE_COOKIE_TYPE_INDEX , + .get_key = nfs_server_get_key, +}; + +static uint16_t nfs_fh_get_key (const void *cookie_netfs_data, +void *buffer,uint16_t bufmax) +{ +const struct nfs_inode *nfsi = cookie_netfs_data; +uint16_t nsize; + +/* set the file handle */ + nsize = nfsi->fh.size; +memcpy (buffer, nfsi->fh.data, nsize); +return nsize; +} + +/* +* get an extra reference on a read context +* - this function can be absent if the completion function doesn't +* require a context +*/ +static void nfs_fh_get_context (void *cookie_netfs_data,void *context) +{ +get_nfs_open_context (context); +} + +/* +* release an extra reference on a read context +* - this function can be absent if the completion function doesn't +* require a context +*/ +static void nfs_fh_put_context (void *cookie_netfs_data,void *context) +{ +if (context) +put_nfs_open_context (context); +} + +/* +* indication the cookie is no longer uncached +* - this function is called when the backing store currently caching a cookie +* is removed +* - the netfs should use this to clean up any markers indicating cached pages +* - this is mandatory for any object that may have data +*/ +static void nfs_fh_now_uncached (void *cookie_netfs_data) +{ +struct nfs_inode *nfsi = cookie_netfs_data; +struct pagevec pvec; +pgoff_t first; +int loop, nr_pages; + +pagevec_init (&pvec,0 ); + first =0 ; + +dprintk ("NFS: nfs_fh_now_uncached: nfs_inode 0x%p\n" , nfsi); + +for (;;) { +/* grab a bunch of pages to clean */ + nr_pages =pagevec_lookup (&pvec, + nfsi->vfs_inode.i_mapping, + first, +PAGEVEC_SIZE -pagevec_count (&pvec)); +if (!nr_pages) +break ; + +for (loop =0 ; loop < nr_pages; loop++) +ClearPageFsCache (pvec.pages[loop]); + + first = pvec.pages[nr_pages -1 ]->index +1 ; + + pvec.nr = nr_pages; +pagevec_release (&pvec); +cond_resched (); + } +} + +/* +* get certain file attributes from the netfs data +* - this function can be absent for an index +* - not permitted to return an error +* - the netfs data from the cookie being used as the source is +* presented +*/ +static void nfs_fh_get_attr (const void *cookie_netfs_data,uint64_t *size) +{ +const struct nfs_inode *nfsi = cookie_netfs_data; + + *size = nfsi->vfs_inode.i_size; +} + +/* +* get the auxilliary data from netfs data +* - this function can be absent if the index carries no state data +* - should store the auxilliary data in the buffer +* - should return the amount of amount stored +* - not permitted to return an error +* - the netfs data from the cookie being used as the source is +* presented +*/ +static uint16_t nfs_fh_get_aux (const void *cookie_netfs_data, +void *buffer,uint16_t bufmax) +{ +struct nfs_fh_auxdata auxdata; +const struct nfs_inode *nfsi = cookie_netfs_data; + + auxdata.i_size = nfsi->vfs_inode.i_size; + auxdata.i_mtime = nfsi->vfs_inode.i_mtime; + auxdata.i_ctime = nfsi->vfs_inode.i_ctime; + +if (bufmax >sizeof (auxdata)) + bufmax =sizeof (auxdata); + +memcpy (buffer, &auxdata, bufmax); +return bufmax; +} + +/* +* consult the netfs about the state of an object +* - this function can be absent if the index carries no state data +* - the netfs data from the cookie being used as the target is +* presented, as is the auxilliary data +*/ +static fscache_checkaux_t nfs_fh_check_aux (void *cookie_netfs_data, +const void *data,uint16_t datalen) +{ +struct nfs_fh_auxdata auxdata; +struct nfs_inode *nfsi = cookie_netfs_data; + +if (datalen >sizeof (auxdata)) +return FSCACHE_CHECKAUX_OBSOLETE ; + + auxdata.i_size = nfsi->vfs_inode.i_size; + auxdata.i_mtime = nfsi->vfs_inode.i_mtime; + auxdata.i_ctime = nfsi->vfs_inode.i_ctime; + +if (memcmp (data, &auxdata, datalen) !=0 ) +return FSCACHE_CHECKAUX_OBSOLETE ; + +return FSCACHE_CHECKAUX_OKAY ; +} + +/* +* the primary index for each server is simply made up of a series of NFS file +* handles +*/ +struct fscache_cookie_def nfs_cache_fh_index_def = { + .name ="NFS.fh" , + .type =FSCACHE_COOKIE_TYPE_DATAFILE , + .get_key = nfs_fh_get_key, + .get_attr = nfs_fh_get_attr, + .get_aux = nfs_fh_get_aux, + .check_aux = nfs_fh_check_aux, + .get_context = nfs_fh_get_context, + .put_context = nfs_fh_put_context, + .now_uncached = nfs_fh_now_uncached, +}; + +static int nfs_file_page_mkwrite (struct vm_area_struct *vma,struct page *page) +{ +wait_on_page_fscache_write (page); +return 0 ; +} + +struct vm_operations_struct nfs_fs_vm_operations = { + .fault = filemap_fault, + .page_mkwrite = nfs_file_page_mkwrite, +}; + +/* +* handle completion of a page being read from the cache +* - called in process (keventd) context +*/ +void nfs_readpage_from_fscache_complete (struct page *page, +void *context, +int error) +{ +dfprintk (FSCACHE , +"NFS: readpage_from_fscache_complete (0x%p/0x%p/%d)\n" , + page, context, 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); + }else { + error =nfs_readpage_async (context, page->mapping->host, page); +if (error) +unlock_page (page); + } +}fs/nfs/fscache.h new file +464
-0@@ -0,0 +1,464 @@ +/* fscache.h: NFS filesystem cache interface definitions +* +* Copyright (C) 2006 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _NFS_FSCACHE_H +#define _NFS_FSCACHE_H + +#include <linux/nfs_fs.h> +#include <linux/nfs_mount.h> +#include <linux/nfs4_mount.h> + +#ifdef CONFIG_NFS_FSCACHE +#include <linux/fscache.h> + +extern struct fscache_netfs nfs_cache_netfs; +extern struct fscache_cookie_def nfs_cache_server_index_def; +extern struct fscache_cookie_def nfs_cache_fh_index_def; +extern struct vm_operations_struct nfs_fs_vm_operations; + +extern void nfs_invalidatepage (struct page *,unsigned long ); +extern int nfs_releasepage (struct page *,gfp_t ); + +extern atomic_t nfs_fscache_to_pages; +extern atomic_t nfs_fscache_from_pages; +extern atomic_t nfs_fscache_uncache_page; +extern int nfs_fscache_from_error; +extern int nfs_fscache_to_error; + +/* +* register NFS for caching +*/ +static inline int nfs_fscache_register (void ) +{ +return fscache_register_netfs (&nfs_cache_netfs); +} + +/* +* unregister NFS for caching +*/ +static inline void nfs_fscache_unregister (void ) +{ +fscache_unregister_netfs (&nfs_cache_netfs); +} + +/* +* get the per-client index cookie for an NFS client if the appropriate mount +* flag was set +* - we always try and get an index cookie for the client, but get filehandle +* cookies on a per-superblock basis, depending on the mount flags +*/ +static inline void nfs_fscache_get_client_cookie (struct nfs_client *clp) +{ +/* create a cache index for looking up filehandles */ + clp->fscache =fscache_acquire_cookie (nfs_cache_netfs.primary_index, + &nfs_cache_server_index_def, + clp); +dfprintk (FSCACHE ,"NFS: get client cookie (0x%p/0x%p)\n" , + clp, clp->fscache); +} + +/* +* dispose of a per-client cookie +*/ +static inline void nfs_fscache_release_client_cookie (struct nfs_client *clp) +{ +dfprintk (FSCACHE ,"NFS: releasing client cookie (0x%p/0x%p)\n" , + clp, clp->fscache); + +fscache_relinquish_cookie (clp->fscache,0 ); + clp->fscache =NULL ; +} + +/* +* indicate the client caching state as readable text +*/ +static inline const char *nfs_server_fscache_state (struct nfs_server *server) +{ +if (server->nfs_client->fscache && (server->flags &NFS_MOUNT_FSCACHE )) +return "yes" ; +return "no " ; +} + +/* +* get the per-filehandle cookie for an NFS inode +*/ +static inline void nfs_fscache_init_fh_cookie (struct inode *inode) +{ +NFS_I (inode)->fscache =NULL ; +if (S_ISREG (inode->i_mode)) +set_bit (NFS_INO_FSCACHE , &NFS_I (inode)->flags); +} + +/* +* get the per-filehandle cookie for an NFS inode +*/ +static inline void nfs_fscache_enable_fh_cookie (struct inode *inode) +{ +struct super_block *sb = inode->i_sb; +struct nfs_inode *nfsi =NFS_I (inode); + +if (nfsi->fscache || !NFS_FSCACHE (inode)) +return ; + +if ((NFS_SB (sb)->flags &NFS_MOUNT_FSCACHE )) { + nfsi->fscache =fscache_acquire_cookie ( +NFS_SB (sb)->nfs_client->fscache, + &nfs_cache_fh_index_def, + nfsi); + +dfprintk (FSCACHE ,"NFS: get FH cookie (0x%p/0x%p/0x%p)\n" , + sb, nfsi, nfsi->fscache); + } +} + +/* +* change the filesize associated with a per-filehandle cookie +*/ +static inline void nfs_fscache_attr_changed (struct inode *inode) +{ +fscache_attr_changed (NFS_I (inode)->fscache); +} + +/* +* replace a per-filehandle cookie due to revalidation detecting a file having +* changed on the server +*/ +static inline void nfs_fscache_renew_fh_cookie (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); +struct nfs_server *server =NFS_SERVER (inode); +struct fscache_cookie *old = nfsi->fscache; + +if (nfsi->fscache) { +/* retire the current fscache cache and get a new one */ +fscache_relinquish_cookie (nfsi->fscache,1 ); + + nfsi->fscache =fscache_acquire_cookie ( + server->nfs_client->fscache, + &nfs_cache_fh_index_def, + nfsi); + +dfprintk (FSCACHE , +"NFS: revalidation new cookie (0x%p/0x%p/0x%p/0x%p)\n" , + server, nfsi, old, nfsi->fscache); + } +} + +/* +* release a per-filehandle cookie +*/ +static inline void nfs_fscache_release_fh_cookie (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); + +dfprintk (FSCACHE ,"NFS: clear cookie (0x%p/0x%p)\n" , + nfsi, nfsi->fscache); + +fscache_relinquish_cookie (nfsi->fscache,0 ); + nfsi->fscache =NULL ; +} + +/* +* retire a per-filehandle cookie, destroying the data attached to it +*/ +static inline void nfs_fscache_zap_fh_cookie (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); + +dfprintk (FSCACHE ,"NFS: zapping cookie (0x%p/0x%p)\n" , + nfsi, nfsi->fscache); + +fscache_relinquish_cookie (nfsi->fscache,1 ); + nfsi->fscache =NULL ; +} + +/* +* turn off the cache with regard to a filehandle cookie if opened for writing, +* invalidating all the pages in the page cache relating to the associated +* inode to clear the per-page caching +*/ +static inline void nfs_fscache_disable_fh_cookie (struct inode *inode) +{ +clear_bit (NFS_INO_FSCACHE , &NFS_I (inode)->flags); + +if (NFS_I (inode)->fscache) { +dfprintk (FSCACHE , +"NFS: nfsi 0x%p turning cache off\n" ,NFS_I (inode)); + +/* Need to invalided any mapped pages that were read in before +* turning off the cache. +*/ +if (inode->i_mapping && inode->i_mapping->nrpages) +invalidate_inode_pages2 (inode->i_mapping); + +nfs_fscache_zap_fh_cookie (inode); + } +} + +/* +* decide if we should enable or disable the FS cache for this inode +* - for now, only regular files that are open read-only will be able to use +* the cache +*/ +static inline void nfs_fscache_set_fh_cookie (struct inode *inode, +struct file *filp) +{ +if (NFS_FSCACHE (inode)) { +if ((filp->f_flags &O_ACCMODE ) !=O_RDONLY ) +nfs_fscache_disable_fh_cookie (inode); +else +nfs_fscache_enable_fh_cookie (inode); + } +} + +/* +* install the VM ops for mmap() of an NFS file so that we can hold up writes +* to pages on shared writable mappings until the store to the cache is +* complete +*/ +static inline void nfs_fscache_install_vm_ops (struct inode *inode, +struct vm_area_struct *vma) +{ +if (NFS_I (inode)->fscache) + vma->vm_ops = &nfs_fs_vm_operations; +} + +/* +* release the caching state associated with a page, if the page isn't busy +* interacting with the cache +* - returns true (can release page) or false (page busy) +*/ +static inline int nfs_fscache_release_page (struct page *page,gfp_t gfp) +{ +if (PageFsCacheWrite (page)) { +if (!(gfp & __GFP_WAIT)) +return 0 ; +wait_on_page_fscache_write (page); + } + +if (PageFsCache (page)) { +struct nfs_inode *nfsi =NFS_I (page->mapping->host); + +BUG_ON (!nfsi->fscache); + +dfprintk (FSCACHE ,"NFS: fscache releasepage (0x%p/0x%p/0x%p)\n" , + nfsi->fscache, page, nfsi); + +fscache_uncache_page (nfsi->fscache, page); +atomic_inc (&nfs_fscache_uncache_page); +ClearPageFsCache (page); + } + +return 1 ; +} + +/* +* release the caching state associated with a page if undergoing complete page +* invalidation +*/ +static inline void nfs_fscache_invalidate_page (struct page *page, +struct inode *inode, +unsigned long offset) +{ +struct nfs_inode *nfsi =NFS_I (page->mapping->host); + +if (PageFsCache (page)) { +BUG_ON (!nfsi->fscache); + +dfprintk (FSCACHE , +"NFS: fscache invalidatepage (0x%p/0x%p/0x%p)\n" , + nfsi->fscache, page, nfsi); + +wait_on_page_fscache_write (page); + +if (offset ==0 ) { +BUG_ON (!PageLocked (page)); +if (!PageWriteback (page)) { +fscache_uncache_page (nfsi->fscache, page); +atomic_inc (&nfs_fscache_uncache_page); +ClearPageFsCache (page); + } + } + } +} + +/* +* store a newly fetched page in fscache +*/ +static inline void nfs_readpage_to_fscache (struct inode *inode, +struct page *page, +int sync) +{ +int ret; + +if (PageFsCache (page)) { +dfprintk (FSCACHE , +"NFS: " +"readpage_to_fscache(fsc:%p/p:%p(i:%lx f:%lx)/%d)\n" , +NFS_I (inode)->fscache, page, page->index, page->flags, + sync); + + ret =fscache_write_page (NFS_I (inode)->fscache, page, +GFP_KERNEL ); +dfprintk (FSCACHE , +"NFS: " +"readpage_to_fscache: p:%p(i:%lu f:%lx) ret %d\n" , + page, page->index, page->flags, ret); + +if (ret !=0 ) { +fscache_uncache_page (NFS_I (inode)->fscache, page); +atomic_inc (&nfs_fscache_uncache_page); +ClearPageFsCache (page); + nfs_fscache_to_error = ret; + }else { +atomic_inc (&nfs_fscache_to_pages); + } + } +} + +/* +* retrieve a page from fscache +*/ +extern void nfs_readpage_from_fscache_complete (struct page *,void *,int ); + +static inline +int nfs_readpage_from_fscache (struct nfs_open_context *ctx, +struct inode *inode, +struct page *page) +{ +int ret; + +if (!NFS_I (inode)->fscache) +return 1 ; + +dfprintk (FSCACHE , +"NFS: readpage_from_fscache(fsc:%p/p:%p(i:%lx f:%lx)/0x%p)\n" , +NFS_I (inode)->fscache, page, page->index, page->flags, inode); + + ret =fscache_read_or_alloc_page (NFS_I (inode)->fscache, + page, + nfs_readpage_from_fscache_complete, + ctx, +GFP_KERNEL ); + +switch (ret) { +case 0 :/* read BIO submitted (page in fscache) */ +dfprintk (FSCACHE , +"NFS: readpage_from_fscache: BIO submitted\n" ); +atomic_inc (&nfs_fscache_from_pages); +return ret; + +case -ENOBUFS :/* inode not in cache */ +case -ENODATA :/* page not in cache */ +dfprintk (FSCACHE , +"NFS: readpage_from_fscache error %d\n" , ret); +return 1 ; + +default : +dfprintk (FSCACHE ,"NFS: readpage_from_fscache %d\n" , ret); + nfs_fscache_from_error = ret; + } +return ret; +} + +/* +* retrieve a set of pages from fscache +*/ +static inline int nfs_readpages_from_fscache (struct nfs_open_context *ctx, +struct inode *inode, +struct address_space *mapping, +struct list_head *pages, +unsigned *nr_pages) +{ +int ret, npages = *nr_pages; + +if (!NFS_I (inode)->fscache) +return 1 ; + +dfprintk (FSCACHE , +"NFS: nfs_getpages_from_fscache (0x%p/%u/0x%p)\n" , +NFS_I (inode)->fscache, *nr_pages, inode); + + ret =fscache_read_or_alloc_pages (NFS_I (inode)->fscache, + mapping, pages, nr_pages, + nfs_readpage_from_fscache_complete, + ctx, +mapping_gfp_mask (mapping)); + + +switch (ret) { +case 0 :/* read BIO submitted (page in fscache) */ +BUG_ON (!list_empty (pages)); +BUG_ON (*nr_pages !=0 ); +dfprintk (FSCACHE , +"NFS: nfs_getpages_from_fscache: BIO submitted\n" ); + +atomic_add (npages, &nfs_fscache_from_pages); +return ret; + +case -ENOBUFS :/* inode not in cache */ +case -ENODATA :/* page not in cache */ +dfprintk (FSCACHE , +"NFS: nfs_getpages_from_fscache: no page: %d\n" , ret); +return 1 ; + +default : +dfprintk (FSCACHE , +"NFS: nfs_getpages_from_fscache: ret %d\n" , ret); + nfs_fscache_from_error = ret; + } + +return ret; +} + +#else /* CONFIG_NFS_FSCACHE */ +static inline int nfs_fscache_register (void ) {return 0 ; } +static inline void nfs_fscache_unregister (void ) {} +static inline void nfs_fscache_get_client_cookie (struct nfs_client *clp) {} +static inline void nfs4_fscache_get_client_cookie (struct nfs_client *clp) {} +static inline void nfs_fscache_release_client_cookie (struct nfs_client *clp) {} +static inline const char *nfs_server_fscache_state (struct nfs_server *server) {return "no " ; } + +static inline void nfs_fscache_init_fh_cookie (struct inode *inode) {} +static inline void nfs_fscache_enable_fh_cookie (struct inode *inode) {} +static inline void nfs_fscache_attr_changed (struct inode *inode) {} +static inline void nfs_fscache_release_fh_cookie (struct inode *inode) {} +static inline void nfs_fscache_zap_fh_cookie (struct inode *inode) {} +static inline void nfs_fscache_renew_fh_cookie (struct inode *inode) {} +static inline void nfs_fscache_disable_fh_cookie (struct inode *inode) {} +static inline void nfs_fscache_set_fh_cookie (struct inode *inode,struct file *filp) {} +static inline void nfs_fscache_install_vm_ops (struct inode *inode,struct vm_area_struct *vma) {} +static inline int nfs_fscache_release_page (struct page *page,gfp_t gfp) +{ +return 1 ;/* True: may release page */ +} +static inline void nfs_fscache_invalidate_page (struct page *page, +struct inode *inode, +unsigned long offset) +{ +} +static inline void nfs_readpage_to_fscache (struct inode *inode,struct page *page,int sync) {} +static inline int nfs_readpage_from_fscache (struct nfs_open_context *ctx, +struct inode *inode,struct page *page) +{ +return -ENOBUFS ; +} +static inline int nfs_readpages_from_fscache (struct nfs_open_context *ctx, +struct inode *inode, +struct address_space *mapping, +struct list_head *pages, +unsigned *nr_pages) +{ +return -ENOBUFS ; +} + +#endif /* CONFIG_NFS_FSCACHE */ +#endif /* _NFS_FSCACHE_H */ fs/nfs/inode.c +7
-0@@ -88,6 +88,7 @@ void nfs_clear_inode(struct inode *inode)BUG_ON (atomic_read (&NFS_I (inode)->data_updates) !=0 );nfs_zap_acl_cache (inode);nfs_access_zap_cache (inode); +nfs_fscache_release_fh_cookie (inode); }/** @@ -220,6 +221,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) };struct inode *inode =ERR_PTR (-ENOENT );unsigned long hash; +int maycache =1 ;if ((fattr->valid &NFS_ATTR_FATTR ) ==0 ) goto out_no_inode;@@ -269,6 +271,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)else inode->i_op = &nfs_mountpoint_inode_operations; inode->i_fop =NULL ; + maycache =0 ; } }else if (S_ISLNK (inode->i_mode)) inode->i_op = &nfs_symlink_inode_operations;@@ -300,6 +303,8 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)memset (nfsi->cookieverf,0 ,sizeof (nfsi->cookieverf)); nfsi->access_cache =RB_ROOT ; +nfs_fscache_init_fh_cookie (inode); +unlock_new_inode (inode); }else nfs_refresh_inode (inode, fattr);@@ -573,6 +578,7 @@ int nfs_open(struct inode *inode, struct file *filp) ctx->mode = filp->f_mode;nfs_file_set_open_context (filp, ctx);put_nfs_open_context (ctx); +nfs_fscache_set_fh_cookie (inode, filp);return 0 ; }@@ -698,6 +704,7 @@ static int nfs_invalidate_mapping_nolock(struct inode *inode, struct address_spa }spin_unlock (&inode->i_lock);nfs_inc_stats (inode,NFSIOS_DATAINVALIDATE ); +nfs_fscache_renew_fh_cookie (inode);dfprintk (PAGECACHE ,"NFS: (%s/%Ld) data cache invalidated\n" , inode->i_sb->s_id, (long long )NFS_FILEID (inode));return 0 ;
fs/nfs/inode.c static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) · line 1010
Quoted 4 lines
fs/nfs/inode.c +1
-0@@ -1000,11 +1007,13 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)if (data_stable) { inode->i_size = new_isize; invalid |=NFS_INO_INVALID_DATA ; +nfs_fscache_attr_changed (inode);
Can't fscache_attr_changed() call kmalloc(GFP_KERNEL)? You are in a spinlocked context here.
Quoted 42 lines
fs/nfs/inode.c +8
-0} invalid |=NFS_INO_INVALID_ATTR ; }else if (new_isize > cur_isize) { inode->i_size = new_isize; invalid |=NFS_INO_INVALID_ATTR |NFS_INO_INVALID_DATA ; +nfs_fscache_attr_changed (inode); } nfsi->cache_change_attribute = now; dprintk("NFS: isize change on server for file %s/%ld\n",@@ -1191,6 +1200,10 @@ static int __init init_nfs_fs(void) {int err; + err =nfs_fscache_register (); +if (err <0 ) + goto out6; + err =nfs_fs_proc_init ();if (err) goto out5;@@ -1237,6 +1250,8 @@ out3: out4:nfs_fs_proc_exit (); out5: +nfs_fscache_unregister (); +out6:return err; }@@ -1247,6 +1262,7 @@ static void __exit exit_nfs_fs(void)nfs_destroy_readpagecache ();nfs_destroy_inodecache ();nfs_destroy_nfspagecache (); +nfs_fscache_unregister ();#ifdef CONFIG_PROC_FS rpc_proc_unregister ("nfs" );#endif fs/nfs/internal.h +0
-0
fs/nfs/internal.h struct nfs_clone_mount { · line 33
Quoted 7 lines
fs/nfs/internal.h +4
-0@@ -27,6 +27,11 @@ struct nfs_clone_mount {rpc_authflavor_t authflavor; }; +/* +* include filesystem caching stuff here +*/ +#include "fscache.h"
Why? internal.h has no dependencies on anything from fscache.h.
fs/nfs/internal.h extern int nfs4_path_walk(struct nfs_server *server, · line 159
Quoted 11 lines
fs/nfs/internal.h +4
-0+/* client.c */ extern struct rpc_program nfs_program;@@ -149,6 +154,9 @@ extern int nfs4_path_walk(struct nfs_server *server, const char *path);#endif +/* read.c */ +extern int nfs_readpage_async (struct nfs_open_context *,struct inode *,struct page *); +
Please put this in nfs_fs.h together with the other NFS read exports.
Quoted 156 lines
fs/nfs/internal.h +0
-0/* * Determine the device name as a string */ fs/nfs/read.c +25
-2@@ -18,6 +18,7 @@#include <linux/sunrpc/clnt.h> #include <linux/nfs_fs.h> #include <linux/nfs_page.h> +#include <linux/nfs_mount.h> #include <linux/smp_lock.h> #include <asm/system.h> @@ -114,8 +115,8 @@ static void nfs_readpage_truncate_uninitialised_page(struct nfs_read_data *data) } } -static int nfs_readpage_async (struct nfs_open_context *ctx,struct inode *inode, -struct page *page) +int nfs_readpage_async (struct nfs_open_context *ctx,struct inode *inode, +struct page *page) {LIST_HEAD (one_request);struct nfs_page *new;@@ -142,6 +143,11 @@ static int nfs_readpage_async(struct nfs_open_context *ctx, struct inode *inode,static void nfs_readpage_release (struct nfs_page *req) { +struct inode *d_inode = req->wb_context->path.dentry->d_inode; + +if (PageUptodate (req->wb_page)) +nfs_readpage_to_fscache (d_inode, req->wb_page,0 ); +unlock_page (req->wb_page); dprintk("NFS: read done (%s/%Ld %d@%Ld)\n",@@ -500,8 +506,15 @@ int nfs_readpage(struct file *file, struct page *page) ctx =get_nfs_open_context ((struct nfs_open_context *) file->private_data); +if (!IS_SYNC (inode)) { + error =nfs_readpage_from_fscache (ctx, inode, page); +if (error ==0 ) + goto out; + } + error =nfs_readpage_async (ctx, inode, page); +out:put_nfs_open_context (ctx);return error; out_unlock:@@ -578,6 +591,15 @@ int nfs_readpages(struct file *filp, struct address_space *mapping, }else desc.ctx =get_nfs_open_context ((struct nfs_open_context *) filp->private_data); + +/* attempt to read as many of the pages as possible from the cache +* - this returns -ENOBUFS immediately if the cookie is negative +*/ + ret =nfs_readpages_from_fscache (desc.ctx, inode, mapping, + pages, &nr_pages); +if (ret ==0 ) + goto read_complete;/* all pages were read */ +if (rsize <PAGE_CACHE_SIZE )nfs_pageio_init (&pgio, inode, nfs_pagein_multi, rsize,0 );else @@ -588,6 +610,7 @@ int nfs_readpages(struct file *filp, struct address_space *mapping,nfs_pageio_complete (&pgio); npages = (pgio.pg_bytes_written +PAGE_CACHE_SIZE -1 ) >>PAGE_CACHE_SHIFT ;nfs_add_stats (inode,NFSIOS_READPAGES , npages); +read_complete:put_nfs_open_context (desc.ctx); out:return ret;fs/nfs/super.c +1
-0@@ -456,6 +456,7 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, { NFS_MOUNT_NOACL, ",noacl", "" }, { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" }, { NFS_MOUNT_UNSHARED, ",nosharecache", ""}, + { NFS_MOUNT_FSCACHE, ",fsc", "" }, { 0, NULL, NULL } };const struct proc_nfs_info *nfs_infop;fs/nfs/sysctl.c +43
-0@@ -14,6 +14,7 @@#include <linux/nfs_fs.h> #include "callback.h" +#include "internal.h" static const int nfs_set_port_min =0 ;static const int nfs_set_port_max =65535 ;@@ -58,6 +59,48 @@ static ctl_table nfs_cb_sysctls[] = { .mode = 0644, .proc_handler = &proc_dointvec, }, +#ifdef CONFIG_NFS_FSCACHE + { + .ctl_name = CTL_UNNUMBERED, + .procname = "fscache_from_error", + .data = &nfs_fscache_from_error, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec, + }, + { + .ctl_name = CTL_UNNUMBERED, + .procname = "fscache_to_error", + .data = &nfs_fscache_to_error, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec, + }, + { + .ctl_name = CTL_UNNUMBERED, + .procname = "fscache_uncache_page", + .data = &nfs_fscache_uncache_page, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec, + }, + { + .ctl_name = CTL_UNNUMBERED, + .procname = "fscache_to_pages", + .data = &nfs_fscache_to_pages, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec_minmax, + }, + { + .ctl_name = CTL_UNNUMBERED, + .procname = "fscache_from_pages", + .data = &nfs_fscache_from_pages, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = &proc_dointvec, + }, +#endif { .ctl_name = 0 } };fs/nfs/write.c +0
-0
fs/nfs/write.c static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int c · line 152
Quoted 6 lines
fs/nfs/write.c +3
-0@@ -147,6 +147,9 @@ static void nfs_grow_file(struct page *page, unsigned int offset, unsigned int creturn ;nfs_inc_stats (inode,NFSIOS_EXTENDWRITE );i_size_write (inode, end); +#ifdef FSCACHE_WRITE_SUPPORT +nfs_set_fscsize (NFS_SERVER (inode),NFS_I (inode), end); +#endif
I can't see how this belongs in this patch.
Quoted 83 lines
fs/nfs/write.c +0
-0}/* A writeback failed: mark the page as bad, and invalidate the page cache */ include/linux/nfs4_mount.h +2
-1@@ -66,6 +66,7 @@ struct nfs4_mount_data {#define NFS4_MOUNT_NOAC 0x0020/* 1 */ #define NFS4_MOUNT_STRICTLOCK 0x1000/* 1 */ #define NFS4_MOUNT_UNSHARED 0x8000/* 1 */ -#define NFS4_MOUNT_FLAGMASK 0x9033 +#define NFS4_MOUNT_FSCACHE 0x10000/* 1 */ +#define NFS4_MOUNT_FLAGMASK 0x19033#endif include/linux/nfs_fs.h +6
-0@@ -172,6 +172,9 @@ struct nfs_inode {int delegation_state;struct rw_semaphore rwsem;#endif /* CONFIG_NFS_V4*/ +#ifdef CONFIG_NFS_FSCACHE +struct fscache_cookie *fscache; +#endif struct inode vfs_inode; };@@ -193,6 +196,7 @@ struct nfs_inode {#define NFS_INO_ADVISE_RDPLUS (1)/* advise readdirplus */ #define NFS_INO_STALE (2)/* possible stale inode */ #define NFS_INO_ACL_LRU_SET (3)/* Inode is on the LRU list */ +#define NFS_INO_FSCACHE (4)/* inode can be cached by FS-Cache */ static inline struct nfs_inode *NFS_I (struct inode *inode) {@@ -218,6 +222,7 @@ static inline struct nfs_inode *NFS_I(struct inode *inode)#define NFS_FLAGS (inode) (NFS_I(inode)->flags)#define NFS_STALE (inode) (test_bit(NFS_INO_STALE, &NFS_FLAGS(inode))) +#define NFS_FSCACHE (inode) (test_bit(NFS_INO_FSCACHE, &NFS_FLAGS(inode)))#define NFS_FILEID (inode) (NFS_I(inode)->fileid)@@ -553,6 +558,7 @@ extern void * nfs_root_data(void);#define NFSDBG_CALLBACK 0x0100#define NFSDBG_CLIENT 0x0200#define NFSDBG_MOUNT 0x0400 +#define NFSDBG_FSCACHE 0x0800#define NFSDBG_ALL 0xFFFF#ifdef __KERNEL__include/linux/nfs_fs_sb.h +5
-0@@ -3,6 +3,7 @@#include <linux/list.h> #include <linux/backing-dev.h> +#include <linux/fscache.h> struct nfs_iostats ;@@ -65,6 +66,10 @@ struct nfs_client {char cl_ipaddr[16 ];unsigned char cl_id_uniquifier;#endif + +#ifdef CONFIG_NFS_FSCACHE +struct fscache_cookie *fscache;/* client index cache cookie */ +#endif };/* include/linux/nfs_mount.h +0
-0
include/linux/nfs_mount.h struct nfs_mount_data { · line 69
Quoted 8 lines
include/linux/nfs_mount.h +2
-1@@ -63,6 +63,7 @@ struct nfs_mount_data {#define NFS_MOUNT_SECFLAVOUR 0x2000/* 5 */ #define NFS_MOUNT_NORDIRPLUS 0x4000/* 5 */ #define NFS_MOUNT_UNSHARED 0x8000/* 5 */ -#define NFS_MOUNT_FLAGMASK 0xFFFF +#define NFS_MOUNT_FSCACHE 0x10000/* 5 */ +#define NFS_MOUNT_FLAGMASK 0x1FFFF#endif
I'm not too happy about the change to the binary mount interface. As far as I'm concerned, the binary interface should really be considered frozen, and should not be touched.
Instead, feel free to update the text-based mount interface (which can be found in 2.6.23-rc1 and later). Please put any such mount interface changes in a separate patch together with the Kconfig changes.
Cheers
Trond
David Howells
maintainerRe: [PATCH 14/14] NFS: Use local caching [try #2]
Quoted 2 lines · Trond Myklebust
Dang, that's a lot of inlines... AFAICS, approx half of
fs/nfs/fscache.hshould really be moved intofscache.c.
If you wish. It seems a shame since a lot of them have only one caller.
Quoted 6 lines
fs/nfs/file.c static int nfs_commit_write(struct file *file, struct page *page, unsigned offse · line 337
Quoted 4 lines
fs/nfs/file.c +4
-0+/* we can do this here as the bits are only set with the page lock +* held, and our caller is holding that */ +if (!page->private) +ClearPagePrivate (page);Why would
PG_privatebe set at this point?
Looks like I've got a bit more cleaning up to do. PG_private isn't set by FS-Cache, so this bit shouldn't be here.
Quoted 3 lines
In any case, please send this and other PagePrivate changes as a separate patch. Any changes to the PagePrivate semantics must be made easy to debug.
There shouldn't be any.
Note that due to patch #2, PG_fscache causes releasepage() and invalidatepage() to be called in addition to PG_private.
Quoted 7 lines
fs/nfs/file.c static int nfs_commit_write(struct file *file, struct page *page, unsigned offse · line 354
Quoted 3 lines
fs/nfs/file.c +3
-0+ +if (!nfs_fscache_release_page (page, gfp)) +return 0 ;This looks _very_ dubious. Why shouldn't I be able to discard a page just because fscache isn't done writing it out? I may have very good reasons to do so.
Hmmm... Looking at the truncate routines, I suppose this ought to be okay, provided the cache retains a reference on the page whilst it's writing it out (put_page() won't can the page until we release it).
It also seems dubious, though, to release the page when the filesystem is doing stuff to it, even if it's by proxy in the cache. I'll have to test that, but I'm slightly concerned that the netfs could end up releasing its cookie before the cache has finished with its pages. On the other hand, with the new asynchronous stuff I've done, I'm not sure this'll be an actual problem.
Quoted 6 lines
fs/nfs/file.c static int nfs_commit_write(struct file *file, struct page *page, unsigned offse · line 363
Quoted 3 lines
static int
nfs_launder_page(struct page *page)
{fs/nfs/file.c +1
-0+nfs_fscache_invalidate_page (page, page->mapping->host,0 );Why? The function of
launder_page()is to clean the page, not to truncate it.
Okay.
Quoted 8 lines
fs/nfs/inode.c static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) · line 1010
Quoted 5 lines
fs/nfs/inode.c +1
-0@@ -1000,11 +1007,13 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)if (data_stable) { inode->i_size = new_isize; invalid |=NFS_INO_INVALID_DATA ; +nfs_fscache_attr_changed (inode);Can't
fscache_attr_changed()callkmalloc(GFP_KERNEL)? You are in a spinlocked context here.
Hmmm... How about I move the call to fscache_attr_changed() to the callers of nfs_update_inode(), to just after the spinlock is unlocked. The operation is going to be asynchronous, so the delay shouldn't matter.
Quoted 3 lines
I'm not too happy about the change to the binary mount interface. As far as I'm concerned, the binary interface should really be considered frozen, and should not be touched.
I hadn't come across that. I'll have a look.
Quoted 3 lines
Instead, feel free to update the text-based mount interface (which can be found in 2.6.23-rc1 and later). Please put any such mount interface changes in a separate patch together with the
Kconfigchanges.
If you wish, but doesn't that violate the rules of patch division laid down by Linus and Andrew?
David
David Howells
maintainerRe: [PATCH 14/14] NFS: Use local caching [try #2]
Quoted 3 lines
Quoted 3 lines
Instead, feel free to update the text-based mount interface (which can be found in 2.6.23-rc1 and later).
I presume you're referring to nfs_mount_option_tokens[] and friends. Is there a mount program that can drive this?
David
Re: [PATCH 14/14] NFS: Use local caching [try #2]
In reply to David HowellsQuoted 6 lines · David Howells
Quoted 2 lines · Trond Myklebust
Dang, that's a lot of inlines... AFAICS, approx half of
fs/nfs/fscache.hshould really be moved intofscache.c.If you wish. It seems a shame since a lot of them have only one caller.
...however it also forces you to export a lot of stuff which is really private to fscache.c (the atomics etc).
Quoted 17 lines
Note that due to patch #2,
PG_fscachecausesreleasepage()andinvalidatepage()to be called in addition toPG_private.Quoted 7 lines
fs/nfs/file.c static int nfs_commit_write(struct file *file, struct page *page, unsigned offse · line 354
Quoted 3 lines
fs/nfs/file.c +3
-0+ +if (!nfs_fscache_release_page (page, gfp)) +return 0 ;This looks _very_ dubious. Why shouldn't I be able to discard a page just because fscache isn't done writing it out? I may have very good reasons to do so.
Hmmm... Looking at the truncate routines, I suppose this ought to be okay, provided the cache retains a reference on the page whilst it's writing it out (
put_page()won't can the page until we release it).
Quoted 6 lines
It also seems dubious, though, to release the page when the filesystem is doing stuff to it, even if it's by proxy in the cache. I'll have to test that, but I'm slightly concerned that the netfs could end up releasing its cookie before the cache has finished with its pages. On the other hand, with the new asynchronous stuff I've done, I'm not sure this'll be an actual problem.
Actually, as long as launder_page() and invalidate_page() are doing their thing, then your current code might be OK. The important thing is to ensure that invalidate_inode_pages2() and truncate_inode_pages() work as expected.
Quoted 8 lines
Quoted 6 lines
fs/nfs/file.c static int nfs_commit_write(struct file *file, struct page *page, unsigned offse · line 363
Quoted 3 lines
static int
nfs_launder_page(struct page *page)
{fs/nfs/file.c +1
-0+nfs_fscache_invalidate_page (page, page->mapping->host,0 );Why? The function of
launder_page()is to clean the page, not to truncate it.Okay.
What you should be doing here is probably to make a call to wait_on_page_fscache_write(page). That should suffice to ensure that the page is clean w.r.t. fscache activity afaics.
Quoted 9 lines
Quoted 8 lines
fs/nfs/inode.c static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) · line 1010
Quoted 5 lines
fs/nfs/inode.c +1
-0@@ -1000,11 +1007,13 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)if (data_stable) { inode->i_size = new_isize; invalid |=NFS_INO_INVALID_DATA ; +nfs_fscache_attr_changed (inode);Can't
fscache_attr_changed()callkmalloc(GFP_KERNEL)? You are in a spinlocked context here.
Quoted 3 lines
Hmmm... How about I move the call to
fscache_attr_changed()to the callers ofnfs_update_inode(), to just after the spinlock is unlocked. The operation is going to be asynchronous, so the delay shouldn't matter.
Right. You might also want to add a flag NFS_INO_INVALID_FSCACHE_ATTR or something like that in order to trigger it.
Quoted 4 lines
Quoted 3 lines
I'm not too happy about the change to the binary mount interface. As far as I'm concerned, the binary interface should really be considered frozen, and should not be touched.
Quoted 8 lines
I hadn't come across that. I'll have a look.
Quoted 3 lines
Instead, feel free to update the text-based mount interface (which can be found in 2.6.23-rc1 and later). Please put any such mount interface changes in a separate patch together with the
Kconfigchanges.If you wish, but doesn't that violate the rules of patch division laid down by Linus and Andrew?
Why? It should be possible to set this up so that the NFS+fscache code compiles correctly without the mount patch.
Trond
David Howells
maintainerRe: [PATCH 14/14] NFS: Use local caching [try #2]
Quoted 7 lines · Trond Myklebust
Quoted 4 lines
Quoted 2 lines
Dang, that's a lot of inlines... AFAICS, approx half of
fs/nfs/fscache.hshould really be moved intofscache.c.If you wish. It seems a shame since a lot of them have only one caller.
...however it also forces you to export a lot of stuff which is really private to
fscache.c(the atomics etc).
The atomics is actually a bad example. These are referred to directly by part of the table in fs/nfs/sysctl.c. Is there a better way of exporting statistics than through /proc/sys/ files?
David
Re: [PATCH 14/14] NFS: Use local caching [try #2]
Quoted 5 lines · David Howells
Quoted 3 lines · Trond Myklebust
Quoted 3 lines
Quoted 2 lines
Dang, that's a lot of inlines... AFAICS, approx half of
fs/nfs/fscache.hshould really be moved intofscache.c.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
If you wish. It seems a shame since a lot of them have only one caller.
...however it also forces you to export a lot of stuff which is really private to
fscache.c(the atomics etc).The atomics is actually a bad example. These are referred to directly by part of the table in
fs/nfs/sysctl.c. Is there a better way of exporting statistics than through/proc/sys/files?
/proc/self/mountstats
Trond