xfs_super.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. /*
  2. * Copyright (c) 2000-2005 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_inum.h"
  34. #include "xfs_log.h"
  35. #include "xfs_clnt.h"
  36. #include "xfs_trans.h"
  37. #include "xfs_sb.h"
  38. #include "xfs_dir.h"
  39. #include "xfs_dir2.h"
  40. #include "xfs_alloc.h"
  41. #include "xfs_dmapi.h"
  42. #include "xfs_quota.h"
  43. #include "xfs_mount.h"
  44. #include "xfs_alloc_btree.h"
  45. #include "xfs_bmap_btree.h"
  46. #include "xfs_ialloc_btree.h"
  47. #include "xfs_btree.h"
  48. #include "xfs_ialloc.h"
  49. #include "xfs_attr_sf.h"
  50. #include "xfs_dir_sf.h"
  51. #include "xfs_dir2_sf.h"
  52. #include "xfs_dinode.h"
  53. #include "xfs_inode.h"
  54. #include "xfs_bmap.h"
  55. #include "xfs_bit.h"
  56. #include "xfs_rtalloc.h"
  57. #include "xfs_error.h"
  58. #include "xfs_itable.h"
  59. #include "xfs_rw.h"
  60. #include "xfs_acl.h"
  61. #include "xfs_cap.h"
  62. #include "xfs_mac.h"
  63. #include "xfs_attr.h"
  64. #include "xfs_buf_item.h"
  65. #include "xfs_utils.h"
  66. #include "xfs_version.h"
  67. #include <linux/namei.h>
  68. #include <linux/init.h>
  69. #include <linux/mount.h>
  70. #include <linux/mempool.h>
  71. #include <linux/writeback.h>
  72. STATIC struct quotactl_ops linvfs_qops;
  73. STATIC struct super_operations linvfs_sops;
  74. STATIC kmem_zone_t *xfs_vnode_zone;
  75. STATIC kmem_zone_t *xfs_ioend_zone;
  76. mempool_t *xfs_ioend_pool;
  77. STATIC struct xfs_mount_args *
  78. xfs_args_allocate(
  79. struct super_block *sb)
  80. {
  81. struct xfs_mount_args *args;
  82. args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP);
  83. args->logbufs = args->logbufsize = -1;
  84. strncpy(args->fsname, sb->s_id, MAXNAMELEN);
  85. /* Copy the already-parsed mount(2) flags we're interested in */
  86. if (sb->s_flags & MS_NOATIME)
  87. args->flags |= XFSMNT_NOATIME;
  88. if (sb->s_flags & MS_DIRSYNC)
  89. args->flags |= XFSMNT_DIRSYNC;
  90. if (sb->s_flags & MS_SYNCHRONOUS)
  91. args->flags |= XFSMNT_WSYNC;
  92. /* Default to 32 bit inodes on Linux all the time */
  93. args->flags |= XFSMNT_32BITINODES;
  94. return args;
  95. }
  96. __uint64_t
  97. xfs_max_file_offset(
  98. unsigned int blockshift)
  99. {
  100. unsigned int pagefactor = 1;
  101. unsigned int bitshift = BITS_PER_LONG - 1;
  102. /* Figure out maximum filesize, on Linux this can depend on
  103. * the filesystem blocksize (on 32 bit platforms).
  104. * __block_prepare_write does this in an [unsigned] long...
  105. * page->index << (PAGE_CACHE_SHIFT - bbits)
  106. * So, for page sized blocks (4K on 32 bit platforms),
  107. * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
  108. * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  109. * but for smaller blocksizes it is less (bbits = log2 bsize).
  110. * Note1: get_block_t takes a long (implicit cast from above)
  111. * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
  112. * can optionally convert the [unsigned] long from above into
  113. * an [unsigned] long long.
  114. */
  115. #if BITS_PER_LONG == 32
  116. # if defined(CONFIG_LBD)
  117. ASSERT(sizeof(sector_t) == 8);
  118. pagefactor = PAGE_CACHE_SIZE;
  119. bitshift = BITS_PER_LONG;
  120. # else
  121. pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
  122. # endif
  123. #endif
  124. return (((__uint64_t)pagefactor) << bitshift) - 1;
  125. }
  126. STATIC __inline__ void
  127. xfs_set_inodeops(
  128. struct inode *inode)
  129. {
  130. switch (inode->i_mode & S_IFMT) {
  131. case S_IFREG:
  132. inode->i_op = &linvfs_file_inode_operations;
  133. inode->i_fop = &linvfs_file_operations;
  134. inode->i_mapping->a_ops = &linvfs_aops;
  135. break;
  136. case S_IFDIR:
  137. inode->i_op = &linvfs_dir_inode_operations;
  138. inode->i_fop = &linvfs_dir_operations;
  139. break;
  140. case S_IFLNK:
  141. inode->i_op = &linvfs_symlink_inode_operations;
  142. if (inode->i_blocks)
  143. inode->i_mapping->a_ops = &linvfs_aops;
  144. break;
  145. default:
  146. inode->i_op = &linvfs_file_inode_operations;
  147. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  148. break;
  149. }
  150. }
  151. STATIC __inline__ void
  152. xfs_revalidate_inode(
  153. xfs_mount_t *mp,
  154. vnode_t *vp,
  155. xfs_inode_t *ip)
  156. {
  157. struct inode *inode = LINVFS_GET_IP(vp);
  158. inode->i_mode = ip->i_d.di_mode;
  159. inode->i_nlink = ip->i_d.di_nlink;
  160. inode->i_uid = ip->i_d.di_uid;
  161. inode->i_gid = ip->i_d.di_gid;
  162. switch (inode->i_mode & S_IFMT) {
  163. case S_IFBLK:
  164. case S_IFCHR:
  165. inode->i_rdev =
  166. MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  167. sysv_minor(ip->i_df.if_u2.if_rdev));
  168. break;
  169. default:
  170. inode->i_rdev = 0;
  171. break;
  172. }
  173. inode->i_blksize = PAGE_CACHE_SIZE;
  174. inode->i_generation = ip->i_d.di_gen;
  175. i_size_write(inode, ip->i_d.di_size);
  176. inode->i_blocks =
  177. XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
  178. inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
  179. inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
  180. inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
  181. inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
  182. inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
  183. inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
  184. if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
  185. inode->i_flags |= S_IMMUTABLE;
  186. else
  187. inode->i_flags &= ~S_IMMUTABLE;
  188. if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
  189. inode->i_flags |= S_APPEND;
  190. else
  191. inode->i_flags &= ~S_APPEND;
  192. if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
  193. inode->i_flags |= S_SYNC;
  194. else
  195. inode->i_flags &= ~S_SYNC;
  196. if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
  197. inode->i_flags |= S_NOATIME;
  198. else
  199. inode->i_flags &= ~S_NOATIME;
  200. vp->v_flag &= ~VMODIFIED;
  201. }
  202. void
  203. xfs_initialize_vnode(
  204. bhv_desc_t *bdp,
  205. vnode_t *vp,
  206. bhv_desc_t *inode_bhv,
  207. int unlock)
  208. {
  209. xfs_inode_t *ip = XFS_BHVTOI(inode_bhv);
  210. struct inode *inode = LINVFS_GET_IP(vp);
  211. if (!inode_bhv->bd_vobj) {
  212. vp->v_vfsp = bhvtovfs(bdp);
  213. bhv_desc_init(inode_bhv, ip, vp, &xfs_vnodeops);
  214. bhv_insert(VN_BHV_HEAD(vp), inode_bhv);
  215. }
  216. /*
  217. * We need to set the ops vectors, and unlock the inode, but if
  218. * we have been called during the new inode create process, it is
  219. * too early to fill in the Linux inode. We will get called a
  220. * second time once the inode is properly set up, and then we can
  221. * finish our work.
  222. */
  223. if (ip->i_d.di_mode != 0 && unlock && (inode->i_state & I_NEW)) {
  224. xfs_revalidate_inode(XFS_BHVTOM(bdp), vp, ip);
  225. xfs_set_inodeops(inode);
  226. ip->i_flags &= ~XFS_INEW;
  227. barrier();
  228. unlock_new_inode(inode);
  229. }
  230. }
  231. int
  232. xfs_blkdev_get(
  233. xfs_mount_t *mp,
  234. const char *name,
  235. struct block_device **bdevp)
  236. {
  237. int error = 0;
  238. *bdevp = open_bdev_excl(name, 0, mp);
  239. if (IS_ERR(*bdevp)) {
  240. error = PTR_ERR(*bdevp);
  241. printk("XFS: Invalid device [%s], error=%d\n", name, error);
  242. }
  243. return -error;
  244. }
  245. void
  246. xfs_blkdev_put(
  247. struct block_device *bdev)
  248. {
  249. if (bdev)
  250. close_bdev_excl(bdev);
  251. }
  252. STATIC struct inode *
  253. linvfs_alloc_inode(
  254. struct super_block *sb)
  255. {
  256. vnode_t *vp;
  257. vp = kmem_cache_alloc(xfs_vnode_zone, kmem_flags_convert(KM_SLEEP));
  258. if (!vp)
  259. return NULL;
  260. return LINVFS_GET_IP(vp);
  261. }
  262. STATIC void
  263. linvfs_destroy_inode(
  264. struct inode *inode)
  265. {
  266. kmem_zone_free(xfs_vnode_zone, LINVFS_GET_VP(inode));
  267. }
  268. STATIC void
  269. linvfs_inode_init_once(
  270. void *data,
  271. kmem_cache_t *cachep,
  272. unsigned long flags)
  273. {
  274. vnode_t *vp = (vnode_t *)data;
  275. if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
  276. SLAB_CTOR_CONSTRUCTOR)
  277. inode_init_once(LINVFS_GET_IP(vp));
  278. }
  279. STATIC int
  280. linvfs_init_zones(void)
  281. {
  282. xfs_vnode_zone = kmem_cache_create("xfs_vnode",
  283. sizeof(vnode_t), 0, SLAB_RECLAIM_ACCOUNT,
  284. linvfs_inode_init_once, NULL);
  285. if (!xfs_vnode_zone)
  286. goto out;
  287. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  288. if (!xfs_ioend_zone)
  289. goto out_destroy_vnode_zone;
  290. xfs_ioend_pool = mempool_create(4 * MAX_BUF_PER_PAGE,
  291. mempool_alloc_slab, mempool_free_slab,
  292. xfs_ioend_zone);
  293. if (!xfs_ioend_pool)
  294. goto out_free_ioend_zone;
  295. return 0;
  296. out_free_ioend_zone:
  297. kmem_zone_destroy(xfs_ioend_zone);
  298. out_destroy_vnode_zone:
  299. kmem_zone_destroy(xfs_vnode_zone);
  300. out:
  301. return -ENOMEM;
  302. }
  303. STATIC void
  304. linvfs_destroy_zones(void)
  305. {
  306. mempool_destroy(xfs_ioend_pool);
  307. kmem_zone_destroy(xfs_vnode_zone);
  308. kmem_zone_destroy(xfs_ioend_zone);
  309. }
  310. /*
  311. * Attempt to flush the inode, this will actually fail
  312. * if the inode is pinned, but we dirty the inode again
  313. * at the point when it is unpinned after a log write,
  314. * since this is when the inode itself becomes flushable.
  315. */
  316. STATIC int
  317. linvfs_write_inode(
  318. struct inode *inode,
  319. int sync)
  320. {
  321. vnode_t *vp = LINVFS_GET_VP(inode);
  322. int error = 0, flags = FLUSH_INODE;
  323. if (vp) {
  324. vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address);
  325. if (sync)
  326. flags |= FLUSH_SYNC;
  327. VOP_IFLUSH(vp, flags, error);
  328. if (error == EAGAIN) {
  329. if (sync)
  330. VOP_IFLUSH(vp, flags | FLUSH_LOG, error);
  331. else
  332. error = 0;
  333. }
  334. }
  335. return -error;
  336. }
  337. STATIC void
  338. linvfs_clear_inode(
  339. struct inode *inode)
  340. {
  341. vnode_t *vp = LINVFS_GET_VP(inode);
  342. int error, cache;
  343. vn_trace_entry(vp, "clear_inode", (inst_t *)__return_address);
  344. XFS_STATS_INC(vn_rele);
  345. XFS_STATS_INC(vn_remove);
  346. XFS_STATS_INC(vn_reclaim);
  347. XFS_STATS_DEC(vn_active);
  348. /*
  349. * This can happen because xfs_iget_core calls xfs_idestroy if we
  350. * find an inode with di_mode == 0 but without IGET_CREATE set.
  351. */
  352. if (vp->v_fbhv)
  353. VOP_INACTIVE(vp, NULL, cache);
  354. VN_LOCK(vp);
  355. vp->v_flag &= ~VMODIFIED;
  356. VN_UNLOCK(vp, 0);
  357. if (vp->v_fbhv) {
  358. VOP_RECLAIM(vp, error);
  359. if (error)
  360. panic("vn_purge: cannot reclaim");
  361. }
  362. ASSERT(vp->v_fbhv == NULL);
  363. #ifdef XFS_VNODE_TRACE
  364. ktrace_free(vp->v_trace);
  365. #endif
  366. }
  367. /*
  368. * Enqueue a work item to be picked up by the vfs xfssyncd thread.
  369. * Doing this has two advantages:
  370. * - It saves on stack space, which is tight in certain situations
  371. * - It can be used (with care) as a mechanism to avoid deadlocks.
  372. * Flushing while allocating in a full filesystem requires both.
  373. */
  374. STATIC void
  375. xfs_syncd_queue_work(
  376. struct vfs *vfs,
  377. void *data,
  378. void (*syncer)(vfs_t *, void *))
  379. {
  380. vfs_sync_work_t *work;
  381. work = kmem_alloc(sizeof(struct vfs_sync_work), KM_SLEEP);
  382. INIT_LIST_HEAD(&work->w_list);
  383. work->w_syncer = syncer;
  384. work->w_data = data;
  385. work->w_vfs = vfs;
  386. spin_lock(&vfs->vfs_sync_lock);
  387. list_add_tail(&work->w_list, &vfs->vfs_sync_list);
  388. spin_unlock(&vfs->vfs_sync_lock);
  389. wake_up_process(vfs->vfs_sync_task);
  390. }
  391. /*
  392. * Flush delayed allocate data, attempting to free up reserved space
  393. * from existing allocations. At this point a new allocation attempt
  394. * has failed with ENOSPC and we are in the process of scratching our
  395. * heads, looking about for more room...
  396. */
  397. STATIC void
  398. xfs_flush_inode_work(
  399. vfs_t *vfs,
  400. void *inode)
  401. {
  402. filemap_flush(((struct inode *)inode)->i_mapping);
  403. iput((struct inode *)inode);
  404. }
  405. void
  406. xfs_flush_inode(
  407. xfs_inode_t *ip)
  408. {
  409. struct inode *inode = LINVFS_GET_IP(XFS_ITOV(ip));
  410. struct vfs *vfs = XFS_MTOVFS(ip->i_mount);
  411. igrab(inode);
  412. xfs_syncd_queue_work(vfs, inode, xfs_flush_inode_work);
  413. delay(HZ/2);
  414. }
  415. /*
  416. * This is the "bigger hammer" version of xfs_flush_inode_work...
  417. * (IOW, "If at first you don't succeed, use a Bigger Hammer").
  418. */
  419. STATIC void
  420. xfs_flush_device_work(
  421. vfs_t *vfs,
  422. void *inode)
  423. {
  424. sync_blockdev(vfs->vfs_super->s_bdev);
  425. iput((struct inode *)inode);
  426. }
  427. void
  428. xfs_flush_device(
  429. xfs_inode_t *ip)
  430. {
  431. struct inode *inode = LINVFS_GET_IP(XFS_ITOV(ip));
  432. struct vfs *vfs = XFS_MTOVFS(ip->i_mount);
  433. igrab(inode);
  434. xfs_syncd_queue_work(vfs, inode, xfs_flush_device_work);
  435. delay(HZ/2);
  436. xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
  437. }
  438. #define SYNCD_FLAGS (SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR)
  439. STATIC void
  440. vfs_sync_worker(
  441. vfs_t *vfsp,
  442. void *unused)
  443. {
  444. int error;
  445. if (!(vfsp->vfs_flag & VFS_RDONLY))
  446. VFS_SYNC(vfsp, SYNCD_FLAGS, NULL, error);
  447. vfsp->vfs_sync_seq++;
  448. wmb();
  449. wake_up(&vfsp->vfs_wait_single_sync_task);
  450. }
  451. STATIC int
  452. xfssyncd(
  453. void *arg)
  454. {
  455. long timeleft;
  456. vfs_t *vfsp = (vfs_t *) arg;
  457. struct list_head tmp;
  458. struct vfs_sync_work *work, *n;
  459. daemonize("xfssyncd");
  460. vfsp->vfs_sync_work.w_vfs = vfsp;
  461. vfsp->vfs_sync_work.w_syncer = vfs_sync_worker;
  462. vfsp->vfs_sync_task = current;
  463. wmb();
  464. wake_up(&vfsp->vfs_wait_sync_task);
  465. INIT_LIST_HEAD(&tmp);
  466. timeleft = (xfs_syncd_centisecs * HZ) / 100;
  467. for (;;) {
  468. set_current_state(TASK_INTERRUPTIBLE);
  469. timeleft = schedule_timeout(timeleft);
  470. /* swsusp */
  471. try_to_freeze();
  472. if (vfsp->vfs_flag & VFS_UMOUNT)
  473. break;
  474. spin_lock(&vfsp->vfs_sync_lock);
  475. /*
  476. * We can get woken by laptop mode, to do a sync -
  477. * that's the (only!) case where the list would be
  478. * empty with time remaining.
  479. */
  480. if (!timeleft || list_empty(&vfsp->vfs_sync_list)) {
  481. if (!timeleft)
  482. timeleft = (xfs_syncd_centisecs * HZ) / 100;
  483. INIT_LIST_HEAD(&vfsp->vfs_sync_work.w_list);
  484. list_add_tail(&vfsp->vfs_sync_work.w_list,
  485. &vfsp->vfs_sync_list);
  486. }
  487. list_for_each_entry_safe(work, n, &vfsp->vfs_sync_list, w_list)
  488. list_move(&work->w_list, &tmp);
  489. spin_unlock(&vfsp->vfs_sync_lock);
  490. list_for_each_entry_safe(work, n, &tmp, w_list) {
  491. (*work->w_syncer)(vfsp, work->w_data);
  492. list_del(&work->w_list);
  493. if (work == &vfsp->vfs_sync_work)
  494. continue;
  495. kmem_free(work, sizeof(struct vfs_sync_work));
  496. }
  497. }
  498. vfsp->vfs_sync_task = NULL;
  499. wmb();
  500. wake_up(&vfsp->vfs_wait_sync_task);
  501. return 0;
  502. }
  503. STATIC int
  504. linvfs_start_syncd(
  505. vfs_t *vfsp)
  506. {
  507. int pid;
  508. pid = kernel_thread(xfssyncd, (void *) vfsp,
  509. CLONE_VM | CLONE_FS | CLONE_FILES);
  510. if (pid < 0)
  511. return -pid;
  512. wait_event(vfsp->vfs_wait_sync_task, vfsp->vfs_sync_task);
  513. return 0;
  514. }
  515. STATIC void
  516. linvfs_stop_syncd(
  517. vfs_t *vfsp)
  518. {
  519. vfsp->vfs_flag |= VFS_UMOUNT;
  520. wmb();
  521. wake_up_process(vfsp->vfs_sync_task);
  522. wait_event(vfsp->vfs_wait_sync_task, !vfsp->vfs_sync_task);
  523. }
  524. STATIC void
  525. linvfs_put_super(
  526. struct super_block *sb)
  527. {
  528. vfs_t *vfsp = LINVFS_GET_VFS(sb);
  529. int error;
  530. linvfs_stop_syncd(vfsp);
  531. VFS_SYNC(vfsp, SYNC_ATTR|SYNC_DELWRI, NULL, error);
  532. if (!error)
  533. VFS_UNMOUNT(vfsp, 0, NULL, error);
  534. if (error) {
  535. printk("XFS unmount got error %d\n", error);
  536. printk("%s: vfsp/0x%p left dangling!\n", __FUNCTION__, vfsp);
  537. return;
  538. }
  539. vfs_deallocate(vfsp);
  540. }
  541. STATIC void
  542. linvfs_write_super(
  543. struct super_block *sb)
  544. {
  545. vfs_t *vfsp = LINVFS_GET_VFS(sb);
  546. int error;
  547. if (sb->s_flags & MS_RDONLY) {
  548. sb->s_dirt = 0; /* paranoia */
  549. return;
  550. }
  551. /* Push the log and superblock a little */
  552. VFS_SYNC(vfsp, SYNC_FSDATA, NULL, error);
  553. sb->s_dirt = 0;
  554. }
  555. STATIC int
  556. linvfs_sync_super(
  557. struct super_block *sb,
  558. int wait)
  559. {
  560. vfs_t *vfsp = LINVFS_GET_VFS(sb);
  561. int error;
  562. int flags = SYNC_FSDATA;
  563. if (unlikely(sb->s_frozen == SB_FREEZE_WRITE))
  564. flags = SYNC_QUIESCE;
  565. else
  566. flags = SYNC_FSDATA | (wait ? SYNC_WAIT : 0);
  567. VFS_SYNC(vfsp, flags, NULL, error);
  568. sb->s_dirt = 0;
  569. if (unlikely(laptop_mode)) {
  570. int prev_sync_seq = vfsp->vfs_sync_seq;
  571. /*
  572. * The disk must be active because we're syncing.
  573. * We schedule xfssyncd now (now that the disk is
  574. * active) instead of later (when it might not be).
  575. */
  576. wake_up_process(vfsp->vfs_sync_task);
  577. /*
  578. * We have to wait for the sync iteration to complete.
  579. * If we don't, the disk activity caused by the sync
  580. * will come after the sync is completed, and that
  581. * triggers another sync from laptop mode.
  582. */
  583. wait_event(vfsp->vfs_wait_single_sync_task,
  584. vfsp->vfs_sync_seq != prev_sync_seq);
  585. }
  586. return -error;
  587. }
  588. STATIC int
  589. linvfs_statfs(
  590. struct super_block *sb,
  591. struct kstatfs *statp)
  592. {
  593. vfs_t *vfsp = LINVFS_GET_VFS(sb);
  594. int error;
  595. VFS_STATVFS(vfsp, statp, NULL, error);
  596. return -error;
  597. }
  598. STATIC int
  599. linvfs_remount(
  600. struct super_block *sb,
  601. int *flags,
  602. char *options)
  603. {
  604. vfs_t *vfsp = LINVFS_GET_VFS(sb);
  605. struct xfs_mount_args *args = xfs_args_allocate(sb);
  606. int error;
  607. VFS_PARSEARGS(vfsp, options, args, 1, error);
  608. if (!error)
  609. VFS_MNTUPDATE(vfsp, flags, args, error);
  610. kmem_free(args, sizeof(*args));
  611. return -error;
  612. }
  613. STATIC void
  614. linvfs_freeze_fs(
  615. struct super_block *sb)
  616. {
  617. VFS_FREEZE(LINVFS_GET_VFS(sb));
  618. }
  619. STATIC int
  620. linvfs_show_options(
  621. struct seq_file *m,
  622. struct vfsmount *mnt)
  623. {
  624. struct vfs *vfsp = LINVFS_GET_VFS(mnt->mnt_sb);
  625. int error;
  626. VFS_SHOWARGS(vfsp, m, error);
  627. return error;
  628. }
  629. STATIC int
  630. linvfs_getxstate(
  631. struct super_block *sb,
  632. struct fs_quota_stat *fqs)
  633. {
  634. struct vfs *vfsp = LINVFS_GET_VFS(sb);
  635. int error;
  636. VFS_QUOTACTL(vfsp, Q_XGETQSTAT, 0, (caddr_t)fqs, error);
  637. return -error;
  638. }
  639. STATIC int
  640. linvfs_setxstate(
  641. struct super_block *sb,
  642. unsigned int flags,
  643. int op)
  644. {
  645. struct vfs *vfsp = LINVFS_GET_VFS(sb);
  646. int error;
  647. VFS_QUOTACTL(vfsp, op, 0, (caddr_t)&flags, error);
  648. return -error;
  649. }
  650. STATIC int
  651. linvfs_getxquota(
  652. struct super_block *sb,
  653. int type,
  654. qid_t id,
  655. struct fs_disk_quota *fdq)
  656. {
  657. struct vfs *vfsp = LINVFS_GET_VFS(sb);
  658. int error, getmode;
  659. getmode = (type == USRQUOTA) ? Q_XGETQUOTA :
  660. ((type == GRPQUOTA) ? Q_XGETGQUOTA : Q_XGETPQUOTA);
  661. VFS_QUOTACTL(vfsp, getmode, id, (caddr_t)fdq, error);
  662. return -error;
  663. }
  664. STATIC int
  665. linvfs_setxquota(
  666. struct super_block *sb,
  667. int type,
  668. qid_t id,
  669. struct fs_disk_quota *fdq)
  670. {
  671. struct vfs *vfsp = LINVFS_GET_VFS(sb);
  672. int error, setmode;
  673. setmode = (type == USRQUOTA) ? Q_XSETQLIM :
  674. ((type == GRPQUOTA) ? Q_XSETGQLIM : Q_XSETPQLIM);
  675. VFS_QUOTACTL(vfsp, setmode, id, (caddr_t)fdq, error);
  676. return -error;
  677. }
  678. STATIC int
  679. linvfs_fill_super(
  680. struct super_block *sb,
  681. void *data,
  682. int silent)
  683. {
  684. vnode_t *rootvp;
  685. struct vfs *vfsp = vfs_allocate();
  686. struct xfs_mount_args *args = xfs_args_allocate(sb);
  687. struct kstatfs statvfs;
  688. int error, error2;
  689. vfsp->vfs_super = sb;
  690. LINVFS_SET_VFS(sb, vfsp);
  691. if (sb->s_flags & MS_RDONLY)
  692. vfsp->vfs_flag |= VFS_RDONLY;
  693. bhv_insert_all_vfsops(vfsp);
  694. VFS_PARSEARGS(vfsp, (char *)data, args, 0, error);
  695. if (error) {
  696. bhv_remove_all_vfsops(vfsp, 1);
  697. goto fail_vfsop;
  698. }
  699. sb_min_blocksize(sb, BBSIZE);
  700. #ifdef CONFIG_XFS_EXPORT
  701. sb->s_export_op = &linvfs_export_ops;
  702. #endif
  703. sb->s_qcop = &linvfs_qops;
  704. sb->s_op = &linvfs_sops;
  705. VFS_MOUNT(vfsp, args, NULL, error);
  706. if (error) {
  707. bhv_remove_all_vfsops(vfsp, 1);
  708. goto fail_vfsop;
  709. }
  710. VFS_STATVFS(vfsp, &statvfs, NULL, error);
  711. if (error)
  712. goto fail_unmount;
  713. sb->s_dirt = 1;
  714. sb->s_magic = statvfs.f_type;
  715. sb->s_blocksize = statvfs.f_bsize;
  716. sb->s_blocksize_bits = ffs(statvfs.f_bsize) - 1;
  717. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  718. sb->s_time_gran = 1;
  719. set_posix_acl_flag(sb);
  720. VFS_ROOT(vfsp, &rootvp, error);
  721. if (error)
  722. goto fail_unmount;
  723. sb->s_root = d_alloc_root(LINVFS_GET_IP(rootvp));
  724. if (!sb->s_root) {
  725. error = ENOMEM;
  726. goto fail_vnrele;
  727. }
  728. if (is_bad_inode(sb->s_root->d_inode)) {
  729. error = EINVAL;
  730. goto fail_vnrele;
  731. }
  732. if ((error = linvfs_start_syncd(vfsp)))
  733. goto fail_vnrele;
  734. vn_trace_exit(rootvp, __FUNCTION__, (inst_t *)__return_address);
  735. kmem_free(args, sizeof(*args));
  736. return 0;
  737. fail_vnrele:
  738. if (sb->s_root) {
  739. dput(sb->s_root);
  740. sb->s_root = NULL;
  741. } else {
  742. VN_RELE(rootvp);
  743. }
  744. fail_unmount:
  745. VFS_UNMOUNT(vfsp, 0, NULL, error2);
  746. fail_vfsop:
  747. vfs_deallocate(vfsp);
  748. kmem_free(args, sizeof(*args));
  749. return -error;
  750. }
  751. STATIC struct super_block *
  752. linvfs_get_sb(
  753. struct file_system_type *fs_type,
  754. int flags,
  755. const char *dev_name,
  756. void *data)
  757. {
  758. return get_sb_bdev(fs_type, flags, dev_name, data, linvfs_fill_super);
  759. }
  760. STATIC struct super_operations linvfs_sops = {
  761. .alloc_inode = linvfs_alloc_inode,
  762. .destroy_inode = linvfs_destroy_inode,
  763. .write_inode = linvfs_write_inode,
  764. .clear_inode = linvfs_clear_inode,
  765. .put_super = linvfs_put_super,
  766. .write_super = linvfs_write_super,
  767. .sync_fs = linvfs_sync_super,
  768. .write_super_lockfs = linvfs_freeze_fs,
  769. .statfs = linvfs_statfs,
  770. .remount_fs = linvfs_remount,
  771. .show_options = linvfs_show_options,
  772. };
  773. STATIC struct quotactl_ops linvfs_qops = {
  774. .get_xstate = linvfs_getxstate,
  775. .set_xstate = linvfs_setxstate,
  776. .get_xquota = linvfs_getxquota,
  777. .set_xquota = linvfs_setxquota,
  778. };
  779. STATIC struct file_system_type xfs_fs_type = {
  780. .owner = THIS_MODULE,
  781. .name = "xfs",
  782. .get_sb = linvfs_get_sb,
  783. .kill_sb = kill_block_super,
  784. .fs_flags = FS_REQUIRES_DEV,
  785. };
  786. STATIC int __init
  787. init_xfs_fs( void )
  788. {
  789. int error;
  790. struct sysinfo si;
  791. static char message[] __initdata = KERN_INFO \
  792. XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
  793. printk(message);
  794. si_meminfo(&si);
  795. xfs_physmem = si.totalram;
  796. ktrace_init(64);
  797. error = linvfs_init_zones();
  798. if (error < 0)
  799. goto undo_zones;
  800. error = pagebuf_init();
  801. if (error < 0)
  802. goto undo_pagebuf;
  803. vn_init();
  804. xfs_init();
  805. uuid_init();
  806. vfs_initquota();
  807. error = register_filesystem(&xfs_fs_type);
  808. if (error)
  809. goto undo_register;
  810. XFS_DM_INIT(&xfs_fs_type);
  811. return 0;
  812. undo_register:
  813. pagebuf_terminate();
  814. undo_pagebuf:
  815. linvfs_destroy_zones();
  816. undo_zones:
  817. return error;
  818. }
  819. STATIC void __exit
  820. exit_xfs_fs( void )
  821. {
  822. vfs_exitquota();
  823. XFS_DM_EXIT(&xfs_fs_type);
  824. unregister_filesystem(&xfs_fs_type);
  825. xfs_cleanup();
  826. pagebuf_terminate();
  827. linvfs_destroy_zones();
  828. ktrace_uninit();
  829. }
  830. module_init(init_xfs_fs);
  831. module_exit(exit_xfs_fs);
  832. MODULE_AUTHOR("Silicon Graphics, Inc.");
  833. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  834. MODULE_LICENSE("GPL");