diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2008-07-22 06:06:20 -0400 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2008-08-13 04:28:44 -0400 |
commit | de94eb558b542873d3f6f9ede1b8575fb5662248 (patch) | |
tree | 3ba858a1c87870e22886ac3d4774287bbf367131 /fs/ubifs/journal.c | |
parent | 014eb04b03202dc75c1c749df4246d98045f5e69 (diff) |
UBIFS: optimize deletions
Every time anything is deleted, UBIFS writes the deletion inode
node twice - once in 'ubifs_jnl_update()' and the second time in
'ubifs_jnl_write_inode()'. However, the second write is not needed
if no commit happened after 'ubifs_jnl_update()'. This patch
checks that condition and avoids writing the deletion inode for
the second time.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'fs/ubifs/journal.c')
-rw-r--r-- | fs/ubifs/journal.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c index 3bc3fc947099..0bcee7d221e8 100644 --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c | |||
@@ -604,6 +604,7 @@ int ubifs_jnl_update(struct ubifs_info *c, const struct inode *dir, | |||
604 | release_head(c, BASEHD); | 604 | release_head(c, BASEHD); |
605 | goto out_finish; | 605 | goto out_finish; |
606 | } | 606 | } |
607 | ui->del_cmtno = c->cmt_no; | ||
607 | } | 608 | } |
608 | 609 | ||
609 | err = write_head(c, BASEHD, dent, len, &lnum, &dent_offs, sync); | 610 | err = write_head(c, BASEHD, dent, len, &lnum, &dent_offs, sync); |
@@ -821,6 +822,64 @@ out_free: | |||
821 | } | 822 | } |
822 | 823 | ||
823 | /** | 824 | /** |
825 | * ubifs_jnl_write_inode - delete an inode. | ||
826 | * @c: UBIFS file-system description object | ||
827 | * @inode: inode to delete | ||
828 | * | ||
829 | * This function deletes inode @inode which includes removing it from orphans, | ||
830 | * deleting it from TNC and, in some cases, writing a deletion inode to the | ||
831 | * journal. | ||
832 | * | ||
833 | * When regular file inodes are unlinked or a directory inode is removed, the | ||
834 | * 'ubifs_jnl_update()' function write corresponding deletion inode and | ||
835 | * direntry to the media, and adds the inode to orphans. After this, when the | ||
836 | * last reference to this inode has been dropped, this function is called. In | ||
837 | * general, it has to write one more deletion inode to the media, because if | ||
838 | * a commit happened between 'ubifs_jnl_update()' and | ||
839 | * 'ubifs_jnl_delete_inode()', the deletion inode is not in the journal | ||
840 | * anymore, and in fact it might be not on the flash anymore, becouse it might | ||
841 | * have been garbage-collected already. And for optimization reasond UBIFS does | ||
842 | * not read the orphan area if it has been unmounted cleanly, so it would have | ||
843 | * no indication in the journal that there is a deleted inode which has to be | ||
844 | * removed from TNC. | ||
845 | * | ||
846 | * However, if there was no commit between 'ubifs_jnl_update()' and | ||
847 | * 'ubifs_jnl_delete_inode()', then there is no need to write the deletion | ||
848 | * inode to the media for the second time. And this is quite typical case. | ||
849 | * | ||
850 | * This function returns zero in case of success and a negative error code in | ||
851 | * case of failure. | ||
852 | */ | ||
853 | int ubifs_jnl_delete_inode(struct ubifs_info *c, const struct inode *inode) | ||
854 | { | ||
855 | int err; | ||
856 | struct ubifs_inode *ui = ubifs_inode(inode); | ||
857 | |||
858 | ubifs_assert(inode->i_nlink == 0); | ||
859 | |||
860 | if (ui->del_cmtno != c->cmt_no) | ||
861 | /* A commit happened for sure */ | ||
862 | return ubifs_jnl_write_inode(c, inode); | ||
863 | |||
864 | down_read(&c->commit_sem); | ||
865 | /* | ||
866 | * Check commit number again, because the first test has been done | ||
867 | * without @c->commit_sem, so a commit might have happened. | ||
868 | */ | ||
869 | if (ui->del_cmtno != c->cmt_no) { | ||
870 | up_read(&c->commit_sem); | ||
871 | return ubifs_jnl_write_inode(c, inode); | ||
872 | } | ||
873 | |||
874 | ubifs_delete_orphan(c, inode->i_ino); | ||
875 | err = ubifs_tnc_remove_ino(c, inode->i_ino); | ||
876 | if (err) | ||
877 | ubifs_ro_mode(c, err); | ||
878 | up_read(&c->commit_sem); | ||
879 | return err; | ||
880 | } | ||
881 | |||
882 | /** | ||
824 | * ubifs_jnl_rename - rename a directory entry. | 883 | * ubifs_jnl_rename - rename a directory entry. |
825 | * @c: UBIFS file-system description object | 884 | * @c: UBIFS file-system description object |
826 | * @old_dir: parent inode of directory entry to rename | 885 | * @old_dir: parent inode of directory entry to rename |
@@ -928,6 +987,7 @@ int ubifs_jnl_rename(struct ubifs_info *c, const struct inode *old_dir, | |||
928 | release_head(c, BASEHD); | 987 | release_head(c, BASEHD); |
929 | goto out_finish; | 988 | goto out_finish; |
930 | } | 989 | } |
990 | new_ui->del_cmtno = c->cmt_no; | ||
931 | } | 991 | } |
932 | 992 | ||
933 | err = write_head(c, BASEHD, dent, len, &lnum, &offs, sync); | 993 | err = write_head(c, BASEHD, dent, len, &lnum, &offs, sync); |