log.c 17 KB

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