Re: [PATCH] ext4: lost matching-pair of trace in ext4_truncate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jun 28, 2020, at 8:13 PM, zhengliang <zhengliang6@xxxxxxxxxx> wrote:
> 
> If truncate inline data successfully, it shoule call trace exit.
> 
> Signed-off-by: zhengliang <zhengliang6@xxxxxxxxxx>
> ---
> fs/ext4/inode.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index e416096fc081..6d24ed658e30 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4171,8 +4171,10 @@ int ext4_truncate(struct inode *inode)
> 		err = ext4_inline_data_truncate(inode, &has_inline);
> 		if (err)
> 			return err;
> -		if (has_inline)
> +		if (has_inline) {
> +			trace_ext4_truncate_exit(inode);
> 			return 0;
> +		}
> 	}

This only handles one of many similar cases in this function.  That is why
the preferred code style is to have a single exit path with labels that
handle the cleanup in reverse order from the setup.  This avoids the need
to have multiple copies of the cleanup code in each error case, and avoids
bugs where some of the cleanup steps are missed.  Something like:

	trace_ext4_truncate_enter(inode);

        if (!ext4_can_truncate(inode))
                goto out_trace;

        ext4_clear_inode_flag(inode, EXT4_INODE_EOFBLOCKS);

        if (inode->i_size == 0 && !test_opt(inode->i_sb, NO_AUTO_DA_ALLOC))
                ext4_set_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE);

        if (ext4_has_inline_data(inode)) {
                int has_inline = 1;

                err = ext4_inline_data_truncate(inode, &has_inline);
                if (err || has_inline)
			goto out_trace;
        }

        /* If we zero-out tail of the page, we have to create jinode for jbd2 */
        if (inode->i_size & (inode->i_sb->s_blocksize - 1)) {
                if (ext4_inode_attach_jinode(inode) < 0)
                        goto out_trace;
        }

        handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits);
        if (IS_ERR(handle)) {
                err = PTR_ERR(handle);
		goto out_trace;
	}
	:
	:

out_trace:
	trace_ext4_truncate_exit(inode);
	return err;

Cheers, Andreas





Attachment: signature.asc
Description: Message signed with OpenPGP


[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux