log.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2005 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 v.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 <asm/semaphore.h>
  15. #include "gfs2.h"
  16. #include "bmap.h"
  17. #include "glock.h"
  18. #include "log.h"
  19. #include "lops.h"
  20. #include "meta_io.h"
  21. #define PULL 1
  22. static inline int is_done(struct gfs2_sbd *sdp, atomic_t *a)
  23. {
  24. int done;
  25. gfs2_log_lock(sdp);
  26. done = atomic_read(a) ? 0 : 1;
  27. gfs2_log_unlock(sdp);
  28. return done;
  29. }
  30. static void do_lock_wait(struct gfs2_sbd *sdp, wait_queue_head_t *wq,
  31. atomic_t *a)
  32. {
  33. gfs2_log_unlock(sdp);
  34. wait_event(*wq, is_done(sdp, a));
  35. gfs2_log_lock(sdp);
  36. }
  37. static void lock_for_trans(struct gfs2_sbd *sdp)
  38. {
  39. gfs2_log_lock(sdp);
  40. do_lock_wait(sdp, &sdp->sd_log_trans_wq, &sdp->sd_log_flush_count);
  41. atomic_inc(&sdp->sd_log_trans_count);
  42. gfs2_log_unlock(sdp);
  43. }
  44. static void unlock_from_trans(struct gfs2_sbd *sdp)
  45. {
  46. gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_trans_count));
  47. if (atomic_dec_and_test(&sdp->sd_log_trans_count))
  48. wake_up(&sdp->sd_log_flush_wq);
  49. }
  50. void gfs2_lock_for_flush(struct gfs2_sbd *sdp)
  51. {
  52. gfs2_log_lock(sdp);
  53. atomic_inc(&sdp->sd_log_flush_count);
  54. do_lock_wait(sdp, &sdp->sd_log_flush_wq, &sdp->sd_log_trans_count);
  55. gfs2_log_unlock(sdp);
  56. }
  57. void gfs2_unlock_from_flush(struct gfs2_sbd *sdp)
  58. {
  59. gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_flush_count));
  60. if (atomic_dec_and_test(&sdp->sd_log_flush_count))
  61. wake_up(&sdp->sd_log_trans_wq);
  62. }
  63. /**
  64. * gfs2_struct2blk - compute stuff
  65. * @sdp: the filesystem
  66. * @nstruct: the number of structures
  67. * @ssize: the size of the structures
  68. *
  69. * Compute the number of log descriptor blocks needed to hold a certain number
  70. * of structures of a certain size.
  71. *
  72. * Returns: the number of blocks needed (minimum is always 1)
  73. */
  74. unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
  75. unsigned int ssize)
  76. {
  77. unsigned int blks;
  78. unsigned int first, second;
  79. blks = 1;
  80. first = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / ssize;
  81. if (nstruct > first) {
  82. second = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header)) / ssize;
  83. blks += DIV_RU(nstruct - first, second);
  84. }
  85. return blks;
  86. }
  87. void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags)
  88. {
  89. struct list_head *head = &sdp->sd_ail1_list;
  90. uint64_t sync_gen;
  91. struct list_head *first, *tmp;
  92. struct gfs2_ail *first_ai, *ai;
  93. gfs2_log_lock(sdp);
  94. if (list_empty(head)) {
  95. gfs2_log_unlock(sdp);
  96. return;
  97. }
  98. sync_gen = sdp->sd_ail_sync_gen++;
  99. first = head->prev;
  100. first_ai = list_entry(first, struct gfs2_ail, ai_list);
  101. first_ai->ai_sync_gen = sync_gen;
  102. gfs2_ail1_start_one(sdp, first_ai);
  103. if (flags & DIO_ALL)
  104. first = NULL;
  105. for (;;) {
  106. if (first &&
  107. (head->prev != first ||
  108. gfs2_ail1_empty_one(sdp, first_ai, 0)))
  109. break;
  110. for (tmp = head->prev; tmp != head; tmp = tmp->prev) {
  111. ai = list_entry(tmp, struct gfs2_ail, ai_list);
  112. if (ai->ai_sync_gen >= sync_gen)
  113. continue;
  114. ai->ai_sync_gen = sync_gen;
  115. gfs2_ail1_start_one(sdp, ai);
  116. break;
  117. }
  118. if (tmp == head)
  119. break;
  120. }
  121. gfs2_log_unlock(sdp);
  122. }
  123. int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
  124. {
  125. struct gfs2_ail *ai, *s;
  126. int ret;
  127. gfs2_log_lock(sdp);
  128. list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) {
  129. if (gfs2_ail1_empty_one(sdp, ai, flags))
  130. list_move(&ai->ai_list, &sdp->sd_ail2_list);
  131. else if (!(flags & DIO_ALL))
  132. break;
  133. }
  134. ret = list_empty(&sdp->sd_ail1_list);
  135. gfs2_log_unlock(sdp);
  136. return ret;
  137. }
  138. static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
  139. {
  140. struct gfs2_ail *ai, *safe;
  141. unsigned int old_tail = sdp->sd_log_tail;
  142. int wrap = (new_tail < old_tail);
  143. int a, b, rm;
  144. gfs2_log_lock(sdp);
  145. list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) {
  146. a = (old_tail <= ai->ai_first);
  147. b = (ai->ai_first < new_tail);
  148. rm = (wrap) ? (a || b) : (a && b);
  149. if (!rm)
  150. continue;
  151. gfs2_ail2_empty_one(sdp, ai);
  152. list_del(&ai->ai_list);
  153. gfs2_assert_warn(sdp, list_empty(&ai->ai_ail1_list));
  154. gfs2_assert_warn(sdp, list_empty(&ai->ai_ail2_list));
  155. kfree(ai);
  156. }
  157. gfs2_log_unlock(sdp);
  158. }
  159. /**
  160. * gfs2_log_reserve - Make a log reservation
  161. * @sdp: The GFS2 superblock
  162. * @blks: The number of blocks to reserve
  163. *
  164. * Returns: errno
  165. */
  166. int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
  167. {
  168. LIST_HEAD(list);
  169. unsigned int try = 0;
  170. if (gfs2_assert_warn(sdp, blks) ||
  171. gfs2_assert_warn(sdp, blks <= sdp->sd_jdesc->jd_blocks))
  172. return -EINVAL;
  173. for (;;) {
  174. gfs2_log_lock(sdp);
  175. if (list_empty(&list)) {
  176. list_add_tail(&list, &sdp->sd_log_blks_list);
  177. while (sdp->sd_log_blks_list.next != &list) {
  178. DECLARE_WAITQUEUE(__wait_chan, current);
  179. set_current_state(TASK_UNINTERRUPTIBLE);
  180. add_wait_queue(&sdp->sd_log_blks_wait,
  181. &__wait_chan);
  182. gfs2_log_unlock(sdp);
  183. schedule();
  184. gfs2_log_lock(sdp);
  185. remove_wait_queue(&sdp->sd_log_blks_wait,
  186. &__wait_chan);
  187. set_current_state(TASK_RUNNING);
  188. }
  189. }
  190. /* Never give away the last block so we can
  191. always pull the tail if we need to. */
  192. if (sdp->sd_log_blks_free > blks) {
  193. sdp->sd_log_blks_free -= blks;
  194. list_del(&list);
  195. gfs2_log_unlock(sdp);
  196. wake_up(&sdp->sd_log_blks_wait);
  197. break;
  198. }
  199. gfs2_log_unlock(sdp);
  200. gfs2_ail1_empty(sdp, 0);
  201. gfs2_log_flush(sdp);
  202. if (try++)
  203. gfs2_ail1_start(sdp, 0);
  204. }
  205. lock_for_trans(sdp);
  206. return 0;
  207. }
  208. /**
  209. * gfs2_log_release - Release a given number of log blocks
  210. * @sdp: The GFS2 superblock
  211. * @blks: The number of blocks
  212. *
  213. */
  214. void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
  215. {
  216. unlock_from_trans(sdp);
  217. gfs2_log_lock(sdp);
  218. sdp->sd_log_blks_free += blks;
  219. gfs2_assert_withdraw(sdp,
  220. sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks);
  221. gfs2_log_unlock(sdp);
  222. }
  223. static uint64_t log_bmap(struct gfs2_sbd *sdp, unsigned int lbn)
  224. {
  225. int new = 0;
  226. uint64_t dbn;
  227. int error;
  228. error = gfs2_block_map(get_v2ip(sdp->sd_jdesc->jd_inode), lbn, &new, &dbn, NULL);
  229. gfs2_assert_withdraw(sdp, !error && dbn);
  230. return dbn;
  231. }
  232. /**
  233. * log_distance - Compute distance between two journal blocks
  234. * @sdp: The GFS2 superblock
  235. * @newer: The most recent journal block of the pair
  236. * @older: The older journal block of the pair
  237. *
  238. * Compute the distance (in the journal direction) between two
  239. * blocks in the journal
  240. *
  241. * Returns: the distance in blocks
  242. */
  243. static inline unsigned int log_distance(struct gfs2_sbd *sdp,
  244. unsigned int newer,
  245. unsigned int older)
  246. {
  247. int dist;
  248. dist = newer - older;
  249. if (dist < 0)
  250. dist += sdp->sd_jdesc->jd_blocks;
  251. return dist;
  252. }
  253. static unsigned int current_tail(struct gfs2_sbd *sdp)
  254. {
  255. struct gfs2_ail *ai;
  256. unsigned int tail;
  257. gfs2_log_lock(sdp);
  258. if (list_empty(&sdp->sd_ail1_list))
  259. tail = sdp->sd_log_head;
  260. else {
  261. ai = list_entry(sdp->sd_ail1_list.prev,
  262. struct gfs2_ail, ai_list);
  263. tail = ai->ai_first;
  264. }
  265. gfs2_log_unlock(sdp);
  266. return tail;
  267. }
  268. static inline void log_incr_head(struct gfs2_sbd *sdp)
  269. {
  270. if (sdp->sd_log_flush_head == sdp->sd_log_tail)
  271. gfs2_assert_withdraw(sdp,
  272. sdp->sd_log_flush_head == sdp->sd_log_head);
  273. if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) {
  274. sdp->sd_log_flush_head = 0;
  275. sdp->sd_log_flush_wrapped = 1;
  276. }
  277. }
  278. /**
  279. * gfs2_log_get_buf - Get and initialize a buffer to use for log control data
  280. * @sdp: The GFS2 superblock
  281. *
  282. * Returns: the buffer_head
  283. */
  284. struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp)
  285. {
  286. uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head);
  287. struct gfs2_log_buf *lb;
  288. struct buffer_head *bh;
  289. lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_NOFS | __GFP_NOFAIL);
  290. list_add(&lb->lb_list, &sdp->sd_log_flush_list);
  291. bh = lb->lb_bh = sb_getblk(sdp->sd_vfs, blkno);
  292. lock_buffer(bh);
  293. memset(bh->b_data, 0, bh->b_size);
  294. set_buffer_uptodate(bh);
  295. clear_buffer_dirty(bh);
  296. unlock_buffer(bh);
  297. log_incr_head(sdp);
  298. return bh;
  299. }
  300. /**
  301. * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log
  302. * @sdp: the filesystem
  303. * @data: the data the buffer_head should point to
  304. *
  305. * Returns: the log buffer descriptor
  306. */
  307. struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp,
  308. struct buffer_head *real)
  309. {
  310. uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head);
  311. struct gfs2_log_buf *lb;
  312. struct buffer_head *bh;
  313. lb = kzalloc(sizeof(struct gfs2_log_buf), GFP_NOFS | __GFP_NOFAIL);
  314. list_add(&lb->lb_list, &sdp->sd_log_flush_list);
  315. lb->lb_real = real;
  316. bh = lb->lb_bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL);
  317. atomic_set(&bh->b_count, 1);
  318. bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate);
  319. set_bh_page(bh, real->b_page, bh_offset(real));
  320. bh->b_blocknr = blkno;
  321. bh->b_size = sdp->sd_sb.sb_bsize;
  322. bh->b_bdev = sdp->sd_vfs->s_bdev;
  323. log_incr_head(sdp);
  324. return bh;
  325. }
  326. static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail, int pull)
  327. {
  328. unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail);
  329. ail2_empty(sdp, new_tail);
  330. gfs2_log_lock(sdp);
  331. sdp->sd_log_blks_free += dist - ((pull) ? 1 : 0);
  332. gfs2_assert_withdraw(sdp,
  333. sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks);
  334. gfs2_log_unlock(sdp);
  335. sdp->sd_log_tail = new_tail;
  336. }
  337. /**
  338. * log_write_header - Get and initialize a journal header buffer
  339. * @sdp: The GFS2 superblock
  340. *
  341. * Returns: the initialized log buffer descriptor
  342. */
  343. static void log_write_header(struct gfs2_sbd *sdp, uint32_t flags, int pull)
  344. {
  345. uint64_t blkno = log_bmap(sdp, sdp->sd_log_flush_head);
  346. struct buffer_head *bh;
  347. struct gfs2_log_header *lh;
  348. unsigned int tail;
  349. uint32_t hash;
  350. atomic_inc(&sdp->sd_log_flush_ondisk);
  351. bh = sb_getblk(sdp->sd_vfs, blkno);
  352. lock_buffer(bh);
  353. memset(bh->b_data, 0, bh->b_size);
  354. set_buffer_uptodate(bh);
  355. clear_buffer_dirty(bh);
  356. unlock_buffer(bh);
  357. gfs2_ail1_empty(sdp, 0);
  358. tail = current_tail(sdp);
  359. lh = (struct gfs2_log_header *)bh->b_data;
  360. memset(lh, 0, sizeof(struct gfs2_log_header));
  361. lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
  362. lh->lh_header.mh_type = cpu_to_be16(GFS2_METATYPE_LH);
  363. lh->lh_header.mh_format = cpu_to_be16(GFS2_FORMAT_LH);
  364. lh->lh_sequence = be64_to_cpu(sdp->sd_log_sequence++);
  365. lh->lh_flags = be32_to_cpu(flags);
  366. lh->lh_tail = be32_to_cpu(tail);
  367. lh->lh_blkno = be32_to_cpu(sdp->sd_log_flush_head);
  368. hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header));
  369. lh->lh_hash = cpu_to_be32(hash);
  370. set_buffer_dirty(bh);
  371. if (sync_dirty_buffer(bh))
  372. gfs2_io_error_bh(sdp, bh);
  373. brelse(bh);
  374. if (sdp->sd_log_tail != tail)
  375. log_pull_tail(sdp, tail, pull);
  376. else
  377. gfs2_assert_withdraw(sdp, !pull);
  378. sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
  379. log_incr_head(sdp);
  380. }
  381. static void log_flush_commit(struct gfs2_sbd *sdp)
  382. {
  383. struct list_head *head = &sdp->sd_log_flush_list;
  384. struct gfs2_log_buf *lb;
  385. struct buffer_head *bh;
  386. unsigned int d;
  387. d = log_distance(sdp, sdp->sd_log_flush_head, sdp->sd_log_head);
  388. gfs2_assert_withdraw(sdp, d + 1 == sdp->sd_log_blks_reserved);
  389. while (!list_empty(head)) {
  390. lb = list_entry(head->next, struct gfs2_log_buf, lb_list);
  391. list_del(&lb->lb_list);
  392. bh = lb->lb_bh;
  393. wait_on_buffer(bh);
  394. if (!buffer_uptodate(bh))
  395. gfs2_io_error_bh(sdp, bh);
  396. if (lb->lb_real) {
  397. while (atomic_read(&bh->b_count) != 1) /* Grrrr... */
  398. schedule();
  399. free_buffer_head(bh);
  400. } else
  401. brelse(bh);
  402. kfree(lb);
  403. }
  404. log_write_header(sdp, 0, 0);
  405. }
  406. /**
  407. * gfs2_log_flush_i - flush incore transaction(s)
  408. * @sdp: the filesystem
  409. * @gl: The glock structure to flush. If NULL, flush the whole incore log
  410. *
  411. */
  412. void gfs2_log_flush_i(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
  413. {
  414. struct gfs2_ail *ai;
  415. atomic_inc(&sdp->sd_log_flush_incore);
  416. ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL);
  417. INIT_LIST_HEAD(&ai->ai_ail1_list);
  418. INIT_LIST_HEAD(&ai->ai_ail2_list);
  419. gfs2_lock_for_flush(sdp);
  420. down(&sdp->sd_log_flush_lock);
  421. gfs2_assert_withdraw(sdp,
  422. sdp->sd_log_num_buf == sdp->sd_log_commited_buf);
  423. gfs2_assert_withdraw(sdp,
  424. sdp->sd_log_num_revoke == sdp->sd_log_commited_revoke);
  425. if (gl && list_empty(&gl->gl_le.le_list)) {
  426. up(&sdp->sd_log_flush_lock);
  427. gfs2_unlock_from_flush(sdp);
  428. kfree(ai);
  429. return;
  430. }
  431. sdp->sd_log_flush_head = sdp->sd_log_head;
  432. sdp->sd_log_flush_wrapped = 0;
  433. ai->ai_first = sdp->sd_log_flush_head;
  434. lops_before_commit(sdp);
  435. if (!list_empty(&sdp->sd_log_flush_list))
  436. log_flush_commit(sdp);
  437. else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle)
  438. log_write_header(sdp, 0, PULL);
  439. lops_after_commit(sdp, ai);
  440. sdp->sd_log_head = sdp->sd_log_flush_head;
  441. if (sdp->sd_log_flush_wrapped)
  442. sdp->sd_log_wraps++;
  443. sdp->sd_log_blks_reserved =
  444. sdp->sd_log_commited_buf =
  445. sdp->sd_log_commited_revoke = 0;
  446. gfs2_log_lock(sdp);
  447. if (!list_empty(&ai->ai_ail1_list)) {
  448. list_add(&ai->ai_list, &sdp->sd_ail1_list);
  449. ai = NULL;
  450. }
  451. gfs2_log_unlock(sdp);
  452. up(&sdp->sd_log_flush_lock);
  453. sdp->sd_vfs->s_dirt = 0;
  454. gfs2_unlock_from_flush(sdp);
  455. kfree(ai);
  456. }
  457. static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
  458. {
  459. unsigned int reserved = 1;
  460. unsigned int old;
  461. gfs2_log_lock(sdp);
  462. sdp->sd_log_commited_buf += tr->tr_num_buf_new - tr->tr_num_buf_rm;
  463. gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_buf) >= 0);
  464. sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm;
  465. gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0);
  466. if (sdp->sd_log_commited_buf)
  467. reserved += 1 + sdp->sd_log_commited_buf + sdp->sd_log_commited_buf/503;
  468. if (sdp->sd_log_commited_revoke)
  469. reserved += gfs2_struct2blk(sdp, sdp->sd_log_commited_revoke,
  470. sizeof(uint64_t));
  471. old = sdp->sd_log_blks_free;
  472. sdp->sd_log_blks_free += tr->tr_reserved -
  473. (reserved - sdp->sd_log_blks_reserved);
  474. gfs2_assert_withdraw(sdp,
  475. sdp->sd_log_blks_free >= old);
  476. gfs2_assert_withdraw(sdp,
  477. sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks);
  478. sdp->sd_log_blks_reserved = reserved;
  479. gfs2_log_unlock(sdp);
  480. }
  481. /**
  482. * gfs2_log_commit - Commit a transaction to the log
  483. * @sdp: the filesystem
  484. * @tr: the transaction
  485. *
  486. * Returns: errno
  487. */
  488. void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
  489. {
  490. log_refund(sdp, tr);
  491. lops_incore_commit(sdp, tr);
  492. sdp->sd_vfs->s_dirt = 1;
  493. unlock_from_trans(sdp);
  494. kfree(tr);
  495. gfs2_log_lock(sdp);
  496. if (sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks)) {
  497. gfs2_log_unlock(sdp);
  498. gfs2_log_flush(sdp);
  499. } else
  500. gfs2_log_unlock(sdp);
  501. }
  502. /**
  503. * gfs2_log_shutdown - write a shutdown header into a journal
  504. * @sdp: the filesystem
  505. *
  506. */
  507. void gfs2_log_shutdown(struct gfs2_sbd *sdp)
  508. {
  509. down(&sdp->sd_log_flush_lock);
  510. gfs2_assert_withdraw(sdp, !atomic_read(&sdp->sd_log_trans_count));
  511. gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved);
  512. gfs2_assert_withdraw(sdp, !sdp->sd_log_num_gl);
  513. gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf);
  514. gfs2_assert_withdraw(sdp, !sdp->sd_log_num_jdata);
  515. gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
  516. gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg);
  517. gfs2_assert_withdraw(sdp, !sdp->sd_log_num_databuf);
  518. gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list));
  519. sdp->sd_log_flush_head = sdp->sd_log_head;
  520. sdp->sd_log_flush_wrapped = 0;
  521. log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT, 0);
  522. gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free ==
  523. sdp->sd_jdesc->jd_blocks);
  524. gfs2_assert_withdraw(sdp, sdp->sd_log_head == sdp->sd_log_tail);
  525. gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail2_list));
  526. sdp->sd_log_head = sdp->sd_log_flush_head;
  527. if (sdp->sd_log_flush_wrapped)
  528. sdp->sd_log_wraps++;
  529. sdp->sd_log_tail = sdp->sd_log_head;
  530. up(&sdp->sd_log_flush_lock);
  531. }