symlink.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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(struct inode *inode, struct page *page)
  27. {
  28. int error;
  29. error = NFS_PROTO(inode)->readlink(inode, page, 0, PAGE_SIZE);
  30. if (error < 0)
  31. goto error;
  32. SetPageUptodate(page);
  33. unlock_page(page);
  34. return 0;
  35. error:
  36. SetPageError(page);
  37. unlock_page(page);
  38. return -EIO;
  39. }
  40. static const char *nfs_get_link(struct dentry *dentry,
  41. struct inode *inode,
  42. struct delayed_call *done)
  43. {
  44. struct page *page;
  45. void *err;
  46. if (!dentry) {
  47. err = ERR_PTR(nfs_revalidate_mapping_rcu(inode));
  48. if (err)
  49. return err;
  50. page = find_get_page(inode->i_mapping, 0);
  51. if (!page)
  52. return ERR_PTR(-ECHILD);
  53. if (!PageUptodate(page)) {
  54. put_page(page);
  55. return ERR_PTR(-ECHILD);
  56. }
  57. } else {
  58. err = ERR_PTR(nfs_revalidate_mapping(inode, inode->i_mapping));
  59. if (err)
  60. return err;
  61. page = read_cache_page(&inode->i_data, 0,
  62. (filler_t *)nfs_symlink_filler, inode);
  63. if (IS_ERR(page))
  64. return ERR_CAST(page);
  65. }
  66. set_delayed_call(done, page_put_link, page);
  67. return page_address(page);
  68. }
  69. /*
  70. * symlinks can't do much...
  71. */
  72. const struct inode_operations nfs_symlink_inode_operations = {
  73. .get_link = nfs_get_link,
  74. .getattr = nfs_getattr,
  75. .setattr = nfs_setattr,
  76. };