xfs_super.c 21 KB

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