ref: 8c2fea16ee857319361994a2a7628d03a7c030d9
parent: e7541250edb2a747a3a339439de98c80025ab022
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Fri Dec 25 12:11:45 EST 2015
ext4: add ext4_trans_start/stop/abort to high level public routines.
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -1048,6 +1048,7 @@
return EINVAL;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
r = ext4_generic_open2(&f, path, O_RDONLY, EXT4_DE_UNKNOWN,
&parent_inode, &name_off);
@@ -1077,6 +1078,11 @@
if (child_loaded)
ext4_fs_put_inode_ref(&child_ref);
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
@@ -1096,6 +1102,7 @@
return ENOENT;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
r = ext4_generic_open2(&f, path, O_RDONLY, EXT4_DE_UNKNOWN,
&parent_inode, &name_off);
@@ -1134,6 +1141,11 @@
if (child_loaded)
ext4_fs_put_inode_ref(&child_ref);
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
@@ -1181,9 +1193,12 @@
return ENOENT;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
+
r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN,
&parent_inode, &name_off);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1191,6 +1206,7 @@
/*Load parent*/
r = ext4_fs_get_inode_ref(&mp->fs, parent_inode, &parent);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1199,6 +1215,7 @@
r = ext4_fs_get_inode_ref(&mp->fs, f.inode, &child);
if (r != EOK) {
ext4_fs_put_inode_ref(&parent);
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1233,6 +1250,12 @@
Finish:
ext4_fs_put_inode_ref(&child);
ext4_fs_put_inode_ref(&parent);
+
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1286,9 +1309,17 @@
return ENOENT;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
+
ext4_block_cache_write_back(mp->fs.bdev, 1);
r = ext4_generic_open(f, path, flags, true, 0, 0);
ext4_block_cache_write_back(mp->fs.bdev, 0);
+
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1305,9 +1336,17 @@
filetype = EXT4_DE_REG_FILE;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
+
ext4_block_cache_write_back(mp->fs.bdev, 1);
r = ext4_generic_open2(f, path, flags, filetype, NULL, NULL);
ext4_block_cache_write_back(mp->fs.bdev, 0);
+
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1377,7 +1416,14 @@
return EPERM;
EXT4_MP_LOCK(f->mp);
+
+ ext4_trans_start(f->mp);
r = ext4_ftruncate_no_lock(f, size);
+ if (r != EOK)
+ ext4_trans_abort(f->mp);
+ else
+ ext4_trans_stop(f->mp);
+
EXT4_MP_UNLOCK(f->mp);
return r;
}
@@ -1565,6 +1611,7 @@
return EOK;
EXT4_MP_LOCK(f->mp);
+ ext4_trans_start(f->mp);
struct ext4_fs *const fs = &f->mp->fs;
struct ext4_sblock *const sb = &f->mp->fs.sb;
@@ -1574,6 +1621,7 @@
r = ext4_fs_get_inode_ref(fs, f->inode, &ref);
if (r != EOK) {
+ ext4_trans_abort(f->mp);
EXT4_MP_UNLOCK(f->mp);
return r;
}
@@ -1713,7 +1761,13 @@
}
Finish:
- ext4_fs_put_inode_ref(&ref);
+ r = ext4_fs_put_inode_ref(&ref);
+
+ if (r != EOK)
+ ext4_trans_abort(f->mp);
+ else
+ ext4_trans_stop(f->mp);
+
EXT4_MP_UNLOCK(f->mp);
return r;
}
@@ -1766,9 +1820,11 @@
return ENOENT;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN, NULL, NULL);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1777,6 +1833,7 @@
ext4_fclose(&f);
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1784,7 +1841,12 @@
ext4_inode_set_mode(sb, inode_ref.inode, mode);
inode_ref.dirty = true;
- ext4_fs_put_inode_ref(&inode_ref);
+ r = ext4_fs_put_inode_ref(&inode_ref);
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1801,9 +1863,11 @@
return ENOENT;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN, NULL, NULL);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1811,6 +1875,7 @@
ext4_fclose(&f);
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1819,7 +1884,12 @@
ext4_inode_set_gid(inode_ref.inode, gid);
inode_ref.dirty = true;
- ext4_fs_put_inode_ref(&inode_ref);
+ r = ext4_fs_put_inode_ref(&inode_ref);
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1836,9 +1906,11 @@
return ENOENT;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN, NULL, NULL);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1846,6 +1918,7 @@
ext4_fclose(&f);
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1853,7 +1926,12 @@
ext4_inode_set_access_time(inode_ref.inode, atime);
inode_ref.dirty = true;
- ext4_fs_put_inode_ref(&inode_ref);
+ r = ext4_fs_put_inode_ref(&inode_ref);
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1870,9 +1948,11 @@
return ENOENT;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN, NULL, NULL);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1880,6 +1960,7 @@
ext4_fclose(&f);
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1887,7 +1968,12 @@
ext4_inode_set_modif_time(inode_ref.inode, mtime);
inode_ref.dirty = true;
- ext4_fs_put_inode_ref(&inode_ref);
+ r = ext4_fs_put_inode_ref(&inode_ref);
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1904,9 +1990,11 @@
return ENOENT;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
r = ext4_generic_open2(&f, path, O_RDWR, EXT4_DE_UNKNOWN, NULL, NULL);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1914,6 +2002,7 @@
ext4_fclose(&f);
r = ext4_fs_get_inode_ref(&mp->fs, ino, &inode_ref);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -1921,7 +2010,12 @@
ext4_inode_set_change_inode_time(inode_ref.inode, ctime);
inode_ref.dirty = true;
- ext4_fs_put_inode_ref(&inode_ref);
+ r = ext4_fs_put_inode_ref(&inode_ref);
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -2006,6 +2100,8 @@
filetype = EXT4_DE_SYMLINK;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
+
ext4_block_cache_write_back(mp->fs.bdev, 1);
r = ext4_generic_open2(&f, path, O_RDWR|O_CREAT, filetype, NULL, NULL);
if (r == EOK)
@@ -2048,6 +2144,11 @@
Finish:
ext4_block_cache_write_back(mp->fs.bdev, 0);
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -2308,6 +2409,7 @@
return ENOENT;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
struct ext4_fs *const fs = &mp->fs;
@@ -2314,6 +2416,7 @@
/*Check if exist.*/
r = ext4_generic_open(&f, path, "r", false, &inode_up, &name_off);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -2479,6 +2582,12 @@
ext4_block_cache_write_back(mp->fs.bdev, 0);
EXT4_MP_UNLOCK(mp);
+
+ if (r != EOK)
+ ext4_trans_abort(mp);
+ else
+ ext4_trans_stop(mp);
+
return r;
}
@@ -2493,11 +2602,13 @@
return ENOENT;
EXT4_MP_LOCK(mp);
+ ext4_trans_start(mp);
/*Check if exist.*/
r = ext4_generic_open(&f, path, "r", false, 0, 0);
if (r == EOK) {
/*Directory already created*/
+ ext4_trans_stop(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
@@ -2505,10 +2616,12 @@
/*Create new dir*/
r = ext4_generic_open(&f, path, "w", false, 0, 0);
if (r != EOK) {
+ ext4_trans_abort(mp);
EXT4_MP_UNLOCK(mp);
return r;
}
+ ext4_trans_stop(mp);
EXT4_MP_UNLOCK(mp);
return r;
}