xfs_super.c 21 KB

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