symlink.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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,
  41. struct delayed_call *done)
  42. {
  43. struct page *page;
  44. void *err;
  45. if (!dentry) {
  46. err = ERR_PTR(nfs_revalidate_mapping_rcu(inode));
  47. if (err)
  48. return err;
  49. page = find_get_page(inode->i_mapping, 0);
  50. if (!page)
  51. return ERR_PTR(-ECHILD);
  52. if (!PageUptodate(page)) {
  53. put_page(page);
  54. return ERR_PTR(-ECHILD);
  55. }
  56. } else {
  57. err = ERR_PTR(nfs_revalidate_mapping(inode, inode->i_mapping));
  58. if (err)
  59. return err;
  60. page = read_cache_page(&inode->i_data, 0,
  61. (filler_t *)nfs_symlink_filler, inode);
  62. if (IS_ERR(page))
  63. return ERR_CAST(page);
  64. }
  65. set_delayed_call(done, page_put_link, page);
  66. return page_address(page);
  67. }
  68. /*
  69. * symlinks can't do much...
  70. */
  71. const struct inode_operations nfs_symlink_inode_operations = {
  72. .readlink = generic_readlink,
  73. .get_link = nfs_get_link,
  74. .getattr = nfs_getattr,
  75. .setattr = nfs_setattr,
  76. };