linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: lost matching-pair of trace in ext4_truncate
@ 2020-06-29  2:13 zhengliang
  2020-06-29 19:38 ` Andreas Dilger
  0 siblings, 1 reply; 2+ messages in thread
From: zhengliang @ 2020-06-29  2:13 UTC (permalink / raw)
  To: tytso, adilger.kernel; +Cc: linux-ext4

If truncate inline data successfully, it shoule call trace exit.

Signed-off-by: zhengliang <zhengliang6@huawei.com>
---
 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;
+		}
 	}
 
 	/* If we zero-out tail of the page, we have to create jinode for jbd2 */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: lost matching-pair of trace in ext4_truncate
  2020-06-29  2:13 [PATCH] ext4: lost matching-pair of trace in ext4_truncate zhengliang
@ 2020-06-29 19:38 ` Andreas Dilger
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Dilger @ 2020-06-29 19:38 UTC (permalink / raw)
  To: zhengliang; +Cc: Theodore Y. Ts'o, Ext4 Developers List

[-- Attachment #1: Type: text/plain, Size: 2154 bytes --]

On Jun 28, 2020, at 8:13 PM, zhengliang <zhengliang6@huawei.com> wrote:
> 
> If truncate inline data successfully, it shoule call trace exit.
> 
> Signed-off-by: zhengliang <zhengliang6@huawei.com>
> ---
> 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 #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-29 19:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29  2:13 [PATCH] ext4: lost matching-pair of trace in ext4_truncate zhengliang
2020-06-29 19:38 ` Andreas Dilger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).