Linux-ext4 Archive on lore.kernel.org
 help / color / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: zhengliang <zhengliang6@huawei.com>
Cc: "Theodore Y. Ts'o" <tytso@mit.edu>,
	Ext4 Developers List <linux-ext4@vger.kernel.org>
Subject: Re: [PATCH] ext4: lost matching-pair of trace in ext4_truncate
Date: Mon, 29 Jun 2020 13:38:47 -0600
Message-ID: <E3E19655-BCA9-4629-9B6E-24B698777E15@dilger.ca> (raw)
In-Reply-To: <20200629021341.36129-1-zhengliang6@huawei.com>


[-- 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 --]

      reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-29  2:13 zhengliang
2020-06-29 19:38 ` Andreas Dilger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E3E19655-BCA9-4629-9B6E-24B698777E15@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=zhengliang6@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-ext4 Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-ext4/0 linux-ext4/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-ext4 linux-ext4/ https://lore.kernel.org/linux-ext4 \
		linux-ext4@vger.kernel.org
	public-inbox-index linux-ext4

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-ext4


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git