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 <asm/uaccess.h>
24 #include <linux/poll.h>
25 #include <linux/seq_file.h>
26 #include <linux/proc_fs.h>
27 #include <linux/net.h>
28 #include <linux/workqueue.h>
29 #include <linux/mutex.h>
30 #include <linux/pagemap.h>
31 #include <asm/ioctls.h>
32 #include <linux/sunrpc/types.h>
33 #include <linux/sunrpc/cache.h>
34 #include <linux/sunrpc/stats.h>
35 #include <linux/sunrpc/rpc_pipe_fs.h>
38 #define RPCDBG_FACILITY RPCDBG_CACHE
40 static void cache_defer_req(struct cache_req
*req
, struct cache_head
*item
);
41 static void cache_revisit_request(struct cache_head
*item
);
43 static void cache_init(struct cache_head
*h
)
45 time_t now
= seconds_since_boot();
49 h
->expiry_time
= now
+ CACHE_NEW_EXPIRY
;
50 h
->last_refresh
= now
;
53 static inline int cache_is_expired(struct cache_detail
*detail
, struct cache_head
*h
)
55 return (h
->expiry_time
< seconds_since_boot()) ||
56 (detail
->flush_time
> h
->last_refresh
);
59 struct cache_head
*sunrpc_cache_lookup(struct cache_detail
*detail
,
60 struct cache_head
*key
, int hash
)
62 struct cache_head
**head
, **hp
;
63 struct cache_head
*new = NULL
, *freeme
= NULL
;
65 head
= &detail
->hash_table
[hash
];
67 read_lock(&detail
->hash_lock
);
69 for (hp
=head
; *hp
!= NULL
; hp
= &(*hp
)->next
) {
70 struct cache_head
*tmp
= *hp
;
71 if (detail
->match(tmp
, key
)) {
72 if (cache_is_expired(detail
, tmp
))
73 /* This entry is expired, we will discard it. */
76 read_unlock(&detail
->hash_lock
);
80 read_unlock(&detail
->hash_lock
);
81 /* Didn't find anything, insert an empty entry */
83 new = detail
->alloc();
86 /* must fully initialise 'new', else
87 * we might get lose if we need to
91 detail
->init(new, key
);
93 write_lock(&detail
->hash_lock
);
95 /* check if entry appeared while we slept */
96 for (hp
=head
; *hp
!= NULL
; hp
= &(*hp
)->next
) {
97 struct cache_head
*tmp
= *hp
;
98 if (detail
->match(tmp
, key
)) {
99 if (cache_is_expired(detail
, tmp
)) {
107 write_unlock(&detail
->hash_lock
);
108 cache_put(new, detail
);
116 write_unlock(&detail
->hash_lock
);
119 cache_put(freeme
, detail
);
122 EXPORT_SYMBOL_GPL(sunrpc_cache_lookup
);
125 static void cache_dequeue(struct cache_detail
*detail
, struct cache_head
*ch
);
127 static void cache_fresh_locked(struct cache_head
*head
, time_t expiry
)
129 head
->expiry_time
= expiry
;
130 head
->last_refresh
= seconds_since_boot();
131 set_bit(CACHE_VALID
, &head
->flags
);
134 static void cache_fresh_unlocked(struct cache_head
*head
,
135 struct cache_detail
*detail
)
137 if (test_and_clear_bit(CACHE_PENDING
, &head
->flags
)) {
138 cache_revisit_request(head
);
139 cache_dequeue(detail
, head
);
143 struct cache_head
*sunrpc_cache_update(struct cache_detail
*detail
,
144 struct cache_head
*new, struct cache_head
*old
, int hash
)
146 /* The 'old' entry is to be replaced by 'new'.
147 * If 'old' is not VALID, we update it directly,
148 * otherwise we need to replace it
150 struct cache_head
**head
;
151 struct cache_head
*tmp
;
153 if (!test_bit(CACHE_VALID
, &old
->flags
)) {
154 write_lock(&detail
->hash_lock
);
155 if (!test_bit(CACHE_VALID
, &old
->flags
)) {
156 if (test_bit(CACHE_NEGATIVE
, &new->flags
))
157 set_bit(CACHE_NEGATIVE
, &old
->flags
);
159 detail
->update(old
, new);
160 cache_fresh_locked(old
, new->expiry_time
);
161 write_unlock(&detail
->hash_lock
);
162 cache_fresh_unlocked(old
, detail
);
165 write_unlock(&detail
->hash_lock
);
167 /* We need to insert a new entry */
168 tmp
= detail
->alloc();
170 cache_put(old
, detail
);
174 detail
->init(tmp
, old
);
175 head
= &detail
->hash_table
[hash
];
177 write_lock(&detail
->hash_lock
);
178 if (test_bit(CACHE_NEGATIVE
, &new->flags
))
179 set_bit(CACHE_NEGATIVE
, &tmp
->flags
);
181 detail
->update(tmp
, new);
186 cache_fresh_locked(tmp
, new->expiry_time
);
187 cache_fresh_locked(old
, 0);
188 write_unlock(&detail
->hash_lock
);
189 cache_fresh_unlocked(tmp
, detail
);
190 cache_fresh_unlocked(old
, detail
);
191 cache_put(old
, detail
);
194 EXPORT_SYMBOL_GPL(sunrpc_cache_update
);
196 static int cache_make_upcall(struct cache_detail
*cd
, struct cache_head
*h
)
198 if (!cd
->cache_upcall
)
200 return cd
->cache_upcall(cd
, h
);
203 static inline int cache_is_valid(struct cache_detail
*detail
, struct cache_head
*h
)
205 if (!test_bit(CACHE_VALID
, &h
->flags
))
209 if (test_bit(CACHE_NEGATIVE
, &h
->flags
))
217 * This is the generic cache management routine for all
218 * the authentication caches.
219 * It checks the currency of a cache item and will (later)
220 * initiate an upcall to fill it if needed.
223 * Returns 0 if the cache_head can be used, or cache_puts it and returns
224 * -EAGAIN if upcall is pending and request has been queued
225 * -ETIMEDOUT if upcall failed or request could not be queue or
226 * upcall completed but item is still invalid (implying that
227 * the cache item has been replaced with a newer one).
228 * -ENOENT if cache entry was negative
230 int cache_check(struct cache_detail
*detail
,
231 struct cache_head
*h
, struct cache_req
*rqstp
)
234 long refresh_age
, age
;
236 /* First decide return status as best we can */
237 rv
= cache_is_valid(detail
, h
);
239 /* now see if we want to start an upcall */
240 refresh_age
= (h
->expiry_time
- h
->last_refresh
);
241 age
= seconds_since_boot() - h
->last_refresh
;
246 } else if (rv
== -EAGAIN
|| age
> refresh_age
/2) {
247 dprintk("RPC: Want update, refage=%ld, age=%ld\n",
249 if (!test_and_set_bit(CACHE_PENDING
, &h
->flags
)) {
250 switch (cache_make_upcall(detail
, h
)) {
252 clear_bit(CACHE_PENDING
, &h
->flags
);
253 cache_revisit_request(h
);
255 set_bit(CACHE_NEGATIVE
, &h
->flags
);
256 cache_fresh_locked(h
, seconds_since_boot()+CACHE_NEW_EXPIRY
);
257 cache_fresh_unlocked(h
, detail
);
263 clear_bit(CACHE_PENDING
, &h
->flags
);
264 cache_revisit_request(h
);
271 cache_defer_req(rqstp
, h
);
272 if (!test_bit(CACHE_PENDING
, &h
->flags
)) {
273 /* Request is not deferred */
274 rv
= cache_is_valid(detail
, h
);
280 cache_put(h
, detail
);
283 EXPORT_SYMBOL_GPL(cache_check
);
286 * caches need to be periodically cleaned.
287 * For this we maintain a list of cache_detail and
288 * a current pointer into that list and into the table
291 * Each time clean_cache is called it finds the next non-empty entry
292 * in the current table and walks the list in that entry
293 * looking for entries that can be removed.
295 * An entry gets removed if:
296 * - The expiry is before current time
297 * - The last_refresh time is before the flush_time for that cache
299 * later we might drop old entries with non-NEVER expiry if that table
300 * is getting 'full' for some definition of 'full'
302 * The question of "how often to scan a table" is an interesting one
303 * and is answered in part by the use of the "nextcheck" field in the
305 * When a scan of a table begins, the nextcheck field is set to a time
306 * that is well into the future.
307 * While scanning, if an expiry time is found that is earlier than the
308 * current nextcheck time, nextcheck is set to that expiry time.
309 * If the flush_time is ever set to a time earlier than the nextcheck
310 * time, the nextcheck time is then set to that flush_time.
312 * A table is then only scanned if the current time is at least
313 * the nextcheck time.
317 static LIST_HEAD(cache_list
);
318 static DEFINE_SPINLOCK(cache_list_lock
);
319 static struct cache_detail
*current_detail
;
320 static int current_index
;
322 static void do_cache_clean(struct work_struct
*work
);
323 static struct delayed_work cache_cleaner
;
325 static void sunrpc_init_cache_detail(struct cache_detail
*cd
)
327 rwlock_init(&cd
->hash_lock
);
328 INIT_LIST_HEAD(&cd
->queue
);
329 spin_lock(&cache_list_lock
);
332 atomic_set(&cd
->readers
, 0);
335 list_add(&cd
->others
, &cache_list
);
336 spin_unlock(&cache_list_lock
);
338 /* start the cleaning process */
339 schedule_delayed_work(&cache_cleaner
, 0);
342 static void sunrpc_destroy_cache_detail(struct cache_detail
*cd
)
345 spin_lock(&cache_list_lock
);
346 write_lock(&cd
->hash_lock
);
347 if (cd
->entries
|| atomic_read(&cd
->inuse
)) {
348 write_unlock(&cd
->hash_lock
);
349 spin_unlock(&cache_list_lock
);
352 if (current_detail
== cd
)
353 current_detail
= NULL
;
354 list_del_init(&cd
->others
);
355 write_unlock(&cd
->hash_lock
);
356 spin_unlock(&cache_list_lock
);
357 if (list_empty(&cache_list
)) {
358 /* module must be being unloaded so its safe to kill the worker */
359 cancel_delayed_work_sync(&cache_cleaner
);
363 printk(KERN_ERR
"nfsd: failed to unregister %s cache\n", cd
->name
);
366 /* clean cache tries to find something to clean
368 * It returns 1 if it cleaned something,
369 * 0 if it didn't find anything this time
370 * -1 if it fell off the end of the list.
372 static int cache_clean(void)
375 struct list_head
*next
;
377 spin_lock(&cache_list_lock
);
379 /* find a suitable table if we don't already have one */
380 while (current_detail
== NULL
||
381 current_index
>= current_detail
->hash_size
) {
383 next
= current_detail
->others
.next
;
385 next
= cache_list
.next
;
386 if (next
== &cache_list
) {
387 current_detail
= NULL
;
388 spin_unlock(&cache_list_lock
);
391 current_detail
= list_entry(next
, struct cache_detail
, others
);
392 if (current_detail
->nextcheck
> seconds_since_boot())
393 current_index
= current_detail
->hash_size
;
396 current_detail
->nextcheck
= seconds_since_boot()+30*60;
400 /* find a non-empty bucket in the table */
401 while (current_detail
&&
402 current_index
< current_detail
->hash_size
&&
403 current_detail
->hash_table
[current_index
] == NULL
)
406 /* find a cleanable entry in the bucket and clean it, or set to next bucket */
408 if (current_detail
&& current_index
< current_detail
->hash_size
) {
409 struct cache_head
*ch
, **cp
;
410 struct cache_detail
*d
;
412 write_lock(¤t_detail
->hash_lock
);
414 /* Ok, now to clean this strand */
416 cp
= & current_detail
->hash_table
[current_index
];
417 for (ch
= *cp
; ch
; cp
= & ch
->next
, ch
= *cp
) {
418 if (current_detail
->nextcheck
> ch
->expiry_time
)
419 current_detail
->nextcheck
= ch
->expiry_time
+1;
420 if (!cache_is_expired(current_detail
, ch
))
425 current_detail
->entries
--;
430 write_unlock(¤t_detail
->hash_lock
);
434 spin_unlock(&cache_list_lock
);
436 if (test_and_clear_bit(CACHE_PENDING
, &ch
->flags
))
437 cache_dequeue(current_detail
, ch
);
438 cache_revisit_request(ch
);
442 spin_unlock(&cache_list_lock
);
448 * We want to regularly clean the cache, so we need to schedule some work ...
450 static void do_cache_clean(struct work_struct
*work
)
453 if (cache_clean() == -1)
454 delay
= round_jiffies_relative(30*HZ
);
456 if (list_empty(&cache_list
))
460 schedule_delayed_work(&cache_cleaner
, delay
);
465 * Clean all caches promptly. This just calls cache_clean
466 * repeatedly until we are sure that every cache has had a chance to
469 void cache_flush(void)
471 while (cache_clean() != -1)
473 while (cache_clean() != -1)
476 EXPORT_SYMBOL_GPL(cache_flush
);
478 void cache_purge(struct cache_detail
*detail
)
480 detail
->flush_time
= LONG_MAX
;
481 detail
->nextcheck
= seconds_since_boot();
483 detail
->flush_time
= 1;
485 EXPORT_SYMBOL_GPL(cache_purge
);
489 * Deferral and Revisiting of Requests.
491 * If a cache lookup finds a pending entry, we
492 * need to defer the request and revisit it later.
493 * All deferred requests are stored in a hash table,
494 * indexed by "struct cache_head *".
495 * As it may be wasteful to store a whole request
496 * structure, we allow the request to provide a
497 * deferred form, which must contain a
498 * 'struct cache_deferred_req'
499 * This cache_deferred_req contains a method to allow
500 * it to be revisited when cache info is available
503 #define DFR_HASHSIZE (PAGE_SIZE/sizeof(struct list_head))
504 #define DFR_HASH(item) ((((long)item)>>4 ^ (((long)item)>>13)) % DFR_HASHSIZE)
506 #define DFR_MAX 300 /* ??? */
508 static DEFINE_SPINLOCK(cache_defer_lock
);
509 static LIST_HEAD(cache_defer_list
);
510 static struct hlist_head cache_defer_hash
[DFR_HASHSIZE
];
511 static int cache_defer_cnt
;
513 static void __unhash_deferred_req(struct cache_deferred_req
*dreq
)
515 hlist_del_init(&dreq
->hash
);
516 if (!list_empty(&dreq
->recent
)) {
517 list_del_init(&dreq
->recent
);
522 static void __hash_deferred_req(struct cache_deferred_req
*dreq
, struct cache_head
*item
)
524 int hash
= DFR_HASH(item
);
526 INIT_LIST_HEAD(&dreq
->recent
);
527 hlist_add_head(&dreq
->hash
, &cache_defer_hash
[hash
]);
530 static void setup_deferral(struct cache_deferred_req
*dreq
,
531 struct cache_head
*item
,
537 spin_lock(&cache_defer_lock
);
539 __hash_deferred_req(dreq
, item
);
543 list_add(&dreq
->recent
, &cache_defer_list
);
546 spin_unlock(&cache_defer_lock
);
550 struct thread_deferred_req
{
551 struct cache_deferred_req handle
;
552 struct completion completion
;
555 static void cache_restart_thread(struct cache_deferred_req
*dreq
, int too_many
)
557 struct thread_deferred_req
*dr
=
558 container_of(dreq
, struct thread_deferred_req
, handle
);
559 complete(&dr
->completion
);
562 static void cache_wait_req(struct cache_req
*req
, struct cache_head
*item
)
564 struct thread_deferred_req sleeper
;
565 struct cache_deferred_req
*dreq
= &sleeper
.handle
;
567 sleeper
.completion
= COMPLETION_INITIALIZER_ONSTACK(sleeper
.completion
);
568 dreq
->revisit
= cache_restart_thread
;
570 setup_deferral(dreq
, item
, 0);
572 if (!test_bit(CACHE_PENDING
, &item
->flags
) ||
573 wait_for_completion_interruptible_timeout(
574 &sleeper
.completion
, req
->thread_wait
) <= 0) {
575 /* The completion wasn't completed, so we need
578 spin_lock(&cache_defer_lock
);
579 if (!hlist_unhashed(&sleeper
.handle
.hash
)) {
580 __unhash_deferred_req(&sleeper
.handle
);
581 spin_unlock(&cache_defer_lock
);
583 /* cache_revisit_request already removed
584 * this from the hash table, but hasn't
585 * called ->revisit yet. It will very soon
586 * and we need to wait for it.
588 spin_unlock(&cache_defer_lock
);
589 wait_for_completion(&sleeper
.completion
);
594 static void cache_limit_defers(void)
596 /* Make sure we haven't exceed the limit of allowed deferred
599 struct cache_deferred_req
*discard
= NULL
;
601 if (cache_defer_cnt
<= DFR_MAX
)
604 spin_lock(&cache_defer_lock
);
606 /* Consider removing either the first or the last */
607 if (cache_defer_cnt
> DFR_MAX
) {
608 if (net_random() & 1)
609 discard
= list_entry(cache_defer_list
.next
,
610 struct cache_deferred_req
, recent
);
612 discard
= list_entry(cache_defer_list
.prev
,
613 struct cache_deferred_req
, recent
);
614 __unhash_deferred_req(discard
);
616 spin_unlock(&cache_defer_lock
);
618 discard
->revisit(discard
, 1);
621 static void cache_defer_req(struct cache_req
*req
, struct cache_head
*item
)
623 struct cache_deferred_req
*dreq
;
625 if (req
->thread_wait
) {
626 cache_wait_req(req
, item
);
627 if (!test_bit(CACHE_PENDING
, &item
->flags
))
630 dreq
= req
->defer(req
);
633 setup_deferral(dreq
, item
, 1);
634 if (!test_bit(CACHE_PENDING
, &item
->flags
))
635 /* Bit could have been cleared before we managed to
636 * set up the deferral, so need to revisit just in case
638 cache_revisit_request(item
);
640 cache_limit_defers();
643 static void cache_revisit_request(struct cache_head
*item
)
645 struct cache_deferred_req
*dreq
;
646 struct list_head pending
;
647 struct hlist_node
*lp
, *tmp
;
648 int hash
= DFR_HASH(item
);
650 INIT_LIST_HEAD(&pending
);
651 spin_lock(&cache_defer_lock
);
653 hlist_for_each_entry_safe(dreq
, lp
, tmp
, &cache_defer_hash
[hash
], hash
)
654 if (dreq
->item
== item
) {
655 __unhash_deferred_req(dreq
);
656 list_add(&dreq
->recent
, &pending
);
659 spin_unlock(&cache_defer_lock
);
661 while (!list_empty(&pending
)) {
662 dreq
= list_entry(pending
.next
, struct cache_deferred_req
, recent
);
663 list_del_init(&dreq
->recent
);
664 dreq
->revisit(dreq
, 0);
668 void cache_clean_deferred(void *owner
)
670 struct cache_deferred_req
*dreq
, *tmp
;
671 struct list_head pending
;
674 INIT_LIST_HEAD(&pending
);
675 spin_lock(&cache_defer_lock
);
677 list_for_each_entry_safe(dreq
, tmp
, &cache_defer_list
, recent
) {
678 if (dreq
->owner
== owner
) {
679 __unhash_deferred_req(dreq
);
680 list_add(&dreq
->recent
, &pending
);
683 spin_unlock(&cache_defer_lock
);
685 while (!list_empty(&pending
)) {
686 dreq
= list_entry(pending
.next
, struct cache_deferred_req
, recent
);
687 list_del_init(&dreq
->recent
);
688 dreq
->revisit(dreq
, 1);
693 * communicate with user-space
695 * We have a magic /proc file - /proc/sunrpc/<cachename>/channel.
696 * On read, you get a full request, or block.
697 * On write, an update request is processed.
698 * Poll works if anything to read, and always allows write.
700 * Implemented by linked list of requests. Each open file has
701 * a ->private that also exists in this list. New requests are added
702 * to the end and may wakeup and preceding readers.
703 * New readers are added to the head. If, on read, an item is found with
704 * CACHE_UPCALLING clear, we free it from the list.
708 static DEFINE_SPINLOCK(queue_lock
);
709 static DEFINE_MUTEX(queue_io_mutex
);
712 struct list_head list
;
713 int reader
; /* if 0, then request */
715 struct cache_request
{
716 struct cache_queue q
;
717 struct cache_head
*item
;
722 struct cache_reader
{
723 struct cache_queue q
;
724 int offset
; /* if non-0, we have a refcnt on next request */
727 static ssize_t
cache_read(struct file
*filp
, char __user
*buf
, size_t count
,
728 loff_t
*ppos
, struct cache_detail
*cd
)
730 struct cache_reader
*rp
= filp
->private_data
;
731 struct cache_request
*rq
;
732 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
738 mutex_lock(&inode
->i_mutex
); /* protect against multiple concurrent
739 * readers on this file */
741 spin_lock(&queue_lock
);
742 /* need to find next request */
743 while (rp
->q
.list
.next
!= &cd
->queue
&&
744 list_entry(rp
->q
.list
.next
, struct cache_queue
, list
)
746 struct list_head
*next
= rp
->q
.list
.next
;
747 list_move(&rp
->q
.list
, next
);
749 if (rp
->q
.list
.next
== &cd
->queue
) {
750 spin_unlock(&queue_lock
);
751 mutex_unlock(&inode
->i_mutex
);
755 rq
= container_of(rp
->q
.list
.next
, struct cache_request
, q
.list
);
756 BUG_ON(rq
->q
.reader
);
759 spin_unlock(&queue_lock
);
761 if (rp
->offset
== 0 && !test_bit(CACHE_PENDING
, &rq
->item
->flags
)) {
763 spin_lock(&queue_lock
);
764 list_move(&rp
->q
.list
, &rq
->q
.list
);
765 spin_unlock(&queue_lock
);
767 if (rp
->offset
+ count
> rq
->len
)
768 count
= rq
->len
- rp
->offset
;
770 if (copy_to_user(buf
, rq
->buf
+ rp
->offset
, count
))
773 if (rp
->offset
>= rq
->len
) {
775 spin_lock(&queue_lock
);
776 list_move(&rp
->q
.list
, &rq
->q
.list
);
777 spin_unlock(&queue_lock
);
782 if (rp
->offset
== 0) {
783 /* need to release rq */
784 spin_lock(&queue_lock
);
786 if (rq
->readers
== 0 &&
787 !test_bit(CACHE_PENDING
, &rq
->item
->flags
)) {
788 list_del(&rq
->q
.list
);
789 spin_unlock(&queue_lock
);
790 cache_put(rq
->item
, cd
);
794 spin_unlock(&queue_lock
);
798 mutex_unlock(&inode
->i_mutex
);
799 return err
? err
: count
;
802 static ssize_t
cache_do_downcall(char *kaddr
, const char __user
*buf
,
803 size_t count
, struct cache_detail
*cd
)
807 if (copy_from_user(kaddr
, buf
, count
))
810 ret
= cd
->cache_parse(cd
, kaddr
, count
);
816 static ssize_t
cache_slow_downcall(const char __user
*buf
,
817 size_t count
, struct cache_detail
*cd
)
819 static char write_buf
[8192]; /* protected by queue_io_mutex */
820 ssize_t ret
= -EINVAL
;
822 if (count
>= sizeof(write_buf
))
824 mutex_lock(&queue_io_mutex
);
825 ret
= cache_do_downcall(write_buf
, buf
, count
, cd
);
826 mutex_unlock(&queue_io_mutex
);
831 static ssize_t
cache_downcall(struct address_space
*mapping
,
832 const char __user
*buf
,
833 size_t count
, struct cache_detail
*cd
)
837 ssize_t ret
= -ENOMEM
;
839 if (count
>= PAGE_CACHE_SIZE
)
842 page
= find_or_create_page(mapping
, 0, GFP_KERNEL
);
847 ret
= cache_do_downcall(kaddr
, buf
, count
, cd
);
850 page_cache_release(page
);
853 return cache_slow_downcall(buf
, count
, cd
);
856 static ssize_t
cache_write(struct file
*filp
, const char __user
*buf
,
857 size_t count
, loff_t
*ppos
,
858 struct cache_detail
*cd
)
860 struct address_space
*mapping
= filp
->f_mapping
;
861 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
862 ssize_t ret
= -EINVAL
;
864 if (!cd
->cache_parse
)
867 mutex_lock(&inode
->i_mutex
);
868 ret
= cache_downcall(mapping
, buf
, count
, cd
);
869 mutex_unlock(&inode
->i_mutex
);
874 static DECLARE_WAIT_QUEUE_HEAD(queue_wait
);
876 static unsigned int cache_poll(struct file
*filp
, poll_table
*wait
,
877 struct cache_detail
*cd
)
880 struct cache_reader
*rp
= filp
->private_data
;
881 struct cache_queue
*cq
;
883 poll_wait(filp
, &queue_wait
, wait
);
885 /* alway allow write */
886 mask
= POLL_OUT
| POLLWRNORM
;
891 spin_lock(&queue_lock
);
893 for (cq
= &rp
->q
; &cq
->list
!= &cd
->queue
;
894 cq
= list_entry(cq
->list
.next
, struct cache_queue
, list
))
896 mask
|= POLLIN
| POLLRDNORM
;
899 spin_unlock(&queue_lock
);
903 static int cache_ioctl(struct inode
*ino
, struct file
*filp
,
904 unsigned int cmd
, unsigned long arg
,
905 struct cache_detail
*cd
)
908 struct cache_reader
*rp
= filp
->private_data
;
909 struct cache_queue
*cq
;
911 if (cmd
!= FIONREAD
|| !rp
)
914 spin_lock(&queue_lock
);
916 /* only find the length remaining in current request,
917 * or the length of the next request
919 for (cq
= &rp
->q
; &cq
->list
!= &cd
->queue
;
920 cq
= list_entry(cq
->list
.next
, struct cache_queue
, list
))
922 struct cache_request
*cr
=
923 container_of(cq
, struct cache_request
, q
);
924 len
= cr
->len
- rp
->offset
;
927 spin_unlock(&queue_lock
);
929 return put_user(len
, (int __user
*)arg
);
932 static int cache_open(struct inode
*inode
, struct file
*filp
,
933 struct cache_detail
*cd
)
935 struct cache_reader
*rp
= NULL
;
937 if (!cd
|| !try_module_get(cd
->owner
))
939 nonseekable_open(inode
, filp
);
940 if (filp
->f_mode
& FMODE_READ
) {
941 rp
= kmalloc(sizeof(*rp
), GFP_KERNEL
);
946 atomic_inc(&cd
->readers
);
947 spin_lock(&queue_lock
);
948 list_add(&rp
->q
.list
, &cd
->queue
);
949 spin_unlock(&queue_lock
);
951 filp
->private_data
= rp
;
955 static int cache_release(struct inode
*inode
, struct file
*filp
,
956 struct cache_detail
*cd
)
958 struct cache_reader
*rp
= filp
->private_data
;
961 spin_lock(&queue_lock
);
963 struct cache_queue
*cq
;
964 for (cq
= &rp
->q
; &cq
->list
!= &cd
->queue
;
965 cq
= list_entry(cq
->list
.next
, struct cache_queue
, list
))
967 container_of(cq
, struct cache_request
, q
)
973 list_del(&rp
->q
.list
);
974 spin_unlock(&queue_lock
);
976 filp
->private_data
= NULL
;
979 cd
->last_close
= seconds_since_boot();
980 atomic_dec(&cd
->readers
);
982 module_put(cd
->owner
);
988 static void cache_dequeue(struct cache_detail
*detail
, struct cache_head
*ch
)
990 struct cache_queue
*cq
;
991 spin_lock(&queue_lock
);
992 list_for_each_entry(cq
, &detail
->queue
, list
)
994 struct cache_request
*cr
= container_of(cq
, struct cache_request
, q
);
997 if (cr
->readers
!= 0)
999 list_del(&cr
->q
.list
);
1000 spin_unlock(&queue_lock
);
1001 cache_put(cr
->item
, detail
);
1006 spin_unlock(&queue_lock
);
1010 * Support routines for text-based upcalls.
1011 * Fields are separated by spaces.
1012 * Fields are either mangled to quote space tab newline slosh with slosh
1013 * or a hexified with a leading \x
1014 * Record is terminated with newline.
1018 void qword_add(char **bpp
, int *lp
, char *str
)
1024 if (len
< 0) return;
1026 while ((c
=*str
++) && len
)
1034 *bp
++ = '0' + ((c
& 0300)>>6);
1035 *bp
++ = '0' + ((c
& 0070)>>3);
1036 *bp
++ = '0' + ((c
& 0007)>>0);
1044 if (c
|| len
<1) len
= -1;
1052 EXPORT_SYMBOL_GPL(qword_add
);
1054 void qword_addhex(char **bpp
, int *lp
, char *buf
, int blen
)
1059 if (len
< 0) return;
1065 while (blen
&& len
>= 2) {
1066 unsigned char c
= *buf
++;
1067 *bp
++ = '0' + ((c
&0xf0)>>4) + (c
>=0xa0)*('a'-'9'-1);
1068 *bp
++ = '0' + (c
&0x0f) + ((c
&0x0f)>=0x0a)*('a'-'9'-1);
1073 if (blen
|| len
<1) len
= -1;
1081 EXPORT_SYMBOL_GPL(qword_addhex
);
1083 static void warn_no_listener(struct cache_detail
*detail
)
1085 if (detail
->last_warn
!= detail
->last_close
) {
1086 detail
->last_warn
= detail
->last_close
;
1087 if (detail
->warn_no_listener
)
1088 detail
->warn_no_listener(detail
, detail
->last_close
!= 0);
1092 static bool cache_listeners_exist(struct cache_detail
*detail
)
1094 if (atomic_read(&detail
->readers
))
1096 if (detail
->last_close
== 0)
1097 /* This cache was never opened */
1099 if (detail
->last_close
< seconds_since_boot() - 30)
1101 * We allow for the possibility that someone might
1102 * restart a userspace daemon without restarting the
1103 * server; but after 30 seconds, we give up.
1110 * register an upcall request to user-space and queue it up for read() by the
1113 * Each request is at most one page long.
1115 int sunrpc_cache_pipe_upcall(struct cache_detail
*detail
, struct cache_head
*h
,
1116 void (*cache_request
)(struct cache_detail
*,
1117 struct cache_head
*,
1123 struct cache_request
*crq
;
1127 if (!cache_listeners_exist(detail
)) {
1128 warn_no_listener(detail
);
1132 buf
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
1136 crq
= kmalloc(sizeof (*crq
), GFP_KERNEL
);
1142 bp
= buf
; len
= PAGE_SIZE
;
1144 cache_request(detail
, h
, &bp
, &len
);
1152 crq
->item
= cache_get(h
);
1154 crq
->len
= PAGE_SIZE
- len
;
1156 spin_lock(&queue_lock
);
1157 list_add_tail(&crq
->q
.list
, &detail
->queue
);
1158 spin_unlock(&queue_lock
);
1159 wake_up(&queue_wait
);
1162 EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall
);
1165 * parse a message from user-space and pass it
1166 * to an appropriate cache
1167 * Messages are, like requests, separated into fields by
1168 * spaces and dequotes as \xHEXSTRING or embedded \nnn octal
1171 * reply cachename expiry key ... content....
1173 * key and content are both parsed by cache
1176 #define isodigit(c) (isdigit(c) && c <= '7')
1177 int qword_get(char **bpp
, char *dest
, int bufsize
)
1179 /* return bytes copied, or -1 on error */
1183 while (*bp
== ' ') bp
++;
1185 if (bp
[0] == '\\' && bp
[1] == 'x') {
1188 while (len
< bufsize
) {
1191 h
= hex_to_bin(bp
[0]);
1195 l
= hex_to_bin(bp
[1]);
1199 *dest
++ = (h
<< 4) | l
;
1204 /* text with \nnn octal quoting */
1205 while (*bp
!= ' ' && *bp
!= '\n' && *bp
&& len
< bufsize
-1) {
1207 isodigit(bp
[1]) && (bp
[1] <= '3') &&
1210 int byte
= (*++bp
-'0');
1212 byte
= (byte
<< 3) | (*bp
++ - '0');
1213 byte
= (byte
<< 3) | (*bp
++ - '0');
1223 if (*bp
!= ' ' && *bp
!= '\n' && *bp
!= '\0')
1225 while (*bp
== ' ') bp
++;
1230 EXPORT_SYMBOL_GPL(qword_get
);
1234 * support /proc/sunrpc/cache/$CACHENAME/content
1236 * We call ->cache_show passing NULL for the item to
1237 * get a header, then pass each real item in the cache
1241 struct cache_detail
*cd
;
1244 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
1245 __acquires(cd
->hash_lock
)
1248 unsigned hash
, entry
;
1249 struct cache_head
*ch
;
1250 struct cache_detail
*cd
= ((struct handle
*)m
->private)->cd
;
1253 read_lock(&cd
->hash_lock
);
1255 return SEQ_START_TOKEN
;
1257 entry
= n
& ((1LL<<32) - 1);
1259 for (ch
=cd
->hash_table
[hash
]; ch
; ch
=ch
->next
)
1262 n
&= ~((1LL<<32) - 1);
1266 } while(hash
< cd
->hash_size
&&
1267 cd
->hash_table
[hash
]==NULL
);
1268 if (hash
>= cd
->hash_size
)
1271 return cd
->hash_table
[hash
];
1274 static void *c_next(struct seq_file
*m
, void *p
, loff_t
*pos
)
1276 struct cache_head
*ch
= p
;
1277 int hash
= (*pos
>> 32);
1278 struct cache_detail
*cd
= ((struct handle
*)m
->private)->cd
;
1280 if (p
== SEQ_START_TOKEN
)
1282 else if (ch
->next
== NULL
) {
1289 *pos
&= ~((1LL<<32) - 1);
1290 while (hash
< cd
->hash_size
&&
1291 cd
->hash_table
[hash
] == NULL
) {
1295 if (hash
>= cd
->hash_size
)
1298 return cd
->hash_table
[hash
];
1301 static void c_stop(struct seq_file
*m
, void *p
)
1302 __releases(cd
->hash_lock
)
1304 struct cache_detail
*cd
= ((struct handle
*)m
->private)->cd
;
1305 read_unlock(&cd
->hash_lock
);
1308 static int c_show(struct seq_file
*m
, void *p
)
1310 struct cache_head
*cp
= p
;
1311 struct cache_detail
*cd
= ((struct handle
*)m
->private)->cd
;
1313 if (p
== SEQ_START_TOKEN
)
1314 return cd
->cache_show(m
, cd
, NULL
);
1317 seq_printf(m
, "# expiry=%ld refcnt=%d flags=%lx\n",
1318 convert_to_wallclock(cp
->expiry_time
),
1319 atomic_read(&cp
->ref
.refcount
), cp
->flags
);
1321 if (cache_check(cd
, cp
, NULL
))
1322 /* cache_check does a cache_put on failure */
1323 seq_printf(m
, "# ");
1327 return cd
->cache_show(m
, cd
, cp
);
1330 static const struct seq_operations cache_content_op
= {
1337 static int content_open(struct inode
*inode
, struct file
*file
,
1338 struct cache_detail
*cd
)
1342 if (!cd
|| !try_module_get(cd
->owner
))
1344 han
= __seq_open_private(file
, &cache_content_op
, sizeof(*han
));
1346 module_put(cd
->owner
);
1354 static int content_release(struct inode
*inode
, struct file
*file
,
1355 struct cache_detail
*cd
)
1357 int ret
= seq_release_private(inode
, file
);
1358 module_put(cd
->owner
);
1362 static int open_flush(struct inode
*inode
, struct file
*file
,
1363 struct cache_detail
*cd
)
1365 if (!cd
|| !try_module_get(cd
->owner
))
1367 return nonseekable_open(inode
, file
);
1370 static int release_flush(struct inode
*inode
, struct file
*file
,
1371 struct cache_detail
*cd
)
1373 module_put(cd
->owner
);
1377 static ssize_t
read_flush(struct file
*file
, char __user
*buf
,
1378 size_t count
, loff_t
*ppos
,
1379 struct cache_detail
*cd
)
1382 unsigned long p
= *ppos
;
1385 sprintf(tbuf
, "%lu\n", convert_to_wallclock(cd
->flush_time
));
1392 if (copy_to_user(buf
, (void*)(tbuf
+p
), len
))
1398 static ssize_t
write_flush(struct file
*file
, const char __user
*buf
,
1399 size_t count
, loff_t
*ppos
,
1400 struct cache_detail
*cd
)
1405 if (*ppos
|| count
> sizeof(tbuf
)-1)
1407 if (copy_from_user(tbuf
, buf
, count
))
1410 simple_strtoul(tbuf
, &ep
, 0);
1411 if (*ep
&& *ep
!= '\n')
1415 cd
->flush_time
= get_expiry(&bp
);
1416 cd
->nextcheck
= seconds_since_boot();
1423 static ssize_t
cache_read_procfs(struct file
*filp
, char __user
*buf
,
1424 size_t count
, loff_t
*ppos
)
1426 struct cache_detail
*cd
= PDE(filp
->f_path
.dentry
->d_inode
)->data
;
1428 return cache_read(filp
, buf
, count
, ppos
, cd
);
1431 static ssize_t
cache_write_procfs(struct file
*filp
, const char __user
*buf
,
1432 size_t count
, loff_t
*ppos
)
1434 struct cache_detail
*cd
= PDE(filp
->f_path
.dentry
->d_inode
)->data
;
1436 return cache_write(filp
, buf
, count
, ppos
, cd
);
1439 static unsigned int cache_poll_procfs(struct file
*filp
, poll_table
*wait
)
1441 struct cache_detail
*cd
= PDE(filp
->f_path
.dentry
->d_inode
)->data
;
1443 return cache_poll(filp
, wait
, cd
);
1446 static long cache_ioctl_procfs(struct file
*filp
,
1447 unsigned int cmd
, unsigned long arg
)
1449 struct inode
*inode
= filp
->f_path
.dentry
->d_inode
;
1450 struct cache_detail
*cd
= PDE(inode
)->data
;
1452 return cache_ioctl(inode
, filp
, cmd
, arg
, cd
);
1455 static int cache_open_procfs(struct inode
*inode
, struct file
*filp
)
1457 struct cache_detail
*cd
= PDE(inode
)->data
;
1459 return cache_open(inode
, filp
, cd
);
1462 static int cache_release_procfs(struct inode
*inode
, struct file
*filp
)
1464 struct cache_detail
*cd
= PDE(inode
)->data
;
1466 return cache_release(inode
, filp
, cd
);
1469 static const struct file_operations cache_file_operations_procfs
= {
1470 .owner
= THIS_MODULE
,
1471 .llseek
= no_llseek
,
1472 .read
= cache_read_procfs
,
1473 .write
= cache_write_procfs
,
1474 .poll
= cache_poll_procfs
,
1475 .unlocked_ioctl
= cache_ioctl_procfs
, /* for FIONREAD */
1476 .open
= cache_open_procfs
,
1477 .release
= cache_release_procfs
,
1480 static int content_open_procfs(struct inode
*inode
, struct file
*filp
)
1482 struct cache_detail
*cd
= PDE(inode
)->data
;
1484 return content_open(inode
, filp
, cd
);
1487 static int content_release_procfs(struct inode
*inode
, struct file
*filp
)
1489 struct cache_detail
*cd
= PDE(inode
)->data
;
1491 return content_release(inode
, filp
, cd
);
1494 static const struct file_operations content_file_operations_procfs
= {
1495 .open
= content_open_procfs
,
1497 .llseek
= seq_lseek
,
1498 .release
= content_release_procfs
,
1501 static int open_flush_procfs(struct inode
*inode
, struct file
*filp
)
1503 struct cache_detail
*cd
= PDE(inode
)->data
;
1505 return open_flush(inode
, filp
, cd
);
1508 static int release_flush_procfs(struct inode
*inode
, struct file
*filp
)
1510 struct cache_detail
*cd
= PDE(inode
)->data
;
1512 return release_flush(inode
, filp
, cd
);
1515 static ssize_t
read_flush_procfs(struct file
*filp
, char __user
*buf
,
1516 size_t count
, loff_t
*ppos
)
1518 struct cache_detail
*cd
= PDE(filp
->f_path
.dentry
->d_inode
)->data
;
1520 return read_flush(filp
, buf
, count
, ppos
, cd
);
1523 static ssize_t
write_flush_procfs(struct file
*filp
,
1524 const char __user
*buf
,
1525 size_t count
, loff_t
*ppos
)
1527 struct cache_detail
*cd
= PDE(filp
->f_path
.dentry
->d_inode
)->data
;
1529 return write_flush(filp
, buf
, count
, ppos
, cd
);
1532 static const struct file_operations cache_flush_operations_procfs
= {
1533 .open
= open_flush_procfs
,
1534 .read
= read_flush_procfs
,
1535 .write
= write_flush_procfs
,
1536 .release
= release_flush_procfs
,
1537 .llseek
= no_llseek
,
1540 static void remove_cache_proc_entries(struct cache_detail
*cd
, struct net
*net
)
1542 struct sunrpc_net
*sn
;
1544 if (cd
->u
.procfs
.proc_ent
== NULL
)
1546 if (cd
->u
.procfs
.flush_ent
)
1547 remove_proc_entry("flush", cd
->u
.procfs
.proc_ent
);
1548 if (cd
->u
.procfs
.channel_ent
)
1549 remove_proc_entry("channel", cd
->u
.procfs
.proc_ent
);
1550 if (cd
->u
.procfs
.content_ent
)
1551 remove_proc_entry("content", cd
->u
.procfs
.proc_ent
);
1552 cd
->u
.procfs
.proc_ent
= NULL
;
1553 sn
= net_generic(net
, sunrpc_net_id
);
1554 remove_proc_entry(cd
->name
, sn
->proc_net_rpc
);
1557 #ifdef CONFIG_PROC_FS
1558 static int create_cache_proc_entries(struct cache_detail
*cd
, struct net
*net
)
1560 struct proc_dir_entry
*p
;
1561 struct sunrpc_net
*sn
;
1563 sn
= net_generic(net
, sunrpc_net_id
);
1564 cd
->u
.procfs
.proc_ent
= proc_mkdir(cd
->name
, sn
->proc_net_rpc
);
1565 if (cd
->u
.procfs
.proc_ent
== NULL
)
1567 cd
->u
.procfs
.channel_ent
= NULL
;
1568 cd
->u
.procfs
.content_ent
= NULL
;
1570 p
= proc_create_data("flush", S_IFREG
|S_IRUSR
|S_IWUSR
,
1571 cd
->u
.procfs
.proc_ent
,
1572 &cache_flush_operations_procfs
, cd
);
1573 cd
->u
.procfs
.flush_ent
= p
;
1577 if (cd
->cache_upcall
|| cd
->cache_parse
) {
1578 p
= proc_create_data("channel", S_IFREG
|S_IRUSR
|S_IWUSR
,
1579 cd
->u
.procfs
.proc_ent
,
1580 &cache_file_operations_procfs
, cd
);
1581 cd
->u
.procfs
.channel_ent
= p
;
1585 if (cd
->cache_show
) {
1586 p
= proc_create_data("content", S_IFREG
|S_IRUSR
|S_IWUSR
,
1587 cd
->u
.procfs
.proc_ent
,
1588 &content_file_operations_procfs
, cd
);
1589 cd
->u
.procfs
.content_ent
= p
;
1595 remove_cache_proc_entries(cd
, net
);
1598 #else /* CONFIG_PROC_FS */
1599 static int create_cache_proc_entries(struct cache_detail
*cd
, struct net
*net
)
1605 void __init
cache_initialize(void)
1607 INIT_DELAYED_WORK_DEFERRABLE(&cache_cleaner
, do_cache_clean
);
1610 int cache_register_net(struct cache_detail
*cd
, struct net
*net
)
1614 sunrpc_init_cache_detail(cd
);
1615 ret
= create_cache_proc_entries(cd
, net
);
1617 sunrpc_destroy_cache_detail(cd
);
1621 int cache_register(struct cache_detail
*cd
)
1623 return cache_register_net(cd
, &init_net
);
1625 EXPORT_SYMBOL_GPL(cache_register
);
1627 void cache_unregister_net(struct cache_detail
*cd
, struct net
*net
)
1629 remove_cache_proc_entries(cd
, net
);
1630 sunrpc_destroy_cache_detail(cd
);
1633 void cache_unregister(struct cache_detail
*cd
)
1635 cache_unregister_net(cd
, &init_net
);
1637 EXPORT_SYMBOL_GPL(cache_unregister
);
1639 static ssize_t
cache_read_pipefs(struct file
*filp
, char __user
*buf
,
1640 size_t count
, loff_t
*ppos
)
1642 struct cache_detail
*cd
= RPC_I(filp
->f_path
.dentry
->d_inode
)->private;
1644 return cache_read(filp
, buf
, count
, ppos
, cd
);
1647 static ssize_t
cache_write_pipefs(struct file
*filp
, const char __user
*buf
,
1648 size_t count
, loff_t
*ppos
)
1650 struct cache_detail
*cd
= RPC_I(filp
->f_path
.dentry
->d_inode
)->private;
1652 return cache_write(filp
, buf
, count
, ppos
, cd
);
1655 static unsigned int cache_poll_pipefs(struct file
*filp
, poll_table
*wait
)
1657 struct cache_detail
*cd
= RPC_I(filp
->f_path
.dentry
->d_inode
)->private;
1659 return cache_poll(filp
, wait
, cd
);
1662 static long cache_ioctl_pipefs(struct file
*filp
,
1663 unsigned int cmd
, unsigned long arg
)
1665 struct inode
*inode
= filp
->f_dentry
->d_inode
;
1666 struct cache_detail
*cd
= RPC_I(inode
)->private;
1668 return cache_ioctl(inode
, filp
, cmd
, arg
, cd
);
1671 static int cache_open_pipefs(struct inode
*inode
, struct file
*filp
)
1673 struct cache_detail
*cd
= RPC_I(inode
)->private;
1675 return cache_open(inode
, filp
, cd
);
1678 static int cache_release_pipefs(struct inode
*inode
, struct file
*filp
)
1680 struct cache_detail
*cd
= RPC_I(inode
)->private;
1682 return cache_release(inode
, filp
, cd
);
1685 const struct file_operations cache_file_operations_pipefs
= {
1686 .owner
= THIS_MODULE
,
1687 .llseek
= no_llseek
,
1688 .read
= cache_read_pipefs
,
1689 .write
= cache_write_pipefs
,
1690 .poll
= cache_poll_pipefs
,
1691 .unlocked_ioctl
= cache_ioctl_pipefs
, /* for FIONREAD */
1692 .open
= cache_open_pipefs
,
1693 .release
= cache_release_pipefs
,
1696 static int content_open_pipefs(struct inode
*inode
, struct file
*filp
)
1698 struct cache_detail
*cd
= RPC_I(inode
)->private;
1700 return content_open(inode
, filp
, cd
);
1703 static int content_release_pipefs(struct inode
*inode
, struct file
*filp
)
1705 struct cache_detail
*cd
= RPC_I(inode
)->private;
1707 return content_release(inode
, filp
, cd
);
1710 const struct file_operations content_file_operations_pipefs
= {
1711 .open
= content_open_pipefs
,
1713 .llseek
= seq_lseek
,
1714 .release
= content_release_pipefs
,
1717 static int open_flush_pipefs(struct inode
*inode
, struct file
*filp
)
1719 struct cache_detail
*cd
= RPC_I(inode
)->private;
1721 return open_flush(inode
, filp
, cd
);
1724 static int release_flush_pipefs(struct inode
*inode
, struct file
*filp
)
1726 struct cache_detail
*cd
= RPC_I(inode
)->private;
1728 return release_flush(inode
, filp
, cd
);
1731 static ssize_t
read_flush_pipefs(struct file
*filp
, char __user
*buf
,
1732 size_t count
, loff_t
*ppos
)
1734 struct cache_detail
*cd
= RPC_I(filp
->f_path
.dentry
->d_inode
)->private;
1736 return read_flush(filp
, buf
, count
, ppos
, cd
);
1739 static ssize_t
write_flush_pipefs(struct file
*filp
,
1740 const char __user
*buf
,
1741 size_t count
, loff_t
*ppos
)
1743 struct cache_detail
*cd
= RPC_I(filp
->f_path
.dentry
->d_inode
)->private;
1745 return write_flush(filp
, buf
, count
, ppos
, cd
);
1748 const struct file_operations cache_flush_operations_pipefs
= {
1749 .open
= open_flush_pipefs
,
1750 .read
= read_flush_pipefs
,
1751 .write
= write_flush_pipefs
,
1752 .release
= release_flush_pipefs
,
1753 .llseek
= no_llseek
,
1756 int sunrpc_cache_register_pipefs(struct dentry
*parent
,
1757 const char *name
, mode_t umode
,
1758 struct cache_detail
*cd
)
1764 sunrpc_init_cache_detail(cd
);
1766 q
.len
= strlen(name
);
1767 q
.hash
= full_name_hash(q
.name
, q
.len
);
1768 dir
= rpc_create_cache_dir(parent
, &q
, umode
, cd
);
1770 cd
->u
.pipefs
.dir
= dir
;
1772 sunrpc_destroy_cache_detail(cd
);
1777 EXPORT_SYMBOL_GPL(sunrpc_cache_register_pipefs
);
1779 void sunrpc_cache_unregister_pipefs(struct cache_detail
*cd
)
1781 rpc_remove_cache_dir(cd
->u
.pipefs
.dir
);
1782 cd
->u
.pipefs
.dir
= NULL
;
1783 sunrpc_destroy_cache_detail(cd
);
1785 EXPORT_SYMBOL_GPL(sunrpc_cache_unregister_pipefs
);