PageRenderTime 80ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/fs/gfs2/ops_fstype.c

https://bitbucket.org/jdstroy/ipaq214
C | 1354 lines | 1052 code | 201 blank | 101 comment | 166 complexity | 5f313ad3f117a43236cfd6be116f513c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/blkdev.h>
  15. #include <linux/kthread.h>
  16. #include <linux/namei.h>
  17. #include <linux/mount.h>
  18. #include <linux/gfs2_ondisk.h>
  19. #include "gfs2.h"
  20. #include "incore.h"
  21. #include "bmap.h"
  22. #include "glock.h"
  23. #include "glops.h"
  24. #include "inode.h"
  25. #include "recovery.h"
  26. #include "rgrp.h"
  27. #include "super.h"
  28. #include "sys.h"
  29. #include "util.h"
  30. #include "log.h"
  31. #include "quota.h"
  32. #include "dir.h"
  33. #define DO 0
  34. #define UNDO 1
  35. static const u32 gfs2_old_fs_formats[] = {
  36. 0
  37. };
  38. static const u32 gfs2_old_multihost_formats[] = {
  39. 0
  40. };
  41. /**
  42. * gfs2_tune_init - Fill a gfs2_tune structure with default values
  43. * @gt: tune
  44. *
  45. */
  46. static void gfs2_tune_init(struct gfs2_tune *gt)
  47. {
  48. spin_lock_init(&gt->gt_spin);
  49. gt->gt_incore_log_blocks = 1024;
  50. gt->gt_log_flush_secs = 60;
  51. gt->gt_recoverd_secs = 60;
  52. gt->gt_logd_secs = 1;
  53. gt->gt_quota_simul_sync = 64;
  54. gt->gt_quota_warn_period = 10;
  55. gt->gt_quota_scale_num = 1;
  56. gt->gt_quota_scale_den = 1;
  57. gt->gt_quota_quantum = 60;
  58. gt->gt_new_files_jdata = 0;
  59. gt->gt_max_readahead = 1 << 18;
  60. gt->gt_stall_secs = 600;
  61. gt->gt_complain_secs = 10;
  62. gt->gt_statfs_quantum = 30;
  63. gt->gt_statfs_slow = 0;
  64. }
  65. static struct gfs2_sbd *init_sbd(struct super_block *sb)
  66. {
  67. struct gfs2_sbd *sdp;
  68. sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL);
  69. if (!sdp)
  70. return NULL;
  71. sb->s_fs_info = sdp;
  72. sdp->sd_vfs = sb;
  73. gfs2_tune_init(&sdp->sd_tune);
  74. mutex_init(&sdp->sd_inum_mutex);
  75. spin_lock_init(&sdp->sd_statfs_spin);
  76. spin_lock_init(&sdp->sd_rindex_spin);
  77. mutex_init(&sdp->sd_rindex_mutex);
  78. INIT_LIST_HEAD(&sdp->sd_rindex_list);
  79. INIT_LIST_HEAD(&sdp->sd_rindex_mru_list);
  80. INIT_LIST_HEAD(&sdp->sd_jindex_list);
  81. spin_lock_init(&sdp->sd_jindex_spin);
  82. mutex_init(&sdp->sd_jindex_mutex);
  83. INIT_LIST_HEAD(&sdp->sd_quota_list);
  84. mutex_init(&sdp->sd_quota_mutex);
  85. init_waitqueue_head(&sdp->sd_quota_wait);
  86. INIT_LIST_HEAD(&sdp->sd_trunc_list);
  87. spin_lock_init(&sdp->sd_trunc_lock);
  88. spin_lock_init(&sdp->sd_log_lock);
  89. INIT_LIST_HEAD(&sdp->sd_log_le_buf);
  90. INIT_LIST_HEAD(&sdp->sd_log_le_revoke);
  91. INIT_LIST_HEAD(&sdp->sd_log_le_rg);
  92. INIT_LIST_HEAD(&sdp->sd_log_le_databuf);
  93. INIT_LIST_HEAD(&sdp->sd_log_le_ordered);
  94. mutex_init(&sdp->sd_log_reserve_mutex);
  95. INIT_LIST_HEAD(&sdp->sd_ail1_list);
  96. INIT_LIST_HEAD(&sdp->sd_ail2_list);
  97. init_rwsem(&sdp->sd_log_flush_lock);
  98. atomic_set(&sdp->sd_log_in_flight, 0);
  99. init_waitqueue_head(&sdp->sd_log_flush_wait);
  100. INIT_LIST_HEAD(&sdp->sd_revoke_list);
  101. mutex_init(&sdp->sd_freeze_lock);
  102. return sdp;
  103. }
  104. /**
  105. * gfs2_check_sb - Check superblock
  106. * @sdp: the filesystem
  107. * @sb: The superblock
  108. * @silent: Don't print a message if the check fails
  109. *
  110. * Checks the version code of the FS is one that we understand how to
  111. * read and that the sizes of the various on-disk structures have not
  112. * changed.
  113. */
  114. static int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb_host *sb, int silent)
  115. {
  116. unsigned int x;
  117. if (sb->sb_magic != GFS2_MAGIC ||
  118. sb->sb_type != GFS2_METATYPE_SB) {
  119. if (!silent)
  120. printk(KERN_WARNING "GFS2: not a GFS2 filesystem\n");
  121. return -EINVAL;
  122. }
  123. /* If format numbers match exactly, we're done. */
  124. if (sb->sb_fs_format == GFS2_FORMAT_FS &&
  125. sb->sb_multihost_format == GFS2_FORMAT_MULTI)
  126. return 0;
  127. if (sb->sb_fs_format != GFS2_FORMAT_FS) {
  128. for (x = 0; gfs2_old_fs_formats[x]; x++)
  129. if (gfs2_old_fs_formats[x] == sb->sb_fs_format)
  130. break;
  131. if (!gfs2_old_fs_formats[x]) {
  132. printk(KERN_WARNING
  133. "GFS2: code version (%u, %u) is incompatible "
  134. "with ondisk format (%u, %u)\n",
  135. GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
  136. sb->sb_fs_format, sb->sb_multihost_format);
  137. printk(KERN_WARNING
  138. "GFS2: I don't know how to upgrade this FS\n");
  139. return -EINVAL;
  140. }
  141. }
  142. if (sb->sb_multihost_format != GFS2_FORMAT_MULTI) {
  143. for (x = 0; gfs2_old_multihost_formats[x]; x++)
  144. if (gfs2_old_multihost_formats[x] ==
  145. sb->sb_multihost_format)
  146. break;
  147. if (!gfs2_old_multihost_formats[x]) {
  148. printk(KERN_WARNING
  149. "GFS2: code version (%u, %u) is incompatible "
  150. "with ondisk format (%u, %u)\n",
  151. GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
  152. sb->sb_fs_format, sb->sb_multihost_format);
  153. printk(KERN_WARNING
  154. "GFS2: I don't know how to upgrade this FS\n");
  155. return -EINVAL;
  156. }
  157. }
  158. if (!sdp->sd_args.ar_upgrade) {
  159. printk(KERN_WARNING
  160. "GFS2: code version (%u, %u) is incompatible "
  161. "with ondisk format (%u, %u)\n",
  162. GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
  163. sb->sb_fs_format, sb->sb_multihost_format);
  164. printk(KERN_INFO
  165. "GFS2: Use the \"upgrade\" mount option to upgrade "
  166. "the FS\n");
  167. printk(KERN_INFO "GFS2: See the manual for more details\n");
  168. return -EINVAL;
  169. }
  170. return 0;
  171. }
  172. static void end_bio_io_page(struct bio *bio, int error)
  173. {
  174. struct page *page = bio->bi_private;
  175. if (!error)
  176. SetPageUptodate(page);
  177. else
  178. printk(KERN_WARNING "gfs2: error %d reading superblock\n", error);
  179. unlock_page(page);
  180. }
  181. static void gfs2_sb_in(struct gfs2_sb_host *sb, const void *buf)
  182. {
  183. const struct gfs2_sb *str = buf;
  184. sb->sb_magic = be32_to_cpu(str->sb_header.mh_magic);
  185. sb->sb_type = be32_to_cpu(str->sb_header.mh_type);
  186. sb->sb_format = be32_to_cpu(str->sb_header.mh_format);
  187. sb->sb_fs_format = be32_to_cpu(str->sb_fs_format);
  188. sb->sb_multihost_format = be32_to_cpu(str->sb_multihost_format);
  189. sb->sb_bsize = be32_to_cpu(str->sb_bsize);
  190. sb->sb_bsize_shift = be32_to_cpu(str->sb_bsize_shift);
  191. sb->sb_master_dir.no_addr = be64_to_cpu(str->sb_master_dir.no_addr);
  192. sb->sb_master_dir.no_formal_ino = be64_to_cpu(str->sb_master_dir.no_formal_ino);
  193. sb->sb_root_dir.no_addr = be64_to_cpu(str->sb_root_dir.no_addr);
  194. sb->sb_root_dir.no_formal_ino = be64_to_cpu(str->sb_root_dir.no_formal_ino);
  195. memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN);
  196. memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN);
  197. memcpy(sb->sb_uuid, str->sb_uuid, 16);
  198. }
  199. /**
  200. * gfs2_read_super - Read the gfs2 super block from disk
  201. * @sdp: The GFS2 super block
  202. * @sector: The location of the super block
  203. * @error: The error code to return
  204. *
  205. * This uses the bio functions to read the super block from disk
  206. * because we want to be 100% sure that we never read cached data.
  207. * A super block is read twice only during each GFS2 mount and is
  208. * never written to by the filesystem. The first time its read no
  209. * locks are held, and the only details which are looked at are those
  210. * relating to the locking protocol. Once locking is up and working,
  211. * the sb is read again under the lock to establish the location of
  212. * the master directory (contains pointers to journals etc) and the
  213. * root directory.
  214. *
  215. * Returns: 0 on success or error
  216. */
  217. static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector)
  218. {
  219. struct super_block *sb = sdp->sd_vfs;
  220. struct gfs2_sb *p;
  221. struct page *page;
  222. struct bio *bio;
  223. page = alloc_page(GFP_NOFS);
  224. if (unlikely(!page))
  225. return -ENOBUFS;
  226. ClearPageUptodate(page);
  227. ClearPageDirty(page);
  228. lock_page(page);
  229. bio = bio_alloc(GFP_NOFS, 1);
  230. bio->bi_sector = sector * (sb->s_blocksize >> 9);
  231. bio->bi_bdev = sb->s_bdev;
  232. bio_add_page(bio, page, PAGE_SIZE, 0);
  233. bio->bi_end_io = end_bio_io_page;
  234. bio->bi_private = page;
  235. submit_bio(READ_SYNC | (1 << BIO_RW_META), bio);
  236. wait_on_page_locked(page);
  237. bio_put(bio);
  238. if (!PageUptodate(page)) {
  239. __free_page(page);
  240. return -EIO;
  241. }
  242. p = kmap(page);
  243. gfs2_sb_in(&sdp->sd_sb, p);
  244. kunmap(page);
  245. __free_page(page);
  246. return 0;
  247. }
  248. /**
  249. * gfs2_read_sb - Read super block
  250. * @sdp: The GFS2 superblock
  251. * @silent: Don't print message if mount fails
  252. *
  253. */
  254. static int gfs2_read_sb(struct gfs2_sbd *sdp, int silent)
  255. {
  256. u32 hash_blocks, ind_blocks, leaf_blocks;
  257. u32 tmp_blocks;
  258. unsigned int x;
  259. int error;
  260. error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
  261. if (error) {
  262. if (!silent)
  263. fs_err(sdp, "can't read superblock\n");
  264. return error;
  265. }
  266. error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
  267. if (error)
  268. return error;
  269. sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
  270. GFS2_BASIC_BLOCK_SHIFT;
  271. sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
  272. sdp->sd_diptrs = (sdp->sd_sb.sb_bsize -
  273. sizeof(struct gfs2_dinode)) / sizeof(u64);
  274. sdp->sd_inptrs = (sdp->sd_sb.sb_bsize -
  275. sizeof(struct gfs2_meta_header)) / sizeof(u64);
  276. sdp->sd_jbsize = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header);
  277. sdp->sd_hash_bsize = sdp->sd_sb.sb_bsize / 2;
  278. sdp->sd_hash_bsize_shift = sdp->sd_sb.sb_bsize_shift - 1;
  279. sdp->sd_hash_ptrs = sdp->sd_hash_bsize / sizeof(u64);
  280. sdp->sd_qc_per_block = (sdp->sd_sb.sb_bsize -
  281. sizeof(struct gfs2_meta_header)) /
  282. sizeof(struct gfs2_quota_change);
  283. /* Compute maximum reservation required to add a entry to a directory */
  284. hash_blocks = DIV_ROUND_UP(sizeof(u64) * (1 << GFS2_DIR_MAX_DEPTH),
  285. sdp->sd_jbsize);
  286. ind_blocks = 0;
  287. for (tmp_blocks = hash_blocks; tmp_blocks > sdp->sd_diptrs;) {
  288. tmp_blocks = DIV_ROUND_UP(tmp_blocks, sdp->sd_inptrs);
  289. ind_blocks += tmp_blocks;
  290. }
  291. leaf_blocks = 2 + GFS2_DIR_MAX_DEPTH;
  292. sdp->sd_max_dirres = hash_blocks + ind_blocks + leaf_blocks;
  293. sdp->sd_heightsize[0] = sdp->sd_sb.sb_bsize -
  294. sizeof(struct gfs2_dinode);
  295. sdp->sd_heightsize[1] = sdp->sd_sb.sb_bsize * sdp->sd_diptrs;
  296. for (x = 2;; x++) {
  297. u64 space, d;
  298. u32 m;
  299. space = sdp->sd_heightsize[x - 1] * sdp->sd_inptrs;
  300. d = space;
  301. m = do_div(d, sdp->sd_inptrs);
  302. if (d != sdp->sd_heightsize[x - 1] || m)
  303. break;
  304. sdp->sd_heightsize[x] = space;
  305. }
  306. sdp->sd_max_height = x;
  307. sdp->sd_heightsize[x] = ~0;
  308. gfs2_assert(sdp, sdp->sd_max_height <= GFS2_MAX_META_HEIGHT);
  309. sdp->sd_jheightsize[0] = sdp->sd_sb.sb_bsize -
  310. sizeof(struct gfs2_dinode);
  311. sdp->sd_jheightsize[1] = sdp->sd_jbsize * sdp->sd_diptrs;
  312. for (x = 2;; x++) {
  313. u64 space, d;
  314. u32 m;
  315. space = sdp->sd_jheightsize[x - 1] * sdp->sd_inptrs;
  316. d = space;
  317. m = do_div(d, sdp->sd_inptrs);
  318. if (d != sdp->sd_jheightsize[x - 1] || m)
  319. break;
  320. sdp->sd_jheightsize[x] = space;
  321. }
  322. sdp->sd_max_jheight = x;
  323. sdp->sd_jheightsize[x] = ~0;
  324. gfs2_assert(sdp, sdp->sd_max_jheight <= GFS2_MAX_META_HEIGHT);
  325. return 0;
  326. }
  327. static int init_names(struct gfs2_sbd *sdp, int silent)
  328. {
  329. char *proto, *table;
  330. int error = 0;
  331. proto = sdp->sd_args.ar_lockproto;
  332. table = sdp->sd_args.ar_locktable;
  333. /* Try to autodetect */
  334. if (!proto[0] || !table[0]) {
  335. error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
  336. if (error)
  337. return error;
  338. error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
  339. if (error)
  340. goto out;
  341. if (!proto[0])
  342. proto = sdp->sd_sb.sb_lockproto;
  343. if (!table[0])
  344. table = sdp->sd_sb.sb_locktable;
  345. }
  346. if (!table[0])
  347. table = sdp->sd_vfs->s_id;
  348. strlcpy(sdp->sd_proto_name, proto, GFS2_FSNAME_LEN);
  349. strlcpy(sdp->sd_table_name, table, GFS2_FSNAME_LEN);
  350. table = sdp->sd_table_name;
  351. while ((table = strchr(table, '/')))
  352. *table = '_';
  353. out:
  354. return error;
  355. }
  356. static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh,
  357. int undo)
  358. {
  359. int error = 0;
  360. if (undo)
  361. goto fail_trans;
  362. error = gfs2_glock_nq_num(sdp,
  363. GFS2_MOUNT_LOCK, &gfs2_nondisk_glops,
  364. LM_ST_EXCLUSIVE, LM_FLAG_NOEXP | GL_NOCACHE,
  365. mount_gh);
  366. if (error) {
  367. fs_err(sdp, "can't acquire mount glock: %d\n", error);
  368. goto fail;
  369. }
  370. error = gfs2_glock_nq_num(sdp,
  371. GFS2_LIVE_LOCK, &gfs2_nondisk_glops,
  372. LM_ST_SHARED,
  373. LM_FLAG_NOEXP | GL_EXACT,
  374. &sdp->sd_live_gh);
  375. if (error) {
  376. fs_err(sdp, "can't acquire live glock: %d\n", error);
  377. goto fail_mount;
  378. }
  379. error = gfs2_glock_get(sdp, GFS2_RENAME_LOCK, &gfs2_nondisk_glops,
  380. CREATE, &sdp->sd_rename_gl);
  381. if (error) {
  382. fs_err(sdp, "can't create rename glock: %d\n", error);
  383. goto fail_live;
  384. }
  385. error = gfs2_glock_get(sdp, GFS2_TRANS_LOCK, &gfs2_trans_glops,
  386. CREATE, &sdp->sd_trans_gl);
  387. if (error) {
  388. fs_err(sdp, "can't create transaction glock: %d\n", error);
  389. goto fail_rename;
  390. }
  391. return 0;
  392. fail_trans:
  393. gfs2_glock_put(sdp->sd_trans_gl);
  394. fail_rename:
  395. gfs2_glock_put(sdp->sd_rename_gl);
  396. fail_live:
  397. gfs2_glock_dq_uninit(&sdp->sd_live_gh);
  398. fail_mount:
  399. gfs2_glock_dq_uninit(mount_gh);
  400. fail:
  401. return error;
  402. }
  403. static int gfs2_lookup_root(struct super_block *sb, struct dentry **dptr,
  404. u64 no_addr, const char *name)
  405. {
  406. struct gfs2_sbd *sdp = sb->s_fs_info;
  407. struct dentry *dentry;
  408. struct inode *inode;
  409. inode = gfs2_inode_lookup(sb, DT_DIR, no_addr, 0, 0);
  410. if (IS_ERR(inode)) {
  411. fs_err(sdp, "can't read in %s inode: %ld\n", name, PTR_ERR(inode));
  412. return PTR_ERR(inode);
  413. }
  414. dentry = d_alloc_root(inode);
  415. if (!dentry) {
  416. fs_err(sdp, "can't alloc %s dentry\n", name);
  417. iput(inode);
  418. return -ENOMEM;
  419. }
  420. dentry->d_op = &gfs2_dops;
  421. *dptr = dentry;
  422. return 0;
  423. }
  424. static int init_sb(struct gfs2_sbd *sdp, int silent)
  425. {
  426. struct super_block *sb = sdp->sd_vfs;
  427. struct gfs2_holder sb_gh;
  428. u64 no_addr;
  429. int ret;
  430. ret = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops,
  431. LM_ST_SHARED, 0, &sb_gh);
  432. if (ret) {
  433. fs_err(sdp, "can't acquire superblock glock: %d\n", ret);
  434. return ret;
  435. }
  436. ret = gfs2_read_sb(sdp, silent);
  437. if (ret) {
  438. fs_err(sdp, "can't read superblock: %d\n", ret);
  439. goto out;
  440. }
  441. /* Set up the buffer cache and SB for real */
  442. if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) {
  443. ret = -EINVAL;
  444. fs_err(sdp, "FS block size (%u) is too small for device "
  445. "block size (%u)\n",
  446. sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev));
  447. goto out;
  448. }
  449. if (sdp->sd_sb.sb_bsize > PAGE_SIZE) {
  450. ret = -EINVAL;
  451. fs_err(sdp, "FS block size (%u) is too big for machine "
  452. "page size (%u)\n",
  453. sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE);
  454. goto out;
  455. }
  456. sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
  457. /* Get the root inode */
  458. no_addr = sdp->sd_sb.sb_root_dir.no_addr;
  459. ret = gfs2_lookup_root(sb, &sdp->sd_root_dir, no_addr, "root");
  460. if (ret)
  461. goto out;
  462. /* Get the master inode */
  463. no_addr = sdp->sd_sb.sb_master_dir.no_addr;
  464. ret = gfs2_lookup_root(sb, &sdp->sd_master_dir, no_addr, "master");
  465. if (ret) {
  466. dput(sdp->sd_root_dir);
  467. goto out;
  468. }
  469. sb->s_root = dget(sdp->sd_args.ar_meta ? sdp->sd_master_dir : sdp->sd_root_dir);
  470. out:
  471. gfs2_glock_dq_uninit(&sb_gh);
  472. return ret;
  473. }
  474. /**
  475. * map_journal_extents - create a reusable "extent" mapping from all logical
  476. * blocks to all physical blocks for the given journal. This will save
  477. * us time when writing journal blocks. Most journals will have only one
  478. * extent that maps all their logical blocks. That's because gfs2.mkfs
  479. * arranges the journal blocks sequentially to maximize performance.
  480. * So the extent would map the first block for the entire file length.
  481. * However, gfs2_jadd can happen while file activity is happening, so
  482. * those journals may not be sequential. Less likely is the case where
  483. * the users created their own journals by mounting the metafs and
  484. * laying it out. But it's still possible. These journals might have
  485. * several extents.
  486. *
  487. * TODO: This should be done in bigger chunks rather than one block at a time,
  488. * but since it's only done at mount time, I'm not worried about the
  489. * time it takes.
  490. */
  491. static int map_journal_extents(struct gfs2_sbd *sdp)
  492. {
  493. struct gfs2_jdesc *jd = sdp->sd_jdesc;
  494. unsigned int lb;
  495. u64 db, prev_db; /* logical block, disk block, prev disk block */
  496. struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
  497. struct gfs2_journal_extent *jext = NULL;
  498. struct buffer_head bh;
  499. int rc = 0;
  500. prev_db = 0;
  501. for (lb = 0; lb < ip->i_disksize >> sdp->sd_sb.sb_bsize_shift; lb++) {
  502. bh.b_state = 0;
  503. bh.b_blocknr = 0;
  504. bh.b_size = 1 << ip->i_inode.i_blkbits;
  505. rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0);
  506. db = bh.b_blocknr;
  507. if (rc || !db) {
  508. printk(KERN_INFO "GFS2 journal mapping error %d: lb="
  509. "%u db=%llu\n", rc, lb, (unsigned long long)db);
  510. break;
  511. }
  512. if (!prev_db || db != prev_db + 1) {
  513. jext = kzalloc(sizeof(struct gfs2_journal_extent),
  514. GFP_KERNEL);
  515. if (!jext) {
  516. printk(KERN_INFO "GFS2 error: out of memory "
  517. "mapping journal extents.\n");
  518. rc = -ENOMEM;
  519. break;
  520. }
  521. jext->dblock = db;
  522. jext->lblock = lb;
  523. jext->blocks = 1;
  524. list_add_tail(&jext->extent_list, &jd->extent_list);
  525. } else {
  526. jext->blocks++;
  527. }
  528. prev_db = db;
  529. }
  530. return rc;
  531. }
  532. static void gfs2_others_may_mount(struct gfs2_sbd *sdp)
  533. {
  534. char *message = "FIRSTMOUNT=Done";
  535. char *envp[] = { message, NULL };
  536. struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  537. ls->ls_first_done = 1;
  538. kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp);
  539. }
  540. /**
  541. * gfs2_jindex_hold - Grab a lock on the jindex
  542. * @sdp: The GFS2 superblock
  543. * @ji_gh: the holder for the jindex glock
  544. *
  545. * Returns: errno
  546. */
  547. static int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
  548. {
  549. struct gfs2_inode *dip = GFS2_I(sdp->sd_jindex);
  550. struct qstr name;
  551. char buf[20];
  552. struct gfs2_jdesc *jd;
  553. int error;
  554. name.name = buf;
  555. mutex_lock(&sdp->sd_jindex_mutex);
  556. for (;;) {
  557. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, ji_gh);
  558. if (error)
  559. break;
  560. name.len = sprintf(buf, "journal%u", sdp->sd_journals);
  561. name.hash = gfs2_disk_hash(name.name, name.len);
  562. error = gfs2_dir_check(sdp->sd_jindex, &name, NULL);
  563. if (error == -ENOENT) {
  564. error = 0;
  565. break;
  566. }
  567. gfs2_glock_dq_uninit(ji_gh);
  568. if (error)
  569. break;
  570. error = -ENOMEM;
  571. jd = kzalloc(sizeof(struct gfs2_jdesc), GFP_KERNEL);
  572. if (!jd)
  573. break;
  574. INIT_LIST_HEAD(&jd->extent_list);
  575. jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1);
  576. if (!jd->jd_inode || IS_ERR(jd->jd_inode)) {
  577. if (!jd->jd_inode)
  578. error = -ENOENT;
  579. else
  580. error = PTR_ERR(jd->jd_inode);
  581. kfree(jd);
  582. break;
  583. }
  584. spin_lock(&sdp->sd_jindex_spin);
  585. jd->jd_jid = sdp->sd_journals++;
  586. list_add_tail(&jd->jd_list, &sdp->sd_jindex_list);
  587. spin_unlock(&sdp->sd_jindex_spin);
  588. }
  589. mutex_unlock(&sdp->sd_jindex_mutex);
  590. return error;
  591. }
  592. static int init_journal(struct gfs2_sbd *sdp, int undo)
  593. {
  594. struct inode *master = sdp->sd_master_dir->d_inode;
  595. struct gfs2_holder ji_gh;
  596. struct task_struct *p;
  597. struct gfs2_inode *ip;
  598. int jindex = 1;
  599. int error = 0;
  600. if (undo) {
  601. jindex = 0;
  602. goto fail_recoverd;
  603. }
  604. sdp->sd_jindex = gfs2_lookup_simple(master, "jindex");
  605. if (IS_ERR(sdp->sd_jindex)) {
  606. fs_err(sdp, "can't lookup journal index: %d\n", error);
  607. return PTR_ERR(sdp->sd_jindex);
  608. }
  609. ip = GFS2_I(sdp->sd_jindex);
  610. /* Load in the journal index special file */
  611. error = gfs2_jindex_hold(sdp, &ji_gh);
  612. if (error) {
  613. fs_err(sdp, "can't read journal index: %d\n", error);
  614. goto fail;
  615. }
  616. error = -EINVAL;
  617. if (!gfs2_jindex_size(sdp)) {
  618. fs_err(sdp, "no journals!\n");
  619. goto fail_jindex;
  620. }
  621. if (sdp->sd_args.ar_spectator) {
  622. sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
  623. atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
  624. } else {
  625. if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
  626. fs_err(sdp, "can't mount journal #%u\n",
  627. sdp->sd_lockstruct.ls_jid);
  628. fs_err(sdp, "there are only %u journals (0 - %u)\n",
  629. gfs2_jindex_size(sdp),
  630. gfs2_jindex_size(sdp) - 1);
  631. goto fail_jindex;
  632. }
  633. sdp->sd_jdesc = gfs2_jdesc_find(sdp, sdp->sd_lockstruct.ls_jid);
  634. error = gfs2_glock_nq_num(sdp, sdp->sd_lockstruct.ls_jid,
  635. &gfs2_journal_glops,
  636. LM_ST_EXCLUSIVE, LM_FLAG_NOEXP,
  637. &sdp->sd_journal_gh);
  638. if (error) {
  639. fs_err(sdp, "can't acquire journal glock: %d\n", error);
  640. goto fail_jindex;
  641. }
  642. ip = GFS2_I(sdp->sd_jdesc->jd_inode);
  643. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
  644. LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE,
  645. &sdp->sd_jinode_gh);
  646. if (error) {
  647. fs_err(sdp, "can't acquire journal inode glock: %d\n",
  648. error);
  649. goto fail_journal_gh;
  650. }
  651. error = gfs2_jdesc_check(sdp->sd_jdesc);
  652. if (error) {
  653. fs_err(sdp, "my journal (%u) is bad: %d\n",
  654. sdp->sd_jdesc->jd_jid, error);
  655. goto fail_jinode_gh;
  656. }
  657. atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
  658. /* Map the extents for this journal's blocks */
  659. map_journal_extents(sdp);
  660. }
  661. if (sdp->sd_lockstruct.ls_first) {
  662. unsigned int x;
  663. for (x = 0; x < sdp->sd_journals; x++) {
  664. error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x));
  665. if (error) {
  666. fs_err(sdp, "error recovering journal %u: %d\n",
  667. x, error);
  668. goto fail_jinode_gh;
  669. }
  670. }
  671. gfs2_others_may_mount(sdp);
  672. } else if (!sdp->sd_args.ar_spectator) {
  673. error = gfs2_recover_journal(sdp->sd_jdesc);
  674. if (error) {
  675. fs_err(sdp, "error recovering my journal: %d\n", error);
  676. goto fail_jinode_gh;
  677. }
  678. }
  679. set_bit(SDF_JOURNAL_CHECKED, &sdp->sd_flags);
  680. gfs2_glock_dq_uninit(&ji_gh);
  681. jindex = 0;
  682. p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd");
  683. error = IS_ERR(p);
  684. if (error) {
  685. fs_err(sdp, "can't start recoverd thread: %d\n", error);
  686. goto fail_jinode_gh;
  687. }
  688. sdp->sd_recoverd_process = p;
  689. return 0;
  690. fail_recoverd:
  691. kthread_stop(sdp->sd_recoverd_process);
  692. fail_jinode_gh:
  693. if (!sdp->sd_args.ar_spectator)
  694. gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
  695. fail_journal_gh:
  696. if (!sdp->sd_args.ar_spectator)
  697. gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
  698. fail_jindex:
  699. gfs2_jindex_free(sdp);
  700. if (jindex)
  701. gfs2_glock_dq_uninit(&ji_gh);
  702. fail:
  703. iput(sdp->sd_jindex);
  704. return error;
  705. }
  706. static int init_inodes(struct gfs2_sbd *sdp, int undo)
  707. {
  708. int error = 0;
  709. struct gfs2_inode *ip;
  710. struct inode *master = sdp->sd_master_dir->d_inode;
  711. if (undo)
  712. goto fail_qinode;
  713. error = init_journal(sdp, undo);
  714. if (error)
  715. goto fail;
  716. /* Read in the master inode number inode */
  717. sdp->sd_inum_inode = gfs2_lookup_simple(master, "inum");
  718. if (IS_ERR(sdp->sd_inum_inode)) {
  719. error = PTR_ERR(sdp->sd_inum_inode);
  720. fs_err(sdp, "can't read in inum inode: %d\n", error);
  721. goto fail_journal;
  722. }
  723. /* Read in the master statfs inode */
  724. sdp->sd_statfs_inode = gfs2_lookup_simple(master, "statfs");
  725. if (IS_ERR(sdp->sd_statfs_inode)) {
  726. error = PTR_ERR(sdp->sd_statfs_inode);
  727. fs_err(sdp, "can't read in statfs inode: %d\n", error);
  728. goto fail_inum;
  729. }
  730. /* Read in the resource index inode */
  731. sdp->sd_rindex = gfs2_lookup_simple(master, "rindex");
  732. if (IS_ERR(sdp->sd_rindex)) {
  733. error = PTR_ERR(sdp->sd_rindex);
  734. fs_err(sdp, "can't get resource index inode: %d\n", error);
  735. goto fail_statfs;
  736. }
  737. ip = GFS2_I(sdp->sd_rindex);
  738. sdp->sd_rindex_uptodate = 0;
  739. /* Read in the quota inode */
  740. sdp->sd_quota_inode = gfs2_lookup_simple(master, "quota");
  741. if (IS_ERR(sdp->sd_quota_inode)) {
  742. error = PTR_ERR(sdp->sd_quota_inode);
  743. fs_err(sdp, "can't get quota file inode: %d\n", error);
  744. goto fail_rindex;
  745. }
  746. return 0;
  747. fail_qinode:
  748. iput(sdp->sd_quota_inode);
  749. fail_rindex:
  750. gfs2_clear_rgrpd(sdp);
  751. iput(sdp->sd_rindex);
  752. fail_statfs:
  753. iput(sdp->sd_statfs_inode);
  754. fail_inum:
  755. iput(sdp->sd_inum_inode);
  756. fail_journal:
  757. init_journal(sdp, UNDO);
  758. fail:
  759. return error;
  760. }
  761. static int init_per_node(struct gfs2_sbd *sdp, int undo)
  762. {
  763. struct inode *pn = NULL;
  764. char buf[30];
  765. int error = 0;
  766. struct gfs2_inode *ip;
  767. struct inode *master = sdp->sd_master_dir->d_inode;
  768. if (sdp->sd_args.ar_spectator)
  769. return 0;
  770. if (undo)
  771. goto fail_qc_gh;
  772. pn = gfs2_lookup_simple(master, "per_node");
  773. if (IS_ERR(pn)) {
  774. error = PTR_ERR(pn);
  775. fs_err(sdp, "can't find per_node directory: %d\n", error);
  776. return error;
  777. }
  778. sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid);
  779. sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf);
  780. if (IS_ERR(sdp->sd_ir_inode)) {
  781. error = PTR_ERR(sdp->sd_ir_inode);
  782. fs_err(sdp, "can't find local \"ir\" file: %d\n", error);
  783. goto fail;
  784. }
  785. sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid);
  786. sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf);
  787. if (IS_ERR(sdp->sd_sc_inode)) {
  788. error = PTR_ERR(sdp->sd_sc_inode);
  789. fs_err(sdp, "can't find local \"sc\" file: %d\n", error);
  790. goto fail_ir_i;
  791. }
  792. sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
  793. sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
  794. if (IS_ERR(sdp->sd_qc_inode)) {
  795. error = PTR_ERR(sdp->sd_qc_inode);
  796. fs_err(sdp, "can't find local \"qc\" file: %d\n", error);
  797. goto fail_ut_i;
  798. }
  799. iput(pn);
  800. pn = NULL;
  801. ip = GFS2_I(sdp->sd_ir_inode);
  802. error = gfs2_glock_nq_init(ip->i_gl,
  803. LM_ST_EXCLUSIVE, 0,
  804. &sdp->sd_ir_gh);
  805. if (error) {
  806. fs_err(sdp, "can't lock local \"ir\" file: %d\n", error);
  807. goto fail_qc_i;
  808. }
  809. ip = GFS2_I(sdp->sd_sc_inode);
  810. error = gfs2_glock_nq_init(ip->i_gl,
  811. LM_ST_EXCLUSIVE, 0,
  812. &sdp->sd_sc_gh);
  813. if (error) {
  814. fs_err(sdp, "can't lock local \"sc\" file: %d\n", error);
  815. goto fail_ir_gh;
  816. }
  817. ip = GFS2_I(sdp->sd_qc_inode);
  818. error = gfs2_glock_nq_init(ip->i_gl,
  819. LM_ST_EXCLUSIVE, 0,
  820. &sdp->sd_qc_gh);
  821. if (error) {
  822. fs_err(sdp, "can't lock local \"qc\" file: %d\n", error);
  823. goto fail_ut_gh;
  824. }
  825. return 0;
  826. fail_qc_gh:
  827. gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
  828. fail_ut_gh:
  829. gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
  830. fail_ir_gh:
  831. gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
  832. fail_qc_i:
  833. iput(sdp->sd_qc_inode);
  834. fail_ut_i:
  835. iput(sdp->sd_sc_inode);
  836. fail_ir_i:
  837. iput(sdp->sd_ir_inode);
  838. fail:
  839. if (pn)
  840. iput(pn);
  841. return error;
  842. }
  843. static int init_threads(struct gfs2_sbd *sdp, int undo)
  844. {
  845. struct task_struct *p;
  846. int error = 0;
  847. if (undo)
  848. goto fail_quotad;
  849. sdp->sd_log_flush_time = jiffies;
  850. p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
  851. error = IS_ERR(p);
  852. if (error) {
  853. fs_err(sdp, "can't start logd thread: %d\n", error);
  854. return error;
  855. }
  856. sdp->sd_logd_process = p;
  857. p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
  858. error = IS_ERR(p);
  859. if (error) {
  860. fs_err(sdp, "can't start quotad thread: %d\n", error);
  861. goto fail;
  862. }
  863. sdp->sd_quotad_process = p;
  864. return 0;
  865. fail_quotad:
  866. kthread_stop(sdp->sd_quotad_process);
  867. fail:
  868. kthread_stop(sdp->sd_logd_process);
  869. return error;
  870. }
  871. static const match_table_t nolock_tokens = {
  872. { Opt_jid, "jid=%d\n", },
  873. { Opt_err, NULL },
  874. };
  875. static const struct lm_lockops nolock_ops = {
  876. .lm_proto_name = "lock_nolock",
  877. .lm_put_lock = kmem_cache_free,
  878. .lm_tokens = &nolock_tokens,
  879. };
  880. /**
  881. * gfs2_lm_mount - mount a locking protocol
  882. * @sdp: the filesystem
  883. * @args: mount arguements
  884. * @silent: if 1, don't complain if the FS isn't a GFS2 fs
  885. *
  886. * Returns: errno
  887. */
  888. static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
  889. {
  890. const struct lm_lockops *lm;
  891. struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  892. struct gfs2_args *args = &sdp->sd_args;
  893. const char *proto = sdp->sd_proto_name;
  894. const char *table = sdp->sd_table_name;
  895. const char *fsname;
  896. char *o, *options;
  897. int ret;
  898. if (!strcmp("lock_nolock", proto)) {
  899. lm = &nolock_ops;
  900. sdp->sd_args.ar_localflocks = 1;
  901. sdp->sd_args.ar_localcaching = 1;
  902. #ifdef CONFIG_GFS2_FS_LOCKING_DLM
  903. } else if (!strcmp("lock_dlm", proto)) {
  904. lm = &gfs2_dlm_ops;
  905. #endif
  906. } else {
  907. printk(KERN_INFO "GFS2: can't find protocol %s\n", proto);
  908. return -ENOENT;
  909. }
  910. fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table);
  911. ls->ls_ops = lm;
  912. ls->ls_first = 1;
  913. ls->ls_id = 0;
  914. for (options = args->ar_hostdata; (o = strsep(&options, ":")); ) {
  915. substring_t tmp[MAX_OPT_ARGS];
  916. int token, option;
  917. if (!o || !*o)
  918. continue;
  919. token = match_token(o, *lm->lm_tokens, tmp);
  920. switch (token) {
  921. case Opt_jid:
  922. ret = match_int(&tmp[0], &option);
  923. if (ret || option < 0)
  924. goto hostdata_error;
  925. ls->ls_jid = option;
  926. break;
  927. case Opt_id:
  928. ret = match_int(&tmp[0], &option);
  929. if (ret)
  930. goto hostdata_error;
  931. ls->ls_id = option;
  932. break;
  933. case Opt_first:
  934. ret = match_int(&tmp[0], &option);
  935. if (ret || (option != 0 && option != 1))
  936. goto hostdata_error;
  937. ls->ls_first = option;
  938. break;
  939. case Opt_nodir:
  940. ret = match_int(&tmp[0], &option);
  941. if (ret || (option != 0 && option != 1))
  942. goto hostdata_error;
  943. ls->ls_nodir = option;
  944. break;
  945. case Opt_err:
  946. default:
  947. hostdata_error:
  948. fs_info(sdp, "unknown hostdata (%s)\n", o);
  949. return -EINVAL;
  950. }
  951. }
  952. if (sdp->sd_args.ar_spectator)
  953. snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.s", table);
  954. else
  955. snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table,
  956. sdp->sd_lockstruct.ls_jid);
  957. fsname = strchr(table, ':');
  958. if (fsname)
  959. fsname++;
  960. if (lm->lm_mount == NULL) {
  961. fs_info(sdp, "Now mounting FS...\n");
  962. return 0;
  963. }
  964. ret = lm->lm_mount(sdp, fsname);
  965. if (ret == 0)
  966. fs_info(sdp, "Joined cluster. Now mounting FS...\n");
  967. return ret;
  968. }
  969. void gfs2_lm_unmount(struct gfs2_sbd *sdp)
  970. {
  971. const struct lm_lockops *lm = sdp->sd_lockstruct.ls_ops;
  972. if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) &&
  973. lm->lm_unmount)
  974. lm->lm_unmount(sdp);
  975. }
  976. /**
  977. * fill_super - Read in superblock
  978. * @sb: The VFS superblock
  979. * @data: Mount options
  980. * @silent: Don't complain if it's not a GFS2 filesystem
  981. *
  982. * Returns: errno
  983. */
  984. static int fill_super(struct super_block *sb, void *data, int silent)
  985. {
  986. struct gfs2_sbd *sdp;
  987. struct gfs2_holder mount_gh;
  988. int error;
  989. sdp = init_sbd(sb);
  990. if (!sdp) {
  991. printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n");
  992. return -ENOMEM;
  993. }
  994. sdp->sd_args.ar_quota = GFS2_QUOTA_DEFAULT;
  995. sdp->sd_args.ar_data = GFS2_DATA_DEFAULT;
  996. error = gfs2_mount_args(sdp, &sdp->sd_args, data);
  997. if (error) {
  998. printk(KERN_WARNING "GFS2: can't parse mount arguments\n");
  999. goto fail;
  1000. }
  1001. if (sdp->sd_args.ar_spectator)
  1002. sb->s_flags |= MS_RDONLY;
  1003. if (sdp->sd_args.ar_posix_acl)
  1004. sb->s_flags |= MS_POSIXACL;
  1005. sb->s_magic = GFS2_MAGIC;
  1006. sb->s_op = &gfs2_super_ops;
  1007. sb->s_export_op = &gfs2_export_ops;
  1008. sb->s_time_gran = 1;
  1009. sb->s_maxbytes = MAX_LFS_FILESIZE;
  1010. /* Set up the buffer cache and fill in some fake block size values
  1011. to allow us to read-in the on-disk superblock. */
  1012. sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK);
  1013. sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
  1014. sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
  1015. GFS2_BASIC_BLOCK_SHIFT;
  1016. sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
  1017. error = init_names(sdp, silent);
  1018. if (error)
  1019. goto fail;
  1020. gfs2_create_debugfs_file(sdp);
  1021. error = gfs2_sys_fs_add(sdp);
  1022. if (error)
  1023. goto fail;
  1024. error = gfs2_lm_mount(sdp, silent);
  1025. if (error)
  1026. goto fail_sys;
  1027. error = init_locking(sdp, &mount_gh, DO);
  1028. if (error)
  1029. goto fail_lm;
  1030. error = init_sb(sdp, silent);
  1031. if (error)
  1032. goto fail_locking;
  1033. error = init_inodes(sdp, DO);
  1034. if (error)
  1035. goto fail_sb;
  1036. error = init_per_node(sdp, DO);
  1037. if (error)
  1038. goto fail_inodes;
  1039. error = gfs2_statfs_init(sdp);
  1040. if (error) {
  1041. fs_err(sdp, "can't initialize statfs subsystem: %d\n", error);
  1042. goto fail_per_node;
  1043. }
  1044. error = init_threads(sdp, DO);
  1045. if (error)
  1046. goto fail_per_node;
  1047. if (!(sb->s_flags & MS_RDONLY)) {
  1048. error = gfs2_make_fs_rw(sdp);
  1049. if (error) {
  1050. fs_err(sdp, "can't make FS RW: %d\n", error);
  1051. goto fail_threads;
  1052. }
  1053. }
  1054. gfs2_glock_dq_uninit(&mount_gh);
  1055. return 0;
  1056. fail_threads:
  1057. init_threads(sdp, UNDO);
  1058. fail_per_node:
  1059. init_per_node(sdp, UNDO);
  1060. fail_inodes:
  1061. init_inodes(sdp, UNDO);
  1062. fail_sb:
  1063. if (sdp->sd_root_dir)
  1064. dput(sdp->sd_root_dir);
  1065. if (sdp->sd_master_dir)
  1066. dput(sdp->sd_master_dir);
  1067. if (sb->s_root)
  1068. dput(sb->s_root);
  1069. sb->s_root = NULL;
  1070. fail_locking:
  1071. init_locking(sdp, &mount_gh, UNDO);
  1072. fail_lm:
  1073. gfs2_gl_hash_clear(sdp);
  1074. gfs2_lm_unmount(sdp);
  1075. while (invalidate_inodes(sb))
  1076. yield();
  1077. fail_sys:
  1078. gfs2_sys_fs_del(sdp);
  1079. fail:
  1080. gfs2_delete_debugfs_file(sdp);
  1081. kfree(sdp);
  1082. sb->s_fs_info = NULL;
  1083. return error;
  1084. }
  1085. static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
  1086. const char *dev_name, void *data, struct vfsmount *mnt)
  1087. {
  1088. return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
  1089. }
  1090. static struct super_block *get_gfs2_sb(const char *dev_name)
  1091. {
  1092. struct super_block *sb;
  1093. struct nameidata nd;
  1094. int error;
  1095. error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
  1096. if (error) {
  1097. printk(KERN_WARNING "GFS2: path_lookup on %s returned error %d\n",
  1098. dev_name, error);
  1099. return NULL;
  1100. }
  1101. sb = nd.path.dentry->d_inode->i_sb;
  1102. if (sb && (sb->s_type == &gfs2_fs_type))
  1103. atomic_inc(&sb->s_active);
  1104. else
  1105. sb = NULL;
  1106. path_put(&nd.path);
  1107. return sb;
  1108. }
  1109. static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
  1110. const char *dev_name, void *data, struct vfsmount *mnt)
  1111. {
  1112. struct super_block *sb = NULL;
  1113. struct gfs2_sbd *sdp;
  1114. sb = get_gfs2_sb(dev_name);
  1115. if (!sb) {
  1116. printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n");
  1117. return -ENOENT;
  1118. }
  1119. sdp = sb->s_fs_info;
  1120. mnt->mnt_sb = sb;
  1121. mnt->mnt_root = dget(sdp->sd_master_dir);
  1122. return 0;
  1123. }
  1124. static void gfs2_kill_sb(struct super_block *sb)
  1125. {
  1126. struct gfs2_sbd *sdp = sb->s_fs_info;
  1127. if (sdp == NULL) {
  1128. kill_block_super(sb);
  1129. return;
  1130. }
  1131. gfs2_meta_syncfs(sdp);
  1132. dput(sdp->sd_root_dir);
  1133. dput(sdp->sd_master_dir);
  1134. sdp->sd_root_dir = NULL;
  1135. sdp->sd_master_dir = NULL;
  1136. shrink_dcache_sb(sb);
  1137. kill_block_super(sb);
  1138. gfs2_delete_debugfs_file(sdp);
  1139. kfree(sdp);
  1140. }
  1141. struct file_system_type gfs2_fs_type = {
  1142. .name = "gfs2",
  1143. .fs_flags = FS_REQUIRES_DEV,
  1144. .get_sb = gfs2_get_sb,
  1145. .kill_sb = gfs2_kill_sb,
  1146. .owner = THIS_MODULE,
  1147. };
  1148. struct file_system_type gfs2meta_fs_type = {
  1149. .name = "gfs2meta",
  1150. .fs_flags = FS_REQUIRES_DEV,
  1151. .get_sb = gfs2_get_sb_meta,
  1152. .owner = THIS_MODULE,
  1153. };