xfs_vfs.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_inum.h"
  21. #include "xfs_log.h"
  22. #include "xfs_clnt.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_dir2.h"
  27. #include "xfs_imap.h"
  28. #include "xfs_alloc.h"
  29. #include "xfs_dmapi.h"
  30. #include "xfs_mount.h"
  31. #include "xfs_quota.h"
  32. int
  33. vfs_mount(
  34. struct bhv_desc *bdp,
  35. struct xfs_mount_args *args,
  36. struct cred *cr)
  37. {
  38. struct bhv_desc *next = bdp;
  39. ASSERT(next);
  40. while (! (bhvtovfsops(next))->vfs_mount)
  41. next = BHV_NEXT(next);
  42. return ((*bhvtovfsops(next)->vfs_mount)(next, args, cr));
  43. }
  44. int
  45. vfs_parseargs(
  46. struct bhv_desc *bdp,
  47. char *s,
  48. struct xfs_mount_args *args,
  49. int f)
  50. {
  51. struct bhv_desc *next = bdp;
  52. ASSERT(next);
  53. while (! (bhvtovfsops(next))->vfs_parseargs)
  54. next = BHV_NEXT(next);
  55. return ((*bhvtovfsops(next)->vfs_parseargs)(next, s, args, f));
  56. }
  57. int
  58. vfs_showargs(
  59. struct bhv_desc *bdp,
  60. struct seq_file *m)
  61. {
  62. struct bhv_desc *next = bdp;
  63. ASSERT(next);
  64. while (! (bhvtovfsops(next))->vfs_showargs)
  65. next = BHV_NEXT(next);
  66. return ((*bhvtovfsops(next)->vfs_showargs)(next, m));
  67. }
  68. int
  69. vfs_unmount(
  70. struct bhv_desc *bdp,
  71. int fl,
  72. struct cred *cr)
  73. {
  74. struct bhv_desc *next = bdp;
  75. ASSERT(next);
  76. while (! (bhvtovfsops(next))->vfs_unmount)
  77. next = BHV_NEXT(next);
  78. return ((*bhvtovfsops(next)->vfs_unmount)(next, fl, cr));
  79. }
  80. int
  81. vfs_mntupdate(
  82. struct bhv_desc *bdp,
  83. int *fl,
  84. struct xfs_mount_args *args)
  85. {
  86. struct bhv_desc *next = bdp;
  87. ASSERT(next);
  88. while (! (bhvtovfsops(next))->vfs_mntupdate)
  89. next = BHV_NEXT(next);
  90. return ((*bhvtovfsops(next)->vfs_mntupdate)(next, fl, args));
  91. }
  92. int
  93. vfs_root(
  94. struct bhv_desc *bdp,
  95. bhv_vnode_t **vpp)
  96. {
  97. struct bhv_desc *next = bdp;
  98. ASSERT(next);
  99. while (! (bhvtovfsops(next))->vfs_root)
  100. next = BHV_NEXT(next);
  101. return ((*bhvtovfsops(next)->vfs_root)(next, vpp));
  102. }
  103. int
  104. vfs_statvfs(
  105. struct bhv_desc *bdp,
  106. bhv_statvfs_t *statp,
  107. bhv_vnode_t *vp)
  108. {
  109. struct bhv_desc *next = bdp;
  110. ASSERT(next);
  111. while (! (bhvtovfsops(next))->vfs_statvfs)
  112. next = BHV_NEXT(next);
  113. return ((*bhvtovfsops(next)->vfs_statvfs)(next, statp, vp));
  114. }
  115. int
  116. vfs_sync(
  117. struct bhv_desc *bdp,
  118. int fl,
  119. struct cred *cr)
  120. {
  121. struct bhv_desc *next = bdp;
  122. ASSERT(next);
  123. while (! (bhvtovfsops(next))->vfs_sync)
  124. next = BHV_NEXT(next);
  125. return ((*bhvtovfsops(next)->vfs_sync)(next, fl, cr));
  126. }
  127. int
  128. vfs_vget(
  129. struct bhv_desc *bdp,
  130. bhv_vnode_t **vpp,
  131. struct fid *fidp)
  132. {
  133. struct bhv_desc *next = bdp;
  134. ASSERT(next);
  135. while (! (bhvtovfsops(next))->vfs_vget)
  136. next = BHV_NEXT(next);
  137. return ((*bhvtovfsops(next)->vfs_vget)(next, vpp, fidp));
  138. }
  139. void
  140. vfs_init_vnode(
  141. struct bhv_desc *bdp,
  142. bhv_vnode_t *vp,
  143. struct xfs_inode *ip,
  144. int unlock)
  145. {
  146. struct bhv_desc *next = bdp;
  147. ASSERT(next);
  148. while (! (bhvtovfsops(next))->vfs_init_vnode)
  149. next = BHV_NEXT(next);
  150. ((*bhvtovfsops(next)->vfs_init_vnode)(next, vp, ip, unlock));
  151. }
  152. void
  153. vfs_force_shutdown(
  154. struct bhv_desc *bdp,
  155. int fl,
  156. char *file,
  157. int line)
  158. {
  159. struct bhv_desc *next = bdp;
  160. ASSERT(next);
  161. while (! (bhvtovfsops(next))->vfs_force_shutdown)
  162. next = BHV_NEXT(next);
  163. ((*bhvtovfsops(next)->vfs_force_shutdown)(next, fl, file, line));
  164. }
  165. void
  166. vfs_freeze(
  167. struct bhv_desc *bdp)
  168. {
  169. struct bhv_desc *next = bdp;
  170. ASSERT(next);
  171. while (! (bhvtovfsops(next))->vfs_freeze)
  172. next = BHV_NEXT(next);
  173. ((*bhvtovfsops(next)->vfs_freeze)(next));
  174. }
  175. bhv_vfs_t *
  176. vfs_allocate(
  177. struct super_block *sb)
  178. {
  179. struct bhv_vfs *vfsp;
  180. vfsp = kmem_zalloc(sizeof(bhv_vfs_t), KM_SLEEP);
  181. bhv_head_init(VFS_BHVHEAD(vfsp), "vfs");
  182. INIT_LIST_HEAD(&vfsp->vfs_sync_list);
  183. spin_lock_init(&vfsp->vfs_sync_lock);
  184. init_waitqueue_head(&vfsp->vfs_wait_single_sync_task);
  185. vfsp->vfs_super = sb;
  186. sb->s_fs_info = vfsp;
  187. if (sb->s_flags & MS_RDONLY)
  188. vfsp->vfs_flag |= VFS_RDONLY;
  189. return vfsp;
  190. }
  191. bhv_vfs_t *
  192. vfs_from_sb(
  193. struct super_block *sb)
  194. {
  195. return (bhv_vfs_t *)sb->s_fs_info;
  196. }
  197. void
  198. vfs_deallocate(
  199. struct bhv_vfs *vfsp)
  200. {
  201. bhv_head_destroy(VFS_BHVHEAD(vfsp));
  202. kmem_free(vfsp, sizeof(bhv_vfs_t));
  203. }
  204. void
  205. vfs_insertops(
  206. struct bhv_vfs *vfsp,
  207. struct bhv_module_vfsops *vfsops)
  208. {
  209. struct bhv_desc *bdp;
  210. bdp = kmem_alloc(sizeof(struct bhv_desc), KM_SLEEP);
  211. bhv_desc_init(bdp, NULL, vfsp, vfsops);
  212. bhv_insert(&vfsp->vfs_bh, bdp);
  213. }
  214. void
  215. vfs_insertbhv(
  216. struct bhv_vfs *vfsp,
  217. struct bhv_desc *bdp,
  218. struct bhv_vfsops *vfsops,
  219. void *mount)
  220. {
  221. bhv_desc_init(bdp, mount, vfsp, vfsops);
  222. bhv_insert_initial(&vfsp->vfs_bh, bdp);
  223. }
  224. void
  225. bhv_remove_vfsops(
  226. struct bhv_vfs *vfsp,
  227. int pos)
  228. {
  229. struct bhv_desc *bhv;
  230. bhv = bhv_lookup_range(&vfsp->vfs_bh, pos, pos);
  231. if (!bhv)
  232. return;
  233. bhv_remove(&vfsp->vfs_bh, bhv);
  234. kmem_free(bhv, sizeof(*bhv));
  235. }
  236. void
  237. bhv_remove_all_vfsops(
  238. struct bhv_vfs *vfsp,
  239. int freebase)
  240. {
  241. struct xfs_mount *mp;
  242. bhv_remove_vfsops(vfsp, VFS_POSITION_QM);
  243. if (!freebase)
  244. return;
  245. mp = XFS_VFSTOM(vfsp);
  246. VFS_REMOVEBHV(vfsp, &mp->m_bhv);
  247. xfs_mount_free(mp, 0);
  248. kmem_free(mp, sizeof(xfs_mount_t));
  249. }
  250. void
  251. bhv_insert_all_vfsops(
  252. struct bhv_vfs *vfsp)
  253. {
  254. struct xfs_mount *mp;
  255. mp = xfs_mount_init();
  256. vfs_insertbhv(vfsp, &mp->m_bhv, &xfs_vfsops, mp);
  257. vfs_insertdmapi(vfsp);
  258. vfs_insertquota(vfsp);
  259. }