4 * Generic code for various authentication-related caches
5 * used by sunrpc clients and servers.
7 * Copyright (C) 2002 Neil Brown <neilb@cse.unsw.edu.au>
9 * Released under terms in GPL version 2. See COPYING.
13 #include <linux/types.h>
15 #include <linux/file.h>
16 #include <linux/slab.h>
17 #include <linux/signal.h>
18 #include <linux/sched.h>
19 #include <linux/kmod.h>
20 #include <linux/list.h>
21 #include <linux/module.h>
22 #include <linux/ctype.h>
23 #include <linux/string_helpers.h>
24 #include <asm/uaccess.h>
25 #include <linux/poll.h>
26 #include <linux/seq_file.h>
27 #include <linux/proc_fs.h>
28 #include <linux/net.h>
29 #include <linux/workqueue.h>
30 #include <linux/mutex.h>
31 #include <linux/pagemap.h>
32 #include <asm/ioctls.h>
33 #include <linux/sunrpc/types.h>
34 #include <linux/sunrpc/cache.h>
35 #include <linux/sunrpc/stats.h>
36 #include <linux/sunrpc/rpc_pipe_fs.h>
39 #define RPCDBG_FACILITY RPCDBG_CACHE
41 static bool cache_defer_req(struct cache_req
*req
, struct cache_head
*item
);
42 static void cache_revisit_request(struct cache_head
*item
);
44 static void cache_init(struct cache_head
*h
)
46 time_t now
= seconds_since_boot();
50 h
->expiry_time
= now
+ CACHE_NEW_EXPIRY
;
51 h
->last_refresh
= now
;
54 struct cache_head
*sunrpc_cache_lookup(struct cache_detail
*detail
,
55 struct cache_head
*key
, int hash
)
57 struct cache_head
**head
, **hp
;
58 struct cache_head
*new = NULL
, *freeme
= NULL
;
60 head
= &detail
->hash_table
[hash
];
62 read_lock(&detail
->hash_lock
);
64 for (hp
=head
; *hp
!= NULL
; hp
= &(*hp
)->next
) {
65 struct cache_head
*tmp
= *hp
;
66 if (detail
->match(tmp
, key
)) {
67 if (cache_is_expired(detail
, tmp
))
68 /* This entry is expired, we will discard it. */
71 read_unlock(&detail
->hash_lock
);
75 read_unlock(&detail
->hash_lock
);
76 /* Didn't find anything, insert an empty entry */
78 new = detail
->alloc();
81 /* must fully initialise 'new', else
82 * we might get lose if we need to
86 detail
->init(new, key
);
88 write_lock(&detail
->hash_lock
);
90 /* check if entry appeared while we slept */
91 for (hp
=head
; *hp
!= NULL
; hp
= &(*hp
)->next
) {
92 struct cache_head
*tmp
= *hp
;
93 if (detail
->match(tmp
, key
)) {
94 if (cache_is_expired(detail
, tmp
)) {
102 write_unlock(&detail
->hash_lock
);
103 cache_put(new, detail
);
111 write_unlock(&detail
->hash_lock
);
114 cache_put(freeme
, detail
);
117 EXPORT_SYMBOL_GPL(sunrpc_cache_lookup
);
120 static void cache_dequeue(struct cache_detail
*detail
, struct cache_head
*ch
);
122 static void cache_fresh_locked(struct cache_head
*head
, time_t expiry
)
124 head
->expiry_time
= expiry
;
125 head
->last_refresh
= seconds_since_boot();
126 smp_wmb(); /* paired with smp_rmb() in cache_is_valid() */
127 set_bit(CACHE_VALID
, &head
->flags
);
130 static void cache_fresh_unlocked(struct cache_head
*head
,
131 struct cache_detail
*detail
)
133 if (test_and_clear_bit(CACHE_PENDING
, &head
->flags
)) {
134 cache_revisit_request(head
);
135 cache_dequeue(detail
, head
);
139 struct cache_head
*sunrpc_cache_update(struct cache_detail
*detail
,
140 struct cache_head
*new, struct cache_head
*old
, int hash
)
142 /* The 'old' entry is to be replaced by 'new'.
143 * If 'old' is not VALID, we update it directly,
144 * otherwise we need to replace it
146 struct cache_head
**head
;
147 struct cache_head
*tmp
;
149 if (!test_bit(CACHE_VALID
, &old
->flags
)) {
150 write_lock(&detail
->hash_lock
);
151 if (!test_bit(CACHE_VALID
, &old
->flags
)) {
152 if (test_bit(CACHE_NEGATIVE
, &new->flags
))
153 set_bit(CACHE_NEGATIVE
, &old
->flags
);
155 detail
->update(old
, new);
156 cache_fresh_locked(old
, new->expiry_time
);
157 write_unlock(&detail
->hash_lock
);
158 cache_fresh_unlocked(old
, detail
);
161 write_unlock(&detail
->hash_lock
);
163 /* We need to insert a new entry */
164 tmp
= detail
->alloc();
166 cache_put(old
, detail
);
170 detail
->init(tmp
, old
);
171 head
= &detail
->hash_table
[hash
];
173 write_lock(&detail
->hash_lock
);
174 if (test_bit(CACHE_NEGATIVE
, &new->flags
))
175 set_bit(CACHE_NEGATIVE
, &tmp
->flags
);
177 detail
->update(tmp
, new);
182 cache_fresh_locked(tmp
, new->expiry_time
);
183 cache_fresh_locked(old
, 0);
184 write_unlock(&detail
->hash_lock
);
185 cache_fresh_unlocked(tmp
, detail
);
186 cache_fresh_unlocked(old
, detail
);
187 cache_put(old
, detail
);
190 EXPORT_SYMBOL_GPL(sunrpc_cache_update
);
192 static int cache_make_upcall(struct cache_detail
*cd
, struct cache_head
*h
)
194 if (cd
->cache_upcall
)
195 return cd
->cache_upcall(cd
, h
);
196 return sunrpc_cache_pipe_upcall(cd
, h
);
199 static inline int cache_is_valid(struct cache_head
*h
)
201 if (!test_bit(CACHE_VALID
, &h
->flags
))
205 if (test_bit(CACHE_NEGATIVE
, &h
->flags
))
209 * In combination with write barrier in
210 * sunrpc_cache_update, ensures that anyone
211 * using the cache entry after this sees the
220 static int try_to_negate_entry(struct cache_detail
*detail
, struct cache_head
*h
)
224 write_lock(&detail
->hash_lock
);
225 rv
= cache_is_valid(h
);
227 set_bit(CACHE_NEGATIVE
, &h
->flags
);
228 cache_fresh_locked(h
, seconds_since_boot()+CACHE_NEW_EXPIRY
);
231 write_unlock(&detail
->hash_lock
);
232 cache_fresh_unlocked(h
, detail
);
237 * This is the generic cache management routine for all
238 * the authentication caches.
239 * It checks the currency of a cache item and will (later)
240 * initiate an upcall to fill it if needed.
243 * Returns 0 if the cache_head can be used, or cache_puts it and returns
244 * -EAGAIN if upcall is pending and request has been queued
245 * -ETIMEDOUT if upcall failed or request could not be queue or
246 * upcall completed but item is still invalid (implying that
247 * the cache item has been replaced with a newer one).
248 * -ENOENT if cache entry was negative
250 int cache_check(struct cache_detail
*detail
,
251 struct cache_head
*h
, struct cache_req
*rqstp
)
254 long refresh_age
, age
;
256 /* First decide return status as best we can */
257 rv
= cache_is_valid(h
);
259 /* now see if we want to start an upcall */
260 refresh_age
= (h
->expiry_time
- h
->last_refresh
);
261 age
= seconds_since_boot() - h
->last_refresh
;
266 } else if (rv
== -EAGAIN
||
267 (h
->expiry_time
!= 0 && age
> refresh_age
/2)) {
268 dprintk("RPC: Want update, refage=%ld, age=%ld\n",
270 if (!test_and_set_bit(CACHE_PENDING
, &h
->flags
)) {
271 switch (cache_make_upcall(detail
, h
)) {
273 rv
= try_to_negate_entry(detail
, h
);
276 cache_fresh_unlocked(h
, detail
);
283 if (!cache_defer_req(rqstp
, h
)) {
285 * Request was not deferred; handle it as best
288 rv
= cache_is_valid(h
);
294 cache_put(h
, detail
);
297 EXPORT_SYMBOL_GPL(cache_check
);
300 * caches need to be periodically cleaned.
301 * For this we maintain a list of cache_detail and
302 * a current pointer into that list and into the table
305 * Each time cache_clean is called it finds the next non-empty entry
306 * in the current table and walks the list in that entry
307 * looking for entries that can be removed.
309 * An entry gets removed if:
310 * - The expiry is before current time
311 * - The last_refresh time is before the flush_time for that cache
313 * later we might drop old entries with non-NEVER expiry if that table
314 * is getting 'full' for some definition of 'full'
316 * The question of "how often to scan a table" is an interesting one
317 * and is answered in part by the use of the "nextcheck" field in the
319 * When a scan of a table begins, the nextcheck field is set to a time
320 * that is well into the future.
321 * While scanning, if an expiry time is found that is earlier than the
322 * current nextcheck time, nextcheck is set to that expiry time.
323 * If the flush_time is ever set to a time earlier than the nextcheck
324 * time, the nextcheck time is then set to that flush_time.
326 * A table is then only scanned if the current time is at least
327 * the nextcheck time.
331 static LIST_HEAD(cache_list
);
332 static DEFINE_SPINLOCK(cache_list_lock
);
333 static struct cache_detail
*current_detail
;
334 static int current_index
;
336 static void do_cache_clean(struct work_struct
*work
);
337 static struct delayed_work cache_cleaner
;
339 void sunrpc_init_cache_detail(struct cache_detail
*cd
)
341 rwlock_init(&cd
->hash_lock
);
342 INIT_LIST_HEAD(&cd
->queue
);
343 spin_lock(&cache_list_lock
);
346 atomic_set(&cd
->readers
, 0);
349 list_add(&cd
->others
, &cache_list
);
350 spin_unlock(&cache_list_lock
);
352 /* start the cleaning process */
353 schedule_delayed_work(&cache_cleaner
, 0);
355 EXPORT_SYMBOL_GPL(sunrpc_init_cache_detail
);
357 void sunrpc_destroy_cache_detail(struct cache_detail
*cd
)
360 spin_lock(&cache_list_lock
);
361 write_lock(&cd
->hash_lock
);
362 if (cd
->entries
|| atomic_read(&cd
->inuse
)) {
363 write_unlock(&cd
->hash_lock
);
364 spin_unlock(&cache_list_lock
);
367 if (current_detail
== cd
)
368 current_detail
= NULL
;
369 list_del_init(&cd
->others
);
370 write_unlock(&cd
->hash_lock
);
371 spin_unlock(&cache_list_lock
);
372 if (list_empty(&cache_list
)) {
373 /* module must be being unloaded so its safe to kill the worker */
374 cancel_delayed_work_sync(&cache_cleaner
);
378 printk(KERN_ERR
"RPC: failed to unregister %s cache\n", cd
->name
);
380 EXPORT_SYMBOL_GPL(sunrpc_destroy_cache_detail
);
382 /* clean cache tries to find something to clean
384 * It returns 1 if it cleaned something,
385 * 0 if it didn't find anything this time
386 * -1 if it fell off the end of the list.
388 static int cache_clean(void)
391 struct list_head
*next
;
393 spin_lock(&cache_list_lock
);
395 /* find a suitable table if we don't already have one */
396 while (current_detail
== NULL
||
397 current_index
>= current_detail
->hash_size
) {
399 next
= current_detail
->others
.next
;
401 next
= cache_list
.next
;
402 if (next
== &cache_list
) {
403 current_detail
= NULL
;
404 spin_unlock(&cache_list_lock
);
407 current_detail
= list_entry(next
, struct cache_detail
, others
);
408 if (current_detail
->nextcheck
> seconds_since_boot())
409 current_index
= current_detail
->hash_size
;
412 current_detail
->nextcheck
= seconds_since_boot()+30*60;
416 /* find a non-empty bucket in the table */
417 while (current_detail
&&
418 current_index
< current_detail
->hash_size
&&
419 current_detail
->hash_table
[current_index
] == NULL
)
422 /* find a cleanable entry in the bucket and clean it, or set to next bucket */
424 if (current_detail
&& current_index
< current_detail
->hash_size
) {
425 struct cache_head
*ch
, **cp
;
426 struct cache_detail
*d
;
428 write_lock(¤t_detail
->hash_lock
);
430 /* Ok, now to clean this strand */
432 cp
= & current_detail
->hash_table
[current_index
];
433 for (ch
= *cp
; ch
; cp
= & ch
->next
, ch
= *cp
) {
434 if (current_detail
->nextcheck
> ch
->expiry_time
)
435 current_detail
->nextcheck
= ch
->expiry_time
+1;
436 if (!cache_is_expired(current_detail
, ch
))
441 current_detail
->entries
--;
446 write_unlock(¤t_detail
->hash_lock
);
450 spin_unlock(&cache_list_lock
);
452 set_bit(CACHE_CLEANED
, &ch
->flags
);
453 cache_fresh_unlocked(ch
, d
);
457 spin_unlock(&cache_list_lock
);
463 * We want to regularly clean the cache, so we need to schedule some work ...
465 static void do_cache_clean(struct work_struct
*work
)
468 if (cache_clean() == -1)
469 delay
= round_jiffies_relative(30*HZ
);
471 if (list_empty(&cache_list
))
475 schedule_delayed_work(&cache_cleaner
, delay
);
480 * Clean all caches promptly. This just calls cache_clean
481 * repeatedly until we are sure that every cache has had a chance to
484 void cache_flush(void)
486 while (cache_clean() != -1)
488 while (cache_clean() != -1)
491 EXPORT_SYMBOL_GPL(cache_flush
);
493 void cache_purge(struct cache_detail
*detail
)
495 detail
->flush_time
= LONG_MAX
;
496 detail
->nextcheck
= seconds_since_boot();
498 detail
->flush_time
= 1;
500 EXPORT_SYMBOL_GPL(cache_purge
);
504 * Deferral and Revisiting of Requests.
506 * If a cache lookup finds a pending entry, we
507 * need to defer the request and revisit it later.
508 * All deferred requests are stored in a hash table,
509 * indexed by "struct cache_head *".
510 * As it may be wasteful to store a whole request
511 * structure, we allow the request to provide a
512 * deferred form, which must contain a
513 * 'struct cache_deferred_req'
514 * This cache_deferred_req contains a method to allow
515 * it to be revisited when cache info is available
518 #define DFR_HASHSIZE (PAGE_SIZE/sizeof(struct list_head))
519 #define DFR_HASH(item) ((((long)item)>>4 ^ (((long)item)>>13)) % DFR_HASHSIZE)
521 #define DFR_MAX 300 /* ??? */
523 static DEFINE_SPINLOCK(cache_defer_lock
);
524 static LIST_HEAD(cache_defer_list
);
525 static struct hlist_head cache_defer_hash
[DFR_HASHSIZE
];
526 static int cache_defer_cnt
;
528 static void __unhash_deferred_req(struct cache_deferred_req
*dreq
)
530 hlist_del_init(&dreq
->hash
);
531 if (!list_empty(&dreq
->recent
)) {
532 list_del_init(&dreq
->recent
);
537 static void __hash_deferred_req(struct cache_deferred_req
*dreq
, struct cache_head
*item
)
539 int hash
= DFR_HASH(item
);
541 INIT_LIST_HEAD(&dreq
->recent
);
542 hlist_add_head(&dreq
->hash
, &cache_defer_hash
[hash
]);
545 static void setup_deferral(struct cache_deferred_req
*dreq
,
546 struct cache_head
*item
,
552 spin_lock(&cache_defer_lock
);
554 __hash_deferred_req(dreq
, item
);
558 list_add(&dreq
->recent
, &cache_defer_list
);
561 spin_unlock(&cache_defer_lock
);
565 struct thread_deferred_req
{
566 struct cache_deferred_req handle
;
567 struct completion completion
;
570 static void cache_restart_thread(struct cache_deferred_req
*dreq
, int too_many
)
572 struct thread_deferred_req
*dr
=
573 container_of(dreq
, struct thread_deferred_req
, handle
);
574 complete(&dr
->completion
);
577 static void cache_wait_req(struct cache_req
*req
, struct cache_head
*item
)
579 struct thread_deferred_req sleeper
;
580 struct cache_deferred_req
*dreq
= &sleeper
.handle
;
582 sleeper
.completion
= COMPLETION_INITIALIZER_ONSTACK(sleeper
.completion
);
583 dreq
->revisit
= cache_restart_thread
;
585 setup_deferral(dreq
, item
, 0);
587 if (!test_bit(CACHE_PENDING
, &item
->flags
) ||
588 wait_for_completion_interruptible_timeout(
589 &sleeper
.completion
, req
->thread_wait
) <= 0) {
590 /* The completion wasn't completed, so we need
593 spin_lock(&cache_defer_lock
);
594 if (!hlist_unhashed(&sleeper
.handle
.hash
)) {
595 __unhash_deferred_req(&sleeper
.handle
);
596 spin_unlock(&cache_defer_lock
);
598 /* cache_revisit_request already removed
599 * this from the hash table, but hasn't
600 * called ->revisit yet. It will very soon
601 * and we need to wait for it.
603 spin_unlock(&cache_defer_lock
);
604 wait_for_completion(&sleeper
.completion
);
609 static void cache_limit_defers(void)
611 /* Make sure we haven't exceed the limit of allowed deferred
614 struct cache_deferred_req
*discard
= NULL
;
616 if (cache_defer_cnt
<= DFR_MAX
)
619 spin_lock(&cache_defer_lock
);
621 /* Consider removing either the first or the last */
622 if (cache_defer_cnt
> DFR_MAX
) {
623 if (prandom_u32() & 1)
624 discard
= list_entry(cache_defer_list
.next
,
625 struct cache_deferred_req
, recent
);
627 discard
= list_entry(cache_defer_list
.prev
,
628 struct cache_deferred_req
, recent
);
629 __unhash_deferred_req(discard
);
631 spin_unlock(&cache_defer_lock
);
633 discard
->revisit(discard
, 1);
636 /* Return true if and only if a deferred request is queued. */
637 static bool cache_defer_req(struct cache_req
*req
, struct cache_head
*item
)
639 struct cache_deferred_req
*dreq
;
641 if (req
->thread_wait
) {
642 cache_wait_req(req
, item
);
643 if (!test_bit(CACHE_PENDING
, &item
->flags
))
646 dreq
= req
->defer(req
);
649 setup_deferral(dreq
, item
, 1);
650 if (!test_bit(CACHE_PENDING
, &item
->flags
))
651 /* Bit could have been cleared before we managed to
652 * set up the deferral, so need to revisit just in case
654 cache_revisit_request(item
);
656 cache_limit_defers();
660 static void cache_revisit_request(struct cache_head
*item
)
662 struct cache_deferred_req
*dreq
;
663 struct list_head pending
;
664 struct hlist_node
*tmp
;
665 int hash
= DFR_HASH(item
);
667 INIT_LIST_HEAD(&pending
);
668 spin_lock(&cache_defer_lock
);
670 hlist_for_each_entry_safe(dreq
, tmp
, &cache_defer_hash
[hash
], hash
)
671 if (dreq
->item
== item
) {
672 __unhash_deferred_req(dreq
);
673 list_add(&dreq
->recent
, &pending
);
676 spin_unlock(&cache_defer_lock
);
678 while (!list_empty(&pending
)) {
679 dreq
= list_entry(pending
.next
, struct cache_deferred_req
, recent
);
680 list_del_init(&dreq
->recent
);
681 dreq
->revisit(dreq
, 0);
685 void cache_clean_deferred(void *owner
)
687 struct cache_deferred_req
*dreq
, *tmp
;
688 struct list_head pending
;
691 INIT_LIST_HEAD(&pending
);
692 spin_lock(&cache_defer_lock
);
694 list_for_each_entry_safe(dreq
, tmp
, &cache_defer_list
, recent
) {
695 if (dreq
->owner
== owner
) {
696 __unhash_deferred_req(dreq
);
697 list_add(&dreq
->recent
, &pending
);
700 spin_unlock(&cache_defer_lock
);
702 while (!list_empty(&pending
)) {
703 dreq
= list_entry(pending
.next
, struct cache_deferred_req
, recent
);
704 list_del_init(&dreq
->recent
);
705 dreq
->revisit(dreq
, 1);
710 * communicate with user-space
712 * We have a magic /proc file - /proc/sunrpc/<cachename>/channel.
713 * On read, you get a full request, or block.
714 * On write, an update request is processed.
715 * Poll works if anything to read, and always allows write.
717 * Implemented by linked list of requests. Each open file has
718 * a ->private that also exists in this list. New requests are added
719 * to the end and may wakeup and preceding readers.
720 * New readers are added to the head. If, on read, an item is found with
721 * CACHE_UPCALLING clear, we free it from the list.
725 static DEFINE_SPINLOCK(queue_lock
);
726 static DEFINE_MUTEX(queue_io_mutex
);
729 struct list_head list
;
730 int reader
; /* if 0, then request */
732 struct cache_request
{
733 struct cache_queue q
;
734 struct cache_head
*item
;
739 struct cache_reader
{
740 struct cache_queue q
;
741 int offset
; /* if non-0, we have a refcnt on next request */
744 static int cache_request(struct cache_detail
*detail
,
745 struct cache_request
*crq
)
750 detail
->cache_request(detail
, crq
->item
, &bp
, &len
);
753 return PAGE_SIZE
- len
;
756 static ssize_t
cache_read(struct file
*filp
, char __user
*buf
, size_t count
,
757 loff_t
*ppos
, struct cache_detail
*cd
)
759 struct cache_reader
*rp
= filp
->private_data
;
760 struct cache_request
*rq
;
761 struct inode
*inode
= file_inode(filp
);
767 mutex_lock(&inode
->i_mutex
); /* protect against multiple concurrent
768 * readers on this file */
770 spin_lock(&queue_lock
);
771 /* need to find next request */
772 while (rp
->q
.list
.next
!= &cd
->queue
&&
773 list_entry(rp
->q
.list
.next
, struct cache_queue
, list
)
775 struct list_head
*next
= rp
->q
.list
.next
;
776 list_move(&rp
->q
.list
, next
);
778 if (rp
->q
.list
.next
== &cd
->queue
) {
779 spin_unlock(&queue_lock
);
780 mutex_unlock(&inode
->i_mutex
);
781 WARN_ON_ONCE(rp
->offset
);
784 rq
= container_of(rp
->q
.list
.next
, struct cache_request
, q
.list
);
785 WARN_ON_ONCE(rq
->q
.reader
);
788 spin_unlock(&queue_lock
);
791 err
= cache_request(cd
, rq
);
797 if (rp
->offset
== 0 && !test_bit(CACHE_PENDING
, &rq
->item
->flags
)) {
799 spin_lock(&queue_lock
);
800 list_move(&rp
->q
.list
, &rq
->q
.list
);
801 spin_unlock(&queue_lock
);
803 if (rp
->offset
+ count
> rq
->len
)
804 count
= rq
->len
- rp
->offset
;
806 if (copy_to_user(buf
, rq
->buf
+ rp
->offset
, count
))
809 if (rp
->offset
>= rq
->len
) {
811 spin_lock(&queue_lock
);
812 list_move(&rp
->q
.list
, &rq
->q
.list
);
813 spin_unlock(&queue_lock
);
818 if (rp
->offset
== 0) {
819 /* need to release rq */
820 spin_lock(&queue_lock
);
822 if (rq
->readers
== 0 &&
823 !test_bit(CACHE_PENDING
, &rq
->item
->flags
)) {
824 list_del(&rq
->q
.list
);
825 spin_unlock(&queue_lock
);
826 cache_put(rq
->item
, cd
);
830 spin_unlock(&queue_lock
);
834 mutex_unlock(&inode
->i_mutex
);
835 return err
? err
: count
;
838 static ssize_t
cache_do_downcall(char *kaddr
, const char __user
*buf
,
839 size_t count
, struct cache_detail
*cd
)
845 if (copy_from_user(kaddr
, buf
, count
))
848 ret
= cd
->cache_parse(cd
, kaddr
, count
);
854 static ssize_t
cache_slow_downcall(const char __user
*buf
,
855 size_t count
, struct cache_detail
*cd
)
857 static char write_buf
[8192]; /* protected by queue_io_mutex */
858 ssize_t ret
= -EINVAL
;
860 if (count
>= sizeof(write_buf
))
862 mutex_lock(&queue_io_mutex
);
863 ret
= cache_do_downcall(write_buf
, buf
, count
, cd
);
864 mutex_unlock(&queue_io_mutex
);
869 static ssize_t
cache_downcall(struct address_space
*mapping
,
870 const char __user
*buf
,
871 size_t count
, struct cache_detail
*cd
)
875 ssize_t ret
= -ENOMEM
;
877 if (count
>= PAGE_CACHE_SIZE
)
880 page
= find_or_create_page(mapping
, 0, GFP_KERNEL
);
885 ret
= cache_do_downcall(kaddr
, buf
, count
, cd
);
888 page_cache_release(page
);
891 return cache_slow_downcall(buf
, count
, cd
);
894 static ssize_t
cache_write(struct file
*filp
, const char __user
*buf
,
895 size_t count
, loff_t
*ppos
,
896 struct cache_detail
*cd
)
898 struct address_space
*mapping
= filp
->f_mapping
;
899 struct inode
*inode
= file_inode(filp
);
900 ssize_t ret
= -EINVAL
;
902 if (!cd
->cache_parse
)
905 mutex_lock(&inode
->i_mutex
);
906 ret
= cache_downcall(mapping
, buf
, count
, cd
);
907 mutex_unlock(&inode
->i_mutex
);
912 static DECLARE_WAIT_QUEUE_HEAD(queue_wait
);
914 static unsigned int cache_poll(struct file
*filp
, poll_table
*wait
,
915 struct cache_detail
*cd
)
918 struct cache_reader
*rp
= filp
->private_data
;
919 struct cache_queue
*cq
;
921 poll_wait(filp
, &queue_wait
, wait
);
923 /* alway allow write */
924 mask
= POLLOUT
| POLLWRNORM
;
929 spin_lock(&queue_lock
);
931 for (cq
= &rp
->q
; &cq
->list
!= &cd
->queue
;
932 cq
= list_entry(cq
->list
.next
, struct cache_queue
, list
))
934 mask
|= POLLIN
| POLLRDNORM
;
937 spin_unlock(&queue_lock
);
941 static int cache_ioctl(struct inode
*ino
, struct file
*filp
,
942 unsigned int cmd
, unsigned long arg
,
943 struct cache_detail
*cd
)
946 struct cache_reader
*rp
= filp
->private_data
;
947 struct cache_queue
*cq
;
949 if (cmd
!= FIONREAD
|| !rp
)
952 spin_lock(&queue_lock
);
954 /* only find the length remaining in current request,
955 * or the length of the next request
957 for (cq
= &rp
->q
; &cq
->list
!= &cd
->queue
;
958 cq
= list_entry(cq
->list
.next
, struct cache_queue
, list
))
960 struct cache_request
*cr
=
961 container_of(cq
, struct cache_request
, q
);
962 len
= cr
->len
- rp
->offset
;
965 spin_unlock(&queue_lock
);
967 return put_user(len
, (int __user
*)arg
);
970 static int cache_open(struct inode
*inode
, struct file
*filp
,
971 struct cache_detail
*cd
)
973 struct cache_reader
*rp
= NULL
;
975 if (!cd
|| !try_module_get(cd
->owner
))
977 nonseekable_open(inode
, filp
);
978 if (filp
->f_mode
& FMODE_READ
) {
979 rp
= kmalloc(sizeof(*rp
), GFP_KERNEL
);
981 module_put(cd
->owner
);
986 atomic_inc(&cd
->readers
);
987 spin_lock(&queue_lock
);
988 list_add(&rp
->q
.list
, &cd
->queue
);
989 spin_unlock(&queue_lock
);
991 filp
->private_data
= rp
;
995 static int cache_release(struct inode
*inode
, struct file
*filp
,
996 struct cache_detail
*cd
)
998 struct cache_reader
*rp
= filp
->private_data
;
1001 spin_lock(&queue_lock
);
1003 struct cache_queue
*cq
;
1004 for (cq
= &rp
->q
; &cq
->list
!= &cd
->queue
;
1005 cq
= list_entry(cq
->list
.next
, struct cache_queue
, list
))
1007 container_of(cq
, struct cache_request
, q
)
1013 list_del(&rp
->q
.list
);
1014 spin_unlock(&queue_lock
);
1016 filp
->private_data
= NULL
;
1019 cd
->last_close
= seconds_since_boot();
1020 atomic_dec(&cd
->readers
);
1022 module_put(cd
->owner
);
1028 static void cache_dequeue(struct cache_detail
*detail
, struct cache_head
*ch
)
1030 struct cache_queue
*cq
, *tmp
;
1031 struct cache_request
*cr
;
1032 struct list_head dequeued
;
1034 INIT_LIST_HEAD(&dequeued
);
1035 spin_lock(&queue_lock
);
1036 list_for_each_entry_safe(cq
, tmp
, &detail
->queue
, list
)
1038 cr
= container_of(cq
, struct cache_request
, q
);
1041 if (test_bit(CACHE_PENDING
, &ch
->flags
))
1042 /* Lost a race and it is pending again */
1044 if (cr
->readers
!= 0)
1046 list_move(&cr
->q
.list
, &dequeued
);
1048 spin_unlock(&queue_lock
);
1049 while (!list_empty(&dequeued
)) {
1050 cr
= list_entry(dequeued
.next
, struct cache_request
, q
.list
);
1051 list_del(&cr
->q
.list
);
1052 cache_put(cr
->item
, detail
);
1059 * Support routines for text-based upcalls.
1060 * Fields are separated by spaces.
1061 * Fields are either mangled to quote space tab newline slosh with slosh
1062 * or a hexified with a leading \x
1063 * Record is terminated with newline.
1067 void qword_add(char **bpp
, int *lp
, char *str
)
1073 if (len
< 0) return;
1075 ret
= string_escape_str(str
, bp
, len
, ESCAPE_OCTAL
, "\\ \n\t");
1088 EXPORT_SYMBOL_GPL(qword_add
);
1090 void qword_addhex(char **bpp
, int *lp
, char *buf
, int blen
)
1095 if (len
< 0) return;
1101 while (blen
&& len
>= 2) {
1102 bp
= hex_byte_pack(bp
, *buf
++);
1107 if (blen
|| len
<1) len
= -1;
1115 EXPORT_SYMBOL_GPL(qword_addhex
);
1117 static void warn_no_listener(struct cache_detail
*detail
)
1119 if (detail
->last_warn
!= detail
->last_close
) {
1120 detail
->last_warn
= detail
->last_close
;
1121 if (detail
->warn_no_listener
)
1122 detail
->warn_no_listener(detail
, detail
->last_close
!= 0);
1126 static bool cache_listeners_exist(struct cache_detail
*detail
)
1128 if (atomic_read(&detail
->readers
))
1130 if (detail
->last_close
== 0)
1131 /* This cache was never opened */
1133 if (detail
->last_close
< seconds_since_boot() - 30)
1135 * We allow for the possibility that someone might
1136 * restart a userspace daemon without restarting the
1137 * server; but after 30 seconds, we give up.
1144 * register an upcall request to user-space and queue it up for read() by the
1147 * Each request is at most one page long.
1149 int sunrpc_cache_pipe_upcall(struct cache_detail
*detail
, struct cache_head
*h
)
1153 struct cache_request
*crq
;
1156 if (!detail
->cache_request
)
1159 if (!cache_listeners_exist(detail
)) {
1160 warn_no_listener(detail
);
1163 if (test_bit(CACHE_CLEANED
, &h
->flags
))
1164 /* Too late to make an upcall */
1167 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1171 crq
= kmalloc(sizeof (*crq
), GFP_KERNEL
);
1178 crq
->item
= cache_get(h
);
1182 spin_lock(&queue_lock
);
1183 if (test_bit(CACHE_PENDING
, &h
->flags
))
1184 list_add_tail(&crq
->q
.list
, &detail
->queue
);
1186 /* Lost a race, no longer PENDING, so don't enqueue */
1188 spin_unlock(&queue_lock
);
1189 wake_up(&queue_wait
);
1190 if (ret
== -EAGAIN
) {
1196 EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall
);
1199 * parse a message from user-space and pass it
1200 * to an appropriate cache
1201 * Messages are, like requests, separated into fields by
1202 * spaces and dequotes as \xHEXSTRING or embedded \nnn octal
1205 * reply cachename expiry key ... content....
1207 * key and content are both parsed by cache
1210 int qword_get(char **bpp
, char *dest
, int bufsize
)
1212 /* return bytes copied, or -1 on error */
1216 while (*bp
== ' ') bp
++;
1218 if (bp
[0] == '\\' && bp
[1] == 'x') {
1221 while (len
< bufsize
) {
1224 h
= hex_to_bin(bp
[0]);
1228 l
= hex_to_bin(bp
[1]);
1232 *dest
++ = (h
<< 4) | l
;
1237 /* text with \nnn octal quoting */
1238 while (*bp
!= ' ' && *bp
!= '\n' && *bp
&& len
< bufsize
-1) {
1240 isodigit(bp
[1]) && (bp
[1] <= '3') &&
1243 int byte
= (*++bp
-'0');
1245 byte
= (byte
<< 3) | (*bp
++ - '0');
1246 byte
= (byte
<< 3) | (*bp
++ - '0');
1256 if (*bp
!= ' ' && *bp
!= '\n' && *bp
!= '\0')
1258 while (*bp
== ' ') bp
++;
1263 EXPORT_SYMBOL_GPL(qword_get
);
1267 * support /proc/sunrpc/cache/$CACHENAME/content
1269 * We call ->cache_show passing NULL for the item to
1270 * get a header, then pass each real item in the cache
1274 struct cache_detail
*cd
;
1277 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
1278 __acquires(cd
->hash_lock
)
1281 unsigned int hash
, entry
;
1282 struct cache_head
*ch
;
1283 struct cache_detail
*cd
= ((struct handle
*)m
->private)->cd
;
1286 read_lock(&cd
->hash_lock
);
1288 return SEQ_START_TOKEN
;
1290 entry
= n
& ((1LL<<32) - 1);
1292 for (ch
=cd
->hash_table
[hash
]; ch
; ch
=ch
->next
)
1295 n
&= ~((1LL<<32) - 1);
1299 } while(hash
< cd
->hash_size
&&
1300 cd
->hash_table
[hash
]==NULL
);
1301 if (hash
>= cd
->hash_size
)
1304 return cd
->hash_table
[hash
];
1307 static void *c_next(struct seq_file
*m
, void *p
, loff_t
*pos
)
1309 struct cache_head
*ch
= p
;
1310 int hash
= (*pos
>> 32);
1311 struct cache_detail
*cd
= ((struct handle
*)m
->private)->cd
;
1313 if (p
== SEQ_START_TOKEN
)
1315 else if (ch
->next
== NULL
) {
1322 *pos
&= ~((1LL<<32) - 1);
1323 while (hash
< cd
->hash_size
&&
1324 cd
->hash_table
[hash
] == NULL
) {
1328 if (hash
>= cd
->hash_size
)
1331 return cd
->hash_table
[hash
];
1334 static void c_stop(struct seq_file
*m
, void *p
)
1335 __releases(cd
->hash_lock
)
1337 struct cache_detail
*cd
= ((struct handle
*)m
->private)->cd
;
1338 read_unlock(&cd
->hash_lock
);
1341 static int c_show(struct seq_file
*m
, void *p
)
1343 struct cache_head
*cp
= p
;
1344 struct cache_detail
*cd
= ((struct handle
*)m
->private)->cd
;
1346 if (p
== SEQ_START_TOKEN
)
1347 return cd
->cache_show(m
, cd
, NULL
);
1350 seq_printf(m
, "# expiry=%ld refcnt=%d flags=%lx\n",
1351 convert_to_wallclock(cp
->expiry_time
),
1352 atomic_read(&cp
->ref
.refcount
), cp
->flags
);
1354 if (cache_check(cd
, cp
, NULL
))
1355 /* cache_check does a cache_put on failure */
1356 seq_printf(m
, "# ");
1358 if (cache_is_expired(cd
, cp
))
1359 seq_printf(m
, "# ");
1363 return cd
->cache_show(m
, cd
, cp
);
1366 static const struct seq_operations cache_content_op
= {
1373 static int content_open(struct inode
*inode
, struct file
*file
,
1374 struct cache_detail
*cd
)
1378 if (!cd
|| !try_module_get(cd
->owner
))
1380 han
= __seq_open_private(file
, &cache_content_op
, sizeof(*han
));
1382 module_put(cd
->owner
);
1390 static int content_release(struct inode
*inode
, struct file
*file
,
1391 struct cache_detail
*cd
)
1393 int ret
= seq_release_private(inode
, file
);
1394 module_put(cd
->owner
);
1398 static int open_flush(struct inode
*inode
, struct file
*file
,
1399 struct cache_detail
*cd
)
1401 if (!cd
|| !try_module_get(cd
->owner
))
1403 return nonseekable_open(inode
, file
);
1406 static int release_flush(struct inode
*inode
, struct file
*file
,
1407 struct cache_detail
*cd
)
1409 module_put(cd
->owner
);
1413 static ssize_t
read_flush(struct file
*file
, char __user
*buf
,
1414 size_t count
, loff_t
*ppos
,
1415 struct cache_detail
*cd
)
1418 unsigned long p
= *ppos
;
1421 snprintf(tbuf
, sizeof(tbuf
), "%lu\n", convert_to_wallclock(cd
->flush_time
));
1428 if (copy_to_user(buf
, (void*)(tbuf
+p
), len
))
1434 static ssize_t
write_flush(struct file
*file
, const char __user
*buf
,
1435 size_t count
, loff_t
*ppos
,
1436 struct cache_detail
*cd
)
1441 if (*ppos
|| count
> sizeof(tbuf
)-1)
1443 if (copy_from_user(tbuf
, buf
, count
))
1446 simple_strtoul(tbuf
, &ep
, 0);
1447 if (*ep
&& *ep
!= '\n')
1451 cd
->flush_time
= get_expiry(&bp
);
1452 cd
->nextcheck
= seconds_since_boot();
1459 static ssize_t
cache_read_procfs(struct file
*filp
, char __user
*buf
,
1460 size_t count
, loff_t
*ppos
)
1462 struct cache_detail
*cd
= PDE_DATA(file_inode(filp
));
1464 return cache_read(filp
, buf
, count
, ppos
, cd
);
1467 static ssize_t
cache_write_procfs(struct file
*filp
, const char __user
*buf
,
1468 size_t count
, loff_t
*ppos
)
1470 struct cache_detail
*cd
= PDE_DATA(file_inode(filp
));
1472 return cache_write(filp
, buf
, count
, ppos
, cd
);
1475 static unsigned int cache_poll_procfs(struct file
*filp
, poll_table
*wait
)
1477 struct cache_detail
*cd
= PDE_DATA(file_inode(filp
));
1479 return cache_poll(filp
, wait
, cd
);
1482 static long cache_ioctl_procfs(struct file
*filp
,
1483 unsigned int cmd
, unsigned long arg
)
1485 struct inode
*inode
= file_inode(filp
);
1486 struct cache_detail
*cd
= PDE_DATA(inode
);
1488 return cache_ioctl(inode
, filp
, cmd
, arg
, cd
);
1491 static int cache_open_procfs(struct inode
*inode
, struct file
*filp
)
1493 struct cache_detail
*cd
= PDE_DATA(inode
);
1495 return cache_open(inode
, filp
, cd
);
1498 static int cache_release_procfs(struct inode
*inode
, struct file
*filp
)
1500 struct cache_detail
*cd
= PDE_DATA(inode
);
1502 return cache_release(inode
, filp
, cd
);
1505 static const struct file_operations cache_file_operations_procfs
= {
1506 .owner
= THIS_MODULE
,
1507 .llseek
= no_llseek
,
1508 .read
= cache_read_procfs
,
1509 .write
= cache_write_procfs
,
1510 .poll
= cache_poll_procfs
,
1511 .unlocked_ioctl
= cache_ioctl_procfs
, /* for FIONREAD */
1512 .open
= cache_open_procfs
,
1513 .release
= cache_release_procfs
,
1516 static int content_open_procfs(struct inode
*inode
, struct file
*filp
)
1518 struct cache_detail
*cd
= PDE_DATA(inode
);
1520 return content_open(inode
, filp
, cd
);
1523 static int content_release_procfs(struct inode
*inode
, struct file
*filp
)
1525 struct cache_detail
*cd
= PDE_DATA(inode
);
1527 return content_release(inode
, filp
, cd
);
1530 static const struct file_operations content_file_operations_procfs
= {
1531 .open
= content_open_procfs
,
1533 .llseek
= seq_lseek
,
1534 .release
= content_release_procfs
,
1537 static int open_flush_procfs(struct inode
*inode
, struct file
*filp
)
1539 struct cache_detail
*cd
= PDE_DATA(inode
);
1541 return open_flush(inode
, filp
, cd
);
1544 static int release_flush_procfs(struct inode
*inode
, struct file
*filp
)
1546 struct cache_detail
*cd
= PDE_DATA(inode
);
1548 return release_flush(inode
, filp
, cd
);
1551 static ssize_t
read_flush_procfs(struct file
*filp
, char __user
*buf
,
1552 size_t count
, loff_t
*ppos
)
1554 struct cache_detail
*cd
= PDE_DATA(file_inode(filp
));
1556 return read_flush(filp
, buf
, count
, ppos
, cd
);
1559 static ssize_t
write_flush_procfs(struct file
*filp
,
1560 const char __user
*buf
,
1561 size_t count
, loff_t
*ppos
)
1563 struct cache_detail
*cd
= PDE_DATA(file_inode(filp
));
1565 return write_flush(filp
, buf
, count
, ppos
, cd
);
1568 static const struct file_operations cache_flush_operations_procfs
= {
1569 .open
= open_flush_procfs
,
1570 .read
= read_flush_procfs
,
1571 .write
= write_flush_procfs
,
1572 .release
= release_flush_procfs
,
1573 .llseek
= no_llseek
,
1576 static void remove_cache_proc_entries(struct cache_detail
*cd
, struct net
*net
)
1578 struct sunrpc_net
*sn
;
1580 if (cd
->u
.procfs
.proc_ent
== NULL
)
1582 if (cd
->u
.procfs
.flush_ent
)
1583 remove_proc_entry("flush", cd
->u
.procfs
.proc_ent
);
1584 if (cd
->u
.procfs
.channel_ent
)
1585 remove_proc_entry("channel", cd
->u
.procfs
.proc_ent
);
1586 if (cd
->u
.procfs
.content_ent
)
1587 remove_proc_entry("content", cd
->u
.procfs
.proc_ent
);
1588 cd
->u
.procfs
.proc_ent
= NULL
;
1589 sn
= net_generic(net
, sunrpc_net_id
);
1590 remove_proc_entry(cd
->name
, sn
->proc_net_rpc
);
1593 #ifdef CONFIG_PROC_FS
1594 static int create_cache_proc_entries(struct cache_detail
*cd
, struct net
*net
)
1596 struct proc_dir_entry
*p
;
1597 struct sunrpc_net
*sn
;
1599 sn
= net_generic(net
, sunrpc_net_id
);
1600 cd
->u
.procfs
.proc_ent
= proc_mkdir(cd
->name
, sn
->proc_net_rpc
);
1601 if (cd
->u
.procfs
.proc_ent
== NULL
)
1603 cd
->u
.procfs
.channel_ent
= NULL
;
1604 cd
->u
.procfs
.content_ent
= NULL
;
1606 p
= proc_create_data("flush", S_IFREG
|S_IRUSR
|S_IWUSR
,
1607 cd
->u
.procfs
.proc_ent
,
1608 &cache_flush_operations_procfs
, cd
);
1609 cd
->u
.procfs
.flush_ent
= p
;
1613 if (cd
->cache_request
|| cd
->cache_parse
) {
1614 p
= proc_create_data("channel", S_IFREG
|S_IRUSR
|S_IWUSR
,
1615 cd
->u
.procfs
.proc_ent
,
1616 &cache_file_operations_procfs
, cd
);
1617 cd
->u
.procfs
.channel_ent
= p
;
1621 if (cd
->cache_show
) {
1622 p
= proc_create_data("content", S_IFREG
|S_IRUSR
,
1623 cd
->u
.procfs
.proc_ent
,
1624 &content_file_operations_procfs
, cd
);
1625 cd
->u
.procfs
.content_ent
= p
;
1631 remove_cache_proc_entries(cd
, net
);
1634 #else /* CONFIG_PROC_FS */
1635 static int create_cache_proc_entries(struct cache_detail
*cd
, struct net
*net
)
1641 void __init
cache_initialize(void)
1643 INIT_DEFERRABLE_WORK(&cache_cleaner
, do_cache_clean
);
1646 int cache_register_net(struct cache_detail
*cd
, struct net
*net
)
1650 sunrpc_init_cache_detail(cd
);
1651 ret
= create_cache_proc_entries(cd
, net
);
1653 sunrpc_destroy_cache_detail(cd
);
1656 EXPORT_SYMBOL_GPL(cache_register_net
);
1658 void cache_unregister_net(struct cache_detail
*cd
, struct net
*net
)
1660 remove_cache_proc_entries(cd
, net
);
1661 sunrpc_destroy_cache_detail(cd
);
1663 EXPORT_SYMBOL_GPL(cache_unregister_net
);
1665 struct cache_detail
*cache_create_net(struct cache_detail
*tmpl
, struct net
*net
)
1667 struct cache_detail
*cd
;
1669 cd
= kmemdup(tmpl
, sizeof(struct cache_detail
), GFP_KERNEL
);
1671 return ERR_PTR(-ENOMEM
);
1673 cd
->hash_table
= kzalloc(cd
->hash_size
* sizeof(struct cache_head
*),
1675 if (cd
->hash_table
== NULL
) {
1677 return ERR_PTR(-ENOMEM
);
1682 EXPORT_SYMBOL_GPL(cache_create_net
);
1684 void cache_destroy_net(struct cache_detail
*cd
, struct net
*net
)
1686 kfree(cd
->hash_table
);
1689 EXPORT_SYMBOL_GPL(cache_destroy_net
);
1691 static ssize_t
cache_read_pipefs(struct file
*filp
, char __user
*buf
,
1692 size_t count
, loff_t
*ppos
)
1694 struct cache_detail
*cd
= RPC_I(file_inode(filp
))->private;
1696 return cache_read(filp
, buf
, count
, ppos
, cd
);
1699 static ssize_t
cache_write_pipefs(struct file
*filp
, const char __user
*buf
,
1700 size_t count
, loff_t
*ppos
)
1702 struct cache_detail
*cd
= RPC_I(file_inode(filp
))->private;
1704 return cache_write(filp
, buf
, count
, ppos
, cd
);
1707 static unsigned int cache_poll_pipefs(struct file
*filp
, poll_table
*wait
)
1709 struct cache_detail
*cd
= RPC_I(file_inode(filp
))->private;
1711 return cache_poll(filp
, wait
, cd
);
1714 static long cache_ioctl_pipefs(struct file
*filp
,
1715 unsigned int cmd
, unsigned long arg
)
1717 struct inode
*inode
= file_inode(filp
);
1718 struct cache_detail
*cd
= RPC_I(inode
)->private;
1720 return cache_ioctl(inode
, filp
, cmd
, arg
, cd
);
1723 static int cache_open_pipefs(struct inode
*inode
, struct file
*filp
)
1725 struct cache_detail
*cd
= RPC_I(inode
)->private;
1727 return cache_open(inode
, filp
, cd
);
1730 static int cache_release_pipefs(struct inode
*inode
, struct file
*filp
)
1732 struct cache_detail
*cd
= RPC_I(inode
)->private;
1734 return cache_release(inode
, filp
, cd
);
1737 const struct file_operations cache_file_operations_pipefs
= {
1738 .owner
= THIS_MODULE
,
1739 .llseek
= no_llseek
,
1740 .read
= cache_read_pipefs
,
1741 .write
= cache_write_pipefs
,
1742 .poll
= cache_poll_pipefs
,
1743 .unlocked_ioctl
= cache_ioctl_pipefs
, /* for FIONREAD */
1744 .open
= cache_open_pipefs
,
1745 .release
= cache_release_pipefs
,
1748 static int content_open_pipefs(struct inode
*inode
, struct file
*filp
)
1750 struct cache_detail
*cd
= RPC_I(inode
)->private;
1752 return content_open(inode
, filp
, cd
);
1755 static int content_release_pipefs(struct inode
*inode
, struct file
*filp
)
1757 struct cache_detail
*cd
= RPC_I(inode
)->private;
1759 return content_release(inode
, filp
, cd
);
1762 const struct file_operations content_file_operations_pipefs
= {
1763 .open
= content_open_pipefs
,
1765 .llseek
= seq_lseek
,
1766 .release
= content_release_pipefs
,
1769 static int open_flush_pipefs(struct inode
*inode
, struct file
*filp
)
1771 struct cache_detail
*cd
= RPC_I(inode
)->private;
1773 return open_flush(inode
, filp
, cd
);
1776 static int release_flush_pipefs(struct inode
*inode
, struct file
*filp
)
1778 struct cache_detail
*cd
= RPC_I(inode
)->private;
1780 return release_flush(inode
, filp
, cd
);
1783 static ssize_t
read_flush_pipefs(struct file
*filp
, char __user
*buf
,
1784 size_t count
, loff_t
*ppos
)
1786 struct cache_detail
*cd
= RPC_I(file_inode(filp
))->private;
1788 return read_flush(filp
, buf
, count
, ppos
, cd
);
1791 static ssize_t
write_flush_pipefs(struct file
*filp
,
1792 const char __user
*buf
,
1793 size_t count
, loff_t
*ppos
)
1795 struct cache_detail
*cd
= RPC_I(file_inode(filp
))->private;
1797 return write_flush(filp
, buf
, count
, ppos
, cd
);
1800 const struct file_operations cache_flush_operations_pipefs
= {
1801 .open
= open_flush_pipefs
,
1802 .read
= read_flush_pipefs
,
1803 .write
= write_flush_pipefs
,
1804 .release
= release_flush_pipefs
,
1805 .llseek
= no_llseek
,
1808 int sunrpc_cache_register_pipefs(struct dentry
*parent
,
1809 const char *name
, umode_t umode
,
1810 struct cache_detail
*cd
)
1812 struct dentry
*dir
= rpc_create_cache_dir(parent
, name
, umode
, cd
);
1814 return PTR_ERR(dir
);
1815 cd
->u
.pipefs
.dir
= dir
;
1818 EXPORT_SYMBOL_GPL(sunrpc_cache_register_pipefs
);
1820 void sunrpc_cache_unregister_pipefs(struct cache_detail
*cd
)
1822 rpc_remove_cache_dir(cd
->u
.pipefs
.dir
);
1823 cd
->u
.pipefs
.dir
= NULL
;
1825 EXPORT_SYMBOL_GPL(sunrpc_cache_unregister_pipefs
);