xfs_vfs.c 6.7 KB

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