log.c 15 KB

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