symlink.c 1.8 KB

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