aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc/cache.c
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2009-08-10 17:45:58 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2009-08-10 17:45:58 -0400
commitf884dcaead5f17bf586ac5fe6a3ad07b5203616a (patch)
tree2406444df167f1d67b38733b544f2e2a96c778c7 /net/sunrpc/cache.c
parent976a6f921cad26651d25e73826c05c7a023f5fa4 (diff)
parent8854e82d9accc80f43c0bc3ff06b5979ac858185 (diff)
Merge branch 'sunrpc_cache-for-2.6.32' into nfs-for-2.6.32
Diffstat (limited to 'net/sunrpc/cache.c')
-rw-r--r--net/sunrpc/cache.c550
1 files changed, 401 insertions, 149 deletions
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index ff0c23053d2f..db7720e453c3 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -27,10 +27,12 @@
27#include <linux/net.h> 27#include <linux/net.h>
28#include <linux/workqueue.h> 28#include <linux/workqueue.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/pagemap.h>
30#include <asm/ioctls.h> 31#include <asm/ioctls.h>
31#include <linux/sunrpc/types.h> 32#include <linux/sunrpc/types.h>
32#include <linux/sunrpc/cache.h> 33#include <linux/sunrpc/cache.h>
33#include <linux/sunrpc/stats.h> 34#include <linux/sunrpc/stats.h>
35#include <linux/sunrpc/rpc_pipe_fs.h>
34 36
35#define RPCDBG_FACILITY RPCDBG_CACHE 37#define RPCDBG_FACILITY RPCDBG_CACHE
36 38
@@ -175,7 +177,13 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
175} 177}
176EXPORT_SYMBOL_GPL(sunrpc_cache_update); 178EXPORT_SYMBOL_GPL(sunrpc_cache_update);
177 179
178static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h); 180static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
181{
182 if (!cd->cache_upcall)
183 return -EINVAL;
184 return cd->cache_upcall(cd, h);
185}
186
179/* 187/*
180 * This is the generic cache management routine for all 188 * This is the generic cache management routine for all
181 * the authentication caches. 189 * the authentication caches.
@@ -284,76 +292,11 @@ static DEFINE_SPINLOCK(cache_list_lock);
284static struct cache_detail *current_detail; 292static struct cache_detail *current_detail;
285static int current_index; 293static int current_index;
286 294
287static const struct file_operations cache_file_operations;
288static const struct file_operations content_file_operations;
289static const struct file_operations cache_flush_operations;
290
291static void do_cache_clean(struct work_struct *work); 295static void do_cache_clean(struct work_struct *work);
292static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean); 296static DECLARE_DELAYED_WORK(cache_cleaner, do_cache_clean);
293 297
294static void remove_cache_proc_entries(struct cache_detail *cd) 298static void sunrpc_init_cache_detail(struct cache_detail *cd)
295{
296 if (cd->proc_ent == NULL)
297 return;
298 if (cd->flush_ent)
299 remove_proc_entry("flush", cd->proc_ent);
300 if (cd->channel_ent)
301 remove_proc_entry("channel", cd->proc_ent);
302 if (cd->content_ent)
303 remove_proc_entry("content", cd->proc_ent);
304 cd->proc_ent = NULL;
305 remove_proc_entry(cd->name, proc_net_rpc);
306}
307
308#ifdef CONFIG_PROC_FS
309static int create_cache_proc_entries(struct cache_detail *cd)
310{
311 struct proc_dir_entry *p;
312
313 cd->proc_ent = proc_mkdir(cd->name, proc_net_rpc);
314 if (cd->proc_ent == NULL)
315 goto out_nomem;
316 cd->channel_ent = cd->content_ent = NULL;
317
318 p = proc_create_data("flush", S_IFREG|S_IRUSR|S_IWUSR,
319 cd->proc_ent, &cache_flush_operations, cd);
320 cd->flush_ent = p;
321 if (p == NULL)
322 goto out_nomem;
323
324 if (cd->cache_request || cd->cache_parse) {
325 p = proc_create_data("channel", S_IFREG|S_IRUSR|S_IWUSR,
326 cd->proc_ent, &cache_file_operations, cd);
327 cd->channel_ent = p;
328 if (p == NULL)
329 goto out_nomem;
330 }
331 if (cd->cache_show) {
332 p = proc_create_data("content", S_IFREG|S_IRUSR|S_IWUSR,
333 cd->proc_ent, &content_file_operations, cd);
334 cd->content_ent = p;
335 if (p == NULL)
336 goto out_nomem;
337 }
338 return 0;
339out_nomem:
340 remove_cache_proc_entries(cd);
341 return -ENOMEM;
342}
343#else /* CONFIG_PROC_FS */
344static int create_cache_proc_entries(struct cache_detail *cd)
345{
346 return 0;
347}
348#endif
349
350int cache_register(struct cache_detail *cd)
351{ 299{
352 int ret;
353
354 ret = create_cache_proc_entries(cd);
355 if (ret)
356 return ret;
357 rwlock_init(&cd->hash_lock); 300 rwlock_init(&cd->hash_lock);
358 INIT_LIST_HEAD(&cd->queue); 301 INIT_LIST_HEAD(&cd->queue);
359 spin_lock(&cache_list_lock); 302 spin_lock(&cache_list_lock);
@@ -367,11 +310,9 @@ int cache_register(struct cache_detail *cd)
367 310
368 /* start the cleaning process */ 311 /* start the cleaning process */
369 schedule_delayed_work(&cache_cleaner, 0); 312 schedule_delayed_work(&cache_cleaner, 0);
370 return 0;
371} 313}
372EXPORT_SYMBOL_GPL(cache_register);
373 314
374void cache_unregister(struct cache_detail *cd) 315static void sunrpc_destroy_cache_detail(struct cache_detail *cd)
375{ 316{
376 cache_purge(cd); 317 cache_purge(cd);
377 spin_lock(&cache_list_lock); 318 spin_lock(&cache_list_lock);
@@ -386,7 +327,6 @@ void cache_unregister(struct cache_detail *cd)
386 list_del_init(&cd->others); 327 list_del_init(&cd->others);
387 write_unlock(&cd->hash_lock); 328 write_unlock(&cd->hash_lock);
388 spin_unlock(&cache_list_lock); 329 spin_unlock(&cache_list_lock);
389 remove_cache_proc_entries(cd);
390 if (list_empty(&cache_list)) { 330 if (list_empty(&cache_list)) {
391 /* module must be being unloaded so its safe to kill the worker */ 331 /* module must be being unloaded so its safe to kill the worker */
392 cancel_delayed_work_sync(&cache_cleaner); 332 cancel_delayed_work_sync(&cache_cleaner);
@@ -395,7 +335,6 @@ void cache_unregister(struct cache_detail *cd)
395out: 335out:
396 printk(KERN_ERR "nfsd: failed to unregister %s cache\n", cd->name); 336 printk(KERN_ERR "nfsd: failed to unregister %s cache\n", cd->name);
397} 337}
398EXPORT_SYMBOL_GPL(cache_unregister);
399 338
400/* clean cache tries to find something to clean 339/* clean cache tries to find something to clean
401 * and cleans it. 340 * and cleans it.
@@ -687,18 +626,18 @@ struct cache_reader {
687 int offset; /* if non-0, we have a refcnt on next request */ 626 int offset; /* if non-0, we have a refcnt on next request */
688}; 627};
689 628
690static ssize_t 629static ssize_t cache_read(struct file *filp, char __user *buf, size_t count,
691cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos) 630 loff_t *ppos, struct cache_detail *cd)
692{ 631{
693 struct cache_reader *rp = filp->private_data; 632 struct cache_reader *rp = filp->private_data;
694 struct cache_request *rq; 633 struct cache_request *rq;
695 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; 634 struct inode *inode = filp->f_path.dentry->d_inode;
696 int err; 635 int err;
697 636
698 if (count == 0) 637 if (count == 0)
699 return 0; 638 return 0;
700 639
701 mutex_lock(&queue_io_mutex); /* protect against multiple concurrent 640 mutex_lock(&inode->i_mutex); /* protect against multiple concurrent
702 * readers on this file */ 641 * readers on this file */
703 again: 642 again:
704 spin_lock(&queue_lock); 643 spin_lock(&queue_lock);
@@ -711,7 +650,7 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
711 } 650 }
712 if (rp->q.list.next == &cd->queue) { 651 if (rp->q.list.next == &cd->queue) {
713 spin_unlock(&queue_lock); 652 spin_unlock(&queue_lock);
714 mutex_unlock(&queue_io_mutex); 653 mutex_unlock(&inode->i_mutex);
715 BUG_ON(rp->offset); 654 BUG_ON(rp->offset);
716 return 0; 655 return 0;
717 } 656 }
@@ -758,49 +697,90 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
758 } 697 }
759 if (err == -EAGAIN) 698 if (err == -EAGAIN)
760 goto again; 699 goto again;
761 mutex_unlock(&queue_io_mutex); 700 mutex_unlock(&inode->i_mutex);
762 return err ? err : count; 701 return err ? err : count;
763} 702}
764 703
765static char write_buf[8192]; /* protected by queue_io_mutex */ 704static ssize_t cache_do_downcall(char *kaddr, const char __user *buf,
705 size_t count, struct cache_detail *cd)
706{
707 ssize_t ret;
708
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;
716}
766 717
767static ssize_t 718static ssize_t cache_slow_downcall(const char __user *buf,
768cache_write(struct file *filp, const char __user *buf, size_t count, 719 size_t count, struct cache_detail *cd)
769 loff_t *ppos)
770{ 720{
771 int err; 721 static char write_buf[8192]; /* protected by queue_io_mutex */
772 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data; 722 ssize_t ret = -EINVAL;
773 723
774 if (count == 0)
775 return 0;
776 if (count >= sizeof(write_buf)) 724 if (count >= sizeof(write_buf))
777 return -EINVAL; 725 goto out;
778
779 mutex_lock(&queue_io_mutex); 726 mutex_lock(&queue_io_mutex);
727 ret = cache_do_downcall(write_buf, buf, count, cd);
728 mutex_unlock(&queue_io_mutex);
729out:
730 return ret;
731}
780 732
781 if (copy_from_user(write_buf, buf, count)) { 733static ssize_t cache_downcall(struct address_space *mapping,
782 mutex_unlock(&queue_io_mutex); 734 const char __user *buf,
783 return -EFAULT; 735 size_t count, struct cache_detail *cd)
784 } 736{
785 write_buf[count] = '\0'; 737 struct page *page;
786 if (cd->cache_parse) 738 char *kaddr;
787 err = cd->cache_parse(cd, write_buf, count); 739 ssize_t ret = -ENOMEM;
788 else 740
789 err = -EINVAL; 741 if (count >= PAGE_CACHE_SIZE)
742 goto out_slow;
743
744 page = find_or_create_page(mapping, 0, GFP_KERNEL);
745 if (!page)
746 goto out_slow;
747
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;
754out_slow:
755 return cache_slow_downcall(buf, count, cd);
756}
790 757
791 mutex_unlock(&queue_io_mutex); 758static ssize_t cache_write(struct file *filp, const char __user *buf,
792 return err ? err : count; 759 size_t count, loff_t *ppos,
760 struct cache_detail *cd)
761{
762 struct address_space *mapping = filp->f_mapping;
763 struct inode *inode = filp->f_path.dentry->d_inode;
764 ssize_t ret = -EINVAL;
765
766 if (!cd->cache_parse)
767 goto out;
768
769 mutex_lock(&inode->i_mutex);
770 ret = cache_downcall(mapping, buf, count, cd);
771 mutex_unlock(&inode->i_mutex);
772out:
773 return ret;
793} 774}
794 775
795static DECLARE_WAIT_QUEUE_HEAD(queue_wait); 776static DECLARE_WAIT_QUEUE_HEAD(queue_wait);
796 777
797static unsigned int 778static unsigned int cache_poll(struct file *filp, poll_table *wait,
798cache_poll(struct file *filp, poll_table *wait) 779 struct cache_detail *cd)
799{ 780{
800 unsigned int mask; 781 unsigned int mask;
801 struct cache_reader *rp = filp->private_data; 782 struct cache_reader *rp = filp->private_data;
802 struct cache_queue *cq; 783 struct cache_queue *cq;
803 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
804 784
805 poll_wait(filp, &queue_wait, wait); 785 poll_wait(filp, &queue_wait, wait);
806 786
@@ -822,14 +802,13 @@ cache_poll(struct file *filp, poll_table *wait)
822 return mask; 802 return mask;
823} 803}
824 804
825static int 805static int cache_ioctl(struct inode *ino, struct file *filp,
826cache_ioctl(struct inode *ino, struct file *filp, 806 unsigned int cmd, unsigned long arg,
827 unsigned int cmd, unsigned long arg) 807 struct cache_detail *cd)
828{ 808{
829 int len = 0; 809 int len = 0;
830 struct cache_reader *rp = filp->private_data; 810 struct cache_reader *rp = filp->private_data;
831 struct cache_queue *cq; 811 struct cache_queue *cq;
832 struct cache_detail *cd = PDE(ino)->data;
833 812
834 if (cmd != FIONREAD || !rp) 813 if (cmd != FIONREAD || !rp)
835 return -EINVAL; 814 return -EINVAL;
@@ -852,15 +831,13 @@ cache_ioctl(struct inode *ino, struct file *filp,
852 return put_user(len, (int __user *)arg); 831 return put_user(len, (int __user *)arg);
853} 832}
854 833
855static int 834static int cache_open(struct inode *inode, struct file *filp,
856cache_open(struct inode *inode, struct file *filp) 835 struct cache_detail *cd)
857{ 836{
858 struct cache_reader *rp = NULL; 837 struct cache_reader *rp = NULL;
859 838
860 nonseekable_open(inode, filp); 839 nonseekable_open(inode, filp);
861 if (filp->f_mode & FMODE_READ) { 840 if (filp->f_mode & FMODE_READ) {
862 struct cache_detail *cd = PDE(inode)->data;
863
864 rp = kmalloc(sizeof(*rp), GFP_KERNEL); 841 rp = kmalloc(sizeof(*rp), GFP_KERNEL);
865 if (!rp) 842 if (!rp)
866 return -ENOMEM; 843 return -ENOMEM;
@@ -875,11 +852,10 @@ cache_open(struct inode *inode, struct file *filp)
875 return 0; 852 return 0;
876} 853}
877 854
878static int 855static int cache_release(struct inode *inode, struct file *filp,
879cache_release(struct inode *inode, struct file *filp) 856 struct cache_detail *cd)
880{ 857{
881 struct cache_reader *rp = filp->private_data; 858 struct cache_reader *rp = filp->private_data;
882 struct cache_detail *cd = PDE(inode)->data;
883 859
884 if (rp) { 860 if (rp) {
885 spin_lock(&queue_lock); 861 spin_lock(&queue_lock);
@@ -908,18 +884,6 @@ cache_release(struct inode *inode, struct file *filp)
908 884
909 885
910 886
911static const struct file_operations cache_file_operations = {
912 .owner = THIS_MODULE,
913 .llseek = no_llseek,
914 .read = cache_read,
915 .write = cache_write,
916 .poll = cache_poll,
917 .ioctl = cache_ioctl, /* for FIONREAD */
918 .open = cache_open,
919 .release = cache_release,
920};
921
922
923static void queue_loose(struct cache_detail *detail, struct cache_head *ch) 887static void queue_loose(struct cache_detail *detail, struct cache_head *ch)
924{ 888{
925 struct cache_queue *cq; 889 struct cache_queue *cq;
@@ -1020,15 +984,21 @@ static void warn_no_listener(struct cache_detail *detail)
1020 if (detail->last_warn != detail->last_close) { 984 if (detail->last_warn != detail->last_close) {
1021 detail->last_warn = detail->last_close; 985 detail->last_warn = detail->last_close;
1022 if (detail->warn_no_listener) 986 if (detail->warn_no_listener)
1023 detail->warn_no_listener(detail); 987 detail->warn_no_listener(detail, detail->last_close != 0);
1024 } 988 }
1025} 989}
1026 990
1027/* 991/*
1028 * register an upcall request to user-space. 992 * register an upcall request to user-space and queue it up for read() by the
993 * upcall daemon.
994 *
1029 * Each request is at most one page long. 995 * Each request is at most one page long.
1030 */ 996 */
1031static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h) 997int sunrpc_cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h,
998 void (*cache_request)(struct cache_detail *,
999 struct cache_head *,
1000 char **,
1001 int *))
1032{ 1002{
1033 1003
1034 char *buf; 1004 char *buf;
@@ -1036,9 +1006,6 @@ static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h)
1036 char *bp; 1006 char *bp;
1037 int len; 1007 int len;
1038 1008
1039 if (detail->cache_request == NULL)
1040 return -EINVAL;
1041
1042 if (atomic_read(&detail->readers) == 0 && 1009 if (atomic_read(&detail->readers) == 0 &&
1043 detail->last_close < get_seconds() - 30) { 1010 detail->last_close < get_seconds() - 30) {
1044 warn_no_listener(detail); 1011 warn_no_listener(detail);
@@ -1057,7 +1024,7 @@ static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h)
1057 1024
1058 bp = buf; len = PAGE_SIZE; 1025 bp = buf; len = PAGE_SIZE;
1059 1026
1060 detail->cache_request(detail, h, &bp, &len); 1027 cache_request(detail, h, &bp, &len);
1061 1028
1062 if (len < 0) { 1029 if (len < 0) {
1063 kfree(buf); 1030 kfree(buf);
@@ -1075,6 +1042,7 @@ static int cache_make_upcall(struct cache_detail *detail, struct cache_head *h)
1075 wake_up(&queue_wait); 1042 wake_up(&queue_wait);
1076 return 0; 1043 return 0;
1077} 1044}
1045EXPORT_SYMBOL_GPL(sunrpc_cache_pipe_upcall);
1078 1046
1079/* 1047/*
1080 * parse a message from user-space and pass it 1048 * parse a message from user-space and pass it
@@ -1242,10 +1210,10 @@ static const struct seq_operations cache_content_op = {
1242 .show = c_show, 1210 .show = c_show,
1243}; 1211};
1244 1212
1245static int content_open(struct inode *inode, struct file *file) 1213static int content_open(struct inode *inode, struct file *file,
1214 struct cache_detail *cd)
1246{ 1215{
1247 struct handle *han; 1216 struct handle *han;
1248 struct cache_detail *cd = PDE(inode)->data;
1249 1217
1250 han = __seq_open_private(file, &cache_content_op, sizeof(*han)); 1218 han = __seq_open_private(file, &cache_content_op, sizeof(*han));
1251 if (han == NULL) 1219 if (han == NULL)
@@ -1255,17 +1223,10 @@ static int content_open(struct inode *inode, struct file *file)
1255 return 0; 1223 return 0;
1256} 1224}
1257 1225
1258static const struct file_operations content_file_operations = {
1259 .open = content_open,
1260 .read = seq_read,
1261 .llseek = seq_lseek,
1262 .release = seq_release_private,
1263};
1264
1265static ssize_t read_flush(struct file *file, char __user *buf, 1226static ssize_t read_flush(struct file *file, char __user *buf,
1266 size_t count, loff_t *ppos) 1227 size_t count, loff_t *ppos,
1228 struct cache_detail *cd)
1267{ 1229{
1268 struct cache_detail *cd = PDE(file->f_path.dentry->d_inode)->data;
1269 char tbuf[20]; 1230 char tbuf[20];
1270 unsigned long p = *ppos; 1231 unsigned long p = *ppos;
1271 size_t len; 1232 size_t len;
@@ -1283,10 +1244,10 @@ static ssize_t read_flush(struct file *file, char __user *buf,
1283 return len; 1244 return len;
1284} 1245}
1285 1246
1286static ssize_t write_flush(struct file * file, const char __user * buf, 1247static ssize_t write_flush(struct file *file, const char __user *buf,
1287 size_t count, loff_t *ppos) 1248 size_t count, loff_t *ppos,
1249 struct cache_detail *cd)
1288{ 1250{
1289 struct cache_detail *cd = PDE(file->f_path.dentry->d_inode)->data;
1290 char tbuf[20]; 1251 char tbuf[20];
1291 char *ep; 1252 char *ep;
1292 long flushtime; 1253 long flushtime;
@@ -1307,8 +1268,299 @@ static ssize_t write_flush(struct file * file, const char __user * buf,
1307 return count; 1268 return count;
1308} 1269}
1309 1270
1310static const struct file_operations cache_flush_operations = { 1271static ssize_t cache_read_procfs(struct file *filp, char __user *buf,
1272 size_t count, loff_t *ppos)
1273{
1274 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1275
1276 return cache_read(filp, buf, count, ppos, cd);
1277}
1278
1279static ssize_t cache_write_procfs(struct file *filp, const char __user *buf,
1280 size_t count, loff_t *ppos)
1281{
1282 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1283
1284 return cache_write(filp, buf, count, ppos, cd);
1285}
1286
1287static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)
1288{
1289 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1290
1291 return cache_poll(filp, wait, cd);
1292}
1293
1294static int cache_ioctl_procfs(struct inode *inode, struct file *filp,
1295 unsigned int cmd, unsigned long arg)
1296{
1297 struct cache_detail *cd = PDE(inode)->data;
1298
1299 return cache_ioctl(inode, filp, cmd, arg, cd);
1300}
1301
1302static int cache_open_procfs(struct inode *inode, struct file *filp)
1303{
1304 struct cache_detail *cd = PDE(inode)->data;
1305
1306 return cache_open(inode, filp, cd);
1307}
1308
1309static int cache_release_procfs(struct inode *inode, struct file *filp)
1310{
1311 struct cache_detail *cd = PDE(inode)->data;
1312
1313 return cache_release(inode, filp, cd);
1314}
1315
1316static const struct file_operations cache_file_operations_procfs = {
1317 .owner = THIS_MODULE,
1318 .llseek = no_llseek,
1319 .read = cache_read_procfs,
1320 .write = cache_write_procfs,
1321 .poll = cache_poll_procfs,
1322 .ioctl = cache_ioctl_procfs, /* for FIONREAD */
1323 .open = cache_open_procfs,
1324 .release = cache_release_procfs,
1325};
1326
1327static int content_open_procfs(struct inode *inode, struct file *filp)
1328{
1329 struct cache_detail *cd = PDE(inode)->data;
1330
1331 return content_open(inode, filp, cd);
1332}
1333
1334static const struct file_operations content_file_operations_procfs = {
1335 .open = content_open_procfs,
1336 .read = seq_read,
1337 .llseek = seq_lseek,
1338 .release = seq_release_private,
1339};
1340
1341static ssize_t read_flush_procfs(struct file *filp, char __user *buf,
1342 size_t count, loff_t *ppos)
1343{
1344 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1345
1346 return read_flush(filp, buf, count, ppos, cd);
1347}
1348
1349static ssize_t write_flush_procfs(struct file *filp,
1350 const char __user *buf,
1351 size_t count, loff_t *ppos)
1352{
1353 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
1354
1355 return write_flush(filp, buf, count, ppos, cd);
1356}
1357
1358static const struct file_operations cache_flush_operations_procfs = {
1359 .open = nonseekable_open,
1360 .read = read_flush_procfs,
1361 .write = write_flush_procfs,
1362};
1363
1364static void remove_cache_proc_entries(struct cache_detail *cd)
1365{
1366 if (cd->u.procfs.proc_ent == NULL)
1367 return;
1368 if (cd->u.procfs.flush_ent)
1369 remove_proc_entry("flush", cd->u.procfs.proc_ent);
1370 if (cd->u.procfs.channel_ent)
1371 remove_proc_entry("channel", cd->u.procfs.proc_ent);
1372 if (cd->u.procfs.content_ent)
1373 remove_proc_entry("content", cd->u.procfs.proc_ent);
1374 cd->u.procfs.proc_ent = NULL;
1375 remove_proc_entry(cd->name, proc_net_rpc);
1376}
1377
1378#ifdef CONFIG_PROC_FS
1379static int create_cache_proc_entries(struct cache_detail *cd)
1380{
1381 struct proc_dir_entry *p;
1382
1383 cd->u.procfs.proc_ent = proc_mkdir(cd->name, proc_net_rpc);
1384 if (cd->u.procfs.proc_ent == NULL)
1385 goto out_nomem;
1386 cd->u.procfs.channel_ent = NULL;
1387 cd->u.procfs.content_ent = NULL;
1388
1389 p = proc_create_data("flush", S_IFREG|S_IRUSR|S_IWUSR,
1390 cd->u.procfs.proc_ent,
1391 &cache_flush_operations_procfs, cd);
1392 cd->u.procfs.flush_ent = p;
1393 if (p == NULL)
1394 goto out_nomem;
1395
1396 if (cd->cache_upcall || cd->cache_parse) {
1397 p = proc_create_data("channel", S_IFREG|S_IRUSR|S_IWUSR,
1398 cd->u.procfs.proc_ent,
1399 &cache_file_operations_procfs, cd);
1400 cd->u.procfs.channel_ent = p;
1401 if (p == NULL)
1402 goto out_nomem;
1403 }
1404 if (cd->cache_show) {
1405 p = proc_create_data("content", S_IFREG|S_IRUSR|S_IWUSR,
1406 cd->u.procfs.proc_ent,
1407 &content_file_operations_procfs, cd);
1408 cd->u.procfs.content_ent = p;
1409 if (p == NULL)
1410 goto out_nomem;
1411 }
1412 return 0;
1413out_nomem:
1414 remove_cache_proc_entries(cd);
1415 return -ENOMEM;
1416}
1417#else /* CONFIG_PROC_FS */
1418static int create_cache_proc_entries(struct cache_detail *cd)
1419{
1420 return 0;
1421}
1422#endif
1423
1424int cache_register(struct cache_detail *cd)
1425{
1426 int ret;
1427
1428 sunrpc_init_cache_detail(cd);
1429 ret = create_cache_proc_entries(cd);
1430 if (ret)
1431 sunrpc_destroy_cache_detail(cd);
1432 return ret;
1433}
1434EXPORT_SYMBOL_GPL(cache_register);
1435
1436void cache_unregister(struct cache_detail *cd)
1437{
1438 remove_cache_proc_entries(cd);
1439 sunrpc_destroy_cache_detail(cd);
1440}
1441EXPORT_SYMBOL_GPL(cache_unregister);
1442
1443static ssize_t cache_read_pipefs(struct file *filp, char __user *buf,
1444 size_t count, loff_t *ppos)
1445{
1446 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1447
1448 return cache_read(filp, buf, count, ppos, cd);
1449}
1450
1451static ssize_t cache_write_pipefs(struct file *filp, const char __user *buf,
1452 size_t count, loff_t *ppos)
1453{
1454 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1455
1456 return cache_write(filp, buf, count, ppos, cd);
1457}
1458
1459static unsigned int cache_poll_pipefs(struct file *filp, poll_table *wait)
1460{
1461 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1462
1463 return cache_poll(filp, wait, cd);
1464}
1465
1466static int cache_ioctl_pipefs(struct inode *inode, struct file *filp,
1467 unsigned int cmd, unsigned long arg)
1468{
1469 struct cache_detail *cd = RPC_I(inode)->private;
1470
1471 return cache_ioctl(inode, filp, cmd, arg, cd);
1472}
1473
1474static int cache_open_pipefs(struct inode *inode, struct file *filp)
1475{
1476 struct cache_detail *cd = RPC_I(inode)->private;
1477
1478 return cache_open(inode, filp, cd);
1479}
1480
1481static int cache_release_pipefs(struct inode *inode, struct file *filp)
1482{
1483 struct cache_detail *cd = RPC_I(inode)->private;
1484
1485 return cache_release(inode, filp, cd);
1486}
1487
1488const struct file_operations cache_file_operations_pipefs = {
1489 .owner = THIS_MODULE,
1490 .llseek = no_llseek,
1491 .read = cache_read_pipefs,
1492 .write = cache_write_pipefs,
1493 .poll = cache_poll_pipefs,
1494 .ioctl = cache_ioctl_pipefs, /* for FIONREAD */
1495 .open = cache_open_pipefs,
1496 .release = cache_release_pipefs,
1497};
1498
1499static int content_open_pipefs(struct inode *inode, struct file *filp)
1500{
1501 struct cache_detail *cd = RPC_I(inode)->private;
1502
1503 return content_open(inode, filp, cd);
1504}
1505
1506const struct file_operations content_file_operations_pipefs = {
1507 .open = content_open_pipefs,
1508 .read = seq_read,
1509 .llseek = seq_lseek,
1510 .release = seq_release_private,
1511};
1512
1513static ssize_t read_flush_pipefs(struct file *filp, char __user *buf,
1514 size_t count, loff_t *ppos)
1515{
1516 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1517
1518 return read_flush(filp, buf, count, ppos, cd);
1519}
1520
1521static ssize_t write_flush_pipefs(struct file *filp,
1522 const char __user *buf,
1523 size_t count, loff_t *ppos)
1524{
1525 struct cache_detail *cd = RPC_I(filp->f_path.dentry->d_inode)->private;
1526
1527 return write_flush(filp, buf, count, ppos, cd);
1528}
1529
1530const struct file_operations cache_flush_operations_pipefs = {
1311 .open = nonseekable_open, 1531 .open = nonseekable_open,
1312 .read = read_flush, 1532 .read = read_flush_pipefs,
1313 .write = write_flush, 1533 .write = write_flush_pipefs,
1314}; 1534};
1535
1536int sunrpc_cache_register_pipefs(struct dentry *parent,
1537 const char *name, mode_t umode,
1538 struct cache_detail *cd)
1539{
1540 struct qstr q;
1541 struct dentry *dir;
1542 int ret = 0;
1543
1544 sunrpc_init_cache_detail(cd);
1545 q.name = name;
1546 q.len = strlen(name);
1547 q.hash = full_name_hash(q.name, q.len);
1548 dir = rpc_create_cache_dir(parent, &q, umode, cd);
1549 if (!IS_ERR(dir))
1550 cd->u.pipefs.dir = dir;
1551 else {
1552 sunrpc_destroy_cache_detail(cd);
1553 ret = PTR_ERR(dir);
1554 }
1555 return ret;
1556}
1557EXPORT_SYMBOL_GPL(sunrpc_cache_register_pipefs);
1558
1559void sunrpc_cache_unregister_pipefs(struct cache_detail *cd)
1560{
1561 rpc_remove_cache_dir(cd->u.pipefs.dir);
1562 cd->u.pipefs.dir = NULL;
1563 sunrpc_destroy_cache_detail(cd);
1564}
1565EXPORT_SYMBOL_GPL(sunrpc_cache_unregister_pipefs);
1566