Staging: hv: remove DWORD and BYTE typedefs
[linux-2.6/mini2440.git] / net / sunrpc / cache.c
blob45cdaff9b361c17272872294c0dfc96962ce9cca
1 /*
2 * net/sunrpc/cache.c
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>
14 #include <linux/fs.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>
37 #define RPCDBG_FACILITY RPCDBG_CACHE
39 static int cache_defer_req(struct cache_req *req, struct cache_head *item);
40 static void cache_revisit_request(struct cache_head *item);
42 static void cache_init(struct cache_head *h)
44 time_t now = get_seconds();
45 h->next = NULL;
46 h->flags = 0;
47 kref_init(&h->ref);
48 h->expiry_time = now + CACHE_NEW_EXPIRY;
49 h->last_refresh = now;
52 struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
53 struct cache_head *key, int hash)
55 struct cache_head **head, **hp;
56 struct cache_head *new = NULL;
58 head = &detail->hash_table[hash];
60 read_lock(&detail->hash_lock);
62 for (hp=head; *hp != NULL ; hp = &(*hp)->next) {
63 struct cache_head *tmp = *hp;
64 if (detail->match(tmp, key)) {
65 cache_get(tmp);
66 read_unlock(&detail->hash_lock);
67 return tmp;
70 read_unlock(&detail->hash_lock);
71 /* Didn't find anything, insert an empty entry */
73 new = detail->alloc();
74 if (!new)
75 return NULL;
76 /* must fully initialise 'new', else
77 * we might get lose if we need to
78 * cache_put it soon.
80 cache_init(new);
81 detail->init(new, key);
83 write_lock(&detail->hash_lock);
85 /* check if entry appeared while we slept */
86 for (hp=head; *hp != NULL ; hp = &(*hp)->next) {
87 struct cache_head *tmp = *hp;
88 if (detail->match(tmp, key)) {
89 cache_get(tmp);
90 write_unlock(&detail->hash_lock);
91 cache_put(new, detail);
92 return tmp;
95 new->next = *head;
96 *head = new;
97 detail->entries++;
98 cache_get(new);
99 write_unlock(&detail->hash_lock);
101 return new;
103 EXPORT_SYMBOL_GPL(sunrpc_cache_lookup);
106 static void queue_loose(struct cache_detail *detail, struct cache_head *ch);
108 static int cache_fresh_locked(struct cache_head *head, time_t expiry)
110 head->expiry_time = expiry;
111 head->last_refresh = get_seconds();
112 return !test_and_set_bit(CACHE_VALID, &head->flags);
115 static void cache_fresh_unlocked(struct cache_head *head,
116 struct cache_detail *detail, int new)
118 if (new)
119 cache_revisit_request(head);
120 if (test_and_clear_bit(CACHE_PENDING, &head->flags)) {
121 cache_revisit_request(head);
122 queue_loose(detail, head);
126 struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
127 struct cache_head *new, struct cache_head *old, int hash)
129 /* The 'old' entry is to be replaced by 'new'.
130 * If 'old' is not VALID, we update it directly,
131 * otherwise we need to replace it
133 struct cache_head **head;
134 struct cache_head *tmp;
135 int is_new;
137 if (!test_bit(CACHE_VALID, &old->flags)) {
138 write_lock(&detail->hash_lock);
139 if (!test_bit(CACHE_VALID, &old->flags)) {
140 if (test_bit(CACHE_NEGATIVE, &new->flags))
141 set_bit(CACHE_NEGATIVE, &old->flags);
142 else
143 detail->update(old, new);
144 is_new = cache_fresh_locked(old, new->expiry_time);
145 write_unlock(&detail->hash_lock);
146 cache_fresh_unlocked(old, detail, is_new);
147 return old;
149 write_unlock(&detail->hash_lock);
151 /* We need to insert a new entry */
152 tmp = detail->alloc();
153 if (!tmp) {
154 cache_put(old, detail);
155 return NULL;
157 cache_init(tmp);
158 detail->init(tmp, old);
159 head = &detail->hash_table[hash];
161 write_lock(&detail->hash_lock);
162 if (test_bit(CACHE_NEGATIVE, &new->flags))
163 set_bit(CACHE_NEGATIVE, &tmp->flags);
164 else
165 detail->update(tmp, new);
166 tmp->next = *head;
167 *head = tmp;
168 detail->entries++;
169 cache_get(tmp);
170 is_new = cache_fresh_locked(tmp, new->expiry_time);
171 cache_fresh_locked(old, 0);
172 write_unlock(&detail->hash_lock);
173 cache_fresh_unlocked(tmp, detail, is_new);
174 cache_fresh_unlocked(old, detail, 0);
175 cache_put(old, detail);
176 return tmp;
178 EXPORT_SYMBOL_GPL(sunrpc_cache_update);
180 static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
182 if (!cd->cache_upcall)
183 return -EINVAL;
184 return cd->cache_upcall(cd, h);
188 * This is the generic cache management routine for all
189 * the authentication caches.
190 * It checks the currency of a cache item and will (later)
191 * initiate an upcall to fill it if needed.
194 * Returns 0 if the cache_head can be used, or cache_puts it and returns
195 * -EAGAIN if upcall is pending,
196 * -ETIMEDOUT if upcall failed and should be retried,
197 * -ENOENT if cache entry was negative
199 int cache_check(struct cache_detail *detail,
200 struct cache_head *h, struct cache_req *rqstp)
202 int rv;
203 long refresh_age, age;
205 /* First decide return status as best we can */
206 if (!test_bit(CACHE_VALID, &h->flags) ||
207 h->expiry_time < get_seconds())
208 rv = -EAGAIN;
209 else if (detail->flush_time > h->last_refresh)
210 rv = -EAGAIN;
211 else {
212 /* entry is valid */
213 if (test_bit(CACHE_NEGATIVE, &h->flags))
214 rv = -ENOENT;
215 else rv = 0;
218 /* now see if we want to start an upcall */
219 refresh_age = (h->expiry_time - h->last_refresh);
220 age = get_seconds() - h->last_refresh;
222 if (rqstp == NULL) {
223 if (rv == -EAGAIN)
224 rv = -ENOENT;
225 } else if (rv == -EAGAIN || age > refresh_age/2) {
226 dprintk("RPC: Want update, refage=%ld, age=%ld\n",
227 refresh_age, age);
228 if (!test_and_set_bit(CACHE_PENDING, &h->flags)) {
229 switch (cache_make_upcall(detail, h)) {
230 case -EINVAL:
231 clear_bit(CACHE_PENDING, &h->flags);
232 if (rv == -EAGAIN) {
233 set_bit(CACHE_NEGATIVE, &h->flags);
234 cache_fresh_unlocked(h, detail,
235 cache_fresh_locked(h, get_seconds()+CACHE_NEW_EXPIRY));
236 rv = -ENOENT;
238 break;
240 case -EAGAIN:
241 clear_bit(CACHE_PENDING, &h->flags);
242 cache_revisit_request(h);
243 break;
248 if (rv == -EAGAIN)
249 if (cache_defer_req(rqstp, h) != 0)
250 rv = -ETIMEDOUT;
252 if (rv)
253 cache_put(h, detail);
254 return rv;
256 EXPORT_SYMBOL_GPL(cache_check);
259 * caches need to be periodically cleaned.
260 * For this we maintain a list of cache_detail and
261 * a current pointer into that list and into the table
262 * for that entry.
264 * Each time clean_cache is called it finds the next non-empty entry
265 * in the current table and walks the list in that entry
266 * looking for entries that can be removed.
268 * An entry gets removed if:
269 * - The expiry is before current time
270 * - The last_refresh time is before the flush_time for that cache
272 * later we might drop old entries with non-NEVER expiry if that table
273 * is getting 'full' for some definition of 'full'
275 * The question of "how often to scan a table" is an interesting one
276 * and is answered in part by the use of the "nextcheck" field in the
277 * cache_detail.
278 * When a scan of a table begins, the nextcheck field is set to a time
279 * that is well into the future.
280 * While scanning, if an expiry time is found that is earlier than the
281 * current nextcheck time, nextcheck is set to that expiry time.
282 * If the flush_time is ever set to a time earlier than the nextcheck
283 * time, the nextcheck time is then set to that flush_time.
285 * A table is then only scanned if the current time is at least
286 * the nextcheck time.
290 static LIST_HEAD(cache_list);
291 static DEFINE_SPINLOCK(cache_list_lock);
292 static struct cache_detail *current_detail;
293 static int current_index;
295 static void do_cache_clean(struct work_struct *work);
296 static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean);
298 static void sunrpc_init_cache_detail(struct cache_detail *cd)
300 rwlock_init(&cd->hash_lock);
301 INIT_LIST_HEAD(&cd->queue);
302 spin_lock(&cache_list_lock);
303 cd->nextcheck = 0;
304 cd->entries = 0;
305 atomic_set(&cd->readers, 0);
306 cd->last_close = 0;
307 cd->last_warn = -1;
308 list_add(&cd->others, &cache_list);
309 spin_unlock(&cache_list_lock);
311 /* start the cleaning process */
312 schedule_delayed_work(&cache_cleaner, 0);
315 static void sunrpc_destroy_cache_detail(struct cache_detail *cd)
317 cache_purge(cd);
318 spin_lock(&cache_list_lock);
319 write_lock(&cd->hash_lock);
320 if (cd->entries || atomic_read(&cd->inuse)) {
321 write_unlock(&cd->hash_lock);
322 spin_unlock(&cache_list_lock);
323 goto out;
325 if (current_detail == cd)
326 current_detail = NULL;
327 list_del_init(&cd->others);
328 write_unlock(&cd->hash_lock);
329 spin_unlock(&cache_list_lock);
330 if (list_empty(&cache_list)) {
331 /* module must be being unloaded so its safe to kill the worker */
332 cancel_delayed_work_sync(&cache_cleaner);
334 return;
335 out:
336 printk(KERN_ERR "nfsd: failed to unregister %s cache\n", cd->name);
339 /* clean cache tries to find something to clean
340 * and cleans it.
341 * It returns 1 if it cleaned something,
342 * 0 if it didn't find anything this time
343 * -1 if it fell off the end of the list.
345 static int cache_clean(void)
347 int rv = 0;
348 struct list_head *next;
350 spin_lock(&cache_list_lock);
352 /* find a suitable table if we don't already have one */
353 while (current_detail == NULL ||
354 current_index >= current_detail->hash_size) {
355 if (current_detail)
356 next = current_detail->others.next;
357 else
358 next = cache_list.next;
359 if (next == &cache_list) {
360 current_detail = NULL;
361 spin_unlock(&cache_list_lock);
362 return -1;
364 current_detail = list_entry(next, struct cache_detail, others);
365 if (current_detail->nextcheck > get_seconds())
366 current_index = current_detail->hash_size;
367 else {
368 current_index = 0;
369 current_detail->nextcheck = get_seconds()+30*60;
373 /* find a non-empty bucket in the table */
374 while (current_detail &&
375 current_index < current_detail->hash_size &&
376 current_detail->hash_table[current_index] == NULL)
377 current_index++;
379 /* find a cleanable entry in the bucket and clean it, or set to next bucket */
381 if (current_detail && current_index < current_detail->hash_size) {
382 struct cache_head *ch, **cp;
383 struct cache_detail *d;
385 write_lock(&current_detail->hash_lock);
387 /* Ok, now to clean this strand */
389 cp = & current_detail->hash_table[current_index];
390 ch = *cp;
391 for (; ch; cp= & ch->next, ch= *cp) {
392 if (current_detail->nextcheck > ch->expiry_time)
393 current_detail->nextcheck = ch->expiry_time+1;
394 if (ch->expiry_time >= get_seconds()
395 && ch->last_refresh >= current_detail->flush_time
397 continue;
398 if (test_and_clear_bit(CACHE_PENDING, &ch->flags))
399 queue_loose(current_detail, ch);
401 if (atomic_read(&ch->ref.refcount) == 1)
402 break;
404 if (ch) {
405 *cp = ch->next;
406 ch->next = NULL;
407 current_detail->entries--;
408 rv = 1;
410 write_unlock(&current_detail->hash_lock);
411 d = current_detail;
412 if (!ch)
413 current_index ++;
414 spin_unlock(&cache_list_lock);
415 if (ch)
416 cache_put(ch, d);
417 } else
418 spin_unlock(&cache_list_lock);
420 return rv;
424 * We want to regularly clean the cache, so we need to schedule some work ...
426 static void do_cache_clean(struct work_struct *work)
428 int delay = 5;
429 if (cache_clean() == -1)
430 delay = round_jiffies_relative(30*HZ);
432 if (list_empty(&cache_list))
433 delay = 0;
435 if (delay)
436 schedule_delayed_work(&cache_cleaner, delay);
441 * Clean all caches promptly. This just calls cache_clean
442 * repeatedly until we are sure that every cache has had a chance to
443 * be fully cleaned
445 void cache_flush(void)
447 while (cache_clean() != -1)
448 cond_resched();
449 while (cache_clean() != -1)
450 cond_resched();
452 EXPORT_SYMBOL_GPL(cache_flush);
454 void cache_purge(struct cache_detail *detail)
456 detail->flush_time = LONG_MAX;
457 detail->nextcheck = get_seconds();
458 cache_flush();
459 detail->flush_time = 1;
461 EXPORT_SYMBOL_GPL(cache_purge);
465 * Deferral and Revisiting of Requests.
467 * If a cache lookup finds a pending entry, we
468 * need to defer the request and revisit it later.
469 * All deferred requests are stored in a hash table,
470 * indexed by "struct cache_head *".
471 * As it may be wasteful to store a whole request
472 * structure, we allow the request to provide a
473 * deferred form, which must contain a
474 * 'struct cache_deferred_req'
475 * This cache_deferred_req contains a method to allow
476 * it to be revisited when cache info is available
479 #define DFR_HASHSIZE (PAGE_SIZE/sizeof(struct list_head))
480 #define DFR_HASH(item) ((((long)item)>>4 ^ (((long)item)>>13)) % DFR_HASHSIZE)
482 #define DFR_MAX 300 /* ??? */
484 static DEFINE_SPINLOCK(cache_defer_lock);
485 static LIST_HEAD(cache_defer_list);
486 static struct list_head cache_defer_hash[DFR_HASHSIZE];
487 static int cache_defer_cnt;
489 static int cache_defer_req(struct cache_req *req, struct cache_head *item)
491 struct cache_deferred_req *dreq;
492 int hash = DFR_HASH(item);
494 if (cache_defer_cnt >= DFR_MAX) {
495 /* too much in the cache, randomly drop this one,
496 * or continue and drop the oldest below
498 if (net_random()&1)
499 return -ETIMEDOUT;
501 dreq = req->defer(req);
502 if (dreq == NULL)
503 return -ETIMEDOUT;
505 dreq->item = item;
507 spin_lock(&cache_defer_lock);
509 list_add(&dreq->recent, &cache_defer_list);
511 if (cache_defer_hash[hash].next == NULL)
512 INIT_LIST_HEAD(&cache_defer_hash[hash]);
513 list_add(&dreq->hash, &cache_defer_hash[hash]);
515 /* it is in, now maybe clean up */
516 dreq = NULL;
517 if (++cache_defer_cnt > DFR_MAX) {
518 dreq = list_entry(cache_defer_list.prev,
519 struct cache_deferred_req, recent);
520 list_del(&dreq->recent);
521 list_del(&dreq->hash);
522 cache_defer_cnt--;
524 spin_unlock(&cache_defer_lock);
526 if (dreq) {
527 /* there was one too many */
528 dreq->revisit(dreq, 1);
530 if (!test_bit(CACHE_PENDING, &item->flags)) {
531 /* must have just been validated... */
532 cache_revisit_request(item);
534 return 0;
537 static void cache_revisit_request(struct cache_head *item)
539 struct cache_deferred_req *dreq;
540 struct list_head pending;
542 struct list_head *lp;
543 int hash = DFR_HASH(item);
545 INIT_LIST_HEAD(&pending);
546 spin_lock(&cache_defer_lock);
548 lp = cache_defer_hash[hash].next;
549 if (lp) {
550 while (lp != &cache_defer_hash[hash]) {
551 dreq = list_entry(lp, struct cache_deferred_req, hash);
552 lp = lp->next;
553 if (dreq->item == item) {
554 list_del(&dreq->hash);
555 list_move(&dreq->recent, &pending);
556 cache_defer_cnt--;
560 spin_unlock(&cache_defer_lock);
562 while (!list_empty(&pending)) {
563 dreq = list_entry(pending.next, struct cache_deferred_req, recent);
564 list_del_init(&dreq->recent);
565 dreq->revisit(dreq, 0);
569 void cache_clean_deferred(void *owner)
571 struct cache_deferred_req *dreq, *tmp;
572 struct list_head pending;
575 INIT_LIST_HEAD(&pending);
576 spin_lock(&cache_defer_lock);
578 list_for_each_entry_safe(dreq, tmp, &cache_defer_list, recent) {
579 if (dreq->owner == owner) {
580 list_del(&dreq->hash);
581 list_move(&dreq->recent, &pending);
582 cache_defer_cnt--;
585 spin_unlock(&cache_defer_lock);
587 while (!list_empty(&pending)) {
588 dreq = list_entry(pending.next, struct cache_deferred_req, recent);
589 list_del_init(&dreq->recent);
590 dreq->revisit(dreq, 1);
595 * communicate with user-space
597 * We have a magic /proc file - /proc/sunrpc/<cachename>/channel.
598 * On read, you get a full request, or block.
599 * On write, an update request is processed.
600 * Poll works if anything to read, and always allows write.
602 * Implemented by linked list of requests. Each open file has
603 * a ->private that also exists in this list. New requests are added
604 * to the end and may wakeup and preceding readers.
605 * New readers are added to the head. If, on read, an item is found with
606 * CACHE_UPCALLING clear, we free it from the list.
610 static DEFINE_SPINLOCK(queue_lock);
611 static DEFINE_MUTEX(queue_io_mutex);
613 struct cache_queue {
614 struct list_head list;
615 int reader; /* if 0, then request */
617 struct cache_request {
618 struct cache_queue q;
619 struct cache_head *item;
620 char * buf;
621 int len;
622 int readers;
624 struct cache_reader {
625 struct cache_queue q;
626 int offset; /* if non-0, we have a refcnt on next request */
629 static ssize_t cache_read(struct file *filp, char __user *buf, size_t count,
630 loff_t *ppos, struct cache_detail *cd)
632 struct cache_reader *rp = filp->private_data;
633 struct cache_request *rq;
634 struct inode *inode = filp->f_path.dentry->d_inode;
635 int err;
637 if (count == 0)
638 return 0;
640 mutex_lock(&inode->i_mutex); /* protect against multiple concurrent
641 * readers on this file */
642 again:
643 spin_lock(&queue_lock);
644 /* need to find next request */
645 while (rp->q.list.next != &cd->queue &&
646 list_entry(rp->q.list.next, struct cache_queue, list)
647 ->reader) {
648 struct list_head *next = rp->q.list.next;
649 list_move(&rp->q.list, next);
651 if (rp->q.list.next == &cd->queue) {
652 spin_unlock(&queue_lock);
653 mutex_unlock(&inode->i_mutex);
654 BUG_ON(rp->offset);
655 return 0;
657 rq = container_of(rp->q.list.next, struct cache_request, q.list);
658 BUG_ON(rq->q.reader);
659 if (rp->offset == 0)
660 rq->readers++;
661 spin_unlock(&queue_lock);
663 if (rp->offset == 0 && !test_bit(CACHE_PENDING, &rq->item->flags)) {
664 err = -EAGAIN;
665 spin_lock(&queue_lock);
666 list_move(&rp->q.list, &rq->q.list);
667 spin_unlock(&queue_lock);
668 } else {
669 if (rp->offset + count > rq->len)
670 count = rq->len - rp->offset;
671 err = -EFAULT;
672 if (copy_to_user(buf, rq->buf + rp->offset, count))
673 goto out;
674 rp->offset += count;
675 if (rp->offset >= rq->len) {
676 rp->offset = 0;
677 spin_lock(&queue_lock);
678 list_move(&rp->q.list, &rq->q.list);
679 spin_unlock(&queue_lock);
681 err = 0;
683 out:
684 if (rp->offset == 0) {
685 /* need to release rq */
686 spin_lock(&queue_lock);
687 rq->readers--;
688 if (rq->readers == 0 &&
689 !test_bit(CACHE_PENDING, &rq->item->flags)) {
690 list_del(&rq->q.list);
691 spin_unlock(&queue_lock);
692 cache_put(rq->item, cd);
693 kfree(rq->buf);
694 kfree(rq);
695 } else
696 spin_unlock(&queue_lock);
698 if (err == -EAGAIN)
699 goto again;
700 mutex_unlock(&inode->i_mutex);
701 return err ? err : count;
704 static ssize_t cache_do_downcall(char *kaddr, const char __user *buf,
705 size_t count, struct cache_detail *cd)
707 ssize_t ret;
709 if (copy_from_user(kaddr, buf, count))
710 return -EFAULT;
711 kaddr[count] = '\0';
712 ret = cd->cache_parse(cd, kaddr, count);
713 if (!ret)
714 ret = count;
715 return ret;
718 static ssize_t cache_slow_downcall(const char __user *buf,
719 size_t count, struct cache_detail *cd)
721 static char write_buf[8192]; /* protected by queue_io_mutex */
722 ssize_t ret = -EINVAL;
724 if (count >= sizeof(write_buf))
725 goto out;
726 mutex_lock(&queue_io_mutex);
727 ret = cache_do_downcall(write_buf, buf, count, cd);
728 mutex_unlock(&queue_io_mutex);
729 out:
730 return ret;
733 static ssize_t cache_downcall(struct address_space *mapping,
734 const char __user *buf,
735 size_t count, struct cache_detail *cd)
737 struct page *page;
738 char *kaddr;
739 ssize_t ret = -ENOMEM;
741 if (count >= PAGE_CACHE_SIZE)
742 goto out_slow;
744 page = find_or_create_page(mapping, 0, GFP_KERNEL);
745 if (!page)
746 goto out_slow;
748 kaddr = kmap(page);
749 ret = cache_do_downcall(kaddr, buf, count, cd);
750 kunmap(page);
751 unlock_page(page);
752 page_cache_release(page);
753 return ret;
754 out_slow:
755 return cache_slow_downcall(buf, count, cd);
758 static ssize_t cache_write(struct file *filp, const char __user *buf,
759 size_t count, loff_t *ppos,
760 struct cache_detail *cd)
762 struct address_space *mapping = filp->f_mapping;
763 struct inode *inode = filp->f_path.dentry->d_inode;
764 ssize_t ret = -EINVAL;
766 if (!cd->cache_parse)
767 goto out;
769 mutex_lock(&inode->i_mutex);
770 ret = cache_downcall(mapping, buf, count, cd);
771 mutex_unlock(&inode->i_mutex);
772 out:
773 return ret;
776 static DECLARE_WAIT_QUEUE_HEAD(queue_wait);
778 static unsigned int cache_poll(struct file *filp, poll_table *wait,
779 struct cache_detail *cd)
781 unsigned int mask;
782 struct cache_reader *rp = filp->private_data;
783 struct cache_queue *cq;
785 poll_wait(filp, &queue_wait, wait);
787 /* alway allow write */
788 mask = POLL_OUT | POLLWRNORM;
790 if (!rp)
791 return mask;
793 spin_lock(&queue_lock);
795 for (cq= &rp->q; &cq->list != &cd->queue;
796 cq = list_entry(cq->list.next, struct cache_queue, list))
797 if (!cq->reader) {
798 mask |= POLLIN | POLLRDNORM;
799 break;
801 spin_unlock(&queue_lock);
802 return mask;
805 static int cache_ioctl(struct inode *ino, struct file *filp,
806 unsigned int cmd, unsigned long arg,
807 struct cache_detail *cd)
809 int len = 0;
810 struct cache_reader *rp = filp->private_data;
811 struct cache_queue *cq;
813 if (cmd != FIONREAD || !rp)
814 return -EINVAL;
816 spin_lock(&queue_lock);
818 /* only find the length remaining in current request,
819 * or the length of the next request
821 for (cq= &rp->q; &cq->list != &cd->queue;
822 cq = list_entry(cq->list.next, struct cache_queue, list))
823 if (!cq->reader) {
824 struct cache_request *cr =
825 container_of(cq, struct cache_request, q);
826 len = cr->len - rp->offset;
827 break;
829 spin_unlock(&queue_lock);
831 return put_user(len, (int __user *)arg);
834 static int cache_open(struct inode *inode, struct file *filp,
835 struct cache_detail *cd)
837 struct cache_reader *rp = NULL;
839 if (!cd || !try_module_get(cd->owner))
840 return -EACCES;
841 nonseekable_open(inode, filp);
842 if (filp->f_mode & FMODE_READ) {
843 rp = kmalloc(sizeof(*rp), GFP_KERNEL);
844 if (!rp)
845 return -ENOMEM;
846 rp->offset = 0;
847 rp->q.reader = 1;
848 atomic_inc(&cd->readers);
849 spin_lock(&queue_lock);
850 list_add(&rp->q.list, &cd->queue);
851 spin_unlock(&queue_lock);
853 filp->private_data = rp;
854 return 0;
857 static int cache_release(struct inode *inode, struct file *filp,
858 struct cache_detail *cd)
860 struct cache_reader *rp = filp->private_data;
862 if (rp) {
863 spin_lock(&queue_lock);
864 if (rp->offset) {
865 struct cache_queue *cq;
866 for (cq= &rp->q; &cq->list != &cd->queue;
867 cq = list_entry(cq->list.next, struct cache_queue, list))
868 if (!cq->reader) {
869 container_of(cq, struct cache_request, q)
870 ->readers--;
871 break;
873 rp->offset = 0;
875 list_del(&rp->q.list);
876 spin_unlock(&queue_lock);
878 filp->private_data = NULL;
879 kfree(rp);
881 cd->last_close = get_seconds();
882 atomic_dec(&cd->readers);
884 module_put(cd->owner);
885 return 0;
890 static void queue_loose(struct cache_detail *detail, struct cache_head *ch)
892 struct cache_queue *cq;
893 spin_lock(&queue_lock);
894 list_for_each_entry(cq, &detail->queue, list)
895 if (!cq->reader) {
896 struct cache_request *cr = container_of(cq, struct cache_request, q);
897 if (cr->item != ch)
898 continue;
899 if (cr->readers != 0)
900 continue;
901 list_del(&cr->q.list);
902 spin_unlock(&queue_lock);
903 cache_put(cr->item, detail);
904 kfree(cr->buf);
905 kfree(cr);
906 return;
908 spin_unlock(&queue_lock);
912 * Support routines for text-based upcalls.
913 * Fields are separated by spaces.
914 * Fields are either mangled to quote space tab newline slosh with slosh
915 * or a hexified with a leading \x
916 * Record is terminated with newline.
920 void qword_add(char **bpp, int *lp, char *str)
922 char *bp = *bpp;
923 int len = *lp;
924 char c;
926 if (len < 0) return;
928 while ((c=*str++) && len)
929 switch(c) {
930 case ' ':
931 case '\t':
932 case '\n':
933 case '\\':
934 if (len >= 4) {
935 *bp++ = '\\';
936 *bp++ = '0' + ((c & 0300)>>6);
937 *bp++ = '0' + ((c & 0070)>>3);
938 *bp++ = '0' + ((c & 0007)>>0);
940 len -= 4;
941 break;
942 default:
943 *bp++ = c;
944 len--;
946 if (c || len <1) len = -1;
947 else {
948 *bp++ = ' ';
949 len--;
951 *bpp = bp;
952 *lp = len;
954 EXPORT_SYMBOL_GPL(qword_add);
956 void qword_addhex(char **bpp, int *lp, char *buf, int blen)
958 char *bp = *bpp;
959 int len = *lp;
961 if (len < 0) return;
963 if (len > 2) {
964 *bp++ = '\\';
965 *bp++ = 'x';
966 len -= 2;
967 while (blen && len >= 2) {
968 unsigned char c = *buf++;
969 *bp++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
970 *bp++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
971 len -= 2;
972 blen--;
975 if (blen || len<1) len = -1;
976 else {
977 *bp++ = ' ';
978 len--;
980 *bpp = bp;
981 *lp = len;
983 EXPORT_SYMBOL_GPL(qword_addhex);
985 static void warn_no_listener(struct cache_detail *detail)
987 if (detail->last_warn != detail->last_close) {
988 detail->last_warn = detail->last_close;
989 if (detail->warn_no_listener)
990 detail->warn_no_listener(detail, detail->last_close != 0);
995 * register an upcall request to user-space and queue it up for read() by the
996 * upcall daemon.
998 * Each request is at most one page long.
1000 int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h,
1001 void (*cache_request)(struct cache_detail *,
1002 struct cache_head *,
1003 char **,
1004 int *))
1007 char *buf;
1008 struct cache_request *crq;
1009 char *bp;
1010 int len;
1012 if (atomic_read(&detail->readers) == 0 &&
1013 detail->last_close < get_seconds() - 30) {
1014 warn_no_listener(detail);
1015 return -EINVAL;
1018 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1019 if (!buf)
1020 return -EAGAIN;
1022 crq = kmalloc(sizeof (*crq), GFP_KERNEL);
1023 if (!crq) {
1024 kfree(buf);
1025 return -EAGAIN;
1028 bp = buf; len = PAGE_SIZE;
1030 cache_request(detail, h, &bp, &len);
1032 if (len < 0) {
1033 kfree(buf);
1034 kfree(crq);
1035 return -EAGAIN;
1037 crq->q.reader = 0;
1038 crq->item = cache_get(h);
1039 crq->buf = buf;
1040 crq->len = PAGE_SIZE - len;
1041 crq->readers = 0;
1042 spin_lock(&queue_lock);
1043 list_add_tail(&crq->q.list, &detail->queue);
1044 spin_unlock(&queue_lock);
1045 wake_up(&queue_wait);
1046 return 0;
1048 EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall);
1051 * parse a message from user-space and pass it
1052 * to an appropriate cache
1053 * Messages are, like requests, separated into fields by
1054 * spaces and dequotes as \xHEXSTRING or embedded \nnn octal
1056 * Message is
1057 * reply cachename expiry key ... content....
1059 * key and content are both parsed by cache
1062 #define isodigit(c) (isdigit(c) && c <= '7')
1063 int qword_get(char **bpp, char *dest, int bufsize)
1065 /* return bytes copied, or -1 on error */
1066 char *bp = *bpp;
1067 int len = 0;
1069 while (*bp == ' ') bp++;
1071 if (bp[0] == '\\' && bp[1] == 'x') {
1072 /* HEX STRING */
1073 bp += 2;
1074 while (isxdigit(bp[0]) && isxdigit(bp[1]) && len < bufsize) {
1075 int byte = isdigit(*bp) ? *bp-'0' : toupper(*bp)-'A'+10;
1076 bp++;
1077 byte <<= 4;
1078 byte |= isdigit(*bp) ? *bp-'0' : toupper(*bp)-'A'+10;
1079 *dest++ = byte;
1080 bp++;
1081 len++;
1083 } else {
1084 /* text with \nnn octal quoting */
1085 while (*bp != ' ' && *bp != '\n' && *bp && len < bufsize-1) {
1086 if (*bp == '\\' &&
1087 isodigit(bp[1]) && (bp[1] <= '3') &&
1088 isodigit(bp[2]) &&
1089 isodigit(bp[3])) {
1090 int byte = (*++bp -'0');
1091 bp++;
1092 byte = (byte << 3) | (*bp++ - '0');
1093 byte = (byte << 3) | (*bp++ - '0');
1094 *dest++ = byte;
1095 len++;
1096 } else {
1097 *dest++ = *bp++;
1098 len++;
1103 if (*bp != ' ' && *bp != '\n' && *bp != '\0')
1104 return -1;
1105 while (*bp == ' ') bp++;
1106 *bpp = bp;
1107 *dest = '\0';
1108 return len;
1110 EXPORT_SYMBOL_GPL(qword_get);
1114 * support /proc/sunrpc/cache/$CACHENAME/content
1115 * as a seqfile.
1116 * We call ->cache_show passing NULL for the item to
1117 * get a header, then pass each real item in the cache
1120 struct handle {
1121 struct cache_detail *cd;
1124 static void *c_start(struct seq_file *m, loff_t *pos)
1125 __acquires(cd->hash_lock)
1127 loff_t n = *pos;
1128 unsigned hash, entry;
1129 struct cache_head *ch;
1130 struct cache_detail *cd = ((struct handle*)m->private)->cd;
1133 read_lock(&cd->hash_lock);
1134 if (!n--)
1135 return SEQ_START_TOKEN;
1136 hash = n >> 32;
1137 entry = n & ((1LL<<32) - 1);
1139 for (ch=cd->hash_table[hash]; ch; ch=ch->next)
1140 if (!entry--)
1141 return ch;
1142 n &= ~((1LL<<32) - 1);
1143 do {
1144 hash++;
1145 n += 1LL<<32;
1146 } while(hash < cd->hash_size &&
1147 cd->hash_table[hash]==NULL);
1148 if (hash >= cd->hash_size)
1149 return NULL;
1150 *pos = n+1;
1151 return cd->hash_table[hash];
1154 static void *c_next(struct seq_file *m, void *p, loff_t *pos)
1156 struct cache_head *ch = p;
1157 int hash = (*pos >> 32);
1158 struct cache_detail *cd = ((struct handle*)m->private)->cd;
1160 if (p == SEQ_START_TOKEN)
1161 hash = 0;
1162 else if (ch->next == NULL) {
1163 hash++;
1164 *pos += 1LL<<32;
1165 } else {
1166 ++*pos;
1167 return ch->next;
1169 *pos &= ~((1LL<<32) - 1);
1170 while (hash < cd->hash_size &&
1171 cd->hash_table[hash] == NULL) {
1172 hash++;
1173 *pos += 1LL<<32;
1175 if (hash >= cd->hash_size)
1176 return NULL;
1177 ++*pos;
1178 return cd->hash_table[hash];
1181 static void c_stop(struct seq_file *m, void *p)
1182 __releases(cd->hash_lock)
1184 struct cache_detail *cd = ((struct handle*)m->private)->cd;
1185 read_unlock(&cd->hash_lock);
1188 static int c_show(struct seq_file *m, void *p)
1190 struct cache_head *cp = p;
1191 struct cache_detail *cd = ((struct handle*)m->private)->cd;
1193 if (p == SEQ_START_TOKEN)
1194 return cd->cache_show(m, cd, NULL);
1196 ifdebug(CACHE)
1197 seq_printf(m, "# expiry=%ld refcnt=%d flags=%lx\n",
1198 cp->expiry_time, atomic_read(&cp->ref.refcount), cp->flags);
1199 cache_get(cp);
1200 if (cache_check(cd, cp, NULL))
1201 /* cache_check does a cache_put on failure */
1202 seq_printf(m, "# ");
1203 else
1204 cache_put(cp, cd);
1206 return cd->cache_show(m, cd, cp);
1209 static const struct seq_operations cache_content_op = {
1210 .start = c_start,
1211 .next = c_next,
1212 .stop = c_stop,
1213 .show = c_show,
1216 static int content_open(struct inode *inode, struct file *file,
1217 struct cache_detail *cd)
1219 struct handle *han;
1221 if (!cd || !try_module_get(cd->owner))
1222 return -EACCES;
1223 han = __seq_open_private(file, &cache_content_op, sizeof(*han));
1224 if (han == NULL)
1225 return -ENOMEM;
1227 han->cd = cd;
1228 return 0;
1231 static int content_release(struct inode *inode, struct file *file,
1232 struct cache_detail *cd)
1234 int ret = seq_release_private(inode, file);
1235 module_put(cd->owner);
1236 return ret;
1239 static int open_flush(struct inode *inode, struct file *file,
1240 struct cache_detail *cd)
1242 if (!cd || !try_module_get(cd->owner))
1243 return -EACCES;
1244 return nonseekable_open(inode, file);
1247 static int release_flush(struct inode *inode, struct file *file,
1248 struct cache_detail *cd)
1250 module_put(cd->owner);
1251 return 0;
1254 static ssize_t read_flush(struct file *file, char __user *buf,
1255 size_t count, loff_t *ppos,
1256 struct cache_detail *cd)
1258 char tbuf[20];
1259 unsigned long p = *ppos;
1260 size_t len;
1262 sprintf(tbuf, "%lu\n", cd->flush_time);
1263 len = strlen(tbuf);
1264 if (p >= len)
1265 return 0;
1266 len -= p;
1267 if (len > count)
1268 len = count;
1269 if (copy_to_user(buf, (void*)(tbuf+p), len))
1270 return -EFAULT;
1271 *ppos += len;
1272 return len;
1275 static ssize_t write_flush(struct file *file, const char __user *buf,
1276 size_t count, loff_t *ppos,
1277 struct cache_detail *cd)
1279 char tbuf[20];
1280 char *ep;
1281 long flushtime;
1282 if (*ppos || count > sizeof(tbuf)-1)
1283 return -EINVAL;
1284 if (copy_from_user(tbuf, buf, count))
1285 return -EFAULT;
1286 tbuf[count] = 0;
1287 flushtime = simple_strtoul(tbuf, &ep, 0);
1288 if (*ep && *ep != '\n')
1289 return -EINVAL;
1291 cd->flush_time = flushtime;
1292 cd->nextcheck = get_seconds();
1293 cache_flush();
1295 *ppos += count;
1296 return count;
1299 static ssize_t cache_read_procfs(struct file *filp, char __user *buf,
1300 size_t count, loff_t *ppos)
1302 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1304 return cache_read(filp, buf, count, ppos, cd);
1307 static ssize_t cache_write_procfs(struct file *filp, const char __user *buf,
1308 size_t count, loff_t *ppos)
1310 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1312 return cache_write(filp, buf, count, ppos, cd);
1315 static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)
1317 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1319 return cache_poll(filp, wait, cd);
1322 static int cache_ioctl_procfs(struct inode *inode, struct file *filp,
1323 unsigned int cmd, unsigned long arg)
1325 struct cache_detail *cd = PDE(inode)->data;
1327 return cache_ioctl(inode, filp, cmd, arg, cd);
1330 static int cache_open_procfs(struct inode *inode, struct file *filp)
1332 struct cache_detail *cd = PDE(inode)->data;
1334 return cache_open(inode, filp, cd);
1337 static int cache_release_procfs(struct inode *inode, struct file *filp)
1339 struct cache_detail *cd = PDE(inode)->data;
1341 return cache_release(inode, filp, cd);
1344 static const struct file_operations cache_file_operations_procfs = {
1345 .owner = THIS_MODULE,
1346 .llseek = no_llseek,
1347 .read = cache_read_procfs,
1348 .write = cache_write_procfs,
1349 .poll = cache_poll_procfs,
1350 .ioctl = cache_ioctl_procfs, /* for FIONREAD */
1351 .open = cache_open_procfs,
1352 .release = cache_release_procfs,
1355 static int content_open_procfs(struct inode *inode, struct file *filp)
1357 struct cache_detail *cd = PDE(inode)->data;
1359 return content_open(inode, filp, cd);
1362 static int content_release_procfs(struct inode *inode, struct file *filp)
1364 struct cache_detail *cd = PDE(inode)->data;
1366 return content_release(inode, filp, cd);
1369 static const struct file_operations content_file_operations_procfs = {
1370 .open = content_open_procfs,
1371 .read = seq_read,
1372 .llseek = seq_lseek,
1373 .release = content_release_procfs,
1376 static int open_flush_procfs(struct inode *inode, struct file *filp)
1378 struct cache_detail *cd = PDE(inode)->data;
1380 return open_flush(inode, filp, cd);
1383 static int release_flush_procfs(struct inode *inode, struct file *filp)
1385 struct cache_detail *cd = PDE(inode)->data;
1387 return release_flush(inode, filp, cd);
1390 static ssize_t read_flush_procfs(struct file *filp, char __user *buf,
1391 size_t count, loff_t *ppos)
1393 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1395 return read_flush(filp, buf, count, ppos, cd);
1398 static ssize_t write_flush_procfs(struct file *filp,
1399 const char __user *buf,
1400 size_t count, loff_t *ppos)
1402 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1404 return write_flush(filp, buf, count, ppos, cd);
1407 static const struct file_operations cache_flush_operations_procfs = {
1408 .open = open_flush_procfs,
1409 .read = read_flush_procfs,
1410 .write = write_flush_procfs,
1411 .release = release_flush_procfs,
1414 static void remove_cache_proc_entries(struct cache_detail *cd)
1416 if (cd->u.procfs.proc_ent == NULL)
1417 return;
1418 if (cd->u.procfs.flush_ent)
1419 remove_proc_entry("flush", cd->u.procfs.proc_ent);
1420 if (cd->u.procfs.channel_ent)
1421 remove_proc_entry("channel", cd->u.procfs.proc_ent);
1422 if (cd->u.procfs.content_ent)
1423 remove_proc_entry("content", cd->u.procfs.proc_ent);
1424 cd->u.procfs.proc_ent = NULL;
1425 remove_proc_entry(cd->name, proc_net_rpc);
1428 #ifdef CONFIG_PROC_FS
1429 static int create_cache_proc_entries(struct cache_detail *cd)
1431 struct proc_dir_entry *p;
1433 cd->u.procfs.proc_ent = proc_mkdir(cd->name, proc_net_rpc);
1434 if (cd->u.procfs.proc_ent == NULL)
1435 goto out_nomem;
1436 cd->u.procfs.channel_ent = NULL;
1437 cd->u.procfs.content_ent = NULL;
1439 p = proc_create_data("flush", S_IFREG|S_IRUSR|S_IWUSR,
1440 cd->u.procfs.proc_ent,
1441 &cache_flush_operations_procfs, cd);
1442 cd->u.procfs.flush_ent = p;
1443 if (p == NULL)
1444 goto out_nomem;
1446 if (cd->cache_upcall || cd->cache_parse) {
1447 p = proc_create_data("channel", S_IFREG|S_IRUSR|S_IWUSR,
1448 cd->u.procfs.proc_ent,
1449 &cache_file_operations_procfs, cd);
1450 cd->u.procfs.channel_ent = p;
1451 if (p == NULL)
1452 goto out_nomem;
1454 if (cd->cache_show) {
1455 p = proc_create_data("content", S_IFREG|S_IRUSR|S_IWUSR,
1456 cd->u.procfs.proc_ent,
1457 &content_file_operations_procfs, cd);
1458 cd->u.procfs.content_ent = p;
1459 if (p == NULL)
1460 goto out_nomem;
1462 return 0;
1463 out_nomem:
1464 remove_cache_proc_entries(cd);
1465 return -ENOMEM;
1467 #else /* CONFIG_PROC_FS */
1468 static int create_cache_proc_entries(struct cache_detail *cd)
1470 return 0;
1472 #endif
1474 int cache_register(struct cache_detail *cd)
1476 int ret;
1478 sunrpc_init_cache_detail(cd);
1479 ret = create_cache_proc_entries(cd);
1480 if (ret)
1481 sunrpc_destroy_cache_detail(cd);
1482 return ret;
1484 EXPORT_SYMBOL_GPL(cache_register);
1486 void cache_unregister(struct cache_detail *cd)
1488 remove_cache_proc_entries(cd);
1489 sunrpc_destroy_cache_detail(cd);
1491 EXPORT_SYMBOL_GPL(cache_unregister);
1493 static ssize_t cache_read_pipefs(struct file *filp, char __user *buf,
1494 size_t count, loff_t *ppos)
1496 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1498 return cache_read(filp, buf, count, ppos, cd);
1501 static ssize_t cache_write_pipefs(struct file *filp, const char __user *buf,
1502 size_t count, loff_t *ppos)
1504 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1506 return cache_write(filp, buf, count, ppos, cd);
1509 static unsigned int cache_poll_pipefs(struct file *filp, poll_table *wait)
1511 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1513 return cache_poll(filp, wait, cd);
1516 static int cache_ioctl_pipefs(struct inode *inode, struct file *filp,
1517 unsigned int cmd, unsigned long arg)
1519 struct cache_detail *cd = RPC_I(inode)->private;
1521 return cache_ioctl(inode, filp, cmd, arg, cd);
1524 static int cache_open_pipefs(struct inode *inode, struct file *filp)
1526 struct cache_detail *cd = RPC_I(inode)->private;
1528 return cache_open(inode, filp, cd);
1531 static int cache_release_pipefs(struct inode *inode, struct file *filp)
1533 struct cache_detail *cd = RPC_I(inode)->private;
1535 return cache_release(inode, filp, cd);
1538 const struct file_operations cache_file_operations_pipefs = {
1539 .owner = THIS_MODULE,
1540 .llseek = no_llseek,
1541 .read = cache_read_pipefs,
1542 .write = cache_write_pipefs,
1543 .poll = cache_poll_pipefs,
1544 .ioctl = cache_ioctl_pipefs, /* for FIONREAD */
1545 .open = cache_open_pipefs,
1546 .release = cache_release_pipefs,
1549 static int content_open_pipefs(struct inode *inode, struct file *filp)
1551 struct cache_detail *cd = RPC_I(inode)->private;
1553 return content_open(inode, filp, cd);
1556 static int content_release_pipefs(struct inode *inode, struct file *filp)
1558 struct cache_detail *cd = RPC_I(inode)->private;
1560 return content_release(inode, filp, cd);
1563 const struct file_operations content_file_operations_pipefs = {
1564 .open = content_open_pipefs,
1565 .read = seq_read,
1566 .llseek = seq_lseek,
1567 .release = content_release_pipefs,
1570 static int open_flush_pipefs(struct inode *inode, struct file *filp)
1572 struct cache_detail *cd = RPC_I(inode)->private;
1574 return open_flush(inode, filp, cd);
1577 static int release_flush_pipefs(struct inode *inode, struct file *filp)
1579 struct cache_detail *cd = RPC_I(inode)->private;
1581 return release_flush(inode, filp, cd);
1584 static ssize_t read_flush_pipefs(struct file *filp, char __user *buf,
1585 size_t count, loff_t *ppos)
1587 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1589 return read_flush(filp, buf, count, ppos, cd);
1592 static ssize_t write_flush_pipefs(struct file *filp,
1593 const char __user *buf,
1594 size_t count, loff_t *ppos)
1596 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1598 return write_flush(filp, buf, count, ppos, cd);
1601 const struct file_operations cache_flush_operations_pipefs = {
1602 .open = open_flush_pipefs,
1603 .read = read_flush_pipefs,
1604 .write = write_flush_pipefs,
1605 .release = release_flush_pipefs,
1608 int sunrpc_cache_register_pipefs(struct dentry *parent,
1609 const char *name, mode_t umode,
1610 struct cache_detail *cd)
1612 struct qstr q;
1613 struct dentry *dir;
1614 int ret = 0;
1616 sunrpc_init_cache_detail(cd);
1617 q.name = name;
1618 q.len = strlen(name);
1619 q.hash = full_name_hash(q.name, q.len);
1620 dir = rpc_create_cache_dir(parent, &q, umode, cd);
1621 if (!IS_ERR(dir))
1622 cd->u.pipefs.dir = dir;
1623 else {
1624 sunrpc_destroy_cache_detail(cd);
1625 ret = PTR_ERR(dir);
1627 return ret;
1629 EXPORT_SYMBOL_GPL(sunrpc_cache_register_pipefs);
1631 void sunrpc_cache_unregister_pipefs(struct cache_detail *cd)
1633 rpc_remove_cache_dir(cd->u.pipefs.dir);
1634 cd->u.pipefs.dir = NULL;
1635 sunrpc_destroy_cache_detail(cd);
1637 EXPORT_SYMBOL_GPL(sunrpc_cache_unregister_pipefs);