]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: handle inline_data in block iterator function
authorZheng Liu <wenqing.lz@taobao.com>
Mon, 3 Mar 2014 05:27:48 +0000 (00:27 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 4 Mar 2014 13:46:13 +0000 (08:46 -0500)
After applied this commit (a7f4c635), we have banned to traverse blocks
for an inode which has inline data because no block belongs to it.  But
before calling this function, we need to check inline data flag.  This
commit add a sanity check ext2fs_inode_has_valid_blocks2() to fix them
except that ext2fs_expand_dir because it will be fixed by another patch.

Meanwhile in this commit it fixes a bug that when we kill a file we
could leak an inode.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debugfs/debugfs.c
debugfs/filefrag.c
debugfs/lsdel.c
lib/ext2fs/valid_blk.c
misc/tune2fs.c

index a3fcbf41761cfe150f0ff991cf5d9572e07ee349..29c0161620bfa6691519623f0bae516d395ae3bb 100644 (file)
@@ -1924,11 +1924,10 @@ static void kill_file_by_inode(ext2_ino_t inode)
        inode_buf.i_dtime = current_fs->now ? current_fs->now : time(0);
        if (debugfs_write_inode(inode, &inode_buf, 0))
                return;
-       if (!ext2fs_inode_has_valid_blocks2(current_fs, &inode_buf))
-               return;
-
-       ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, NULL,
-                             release_blocks_proc, NULL);
+       if (ext2fs_inode_has_valid_blocks2(current_fs, &inode_buf)) {
+               ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY,
+                                     NULL, release_blocks_proc, NULL);
+       }
        printf("\n");
        ext2fs_inode_alloc_stats2(current_fs, inode, -1,
                                  LINUX_S_ISDIR(inode_buf.i_mode));
index 6219d7cb71913809b17a5969099b236e6207c890..49345ad1fcea469fb517f08d0f71124e1d033067 100644 (file)
@@ -154,11 +154,13 @@ static void filefrag(ext2_ino_t ino, struct ext2_inode *inode,
                        fs->name, num_blocks, EXT2_I_SIZE(inode));
        }
        print_header(fs);
-       retval = ext2fs_block_iterate3(current_fs, ino,
-                                      BLOCK_FLAG_READ_ONLY, NULL,
-                                      filefrag_blocks_proc, fs);
-       if (retval)
-               com_err("ext2fs_block_iterate3", retval, 0);
+       if (ext2fs_inode_has_valid_blocks2(current_fs, inode)) {
+               retval = ext2fs_block_iterate3(current_fs, ino,
+                                              BLOCK_FLAG_READ_ONLY, NULL,
+                                              filefrag_blocks_proc, fs);
+               if (retval)
+                       com_err("ext2fs_block_iterate3", retval, 0);
+       }
 
        report_filefrag(fs);
        fprintf(fs->f, "%s: %d contiguous extents%s\n", fs->name, fs->ext,
index e5b2d203bacb8207984cdf858cb40e1ece98720b..0e774a302ccc9841f46fdc55c73c335b3557ea5b 100644 (file)
@@ -141,13 +141,16 @@ void do_lsdel(int argc, char **argv)
                lsd.free_blocks = 0;
                lsd.bad_blocks = 0;
 
-               retval = ext2fs_block_iterate3(current_fs, ino,
-                                              BLOCK_FLAG_READ_ONLY, block_buf,
-                                              lsdel_proc, &lsd);
-               if (retval) {
-                       com_err("ls_deleted_inodes", retval,
-                               "while calling ext2fs_block_iterate2");
-                       goto next;
+               if (ext2fs_inode_has_valid_blocks2(current_fs, &inode)) {
+                       retval = ext2fs_block_iterate3(current_fs, ino,
+                                                      BLOCK_FLAG_READ_ONLY,
+                                                      block_buf,
+                                                      lsdel_proc, &lsd);
+                       if (retval) {
+                               com_err("ls_deleted_inodes", retval,
+                                       "while calling ext2fs_block_iterate2");
+                               goto next;
+                       }
                }
                if (lsd.free_blocks && !lsd.bad_blocks) {
                        if (num_delarray >= max_delarray) {
index 895e36ef0f5d818f3a54c55cfcfc49c8b06b8bb2..db5d90ae4076d035020af61ab927417d17811bf6 100644 (file)
@@ -52,6 +52,13 @@ int ext2fs_inode_has_valid_blocks2(ext2_filsys fs, struct ext2_inode *inode)
                        return 0; /* Probably a fast symlink */
                }
        }
+
+       /*
+        * If this inode has inline data, it shouldn't have valid block
+        * entries.
+        */
+       if (inode->i_flags & EXT4_INLINE_DATA_FL)
+               return 0;
        return 1;
 }
 
index 09dd973aee1e44ae754a02680bd9753ca94c0a46..657176415c7fc4a49f1f06cd603f985aa60512ef 100644 (file)
@@ -693,7 +693,8 @@ static void rewrite_inodes(ext2_filsys fs)
                        exit(1);
                }
 
-               if (LINUX_S_ISDIR(inode->i_mode)) {
+               if (LINUX_S_ISDIR(inode->i_mode) &&
+                   ext2fs_inode_has_valid_blocks2(fs, inode)) {
                        retval = rewrite_directory(fs, ino, inode);
                        if (retval) {
                                com_err("rewrite_directory", retval,