xfs_super.c 21 KB

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