xfs_vfs.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. struct bhv_vnode **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. struct bhv_vnode *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. struct bhv_vnode **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. int
  140. vfs_dmapiops(
  141. struct bhv_desc *bdp,
  142. caddr_t addr)
  143. {
  144. struct bhv_desc *next = bdp;
  145. ASSERT(next);
  146. while (! (bhvtovfsops(next))->vfs_dmapiops)
  147. next = BHV_NEXT(next);
  148. return ((*bhvtovfsops(next)->vfs_dmapiops)(next, addr));
  149. }
  150. int
  151. vfs_quotactl(
  152. struct bhv_desc *bdp,
  153. int cmd,
  154. int id,
  155. caddr_t addr)
  156. {
  157. struct bhv_desc *next = bdp;
  158. ASSERT(next);
  159. while (! (bhvtovfsops(next))->vfs_quotactl)
  160. next = BHV_NEXT(next);
  161. return ((*bhvtovfsops(next)->vfs_quotactl)(next, cmd, id, addr));
  162. }
  163. void
  164. vfs_init_vnode(
  165. struct bhv_desc *bdp,
  166. struct bhv_vnode *vp,
  167. struct bhv_desc *bp,
  168. int unlock)
  169. {
  170. struct bhv_desc *next = bdp;
  171. ASSERT(next);
  172. while (! (bhvtovfsops(next))->vfs_init_vnode)
  173. next = BHV_NEXT(next);
  174. ((*bhvtovfsops(next)->vfs_init_vnode)(next, vp, bp, unlock));
  175. }
  176. void
  177. vfs_force_shutdown(
  178. struct bhv_desc *bdp,
  179. int fl,
  180. char *file,
  181. int line)
  182. {
  183. struct bhv_desc *next = bdp;
  184. ASSERT(next);
  185. while (! (bhvtovfsops(next))->vfs_force_shutdown)
  186. next = BHV_NEXT(next);
  187. ((*bhvtovfsops(next)->vfs_force_shutdown)(next, fl, file, line));
  188. }
  189. void
  190. vfs_freeze(
  191. struct bhv_desc *bdp)
  192. {
  193. struct bhv_desc *next = bdp;
  194. ASSERT(next);
  195. while (! (bhvtovfsops(next))->vfs_freeze)
  196. next = BHV_NEXT(next);
  197. ((*bhvtovfsops(next)->vfs_freeze)(next));
  198. }
  199. bhv_vfs_t *
  200. vfs_allocate(
  201. struct super_block *sb)
  202. {
  203. struct bhv_vfs *vfsp;
  204. vfsp = kmem_zalloc(sizeof(bhv_vfs_t), KM_SLEEP);
  205. bhv_head_init(VFS_BHVHEAD(vfsp), "vfs");
  206. INIT_LIST_HEAD(&vfsp->vfs_sync_list);
  207. spin_lock_init(&vfsp->vfs_sync_lock);
  208. init_waitqueue_head(&vfsp->vfs_wait_single_sync_task);
  209. vfsp->vfs_super = sb;
  210. sb->s_fs_info = vfsp;
  211. if (sb->s_flags & MS_RDONLY)
  212. vfsp->vfs_flag |= VFS_RDONLY;
  213. return vfsp;
  214. }
  215. bhv_vfs_t *
  216. vfs_from_sb(
  217. struct super_block *sb)
  218. {
  219. return (bhv_vfs_t *)sb->s_fs_info;
  220. }
  221. void
  222. vfs_deallocate(
  223. struct bhv_vfs *vfsp)
  224. {
  225. bhv_head_destroy(VFS_BHVHEAD(vfsp));
  226. kmem_free(vfsp, sizeof(bhv_vfs_t));
  227. }
  228. void
  229. vfs_insertops(
  230. struct bhv_vfs *vfsp,
  231. struct bhv_module_vfsops *vfsops)
  232. {
  233. struct bhv_desc *bdp;
  234. bdp = kmem_alloc(sizeof(struct bhv_desc), KM_SLEEP);
  235. bhv_desc_init(bdp, NULL, vfsp, vfsops);
  236. bhv_insert(&vfsp->vfs_bh, bdp);
  237. }
  238. void
  239. vfs_insertbhv(
  240. struct bhv_vfs *vfsp,
  241. struct bhv_desc *bdp,
  242. struct bhv_vfsops *vfsops,
  243. void *mount)
  244. {
  245. bhv_desc_init(bdp, mount, vfsp, vfsops);
  246. bhv_insert_initial(&vfsp->vfs_bh, bdp);
  247. }
  248. void
  249. bhv_remove_vfsops(
  250. struct bhv_vfs *vfsp,
  251. int pos)
  252. {
  253. struct bhv_desc *bhv;
  254. bhv = bhv_lookup_range(&vfsp->vfs_bh, pos, pos);
  255. if (!bhv)
  256. return;
  257. bhv_remove(&vfsp->vfs_bh, bhv);
  258. kmem_free(bhv, sizeof(*bhv));
  259. }
  260. void
  261. bhv_remove_all_vfsops(
  262. struct bhv_vfs *vfsp,
  263. int freebase)
  264. {
  265. struct xfs_mount *mp;
  266. bhv_remove_vfsops(vfsp, VFS_POSITION_QM);
  267. bhv_remove_vfsops(vfsp, VFS_POSITION_DM);
  268. if (!freebase)
  269. return;
  270. mp = XFS_VFSTOM(vfsp);
  271. VFS_REMOVEBHV(vfsp, &mp->m_bhv);
  272. xfs_mount_free(mp, 0);
  273. }
  274. void
  275. bhv_insert_all_vfsops(
  276. struct bhv_vfs *vfsp)
  277. {
  278. struct xfs_mount *mp;
  279. mp = xfs_mount_init();
  280. vfs_insertbhv(vfsp, &mp->m_bhv, &xfs_vfsops, mp);
  281. vfs_insertdmapi(vfsp);
  282. vfs_insertquota(vfsp);
  283. }