1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/time.h>
21#include <linux/fs.h>
22#include <linux/jbd2.h>
23#include <linux/errno.h>
24#include <linux/slab.h>
25#include <linux/timer.h>
26#include <linux/mm.h>
27#include <linux/highmem.h>
28
29static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh);
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46static transaction_t *
47jbd2_get_transaction(journal_t *journal, transaction_t *transaction)
48{
49 transaction->t_journal = journal;
50 transaction->t_state = T_RUNNING;
51 transaction->t_tid = journal->j_transaction_sequence++;
52 transaction->t_expires = jiffies + journal->j_commit_interval;
53 spin_lock_init(&transaction->t_handle_lock);
54 INIT_LIST_HEAD(&transaction->t_inode_list);
55 INIT_LIST_HEAD(&transaction->t_private_list);
56
57
58 journal->j_commit_timer.expires = round_jiffies(transaction->t_expires);
59 add_timer(&journal->j_commit_timer);
60
61 J_ASSERT(journal->j_running_transaction == NULL);
62 journal->j_running_transaction = transaction;
63 transaction->t_max_wait = 0;
64 transaction->t_start = jiffies;
65
66 return transaction;
67}
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84static int start_this_handle(journal_t *journal, handle_t *handle)
85{
86 transaction_t *transaction;
87 int needed;
88 int nblocks = handle->h_buffer_credits;
89 transaction_t *new_transaction = NULL;
90 int ret = 0;
91 unsigned long ts = jiffies;
92
93 if (nblocks > journal->j_max_transaction_buffers) {
94 printk(KERN_ERR "JBD: %s wants too many credits (%d > %d)\n",
95 current->comm, nblocks,
96 journal->j_max_transaction_buffers);
97 ret = -ENOSPC;
98 goto out;
99 }
100
101alloc_transaction:
102 if (!journal->j_running_transaction) {
103 new_transaction = kzalloc(sizeof(*new_transaction),
104 GFP_NOFS|__GFP_NOFAIL);
105 if (!new_transaction) {
106 ret = -ENOMEM;
107 goto out;
108 }
109 }
110
111 jbd_debug(3, "New handle %p going live.\n", handle);
112
113repeat:
114
115
116
117
118
119 spin_lock(&journal->j_state_lock);
120repeat_locked:
121 if (is_journal_aborted(journal) ||
122 (journal->j_errno != 0 && !(journal->j_flags & JBD2_ACK_ERR))) {
123 spin_unlock(&journal->j_state_lock);
124 ret = -EROFS;
125 goto out;
126 }
127
128
129 if (journal->j_barrier_count) {
130 spin_unlock(&journal->j_state_lock);
131 wait_event(journal->j_wait_transaction_locked,
132 journal->j_barrier_count == 0);
133 goto repeat;
134 }
135
136 if (!journal->j_running_transaction) {
137 if (!new_transaction) {
138 spin_unlock(&journal->j_state_lock);
139 goto alloc_transaction;
140 }
141 jbd2_get_transaction(journal, new_transaction);
142 new_transaction = NULL;
143 }
144
145 transaction = journal->j_running_transaction;
146
147
148
149
150
151 if (transaction->t_state == T_LOCKED) {
152 DEFINE_WAIT(wait);
153
154 prepare_to_wait(&journal->j_wait_transaction_locked,
155 &wait, TASK_UNINTERRUPTIBLE);
156 spin_unlock(&journal->j_state_lock);
157 schedule();
158 finish_wait(&journal->j_wait_transaction_locked, &wait);
159 goto repeat;
160 }
161
162
163
164
165
166
167 spin_lock(&transaction->t_handle_lock);
168 needed = transaction->t_outstanding_credits + nblocks;
169
170 if (needed > journal->j_max_transaction_buffers) {
171
172
173
174
175
176 DEFINE_WAIT(wait);
177
178 jbd_debug(2, "Handle %p starting new commit...\n", handle);
179 spin_unlock(&transaction->t_handle_lock);
180 prepare_to_wait(&journal->j_wait_transaction_locked, &wait,
181 TASK_UNINTERRUPTIBLE);
182 __jbd2_log_start_commit(journal, transaction->t_tid);
183 spin_unlock(&journal->j_state_lock);
184 schedule();
185 finish_wait(&journal->j_wait_transaction_locked, &wait);
186 goto repeat;
187 }
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214 if (__jbd2_log_space_left(journal) < jbd_space_needed(journal)) {
215 jbd_debug(2, "Handle %p waiting for checkpoint...\n", handle);
216 spin_unlock(&transaction->t_handle_lock);
217 __jbd2_log_wait_for_space(journal);
218 goto repeat_locked;
219 }
220
221
222
223
224 if (time_after(transaction->t_start, ts)) {
225 ts = jbd2_time_diff(ts, transaction->t_start);
226 if (ts > transaction->t_max_wait)
227 transaction->t_max_wait = ts;
228 }
229
230 handle->h_transaction = transaction;
231 transaction->t_outstanding_credits += nblocks;
232 transaction->t_updates++;
233 transaction->t_handle_count++;
234 jbd_debug(4, "Handle %p given %d credits (total %d, free %d)\n",
235 handle, nblocks, transaction->t_outstanding_credits,
236 __jbd2_log_space_left(journal));
237 spin_unlock(&transaction->t_handle_lock);
238 spin_unlock(&journal->j_state_lock);
239out:
240 if (unlikely(new_transaction))
241 kfree(new_transaction);
242 return ret;
243}
244
245static struct lock_class_key jbd2_handle_key;
246
247
248static handle_t *new_handle(int nblocks)
249{
250 handle_t *handle = jbd2_alloc_handle(GFP_NOFS);
251 if (!handle)
252 return NULL;
253 memset(handle, 0, sizeof(*handle));
254 handle->h_buffer_credits = nblocks;
255 handle->h_ref = 1;
256
257 lockdep_init_map(&handle->h_lockdep_map, "jbd2_handle",
258 &jbd2_handle_key, 0);
259
260 return handle;
261}
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277handle_t *jbd2_journal_start(journal_t *journal, int nblocks)
278{
279 handle_t *handle = journal_current_handle();
280 int err;
281
282 if (!journal)
283 return ERR_PTR(-EROFS);
284
285 if (handle) {
286 J_ASSERT(handle->h_transaction->t_journal == journal);
287 handle->h_ref++;
288 return handle;
289 }
290
291 handle = new_handle(nblocks);
292 if (!handle)
293 return ERR_PTR(-ENOMEM);
294
295 current->journal_info = handle;
296
297 err = start_this_handle(journal, handle);
298 if (err < 0) {
299 jbd2_free_handle(handle);
300 current->journal_info = NULL;
301 handle = ERR_PTR(err);
302 goto out;
303 }
304
305 lock_map_acquire(&handle->h_lockdep_map);
306out:
307 return handle;
308}
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330int jbd2_journal_extend(handle_t *handle, int nblocks)
331{
332 transaction_t *transaction = handle->h_transaction;
333 journal_t *journal = transaction->t_journal;
334 int result;
335 int wanted;
336
337 result = -EIO;
338 if (is_handle_aborted(handle))
339 goto out;
340
341 result = 1;
342
343 spin_lock(&journal->j_state_lock);
344
345
346 if (handle->h_transaction->t_state != T_RUNNING) {
347 jbd_debug(3, "denied handle %p %d blocks: "
348 "transaction not running\n", handle, nblocks);
349 goto error_out;
350 }
351
352 spin_lock(&transaction->t_handle_lock);
353 wanted = transaction->t_outstanding_credits + nblocks;
354
355 if (wanted > journal->j_max_transaction_buffers) {
356 jbd_debug(3, "denied handle %p %d blocks: "
357 "transaction too large\n", handle, nblocks);
358 goto unlock;
359 }
360
361 if (wanted > __jbd2_log_space_left(journal)) {
362 jbd_debug(3, "denied handle %p %d blocks: "
363 "insufficient log space\n", handle, nblocks);
364 goto unlock;
365 }
366
367 handle->h_buffer_credits += nblocks;
368 transaction->t_outstanding_credits += nblocks;
369 result = 0;
370
371 jbd_debug(3, "extended handle %p by %d\n", handle, nblocks);
372unlock:
373 spin_unlock(&transaction->t_handle_lock);
374error_out:
375 spin_unlock(&journal->j_state_lock);
376out:
377 return result;
378}
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396int jbd2_journal_restart(handle_t *handle, int nblocks)
397{
398 transaction_t *transaction = handle->h_transaction;
399 journal_t *journal = transaction->t_journal;
400 int ret;
401
402
403
404 if (is_handle_aborted(handle))
405 return 0;
406
407
408
409
410
411 J_ASSERT(transaction->t_updates > 0);
412 J_ASSERT(journal_current_handle() == handle);
413
414 spin_lock(&journal->j_state_lock);
415 spin_lock(&transaction->t_handle_lock);
416 transaction->t_outstanding_credits -= handle->h_buffer_credits;
417 transaction->t_updates--;
418
419 if (!transaction->t_updates)
420 wake_up(&journal->j_wait_updates);
421 spin_unlock(&transaction->t_handle_lock);
422
423 jbd_debug(2, "restarting handle %p\n", handle);
424 __jbd2_log_start_commit(journal, transaction->t_tid);
425 spin_unlock(&journal->j_state_lock);
426
427 handle->h_buffer_credits = nblocks;
428 ret = start_this_handle(journal, handle);
429 return ret;
430}
431
432
433
434
435
436
437
438
439
440
441
442
443void jbd2_journal_lock_updates(journal_t *journal)
444{
445 DEFINE_WAIT(wait);
446
447 spin_lock(&journal->j_state_lock);
448 ++journal->j_barrier_count;
449
450
451 while (1) {
452 transaction_t *transaction = journal->j_running_transaction;
453
454 if (!transaction)
455 break;
456
457 spin_lock(&transaction->t_handle_lock);
458 if (!transaction->t_updates) {
459 spin_unlock(&transaction->t_handle_lock);
460 break;
461 }
462 prepare_to_wait(&journal->j_wait_updates, &wait,
463 TASK_UNINTERRUPTIBLE);
464 spin_unlock(&transaction->t_handle_lock);
465 spin_unlock(&journal->j_state_lock);
466 schedule();
467 finish_wait(&journal->j_wait_updates, &wait);
468 spin_lock(&journal->j_state_lock);
469 }
470 spin_unlock(&journal->j_state_lock);
471
472
473
474
475
476
477
478 mutex_lock(&journal->j_barrier);
479}
480
481
482
483
484
485
486
487
488
489void jbd2_journal_unlock_updates (journal_t *journal)
490{
491 J_ASSERT(journal->j_barrier_count != 0);
492
493 mutex_unlock(&journal->j_barrier);
494 spin_lock(&journal->j_state_lock);
495 --journal->j_barrier_count;
496 spin_unlock(&journal->j_state_lock);
497 wake_up(&journal->j_wait_transaction_locked);
498}
499
500
501
502
503
504
505
506
507
508
509
510static void jbd_unexpected_dirty_buffer(struct journal_head *jh)
511{
512 int jlist;
513
514
515
516
517
518
519 jlist = jh->b_jlist;
520
521 if (jlist == BJ_Metadata || jlist == BJ_Reserved ||
522 jlist == BJ_Shadow || jlist == BJ_Forget) {
523 struct buffer_head *bh = jh2bh(jh);
524
525 if (test_clear_buffer_dirty(bh))
526 set_buffer_jbddirty(bh);
527 }
528}
529
530
531
532
533
534
535
536
537
538
539
540static int
541do_get_write_access(handle_t *handle, struct journal_head *jh,
542 int force_copy)
543{
544 struct buffer_head *bh;
545 transaction_t *transaction;
546 journal_t *journal;
547 int error;
548 char *frozen_buffer = NULL;
549 int need_copy = 0;
550
551 if (is_handle_aborted(handle))
552 return -EROFS;
553
554 transaction = handle->h_transaction;
555 journal = transaction->t_journal;
556
557 jbd_debug(5, "buffer_head %p, force_copy %d\n", jh, force_copy);
558
559 JBUFFER_TRACE(jh, "entry");
560repeat:
561 bh = jh2bh(jh);
562
563
564
565 lock_buffer(bh);
566 jbd_lock_bh_state(bh);
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581 if (buffer_dirty(bh)) {
582
583
584
585
586 if (jh->b_transaction) {
587 J_ASSERT_JH(jh,
588 jh->b_transaction == transaction ||
589 jh->b_transaction ==
590 journal->j_committing_transaction);
591 if (jh->b_next_transaction)
592 J_ASSERT_JH(jh, jh->b_next_transaction ==
593 transaction);
594 }
595
596
597
598
599
600 JBUFFER_TRACE(jh, "Unexpected dirty buffer");
601 jbd_unexpected_dirty_buffer(jh);
602 }
603
604 unlock_buffer(bh);
605
606 error = -EROFS;
607 if (is_handle_aborted(handle)) {
608 jbd_unlock_bh_state(bh);
609 goto out;
610 }
611 error = 0;
612
613
614
615
616
617 if (jh->b_transaction == transaction ||
618 jh->b_next_transaction == transaction)
619 goto done;
620
621
622
623
624
625 jh->b_modified = 0;
626
627
628
629
630
631 if (jh->b_frozen_data) {
632 JBUFFER_TRACE(jh, "has frozen data");
633 J_ASSERT_JH(jh, jh->b_next_transaction == NULL);
634 jh->b_next_transaction = transaction;
635 goto done;
636 }
637
638
639
640 if (jh->b_transaction && jh->b_transaction != transaction) {
641 JBUFFER_TRACE(jh, "owned by older transaction");
642 J_ASSERT_JH(jh, jh->b_next_transaction == NULL);
643 J_ASSERT_JH(jh, jh->b_transaction ==
644 journal->j_committing_transaction);
645
646
647
648
649
650
651
652
653
654
655 if (jh->b_jlist == BJ_Shadow) {
656 DEFINE_WAIT_BIT(wait, &bh->b_state, BH_Unshadow);
657 wait_queue_head_t *wqh;
658
659 wqh = bit_waitqueue(&bh->b_state, BH_Unshadow);
660
661 JBUFFER_TRACE(jh, "on shadow: sleep");
662 jbd_unlock_bh_state(bh);
663
664 for ( ; ; ) {
665 prepare_to_wait(wqh, &wait.wait,
666 TASK_UNINTERRUPTIBLE);
667 if (jh->b_jlist != BJ_Shadow)
668 break;
669 schedule();
670 }
671 finish_wait(wqh, &wait.wait);
672 goto repeat;
673 }
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689 if (jh->b_jlist != BJ_Forget || force_copy) {
690 JBUFFER_TRACE(jh, "generate frozen data");
691 if (!frozen_buffer) {
692 JBUFFER_TRACE(jh, "allocate memory for buffer");
693 jbd_unlock_bh_state(bh);
694 frozen_buffer =
695 jbd2_alloc(jh2bh(jh)->b_size,
696 GFP_NOFS);
697 if (!frozen_buffer) {
698 printk(KERN_EMERG
699 "%s: OOM for frozen_buffer\n",
700 __func__);
701 JBUFFER_TRACE(jh, "oom!");
702 error = -ENOMEM;
703 jbd_lock_bh_state(bh);
704 goto done;
705 }
706 goto repeat;
707 }
708 jh->b_frozen_data = frozen_buffer;
709 frozen_buffer = NULL;
710 need_copy = 1;
711 }
712 jh->b_next_transaction = transaction;
713 }
714
715
716
717
718
719
720
721 if (!jh->b_transaction) {
722 JBUFFER_TRACE(jh, "no transaction");
723 J_ASSERT_JH(jh, !jh->b_next_transaction);
724 jh->b_transaction = transaction;
725 JBUFFER_TRACE(jh, "file as BJ_Reserved");
726 spin_lock(&journal->j_list_lock);
727 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
728 spin_unlock(&journal->j_list_lock);
729 }
730
731done:
732 if (need_copy) {
733 struct page *page;
734 int offset;
735 char *source;
736
737 J_EXPECT_JH(jh, buffer_uptodate(jh2bh(jh)),
738 "Possible IO failure.\n");
739 page = jh2bh(jh)->b_page;
740 offset = ((unsigned long) jh2bh(jh)->b_data) & ~PAGE_MASK;
741 source = kmap_atomic(page, KM_USER0);
742 memcpy(jh->b_frozen_data, source+offset, jh2bh(jh)->b_size);
743 kunmap_atomic(source, KM_USER0);
744 }
745 jbd_unlock_bh_state(bh);
746
747
748
749
750
751 jbd2_journal_cancel_revoke(handle, jh);
752
753out:
754 if (unlikely(frozen_buffer))
755 jbd2_free(frozen_buffer, bh->b_size);
756
757 JBUFFER_TRACE(jh, "exit");
758 return error;
759}
760
761
762
763
764
765
766
767
768
769
770
771
772
773int jbd2_journal_get_write_access(handle_t *handle, struct buffer_head *bh)
774{
775 struct journal_head *jh = jbd2_journal_add_journal_head(bh);
776 int rc;
777
778
779
780
781 rc = do_get_write_access(handle, jh, 0);
782 jbd2_journal_put_journal_head(jh);
783 return rc;
784}
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh)
807{
808 transaction_t *transaction = handle->h_transaction;
809 journal_t *journal = transaction->t_journal;
810 struct journal_head *jh = jbd2_journal_add_journal_head(bh);
811 int err;
812
813 jbd_debug(5, "journal_head %p\n", jh);
814 err = -EROFS;
815 if (is_handle_aborted(handle))
816 goto out;
817 err = 0;
818
819 JBUFFER_TRACE(jh, "entry");
820
821
822
823
824
825
826
827 jbd_lock_bh_state(bh);
828 spin_lock(&journal->j_list_lock);
829 J_ASSERT_JH(jh, (jh->b_transaction == transaction ||
830 jh->b_transaction == NULL ||
831 (jh->b_transaction == journal->j_committing_transaction &&
832 jh->b_jlist == BJ_Forget)));
833
834 J_ASSERT_JH(jh, jh->b_next_transaction == NULL);
835 J_ASSERT_JH(jh, buffer_locked(jh2bh(jh)));
836
837 if (jh->b_transaction == NULL) {
838 jh->b_transaction = transaction;
839
840
841 jh->b_modified = 0;
842
843 JBUFFER_TRACE(jh, "file as BJ_Reserved");
844 __jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
845 } else if (jh->b_transaction == journal->j_committing_transaction) {
846
847 jh->b_modified = 0;
848
849 JBUFFER_TRACE(jh, "set next transaction");
850 jh->b_next_transaction = transaction;
851 }
852 spin_unlock(&journal->j_list_lock);
853 jbd_unlock_bh_state(bh);
854
855
856
857
858
859
860
861
862 JBUFFER_TRACE(jh, "cancelling revoke");
863 jbd2_journal_cancel_revoke(handle, jh);
864 jbd2_journal_put_journal_head(jh);
865out:
866 return err;
867}
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896int jbd2_journal_get_undo_access(handle_t *handle, struct buffer_head *bh)
897{
898 int err;
899 struct journal_head *jh = jbd2_journal_add_journal_head(bh);
900 char *committed_data = NULL;
901
902 JBUFFER_TRACE(jh, "entry");
903
904
905
906
907
908
909 err = do_get_write_access(handle, jh, 1);
910 if (err)
911 goto out;
912
913repeat:
914 if (!jh->b_committed_data) {
915 committed_data = jbd2_alloc(jh2bh(jh)->b_size, GFP_NOFS);
916 if (!committed_data) {
917 printk(KERN_EMERG "%s: No memory for committed data\n",
918 __func__);
919 err = -ENOMEM;
920 goto out;
921 }
922 }
923
924 jbd_lock_bh_state(bh);
925 if (!jh->b_committed_data) {
926
927
928 JBUFFER_TRACE(jh, "generate b_committed data");
929 if (!committed_data) {
930 jbd_unlock_bh_state(bh);
931 goto repeat;
932 }
933
934 jh->b_committed_data = committed_data;
935 committed_data = NULL;
936 memcpy(jh->b_committed_data, bh->b_data, bh->b_size);
937 }
938 jbd_unlock_bh_state(bh);
939out:
940 jbd2_journal_put_journal_head(jh);
941 if (unlikely(committed_data))
942 jbd2_free(committed_data, bh->b_size);
943 return err;
944}
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh)
966{
967 transaction_t *transaction = handle->h_transaction;
968 journal_t *journal = transaction->t_journal;
969 struct journal_head *jh = bh2jh(bh);
970
971 jbd_debug(5, "journal_head %p\n", jh);
972 JBUFFER_TRACE(jh, "entry");
973 if (is_handle_aborted(handle))
974 goto out;
975
976 jbd_lock_bh_state(bh);
977
978 if (jh->b_modified == 0) {
979
980
981
982
983
984 jh->b_modified = 1;
985 J_ASSERT_JH(jh, handle->h_buffer_credits > 0);
986 handle->h_buffer_credits--;
987 }
988
989
990
991
992
993
994
995
996 if (jh->b_transaction == transaction && jh->b_jlist == BJ_Metadata) {
997 JBUFFER_TRACE(jh, "fastpath");
998 J_ASSERT_JH(jh, jh->b_transaction ==
999 journal->j_running_transaction);
1000 goto out_unlock_bh;
1001 }
1002
1003 set_buffer_jbddirty(bh);
1004
1005
1006
1007
1008
1009
1010
1011 if (jh->b_transaction != transaction) {
1012 JBUFFER_TRACE(jh, "already on other transaction");
1013 J_ASSERT_JH(jh, jh->b_transaction ==
1014 journal->j_committing_transaction);
1015 J_ASSERT_JH(jh, jh->b_next_transaction == transaction);
1016
1017
1018 goto out_unlock_bh;
1019 }
1020
1021
1022 J_ASSERT_JH(jh, jh->b_frozen_data == NULL);
1023
1024 JBUFFER_TRACE(jh, "file as BJ_Metadata");
1025 spin_lock(&journal->j_list_lock);
1026 __jbd2_journal_file_buffer(jh, handle->h_transaction, BJ_Metadata);
1027 spin_unlock(&journal->j_list_lock);
1028out_unlock_bh:
1029 jbd_unlock_bh_state(bh);
1030out:
1031 JBUFFER_TRACE(jh, "exit");
1032 return 0;
1033}
1034
1035
1036
1037
1038
1039
1040void
1041jbd2_journal_release_buffer(handle_t *handle, struct buffer_head *bh)
1042{
1043 BUFFER_TRACE(bh, "entry");
1044}
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)
1064{
1065 transaction_t *transaction = handle->h_transaction;
1066 journal_t *journal = transaction->t_journal;
1067 struct journal_head *jh;
1068 int drop_reserve = 0;
1069 int err = 0;
1070 int was_modified = 0;
1071
1072 BUFFER_TRACE(bh, "entry");
1073
1074 jbd_lock_bh_state(bh);
1075 spin_lock(&journal->j_list_lock);
1076
1077 if (!buffer_jbd(bh))
1078 goto not_jbd;
1079 jh = bh2jh(bh);
1080
1081
1082
1083 if (!J_EXPECT_JH(jh, !jh->b_committed_data,
1084 "inconsistent data on disk")) {
1085 err = -EIO;
1086 goto not_jbd;
1087 }
1088
1089
1090 was_modified = jh->b_modified;
1091
1092
1093
1094
1095
1096 jh->b_modified = 0;
1097
1098 if (jh->b_transaction == handle->h_transaction) {
1099 J_ASSERT_JH(jh, !jh->b_frozen_data);
1100
1101
1102
1103
1104 clear_buffer_dirty(bh);
1105 clear_buffer_jbddirty(bh);
1106
1107 JBUFFER_TRACE(jh, "belongs to current transaction: unfile");
1108
1109
1110
1111
1112
1113 if (was_modified)
1114 drop_reserve = 1;
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128 if (jh->b_cp_transaction) {
1129 __jbd2_journal_temp_unlink_buffer(jh);
1130 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1131 } else {
1132 __jbd2_journal_unfile_buffer(jh);
1133 jbd2_journal_remove_journal_head(bh);
1134 __brelse(bh);
1135 if (!buffer_jbd(bh)) {
1136 spin_unlock(&journal->j_list_lock);
1137 jbd_unlock_bh_state(bh);
1138 __bforget(bh);
1139 goto drop;
1140 }
1141 }
1142 } else if (jh->b_transaction) {
1143 J_ASSERT_JH(jh, (jh->b_transaction ==
1144 journal->j_committing_transaction));
1145
1146
1147 JBUFFER_TRACE(jh, "belongs to older transaction");
1148
1149
1150
1151 if (jh->b_next_transaction) {
1152 J_ASSERT(jh->b_next_transaction == transaction);
1153 jh->b_next_transaction = NULL;
1154
1155
1156
1157
1158
1159 if (was_modified)
1160 drop_reserve = 1;
1161 }
1162 }
1163
1164not_jbd:
1165 spin_unlock(&journal->j_list_lock);
1166 jbd_unlock_bh_state(bh);
1167 __brelse(bh);
1168drop:
1169 if (drop_reserve) {
1170
1171 handle->h_buffer_credits++;
1172 }
1173 return err;
1174}
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192int jbd2_journal_stop(handle_t *handle)
1193{
1194 transaction_t *transaction = handle->h_transaction;
1195 journal_t *journal = transaction->t_journal;
1196 int old_handle_count, err;
1197 pid_t pid;
1198
1199 J_ASSERT(journal_current_handle() == handle);
1200
1201 if (is_handle_aborted(handle))
1202 err = -EIO;
1203 else {
1204 J_ASSERT(transaction->t_updates > 0);
1205 err = 0;
1206 }
1207
1208 if (--handle->h_ref > 0) {
1209 jbd_debug(4, "h_ref %d -> %d\n", handle->h_ref + 1,
1210 handle->h_ref);
1211 return err;
1212 }
1213
1214 jbd_debug(4, "Handle %p going down\n", handle);
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230 pid = current->pid;
1231 if (handle->h_sync && journal->j_last_sync_writer != pid) {
1232 journal->j_last_sync_writer = pid;
1233 do {
1234 old_handle_count = transaction->t_handle_count;
1235 schedule_timeout_uninterruptible(1);
1236 } while (old_handle_count != transaction->t_handle_count);
1237 }
1238
1239 current->journal_info = NULL;
1240 spin_lock(&journal->j_state_lock);
1241 spin_lock(&transaction->t_handle_lock);
1242 transaction->t_outstanding_credits -= handle->h_buffer_credits;
1243 transaction->t_updates--;
1244 if (!transaction->t_updates) {
1245 wake_up(&journal->j_wait_updates);
1246 if (journal->j_barrier_count)
1247 wake_up(&journal->j_wait_transaction_locked);
1248 }
1249
1250
1251
1252
1253
1254
1255
1256 if (handle->h_sync ||
1257 transaction->t_outstanding_credits >
1258 journal->j_max_transaction_buffers ||
1259 time_after_eq(jiffies, transaction->t_expires)) {
1260
1261
1262
1263 tid_t tid = transaction->t_tid;
1264
1265 spin_unlock(&transaction->t_handle_lock);
1266 jbd_debug(2, "transaction too old, requesting commit for "
1267 "handle %p\n", handle);
1268
1269 __jbd2_log_start_commit(journal, transaction->t_tid);
1270 spin_unlock(&journal->j_state_lock);
1271
1272
1273
1274
1275
1276 if (handle->h_sync && !(current->flags & PF_MEMALLOC))
1277 err = jbd2_log_wait_commit(journal, tid);
1278 } else {
1279 spin_unlock(&transaction->t_handle_lock);
1280 spin_unlock(&journal->j_state_lock);
1281 }
1282
1283 lock_map_release(&handle->h_lockdep_map);
1284
1285 jbd2_free_handle(handle);
1286 return err;
1287}
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297int jbd2_journal_force_commit(journal_t *journal)
1298{
1299 handle_t *handle;
1300 int ret;
1301
1302 handle = jbd2_journal_start(journal, 1);
1303 if (IS_ERR(handle)) {
1304 ret = PTR_ERR(handle);
1305 } else {
1306 handle->h_sync = 1;
1307 ret = jbd2_journal_stop(handle);
1308 }
1309 return ret;
1310}
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328static inline void
1329__blist_add_buffer(struct journal_head **list, struct journal_head *jh)
1330{
1331 if (!*list) {
1332 jh->b_tnext = jh->b_tprev = jh;
1333 *list = jh;
1334 } else {
1335
1336 struct journal_head *first = *list, *last = first->b_tprev;
1337 jh->b_tprev = last;
1338 jh->b_tnext = first;
1339 last->b_tnext = first->b_tprev = jh;
1340 }
1341}
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352static inline void
1353__blist_del_buffer(struct journal_head **list, struct journal_head *jh)
1354{
1355 if (*list == jh) {
1356 *list = jh->b_tnext;
1357 if (*list == jh)
1358 *list = NULL;
1359 }
1360 jh->b_tprev->b_tnext = jh->b_tnext;
1361 jh->b_tnext->b_tprev = jh->b_tprev;
1362}
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh)
1376{
1377 struct journal_head **list = NULL;
1378 transaction_t *transaction;
1379 struct buffer_head *bh = jh2bh(jh);
1380
1381 J_ASSERT_JH(jh, jbd_is_locked_bh_state(bh));
1382 transaction = jh->b_transaction;
1383 if (transaction)
1384 assert_spin_locked(&transaction->t_journal->j_list_lock);
1385
1386 J_ASSERT_JH(jh, jh->b_jlist < BJ_Types);
1387 if (jh->b_jlist != BJ_None)
1388 J_ASSERT_JH(jh, transaction != NULL);
1389
1390 switch (jh->b_jlist) {
1391 case BJ_None:
1392 return;
1393 case BJ_Metadata:
1394 transaction->t_nr_buffers--;
1395 J_ASSERT_JH(jh, transaction->t_nr_buffers >= 0);
1396 list = &transaction->t_buffers;
1397 break;
1398 case BJ_Forget:
1399 list = &transaction->t_forget;
1400 break;
1401 case BJ_IO:
1402 list = &transaction->t_iobuf_list;
1403 break;
1404 case BJ_Shadow:
1405 list = &transaction->t_shadow_list;
1406 break;
1407 case BJ_LogCtl:
1408 list = &transaction->t_log_list;
1409 break;
1410 case BJ_Reserved:
1411 list = &transaction->t_reserved_list;
1412 break;
1413 }
1414
1415 __blist_del_buffer(list, jh);
1416 jh->b_jlist = BJ_None;
1417 if (test_clear_buffer_jbddirty(bh))
1418 mark_buffer_dirty(bh);
1419}
1420
1421void __jbd2_journal_unfile_buffer(struct journal_head *jh)
1422{
1423 __jbd2_journal_temp_unlink_buffer(jh);
1424 jh->b_transaction = NULL;
1425}
1426
1427void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh)
1428{
1429 jbd_lock_bh_state(jh2bh(jh));
1430 spin_lock(&journal->j_list_lock);
1431 __jbd2_journal_unfile_buffer(jh);
1432 spin_unlock(&journal->j_list_lock);
1433 jbd_unlock_bh_state(jh2bh(jh));
1434}
1435
1436
1437
1438
1439
1440
1441static void
1442__journal_try_to_free_buffer(journal_t *journal, struct buffer_head *bh)
1443{
1444 struct journal_head *jh;
1445
1446 jh = bh2jh(bh);
1447
1448 if (buffer_locked(bh) || buffer_dirty(bh))
1449 goto out;
1450
1451 if (jh->b_next_transaction != NULL)
1452 goto out;
1453
1454 spin_lock(&journal->j_list_lock);
1455 if (jh->b_cp_transaction != NULL && jh->b_transaction == NULL) {
1456
1457 if (jh->b_jlist == BJ_None) {
1458 JBUFFER_TRACE(jh, "remove from checkpoint list");
1459 __jbd2_journal_remove_checkpoint(jh);
1460 jbd2_journal_remove_journal_head(bh);
1461 __brelse(bh);
1462 }
1463 }
1464 spin_unlock(&journal->j_list_lock);
1465out:
1466 return;
1467}
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481static void jbd2_journal_wait_for_transaction_sync_data(journal_t *journal)
1482{
1483 transaction_t *transaction;
1484 tid_t tid;
1485
1486 spin_lock(&journal->j_state_lock);
1487 transaction = journal->j_committing_transaction;
1488
1489 if (!transaction) {
1490 spin_unlock(&journal->j_state_lock);
1491 return;
1492 }
1493
1494 tid = transaction->t_tid;
1495 spin_unlock(&journal->j_state_lock);
1496 jbd2_log_wait_commit(journal, tid);
1497}
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537int jbd2_journal_try_to_free_buffers(journal_t *journal,
1538 struct page *page, gfp_t gfp_mask)
1539{
1540 struct buffer_head *head;
1541 struct buffer_head *bh;
1542 int ret = 0;
1543
1544 J_ASSERT(PageLocked(page));
1545
1546 head = page_buffers(page);
1547 bh = head;
1548 do {
1549 struct journal_head *jh;
1550
1551
1552
1553
1554
1555
1556
1557 jh = jbd2_journal_grab_journal_head(bh);
1558 if (!jh)
1559 continue;
1560
1561 jbd_lock_bh_state(bh);
1562 __journal_try_to_free_buffer(journal, bh);
1563 jbd2_journal_put_journal_head(jh);
1564 jbd_unlock_bh_state(bh);
1565 if (buffer_jbd(bh))
1566 goto busy;
1567 } while ((bh = bh->b_this_page) != head);
1568
1569 ret = try_to_free_buffers(page);
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585 if (ret == 0 && (gfp_mask & __GFP_WAIT) && (gfp_mask & __GFP_FS)) {
1586 jbd2_journal_wait_for_transaction_sync_data(journal);
1587 ret = try_to_free_buffers(page);
1588 }
1589
1590busy:
1591 return ret;
1592}
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction)
1607{
1608 int may_free = 1;
1609 struct buffer_head *bh = jh2bh(jh);
1610
1611 __jbd2_journal_unfile_buffer(jh);
1612
1613 if (jh->b_cp_transaction) {
1614 JBUFFER_TRACE(jh, "on running+cp transaction");
1615 __jbd2_journal_file_buffer(jh, transaction, BJ_Forget);
1616 clear_buffer_jbddirty(bh);
1617 may_free = 0;
1618 } else {
1619 JBUFFER_TRACE(jh, "on running transaction");
1620 jbd2_journal_remove_journal_head(bh);
1621 __brelse(bh);
1622 }
1623 return may_free;
1624}
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1674{
1675 transaction_t *transaction;
1676 struct journal_head *jh;
1677 int may_free = 1;
1678 int ret;
1679
1680 BUFFER_TRACE(bh, "entry");
1681
1682
1683
1684
1685
1686
1687
1688 if (!buffer_jbd(bh))
1689 goto zap_buffer_unlocked;
1690
1691
1692 spin_lock(&journal->j_state_lock);
1693 jbd_lock_bh_state(bh);
1694 spin_lock(&journal->j_list_lock);
1695
1696 jh = jbd2_journal_grab_journal_head(bh);
1697 if (!jh)
1698 goto zap_buffer_no_jh;
1699
1700 transaction = jh->b_transaction;
1701 if (transaction == NULL) {
1702
1703
1704
1705
1706 if (!jh->b_cp_transaction) {
1707 JBUFFER_TRACE(jh, "not on any transaction: zap");
1708 goto zap_buffer;
1709 }
1710
1711 if (!buffer_dirty(bh)) {
1712
1713 goto zap_buffer;
1714 }
1715
1716
1717
1718
1719
1720 if (journal->j_running_transaction) {
1721
1722
1723
1724 JBUFFER_TRACE(jh, "checkpointed: add to BJ_Forget");
1725 ret = __dispose_buffer(jh,
1726 journal->j_running_transaction);
1727 jbd2_journal_put_journal_head(jh);
1728 spin_unlock(&journal->j_list_lock);
1729 jbd_unlock_bh_state(bh);
1730 spin_unlock(&journal->j_state_lock);
1731 return ret;
1732 } else {
1733
1734
1735
1736
1737 if (journal->j_committing_transaction) {
1738 JBUFFER_TRACE(jh, "give to committing trans");
1739 ret = __dispose_buffer(jh,
1740 journal->j_committing_transaction);
1741 jbd2_journal_put_journal_head(jh);
1742 spin_unlock(&journal->j_list_lock);
1743 jbd_unlock_bh_state(bh);
1744 spin_unlock(&journal->j_state_lock);
1745 return ret;
1746 } else {
1747
1748
1749 clear_buffer_jbddirty(bh);
1750 goto zap_buffer;
1751 }
1752 }
1753 } else if (transaction == journal->j_committing_transaction) {
1754 JBUFFER_TRACE(jh, "on committing transaction");
1755
1756
1757
1758
1759
1760 set_buffer_freed(bh);
1761 if (jh->b_next_transaction) {
1762 J_ASSERT(jh->b_next_transaction ==
1763 journal->j_running_transaction);
1764 jh->b_next_transaction = NULL;
1765 }
1766 jbd2_journal_put_journal_head(jh);
1767 spin_unlock(&journal->j_list_lock);
1768 jbd_unlock_bh_state(bh);
1769 spin_unlock(&journal->j_state_lock);
1770 return 0;
1771 } else {
1772
1773
1774
1775
1776
1777
1778 J_ASSERT_JH(jh, transaction == journal->j_running_transaction);
1779 JBUFFER_TRACE(jh, "on running transaction");
1780 may_free = __dispose_buffer(jh, transaction);
1781 }
1782
1783zap_buffer:
1784 jbd2_journal_put_journal_head(jh);
1785zap_buffer_no_jh:
1786 spin_unlock(&journal->j_list_lock);
1787 jbd_unlock_bh_state(bh);
1788 spin_unlock(&journal->j_state_lock);
1789zap_buffer_unlocked:
1790 clear_buffer_dirty(bh);
1791 J_ASSERT_BH(bh, !buffer_jbddirty(bh));
1792 clear_buffer_mapped(bh);
1793 clear_buffer_req(bh);
1794 clear_buffer_new(bh);
1795 bh->b_bdev = NULL;
1796 return may_free;
1797}
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808void jbd2_journal_invalidatepage(journal_t *journal,
1809 struct page *page,
1810 unsigned long offset)
1811{
1812 struct buffer_head *head, *bh, *next;
1813 unsigned int curr_off = 0;
1814 int may_free = 1;
1815
1816 if (!PageLocked(page))
1817 BUG();
1818 if (!page_has_buffers(page))
1819 return;
1820
1821
1822
1823
1824
1825 head = bh = page_buffers(page);
1826 do {
1827 unsigned int next_off = curr_off + bh->b_size;
1828 next = bh->b_this_page;
1829
1830 if (offset <= curr_off) {
1831
1832 lock_buffer(bh);
1833 may_free &= journal_unmap_buffer(journal, bh);
1834 unlock_buffer(bh);
1835 }
1836 curr_off = next_off;
1837 bh = next;
1838
1839 } while (bh != head);
1840
1841 if (!offset) {
1842 if (may_free && try_to_free_buffers(page))
1843 J_ASSERT(!page_has_buffers(page));
1844 }
1845}
1846
1847
1848
1849
1850void __jbd2_journal_file_buffer(struct journal_head *jh,
1851 transaction_t *transaction, int jlist)
1852{
1853 struct journal_head **list = NULL;
1854 int was_dirty = 0;
1855 struct buffer_head *bh = jh2bh(jh);
1856
1857 J_ASSERT_JH(jh, jbd_is_locked_bh_state(bh));
1858 assert_spin_locked(&transaction->t_journal->j_list_lock);
1859
1860 J_ASSERT_JH(jh, jh->b_jlist < BJ_Types);
1861 J_ASSERT_JH(jh, jh->b_transaction == transaction ||
1862 jh->b_transaction == NULL);
1863
1864 if (jh->b_transaction && jh->b_jlist == jlist)
1865 return;
1866
1867
1868
1869
1870
1871 if (jlist == BJ_Metadata || jlist == BJ_Reserved ||
1872 jlist == BJ_Shadow || jlist == BJ_Forget) {
1873 if (test_clear_buffer_dirty(bh) ||
1874 test_clear_buffer_jbddirty(bh))
1875 was_dirty = 1;
1876 }
1877
1878 if (jh->b_transaction)
1879 __jbd2_journal_temp_unlink_buffer(jh);
1880 jh->b_transaction = transaction;
1881
1882 switch (jlist) {
1883 case BJ_None:
1884 J_ASSERT_JH(jh, !jh->b_committed_data);
1885 J_ASSERT_JH(jh, !jh->b_frozen_data);
1886 return;
1887 case BJ_Metadata:
1888 transaction->t_nr_buffers++;
1889 list = &transaction->t_buffers;
1890 break;
1891 case BJ_Forget:
1892 list = &transaction->t_forget;
1893 break;
1894 case BJ_IO:
1895 list = &transaction->t_iobuf_list;
1896 break;
1897 case BJ_Shadow:
1898 list = &transaction->t_shadow_list;
1899 break;
1900 case BJ_LogCtl:
1901 list = &transaction->t_log_list;
1902 break;
1903 case BJ_Reserved:
1904 list = &transaction->t_reserved_list;
1905 break;
1906 }
1907
1908 __blist_add_buffer(list, jh);
1909 jh->b_jlist = jlist;
1910
1911 if (was_dirty)
1912 set_buffer_jbddirty(bh);
1913}
1914
1915void jbd2_journal_file_buffer(struct journal_head *jh,
1916 transaction_t *transaction, int jlist)
1917{
1918 jbd_lock_bh_state(jh2bh(jh));
1919 spin_lock(&transaction->t_journal->j_list_lock);
1920 __jbd2_journal_file_buffer(jh, transaction, jlist);
1921 spin_unlock(&transaction->t_journal->j_list_lock);
1922 jbd_unlock_bh_state(jh2bh(jh));
1923}
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935void __jbd2_journal_refile_buffer(struct journal_head *jh)
1936{
1937 int was_dirty;
1938 struct buffer_head *bh = jh2bh(jh);
1939
1940 J_ASSERT_JH(jh, jbd_is_locked_bh_state(bh));
1941 if (jh->b_transaction)
1942 assert_spin_locked(&jh->b_transaction->t_journal->j_list_lock);
1943
1944
1945 if (jh->b_next_transaction == NULL) {
1946 __jbd2_journal_unfile_buffer(jh);
1947 return;
1948 }
1949
1950
1951
1952
1953
1954
1955 was_dirty = test_clear_buffer_jbddirty(bh);
1956 __jbd2_journal_temp_unlink_buffer(jh);
1957 jh->b_transaction = jh->b_next_transaction;
1958 jh->b_next_transaction = NULL;
1959 __jbd2_journal_file_buffer(jh, jh->b_transaction,
1960 jh->b_modified ? BJ_Metadata : BJ_Reserved);
1961 J_ASSERT_JH(jh, jh->b_transaction->t_state == T_RUNNING);
1962
1963 if (was_dirty)
1964 set_buffer_jbddirty(bh);
1965}
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh)
1982{
1983 struct buffer_head *bh = jh2bh(jh);
1984
1985 jbd_lock_bh_state(bh);
1986 spin_lock(&journal->j_list_lock);
1987
1988 __jbd2_journal_refile_buffer(jh);
1989 jbd_unlock_bh_state(bh);
1990 jbd2_journal_remove_journal_head(bh);
1991
1992 spin_unlock(&journal->j_list_lock);
1993 __brelse(bh);
1994}
1995
1996
1997
1998
1999int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode)
2000{
2001 transaction_t *transaction = handle->h_transaction;
2002 journal_t *journal = transaction->t_journal;
2003
2004 if (is_handle_aborted(handle))
2005 return -EIO;
2006
2007 jbd_debug(4, "Adding inode %lu, tid:%d\n", jinode->i_vfs_inode->i_ino,
2008 transaction->t_tid);
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023 if (jinode->i_transaction == transaction ||
2024 jinode->i_next_transaction == transaction)
2025 return 0;
2026
2027 spin_lock(&journal->j_list_lock);
2028
2029 if (jinode->i_transaction == transaction ||
2030 jinode->i_next_transaction == transaction)
2031 goto done;
2032
2033
2034
2035 if (jinode->i_transaction) {
2036 J_ASSERT(jinode->i_next_transaction == NULL);
2037 J_ASSERT(jinode->i_transaction ==
2038 journal->j_committing_transaction);
2039 jinode->i_next_transaction = transaction;
2040 goto done;
2041 }
2042
2043 J_ASSERT(!jinode->i_next_transaction);
2044 jinode->i_transaction = transaction;
2045 list_add(&jinode->i_list, &transaction->t_inode_list);
2046done:
2047 spin_unlock(&journal->j_list_lock);
2048
2049 return 0;
2050}
2051
2052
2053
2054
2055
2056
2057
2058int jbd2_journal_begin_ordered_truncate(struct jbd2_inode *inode,
2059 loff_t new_size)
2060{
2061 journal_t *journal;
2062 transaction_t *commit_trans;
2063 int ret = 0;
2064
2065 if (!inode->i_transaction && !inode->i_next_transaction)
2066 goto out;
2067 journal = inode->i_transaction->t_journal;
2068 spin_lock(&journal->j_state_lock);
2069 commit_trans = journal->j_committing_transaction;
2070 spin_unlock(&journal->j_state_lock);
2071 if (inode->i_transaction == commit_trans) {
2072 ret = filemap_fdatawrite_range(inode->i_vfs_inode->i_mapping,
2073 new_size, LLONG_MAX);
2074 if (ret)
2075 jbd2_journal_abort(journal, ret);
2076 }
2077out:
2078 return ret;
2079}