symlink.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * linux/fs/nfs/symlink.c
  3. *
  4. * Copyright (C) 1992 Rick Sladkey
  5. *
  6. * Optimization changes Copyright (C) 1994 Florian La Roche
  7. *
  8. * Jun 7 1999, cache symlink lookups in the page cache. -DaveM
  9. *
  10. * nfs symlink handling code
  11. */
  12. #include <linux/time.h>
  13. #include <linux/errno.h>
  14. #include <linux/sunrpc/clnt.h>
  15. #include <linux/nfs.h>
  16. #include <linux/nfs2.h>
  17. #include <linux/nfs_fs.h>
  18. #include <linux/pagemap.h>
  19. #include <linux/stat.h>
  20. #include <linux/mm.h>
  21. #include <linux/string.h>
  22. /* Symlink caching in the page cache is even more simplistic
  23. * and straight-forward than readdir caching.
  24. */
  25. static int nfs_symlink_filler(struct inode *inode, struct page *page)
  26. {
  27. int error;
  28. error = NFS_PROTO(inode)->readlink(inode, page, 0, PAGE_SIZE);
  29. if (error < 0)
  30. goto error;
  31. SetPageUptodate(page);
  32. unlock_page(page);
  33. return 0;
  34. error:
  35. SetPageError(page);
  36. unlock_page(page);
  37. return -EIO;
  38. }
  39. static const char *nfs_get_link(struct dentry *dentry,
  40. struct inode *inode, void **cookie)
  41. {
  42. struct page *page;
  43. void *err;
  44. if (!dentry) {
  45. err = ERR_PTR(nfs_revalidate_mapping_rcu(inode));
  46. if (err)
  47. return err;
  48. page = find_get_page(inode->i_mapping, 0);
  49. if (!page)
  50. return ERR_PTR(-ECHILD);
  51. if (!PageUptodate(page)) {
  52. put_page(page);
  53. return ERR_PTR(-ECHILD);
  54. }
  55. } else {
  56. err = ERR_PTR(nfs_revalidate_mapping(inode, inode->i_mapping));
  57. if (err)
  58. return err;
  59. page = read_cache_page(&inode->i_data, 0,
  60. (filler_t *)nfs_symlink_filler, inode);
  61. if (IS_ERR(page))
  62. return ERR_CAST(page);
  63. }
  64. *cookie = page;
  65. return page_address(page);
  66. }
  67. /*
  68. * symlinks can't do much...
  69. */
  70. const struct inode_operations nfs_symlink_inode_operations = {
  71. .readlink = generic_readlink,
  72. .get_link = nfs_get_link,
  73. .put_link = page_put_link,
  74. .getattr = nfs_getattr,
  75. .setattr = nfs_setattr,
  76. };