xfs_vfs.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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_dir.h"
  27. #include "xfs_dir2.h"
  28. #include "xfs_imap.h"
  29. #include "xfs_alloc.h"
  30. #include "xfs_dmapi.h"
  31. #include "xfs_mount.h"
  32. #include "xfs_quota.h"
  33. int
  34. vfs_mount(
  35. struct bhv_desc *bdp,
  36. struct xfs_mount_args *args,
  37. struct cred *cr)
  38. {
  39. struct bhv_desc *next = bdp;
  40. ASSERT(next);
  41. while (! (bhvtovfsops(next))->vfs_mount)
  42. next = BHV_NEXT(next);
  43. return ((*bhvtovfsops(next)->vfs_mount)(next, args, cr));
  44. }
  45. int
  46. vfs_parseargs(
  47. struct bhv_desc *bdp,
  48. char *s,
  49. struct xfs_mount_args *args,
  50. int f)
  51. {
  52. struct bhv_desc *next = bdp;
  53. ASSERT(next);
  54. while (! (bhvtovfsops(next))->vfs_parseargs)
  55. next = BHV_NEXT(next);
  56. return ((*bhvtovfsops(next)->vfs_parseargs)(next, s, args, f));
  57. }
  58. int
  59. vfs_showargs(
  60. struct bhv_desc *bdp,
  61. struct seq_file *m)
  62. {
  63. struct bhv_desc *next = bdp;
  64. ASSERT(next);
  65. while (! (bhvtovfsops(next))->vfs_showargs)
  66. next = BHV_NEXT(next);
  67. return ((*bhvtovfsops(next)->vfs_showargs)(next, m));
  68. }
  69. int
  70. vfs_unmount(
  71. struct bhv_desc *bdp,
  72. int fl,
  73. struct cred *cr)
  74. {
  75. struct bhv_desc *next = bdp;
  76. ASSERT(next);
  77. while (! (bhvtovfsops(next))->vfs_unmount)
  78. next = BHV_NEXT(next);
  79. return ((*bhvtovfsops(next)->vfs_unmount)(next, fl, cr));
  80. }
  81. int
  82. vfs_mntupdate(
  83. struct bhv_desc *bdp,
  84. int *fl,
  85. struct xfs_mount_args *args)
  86. {
  87. struct bhv_desc *next = bdp;
  88. ASSERT(next);
  89. while (! (bhvtovfsops(next))->vfs_mntupdate)
  90. next = BHV_NEXT(next);
  91. return ((*bhvtovfsops(next)->vfs_mntupdate)(next, fl, args));
  92. }
  93. int
  94. vfs_root(
  95. struct bhv_desc *bdp,
  96. struct vnode **vpp)
  97. {
  98. struct bhv_desc *next = bdp;
  99. ASSERT(next);
  100. while (! (bhvtovfsops(next))->vfs_root)
  101. next = BHV_NEXT(next);
  102. return ((*bhvtovfsops(next)->vfs_root)(next, vpp));
  103. }
  104. int
  105. vfs_statvfs(
  106. struct bhv_desc *bdp,
  107. xfs_statfs_t *sp,
  108. struct vnode *vp)
  109. {
  110. struct bhv_desc *next = bdp;
  111. ASSERT(next);
  112. while (! (bhvtovfsops(next))->vfs_statvfs)
  113. next = BHV_NEXT(next);
  114. return ((*bhvtovfsops(next)->vfs_statvfs)(next, sp, vp));
  115. }
  116. int
  117. vfs_sync(
  118. struct bhv_desc *bdp,
  119. int fl,
  120. struct cred *cr)
  121. {
  122. struct bhv_desc *next = bdp;
  123. ASSERT(next);
  124. while (! (bhvtovfsops(next))->vfs_sync)
  125. next = BHV_NEXT(next);
  126. return ((*bhvtovfsops(next)->vfs_sync)(next, fl, cr));
  127. }
  128. int
  129. vfs_vget(
  130. struct bhv_desc *bdp,
  131. struct vnode **vpp,
  132. struct fid *fidp)
  133. {
  134. struct bhv_desc *next = bdp;
  135. ASSERT(next);
  136. while (! (bhvtovfsops(next))->vfs_vget)
  137. next = BHV_NEXT(next);
  138. return ((*bhvtovfsops(next)->vfs_vget)(next, vpp, fidp));
  139. }
  140. int
  141. vfs_dmapiops(
  142. struct bhv_desc *bdp,
  143. caddr_t addr)
  144. {
  145. struct bhv_desc *next = bdp;
  146. ASSERT(next);
  147. while (! (bhvtovfsops(next))->vfs_dmapiops)
  148. next = BHV_NEXT(next);
  149. return ((*bhvtovfsops(next)->vfs_dmapiops)(next, addr));
  150. }
  151. int
  152. vfs_quotactl(
  153. struct bhv_desc *bdp,
  154. int cmd,
  155. int id,
  156. caddr_t addr)
  157. {
  158. struct bhv_desc *next = bdp;
  159. ASSERT(next);
  160. while (! (bhvtovfsops(next))->vfs_quotactl)
  161. next = BHV_NEXT(next);
  162. return ((*bhvtovfsops(next)->vfs_quotactl)(next, cmd, id, addr));
  163. }
  164. void
  165. vfs_init_vnode(
  166. struct bhv_desc *bdp,
  167. struct vnode *vp,
  168. struct bhv_desc *bp,
  169. int unlock)
  170. {
  171. struct bhv_desc *next = bdp;
  172. ASSERT(next);
  173. while (! (bhvtovfsops(next))->vfs_init_vnode)
  174. next = BHV_NEXT(next);
  175. ((*bhvtovfsops(next)->vfs_init_vnode)(next, vp, bp, unlock));
  176. }
  177. void
  178. vfs_force_shutdown(
  179. struct bhv_desc *bdp,
  180. int fl,
  181. char *file,
  182. int line)
  183. {
  184. struct bhv_desc *next = bdp;
  185. ASSERT(next);
  186. while (! (bhvtovfsops(next))->vfs_force_shutdown)
  187. next = BHV_NEXT(next);
  188. ((*bhvtovfsops(next)->vfs_force_shutdown)(next, fl, file, line));
  189. }
  190. void
  191. vfs_freeze(
  192. struct bhv_desc *bdp)
  193. {
  194. struct bhv_desc *next = bdp;
  195. ASSERT(next);
  196. while (! (bhvtovfsops(next))->vfs_freeze)
  197. next = BHV_NEXT(next);
  198. ((*bhvtovfsops(next)->vfs_freeze)(next));
  199. }
  200. bhv_vfs_t *
  201. vfs_allocate(
  202. struct super_block *sb)
  203. {
  204. struct bhv_vfs *vfsp;
  205. vfsp = kmem_zalloc(sizeof(bhv_vfs_t), KM_SLEEP);
  206. bhv_head_init(VFS_BHVHEAD(vfsp), "vfs");
  207. INIT_LIST_HEAD(&vfsp->vfs_sync_list);
  208. spin_lock_init(&vfsp->vfs_sync_lock);
  209. init_waitqueue_head(&vfsp->vfs_wait_single_sync_task);
  210. vfsp->vfs_super = sb;
  211. sb->s_fs_info = vfsp;
  212. if (sb->s_flags & MS_RDONLY)
  213. vfsp->vfs_flag |= VFS_RDONLY;
  214. return vfsp;
  215. }
  216. bhv_vfs_t *
  217. vfs_from_sb(
  218. struct super_block *sb)
  219. {
  220. return (bhv_vfs_t *)sb->s_fs_info;
  221. }
  222. void
  223. vfs_deallocate(
  224. struct bhv_vfs *vfsp)
  225. {
  226. bhv_head_destroy(VFS_BHVHEAD(vfsp));
  227. kmem_free(vfsp, sizeof(bhv_vfs_t));
  228. }
  229. void
  230. vfs_insertops(
  231. struct bhv_vfs *vfsp,
  232. struct bhv_module_vfsops *vfsops)
  233. {
  234. struct bhv_desc *bdp;
  235. bdp = kmem_alloc(sizeof(struct bhv_desc), KM_SLEEP);
  236. bhv_desc_init(bdp, NULL, vfsp, vfsops);
  237. bhv_insert(&vfsp->vfs_bh, bdp);
  238. }
  239. void
  240. vfs_insertbhv(
  241. struct bhv_vfs *vfsp,
  242. struct bhv_desc *bdp,
  243. struct bhv_vfsops *vfsops,
  244. void *mount)
  245. {
  246. bhv_desc_init(bdp, mount, vfsp, vfsops);
  247. bhv_insert_initial(&vfsp->vfs_bh, bdp);
  248. }
  249. void
  250. bhv_remove_vfsops(
  251. struct bhv_vfs *vfsp,
  252. int pos)
  253. {
  254. struct bhv_desc *bhv;
  255. bhv = bhv_lookup_range(&vfsp->vfs_bh, pos, pos);
  256. if (!bhv)
  257. return;
  258. bhv_remove(&vfsp->vfs_bh, bhv);
  259. kmem_free(bhv, sizeof(*bhv));
  260. }
  261. void
  262. bhv_remove_all_vfsops(
  263. struct bhv_vfs *vfsp,
  264. int freebase)
  265. {
  266. struct xfs_mount *mp;
  267. bhv_remove_vfsops(vfsp, VFS_POSITION_QM);
  268. bhv_remove_vfsops(vfsp, VFS_POSITION_DM);
  269. if (!freebase)
  270. return;
  271. mp = XFS_VFSTOM(vfsp);
  272. VFS_REMOVEBHV(vfsp, &mp->m_bhv);
  273. xfs_mount_free(mp, 0);
  274. }
  275. void
  276. bhv_insert_all_vfsops(
  277. struct bhv_vfs *vfsp)
  278. {
  279. struct xfs_mount *mp;
  280. mp = xfs_mount_init();
  281. vfs_insertbhv(vfsp, &mp->m_bhv, &xfs_vfsops, mp);
  282. vfs_insertdmapi(vfsp);
  283. vfs_insertquota(vfsp);
  284. }