2 * Copyright (c) 2015 Grzegorz Kostka (kostka.grzegorz@gmail.com)
3 * Copyright (c) 2015 Kaho Ng (ngkaho1234@gmail.com)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 /** @addtogroup lwext4
35 * @brief Ext4 transaction buffer operations.
38 #include "ext4_config.h"
39 #include "ext4_types.h"
40 #include "ext4_misc.h"
41 #include "ext4_errno.h"
42 #include "ext4_debug.h"
45 #include "ext4_journal.h"
47 static int ext4_trans_get_write_access(struct ext4_fs *fs __unused,
48 struct ext4_block *block __unused)
51 #if CONFIG_JOURNALING_ENABLE
52 if (fs->jbd_journal && fs->curr_trans) {
53 struct jbd_journal *journal = fs->jbd_journal;
54 struct jbd_trans *trans = fs->curr_trans;
55 r = jbd_trans_get_access(journal, trans, block);
61 int ext4_trans_set_block_dirty(struct ext4_buf *buf)
64 #if CONFIG_JOURNALING_ENABLE
65 struct ext4_fs *fs = buf->bc->bdev->fs;
66 struct ext4_block block = {
72 if (fs->jbd_journal && fs->curr_trans) {
73 struct jbd_trans *trans = fs->curr_trans;
74 return jbd_trans_set_block_dirty(trans, &block);
77 ext4_bcache_set_dirty(buf);
81 int ext4_trans_block_get_noread(struct ext4_blockdev *bdev,
85 int r = ext4_block_get_noread(bdev, b, lba);
89 r = ext4_trans_get_write_access(bdev->fs, b);
91 ext4_block_set(bdev, b);
96 int ext4_trans_block_get(struct ext4_blockdev *bdev,
100 int r = ext4_block_get(bdev, b, lba);
104 r = ext4_trans_get_write_access(bdev->fs, b);
106 ext4_block_set(bdev, b);
111 int ext4_trans_try_revoke_block(struct ext4_blockdev *bdev __unused,
112 uint64_t lba __unused)
115 #if CONFIG_JOURNALING_ENABLE
116 struct ext4_fs *fs = bdev->fs;
117 if (fs->jbd_journal && fs->curr_trans) {
118 struct jbd_trans *trans = fs->curr_trans;
119 r = jbd_trans_try_revoke_block(trans, lba);
120 } else if (fs->jbd_journal) {
121 r = ext4_block_flush_lba(fs->bdev, lba);