xfs_super.c 21 KB

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