symlink.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. wait_on_page_locked(page);
  64. if (!PageUptodate(page))
  65. goto async_fail;
  66. *ppage = page;
  67. return kmap(page);
  68. async_fail:
  69. page_cache_release(page);
  70. return ERR_PTR(-EIO);
  71. sync_fail:
  72. return (char*)page;
  73. }
  74. static char *ocfs2_fast_symlink_getlink(struct inode *inode,
  75. struct buffer_head **bh)
  76. {
  77. int status;
  78. char *link = NULL;
  79. struct ocfs2_dinode *fe;
  80. mlog_entry_void();
  81. status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
  82. OCFS2_I(inode)->ip_blkno,
  83. bh,
  84. OCFS2_BH_CACHED,
  85. inode);
  86. if (status < 0) {
  87. mlog_errno(status);
  88. link = ERR_PTR(status);
  89. goto bail;
  90. }
  91. fe = (struct ocfs2_dinode *) (*bh)->b_data;
  92. link = (char *) fe->id2.i_symlink;
  93. bail:
  94. mlog_exit(status);
  95. return link;
  96. }
  97. static int ocfs2_readlink(struct dentry *dentry,
  98. char __user *buffer,
  99. int buflen)
  100. {
  101. int ret;
  102. char *link;
  103. struct buffer_head *bh = NULL;
  104. struct inode *inode = dentry->d_inode;
  105. mlog_entry_void();
  106. link = ocfs2_fast_symlink_getlink(inode, &bh);
  107. if (IS_ERR(link)) {
  108. ret = PTR_ERR(link);
  109. goto out;
  110. }
  111. ret = vfs_readlink(dentry, buffer, buflen, link);
  112. brelse(bh);
  113. out:
  114. mlog_exit(ret);
  115. return ret;
  116. }
  117. static void *ocfs2_follow_link(struct dentry *dentry,
  118. struct nameidata *nd)
  119. {
  120. int status;
  121. char *link;
  122. struct inode *inode = dentry->d_inode;
  123. struct page *page = NULL;
  124. struct buffer_head *bh = NULL;
  125. if (ocfs2_inode_is_fast_symlink(inode))
  126. link = ocfs2_fast_symlink_getlink(inode, &bh);
  127. else
  128. link = ocfs2_page_getlink(dentry, &page);
  129. if (IS_ERR(link)) {
  130. status = PTR_ERR(link);
  131. mlog_errno(status);
  132. goto bail;
  133. }
  134. status = vfs_follow_link(nd, link);
  135. if (status && status != -ENOENT)
  136. mlog_errno(status);
  137. bail:
  138. if (page) {
  139. kunmap(page);
  140. page_cache_release(page);
  141. }
  142. if (bh)
  143. brelse(bh);
  144. return ERR_PTR(status);
  145. }
  146. struct inode_operations ocfs2_symlink_inode_operations = {
  147. .readlink = page_readlink,
  148. .follow_link = ocfs2_follow_link,
  149. .getattr = ocfs2_getattr,
  150. };
  151. struct inode_operations ocfs2_fast_symlink_inode_operations = {
  152. .readlink = ocfs2_readlink,
  153. .follow_link = ocfs2_follow_link,
  154. .getattr = ocfs2_getattr,
  155. };