]> git.sur5r.net Git - u-boot/commitdiff
ext4: Only write journal entries for modified blocks in unlink_filename
authorStefan Brüns <stefan.bruens@rwth-aachen.de>
Sun, 9 Oct 2016 18:15:28 +0000 (20:15 +0200)
committerTom Rini <trini@konsulko.com>
Mon, 24 Oct 2016 12:04:37 +0000 (08:04 -0400)
Instead of creating a journal entry for each directory block, even
if the block is unmodified, only log the modified block.

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
fs/ext4/ext4_common.c

index 0c11ddb1b5891d5aa766d2d5f324d1593e490cbb..4248ac1dcf500f7ad9b15d4f80c493304c36ce26 100644 (file)
@@ -874,8 +874,6 @@ static int unlink_filename(char *filename, unsigned int blknr)
        if (status == 0)
                goto fail;
 
-       if (ext4fs_log_journal(block_buffer, blknr))
-               goto fail;
        offset = 0;
        do {
                previous_dir = dir;
@@ -889,14 +887,6 @@ static int unlink_filename(char *filename, unsigned int blknr)
                if (dir->inode && (strlen(filename) == dir->namelen) &&
                    (strncmp(direntname, filename, dir->namelen) == 0)) {
                        inodeno = le32_to_cpu(dir->inode);
-                       if (previous_dir) {
-                               uint16_t new_len;
-                               new_len = le16_to_cpu(previous_dir->direntlen);
-                               new_len += le16_to_cpu(dir->direntlen);
-                               previous_dir->direntlen = cpu_to_le16(new_len);
-                       } else {
-                               dir->inode = 0;
-                       }
                        break;
                }
 
@@ -905,7 +895,20 @@ static int unlink_filename(char *filename, unsigned int blknr)
        } while (offset < fs->blksz);
 
        if (inodeno > 0) {
+               printf("file found, deleting\n");
+               if (ext4fs_log_journal(block_buffer, blknr))
+                       goto fail;
 
+               if (previous_dir) {
+                       /* merge dir entry with predecessor */
+                       uint16_t new_len;
+                       new_len = le16_to_cpu(previous_dir->direntlen);
+                       new_len += le16_to_cpu(dir->direntlen);
+                       previous_dir->direntlen = cpu_to_le16(new_len);
+               } else {
+                       /* invalidate dir entry */
+                       dir->inode = 0;
+               }
                if (ext4fs_put_metadata(block_buffer, blknr))
                        goto fail;
                ret = inodeno;