xfs_vfs.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*
  2. * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #include "xfs.h"
  33. #include "xfs_fs.h"
  34. #include "xfs_macros.h"
  35. #include "xfs_inum.h"
  36. #include "xfs_log.h"
  37. #include "xfs_clnt.h"
  38. #include "xfs_trans.h"
  39. #include "xfs_sb.h"
  40. #include "xfs_ag.h"
  41. #include "xfs_dir.h"
  42. #include "xfs_dir2.h"
  43. #include "xfs_imap.h"
  44. #include "xfs_alloc.h"
  45. #include "xfs_dmapi.h"
  46. #include "xfs_mount.h"
  47. #include "xfs_quota.h"
  48. int
  49. vfs_mount(
  50. struct bhv_desc *bdp,
  51. struct xfs_mount_args *args,
  52. struct cred *cr)
  53. {
  54. struct bhv_desc *next = bdp;
  55. ASSERT(next);
  56. while (! (bhvtovfsops(next))->vfs_mount)
  57. next = BHV_NEXT(next);
  58. return ((*bhvtovfsops(next)->vfs_mount)(next, args, cr));
  59. }
  60. int
  61. vfs_parseargs(
  62. struct bhv_desc *bdp,
  63. char *s,
  64. struct xfs_mount_args *args,
  65. int f)
  66. {
  67. struct bhv_desc *next = bdp;
  68. ASSERT(next);
  69. while (! (bhvtovfsops(next))->vfs_parseargs)
  70. next = BHV_NEXT(next);
  71. return ((*bhvtovfsops(next)->vfs_parseargs)(next, s, args, f));
  72. }
  73. int
  74. vfs_showargs(
  75. struct bhv_desc *bdp,
  76. struct seq_file *m)
  77. {
  78. struct bhv_desc *next = bdp;
  79. ASSERT(next);
  80. while (! (bhvtovfsops(next))->vfs_showargs)
  81. next = BHV_NEXT(next);
  82. return ((*bhvtovfsops(next)->vfs_showargs)(next, m));
  83. }
  84. int
  85. vfs_unmount(
  86. struct bhv_desc *bdp,
  87. int fl,
  88. struct cred *cr)
  89. {
  90. struct bhv_desc *next = bdp;
  91. ASSERT(next);
  92. while (! (bhvtovfsops(next))->vfs_unmount)
  93. next = BHV_NEXT(next);
  94. return ((*bhvtovfsops(next)->vfs_unmount)(next, fl, cr));
  95. }
  96. int
  97. vfs_mntupdate(
  98. struct bhv_desc *bdp,
  99. int *fl,
  100. struct xfs_mount_args *args)
  101. {
  102. struct bhv_desc *next = bdp;
  103. ASSERT(next);
  104. while (! (bhvtovfsops(next))->vfs_mntupdate)
  105. next = BHV_NEXT(next);
  106. return ((*bhvtovfsops(next)->vfs_mntupdate)(next, fl, args));
  107. }
  108. int
  109. vfs_root(
  110. struct bhv_desc *bdp,
  111. struct vnode **vpp)
  112. {
  113. struct bhv_desc *next = bdp;
  114. ASSERT(next);
  115. while (! (bhvtovfsops(next))->vfs_root)
  116. next = BHV_NEXT(next);
  117. return ((*bhvtovfsops(next)->vfs_root)(next, vpp));
  118. }
  119. int
  120. vfs_statvfs(
  121. struct bhv_desc *bdp,
  122. xfs_statfs_t *sp,
  123. struct vnode *vp)
  124. {
  125. struct bhv_desc *next = bdp;
  126. ASSERT(next);
  127. while (! (bhvtovfsops(next))->vfs_statvfs)
  128. next = BHV_NEXT(next);
  129. return ((*bhvtovfsops(next)->vfs_statvfs)(next, sp, vp));
  130. }
  131. int
  132. vfs_sync(
  133. struct bhv_desc *bdp,
  134. int fl,
  135. struct cred *cr)
  136. {
  137. struct bhv_desc *next = bdp;
  138. ASSERT(next);
  139. while (! (bhvtovfsops(next))->vfs_sync)
  140. next = BHV_NEXT(next);
  141. return ((*bhvtovfsops(next)->vfs_sync)(next, fl, cr));
  142. }
  143. int
  144. vfs_vget(
  145. struct bhv_desc *bdp,
  146. struct vnode **vpp,
  147. struct fid *fidp)
  148. {
  149. struct bhv_desc *next = bdp;
  150. ASSERT(next);
  151. while (! (bhvtovfsops(next))->vfs_vget)
  152. next = BHV_NEXT(next);
  153. return ((*bhvtovfsops(next)->vfs_vget)(next, vpp, fidp));
  154. }
  155. int
  156. vfs_dmapiops(
  157. struct bhv_desc *bdp,
  158. caddr_t addr)
  159. {
  160. struct bhv_desc *next = bdp;
  161. ASSERT(next);
  162. while (! (bhvtovfsops(next))->vfs_dmapiops)
  163. next = BHV_NEXT(next);
  164. return ((*bhvtovfsops(next)->vfs_dmapiops)(next, addr));
  165. }
  166. int
  167. vfs_quotactl(
  168. struct bhv_desc *bdp,
  169. int cmd,
  170. int id,
  171. caddr_t addr)
  172. {
  173. struct bhv_desc *next = bdp;
  174. ASSERT(next);
  175. while (! (bhvtovfsops(next))->vfs_quotactl)
  176. next = BHV_NEXT(next);
  177. return ((*bhvtovfsops(next)->vfs_quotactl)(next, cmd, id, addr));
  178. }
  179. void
  180. vfs_init_vnode(
  181. struct bhv_desc *bdp,
  182. struct vnode *vp,
  183. struct bhv_desc *bp,
  184. int unlock)
  185. {
  186. struct bhv_desc *next = bdp;
  187. ASSERT(next);
  188. while (! (bhvtovfsops(next))->vfs_init_vnode)
  189. next = BHV_NEXT(next);
  190. ((*bhvtovfsops(next)->vfs_init_vnode)(next, vp, bp, unlock));
  191. }
  192. void
  193. vfs_force_shutdown(
  194. struct bhv_desc *bdp,
  195. int fl,
  196. char *file,
  197. int line)
  198. {
  199. struct bhv_desc *next = bdp;
  200. ASSERT(next);
  201. while (! (bhvtovfsops(next))->vfs_force_shutdown)
  202. next = BHV_NEXT(next);
  203. ((*bhvtovfsops(next)->vfs_force_shutdown)(next, fl, file, line));
  204. }
  205. void
  206. vfs_freeze(
  207. struct bhv_desc *bdp)
  208. {
  209. struct bhv_desc *next = bdp;
  210. ASSERT(next);
  211. while (! (bhvtovfsops(next))->vfs_freeze)
  212. next = BHV_NEXT(next);
  213. ((*bhvtovfsops(next)->vfs_freeze)(next));
  214. }
  215. vfs_t *
  216. vfs_allocate( void )
  217. {
  218. struct vfs *vfsp;
  219. vfsp = kmem_zalloc(sizeof(vfs_t), KM_SLEEP);
  220. bhv_head_init(VFS_BHVHEAD(vfsp), "vfs");
  221. INIT_LIST_HEAD(&vfsp->vfs_sync_list);
  222. spin_lock_init(&vfsp->vfs_sync_lock);
  223. init_waitqueue_head(&vfsp->vfs_wait_sync_task);
  224. init_waitqueue_head(&vfsp->vfs_wait_single_sync_task);
  225. return vfsp;
  226. }
  227. void
  228. vfs_deallocate(
  229. struct vfs *vfsp)
  230. {
  231. bhv_head_destroy(VFS_BHVHEAD(vfsp));
  232. kmem_free(vfsp, sizeof(vfs_t));
  233. }
  234. void
  235. vfs_insertops(
  236. struct vfs *vfsp,
  237. struct bhv_vfsops *vfsops)
  238. {
  239. struct bhv_desc *bdp;
  240. bdp = kmem_alloc(sizeof(struct bhv_desc), KM_SLEEP);
  241. bhv_desc_init(bdp, NULL, vfsp, vfsops);
  242. bhv_insert(&vfsp->vfs_bh, bdp);
  243. }
  244. void
  245. vfs_insertbhv(
  246. struct vfs *vfsp,
  247. struct bhv_desc *bdp,
  248. struct vfsops *vfsops,
  249. void *mount)
  250. {
  251. bhv_desc_init(bdp, mount, vfsp, vfsops);
  252. bhv_insert_initial(&vfsp->vfs_bh, bdp);
  253. }
  254. void
  255. bhv_remove_vfsops(
  256. struct vfs *vfsp,
  257. int pos)
  258. {
  259. struct bhv_desc *bhv;
  260. bhv = bhv_lookup_range(&vfsp->vfs_bh, pos, pos);
  261. if (!bhv)
  262. return;
  263. bhv_remove(&vfsp->vfs_bh, bhv);
  264. kmem_free(bhv, sizeof(*bhv));
  265. }
  266. void
  267. bhv_remove_all_vfsops(
  268. struct vfs *vfsp,
  269. int freebase)
  270. {
  271. struct xfs_mount *mp;
  272. bhv_remove_vfsops(vfsp, VFS_POSITION_QM);
  273. bhv_remove_vfsops(vfsp, VFS_POSITION_DM);
  274. if (!freebase)
  275. return;
  276. mp = XFS_BHVTOM(bhv_lookup(VFS_BHVHEAD(vfsp), &xfs_vfsops));
  277. VFS_REMOVEBHV(vfsp, &mp->m_bhv);
  278. xfs_mount_free(mp, 0);
  279. }
  280. void
  281. bhv_insert_all_vfsops(
  282. struct vfs *vfsp)
  283. {
  284. struct xfs_mount *mp;
  285. mp = xfs_mount_init();
  286. vfs_insertbhv(vfsp, &mp->m_bhv, &xfs_vfsops, mp);
  287. vfs_insertdmapi(vfsp);
  288. vfs_insertquota(vfsp);
  289. }