symlink.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * linux/cluster/ssi/cfs/symlink.c
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE
  14. * or NON INFRINGEMENT. See the GNU General Public License for more
  15. * details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. * Questions/Comments/Bugfixes to ssic-linux-devel@lists.sourceforge.net
  22. *
  23. * Copyright (C) 1992 Rick Sladkey
  24. *
  25. * Optimization changes Copyright (C) 1994 Florian La Roche
  26. *
  27. * Jun 7 1999, cache symlink lookups in the page cache. -DaveM
  28. *
  29. * Portions Copyright (C) 2001 Compaq Computer Corporation
  30. *
  31. * ocfs2 symlink handling code.
  32. *
  33. * Copyright (C) 2004, 2005 Oracle.
  34. *
  35. */
  36. #include <linux/fs.h>
  37. #include <linux/types.h>
  38. #include <linux/slab.h>
  39. #include <linux/pagemap.h>
  40. #include <linux/utsname.h>
  41. #define MLOG_MASK_PREFIX ML_NAMEI
  42. #include <cluster/masklog.h>
  43. #include "ocfs2.h"
  44. #include "alloc.h"
  45. #include "file.h"
  46. #include "inode.h"
  47. #include "journal.h"
  48. #include "symlink.h"
  49. #include "buffer_head_io.h"
  50. static char *ocfs2_page_getlink(struct dentry * dentry,
  51. struct page **ppage);
  52. static char *ocfs2_fast_symlink_getlink(struct inode *inode,
  53. struct buffer_head **bh);
  54. /* get the link contents into pagecache */
  55. static char *ocfs2_page_getlink(struct dentry * dentry,
  56. struct page **ppage)
  57. {
  58. struct page * page;
  59. struct address_space *mapping = dentry->d_inode->i_mapping;
  60. page = read_mapping_page(mapping, 0, NULL);
  61. if (IS_ERR(page))
  62. goto sync_fail;
  63. *ppage = page;
  64. return kmap(page);
  65. sync_fail:
  66. return (char*)page;
  67. }
  68. static char *ocfs2_fast_symlink_getlink(struct inode *inode,
  69. struct buffer_head **bh)
  70. {
  71. int status;
  72. char *link = NULL;
  73. struct ocfs2_dinode *fe;
  74. mlog_entry_void();
  75. status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
  76. OCFS2_I(inode)->ip_blkno,
  77. bh,
  78. OCFS2_BH_CACHED,
  79. inode);
  80. if (status < 0) {
  81. mlog_errno(status);
  82. link = ERR_PTR(status);
  83. goto bail;
  84. }
  85. fe = (struct ocfs2_dinode *) (*bh)->b_data;
  86. link = (char *) fe->id2.i_symlink;
  87. bail:
  88. mlog_exit(status);
  89. return link;
  90. }
  91. static int ocfs2_readlink(struct dentry *dentry,
  92. char __user *buffer,
  93. int buflen)
  94. {
  95. int ret;
  96. char *link;
  97. struct buffer_head *bh = NULL;
  98. struct inode *inode = dentry->d_inode;
  99. mlog_entry_void();
  100. link = ocfs2_fast_symlink_getlink(inode, &bh);
  101. if (IS_ERR(link)) {
  102. ret = PTR_ERR(link);
  103. goto out;
  104. }
  105. /*
  106. * Without vfsmount we can't update atime now,
  107. * but we will update atime here ultimately.
  108. */
  109. ret = vfs_readlink(dentry, buffer, buflen, link);
  110. brelse(bh);
  111. out:
  112. mlog_exit(ret);
  113. return ret;
  114. }
  115. static void *ocfs2_follow_link(struct dentry *dentry,
  116. struct nameidata *nd)
  117. {
  118. int status;
  119. char *link;
  120. struct inode *inode = dentry->d_inode;
  121. struct page *page = NULL;
  122. struct buffer_head *bh = NULL;
  123. if (ocfs2_inode_is_fast_symlink(inode))
  124. link = ocfs2_fast_symlink_getlink(inode, &bh);
  125. else
  126. link = ocfs2_page_getlink(dentry, &page);
  127. if (IS_ERR(link)) {
  128. status = PTR_ERR(link);
  129. mlog_errno(status);
  130. goto bail;
  131. }
  132. status = vfs_follow_link(nd, link);
  133. bail:
  134. if (page) {
  135. kunmap(page);
  136. page_cache_release(page);
  137. }
  138. if (bh)
  139. brelse(bh);
  140. return ERR_PTR(status);
  141. }
  142. const struct inode_operations ocfs2_symlink_inode_operations = {
  143. .readlink = page_readlink,
  144. .follow_link = ocfs2_follow_link,
  145. .getattr = ocfs2_getattr,
  146. };
  147. const struct inode_operations ocfs2_fast_symlink_inode_operations = {
  148. .readlink = ocfs2_readlink,
  149. .follow_link = ocfs2_follow_link,
  150. .getattr = ocfs2_getattr,
  151. };