shithub: lwext4

Download patch

ref: e7541250edb2a747a3a339439de98c80025ab022
parent: c568b087e35003acc2b4d3a14049787d22617c3a
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Thu Dec 24 13:32:19 EST 2015

ext4: move journalling start/stop code outside mount/umount.

--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -415,16 +415,6 @@
 		return r;
 	}
 
-	if (ext4_sb_feature_com(&mp->fs.sb,
-				EXT4_FCOM_HAS_JOURNAL)) {
-		r = jbd_get_fs(&mp->fs, &mp->jbd_fs);
-		ext4_assert(r == EOK);
-		r = jbd_journal_start(&mp->jbd_fs, &mp->jbd_journal);
-		ext4_assert(r == EOK);
-		mp->fs.jbd_fs = &mp->jbd_fs;
-		mp->fs.jbd_journal = &mp->jbd_journal;
-	}
-
 	return r;
 }
 
@@ -445,16 +435,6 @@
 	if (!mp)
 		return ENODEV;
 
-	if (ext4_sb_feature_com(&mp->fs.sb,
-				EXT4_FCOM_HAS_JOURNAL)) {
-		r = jbd_journal_stop(&mp->jbd_journal);
-		ext4_assert(r == EOK);
-		r = jbd_put_fs(&mp->jbd_fs);
-		ext4_assert(r == EOK);
-		mp->fs.jbd_journal = NULL;
-		mp->fs.jbd_fs = NULL;
-	}
-
 	r = ext4_fs_fini(&mp->fs);
 	if (r != EOK)
 		return r;
@@ -482,6 +462,64 @@
 			return &_mp[i];
 	}
 	return 0;
+}
+
+int ext4_journal_start(const char *mount_point)
+{
+	int r = EOK;
+	struct ext4_mountpoint *mp = ext4_get_mount(mount_point);
+	if (!mp)
+		return ENOENT;
+
+	if (ext4_sb_feature_com(&mp->fs.sb,
+				EXT4_FCOM_HAS_JOURNAL)) {
+		r = jbd_get_fs(&mp->fs, &mp->jbd_fs);
+		if (r != EOK)
+			goto Finish;
+
+		r = jbd_journal_start(&mp->jbd_fs, &mp->jbd_journal);
+		if (r != EOK) {
+			mp->jbd_fs.dirty = false;
+			jbd_put_fs(&mp->jbd_fs);
+			goto Finish;
+		}
+		mp->fs.jbd_fs = &mp->jbd_fs;
+		mp->fs.jbd_journal = &mp->jbd_journal;
+	}
+Finish:
+	return r;
+}
+
+int ext4_journal_stop(const char *mount_point)
+{
+	int r = EOK;
+	struct ext4_mountpoint *mp = ext4_get_mount(mount_point);
+	if (!mp)
+		return ENOENT;
+
+	if (ext4_sb_feature_com(&mp->fs.sb,
+				EXT4_FCOM_HAS_JOURNAL)) {
+		r = jbd_journal_stop(&mp->jbd_journal);
+		if (r != EOK) {
+			mp->jbd_fs.dirty = false;
+			jbd_put_fs(&mp->jbd_fs);
+			mp->fs.jbd_journal = NULL;
+			mp->fs.jbd_fs = NULL;
+			goto Finish;
+		}
+
+		r = jbd_put_fs(&mp->jbd_fs);
+		if (r != EOK) {
+			mp->fs.jbd_journal = NULL;
+			mp->fs.jbd_fs = NULL;
+			goto Finish;
+		}
+
+		mp->fs.jbd_journal = NULL;
+		mp->fs.jbd_fs = NULL;
+	}
+Finish:
+	return r;
 }
 
 int ext4_recover(const char *mount_point)