ext4_journal: two changes on adding block descriptor to a transaction.
authorngkaho1234 <ngkaho1234@gmail.com>
Mon, 21 Dec 2015 08:28:48 +0000 (08:28 +0000)
committerngkaho1234 <ngkaho1234@gmail.com>
Mon, 21 Dec 2015 08:49:30 +0000 (08:49 +0000)
  - jbd_trans_add_block is renamed to jbd_trans_set_block_dirty
  - jbd_trans_get_access routine should be called to gain access
    to a buffer.

lwext4/ext4.c
lwext4/ext4_journal.c
lwext4/ext4_journal.h

index d9381a2961dd7eeb8c8291b89d8b2050064e8dcc..b63f65b842b30ad75d47ed7261904adb93215072 100644 (file)
@@ -2562,7 +2562,15 @@ int ext4_test_journal(const char *mount_point)
 
                        switch (rand() % 2) {
                        case 0:
-                               r = jbd_trans_add_block(t, &block);
+                               r = jbd_trans_get_access(journal, &block);
+                               if (r != EOK) {
+                                       jbd_journal_free_trans(journal, t,
+                                                              true);
+                                       ext4_block_set(mp->fs.bdev, &block);
+                                       r = ENOMEM;
+                                       goto out;
+                               }
+                               r = jbd_trans_set_block_dirty(t, &block);
                                if (r != EOK) {
                                        jbd_journal_free_trans(journal, t,
                                                               true);
@@ -2570,7 +2578,6 @@ int ext4_test_journal(const char *mount_point)
                                        r = ENOMEM;
                                        goto out;
                                }
-                               ext4_bcache_set_dirty(block.buf);
                                break;
                        case 1:
                                r = jbd_trans_revoke_block(t, rand_block);
index c9dc99a549cb54d1944468ddf7a6a215d386736a..e062f6a88a76fb93c6e8921b993304c57198a2a6 100644 (file)
@@ -1092,25 +1092,33 @@ static void jbd_trans_end_write(struct ext4_bcache *bc __unused,
                          int res,
                          void *arg);
 
-/**@brief  Add block to a transaction and gain
- *         access to it before making any modications.
- * @param  trans transaction
- * @param  block block descriptor
- * @return standard error code*/
-int jbd_trans_add_block(struct jbd_trans *trans,
-                       struct ext4_block *block)
+/**@brief  gain access to it before making any modications.
+ * @param  journal current journal session
+ * @param  block descriptor
+ * @return standard error code.*/
+int jbd_trans_get_access(struct jbd_journal *journal,
+                        struct ext4_block *block)
 {
-       struct jbd_buf *buf;
-       struct ext4_fs *fs =
-               trans->journal->jbd_fs->inode_ref.fs;
+       int r = EOK;
+       struct ext4_fs *fs = journal->jbd_fs->inode_ref.fs;
 
        /* If the buffer has already been modified, we should
         * flush dirty data in this buffer to disk.*/
-       if (ext4_bcache_test_flag(block->buf, BC_DIRTY)) {
-               /* XXX: i don't want to know whether the call
-                * succeeds or not. */
-               ext4_block_flush_buf(fs->bdev, block->buf);
+       if (ext4_bcache_test_flag(block->buf, BC_DIRTY) &&
+           block->buf->end_write == jbd_trans_end_write) {
+               r = ext4_block_flush_buf(fs->bdev, block->buf);
        }
+       return r;
+}
+
+/**@brief  Add block to a transaction and mark it dirty.
+ * @param  trans transaction
+ * @param  block block descriptor
+ * @return standard error code*/
+int jbd_trans_set_block_dirty(struct jbd_trans *trans,
+                             struct ext4_block *block)
+{
+       struct jbd_buf *buf;
 
        buf = calloc(1, sizeof(struct jbd_buf));
        if (!buf)
@@ -1127,6 +1135,8 @@ int jbd_trans_add_block(struct jbd_trans *trans,
 
        trans->data_cnt++;
        LIST_INSERT_HEAD(&trans->buf_list, buf, buf_node);
+
+       ext4_bcache_set_dirty(block->buf);
        return EOK;
 }
 
index 6206873f749ce294179c0a9f91f8b0e1a6bd6c24..d68c7083e4e7c2f3c4873785891de7437b3af06c 100644 (file)
@@ -55,8 +55,10 @@ int jbd_journal_start(struct jbd_fs *jbd_fs,
                      struct jbd_journal *journal);
 int jbd_journal_stop(struct jbd_journal *journal);
 struct jbd_trans *jbd_journal_new_trans(struct jbd_journal *journal);
-int jbd_trans_add_block(struct jbd_trans *trans,
-                       struct ext4_block *block);
+int jbd_trans_get_access(struct jbd_journal *journal,
+                        struct ext4_block *block);
+int jbd_trans_set_block_dirty(struct jbd_trans *trans,
+                             struct ext4_block *block);
 int jbd_trans_revoke_block(struct jbd_trans *trans,
                           ext4_fsblk_t lba);
 void jbd_journal_free_trans(struct jbd_journal *journal,